#[non_exhaustive]pub struct FactorizeResult<T: TensorIndex> {
pub left: T,
pub right: T,
pub bond_index: T::Index,
pub singular_values: Option<Vec<f64>>,
pub rank: usize,
/* private fields */
}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, TensorContractionLike, IdxTensor,
};
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 = IdxTensor::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_pair(&result.right).unwrap();
assert!(tensor.distance(&recovered).unwrap() < 1e-12);
// SVD provides singular values
assert!(result.singular_values.is_some());
assert_eq!(result.singular_values.as_ref().unwrap().len(), result.rank);This struct is #[non_exhaustive]: it carries a private
algorithm-internal field (incremental_qr_state) that downstream crates
cannot see or set, so external construction always goes through
FactorizeResult::new rather than struct-literal syntax.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.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.
Implementations§
Source§impl<T: TensorIndex> FactorizeResult<T>
impl<T: TensorIndex> FactorizeResult<T>
Sourcepub fn new(
left: T,
right: T,
bond_index: T::Index,
singular_values: Option<Vec<f64>>,
rank: usize,
) -> Self
pub fn new( left: T, right: T, bond_index: T::Index, singular_values: Option<Vec<f64>>, rank: usize, ) -> Self
Construct a factorization result without an algorithm-private update state.
§Arguments
left- Left factor tensor.right- Right factor tensor.bond_index- Index connecting the two factors.singular_values- Singular values when the result came from SVD.rank- Number of columns in the factorization.
§Returns
A factorization result suitable for public factorization APIs. Native incremental QR callers attach their private update state afterward.
§Examples
use tensor4all_core::{DynIndex, FactorizeResult, IdxTensor};
let left_index = DynIndex::new_dyn(1);
let bond = DynIndex::new_bond(1).unwrap();
let left = IdxTensor::from_dense(vec![left_index.clone(), bond.clone()], vec![1.0]).unwrap();
let right = IdxTensor::from_dense(vec![bond.clone()], vec![2.0]).unwrap();
let result = FactorizeResult::new(left, right, bond, None, 1);
assert_eq!(result.rank, 1);Trait Implementations§
Source§impl<T: Clone + TensorIndex> Clone for FactorizeResult<T>
impl<T: Clone + TensorIndex> Clone for FactorizeResult<T>
Source§fn clone(&self) -> FactorizeResult<T>
fn clone(&self) -> FactorizeResult<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
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