keras-team/keras · error · ValueError

At least one tensor in input `x` is not of type…

Error message

At least one tensor in input `x` is not of type float.Received: x={x}.

What it means

Dtype guard in `_get_complex_tensor_from_tuple` (NumPy backend), run after the tuple-format and shape checks: both elements (real and imaginary parts) must be floating-point tensors because the subsequent complex arithmetic requires fractional values. If either element is an integer/boolean tensor, the float check fails and this error reports the whole received tuple so the offending part can be identified.

Solutions

  1. Cast both parts to a float dtype: (keras.ops.cast(r, 'float32'), keras.ops.cast(i, 'float32'))
  2. Ensure the code building the tuple did not pass int-index arrays or integer counts as the imaginary part
  3. Standardize the complex pipeline on keras.config.floatx() precision
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at keras/src/backend/numpy/ops/math.py:156 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/ed248ec796eea9fb. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/numpy/ops/math.py:156

        raise ValueError(
            "Input `x` should be a tuple of two tensors - real and imaginary."
            f"Received: x={x}"
        )
    # `convert_to_tensor` does not support passing complex tensors. We separate
    # the input out into real and imaginary and convert them separately.
    real, imag = x
    # Check shapes.
    if real.shape != imag.shape:
        raise ValueError(
            "Input `x` should be a tuple of two tensors - real and imaginary."
            "Both the real and imaginary parts should have the same shape. "
            f"Received: x[0].shape = {real.shape}, x[1].shape = {imag.shape}"
        )
    # Ensure dtype is float.
    if not np.issubdtype(real.dtype, np.floating) or not np.issubdtype(
        imag.dtype, np.floating
    ):
        raise ValueError(
            "At least one tensor in input `x` is not of type float."
            f"Received: x={x}."
        )
    complex_input = real + 1j * imag
    return complex_input


def fft(x):
    real, imag = jax_fft(x)
    return np.array(real), np.array(imag)


def fft2(x):
    real, imag = jax_fft2(x)
    return np.array(real), np.array(imag)


def ifft2(x):

View on GitHub (pinned to 7a34a03db6)