Expand description
The bit-accounted QTT codec.
§Encoder
One pass at absolute quantization step Δ runs TT-SVD left to right
with error feedback: core k is computed from the remainder that is
least-squares optimal given the already-quantized prefix, quantized, and
only then is the remainder refit against it.
Let P_{k−1} be the quantized prefix (rows = prefix indices, cols =
r_{k−1}), H = P_{k−1}ᵀP_{k−1} its Gram, and C the LS remainder
(X = (P_{k−1}⊗I)·C + E, E ⊥ range). In the metric H̃ = H ⊗ I_{n_k}:
- eigendecompose the whitened Gram of
C→ singular valuesσ_jand anH̃-orthonormal coreG(the canonical left-orthogonal gauge, now w.r.t. the true prefix); - quantize column
jofGwith stepΔ / σ̂_j,σ̂_j = 2^{e_j/4},e_j = round(4 log₂ σ_j)— the equal-slope rule: perturbing columnjcostsσ_j²·step²/12per entry, so every entry ends up with the same distortionΔ²/12as an entry of the last core. Columns that round to all zeros are dropped, so ranks are chosen by rate–distortion, not by a separate tolerance; - refit
C ← (QᵀH̃Q)⁻¹ QᵀH̃ C,H ← QᵀH̃Q, and add the exact discarded energy‖C‖²_H̃ − ‖proj‖²to the running SSE.
The last core (the LS remainder, carrying the norm) is quantized with step
Δ; its error eᵀH̃e is added too. The SSE is therefore known exactly at
encode time without reconstructing the tensor (the error pieces are
mutually orthogonal). Δ is then found by a bracketed log–log secant search
on that SSE.
§Error modes
ErrorBound::Rmse/ErrorBound::Psnr(range-normalised): the searched SSE is followed by an actual decode; if the true RMSE on the original (unpadded) cells exceeds the target the search is redone.ErrorBound::MaxAbs(SZ-style pointwise boundb): the TT is coded at an RMSE targetf·bfor a fewf, the encoder decodes its own stream, and every cell with|x − x̂| > bgets a correctionk = round((x−x̂)/2b)(then|x − (x̂+2bk)| ≤ b), stored as entropy-coded position gaps + values (a raw-value escape covers float-cast edge cases). Thefgiving the smallest total stream wins.
§Bit account
The stream is self-describing: magic, dtype, digit order, padding policy,
shape, Δ, all ranks, all per-column step exponents, every frequency
table, all payloads, the residual stream. bytes.len() is the size.
Structs§
- Config
- Encoder configuration.
- Encode
Stats - What the encoder did, for benchmarking.
Enums§
- Decoded
- A decoded array.
- Dtype
- Sample type of the original array (decoded output has the same type).
- Error
Bound - Error target.
Functions§
- decode
- Decode a stream produced by
encode_f32/encode_f64. - encode_
f32 - Encode an f32 array of shape
dims(row-major). - encode_
f64 - Encode an f64 array of shape
dims(row-major).