pub struct Config {
pub bound: ErrorBound,
pub order: DigitOrder,
pub pad: PadPolicy,
pub gavish_donoho: bool,
pub max_rank: usize,
pub residual_only: bool,
}Expand description
Encoder configuration.
Fields§
§bound: ErrorBoundError target.
order: DigitOrderDigit order of the tensorization.
pad: PadPolicyPadding policy for non-power-of-two axes.
gavish_donoho: boolCap ranks at the Gavish–Donoho threshold of each unfolding.
max_rank: usizeHard rank cap.
residual_only: boolMax-abs only: skip the TT candidates and code the field as the sparse
residual stream alone (the f = 0 candidate; cheap, wins on sparse
peaky data).
Implementations§
Source§impl Config
impl Config
Sourcepub fn new(bound: ErrorBound) -> Self
pub fn new(bound: ErrorBound) -> Self
Defaults (Morton, mixed radix, no GD, rank cap 1024) for a bound.
Examples found in repository?
examples/roundtrip.rs (line 23)
9fn main() {
10 let (h, w) = (128, 128);
11 let x: Vec<f32> = (0..h * w)
12 .map(|k| {
13 let (i, j) = ((k / w) as f32, (k % w) as f32);
14 (i * 0.05).sin() * (j * 0.03).cos() + 0.1 * (i * j * 1e-3).sin()
15 })
16 .collect();
17
18 for bound in [
19 ErrorBound::MaxAbs(1e-3),
20 ErrorBound::Rmse(1e-4),
21 ErrorBound::Psnr(60.0),
22 ] {
23 let (bytes, stats) = encode_f32(&x, &[h, w], &Config::new(bound));
24 let Decoded::F32 { data, .. } = decode(&bytes).expect("decode") else {
25 unreachable!("encoded f32")
26 };
27 let max_abs = x
28 .iter()
29 .zip(&data)
30 .map(|(a, b)| (a - b).abs() as f64)
31 .fold(0.0, f64::max);
32 let rmse = (x
33 .iter()
34 .zip(&data)
35 .map(|(a, b)| ((a - b) as f64).powi(2))
36 .sum::<f64>()
37 / x.len() as f64)
38 .sqrt();
39 println!(
40 "{bound:?}: {} bytes ({:.3} bits/value, ratio {:.1}x), max|err| {max_abs:.2e}, rmse {rmse:.2e}",
41 stats.bytes,
42 stats.bits_per_value,
43 32.0 / stats.bits_per_value
44 );
45 if let ErrorBound::MaxAbs(e) = bound {
46 assert!(max_abs <= e);
47 }
48 }
49}More examples
examples/qtt.rs (line 92)
32fn parse(args: &[String], data: &[f32]) -> (Vec<usize>, Config) {
33 let mut dims = None;
34 let mut bound = None;
35 let mut order = DigitOrder::Morton;
36 let mut pad = PadPolicy::MixedRadix;
37 let mut gd = false;
38 let mut max_rank = 512;
39 let range = {
40 let (a, b) = data
41 .iter()
42 .fold((f32::INFINITY, f32::NEG_INFINITY), |(a, b), &v| {
43 (a.min(v), b.max(v))
44 });
45 (b - a) as f64
46 };
47 let mut i = 0;
48 while i < args.len() {
49 let v = || args.get(i + 1).cloned().unwrap_or_else(|| usage());
50 match args[i].as_str() {
51 "--dims" => {
52 dims = Some(
53 v().split('x')
54 .map(|s| s.parse().unwrap())
55 .collect::<Vec<usize>>(),
56 )
57 }
58 "--psnr" => bound = Some(ErrorBound::Psnr(v().parse().unwrap())),
59 "--rmse" => bound = Some(ErrorBound::Rmse(v().parse().unwrap())),
60 "--max-abs" => bound = Some(ErrorBound::MaxAbs(v().parse().unwrap())),
61 "--max-rel" => bound = Some(ErrorBound::MaxAbs(v().parse::<f64>().unwrap() * range)),
62 "--order" => {
63 order = match v().as_str() {
64 "morton" => DigitOrder::Morton,
65 "row" => DigitOrder::RowMajor,
66 _ => usage(),
67 }
68 }
69 "--pad" => {
70 pad = match v().as_str() {
71 "mixed" => PadPolicy::MixedRadix,
72 "pow2" => PadPolicy::Pow2,
73 _ => usage(),
74 }
75 }
76 "--max-rank" => max_rank = v().parse().unwrap(),
77 "--gd" => {
78 gd = true;
79 i += 1;
80 continue;
81 }
82 _ => usage(),
83 }
84 i += 2;
85 }
86 let dims = dims.unwrap_or_else(|| vec![data.len()]);
87 assert_eq!(
88 dims.iter().product::<usize>(),
89 data.len(),
90 "--dims does not match file size"
91 );
92 let mut cfg = Config::new(bound.unwrap_or_else(|| usage()));
93 cfg.order = order;
94 cfg.pad = pad;
95 cfg.gavish_donoho = gd;
96 cfg.max_rank = max_rank;
97 (dims, cfg)
98}Trait Implementations§
impl Copy for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
impl<T> Boilerplate for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more