Struct Tensor

Source
pub struct Tensor<T: CoordinateSystem, U: Variance>
where T::Dimension: Pow<U::Rank>, Exp<T::Dimension, U::Rank>: ArrayLength<f64>,
{ /* private fields */ }
Expand description

Struct representing a tensor.

A tensor is anchored at a given point and has coordinates represented in the system defined by the generic parameter T. The variance of the tensor (meaning its rank and types of its indices) is defined by V. This allows Rust to decide at compile time whether two tensors are legal to be added / multiplied / etc.

It is only OK to perform an operation on two tensors if they belong to the same coordinate system.

Implementations§

Source§

impl<T> Tensor<T, ContravariantIndex>

Source

pub fn square(&self) -> f64

Source

pub fn normalize(&mut self)

Source§

impl<T> Tensor<T, CovariantIndex>

Source

pub fn square(&self) -> f64

Source

pub fn normalize(&mut self)

Source§

impl<T, V> Tensor<T, V>

Source

pub fn get_point(&self) -> &Point<T>

Returns the point at which the tensor is defined.

Source

pub fn set_point(&mut self, p: Point<T>)

Sets the point at which the tensor is defined.

Source

pub fn coords_array(&self) -> &GenericArray<f64, Exp<T::Dimension, V::Rank>>

Returns the tensor’s coordinates as an array

Source

pub fn get_coord(i: &[usize]) -> usize

Converts a set of tensor indices passed as a slice into a single index for the internal array.

The length of the slice (the number of indices) has to be compatible with the rank of the tensor.

Source

pub fn get_variance() -> Vec<IndexType>

Returns the variance of the tensor, that is, the list of the index types. A vector would return vec![Contravariant], a metric tensor: vec![Covariant, Covariant].

Source

pub fn get_rank() -> usize

Returns the rank of the tensor

Source

pub fn get_num_coords() -> usize

Returns the number of coordinates of the tensor (equal to [Dimension]^[Rank])

Source

pub fn zero(point: Point<T>) -> Tensor<T, V>

Creates a new, zero tensor at a given point

Source

pub fn new( point: Point<T>, coords: GenericArray<f64, Exp<T::Dimension, V::Rank>>, ) -> Tensor<T, V>

Creates a tensor at a given point with the coordinates defined by the array.

The number of elements in the array must be equal to the number of coordinates of the tensor.

One-dimensional array represents an n-dimensional tensor in such a way, that the last index is the one that is changing the most often, i.e. the sequence is as follows: (0,0,…,0), (0,0,…,1), (0,0,…,2), …, (0,0,…,1,0), (0,0,…,1,1), … etc.

Source

pub fn from_slice(point: Point<T>, slice: &[f64]) -> Tensor<T, V>

Creates a tensor at a given point with the coordinates defined by the slice.

The number of elements in the slice must be equal to the number of coordinates of the tensor.

One-dimensional slice represents an n-dimensional tensor in such a way, that the last index is the one that is changing the most often, i.e. the sequence is as follows: (0,0,…,0), (0,0,…,1), (0,0,…,2), …, (0,0,…,1,0), (0,0,…,1,1), … etc.

Source

pub fn trace<Ul, Uh>(&self) -> Tensor<T, Contracted<V, Ul, Uh>>
where Ul: Unsigned, Uh: Unsigned, V: Contract<Ul, Uh>, <Contracted<V, Ul, Uh> as Variance>::Rank: ArrayLength<usize>, T::Dimension: Pow<<Contracted<V, Ul, Uh> as Variance>::Rank>, Exp<T::Dimension, <Contracted<V, Ul, Uh> as Variance>::Rank>: ArrayLength<f64>,

Contracts two indices

The indices must be of opposite types. This is checked at compile time.

Source§

impl<T, U> Tensor<T, U>

Source

pub fn iter_coords(&self) -> CoordIterator<U>

Returns an iterator over the coordinates of the tensor.

Source§

impl<T, Ul, Ur> Tensor<T, (Ul, Ur)>

Source

pub fn unit(p: Point<T>) -> Tensor<T, (Ul, Ur)>

Returns a unit matrix (1 on the diagonal, 0 everywhere else)

Source

pub fn transpose(&self) -> Tensor<T, (Ur, Ul)>

Transposes the matrix

Source

pub fn inverse( &self, ) -> Option<Tensor<T, (<Ul as OtherIndex>::Output, <Ur as OtherIndex>::Output)>>

Function calculating the inverse of self using the LU ddecomposition.

The return value is an Option, since self may be non-invertible - in such a case, None is returned

Source§

impl<T, U> Tensor<T, U>

Source

