ptwm_core::quantize
ptwm_core::quantize
Shared PMF quantization + validation primitives. Used by PerGroupCodebook (PGC, alphabet=16, total=256) and Order1ScaleAC (alphabet=256, total=4096); each codec passes its own total constant.
ptwm_core::quantize
crates/ptwm-core/src/quantize.rs:1mod quantizeShared PMF quantization + validation primitives. Used by PerGroupCodebook (PGC, alphabet=16, total=256) and Order1ScaleAC (alphabet=256, total=4096); each codec passes its own `total` constant.
ptwm_core::quantize::ORDER1_QUANT_TOTAL
crates/ptwm-core/src/quantize.rs:8pub const ORDER1_QUANT_TOTALptwm_core::quantize::PGC_QUANT_TOTAL
crates/ptwm-core/src/quantize.rs:7pub const PGC_QUANT_TOTALptwm_core::quantize::quantize_pmf
crates/ptwm-core/src/quantize.rs:13pub fn quantize_pmf(raw_counts: &[u32], total: u32) -> Vec<u16>Quantize raw integer counts into u16 counts summing to exactly `total`. Applies Laplace +1 smoothing first (every entry becomes ≥1, guaranteeing no zero-prob symbol on encode/decode).
ptwm_core::quantize::validate_pmf_sum
crates/ptwm-core/src/quantize.rs:50pub fn validate_pmf_sum(pmf: &[u16], expected_total: u32, ctx: &str) -> Result<(), PtwmCoreError>Verify that quantized counts sum to exactly `expected_total` AND that every entry is at least 1. Returns a `CodecDecode` error on mismatch (state-load corruption tripwire). Zero-probability symbols are forbidden because the range coder divides by `prob` on encode and would loop forever on `prob == 0` during decode renormalization.