Repository navigation
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
tf-nightly 2.23.0.dev20261003 (v1.12.1-146048-g170cb1a320b)
Custom code
Yes
OS platform and distribution
macOS 26.6.2, arm64
Mobile device
Not applicable
Python version
3.13.7
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
tf.experimental.numpy.isclose returns the opposite of NumPy for infinities:
same-sign infinities are reported as not close, while opposite-sign infinities
are reported as close with the default tolerances. allclose inherits the
same behavior.
The floating-point branch applies the finite tolerance formula directly.
Thus inf - inf becomes NaN, while abs(-inf - inf) <= rtol * abs(inf)
becomes inf <= inf.
Expected behavior
Matching NumPy, infinities should be close only when they have the same sign.
Related upstream issues
I could not find an existing issue or PR for infinity handling. Issue #108657
and PRs #108702/#123867 concern integer inputs; PR #122605 concerns an XLA
shape mismatch. None cover this floating-point non-finite case.
Standalone code to reproduce the issue
import numpy as np
import tensorflow as tf
import tensorflow.experimental.numpy as tnp
a = tf.constant([np.inf, -np.inf, -np.inf, np.inf, 1.0], tf.float64)
b = tf.constant([np.inf, -np.inf, np.inf, -np.inf, 1.0], tf.float64)
print("TensorFlow isclose:", tnp.isclose(a, b).numpy().tolist())
print("NumPy isclose: ", np.isclose(a.numpy(), b.numpy()).tolist())
print("TensorFlow allclose same inf:", bool(tnp.allclose([np.inf], [np.inf]).numpy()))
print("NumPy allclose same inf: ", bool(np.allclose([np.inf], [np.inf])))
print("TensorFlow allclose opposite inf:", bool(tnp.allclose([-np.inf], [np.inf]).numpy()))
print("NumPy allclose opposite inf: ", bool(np.allclose([-np.inf], [np.inf])))Relevant log output
TensorFlow isclose: [False, False, True, True, True]
NumPy isclose: [True, True, False, False, True]
TensorFlow allclose same inf: False
NumPy allclose same inf: True
TensorFlow allclose opposite inf: True
NumPy allclose opposite inf: False
The same result occurs for `float32` and `float64`, scalars and vectors, eager
execution, `tf.function`, and XLA. NumPy version: 2.5.3.
Activity
genius-0963 commentedon Oct 4, 2026
Could you please check whether the issue has been fixed or not?
Kayyuri commentedon Oct 5, 2026
Hi @CaelusHu, Thank you for reporting this issue!
A fix for this issue has been proposed in this PR. Once it is merged, this issue will be resolved.
Many thanks to @genius-0963 for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
Fix isclose/allclose returning inverted results for infinities
Fix isclose/allclose returning inverted results for infinities
google-ml-butler commentedon Oct 15, 2026
Are you satisfied with the resolution of your issue?
Yes
No