{"record":{"id":"2d0956826487d551","repo":"jax-ml/jax","slug":"order-must-be-either-little-or-big","errorCode":null,"errorMessage":"'order' must be either 'little' or 'big'","messagePattern":"'order' must be either 'little' or 'big'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":8697,"sourceCode":"\n    >>> a = jnp.array([[1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0],\n    ...                [0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]])\n    >>> vals = jnp.packbits(a, axis=1)\n    >>> vals\n    Array([[212, 150],\n           [ 69, 207]], dtype=uint8)\n\n    The inverse of ``packbits`` is provided by :func:`~jax.numpy.unpackbits`:\n\n    >>> jnp.unpackbits(vals, axis=1)\n    Array([[1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0],\n           [0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1]], dtype=uint8)\n  \"\"\"\n  arr = util.ensure_arraylike(\"packbits\", a)\n  if not (issubdtype(arr.dtype, np.integer) or issubdtype(arr.dtype, np.bool_)):\n    raise TypeError('Expected an input array of integer or boolean data type')\n  if bitorder not in ['little', 'big']:\n    raise ValueError(\"'order' must be either 'little' or 'big'\")\n  arr = lax.ne(arr, lax._const(arr, 0)).astype('uint8')\n  bits = arange(8, dtype='uint8')\n  if bitorder == 'big':\n    bits = bits[::-1]\n  if axis is None:\n    arr = ravel(arr)\n    axis = 0\n  arr = swapaxes(arr, axis, -1)\n\n  remainder = arr.shape[-1] % 8\n  if remainder:\n    arr = lax.pad(arr, np.uint8(0),\n                  (arr.ndim - 1) * [(0, 0, 0)] + [(0, 8 - remainder, 0)])\n\n  arr = arr.reshape(arr.shape[:-1] + (arr.shape[-1] // 8, 8))\n  bits = expand_dims(bits, tuple(range(arr.ndim - 1)))\n  packed = (arr << bits).sum(-1).astype('uint8')\n  return swapaxes(packed, axis, -1)","sourceCodeStart":8679,"sourceCodeEnd":8715,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L8679-L8715","documentation":"Raised by jnp.packbits when the bitorder argument is anything other than 'little' or 'big', which are the only two bit-ordering conventions supported.","triggerScenarios":"jnp.packbits(a, bitorder='msb') or 'MSB'/'big-endian'; passing an enum/None; typos like 'Big'.","commonSituations":"Confusing bitorder with byteorder terminology from struct/numpy dtype ('>'/'<'); case-sensitive values from config files; default None from an optional parameter threaded through.","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'"],"exampleFix":"// before\njnp.packbits(a, bitorder='big-endian')\n// after\njnp.packbits(a, bitorder='big')\n","handlingStrategy":"validation","validationCode":"assert bitorder in ('little', 'big'), \"bitorder must be 'little' or 'big'\"","typeGuard":"def valid_bitorder(order):\n    return order in ('little', 'big')","tryCatchPattern":null,"preventionTips":["Use exact lowercase strings 'little'/'big'","Normalize config values at load time","Don't confuse with numpy byteorder chars like '>' '<'"],"tags":["jax","packbits","bitorder","argument-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}