tensor4all_treetn/linsolve/common/
options.rs1use crate::TruncationOptions;
4use tensor4all_core::SvdTruncationPolicy;
5
6#[derive(Debug, Clone)]
8pub struct LinsolveOptions {
9 pub nfullsweeps: usize,
13 pub truncation: TruncationOptions,
15 pub krylov_tol: f64,
17 pub krylov_maxiter: usize,
19 pub krylov_dim: usize,
21 pub a0: f64,
23 pub a1: f64,
25 pub convergence_tol: Option<f64>,
28}
29
30impl Default for LinsolveOptions {
31 fn default() -> Self {
32 Self {
33 nfullsweeps: 5,
34 truncation: TruncationOptions::default(),
35 krylov_tol: 1e-10,
36 krylov_maxiter: 100,
37 krylov_dim: 30,
38 a0: 0.0,
39 a1: 1.0,
40 convergence_tol: None,
41 }
42 }
43}
44
45impl LinsolveOptions {
46 pub fn new(nfullsweeps: usize) -> Self {
48 Self {
49 nfullsweeps,
50 ..Default::default()
51 }
52 }
53
54 pub fn with_nfullsweeps(mut self, nfullsweeps: usize) -> Self {
56 self.nfullsweeps = nfullsweeps;
57 self
58 }
59
60 pub fn with_truncation(mut self, truncation: TruncationOptions) -> Self {
62 self.truncation = truncation;
63 self
64 }
65
66 pub fn with_max_rank(mut self, max_rank: usize) -> Self {
68 self.truncation = self.truncation.with_max_rank(max_rank);
69 self
70 }
71
72 pub fn with_svd_policy(mut self, policy: SvdTruncationPolicy) -> Self {
74 self.truncation = self.truncation.with_svd_policy(policy);
75 self
76 }
77
78 pub fn with_krylov_tol(mut self, tol: f64) -> Self {
80 self.krylov_tol = tol;
81 self
82 }
83
84 pub fn with_krylov_maxiter(mut self, maxiter: usize) -> Self {
86 self.krylov_maxiter = maxiter;
87 self
88 }
89
90 pub fn with_krylov_dim(mut self, dim: usize) -> Self {
92 self.krylov_dim = dim;
93 self
94 }
95
96 pub fn with_coefficients(mut self, a0: f64, a1: f64) -> Self {
98 self.a0 = a0;
99 self.a1 = a1;
100 self
101 }
102
103 pub fn with_convergence_tol(mut self, tol: f64) -> Self {
105 self.convergence_tol = Some(tol);
106 self
107 }
108}
109
110#[cfg(test)]
111mod tests;