I found ops.ifft2 reports an error when computing arrays with float64 dtype using TensorFlow backend. This issue is specifically with ifft2 while fft2 works fine. It is annoying for us because we need to test our code in various precision and backend.
from keras import ops
import numpy as np
precision = "float64"
xreal = np.random.rand(4, 5).astype(precision)
ximag = np.random.rand(4, 5).astype(precision)
result = ops.ifft2((xreal, ximag))
Error Message
Traceback (most recent call last):
File "/Users/yifengshao/.vscode/extensions/ms-python.python-2025.0.0-darwin-arm64/python_files/python_server.py", line 133, in exec_user_input
retval = callable_(user_input, user_globals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 6, in <module>
File "/opt/anaconda3/envs/ptychoflow/lib/python3.11/site-packages/keras/src/ops/math.py", line 548, in ifft2
return backend.math.ifft2(x)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/anaconda3/envs/ptychoflow/lib/python3.11/site-packages/keras/src/backend/tensorflow/math.py", line 122, in ifft2
return fft_real [/](https://file+.vscode-resource.vscode-cdn.net/) (h * w), -fft_imag [/](https://file+.vscode-resource.vscode-cdn.net/) (h * w)
~~~~~~~~~^~~~~~~~~
File "/opt/anaconda3/envs/ptychoflow/lib/python3.11/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/opt/anaconda3/envs/ptychoflow/lib/python3.11/site-packages/tensorflow/python/ops/math_ops.py", line 1434, in _truediv_python3
raise TypeError(f"`x` and `y` must have the same dtype, "
TypeError: `x` and `y` must have the same dtype, got tf.float64 != tf.float32.
Environment
tensorflow 2.18.0
keras 3.8.0
Comment From: google-ml-butler[bot]