You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tf.math.angle gives inconsistent outputs on NaN value: if tensor dtype=complex128 then NaN, while for dtype=float64 it is 0.
Although doc states that for any real input the output will be zero, I would like to list some points to argue.
It does not make sense for ending up with a regular value for calculating NaN.
The nature of NaN should not change, regardless of the dtype of the tensor it's staying in.
Such behavior may let NaN error to escape, causing trouble in debugging.
Expected behavior: the result is NaN when input is NaN.
def angle_with_nan_handling(input_tensor):
# Check if input_tensor contains NaN values
contains_nan = tf.reduce_any(tf.math.is_nan(input_tensor))
# If input_tensor contains NaN values, return NaN
if contains_nan:
return tf.fill(tf.shape(input_tensor), tf.constant(np.nan, dtype=tf.float64))
else:
# Calculate angle for non-NaN values
return tf.math.angle(input_tensor)
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
tf 2.15.0
Custom code
Yes
OS platform and distribution
Linux-5.14.0-362.18.1.el9_3.x86_64-x86_64-with-glibc2.34
Mobile device
AlmaLinux 9
Python version
3.9
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current behavior?
tf.math.angle gives inconsistent outputs on NaN value: if tensor dtype=complex128 then NaN, while for dtype=float64 it is 0.
Although doc states that for any real input the output will be zero, I would like to list some points to argue.
Expected behavior: the result is NaN when input is NaN.
Standalone code to reproduce the issue
Relevant log output
No response
The text was updated successfully, but these errors were encountered: