Repository navigation
Description
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
gamila-wisam commentedon Jan 23, 2026
This PR fixes integer behavior for tf.experimental.numpy.isclose and matches NumPy.
gamila-wisam commentedon Jan 26, 2026
Hi @AVPtheGOAT, Thank you for the suggestion! you're right , i added a test to compare TensorFlow vs NumPy for integer broadcasting.
Kayyuri commentedon Jul 23, 2026
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!
google-ml-butler commentedon Jul 28, 2026
Are you satisfied with the resolution of your issue?
Yes
No
Apply rtol and atol to integer inputs in tf.experimental.numpy.isclose