Skip to main content

CompositeTensor

Struct CompositeTensor 

Source
pub struct CompositeTensor(/* private fields */);
Expand description

A composite tensor that has other tensors as children, similar to a tensor network.

Implementations§

Source§

impl CompositeTensor

Source

pub fn new<T>(tensors: T) -> Self
where T: TensorList,

Creates a new composite tensor with the given nested tensors.

Source

pub fn as_tensor(&self) -> &Tensor

Returns a reference to this composite tensor as a Tensor.

Source

pub fn tensors(&self) -> &Vec<Tensor>

Returns the children tensors.

§Examples
let bond_dims = FxHashMap::from_iter([(0, 17), (1, 19), (2, 8)]);
let v1 = LeafTensor::new_from_map(vec![0, 1], &bond_dims);
let v2 = LeafTensor::new_from_map(vec![1, 2], &bond_dims);
let tn = CompositeTensor::new(vec![v1.clone(), v2.clone()]);
for (tensor, ref_tensor) in std::iter::zip(tn.tensors(), vec![v1, v2]){
   assert_abs_diff_eq!(tensor, ref_tensor.as_tensor());
}
Source

pub fn tensor(&self, i: TensorIndex) -> &Tensor

Get the ith tensor.

§Examples
let bond_dims = FxHashMap::from_iter([(0, 17), (1, 19), (2, 8)]);
let v1 = LeafTensor::new_from_map(vec![0, 1], &bond_dims);
let v2 = LeafTensor::new_from_map(vec![1, 2], &bond_dims);
let tn = CompositeTensor::new(vec![v1.clone(), v2]);
assert_abs_diff_eq!(tn.tensor(0), v1.as_tensor());
Source

pub fn into_tensors(self) -> Vec<Tensor>

Converts this tensor into the vec of its children.

Source

pub fn is_empty(&self) -> bool

Returns true if the tensor is empty. This means, it doesn’t have any children.

§Examples
let tensor = CompositeTensor::default();
assert_eq!(tensor.is_empty(), true);
Source

pub fn len(&self) -> usize

Returns the number of direct children of this tensor.

§Examples
let tensor = CompositeTensor::default();
assert_eq!(tensor.len(), 0);
Source

pub fn nested_tensor(&self, nested_indices: &[usize]) -> &Tensor

Gets a nested Tensor based on the nested_indices which specify the index of the tensor at each level of the hierarchy.

§Examples
let bond_dims = FxHashMap::from_iter([(0, 17), (1, 19), (2, 8), (3, 2), (4, 1)]);
let mut v1 = LeafTensor::new_from_map(vec![0, 1], &bond_dims);
let mut v2 = LeafTensor::new_from_map(vec![1, 2], &bond_dims);
let mut v3 = LeafTensor::new_from_map(vec![2, 3], &bond_dims);
let mut v4 = LeafTensor::new_from_map(vec![3, 4], &bond_dims);
let tn1 = CompositeTensor::new(vec![v1, v2]);
let tn2 = CompositeTensor::new(vec![v3.clone(), v4]);
let nested_tn = CompositeTensor::new(vec![tn1, tn2]);

let found = nested_tn.nested_tensor(&[1, 0]);
assert!(found.is_leaf());
let found = found.as_leaf().unwrap();
assert_eq!(found.legs(), v3.legs());
Source

pub fn total_num_tensors(&self) -> usize

Returns the total number of leaf tensors in the hierarchy.

Source

pub fn push_tensor<T>(&mut self, tensor: T)
where T: Into<Tensor>,

Pushes additional tensor into this composite tensor.

Source

pub fn push_tensors<T>(&mut self, tensors: T)
where T: TensorList,

Pushes additional tensors into this composite tensor.

Source

pub fn reserve(&mut self, additional: usize)

Reserves space for at least additional more tensors to be pushed to this composite tensor without reallocation.

Source

pub fn is_connected(&self) -> bool

Returns whether all tensors inside this tensor are connected. This currently requires all children to be leaf tensors.

§Examples
// Create a tensor network with two connected tensors
let bond_dims = FxHashMap::from_iter([(0, 17), (1, 19), (2, 8), (3, 5)]);
let v1 = LeafTensor::new_from_map(vec![0, 1], &bond_dims);
let v2 = LeafTensor::new_from_map(vec![1, 2], &bond_dims);
let mut tn = CompositeTensor::new(vec![v1, v2]);
assert!(tn.is_connected());

