pub enum AllowedPairs<'a> {
All,
Specified(&'a [(usize, usize)]),
}Expand description
Specifies which tensor pairs are allowed to contract.
This enum controls which tensor pairs can have their indices contracted in multi-tensor contraction operations. This is useful for tensor networks where the graph structure determines which tensors are connected.
§Example
use tensor4all_core::{AllowedPairs, DynIndex, TensorDynLen, TensorLike};
let i = DynIndex::new_dyn(2);
let j = DynIndex::new_dyn(2);
let k = DynIndex::new_dyn(2);
let a = TensorDynLen::from_dense(
vec![i.clone(), j.clone()],
vec![1.0, 0.0, 0.0, 1.0],
)?;
let b = TensorDynLen::from_dense(
vec![j.clone(), k.clone()],
vec![1.0, 2.0, 3.0, 4.0],
)?;
let c = TensorDynLen::from_dense(vec![k.clone()], vec![1.0, 10.0])?;
let tensor_refs: Vec<&TensorDynLen> = vec![&a, &b, &c];
let all = <TensorDynLen as TensorLike>::contract(&tensor_refs, AllowedPairs::All)?;
let edges = vec![(0, 1), (1, 2)];
let specified =
<TensorDynLen as TensorLike>::contract(&tensor_refs, AllowedPairs::Specified(&edges))?;
assert_eq!(all.dims(), vec![2]);
assert!(all.sub(&specified)?.maxabs() < 1e-12);Variants§
All
All tensor pairs are allowed to contract.
Indices with matching IDs across any two tensors will be contracted.
This is the default behavior, equivalent to ITensor’s * operator.
Specified(&'a [(usize, usize)])
Only specified tensor pairs are allowed to contract.
Each pair is (tensor_idx_a, tensor_idx_b) into the input tensor slice.
Indices are only contracted if they belong to an allowed pair.
This is useful for tensor networks where the graph structure determines which tensors are connected (e.g., TreeTN edges).
Trait Implementations§
Source§impl<'a> Clone for AllowedPairs<'a>
impl<'a> Clone for AllowedPairs<'a>
Source§fn clone(&self) -> AllowedPairs<'a>
fn clone(&self) -> AllowedPairs<'a>
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 moreSource§impl<'a> Debug for AllowedPairs<'a>
impl<'a> Debug for AllowedPairs<'a>
impl<'a> Copy for AllowedPairs<'a>
Auto Trait Implementations§
impl<'a> Freeze for AllowedPairs<'a>
impl<'a> RefUnwindSafe for AllowedPairs<'a>
impl<'a> Send for AllowedPairs<'a>
impl<'a> Sync for AllowedPairs<'a>
impl<'a> Unpin for AllowedPairs<'a>
impl<'a> UnwindSafe for AllowedPairs<'a>
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