{"record":{"id":"4078d94c82a73312","repo":"keras-team/keras","slug":"shapes-are-incompatible-for-associative-scan-inter-4078d9","errorCode":null,"errorMessage":"Shapes are incompatible for associative_scan interleaving. a.shape[{axis}]={a.shape[axis]}, b.shape[{axis}]={b.shape[axis]}","messagePattern":"Shapes are incompatible for associative_scan interleaving\\. a\\.shape\\[(.+?)\\]=(.+?), b\\.shape\\[(.+?)\\]=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/numpy/ops/core.py","lineNumber":240,"sourceCode":"        c = f(a, b)\n        c_flat = tree.flatten(c)\n        return c_flat\n\n    num_elems = int(elems_flat[0].shape[axis])\n    if not all(int(elem.shape[axis]) == num_elems for elem in elems_flat[1:]):\n        raise ValueError(\n            \"Array inputs to associative_scan must have the same \"\n            \"first dimension. (saw: {})\".format(\n                [elem.shape for elem in elems_flat]\n            )\n        )\n\n    def _interleave(a, b, axis):\n        \"\"\"Given two Tensors of static shape, interleave them along axis.\"\"\"\n        if not (\n            a.shape[axis] == b.shape[axis] or a.shape[axis] == b.shape[axis] + 1\n        ):\n            raise ValueError(\n                \"Shapes are incompatible for associative_scan interleaving. \"\n                f\"a.shape[{axis}]={a.shape[axis]}, \"\n                f\"b.shape[{axis}]={b.shape[axis]}\"\n            )\n\n        # we want to get a: [a1, a2], b: [b1, b2]\n        # to a: [a1, 0, a2, 0], b: [0, b1, 0, b2]\n        a_shape = list(a.shape)\n        a_shape[axis] = a.shape[axis] * 2 - 1\n\n        b_shape = list(b.shape)\n        b_shape[axis] = b.shape[axis] * 2 - 1\n\n        a_dil = np.zeros(a_shape)\n        np.copyto(slice_along_axis(a_dil, 0, None, 2, axis), a)\n        b_dil = np.zeros(b_shape)\n        np.copyto(slice_along_axis(b_dil, 0, None, 2, axis), b)\n","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/numpy/ops/core.py#L222-L258","documentation":"Internal shape check inside the NumPy `associative_scan`'s `_interleave` helper. While combining partial scan results, it interleaves two tensors a and b along the scan axis; for odd lengths the two operands may differ by exactly one element along that axis, otherwise the interleave is geometrically impossible. If a.shape[axis] and b.shape[axis] differ by more than one (or disagree when they must match), this error reports both sizes and the axis.","triggerScenarios":"Thrown at keras/src/backend/numpy/ops/core.py:240 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure scan inputs have lengths that are compatible with the halving scheme (differences of at most one element per level) — typically satisfied by any valid associative_scan input, so treat this as a sign of malformed custom elems","Check that the combine function `f` returns tensors with the same shapes as its inputs, preserving the scan-axis length","Report the issue upstream if it occurs with well-formed inputs, as it indicates an internal inconsistency in the divide-and-conquer path"],"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"}