// Introduce a new tensor that is not connected
let v3 = LeafTensor::new_from_map(vec![3], &bond_dims);
tn.push_tensor(v3);
assert!(!tn.is_connected());
Source

pub fn external_tensor(&self) -> LeafTensor

Get output legs after tensor contraction.

Trait Implementations§

Source§

impl AbsDiffEq for CompositeTensor

Source§

type Epsilon = f64

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of [AbsDiffEq::abs_diff_eq].
Source§

impl Clone for CompositeTensor

Source§

fn clone(&self) -> CompositeTensor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompositeTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CompositeTensor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CompositeTensor

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<CompositeTensor> for Tensor

Source§

fn from(value: CompositeTensor) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for CompositeTensor

Source§

fn eq(&self, other: &CompositeTensor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CompositeTensor

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TransparentWrapper<TensorRepr> for CompositeTensor

§

fn wrap(s: Inner) -> Self
where Self: Sized,

Convert the inner type into the wrapper type.
§

fn wrap_ref(s: &Inner) -> &Self

Convert a reference to the inner type into a reference to the wrapper type.
§

fn wrap_mut(s: &mut Inner) -> &mut Self

Convert a mutable reference to the inner type into a mutable reference to the wrapper type.
§

fn wrap_slice(s: &[Inner]) -> &[Self]
where Self: Sized,

Convert a slice to the inner type into a slice to the wrapper type.
§

fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]
where Self: Sized,

Convert a mutable slice to the inner type into a mutable slice to the wrapper type.
§

fn peel(s: Self) -> Inner
where Self: Sized,

Convert the wrapper type into the inner type.
§

fn peel_ref(s: &Self) -> &Inner

Convert a reference to the wrapper type into a reference to the inner type.
§

fn peel_mut(s: &mut Self) -> &mut Inner

Convert a mutable reference to the wrapper type into a mutable reference to the inner type.
§

fn peel_slice(s: &[Self]) -> &[Inner]
where Self: Sized,

Convert a slice to the wrapped type into a slice to the inner type.
§

fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]
where Self: Sized,

Convert a mutable slice to the wrapped type into a mutable slice to the inner type.
Source§

impl StructuralPartialEq for CompositeTensor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyExt for T
where T: Any + ?Sized,

§

fn downcast_ref<T>(this: &Self) -> Option<&T>
where T: Any,

Attempts to downcast this to T behind reference
§

fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>
where T: Any,

Attempts to downcast this to T behind mutable reference
§

fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Any,

Attempts to downcast this to T behind Rc pointer
§

fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Any,

Attempts to downcast this to T behind Arc pointer
§

fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Any,

Attempts to downcast this to T behind Box pointer
§

fn downcast_move<T>(this: Self) -> Option<T>
where T: Any, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

§

type Err = NoError

The error type produced by a failed conversion.
§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

§

fn coerce_box_to(self: Box<X>) -> Box<T>

§

fn coerce_ref_to(&self) -> &T

§

fn coerce_mut_to(&mut self) -> &mut T

§

impl<T, Dst> ConvAsUtil<Dst> for T

§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
§

impl<T> ConvUtil for T

§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<I, T> TransparentWrapperAlloc<I> for T
where T: TransparentWrapper<I> + ?Sized, I: ?Sized,

§

fn wrap_vec(s: Vec<Inner>) -> Vec<Self>
where Self: Sized,

Convert a vec of the inner type into a vec of the wrapper type.
§

fn wrap_box(s: Box<Inner>) -> Box<Self>

Convert a box to the inner type into a box to the wrapper type.
§

fn wrap_rc(s: Rc<Inner>) -> Rc<Self>

Convert an Rc to the inner type into an Rc to the wrapper type.
§

fn wrap_arc(s: Arc<Inner>) -> Arc<Self>

Convert an Arc to the inner type into an Arc to the wrapper type.
§

fn peel_vec(s: Vec<Self>) -> Vec<Inner>
where Self: Sized,

Convert a vec of the wrapper type into a vec of the inner type.
§

fn peel_box(s: Box<Self>) -> Box<Inner>

Convert a box to the wrapper type into a box to the inner type.
§

fn peel_rc(s: Rc<Self>) -> Rc<Inner>

Convert an Rc to the wrapper type into an Rc to the inner type.
§

fn peel_arc(s: Arc<Self>) -> Arc<Inner>

Convert an Arc to the wrapper type into an Arc to the inner type.
§

impl<Src> TryFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<Src> ValueFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,