BitPacking.jl provides small bit-packed building blocks for Julia array code:
NArray,NVector, andNMatrixpack a static group of narrow values into one storage value.NarrowArray,NarrowVector, andNarrowMatrixview an array of packed groups as a logical array of values.NarrowTupleand@NarrowTuplepack heterogeneous isbits values, with optional padding fields.
Packages can extend BitPacking.bitwidth(::Type) for their own narrow scalar types.
using BitPacking
v = NVector(true, false, true, false, true, false, true, false)
Tuple(v) # (true, false, true, false, true, false, true, false)
reinterpret(UInt8, v) # 0x55x = Bool[1, 0, 1, 0, 1, 0, 1, 0]
packed = NarrowArray{Bool}(x)
copy(packed) == x # true
parent(packed) # Vector{NVector{Bool,8}}t = @NarrowTuple(0x12, true)
Tuple(t) # (0x12, true)
BitPacking.bitwidth(t) # 9using Pkg
Pkg.add("BitPacking")