pub struct FactorizeResult<T: TensorLike> {
pub left: T,
pub right: T,
pub bond_index: T::Index,
pub singular_values: Option<Vec<f64>>,
pub rank: usize,
}Expand description
Result of tensor factorization.
Contains the two factors, the bond index connecting them, and metadata
about the decomposition. The original tensor can be recovered (up to
truncation error) by contracting left and right along bond_index.
§Examples
use tensor4all_core::{factorize, DynIndex, FactorizeOptions, TensorDynLen};
let i = DynIndex::new_dyn(3);
let j = DynIndex::new_dyn(4);
let data: Vec<f64> = (0..12).map(|x| x as f64).collect();
let tensor = TensorDynLen::from_dense(vec![i.clone(), j.clone()], data).unwrap();
let result = factorize(&tensor, &[i.clone()], &FactorizeOptions::svd()).unwrap();
// Contracting left * right recovers the original tensor
let recovered = result.left.contract(&result.right);
assert!(tensor.distance(&recovered) < 1e-12);
// SVD provides singular values
assert!(result.singular_values.is_some());
assert_eq!(result.singular_values.as_ref().unwrap().len(), result.rank);Fields§
§left: TLeft factor tensor.
right: TRight factor tensor.
bond_index: T::IndexBond index connecting left and right factors.
singular_values: Option<Vec<f64>>Singular values (only for SVD).
rank: usizeRank of the factorization.
Trait Implementations§
Source§impl<T: Clone + TensorLike> Clone for FactorizeResult<T>
impl<T: Clone + TensorLike> Clone for FactorizeResult<T>
Source§fn clone(&self) -> FactorizeResult<T>
fn clone(&self) -> FactorizeResult<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for FactorizeResult<T>
impl<T> RefUnwindSafe for FactorizeResult<T>
impl<T> Send for FactorizeResult<T>
impl<T> Sync for FactorizeResult<T>
impl<T> Unpin for FactorizeResult<T>
impl<T> UnsafeUnpin for FactorizeResult<T>
impl<T> UnwindSafe for FactorizeResult<T>
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
Casts
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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>
Converts
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>
Converts
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