pub struct FactorizeOptions {
pub alg: FactorizeAlg,
pub canonical: Canonical,
pub max_bond_dim: Option<usize>,
pub svd_policy: Option<SvdTruncationPolicy>,
pub qr_rtol: Option<f64>,
}Expand description
Options for tensor factorization.
Controls the algorithm, canonical direction, and truncation parameters
for TensorFactorizationLike::factorize.
§Defaults
- Algorithm: SVD
- Canonical: Left (left factor is orthogonal)
- max_bond_dim:
None(no rank limit) - svd_policy:
None(uses the SVD global default policy) - qr_rtol:
None(uses the QR global default tolerance)
§Field Interactions
svd_policyis only valid forFactorizeAlg::SVD.qr_rtolis only valid forFactorizeAlg::QR.max_bond_dimis independent of the algorithm-specific tolerance settings.
§Examples
use tensor4all_core::{
factorize, Canonical, DynIndex, FactorizeOptions, IdxTensor,
};
let i = DynIndex::new_dyn(4);
let j = DynIndex::new_dyn(4);
let mut data = vec![0.0_f64; 16];
data[0] = 1.0; // rank-1 matrix
let tensor = IdxTensor::from_dense(vec![i.clone(), j.clone()], data).unwrap();
// SVD with an explicit policy
let opts = FactorizeOptions::svd()
.with_svd_policy(tensor4all_core::SvdTruncationPolicy::new(1e-10));
let result = factorize(&tensor, &[i.clone()], &opts).unwrap();
assert_eq!(result.rank, 1);
// QR with max-rank truncation
let opts = FactorizeOptions::qr().with_qr_rtol(1e-8).with_max_bond_dim(2);
let result = factorize(&tensor, &[i.clone()], &opts).unwrap();
assert!(result.rank <= 2);Fields§
§alg: FactorizeAlgFactorization algorithm to use.
canonical: CanonicalCanonical direction.
max_bond_dim: Option<usize>Maximum rank for truncation.
If None, no rank limit is applied.
svd_policy: Option<SvdTruncationPolicy>SVD truncation policy.
If None, uses the SVD global default.
qr_rtol: Option<f64>QR-specific relative tolerance.
If None, uses the QR global default.
Implementations§
Source§impl FactorizeOptions
impl FactorizeOptions
Sourcepub fn svd() -> Self
pub fn svd() -> Self
Create options for SVD factorization.
§Examples
use tensor4all_core::{FactorizeAlg, FactorizeOptions};
let opts = FactorizeOptions::svd();
assert_eq!(opts.alg, FactorizeAlg::SVD);Sourcepub fn qr() -> Self
pub fn qr() -> Self
Create options for QR factorization.
§Examples
use tensor4all_core::{FactorizeAlg, FactorizeOptions};
let opts = FactorizeOptions::qr();
assert_eq!(opts.alg, FactorizeAlg::QR);Sourcepub fn lu() -> Self
pub fn lu() -> Self
Create options for LU factorization.
§Examples
use tensor4all_core::{FactorizeAlg, FactorizeOptions};
let opts = FactorizeOptions::lu();
assert_eq!(opts.alg, FactorizeAlg::LU);Sourcepub fn ci() -> Self
pub fn ci() -> Self
Create options for CI factorization.
§Examples
use tensor4all_core::{FactorizeAlg, FactorizeOptions};
let opts = FactorizeOptions::ci();
assert_eq!(opts.alg, FactorizeAlg::CI);Sourcepub fn with_canonical(self, canonical: Canonical) -> Self
pub fn with_canonical(self, canonical: Canonical) -> Self
Set canonical direction.
§Examples
use tensor4all_core::{Canonical, FactorizeOptions};
let opts = FactorizeOptions::svd().with_canonical(Canonical::Right);
assert_eq!(opts.canonical, Canonical::Right);Sourcepub fn with_svd_policy(self, policy: SvdTruncationPolicy) -> Self
pub fn with_svd_policy(self, policy: SvdTruncationPolicy) -> Self
Set the SVD truncation policy.
§Examples
use tensor4all_core::{FactorizeOptions, SvdTruncationPolicy};
let opts = FactorizeOptions::svd().with_svd_policy(SvdTruncationPolicy::new(1e-8));
assert_eq!(opts.svd_policy, Some(SvdTruncationPolicy::new(1e-8)));Sourcepub fn with_qr_rtol(self, rtol: f64) -> Self
pub fn with_qr_rtol(self, rtol: f64) -> Self
Set the QR-specific relative tolerance.
§Examples
use tensor4all_core::FactorizeOptions;
let opts = FactorizeOptions::qr().with_qr_rtol(1e-8);
assert_eq!(opts.qr_rtol, Some(1e-8));Sourcepub fn with_max_bond_dim(self, max_bond_dim: usize) -> Self
pub fn with_max_bond_dim(self, max_bond_dim: usize) -> Self
Set maximum rank.
§Examples
use tensor4all_core::FactorizeOptions;
let opts = FactorizeOptions::svd().with_max_bond_dim(10);
assert_eq!(opts.max_bond_dim, Some(10));Sourcepub fn validate(&self) -> Result<(), FactorizeError>
pub fn validate(&self) -> Result<(), FactorizeError>
Validate that the selected fields make sense for the chosen algorithm.
Validates max bond dimension and explicit SVD policy thresholds through
the shared validate_svd_truncation_options seam, then checks the
algorithm/option compatibility rules.
§Errors
Returns FactorizeError::InvalidOptions if an algorithm is paired with
unsupported algorithm-specific truncation settings, or if max_bond_dim
is zero or an SVD policy threshold is non-finite/negative.
Trait Implementations§
Source§impl Clone for FactorizeOptions
impl Clone for FactorizeOptions
Source§fn clone(&self) -> FactorizeOptions
fn clone(&self) -> FactorizeOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FactorizeOptions
impl Debug for FactorizeOptions
Auto Trait Implementations§
impl Freeze for FactorizeOptions
impl RefUnwindSafe for FactorizeOptions
impl Send for FactorizeOptions
impl Sync for FactorizeOptions
impl Unpin for FactorizeOptions
impl UnsafeUnpin for FactorizeOptions
impl UnwindSafe for FactorizeOptions
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more