jax-ml/jax · error · ValueError
must satisfy <=start<=
Error message
{start=} must satisfy {-a_ndim}<=start<={a_ndim} What it means
jnp.rollaxis reinserts the moved axis at position start, which must lie in the closed range [-ndim, ndim] to be canonicalizable. It fires when start is outside that range for the given array rank.
Solutions
- Clamp or validate start within [-a.ndim, a.ndim] before calling
- Compute start adaptively from a.ndim rather than hardcoding
- Prefer jnp.moveaxis(a, source, destination) which has clearer semantics and its own validation
Example fix
// before jnp.rollaxis(a, axis=1, start=4) # a.ndim == 3 // after jnp.moveaxis(a, source=1, destination=2) # explicit, validated destination
Defensive patterns
Strategy: validation
Validate before calling
start = int(start)
n = jnp.ndim(a)
if not (-n <= start <= n): raise ValueError(f'start {start} out of range for ndim {n}') Type guard
def valid_rollaxis_start(a, start):
n = jnp.ndim(a)
return -n <= int(start) <= n Prevention
- Derive start from a.ndim, not constants
- Prefer jnp.moveaxis for clarity
- Validate axis params from config before use
When it happens
Trigger: jnp.rollaxis(a, axis=0, start=5) on a 3-D array; start derived from user config or loop arithmetic exceeding the rank; start passed as a traced value is also rejected earlier by concrete_or_error.
Common situations: Hardcoded start values breaking after arrays are reshaped to lower rank; looping axis reordering with unclamped counters; mixing up rollaxis(start) vs moveaxis destination conventions.
Related errors
- a_scale and b_scale must both be present or absent.
- args argument to jax.scipy.optimize.minimize must be a…
- Argument ' ' of type is not a valid JAX type.
- Argument ' ' of type ' ' is not a valid JAX type
- array() got multiple values for argument
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/c62d0665a688818b.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/numpy/lax_numpy.py:8626
Roll axis 1 to the end of the array:
>>> jnp.rollaxis(a, 1, a.ndim).shape
(2, 4, 5, 3)
Equivalent of these two with :func:`~jax.numpy.moveaxis`
>>> jnp.moveaxis(a, 2, 0).shape
(4, 2, 3, 5)
>>> jnp.moveaxis(a, 1, -1).shape
(2, 4, 5, 3)
"""
a = util.ensure_arraylike("rollaxis", a)
start = core.concrete_or_error(operator.index, start, "'start' argument of jnp.rollaxis()")
a_ndim = np.ndim(a)
axis = _canonicalize_axis(axis, a_ndim)
if not (-a_ndim <= start <= a_ndim):
raise ValueError(f"{start=} must satisfy {-a_ndim}<=start<={a_ndim}")
if start < 0:
start += a_ndim
if start > axis:
start -= 1
return moveaxis(a, axis, start)
@export
@api.jit(static_argnames=('axis', 'bitorder'))
def packbits(a: ArrayLike, axis: int | None = None, bitorder: str = "big") -> Array:
"""Pack array of bits into a uint8 array.
JAX implementation of :func:`numpy.packbits`
Args:
a: N-dimensional array of bits to pack.
axis: optional axis along which to pack bits. If not specified, ``a`` will
be flattened.View on GitHub (pinned to 1e1c6a8fc0)