pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
pRC::Tensor< T, Ns > Class Template Reference

Class storing tensors. More...

#include <tensor.hpp>

Public Types

using Type = T
 
template<class C >
using ChangeType = Tensor< C, Ns... >
 
using Subscripts = pRC::Subscripts< Ns... >
 
using Sizes = pRC::Sizes< Ns... >
 
template<Size... Ss>
using ChangeSizes = Tensor< T, Ss... >
 
using Dimension = typename Sizes::Dimension
 
using Value = typename T::Value
 
template<class V , If< IsValue< V > > = 0>
using ChangeValue = Tensor< typename T::template ChangeValue< V >, Ns... >
 
using Signed = typename T::Signed
 
template<Bool R>
using ChangeSigned = Tensor< typename T::template ChangeSigned< R >, Ns... >
 
using Width = typename T::Width
 
template<Size Q>
using ChangeWidth = Tensor< typename T::template ChangeWidth< Q >, Ns... >
 
using IsComplexified = typename T::IsComplexified
 
using Complexify = Tensor< typename T::Complexify, Ns... >
 
using NonComplex = Tensor< typename T::NonComplex, Ns... >
 

Public Member Functions

 ~Tensor ()=default
 
constexpr Tensor (Tensor const &)=default
 
constexpr Tensor (Tensor &&)=default
 
constexpr Tensoroperator= (Tensor const &) &=default
 
constexpr Tensoroperator= (Tensor &&) &=default
 
constexpr Tensor ()=default
 
template<class X , If< IsAssignable< TensorViews::Reference< T, Sizes >, X > > = 0>
constexpr Tensor (X &&other)
 Tensor initializer from compatible tensorish object.
 
