{"record":{"id":"0cbe14c7be148181","repo":"jax-ml/jax","slug":"fill-value-argument-to-indexed-get-must-be-a-sca","errorCode":null,"errorMessage":"fill_value argument to indexed get() must be a scalar","messagePattern":"fill_value argument to indexed get\\(\\) must be a scalar","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":1217,"sourceCode":"  return result\n\n\n# TODO(phawkins): re-enable jit after fixing excessive recompilation for\n# slice indexes (e.g., slice(0, 5, None), slice(10, 15, None), etc.).\n# @api.jit(static_argnums=(1, 2))\ndef _gather(arr, dynamic_idx, *, treedef, indices_are_sorted,\n            unique_indices, mode, fill_value, normalize_indices):\n  parsed_idx = tree_unflatten(treedef, dynamic_idx)\n  indexer = parsed_idx.to_gather(core.typeof(arr).sharding,\n                                 normalize_indices=normalize_indices)\n  jnp_error._check_precondition_oob_gather(arr.shape, indexer.gather_indices)\n  y = arr\n\n  if fill_value is not None:\n    core.concrete_or_error(None, fill_value,\n                           \"fill_value argument to indexed get()\")\n    if np.ndim(fill_value) != 0:\n      raise ValueError(\"fill_value argument to indexed get() must be a scalar\")\n    if isinstance(fill_value, np.ndarray):\n      fill_value = fill_value.item()\n\n  if indexer.scalar_bool_dims:\n    y = lax.expand_dims(y, indexer.scalar_bool_dims)\n\n  # Avoid calling gather if the slice shape is empty, both as a fast path and to\n  # handle cases like zeros(0)[array([], int32)].\n  if core.is_empty_shape(indexer.slice_shape):\n    return lax.full_like(y, 0, shape=indexer.slice_shape,\n                         sharding=indexer.slice_sharding)\n\n  # We avoid generating a gather when indexer.gather_indices.size is empty.\n  if not core.is_empty_shape(indexer.gather_indices.shape):\n    y = slicing.gather(\n        y, indexer.gather_indices, indexer.dnums, indexer.gather_slice_shape,\n        unique_indices=unique_indices or indexer.unique_indices,\n        indices_are_sorted=indices_are_sorted or indexer.indices_are_sorted,","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L1199-L1235","documentation":"For indexed get() with a fill_value (drop/fill out-of-bounds mode), the fill value must be a 0-dimensional scalar so a single fill element can be scattered for all OOB positions.","triggerScenarios":"Calling arr.at[idx].get(mode='fill', fill_value=jnp.array([0, 0])) or passing a shape-(1,) array/list as fill_value instead of a scalar.","commonSituations":"Passing a list like [0] or a 1-element array instead of 0; constructing fill values dynamically with an unexpected leading dimension.","solutions":["Pass a scalar: fill_value=0 or fill_value=jnp.asarray(0.0, dtype=arr.dtype)","Squeeze/convert arrays: fill_value=jnp.asarray(fv).reshape(()) or use .item()"],"exampleFix":"// before\ny = x.at[idx].get(mode='fill', fill_value=[0])\n// after\ny = x.at[idx].get(mode='fill', fill_value=0)","handlingStrategy":"type-guard","validationCode":"import numpy as np\nassert np.ndim(fill_value) == 0, 'fill_value must be scalar'","typeGuard":"def is_scalar_fill(f) -> bool:\n    import numpy as np\n    return np.ndim(f) == 0","tryCatchPattern":null,"preventionTips":["Pass plain scalars (0, -1, nan) as fill_value","Convert arrays with .item() or reshape(()) before use"],"tags":["jax","indexing","fill-value","scalar"],"backgroundTag":"non-scalar-fill-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}