{"record":{"id":"04ebfaeead893c0a","repo":"keras-team/keras","slug":"input-should-have-rank-1-received-input-shape-04ebfa","errorCode":null,"errorMessage":"Input should have rank >= 1. Received: input.shape = {real.shape}","messagePattern":"Input should have rank >= 1\\. Received: input\\.shape = (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/math.py","lineNumber":518,"sourceCode":"        if not isinstance(x, (tuple, list)) or len(x) != 2:\n            raise ValueError(\n                \"Input `x` should be a tuple of two tensors - real and \"\n                f\"imaginary. Received: x={x}\"\n            )\n\n        real, imag = x\n        # Both real and imaginary parts should have the same shape.\n        if real.shape != imag.shape:\n            raise ValueError(\n                \"Input `x` should be a tuple of two tensors - real and \"\n                \"imaginary. Both the real and imaginary parts should have the \"\n                f\"same shape. Received: x[0].shape = {real.shape}, \"\n                f\"x[1].shape = {imag.shape}\"\n            )\n\n        # We are calculating 1D FFT. Hence, rank >= 1.\n        if len(real.shape) < 1:\n            raise ValueError(\n                f\"Input should have rank >= 1. \"\n                f\"Received: input.shape = {real.shape}\"\n            )\n\n        # The axis along which we are calculating FFT should be fully-defined.\n        m = real.shape[-1]\n        if m is None:\n            raise ValueError(\n                f\"Input should have its last dimension fully-defined. \"\n                f\"Received: input.shape = {real.shape}\"\n            )\n\n        return (\n            KerasTensor(shape=real.shape, dtype=real.dtype),\n            KerasTensor(shape=imag.shape, dtype=imag.dtype),\n        )\n\n    def call(self, x):","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/math.py#L500-L536","documentation":"keras.ops.fft computes a 1D FFT over the last axis, so every input (real and imaginary part) must have at least one dimension. A rank-0 scalar tensor fails this check in compute_output_spec.","triggerScenarios":"Passing scalar tensors like keras.ops.cast(3.0, 'float32') as either part; aggressive reduction (sum/mean without keepdims) collapsing the signal to a scalar before the FFT.","commonSituations":"Preprocessing that aggregates the time series (mean/variance normalization) forgetting keepdims=True, or unit tests using trivial scalar placeholders.","solutions":["Keep at least a length-1 vector: reshape scalars to shape (1,) or (n,) before the call","Audit reductions upstream (mean/sum/max) and add keepdims=True","Use keras.ops.expand_dims(x, -1) if the signal may be scalar"],"exampleFix":"# before\nsig = keras.ops.mean(x)  # scalar\nout = keras.ops.fft((sig, keras.ops.zeros_like(sig)))\n# after\nsig = keras.ops.mean(x, keepdims=True)  # shape (1,)\nout = keras.ops.fft((sig, keras.ops.zeros_like(sig)))","handlingStrategy":"validation","validationCode":"assert len(real.shape) >= 1 and len(imag.shape) >= 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use keepdims=True on reductions feeding FFTs","Expand dims defensively for possibly-scalar signals"],"tags":["keras","fft","rank","shape"],"backgroundTag":"invalid-tensor-rank","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}