Skip to content

tf.experimental.numpy.isclose returns incorrect results for integer inputs #108657

Closed

Description

@Thrsu

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

v2.20.0-rc0-4-g72fbba3d20f 2.20.0

Custom code

Yes

OS platform and distribution

No response

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

Description:

tf.experimental.numpy.isclose is documented as a TensorFlow variant of NumPy's isclose function. It is expected to behave identically to NumPy, including support for integer inputs. However, when the input tensors are integers, tf.experimental.numpy.isclose return incorrect results.

Analysis:

The expected behavior of the below reproduction code is that all elements return True, consistent with NumPy.
The discrepancy occurs only when the inputs are integer types (int32, int64).
TensorFlow does not correctly handle integer inputs internally in tf.experimental.numpy.isclose. Even though integer arithmetic should in principle work with the formula: ∣a − b∣ ≤ atol + rtol * ∣b∣
the internal implementation appears to mishandle the comparison, resulting in all False.
Casting inputs to float32 or float64 returns the correct results.

Standalone code to reproduce the issue

import tensorflow as tf
import numpy as np

input = tf.constant(np.array([[-13, -5, -12], [3, 17, -6], [5, 3, -8], [-18, 19, 10]]), dtype='int32')
other = tf.constant(np.array([-7]), dtype='int32')
rtol = 9
atol = 0
equal_nan = False

out_tf_int = tf.experimental.numpy.isclose(input, other, rtol=rtol, atol=atol, equal_nan=equal_nan)
print("out_tf_int:\n", out_tf_int)

out_tf_float = tf.experimental.numpy.isclose(tf.cast(input, tf.float64), tf.cast(other, tf.float64), rtol=rtol, atol=atol)
print("out_tf_float:\n", out_tf_float)

input = np.array([[-13, -5, -12], [3, 17, -6], [5, 3, -8], [-18, 19, 10]], dtype=np.int32)
other = np.array([-7], dtype=np.int32)
rtol = 9
atol = 0
equal_nan = False

out_np_int = np.isclose(input, other, rtol=rtol, atol=atol, equal_nan=equal_nan)
print("out_np_int:\n", out_np_int)

out_np_float = np.isclose(input.astype(np.float64), other.astype(np.float64), rtol=rtol, atol=atol)
print("out_np_float:\n", out_np_float)

Relevant log output

out_tf_int:
 tf.Tensor(
[[False False False]
 [False False False]
 [False False False]
 [False False False]], shape=(4, 3), dtype=bool)
out_tf_float:
 tf.Tensor(
[[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]], shape=(4, 3), dtype=bool)
out_np_int:
 [[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]]
out_np_float:
 [[ True  True  True]
 [ True  True  True]
 [ True  True  True]
 [ True  True  True]]

Activity

  1. gamila-wisam commented on Jan 23, 2026

    @gamila-wisam

    This PR fixes integer behavior for tf.experimental.numpy.isclose and matches NumPy.

  2. gamila-wisam commented on Jan 26, 2026

    @gamila-wisam

    Hi @AVPtheGOAT, Thank you for the suggestion! you're right , i added a test to compare TensorFlow vs NumPy for integer broadcasting.

  3. added
    comp:apis
    on Jan 27, 2026
  4. removed
    awaiting PR merge
    on Jul 23, 2026
  5. Kayyuri commented on Jul 23, 2026

    @Kayyuri

    Hi @Thrsu,
    Thank you so much for filing this issue! We truly appreciate your support. At the moment, this request is not prioritized and mark it for community contributions. If you would like to contribute on a fix, please feel free to fork the repository and submit a pull request in accordance with the TensorFlow CONTRIBUTION GUIDELINES and link this issue in your PR to ensure the maintainers can easily review and collaborate.
    To avoid duplicate work, please leave a comment here if you decide to take it on!

    Thank you again for your interest and we look forward to seeing your contributions!

  6. added
    stat:contribution welcome
    awaiting PR merge
    and removed
    stat:contribution welcome
    on Jul 23, 2026
  7. google-ml-butler commented on Jul 28, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

  8. added a commit that references this issue on Jul 28, 2026
    c05c0c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

TF 2.19awaiting PR mergecomp:apistype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions