jax-ml/jax · error · ValueError
'order' must be either 'little' or 'big'
Error message
'order' must be either 'little' or 'big'
What it means
packbits assembles bits into bytes with a defined bit order; only 'little' and 'big' endian are implemented. It fires when the bitorder argument is any other string.
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.
Understand the failure class
Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.
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/2d0956826487d551.
Report an issue: GitHub.
Appendix: 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)