{"record":{"id":"f1f0d40b2ddf03e8","repo":"jax-ml/jax","slug":"jax-numpy-quantile-does-not-support-overwrite-inpu","errorCode":null,"errorMessage":"jax.numpy.quantile does not support overwrite_input=True or out != None","messagePattern":"jax\\.numpy\\.quantile does not support overwrite_input=True or out != None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":2446,"sourceCode":"    Array([2.25, 4.5 , 6.75], dtype=float32)\n\n    Computing the quartiles using nearest-value interpolation:\n\n    >>> jnp.quantile(x, q, method='nearest')\n    Array([2., 4., 7.], dtype=float32)\n\n    Computing weighted quantiles:\n\n    >>> x = jnp.array([1, 2, 3, 4, 5])\n    >>> weights = jnp.array([1, 1, 2, 1, 1])\n    >>> jnp.quantile(x, 0.5, weights=weights, method='inverted_cdf')\n    Array(3., dtype=float32)\n  \"\"\"\n  a, q = ensure_arraylike(\"quantile\", a, q)\n  if weights is not None:\n    weights = ensure_arraylike(\"quantile\", weights)\n  if overwrite_input or out is not None:\n    raise ValueError(\"jax.numpy.quantile does not support overwrite_input=True \"\n                     \"or out != None\")\n  return _quantile(a, q, axis, method, keepdims, False, weights)\n\n\n@export\n@api.jit(static_argnames=('axis', 'overwrite_input', 'keepdims', 'method'))\ndef nanquantile(a: ArrayLike, q: ArrayLike, axis: int | tuple[int, ...] | None = None,\n                out: None = None, overwrite_input: bool = False, method: str = \"linear\",\n                keepdims: bool = False, *, weights: ArrayLike | None = None) -> Array:\n  \"\"\"Compute the quantile of the data along the specified axis, ignoring NaNs.\n\n  JAX implementation of :func:`numpy.nanquantile`.\n\n  Args:\n    a: N-dimensional array input.\n    q: scalar or 1-dimensional array specifying the desired quantiles. ``q``\n      should contain floating-point values between ``0.0`` and ``1.0``.\n    axis: optional axis or tuple of axes along which to compute the quantile","sourceCodeStart":2428,"sourceCodeEnd":2464,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L2428-L2464","documentation":"jnp.quantile does not support overwrite_input=True (a NumPy memory optimization that mutates the input during partitioning) or an out= buffer, because JAX arrays are immutable. Either raises ValueError.","triggerScenarios":"Calling jnp.quantile(a, q, overwrite_input=True) or jnp.quantile(a, q, out=buf); jnp.median forwards here too, so np.median(x, overwrite_input=True)-style ports also fail.","commonSituations":"Porting NumPy percentile/median code that used overwrite_input to save memory on large arrays; kwargs passthrough shims.","solutions":["Remove overwrite_input and out from the call","If memory matters, operate on jnp.sort/argsort explicitly or rely on jit fusion"],"exampleFix":"// before\nnp.percentile(a, 50, overwrite_input=True)\n// after\njnp.percentile(a, 50)","handlingStrategy":"validation","validationCode":"def quantile_kwargs(overwrite_input=False, out=None, **kw):\n    assert not overwrite_input and out is None, 'jax quantile: out/overwrite_input unsupported'\n    return kw\njnp.quantile(a, q, **quantile_kwargs(**user_kwargs))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip overwrite_input/out in NumPy adapters","Never assume memory-mutation flags carry over to JAX"],"tags":["jax","numpy","quantile","out-argument","overwrite-input"],"backgroundTag":"unsupported-out-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}