cram-codec
Error-bounded lossy compression of scientific f32/f64 arrays, in pure
Rust. Every byte of the stream counts toward the reported rate, encoding is
deterministic, and the error bound you ask for is the one you get.
Codecs (all decode through cram_codec::decode_any):
- QTT (
codec) — bit-accounted quantized tensor train: TT-SVD, error-feedback quantization, rate–distortion rank choice, static rANS. - Wavelet (
wavcodec) — CDF 9/7 integer lifting with a context-modelled coefficient coder; the strongest codec on most smooth fields. - Tucker (
tucker) and interpolation (interp) codecs. - tc-gpu / TCG3 (
gpuwav,gpuwav3) — brick-parallel wavelet streams laid out for GPU decoding, optionally with a learned coefficient model.
Part of tang.
Usage
use ;
// a 64×64 field
let x: = .map.collect;
// pointwise |x − x̂| ≤ 1e-3
let = encode_f32;
println!;
let F32 = decode.unwrap else ;
assert!;
Error bounds: ErrorBound::MaxAbs(e) (pointwise), ErrorBound::Rmse(r)
(absolute RMSE), ErrorBound::Psnr(db) (range-normalised PSNR).
Examples (cargo run --release -p cram-codec --example <name>):
roundtrip (the snippet above, all bounds), tc / qtt (encode and decode
raw little-endian .f32 files from the command line).
Features
default = []— CPU encoders and decoders; dependencies aretang-la,tang-optim,tang-exprandfaeronly.gpu—gpudec::GpuDecoder, a wgpu (WebGPU / Vulkan / Metal / DX12) decoder for tc-gpu and TCG3 streams. Its output is bit-identical to the CPU decoder: the kernels are integer only.GpuDecoder::newblocks on native;GpuDecoder::new_asyncis the constructor on wasm32.
WebAssembly
The decoders build for wasm32-unknown-unknown. The browser front end
(wasm-bindgen, WebGPU with a CPU fallback) is the cram-codec-wasm crate in
the tang repository;
it is not published to crates.io.
TCG3 streams can carry their own decoder as a checked tang-expr integer
program; see SHIPPED_DECODER.md.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option. Contributions are accepted under the same terms with a DCO sign-off (see CONTRIBUTING.md).