{"record":{"id":"4833b3508f646617","repo":"keras-team/keras","slug":"shift-and-axis-must-be-broadcastable-to-the-sa","errorCode":null,"errorMessage":"`shift` and `axis` must be broadcastable to the same length. Received: shift={shift}, axis={axis}","messagePattern":"`shift` and `axis` must be broadcastable to the same length\\. Received: shift=(.+?), axis=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/backend_utils.py","lineNumber":454,"sourceCode":"        return (value,)\n    return value\n\n\ndef normalize_shift_and_axis(shift, axis):\n    \"\"\"Normalize `shift` and `axis` arguments of `roll` to the same length.\n\n    Mirrors numpy's behavior of broadcasting a scalar (or length-1\n    sequence) `shift`/`axis` against the other argument. Accepts ints,\n    lists, tuples, and array-likes (e.g. numpy arrays).\n    \"\"\"\n    shifts = list(to_tuple_or_list(shift))\n    axes = list(to_tuple_or_list(axis))\n    if len(shifts) == 1:\n        shifts = shifts * len(axes)\n    if len(axes) == 1:\n        axes = axes * len(shifts)\n    if len(shifts) != len(axes):\n        raise ValueError(\n            \"`shift` and `axis` must be broadcastable to the same length. \"\n            f\"Received: shift={shift}, axis={axis}\"\n        )\n    return shifts, axes\n\n\n### Code for ops.vectorize() used for TF and torch backends.\n\n# See http://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html\n_DIMENSION_NAME = r\"\\w+\"\n_CORE_DIMENSION_LIST = \"(?:{0:}(?:,{0:})*)?\".format(_DIMENSION_NAME)\n_ARGUMENT = rf\"\\({_CORE_DIMENSION_LIST}\\)\"\n_ARGUMENT_LIST = \"{0:}(?:,{0:})*\".format(_ARGUMENT)\n_SIGNATURE = \"^{0:}->{0:}$\".format(_ARGUMENT_LIST)\n\n\ndef _vectorize_parse_gufunc_signature(\n    signature,","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/backend_utils.py#L436-L472","documentation":"Guard in normalize_shift_and_axis (used by ops.roll): after a scalar shift or axis is broadcast against the other sequence, the two lists still differ in length, so there is no one-to-one mapping between each shift amount and the axis it applies to.","triggerScenarios":"Thrown at keras/src/backend/common/backend_utils.py:454 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Give shift and axis matching lengths, e.g. shift=(1, 2), axis=(0, 1).","Use a scalar for one side: shift=1 with axis=(0, 1) broadcasts the shift to both axes.","For distinct shifts per axis, list every axis explicitly instead of relying on broadcasting."],"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"}