{"record":{"id":"1babb3e83077100b","repo":"keras-team/keras","slug":"invalid-input-type-expected-float32-or-float64-1babb3","errorCode":null,"errorMessage":"Invalid input type. Expected `float32` or `float64`. Received: input type={x.dtype}","messagePattern":"Invalid input type\\. Expected `float32` or `float64`\\. Received: input type=(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/tensorflow/math.py","lineNumber":181,"sourceCode":"def rfft(x, fft_length=None):\n    if fft_length is not None:\n        fft_length = [fft_length]\n    complex_output = tf.signal.rfft(x, fft_length=fft_length)\n    return tf.math.real(complex_output), tf.math.imag(complex_output)\n\n\ndef irfft(x, fft_length=None):\n    complex_input = _get_complex_tensor_from_tuple(x)\n    if fft_length is not None:\n        fft_length = [fft_length]\n    return tf.signal.irfft(complex_input, fft_length)\n\n\ndef stft(\n    x, sequence_length, sequence_stride, fft_length, window=\"hann\", center=True\n):\n    if standardize_dtype(x.dtype) not in {\"float32\", \"float64\"}:\n        raise TypeError(\n            \"Invalid input type. Expected `float32` or `float64`. \"\n            f\"Received: input type={x.dtype}\"\n        )\n    if fft_length < sequence_length:\n        raise ValueError(\n            \"`fft_length` must equal or larger than `sequence_length`. \"\n            f\"Received: sequence_length={sequence_length}, \"\n            f\"fft_length={fft_length}\"\n        )\n    if isinstance(window, str):\n        if window not in {\"hann\", \"hamming\"}:\n            raise ValueError(\n                \"If a string is passed to `window`, it must be one of \"\n                f'`\"hann\"`, `\"hamming\"`. Received: window={window}'\n            )\n    x = convert_to_tensor(x)\n\n    if center:","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/tensorflow/math.py#L163-L199","documentation":"Raised by the dtype guard at the top of keras/src/backend/tensorflow/math.py stft: tf.signal.stft only accepts float32 or float64 input. The input tensor has some other dtype (e.g. float16, int, or bfloat16), so a TypeError is raised before framing/windowing begins.","triggerScenarios":"Thrown at keras/src/backend/tensorflow/math.py:181 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Cast x to float32 or float64 before calling stft: x = tf.cast(x, 'float32')","Avoid passing bfloat16/fp16 activations directly; convert them first","Check dtype policies (mixed precision) that may cause fp16 inputs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}