{"record":{"id":"ffaab03c48fda001","repo":"keras-team/keras","slug":"in-axis-axis-a-is-out-of-bounds-for-array-of","errorCode":null,"errorMessage":"In `axis`, axis {a} is out of bounds for array of dimension {result_dims}","messagePattern":"In `axis`, axis (.+?) is out of bounds for array of dimension (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/jax/sparse.py","lineNumber":43,"sourceCode":"        - The broadcast dimensions: list of dimensions not in `axis`, for use as\n          the `broadcast_dimensions` argument of `broadcast_in_dim`.\n    \"\"\"\n    if axis is None:\n        raise ValueError(\"Received `None` value for `axis`\")\n    if isinstance(axis, int):\n        axis = (axis,)\n    # Check uniqueness.\n    if len(set(axis)) != len(axis):\n        raise ValueError(f\"Repeated axis in `axis`: {axis}\")\n    result_dims = len(input_shape)\n    if insert_dims:\n        result_dims += len(axis)\n\n    # Resolve negative values.\n    canonical_axis = []\n    for a in axis:\n        if not -result_dims <= a < result_dims:\n            raise ValueError(\n                f\"In `axis`, axis {a} is out of bounds for array \"\n                f\"of dimension {result_dims}\"\n            )\n        if a < 0:\n            a = a + result_dims\n        canonical_axis.append(a)\n\n    # Check uniqueness again after resolving negative values.\n    if len(set(canonical_axis)) != len(canonical_axis):\n        raise ValueError(f\"Repeated axis in `axis`: {canonical_axis}\")\n    canonical_axis = sorted(canonical_axis)\n\n    # Compute output shape.\n    output_shape = list(input_shape)\n    for i in canonical_axis:\n        if insert_dims:\n            output_shape.insert(i, 1)\n        else:","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/jax/sparse.py#L25-L61","documentation":"Bounds check in the JAX sparse backend's axis helper while resolving each entry of the axis argument: an index a must satisfy -result_dims <= a < result_dims, where result_dims is the input rank (plus len(axis) when insert_dims=True). Out-of-range indices (e.g. axis=3 on a 2D tensor) are rejected.","triggerScenarios":"Thrown at keras/src/backend/jax/sparse.py:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use indices in [0, ndim) or the equivalent negative form [-ndim, 0)","Print x.ndim (or the passed input_shape) and correct the axis values to fit that rank","For expand_dims-style calls remember the valid range extends by the number of inserted dims"],"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"}