pub struct Tensor {
pub data: ArrayD<Complex64>,
pub rank: usize,
pub dimensions: Vec<usize>,
}Expand description
A tensor representing a quantum state or operation
Fields§
§data: ArrayD<Complex64>The tensor data
rank: usizeThe tensor rank (number of indices)
dimensions: Vec<usize>The dimensions of each index
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn from_matrix(matrix: &[Complex64], dim: usize) -> Self
pub fn from_matrix(matrix: &[Complex64], dim: usize) -> Self
Create a tensor from a matrix (gate)
Sourcepub fn qubit_zero() -> Self
pub fn qubit_zero() -> Self
Create a tensor representing the |0⟩ state
Sourcepub fn qubit_plus() -> Self
pub fn qubit_plus() -> Self
Create a tensor representing the |+⟩ state
Sourcepub fn contract(
&self,
other: &Self,
self_axis: usize,
other_axis: usize,
) -> QuantRS2Result<Self>
pub fn contract( &self, other: &Self, self_axis: usize, other_axis: usize, ) -> QuantRS2Result<Self>
Contract this tensor with another tensor along specified axes.
Performs the Einstein summation over one pair of indices:
result[i₀,…,iₙ₋₁, j₀,…,jₘ₋₁] = Σₖ self[…k…] * other[…k…]
where k runs over self.dimensions[self_axis] (= other.dimensions[other_axis]).
The output shape is self.dimensions with self_axis removed, followed by
other.dimensions with other_axis removed.
Sourcepub fn svd(
&self,
left_axes: &[usize],
right_axes: &[usize],
max_bond_dim: usize,
) -> QuantRS2Result<(Self, Self)>
pub fn svd( &self, left_axes: &[usize], right_axes: &[usize], max_bond_dim: usize, ) -> QuantRS2Result<(Self, Self)>
Perform SVD decomposition on this tensor, splitting it into two lower-rank tensors.
The tensor is logically reshaped into a matrix by grouping left_axes into rows
and right_axes into columns. The SVD is then computed and the result is split
into two tensors:
left_tensor: shape(*left_dims, bond_dim)— absorbs U * diag(S)right_tensor: shape(bond_dim, *right_dims)— contains Vᴴ
max_bond_dim caps how many singular values are kept (bond dimension).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnsafeUnpin for Tensor
impl UnwindSafe for Tensor
Blanket Implementations§
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
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,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.