Skip to main content

Config

Struct Config 

Source
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: ErrorBound

Error target.

§order: DigitOrder

Digit order of the tensorization.

§pad: PadPolicy

Padding policy for non-power-of-two axes.

§gavish_donoho: bool

Cap ranks at the Gavish–Donoho threshold of each unfolding.

§max_rank: usize

Hard rank cap.

§residual_only: bool

Max-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

Source

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
Hide additional 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§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Config

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.