pub struct LeafTensor(/* private fields */);Expand description
A single leaf tensor.
Implementations§
Source§impl LeafTensor
impl LeafTensor
Sourcepub fn new_from_map(
legs: Vec<EdgeIndex>,
bond_dims_map: &FxHashMap<EdgeIndex, u64>,
) -> Self
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]);Sourcepub fn new_from_const(legs: Vec<EdgeIndex>, bond_dim: u64) -> Self
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]);Sourcepub fn shallow_clone(&self) -> Self
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.
Sourcepub fn legs(&self) -> &Vec<EdgeIndex> ⓘ
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]);Sourcepub fn edges(&self) -> impl Iterator<Item = (EdgeIndex, u64)> + '_
pub fn edges(&self) -> impl Iterator<Item = (EdgeIndex, u64)> + '_
Returns an iterator of tuples of leg ids and their corresponding bond size.
Sourcepub fn shape(&self) -> Result<Vec<usize>, TryFromIntError>
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.
Sourcepub fn dims(&self) -> usize
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);Sourcepub fn size(&self) -> f64
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);Sourcepub fn into_legs(self) -> Vec<EdgeIndex> ⓘ
pub fn into_legs(self) -> Vec<EdgeIndex> ⓘ
Converts this tensor into the leg ids and bond dimensions it is made of.
Sourcepub fn into_data(self) -> TensorData
pub fn into_data(self) -> TensorData
Converts this tensor into the data it contains.
Sourcepub fn into_inner(self) -> (Vec<EdgeIndex>, Vec<u64>, TensorData)
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.
Sourcepub fn tensor_data(&self) -> &TensorData
pub fn tensor_data(&self) -> &TensorData
Getter for tensor data.
Sourcepub fn set_tensor_data(&mut self, tensordata: TensorData)
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);Sourcepub fn difference(&self, other: &Self) -> Self
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]);Sourcepub fn union(&self, other: &Self) -> Self
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]);Sourcepub fn intersection(&self, other: &Self) -> Self
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]);Sourcepub fn symmetric_difference(&self, other: &Self) -> Self
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
impl AbsDiffEq for LeafTensor
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq].Source§impl BitAnd for &LeafTensor
impl BitAnd for &LeafTensor
Source§impl BitOr for &LeafTensor
impl BitOr for &LeafTensor
Source§impl BitXor for &LeafTensor
impl BitXor for &LeafTensor
Source§impl BitXorAssign<&LeafTensor> for LeafTensor
impl BitXorAssign<&LeafTensor> for LeafTensor
Source§fn bitxor_assign(&mut self, rhs: &Self)
fn bitxor_assign(&mut self, rhs: &Self)
^= operation. Read moreSource§impl Clone for LeafTensor
impl Clone for LeafTensor
Source§fn clone(&self) -> LeafTensor
fn clone(&self) -> LeafTensor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LeafTensor
impl Debug for LeafTensor
Source§impl Default for LeafTensor
impl Default for LeafTensor
Source§impl<'de> Deserialize<'de> for LeafTensor
impl<'de> Deserialize<'de> for LeafTensor
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<LeafTensor> for Tensor
impl From<LeafTensor> for Tensor
Source§fn from(value: LeafTensor) -> Self
fn from(value: LeafTensor) -> Self
Source§impl PartialEq for LeafTensor
impl PartialEq for LeafTensor
Source§fn eq(&self, other: &LeafTensor) -> bool
fn eq(&self, other: &LeafTensor) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for LeafTensor
impl Serialize for LeafTensor
Source§impl Sub for &LeafTensor
impl Sub for &LeafTensor
Source§impl TransparentWrapper<TensorRepr> for LeafTensor
impl TransparentWrapper<TensorRepr> for LeafTensor
§fn wrap_ref(s: &Inner) -> &Self
fn wrap_ref(s: &Inner) -> &Self
§fn wrap_mut(s: &mut Inner) -> &mut Self
fn wrap_mut(s: &mut Inner) -> &mut Self
§fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
fn wrap_slice(s: &[Inner]) -> &[Self]where
Self: Sized,
§fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
fn wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]where
Self: Sized,
§fn peel_ref(s: &Self) -> &Inner
fn peel_ref(s: &Self) -> &Inner
§fn peel_mut(s: &mut Self) -> &mut Inner
fn peel_mut(s: &mut Self) -> &mut Inner
§fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
fn peel_slice(s: &[Self]) -> &[Inner]where
Self: Sized,
§fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
fn peel_slice_mut(s: &mut [Self]) -> &mut [Inner]where
Self: Sized,
impl StructuralPartialEq for LeafTensor
Auto Trait Implementations§
impl Freeze for LeafTensor
impl RefUnwindSafe for LeafTensor
impl Send for LeafTensor
impl Sync for LeafTensor
impl Unpin for LeafTensor
impl UnsafeUnpin for LeafTensor
impl UnwindSafe for LeafTensor
Blanket Implementations§
§impl<T> AnyExt for T
impl<T> AnyExt for T
§fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
fn downcast_ref<T>(this: &Self) -> Option<&T>where
T: Any,
T behind reference§fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>where
T: Any,
T behind mutable reference§fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Any,
T behind Rc pointer§fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Any,
T behind Arc pointer§fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Any,
T behind Box pointer§fn downcast_move<T>(this: Self) -> Option<T>
fn downcast_move<T>(this: Self) -> Option<T>
Self to T,
useful only in generic context as a workaround for specialization§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Source§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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, X> CoerceTo<T> for Xwhere
T: CoerceFrom<X> + ?Sized,
impl<T, X> CoerceTo<T> for Xwhere
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
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
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§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<I, T> TransparentWrapperAlloc<I> for T
impl<I, T> TransparentWrapperAlloc<I> for T
§fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
fn wrap_vec(s: Vec<Inner>) -> Vec<Self>where
Self: Sized,
§fn wrap_box(s: Box<Inner>) -> Box<Self>
fn wrap_box(s: Box<Inner>) -> Box<Self>
§fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
fn wrap_rc(s: Rc<Inner>) -> Rc<Self>
Rc to the inner type into an Rc to the wrapper type.§fn wrap_arc(s: Arc<Inner>) -> Arc<Self> ⓘ
fn wrap_arc(s: Arc<Inner>) -> Arc<Self> ⓘ
Arc to the inner type into an Arc to the wrapper type.