template<class X , If< IsAssignable< TensorViews::Reference< T, Sizes >, X > > = 0>
constexpr autooperator= (X &&rhs) &
 Tensor assignment from compatible tensorish objects.
 
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(autooperator() (Is const ... indices) &&
 Getter/setter for rvalue Tensor entries from indices.
 
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(autooperator() (Is const ... indices) const &&
 Getter for const rvalue Tensor entries from indices.
 
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(autooperator() (Is const ... indices) &
 Getter/setter for lvalue Tensor entries from indices.
 
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(autooperator() (Is const ... indices) const &
 Getter for const lvalue Tensor entries from indices.
 
constexpr decltype(autooperator() (Subscripts const &subscripts) &&
 Getter/setter for rvalue Tensor entries from indices.
 
constexpr decltype(autooperator() (Subscripts const &subscripts) const &&
 Getter for const rvalue Tensor entries from indices.
 
constexpr decltype(autooperator() (Subscripts const &subscripts) &
 Getter/setter for lvalue Tensor entries from indices.
 
constexpr decltype(autooperator() (Subscripts const &subscripts) const &
 Getter for const rvalue Tensor entries from indices.
 
constexpr decltype(autooperator[] (Index const index) &&
 Getter/setter for rvalue Tensor entries from linearized index.
 
constexpr decltype(autooperator[] (Index const index) const &&
 Getter for const rvalue Tensor entries from linearized index.
 
constexpr decltype(autooperator[] (Index const index) &
 Getter/setter for lvalue Tensor entries from linearized index.
 
constexpr decltype(autooperator[] (Index const index) const &
 Getter for const lvalue Tensor entries from linearized index.
 
template<class X , If< IsInvocable< Add, Tensor &, X > > = 0>
constexpr autooperator+= (X &&rhs) &
 += operator for Tensors
 
template<class X , If< IsInvocable< Sub, Tensor &, X > > = 0>
constexpr autooperator-= (X &&rhs) &
 -= operator for Tensors
 
template<class X , If< IsInvocable< Mul, X, Tensor & > > = 0>
constexpr autoapplyOnTheLeft (X &&lhs) &
 Applies an object from the left.
 
template<class X , If< IsInvocable< Mul, Tensor &, X > > = 0>
constexpr autoapplyOnTheRight (X &&rhs) &
 Applies an object from the right.
 
template<class X , If< IsInvocable< Mul, Tensor &, X > > = 0>
constexpr autooperator*= (X &&rhs) &
 *= operator for Tensor
 
template<class X , If< IsInvocable< Div, Tensor &, X > > = 0>
constexpr autooperator/= (X &&rhs) &
 /= operator for Tensor
 
template<class E = IsSatisfied<(Dimension() == 0)>, If< E > = 0>
constexpr operator T () const
 Conversion operator for zero-dimensional Tensors.
 

Static Public Member Functions

template<class E = typename Sizes::IsLinearizable, If< E > = 0>
static constexpr auto size ()
 Returns the number of entries of the Tensor class.
 
static constexpr auto size (Index const dimension)
 Returns the mode size along a particular axis of the Tensor class.
 
template<class X , class... Is, If< IsConstructible< T, X > > = 0, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
static constexpr auto Single (X &&value, Is const ... indices)
 Returns a Tensor of the Tensor class with a single non-zero entry.
 
template<class X , If< IsConstructible< T, X > > = 0>
static constexpr auto Single (X &&value, Subscripts const &subscripts)
 Returns a Tensor of the Tensor class with a single non-zero entry.
 

Detailed Description

template<class T, Size... Ns>
class pRC::Tensor< T, Ns >

Class storing tensors.

This class is used to store tensors in pRC. All entries of the Tensor have to have the same type, and both type and mode sizes of the Tensor are set at compile time.

Calculations using Tensors use lazy evaluation for more efficient calculations.

See Tensorish Types in pRC for more details.

Template Parameters
TpRC value class, class of the tensor entries
Ns...parameter pack of class pRC::Size..., mode sizes of the tensor

Member Typedef Documentation

◆ ChangeSigned

template<class T , Size... Ns>
template<Bool R>
using pRC::Tensor< T, Ns >::ChangeSigned = Tensor<typename T::template ChangeSigned<R>, Ns...>

◆ ChangeSizes

template<class T , Size... Ns>
template<Size... Ss>
using pRC::Tensor< T, Ns >::ChangeSizes = Tensor<T, Ss...>

◆ ChangeType

template<class T , Size... Ns>
template<class C >
using pRC::Tensor< T, Ns >::ChangeType = Tensor<C, Ns...>

◆ ChangeValue

template<class T , Size... Ns>
template<class V , If< IsValue< V > > = 0>
using pRC::Tensor< T, Ns >::ChangeValue = Tensor<typename T::template ChangeValue<V>, Ns...>

◆ ChangeWidth

template<class T , Size... Ns>
template<Size Q>
using pRC::Tensor< T, Ns >::ChangeWidth = Tensor<typename T::template ChangeWidth<Q>, Ns...>

◆ Complexify

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Complexify = Tensor<typename T::Complexify, Ns...>

◆ Dimension

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Dimension = typename Sizes::Dimension

◆ IsComplexified

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::IsComplexified = typename T::IsComplexified

◆ NonComplex

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::NonComplex = Tensor<typename T::NonComplex, Ns...>

◆ Signed

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Signed = typename T::Signed

◆ Sizes

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Sizes = pRC::Sizes<Ns...>

◆ Subscripts

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Subscripts = pRC::Subscripts<Ns...>

◆ Type

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Type = T

◆ Value

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Value = typename T::Value

◆ Width

template<class T , Size... Ns>
using pRC::Tensor< T, Ns >::Width = typename T::Width

Constructor & Destructor Documentation

◆ ~Tensor()

template<class T , Size... Ns>
pRC::Tensor< T, Ns >::~Tensor ( )
default

◆ Tensor() [1/4]

template<class T , Size... Ns>
constexpr pRC::Tensor< T, Ns >::Tensor ( Tensor< T, Ns > const )
constexprdefault

◆ Tensor() [2/4]

template<class T , Size... Ns>
constexpr pRC::Tensor< T, Ns >::Tensor ( Tensor< T, Ns > &&  )
constexprdefault

◆ Tensor() [3/4]

template<class T , Size... Ns>
constexpr pRC::Tensor< T, Ns >::Tensor ( )
constexprdefault

◆ Tensor() [4/4]

template<class T , Size... Ns>
template<class X , If< IsAssignable< TensorViews::Reference< T, Sizes >, X > > = 0>
constexpr pRC::Tensor< T, Ns >::Tensor ( X &&  other)
inlineconstexpr

Tensor initializer from compatible tensorish object.

Template Parameters
XTensorish class (inferred)
Parameters
otherobject of class X

Member Function Documentation

◆ applyOnTheLeft()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Mul, X, Tensor & > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::applyOnTheLeft ( X &&  lhs) &
inlineconstexpr

Applies an object from the left.

Applies an object from the left to *this, and returns the result.

Depending on the argument, matrix-multiplication or scalar multiplication is performed.

Template Parameters
XTensorish class or pRC value class (inferred)
Parameters
lhsobject of class X that is applied from the left

◆ applyOnTheRight()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Mul, Tensor &, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::applyOnTheRight ( X &&  rhs) &
inlineconstexpr

Applies an object from the right.

Applies an object from the right to *this, and returns the result.

Depending on the argument, matrix-multiplication or scalar multiplication is performed.

Template Parameters
XTensorish class or pRC value class (inferred)
Parameters
rhsobject of class X that is applied from the right

◆ operator T()

template<class T , Size... Ns>
template<class E = IsSatisfied<(Dimension() == 0)>, If< E > = 0>
constexpr pRC::Tensor< T, Ns >::operator T ( ) const
inlineexplicitconstexpr

Conversion operator for zero-dimensional Tensors.

This operator allows for type casting from Tensor<T> to T. This is only defined for zero-dimensional Tensors, i.e. Tensors with only one element, as it is not a well-defined operation otherwise.

◆ operator()() [1/8]

template<class T , Size... Ns>
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Is const ...  indices) &
inlineconstexpr

Getter/setter for lvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [2/8]

template<class T , Size... Ns>
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Is const ...  indices) &&
inlineconstexpr

Getter/setter for rvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [3/8]

template<class T , Size... Ns>
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Is const ...  indices) const &
inlineconstexpr

Getter for const lvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of Tensor entry

◆ operator()() [4/8]

template<class T , Size... Ns>
template<class... Is, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Is const ...  indices) const &&
inlineconstexpr

Getter for const rvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [5/8]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Subscripts const subscripts) &
inlineconstexpr

Getter/setter for lvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [6/8]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Subscripts const subscripts) &&
inlineconstexpr

Getter/setter for rvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [7/8]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Subscripts const subscripts) const &
inlineconstexpr

Getter for const rvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator()() [8/8]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator() ( Subscripts const subscripts) const &&
inlineconstexpr

Getter for const rvalue Tensor entries from indices.

Template Parameters
Is...parameter pack of classes convertible to Index (inferred)
Parameters
indices...objects of classes Is..., indices of the Tensor entry

◆ operator*=()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Mul, Tensor &, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::operator*= ( X &&  rhs) &
inlineconstexpr

*= operator for Tensor

Multiplies an object to the tensor. This returns the same as calling applyOnTheRight().

Template Parameters
XTensorish class or pRC value class (inferred)
Parameters
rhsobject of class X, multiplicator

◆ operator+=()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Add, Tensor &, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::operator+= ( X &&  rhs) &
inlineconstexpr

+= operator for Tensors

Template Parameters
XTensorish class (inferred)
Parameters
rhsobject of class X, addend

◆ operator-=()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Sub, Tensor &, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::operator-= ( X &&  rhs) &
inlineconstexpr

-= operator for Tensors

Template Parameters
XTensorish class (inferred)
Parameters
rhsobject of class X, subtrahend

◆ operator/=()

template<class T , Size... Ns>
template<class X , If< IsInvocable< Div, Tensor &, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::operator/= ( X &&  rhs) &
inlineconstexpr

/= operator for Tensor

Divides the tensor by an object. This function does element-wise division if given a Tensor of the same size. If given a value, every entry of the tensor is divided by the value.

Template Parameters
XTensorish class or pRC value class (inferred)
Parameters
rhsobject of class X, numerator

◆ operator=() [1/3]

template<class T , Size... Ns>
constexpr Tensor & pRC::Tensor< T, Ns >::operator= ( Tensor< T, Ns > &&  ) &
constexprdefault

◆ operator=() [2/3]

template<class T , Size... Ns>
constexpr Tensor & pRC::Tensor< T, Ns >::operator= ( Tensor< T, Ns > const ) &
constexprdefault

◆ operator=() [3/3]

template<class T , Size... Ns>
template<class X , If< IsAssignable< TensorViews::Reference< T, Sizes >, X > > = 0>
constexpr auto & pRC::Tensor< T, Ns >::operator= ( X &&  rhs) &
inlineconstexpr

Tensor assignment from compatible tensorish objects.

Template Parameters
XTensorish class (inferred)
Parameters
otherobject of class X

◆ operator[]() [1/4]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator[] ( Index const  index) &
inlineconstexpr

Getter/setter for lvalue Tensor entries from linearized index.

Parameters
indexlinearized Index of the Tensor entry

◆ operator[]() [2/4]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator[] ( Index const  index) &&
inlineconstexpr

Getter/setter for rvalue Tensor entries from linearized index.

Parameters
indexlinearized Index of the Tensor entry

◆ operator[]() [3/4]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator[] ( Index const  index) const &
inlineconstexpr

Getter for const lvalue Tensor entries from linearized index.

Parameters
indexlinearized Index of the Tensor entry

◆ operator[]() [4/4]

template<class T , Size... Ns>
constexpr decltype(auto) pRC::Tensor< T, Ns >::operator[] ( Index const  index) const &&
inlineconstexpr

Getter for const rvalue Tensor entries from linearized index.

Parameters
indexlinearized Index of the Tensor entry

◆ Single() [1/2]

template<class T , Size... Ns>
template<class X , class... Is, If< IsConstructible< T, X > > = 0, If< All< IsConvertible< Is, Index >... > > = 0, If< IsSatisfied<(sizeof...(Is)==Dimension())> > = 0>
static constexpr auto pRC::Tensor< T, Ns >::Single ( X &&  value,
Is const ...  indices 
)
inlinestaticconstexpr

Returns a Tensor of the Tensor class with a single non-zero entry.

The class of the value passed has to be compatible with the Tensor's value class, meaning the Tensor's value class has to be constructible from an object of class X. Additionally, the number of indices passed has to match the Tensor's dimension.

Template Parameters
XpRC value class (inferred)
Is...parameter pack of classes convertible to Index (inferred)
Parameters
valueobject of class X, value of the non-zero entry
indices...parameter pack of classes Is..., indices of the non-zero entry

◆ Single() [2/2]

template<class T , Size... Ns>
template<class X , If< IsConstructible< T, X > > = 0>
static constexpr auto pRC::Tensor< T, Ns >::Single ( X &&  value,
Subscripts const subscripts 
)
inlinestaticconstexpr

Returns a Tensor of the Tensor class with a single non-zero entry.

The class of the value passed has to be compatible with the tensor's value class, meaning the Tensor's value class has to be constructible from an object of class X.

Template Parameters
XpRC value class (inferred)
Parameters
valueobject of class X, value of the non-zero entry
subscriptspRC::Subscripts object specifying the indices of the non-zero entry

◆ size() [1/2]

template<class T , Size... Ns>
template<class E = typename Sizes::IsLinearizable, If< E > = 0>
static constexpr auto pRC::Tensor< T, Ns >::size ( )
inlinestaticconstexpr

Returns the number of entries of the Tensor class.

◆ size() [2/2]

template<class T , Size... Ns>
static constexpr auto pRC::Tensor< T, Ns >::size ( Index const  dimension)
inlinestaticconstexpr

Returns the mode size along a particular axis of the Tensor class.

Parameters
dimensionpRC::Index specifying the axis

The documentation for this class was generated from the following file: