Struct diffgeom::tensors::Tensor [] [src]

pub struct Tensor<T: CoordinateSystem, U: Variance> where T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64> {
    // some fields omitted
}

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.

Methods

impl<T, V> Tensor<T, V> where T: CoordinateSystem, V: Variance, T::Dimension: Pow<V::Rank>, Power<T::Dimension, V::Rank>: ArrayLength<f64>
[src]

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

Returns the point at which the tensor is defined.

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.

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].

fn get_rank() -> usize

Returns the rank of the tensor

fn get_num_coords() -> usize

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

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

Creates a new, zero tensor at a given point

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.

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

Contracts two indices

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

impl<T, U> Tensor<T, U> where T: CoordinateSystem, U: Variance, U::Rank: ArrayLength<usize>, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

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

Returns an iterator over the coordinates of the tensor.

impl<T, Ul, Ur> Tensor<T, (Ul, Ur)> where T: CoordinateSystem, Ul: TensorIndex + OtherIndex, Ur: TensorIndex + OtherIndex, Add1<Ul::Rank>: Unsigned + Add<U1>, Add1<Ur::Rank>: Unsigned + Add<U1>, Add1<Ul::Output::Rank>: Unsigned + Add<U1>, Add1<Ur::Output::Rank>: Unsigned + Add<U1>, (Ul, Ur)::Rank: ArrayLength<usize>, T::Dimension: Pow<Add1<Ul::Rank>> + Pow<Add1<Ur::Rank>> + ArrayLength<usize>, T::Dimension: Pow<Add1<Ul::Output::Rank>>, T::Dimension: Pow<Add1<Ur::Output::Rank>>, Power<T::Dimension, Add1<Ul::Rank>>: ArrayLength<f64>, Power<T::Dimension, Add1<Ur::Rank>>: ArrayLength<f64>, Power<T::Dimension, Add1<Ul::Output::Rank>>: ArrayLength<f64>, Power<T::Dimension, Add1<Ur::Output::Rank>>: ArrayLength<f64>
[src]

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

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

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

Transposes the matrix

fn inverse(&self) -> Option<Tensor<T, (Ul::Output, Ur::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

Trait Implementations

impl<T, U> Clone for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

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

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl<T, U> Copy for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, T::Dimension::ArrayType: Copy, Power<T::Dimension, U::Rank>: ArrayLength<f64>, Power<T::Dimension, U::Rank>::ArrayType: Copy
[src]

impl<'a, T, U> Index<&'a [usize]> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = f64

The returned type after indexing

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

The method for the indexing (Foo[Bar]) operation

impl<'a, T, U> IndexMut<&'a [usize]> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

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

The method for the indexing (Foo[Bar]) operation

impl<'a, T, U> Index<usize> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = f64

The returned type after indexing

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

The method for the indexing (Foo[Bar]) operation

impl<'a, T, U> IndexMut<usize> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

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

The method for the indexing (Foo[Bar]) operation

impl<T, U> Add<Tensor<T, U>> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = Tensor<T, U>

The resulting type after applying the + operator

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

The method for the + operator

impl<T, U> Sub<Tensor<T, U>> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = Tensor<T, U>

The resulting type after applying the - operator

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

The method for the - operator

impl<T, U> Mul<f64> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = Tensor<T, U>

The resulting type after applying the * operator

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

The method for the * operator

impl<T, U> Div<f64> for Tensor<T, U> where T: CoordinateSystem, U: Variance, T::Dimension: Pow<U::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>
[src]

type Output = Tensor<T, U>

The resulting type after applying the / operator

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

The method for the / operator

impl<T, U, V> Mul<Tensor<T, V>> for Tensor<T, U> where T: CoordinateSystem, U: Variance, V: Variance, U::Rank: ArrayLength<usize>, V::Rank: ArrayLength<usize>, T::Dimension: Pow<U::Rank> + Pow<V::Rank>, Power<T::Dimension, U::Rank>: ArrayLength<f64>, Power<T::Dimension, V::Rank>: ArrayLength<f64>, U: Concat<V>, Joined<U, V>: Variance, T::Dimension: Pow<Joined<U, V>::Rank>, Power<T::Dimension, Joined<U, V>::Rank>: ArrayLength<f64>
[src]

type Output = Tensor<T, Joined<U, V>>

The resulting type after applying the * operator

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

The method for the * operator

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

type Output = Tensor<T, Contracted<Joined<U, V>, Ul, Uh>>

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