{"record":{"id":"0a39c28a6b14d91a","repo":"jax-ml/jax","slug":"the-raise-mode-to-jnp-take-is-not-supported","errorCode":null,"errorMessage":"The 'raise' mode to jnp.take is not supported.","messagePattern":"The 'raise' mode to jnp\\.take is not supported\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":719,"sourceCode":"def _take(a, indices, axis: int | None = None, out=None, mode=None,\n          unique_indices=False, indices_are_sorted=False, fill_value=None):\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.take is not supported.\")\n  a, indices = util.ensure_arraylike(\"take\", a, indices)\n\n  if axis is None:\n    a = a.ravel()\n    axis_idx = 0\n  else:\n    axis_idx = canonicalize_axis(axis, np.ndim(a))\n\n  if mode is None or mode == \"fill\":\n    gather_mode = slicing.GatherScatterMode.FILL_OR_DROP\n    # lax.gather() does not support negative indices, so we wrap them here\n    indices = util._where(indices < 0, indices + a.shape[axis_idx], indices)\n  elif mode == \"raise\":\n    # TODO(phawkins): we have no way to report out of bounds errors yet.\n    raise NotImplementedError(\"The 'raise' mode to jnp.take is not supported.\")\n  elif mode == \"wrap\":\n    indices = ufuncs.mod(indices, lax._const(indices, a.shape[axis_idx]))\n    gather_mode = slicing.GatherScatterMode.PROMISE_IN_BOUNDS\n  elif mode == \"clip\":\n    gather_mode = slicing.GatherScatterMode.CLIP\n  else:\n    raise ValueError(f\"Invalid mode '{mode}' for np.take\")\n\n  index_dims = len(np.shape(indices))\n  slice_sizes = list(np.shape(a))\n  if slice_sizes[axis_idx] == 0:\n    if indices.size != 0:\n      raise IndexError(\"Cannot do a non-empty jnp.take() from an empty axis.\")\n    return a\n\n  if indices.size == 0:\n    out_shape = (slice_sizes[:axis_idx] + list(indices.shape) +\n                 slice_sizes[axis_idx + 1:])","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L701-L737","documentation":"NumPy's mode='raise' for np.take raises on out-of-bound indices at runtime; JAX cannot support this because errors cannot be raised from jit-compiled/XLA code, so it raises NotImplementedError up front.","triggerScenarios":"Calling jnp.take(a, indices, mode='raise').","commonSituations":"Ported NumPy code that relied on mode='raise' for bounds checking; debugging index computations in NumPy before moving to JAX.","solutions":["Use mode='clip' or mode='wrap' (or default fill behavior) instead","Validate indices in Python before the call: assert ((indices >= 0) & (indices < n)).all() when indices are concrete"],"exampleFix":"// before\ny = jnp.take(a, idx, mode='raise')\n// after\ny = jnp.take(a, idx, mode='clip')  # or validate idx beforehand","handlingStrategy":"fallback","validationCode":"assert mode != 'raise', \"mode='raise' unsupported; use 'clip' or 'wrap'\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Replace mode='raise' with clip/wrap plus explicit validation","Validate concrete indices in Python: ((idx >= 0) & (idx < n)).all()"],"tags":["jax","take","mode","bounds-check"],"backgroundTag":"unsupported-error-mode","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}