jax-ml/jax · error · ValueError
'order' must be either 'little' or 'big'
Error message
'order' must be either 'little' or 'big'
What it means
Raised by jnp.packbits when the bitorder argument is anything other than 'little' or 'big', which are the only two bit-ordering conventions supported.
Source
Thrown at jax/_src/numpy/lax_numpy.py:8697
>>> a = jnp.array([[1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0],
... [0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]])
>>> vals = jnp.packbits(a, axis=1)
>>> vals
Array([[212, 150],
[ 69, 207]], dtype=uint8)
The inverse of ``packbits`` is provided by :func:`~jax.numpy.unpackbits`:
>>> jnp.unpackbits(vals, axis=1)
Array([[1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0],
[0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]], dtype=uint8)
"""
arr = util.ensure_arraylike("packbits", a)
if not (issubdtype(arr.dtype, np.integer) or issubdtype(arr.dtype, np.bool_)):
raise TypeError('Expected an input array of integer or boolean data type')
if bitorder not in ['little', 'big']:
raise ValueError("'order' must be either 'little' or 'big'")
arr = lax.ne(arr, lax._const(arr, 0)).astype('uint8')
bits = arange(8, dtype='uint8')
if bitorder == 'big':
bits = bits[::-1]
if axis is None:
arr = ravel(arr)
axis = 0
arr = swapaxes(arr, axis, -1)
remainder = arr.shape[-1] % 8
if remainder:
arr = lax.pad(arr, np.uint8(0),
(arr.ndim - 1) * [(0, 0, 0)] + [(0, 8 - remainder, 0)])
arr = arr.reshape(arr.shape[:-1] + (arr.shape[-1] // 8, 8))
bits = expand_dims(bits, tuple(range(arr.ndim - 1)))
packed = (arr << bits).sum(-1).astype('uint8')
return swapaxes(packed, axis, -1)View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use exactly 'little' or 'big' (case-sensitive)
- Map external config values to the allowed strings, defaulting sensibly
- Add a validation/default at the config layer: order = order or 'big'
Example fix
// before jnp.packbits(a, bitorder='big-endian') // after jnp.packbits(a, bitorder='big')
Defensive patterns
Strategy: validation
Validate before calling
assert bitorder in ('little', 'big'), "bitorder must be 'little' or 'big'" Type guard
def valid_bitorder(order):
return order in ('little', 'big') Prevention
- Use exact lowercase strings 'little'/'big'
- Normalize config values at load time
- Don't confuse with numpy byteorder chars like '>' '<'
When it happens
Trigger: jnp.packbits(a, bitorder='msb') or 'MSB'/'big-endian'; passing an enum/None; typos like 'Big'.
Common situations: Confusing bitorder with byteorder terminology from struct/numpy dtype ('>'/'<'); case-sensitive values from config files; default None from an optional parameter threaded through.
Related errors
- `compute_on`'s compute_type argument must be a string.
- Argument '{x}' of type '{typ}' is not a valid JAX type
- Argument '{arg}' of type {type(arg)} is not a valid JAX type
- Expected kind to be a dtype, string, or tuple; got {kind=}
- at least one array or dtype is required
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/2d0956826487d551.
Report an issue: GitHub.