TensorExpression

Struct TensorExpression 

Source
pub struct TensorExpression { /* private fields */ }

Implementations§

Source§

impl TensorExpression

Source

pub fn new<T: AsRef<str>>(input: T) -> Self

Source

pub fn from_raw(indices: Vec<TensorIndex>, inner: NamedExpression) -> Self

Source

pub fn indices(&self) -> &[TensorIndex]

Source

pub fn dimensions(&self) -> Vec<IndexSize>

Source

pub fn rank(&self) -> usize

Source

pub fn generation_shape(&self) -> GenerationShape

Source

pub fn tensor_strides(&self) -> Vec<usize>

Calculates the strides for each dimension of the tensor.

The stride for a dimension is the number of elements one must skip in the flattened array to move to the next element along that dimension. The strides are calculated such that the last dimension has a stride of 1, the second to last dimension has a stride equal to the size of the last dimension, and so on.

§Examples
use qudit_expr::TensorExpression;

let mut tensor = TensorExpression::new("example() {[
        [
            [ 1, 0, 0, 0 ],
            [ 0, 1, 0, 0 ],
            [ 0, 0, 1, 0 ],
            [ 0, 0, 0, 1 ],
        ], [
            [ 1, 0, 0, 0 ],
            [ 0, 1, 0, 0 ],
            [ 0, 0, 0, 1 ],
            [ 0, 0, 1, 0 ],
        ]
    ]}");

assert_eq!(tensor.tensor_strides(), vec![16, 8, 4, 2, 1]);
Source

pub fn reindex(&mut self, new_indices: Vec<TensorIndex>) -> &mut Self

Source

pub fn permute( &mut self, perm: &[usize], redirection: Vec<IndexDirection>, ) -> &mut Self

Source

pub fn stack_with_identity( &self, positions: &[usize], new_dim: usize, ) -> TensorExpression

Source

pub fn partial_trace( &self, dimension_pairs: &[(usize, usize)], ) -> TensorExpression

Source

pub fn substitute_parameters<S: AsRef<str>, C: AsRef<Expression>>( &self, variables: &[S], values: &[C], ) -> Self

replace all variables with values, new variables given in variables input

Source

pub fn destruct( self, ) -> (String, Vec<String>, Vec<ComplexExpression>, Vec<TensorIndex>)

Methods from Deref<Target = NamedExpression>§

Source

pub fn name(&self) -> &str

Source

pub fn set_name(&mut self, new_name: impl Into<String>)

Source

pub fn set_variables(&mut self, new_variables: Vec<String>)

Source

pub fn apply_element_permutation(&mut self, elem_perm: &[usize])

Trait Implementations§

Source§

impl AsRef<NamedExpression> for TensorExpression

Source§

fn as_ref(&self) -> &NamedExpression

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for TensorExpression

Source§

fn clone(&self) -> TensorExpression

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TensorExpression

Source§

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

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

impl Deref for TensorExpression

Source§

type Target = NamedExpression

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for TensorExpression

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl From<BraExpression> for TensorExpression

Source§

fn from(value: BraExpression) -> Self

Converts to this type from the input type.
Source§

impl From<BraSystemExpression> for TensorExpression

Source§

fn from(value: BraSystemExpression) -> Self

Converts to this type from the input type.
Source§

impl From<IsometryExpression> for TensorExpression

Source§

fn from(value: IsometryExpression) -> Self

Converts to this type from the input type.
Source§

impl From<KetExpression> for TensorExpression

Source§

fn from(value: KetExpression) -> Self

Converts to this type from the input type.
Source§

impl From<KetSystemExpression> for TensorExpression

Source§

fn from(value: KetSystemExpression) -> Self

Converts to this type from the input type.
Source§

impl From<KrausOperatorsExpression> for TensorExpression

Source§

fn from(value: KrausOperatorsExpression) -> Self

Converts to this type from the input type.
Source§

impl From<TensorExpression> for NamedExpression

Source§

fn from(value: TensorExpression) -> Self

Converts to this type from the input type.
Source§

impl From<UnitaryExpression> for TensorExpression

Source§

fn from(value: UnitaryExpression) -> Self

Converts to this type from the input type.
Source§

impl From<UnitarySystemExpression> for TensorExpression

Source§

fn from(value: UnitarySystemExpression) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for TensorExpression

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 TryFrom<TensorExpression> for BraExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for BraSystemExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for IsometryExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for KetExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for KetSystemExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for KrausOperatorsExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for UnitaryExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<TensorExpression> for UnitarySystemExpression

Source§

type Error = String

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

fn try_from(value: TensorExpression) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for TensorExpression

Source§

impl StructuralPartialEq for TensorExpression

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

impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
where T: AsRef<Target> + ?Sized, Target: ?Sized,

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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
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.
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.
Source§

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

Source§

fn vzip(self) -> V