Skip to main content

LeafTensor

Struct LeafTensor 

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

A single leaf tensor.

Implementations§

Source§

impl LeafTensor

Source

pub fn new_from_map( legs: Vec<EdgeIndex>, bond_dims_map: &FxHashMap<EdgeIndex, u64>, ) -> Self

Constructs a leaf tensor with the given edge ids and a mapping of edge ids to corresponding bond dimensions.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 2), (2, 4), (3, 6)]);
let tensor = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
assert_eq!(tensor.legs(), &[1, 2, 3]);
assert_eq!(tensor.bond_dims(), &[2, 4, 6]);
Source

pub fn new_from_const(legs: Vec<EdgeIndex>, bond_dim: u64) -> Self

Constructs a leaf tensor with the given edge ids and the same bond dimension for all edges.

§Examples
let tensor = LeafTensor::new_from_const(vec![1, 2, 3], 2);
assert_eq!(tensor.legs(), &[1, 2, 3]);
assert_eq!(tensor.bond_dims(), &[2, 2, 2]);
Source

pub fn as_tensor(&self) -> &Tensor

Returns a reference to this leaf tensor as a Tensor.

Source

pub fn shallow_clone(&self) -> Self

Returns a new leaf tensor with the same legs and bond dimensions as this tensor, but without any data.

Source

pub fn legs(&self) -> &Vec<EdgeIndex>

Returns edge ids of the tensor.

§Examples
let tensor = LeafTensor::new_from_const(vec![1, 2, 3], 3);
assert_eq!(tensor.legs(), &[1, 2, 3]);
Source

pub fn edges(&self) -> impl Iterator<Item = (EdgeIndex, u64)> + '_

Returns an iterator of tuples of leg ids and their corresponding bond size.

Source

pub fn bond_dims(&self) -> &Vec<u64>

Getter for bond dimensions.

Source

pub fn shape(&self) -> Result<Vec<usize>, TryFromIntError>

Returns the shape of tensor. This is the same as the bond dimensions, but as usize. The conversion can fail, hence a Result is returned.

Source

pub fn dims(&self) -> usize

Returns the number of dimensions.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 4), (2, 6), (3, 2)]);
let tensor = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
assert_eq!(tensor.dims(), 3);
Source

pub fn size(&self) -> f64

Returns the number of elements. This is a f64 to avoid overflow in large tensors.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 5), (2, 15), (3, 8)]);
let tensor = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
assert_eq!(tensor.size(), 600.0);
Source

pub fn into_legs(self) -> Vec<EdgeIndex>

Converts this tensor into the leg ids and bond dimensions it is made of.

Source

pub fn into_data(self) -> TensorData

Converts this tensor into the data it contains.

Source

pub fn into_inner(self) -> (Vec<EdgeIndex>, Vec<u64>, TensorData)

Converts this tensor into the leg ids, bond dimensions and data it is made of.

Source

pub fn tensor_data(&self) -> &TensorData

Getter for tensor data.

Source

pub fn set_tensor_data(&mut self, tensordata: TensorData)

Setter for tensor data.

§Examples
let mut tensor = LeafTensor::new_from_const(vec![0, 1], 2);
let tensordata = TensorData::Gate((String::from("x"), vec![], false));
tensor.set_tensor_data(tensordata);
Source

pub fn difference(&self, other: &Self) -> Self

Returns the tensor with legs in self that are not in other.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 2), (2, 4), (3, 6), (4, 3), (5, 9)]);
let tensor1 = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
let tensor2 = LeafTensor::new_from_map(vec![4, 2, 5], &bond_dims);
let diff_tensor = &tensor1 - &tensor2;
assert_eq!(diff_tensor.legs(), &[1, 3]);
assert_eq!(diff_tensor.bond_dims(), &[2, 6]);
Source

pub fn union(&self, other: &Self) -> Self

Returns the tensor with union of legs in both self and other.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 2), (2, 4), (3, 6), (4, 3), (5, 9)]);
let tensor1 = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
let tensor2 = LeafTensor::new_from_map(vec![4, 2, 5], &bond_dims);
let union_tensor = &tensor1 | &tensor2;
assert_eq!(union_tensor.legs(), &[1, 2, 3, 4, 5]);
assert_eq!(union_tensor.bond_dims(), &[2, 4, 6, 3, 9]);
Source

pub fn intersection(&self, other: &Self) -> Self

Returns the tensor with intersection of legs in self and other.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 2), (2, 4), (3, 6), (4, 3), (5, 9)]);
let tensor1 = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
let tensor2 = LeafTensor::new_from_map(vec![4, 2, 5], &bond_dims);
let intersection_tensor = &tensor1 & &tensor2;
assert_eq!(intersection_tensor.legs(), &[2]);
assert_eq!(intersection_tensor.bond_dims(), &[4]);
Source

pub fn symmetric_difference(&self, other: &Self) -> Self

Returns the tensor with symmetrical difference of legs in self and other.

§Examples
let bond_dims = FxHashMap::from_iter([(1, 2), (2, 4), (3, 6), (4, 3), (5, 9)]);
let tensor1 = LeafTensor::new_from_map(vec![1, 2, 3], &bond_dims);
let tensor2 = LeafTensor::new_from_map(vec![4, 2, 5], &bond_dims);
let sym_dif_tensor = &tensor1 ^ &tensor2;
assert_eq!(sym_dif_tensor.legs(), &[1, 3, 4, 5]);
assert_eq!(sym_dif_tensor.bond_dims(), &[2, 6, 3, 9]);

Trait Implementations§

Source§

impl AbsDiffEq for LeafTensor

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 BitAnd for &LeafTensor

Source§

type Output = LeafTensor

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl BitOr for &LeafTensor

Source§

type Output = LeafTensor

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl BitXor for &LeafTensor

Source§

type Output = LeafTensor

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl BitXorAssign<&LeafTensor> for LeafTensor

Source§

fn bitxor_assign(&mut self, rhs: &Self)

Performs the ^= operation. Read more
Source§

impl Clone for LeafTensor

Source§

fn clone(&self) -> LeafTensor

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 LeafTensor

Source§

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

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

impl Default for LeafTensor

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for LeafTensor

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<LeafTensor> for Tensor

Source§

fn from(value: LeafTensor) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for LeafTensor

Source§

fn eq(&self, other: &LeafTensor) -> 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 LeafTensor

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 Sub for &LeafTensor

Source§

type Output = LeafTensor

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl TransparentWrapper<TensorRepr> for LeafTensor

§

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 LeafTensor

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>,