Expand description
Arithmetic Coder implementation for rwkvzip.
This implements a binary arithmetic coder with 32-bit precision, optimized for neural network probability distributions. The implementation is mathematically rigorous to ensure lossless compression.
§Information-Theoretic Properties
- Uses base-2 arithmetic for bitstream output
- 32-bit precision prevents underflow for typical neural network distributions
- Integer CDF quantization uses 30-bit total (2^30) to minimize quantization error
- Probability floor ensures no symbol has zero probability (critical for lossless)
Structs§
- Arithmetic
Decoder - Binary arithmetic decoder.
- Arithmetic
Encoder - Binary arithmetic encoder.
Constants§
- CDF_
TOTAL - Total count for CDF quantization (2^30 for high precision)
Functions§
- p_min
- Returns the minimum probability floor for symbols. P_MIN = 2 * 2^(-(PRECISION-2)) = 2^(-(PRECISION-3)) = 2^(-29)
- quantize_
pdf_ to_ cdf - Quantize probability distribution to integer CDF.
- quantize_
pdf_ to_ cdf_ inplace - Quantize PDF to integer CDF using a reusable output buffer.
- softmax_
pdf - Compute softmax PDF without floor (for entropy calculation).
- softmax_
pdf_ floor - Compute softmax PDF with probability floor.
- softmax_
pdf_ floor_ inplace - In-place version of softmax_pdf_floor to avoid allocations.
- softmax_
pdf_ inplace