Skip to main content

Module interp

Module interp 

Source
Expand description

SZ3-style multilevel interpolation codec for pointwise (max-abs) bounds, and for RMSE / PSNR targets through rate control of the bound (encode_rmse_f32).

Aimed at loose bounds on smooth fields, where the wavelet codec’s fixed overheads (centroids, band predictors, outlier map) dominate a tiny stream.

  1. Prediction. The grid is refined coarse to fine: at stride s (a power of two, largest first) and for each axis k in turn, the points whose k coordinate is an odd multiple of s are predicted from already reconstructed points at ±s, ±3s along k — cubic (−1, 9, 9, −1)/16 inside, one-sided quadratics near an edge, linear or copy at the boundary. Each level picks linear or cubic by a trial cost (one header bit per level).
  2. Quantization. q = round((x − x̃)/2b_ℓ) with a level bound b_ℓ = b / min(α^(ℓ−1), β) ≤ b (finer prediction anchors, as in QoZ); the reconstruction x̃ + 2b_ℓq is cast to f32 and checked against b exactly as the decoder will compute it, and any point that fails (or overflows the code range) is escaped and stored raw. (α, β) is picked from a small preset list by actual stream size.
  3. Coding. Adaptive binary range coding (crate::abac): a zero flag with contexts (level, log₂ of the local neighbour difference in quanta, previous symbol class), a sign bit per level and an adaptive Elias-gamma magnitude.

Prediction is f64 arithmetic on f32 reconstructions in a fixed order, so encoder and decoder agree bit for bit.

Constants§

FAST_TUNE
Fast-mode preset index into the (α, β) table (the one most often kept by encode_f32 on the seen fields).
MAGIC
Stream magic of the interpolation codec.

Functions§

decode
Decode an interpolation stream.
encode_f32
Encode x (row-major, shape dims) with |x − x̂| ≤ b everywhere, trying each (α, β) preset and keeping the smallest stream.
encode_fast_f32
encode_f32 with a single (α, β) preset (FAST_TUNE).
encode_psnr_f32
encode_rmse_f32 at PSNR = 20 log₁₀(range / RMSE) dB.
encode_rmse_f32
Encode for an RMSE target (rmse absolute): the bound b is rate controlled per (α, β) preset — the largest b whose reconstruction meets the squared-error budget, by secant steps on log SSE(log b) inside a bisection bracket — and the smallest stream wins. The stream is an ordinary max-abs stream at that b; the target is checked on the exact reconstruction the decoder computes.