Entropy coding
Entropy helpers expose normalized-CDF range coding and probability-row rANS
coding through the native extension. They operate on dense MLX arrays rather
than sparse tensors.
Warning
Entropy coding helpers are provisional in this release line. The Python
signatures are public, but encoded byte-stream compatibility is not yet a
stable cross-version storage contract. Use them for experiments and
controlled pipelines, not long-lived file formats.
Probability inputs are row-major (N, S) arrays where S is the symbol
alphabet size. Symbol inputs are one-dimensional integer rows. Encoders return
Python bytes; decoders reconstruct an MLX integer array using the model
shape implied by the probability or CDF rows.
Related pages
-
mlx_lattice.ops.entropy.normalized_cdf(prob)[source]
Convert probability rows to int16 normalized CDF rows.
prob is a two-dimensional probability table with one distribution per
row. The returned CDF is suitable for the range-coding helpers in this
module.
- Return type:
array
- Parameters:
prob (array)
-
mlx_lattice.ops.entropy.range_encode(cdf, symbols)[source]
Encode symbols using normalized CDF rows and return a byte stream.
- Return type:
bytes
- Parameters:
cdf (array)
symbols (array)
-
mlx_lattice.ops.entropy.range_decode(cdf, stream)[source]
Decode symbols from a range-coded byte stream using CDF rows.
- Return type:
array
- Parameters:
cdf (array)
stream (bytes)
-
mlx_lattice.ops.entropy.range_encode_from_prob(prob, symbols)[source]
Normalize probability rows and range-encode symbols in one call.
- Return type:
bytes
- Parameters:
prob (array)
symbols (array)
-
mlx_lattice.ops.entropy.range_decode_from_prob(prob, stream)[source]
Normalize probability rows and range-decode symbols in one call.
- Return type:
array
- Parameters:
prob (array)
stream (bytes)
-
mlx_lattice.ops.entropy.rans_encode_from_prob(prob, symbols)[source]
Encode symbols with byte-oriented rANS from probability rows.
- Return type:
bytes
- Parameters:
prob (array)
symbols (array)
-
mlx_lattice.ops.entropy.rans_decode_from_prob(prob, stream)[source]
Decode symbols with byte-oriented rANS from probability rows.
- Return type:
array
- Parameters:
prob (array)
stream (bytes)