{"record":{"id":"5c9eb9d26150356a","repo":"jax-ml/jax","slug":"mode-mode-r-not-understood-must-be-raise-wr","errorCode":null,"errorMessage":"mode={mode!r} not understood. Must be 'raise', 'wrap', or 'clip'","messagePattern":"mode=(.+?) not understood\\. Must be 'raise', 'wrap', or 'clip'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":4980,"sourceCode":"  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.choose is not supported.\")\n  a, *choices = util.ensure_arraylike_tuple('choose', (a, *choices))\n  if not issubdtype(a.dtype, np.integer):\n    raise ValueError(\"`a` array must be integer typed\")\n  N = len(choices)\n\n  if mode == 'raise':\n    arr: Array = core.concrete_or_error(asarray, a,\n      \"The error occurred because jnp.choose was jit-compiled\"\n      \" with mode='raise'. Use mode='wrap' or mode='clip' instead.\")\n    if reductions.any((arr < 0) | (arr >= N)):\n      raise ValueError(\"invalid entry in choice array\")\n  elif mode == 'wrap':\n    arr = asarray(a) % N\n  elif mode == 'clip':\n    arr = clip(a, 0, N - 1)\n  else:\n    raise ValueError(f\"mode={mode!r} not understood. Must be 'raise', 'wrap', or 'clip'\")\n\n  arr, *choices = broadcast_arrays(arr, *choices)\n  return array(choices)[(arr,) + indices(arr.shape, sparse=True)]\n\n\ndef _atleast_nd(x: ArrayLike, n: int) -> Array:\n  m = np.ndim(x)\n  return lax.broadcast(x, (1,) * (n - m)) if m < n else asarray(x)\n\ndef _block(xs: ArrayLike | list[Any]) -> tuple[Array, int]:\n  if isinstance(xs, tuple):\n    raise ValueError(\"jax.numpy.block does not allow tuples, got {}\"\n                     .format(xs))\n  elif isinstance(xs, list):\n    if len(xs) == 0:\n      raise ValueError(\"jax.numpy.block does not allow empty list arguments\")\n    xs_tup, depths = unzip2([_block(x) for x in xs])\n    if any(d != depths[0] for d in depths[1:]):","sourceCodeStart":4962,"sourceCodeEnd":4998,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L4962-L4998","documentation":"jnp.choose only accepts mode in {'raise', 'wrap', 'clip'}. Any other string (or non-string) value for the mode keyword raises this ValueError with the offending value echoed back. This matches NumPy's choose modes but JAX adds tracer-related constraints on 'raise' under jit.","triggerScenarios":"Calling jnp.choose(a, choices, mode='Raise') (wrong case), mode='fill' (not a real mode), or passing mode=None. Also typos like mode='wrapp'.","commonSituations":"Copy-paste from code that used np.take (which uses mode='wrap'/'clip' too but also 'raise' semantics differently), or assumption that NumPy's error message strings differ.","solutions":["Use exactly one of 'raise', 'wrap', or 'clip' (lowercase)","If under jit, prefer 'wrap' or 'clip' since 'raise' needs concrete values"],"exampleFix":"// before\nout = jnp.choose(a, ch, mode='fill')\n// after\nout = jnp.choose(a, ch, mode='clip')","handlingStrategy":"validation","validationCode":"assert mode in ('raise', 'wrap', 'clip'), f\"bad mode: {mode}\"","typeGuard":"def is_valid_choose_mode(mode) -> bool:\n    return mode in ('raise', 'wrap', 'clip')","tryCatchPattern":null,"preventionTips":["Keep mode strings in a module-level constant or Literal type","Validate mode once at config parse time"],"tags":["jax","choose","invalid-argument","valueerror"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}