{"record":{"id":"1ac944dd56f913e3","repo":"jax-ml/jax","slug":"size-and-fill-value-arguments-cannot-be-used-in-th","errorCode":null,"errorMessage":"size and fill_value arguments cannot be used in three-term where function.","messagePattern":"size and fill_value arguments cannot be used in three-term where function\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":2798,"sourceCode":"    >>> x = jnp.arange(10)\n    >>> jnp.where(x > 4)\n    (Array([5, 6, 7, 8, 9], dtype=int32),)\n    >>> jnp.nonzero(x > 4)\n    (Array([5, 6, 7, 8, 9], dtype=int32),)\n\n    When ``x`` and ``y`` are provided, ``where`` selects between them based on\n    the specified condition:\n\n    >>> jnp.where(x > 4, x, 0)\n    Array([0, 0, 0, 0, 0, 5, 6, 7, 8, 9], dtype=int32)\n  \"\"\"\n  if x is None and y is None:\n    util.check_arraylike(\"where\", condition)\n    return nonzero(condition, size=size, fill_value=fill_value)\n  else:\n    util.check_arraylike(\"where\", condition, x, y)\n    if size is not None or fill_value is not None:\n      raise ValueError(\"size and fill_value arguments cannot be used in \"\n                       \"three-term where function.\")\n    if x is None or y is None:\n      raise ValueError(\"Either both or neither of the x and y arguments \"\n                       \"should be provided to jax.numpy.where, got \"\n                       f\"{x} and {y}.\")\n    return util._where(condition, x, y)\n\n\n@export\ndef select(\n    condlist: Sequence[ArrayLike],\n    choicelist: Sequence[ArrayLike],\n    default: ArrayLike = 0,\n) -> Array:\n  \"\"\"Select values based on a series of conditions.\n\n  JAX implementation of :func:`numpy.select`, implemented in terms\n  of :func:`jax.lax.select_n`","sourceCodeStart":2780,"sourceCodeEnd":2816,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L2780-L2816","documentation":"jnp.where has two modes: one-argument (condition only, returning indices via nonzero with size/fill_value) and three-argument (condition, x, y). The size and fill_value kwargs are only meaningful for the one-argument form and are rejected when x and y are provided.","triggerScenarios":"Calling jnp.where(cond, x, y, size=10) or jnp.where(cond, x, y, fill_value=-1).","commonSituations":"Copy-pasting size/fill_value from jitted nonzero-style code into a boolean-select where call; refactoring where(condition) into where(condition, x, y) but leaving the kwargs.","solutions":["Remove size and fill_value when using three-argument where","If you need a bounded-size index result, use jnp.where(cond) or jnp.nonzero(cond, size=..., fill_value=...) instead"],"exampleFix":"// before\njnp.where(cond, x, y, size=5)\n// after\njnp.where(cond, x, y)","handlingStrategy":"validation","validationCode":"if size is not None or fill_value is not None:\n    assert x is None and y is None, 'size/fill_value only valid for one-arg where'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep index-mode and select-mode where calls in separate helper functions","Review kwargs when refactoring where(condition) to where(condition, x, y)"],"tags":["jax","where","invalid-argument","api-misuse"],"backgroundTag":"invalid-argument-combination","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}