jax-ml/jax · error · NotImplementedError
The 'out' argument to jnp.argmax is not supported.
Error message
The 'out' argument to jnp.argmax is not supported.
What it means
jnp.argmax does not support the out parameter because JAX arrays are immutable and jit-traced functions cannot write into caller-provided buffers, unlike NumPy.
Source
Thrown at jax/_src/numpy/lax_numpy.py:8273
smallest index is returned.
Examples:
>>> x = jnp.array([1, 3, 5, 4, 2])
>>> jnp.argmax(x)
Array(2, dtype=int32)
>>> x = jnp.array([[1, 3, 2],
... [5, 4, 1]])
>>> jnp.argmax(x, axis=1)
Array([1, 0], dtype=int32)
>>> jnp.argmax(x, axis=1, keepdims=True)
Array([[1],
[0]], dtype=int32)
"""
arr = util.ensure_arraylike("argmax", a)
if out is not None:
raise NotImplementedError("The 'out' argument to jnp.argmax is not supported.")
return _argmax(arr, None if axis is None else operator.index(axis),
keepdims=bool(keepdims))
@api.jit(static_argnames=('axis', 'keepdims'), inline=True)
def _argmax(a: Array, axis: int | None = None, keepdims: bool = False) -> Array:
if axis is None:
dims = list(range(np.ndim(a)))
a = ravel(a)
axis = 0
else:
dims = [axis]
if a.shape[axis] == 0:
raise ValueError("attempt to get argmax of an empty sequence")
# TODO(phawkins): use an int64 index if the dimension is large enough.
result = lax.argmax(a, _canonicalize_axis(axis, a.ndim), int)
return expand_dims(result, dims) if keepdims else result
View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Remove the out argument and use the returned array: idx = jnp.argmax(a)
- If a buffer must be filled, do buf = jnp.argmax(a) or buf.at[...].set(...) at the call site
- Strip out from kwargs before forwarding to jnp
Example fix
// before jnp.argmax(a, axis=0, out=buf) // after buf = jnp.argmax(a, axis=0)
Defensive patterns
Strategy: validation
Validate before calling
kwargs.pop('out', None) # before forwarding to jnp.argmax Prevention
- Never pass out= to jnp reductions
- Strip out in generic wrappers
- Use return-value assignment instead of buffers
When it happens
Trigger: Calling jnp.argmax(a, out=buf), usually by porting NumPy code that reused an output buffer for performance.
Common situations: Copy-pasted NumPy micro-optimized code using out= to avoid allocations; generic wrappers that forward **kwargs including out.
Related errors
- The 'out' argument to jnp.argmin is not supported.
- The 'out' argument to jnp.nanargmax is not supported.
- The 'out' argument to jnp.nanargmin is not supported.
- The 'out' argument to jnp.compress is not supported.
- 'order' argument to argsort is not supported.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/bfa24c105a6c4f4e.
Report an issue: GitHub.