{"record":{"id":"5fe9e751631cc2ea","repo":"keras-team/keras","slug":"input-x-should-be-a-tuple-of-two-tensors-real-5fe9e7","errorCode":null,"errorMessage":"Input `x` should be a tuple of two tensors - real and imaginary. Both the real and imaginary parts should have the same shape. Received: x[0].shape = {real.shape}, x[1].shape = {imag.shape}","messagePattern":"Input `x` should be a tuple of two tensors - real and imaginary\\. Both the real and imaginary parts should have the same shape\\. Received: x\\[0\\]\\.shape = (.+?), x\\[1\\]\\.shape = (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/math.py","lineNumber":509,"sourceCode":"    if any_symbolic_tensors((x,)):\n        return ExtractSequences(sequence_length, sequence_stride).symbolic_call(\n            x\n        )\n    return backend.math.extract_sequences(x, sequence_length, sequence_stride)\n\n\nclass FFT(Operation):\n    def compute_output_spec(self, x):\n        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. \"","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/math.py#L491-L527","documentation":"The real and imaginary tensors passed to keras.ops.fft must have identical shapes; the op computes element-wise 1D FFT over the last axis for both parts. Symbolic shape inference raises when x[0].shape != x[1].shape.","triggerScenarios":"Passing real of shape (2, 8) and imag of shape (2, 16); slicing real and imag from differently padded sequences; one part having an extra leading batch dimension.","commonSituations":"Building real/imag parts in separate preprocessing steps (e.g. imag computed from a different window length), or broadcasting bugs where one branch adds a dimension. Partially-defined (None) dims also compare unequal during functional-model building.","solutions":["Print/inspect x[0].shape and x[1].shape right before the call and reconcile padding/windowing so they match","Recompute both parts from the same source tensor (e.g. real=x.real, imag=x.imag of one complex array)","In functional models, ensure both inputs flow from the same upstream layer so symbolic shapes stay identical","Fix slicing: use the same index range for both parts"],"exampleFix":"# before\nout = keras.ops.fft((real[:, :8], imag[:, :16]))\n# after\nout = keras.ops.fft((real[:, :8], imag[:, :8]))","handlingStrategy":"validation","validationCode":"assert real.shape == imag.shape, f'{real.shape} != {imag.shape}'","typeGuard":null,"tryCatchPattern":"try:\n    out = keras.ops.fft((real, imag))\nexcept ValueError as e:\n    if 'same shape' in str(e):\n        imag = pad_to(imag, real.shape)\n        out = keras.ops.fft((real, imag))\n    else:\n        raise","preventionTips":["Derive both parts from the same tensor","Log shapes in preprocessing when handling variable-length data"],"tags":["keras","fft","shape-mismatch","input-validation"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}