def packbits(
    a: ndarray, axis: int | None = None, bitorder: BitOrder = "big"
) -> ndarray:
    """

    Packs the elements of a binary-valued array into bits in a uint8 array.

    The result is padded to full bytes by inserting zero bits at the end.

    Parameters
    ----------
    a : array_like
        An array of integers or booleans whose elements should be packed to
        bits.
    axis : int, optional
        The dimension over which bit-packing is done.
        ``None`` implies packing the flattened array.
    bitorder : ``{"big", "little"}``, optional
        The order of the input bits. 'big' will mimic bin(val),
        ``[0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011``, 'little' will
        reverse the order so ``[1, 1, 0, 0, 0, 0, 0, 0] => 3``.
        Defaults to "big".

    Returns
    -------
    packed : ndarray
        Array of type uint8 whose elements represent bits corresponding to the
        logical (0 or nonzero) value of the input elements. The shape of
        `packed` has the same number of dimensions as the input (unless `axis`
        is None, in which case the output is 1-D).

    See Also
    --------
    numpy.packbits

    Availability
    --------
    Multiple GPUs, Multiple CPUs
    """

    if a.dtype.kind not in ("u", "i", "b"):
        raise TypeError(
            "Expected an input array of integer or boolean data type"
        )

    a, sanitized_axis = _sanitize_arguments(a, axis, bitorder)

    out_shape = tuple(
        (extent + 7) // 8 if dim == sanitized_axis else extent
        for dim, extent in enumerate(a.shape)
    )
    out = empty(out_shape, dtype="B")
    out._thunk.packbits(a._thunk, sanitized_axis, bitorder)

    return out


    Packs the elements of a binary-valued array into bits in a uint8 array.

    The result is padded to full bytes by inserting zero bits at the end.

    Parameters
    ----------
    a : array_like
        An array of integers or booleans whose elements should be packed to
        bits.
    axis : int, optional
        The dimension over which bit-packing is done.
        ``None`` implies packing the flattened array.
    bitorder : ``{"big", "little"}``, optional
        The order of the input bits. 'big' will mimic bin(val),
        ``[0, 0, 0, 0, 0, 0, 1, 1] => 3 = 0b00000011``, 'little' will
        reverse the order so ``[1, 1, 0, 0, 0, 0, 0, 0] => 3``.
        Defaults to "big".

    Returns
    -------
    packed : ndarray
        Array of type uint8 whose elements represent bits corresponding to the
        logical (0 or nonzero) value of the input elements. The shape of
        `packed` has the same number of dimensions as the input (unless `axis`
        is None, in which case the output is 1-D).

    See Also
    --------
    numpy.packbits

    Availability
    --------
    Multiple GPUs, Multiple CPUs
    
cupynumeric/_module/binary_bit_packing.py