Module ac

Module ac 

Source
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§

ArithmeticDecoder
Binary arithmetic decoder.
ArithmeticEncoder
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