pub fn convert<T2>(&self) -> Tensor<T2, U>
where T2: CoordinateSystem + 'static, T2::Dimension: Pow<U::Rank> + Pow<U2> + Same<T::Dimension>, Exp<T2::Dimension, U::Rank>: ArrayLength<f64>, Exp<T2::Dimension, U2>: ArrayLength<f64>, T: ConversionTo<T2>,

Trait Implementations§

Source§

impl<T, U> Add for Tensor<T, U>

Source§

type Output = Tensor<T, U>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Tensor<T, U>) -> Tensor<T, U>

Performs the + operation. Read more
Source§

impl<T, U> AddAssign for Tensor<T, U>

Source§

fn add_assign(&mut self, rhs: Tensor<T, U>)

Performs the += operation. Read more
Source§

impl<T, U> Clone for Tensor<T, U>

Source§

fn clone(&self) -> Tensor<T, U>

Returns a copy 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<T, U> Div<f64> for Tensor<T, U>

Source§

type Output = Tensor<T, U>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Tensor<T, U>

Performs the / operation. Read more
Source§

impl<T, U> DivAssign<f64> for Tensor<T, U>

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl<'a, T, U> Index<&'a [usize]> for Tensor<T, U>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, idx: &'a [usize]) -> &f64

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T, U> Index<usize> for Tensor<T, U>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &f64

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T, U> IndexMut<&'a [usize]> for Tensor<T, U>

Source§

fn index_mut(&mut self, idx: &'a [usize]) -> &mut f64

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T, U> IndexMut<usize> for Tensor<T, U>

Source§

fn index_mut(&mut self, idx: usize) -> &mut f64

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, U, V, Ul, Uh> InnerProduct<Tensor<T, V>, Ul, Uh> for Tensor<T, U>
where T: CoordinateSystem, U: Variance + Concat<V>, V: Variance, Ul: Unsigned, Uh: Unsigned, T::Dimension: Pow<U::Rank> + Pow<V::Rank> + Pow<<Contracted<Joined<U, V>, Ul, Uh> as Variance>::Rank>, Exp<T::Dimension, U::Rank>: ArrayLength<f64>, Exp<T::Dimension, V::Rank>: ArrayLength<f64>, Joined<U, V>: Contract<Ul, Uh>, <Contracted<Joined<U, V>, Ul, Uh> as Variance>::Rank: ArrayLength<usize>, Exp<T::Dimension, <Contracted<Joined<U, V>, Ul, Uh> as Variance>::Rank>: ArrayLength<f64>,

Source§

type Output = Tensor<T, <<U as Concat<V>>::Output as Contract<Ul, Uh>>::Output>

Source§

fn inner_product( self, rhs: Tensor<T, V>, ) -> Tensor<T, Contracted<Joined<U, V>, Ul, Uh>>

Source§

impl<T, U> Mul<Tensor<T, U>> for f64

Source§

type Output = Tensor<T, U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tensor<T, U>) -> Tensor<T, U>

Performs the * operation. Read more
Source§

impl<T, U, V> Mul<Tensor<T, V>> for Tensor<T, U>

Source§

type Output = Tensor<T, <U as Concat<V>>::Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tensor<T, V>) -> Tensor<T, Joined<U, V>>

Performs the * operation. Read more
Source§

impl<T, U> Mul<f64> for Tensor<T, U>

Source§

type Output = Tensor<T, U>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Tensor<T, U>

Performs the * operation. Read more
Source§

impl<T, U> MulAssign<f64> for Tensor<T, U>

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl<T, U> Sub for Tensor<T, U>

Source§

type Output = Tensor<T, U>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Tensor<T, U>) -> Tensor<T, U>

Performs the - operation. Read more
Source§

impl<T, U> SubAssign for Tensor<T, U>

Source§

fn sub_assign(&mut self, rhs: Tensor<T, U>)

Performs the -= operation. Read more
Source§

impl<T, U> Copy for Tensor<T, U>

Auto Trait Implementations§

§

impl<T, U> Freeze for Tensor<T, U>

§

impl<T, U> RefUnwindSafe for Tensor<T, U>

§

impl<T, U> Send for Tensor<T, U>
where <<T as CoordinateSystem>::Dimension as Pow<<U as Variance>::Rank>>::Output: Sized,

§

impl<T, U> Sync for Tensor<T, U>
where <<T as CoordinateSystem>::Dimension as Pow<<U as Variance>::Rank>>::Output: Sized,

§

impl<T, U> Unpin for Tensor<T, U>

§

impl<T, U> UnwindSafe for Tensor<T, U>

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

Source§

type Output = T

Should always be Self
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.