PTEMS  0.1.0-dev+git.47ec727
PolyTopic Element Method Solver
ptems::BasicTensor< T, R, N > Class Template Reference

A basic class for storing high-order tensors. More...

#include <ptems/tensor.hpp>

Public Member Functions

constexpr BasicTensor ()
 Constructs a tensor filled with zeros. More...
 
constexpr BasicTensor (T value)
 Constructs a tensor filled with with the specified value. More...
 
template<typename V >
constexpr BasicTensor (const BasicTensor< V, R, N > &value)
 Constructs a tensor by explicitly casting from a compatible tensor type. More...
 
template<typename U , std::size_t D = N, typename = std::enable_if_t<((D == N) && (R == 2))>>
constexpr BasicTensor (const BasicMatrix< U, D > &rhs)
 Constructs a tensor equal to the specified matrix. More...
 
template<typename U , std::size_t D = N, typename = std::enable_if_t<((D == N) && (R == 1))>>
constexpr BasicTensor (const BasicVector< U, D > &rhs)
 Construct a tensor equal to the specified vector. More...
 
constexpr BasicTensor (const BasicTensor< T, R, N > &)=default
 Copy constructor. More...
 
constexpr BasicTensor (BasicTensor< T, R, N > &&)=default
 Move constructor. More...
 
constexpr BasicTensoroperator= (T rhs)
 Sets all entries in the tensor equal to the specified constant. More...
 
constexpr BasicTensoroperator= (const BasicTensor< T, R, N > &rhs)
 Sets this tensor equal to the specified tensor. More...
 
constexpr BasicTensoroperator+= (T rhs)
 Adds the specified constant to every entry of this tensor. More...
 
template<typename U >
constexpr BasicTensoroperator+= (const BasicTensor< U, R, N > &rhs)
 Adds the specified tensor elementwise to this tensor. More...
 
constexpr BasicTensoroperator-= (T rhs)
 Subtracts the specified constant to every entry of this tensor. More...
 
template<typename U >
constexpr BasicTensoroperator-= (const BasicTensor< U, R, N > &rhs)
 Subtracts the specified tensor elementwise from this tensor. More...
 
constexpr BasicTensoroperator*= (T rhs)
 Multiplies every entry of this tensor by the specified constant. More...
 
template<typename U >
constexpr BasicTensorElementalMultiply (const BasicTensor< U, R, N > &rhs)
 Multiplies every entry in this tensor by the corresponding entry in the passed tensor (elementwise multiplication) More...
 
constexpr BasicTensoroperator/= (T rhs)
 Divides every entry of this tensor by the specified constant. More...
 
template<typename U >
constexpr BasicTensorElementalDivide (const BasicTensor< U, R, N > &rhs)
 Divides every entry in this tensor by the corresponding entry in the passed tensor (elementwise division) More...
 
constexpr BasicTensor operator- () const
 Gets a tensor containing the negation of this tensor. More...
 
template<typename... IDX>
constexpr std::enable_if_t< sizeof...(IDX)==R, T > operator() (IDX... idx) const
 Gets the value in the specified entry of the tensor. More...
 
template<typename... IDX>
constexpr std::enable_if_t< sizeof...(IDX)==R, T & > operator() (IDX... idx)
 Gets a mutable reference to the specified entry of the tensor. More...
 
const T * data () const
 Gets a const pointer to the underlying array for the tensor. More...
 
T * data ()
 Gets a pointer to the mutable underlying array for the tensor. More...
 

Friends

template<typename U , typename V , std::size_t R1, std::size_t N1>
constexpr friend BasicTensor< std::common_type_t< U, V >, R1, N1 > operator+ (const BasicTensor< U, R1, N1 > &lhs, const BasicTensor< V, R1, N1 > &rhs)
 
template<typename U , typename V , std::size_t R1, std::size_t N1>
constexpr friend BasicTensor< std::common_type_t< U, V >, R1, N1 > operator- (const BasicTensor< U, R1, N1 > &lhs, const BasicTensor< V, R1, N1 > &rhs)
 
template<typename U , typename V , std::size_t R1, std::size_t N1>
constexpr friend BasicTensor< std::common_type_t< U, V >, R1, N1 > ElementalMultiply (const BasicTensor< U, R1, N1 > &lhs, const BasicTensor< V, R1, N1 > &rhs)
 
template<typename U , typename V , std::size_t R1, std::size_t N1>
constexpr friend BasicTensor< std::common_type_t< U, V >, R1, N1 > ElementalDivide (const BasicTensor< U, R1, N1 > &lhs, const BasicTensor< V, R1, N1 > &rhs)
 

Detailed Description

template<typename T, std::size_t R, std::size_t N>
class ptems::BasicTensor< T, R, N >

A basic class for storing high-order tensors.

Note
This class should only be used for rank 3 or higher tensors; use BasicVector and BasicMatrix for rank one and two tensors, respectively.
Template Parameters
TType of the tensor entries
RThe rank of the matrix
NThe number of entries in each rank

Constructor & Destructor Documentation

◆ BasicTensor() [1/7]

template<typename T , std::size_t R, std::size_t N>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( )
inlineconstexpr

Constructs a tensor filled with zeros.

◆ BasicTensor() [2/7]

template<typename T , std::size_t R, std::size_t N>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( value)
inlineexplicitconstexpr

Constructs a tensor filled with with the specified value.

Parameters
valueThe value to fill the tensor with

◆ BasicTensor() [3/7]

template<typename T , std::size_t R, std::size_t N>
template<typename V >
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( const BasicTensor< V, R, N > &  value)
inlineexplicitconstexpr

Constructs a tensor by explicitly casting from a compatible tensor type.

Template Parameters
VThe type of the tensor entries, must be convertible to T by explicit cast
Parameters
valueThe value to fill the matrix with

◆ BasicTensor() [4/7]

template<typename T , std::size_t R, std::size_t N>
template<typename U , std::size_t D = N, typename = std::enable_if_t<((D == N) && (R == 2))>>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( const BasicMatrix< U, D > &  rhs)
inlineexplicitconstexpr

Constructs a tensor equal to the specified matrix.

Note
This function is ONLY available for rank 2 tensors
Parameters
rhsMatrix to assign to tensor

◆ BasicTensor() [5/7]

template<typename T , std::size_t R, std::size_t N>
template<typename U , std::size_t D = N, typename = std::enable_if_t<((D == N) && (R == 1))>>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( const BasicVector< U, D > &  rhs)
inlineexplicitconstexpr

Construct a tensor equal to the specified vector.

Note
This function is ONLY available for rank 1 tensors
Parameters
rhsVector to assign to tensor

◆ BasicTensor() [6/7]

template<typename T , std::size_t R, std::size_t N>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( const BasicTensor< T, R, N > &  )
constexprdefault

Copy constructor.

◆ BasicTensor() [7/7]

template<typename T , std::size_t R, std::size_t N>
constexpr ptems::BasicTensor< T, R, N >::BasicTensor ( BasicTensor< T, R, N > &&  )
constexprdefault

Move constructor.

Member Function Documentation

◆ data() [1/2]

template<typename T , std::size_t R, std::size_t N>
T* ptems::BasicTensor< T, R, N >::data ( )
inline

Gets a pointer to the mutable underlying array for the tensor.

Returns
The underlying array

◆ data() [2/2]

template<typename T , std::size_t R, std::size_t N>
const T* ptems::BasicTensor< T, R, N >::data ( ) const
inline

Gets a const pointer to the underlying array for the tensor.

Returns
The underlying array

◆ ElementalDivide()

template<typename T , std::size_t R, std::size_t N>
template<typename U >
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::ElementalDivide ( const BasicTensor< U, R, N > &  rhs)
inlineconstexpr

Divides every entry in this tensor by the corresponding entry in the passed tensor (elementwise division)

Template Parameters
UThe type of the entries of the right hand tensor
Parameters
rhsTensor to elementwise divide this tensor by
Returns
this

◆ ElementalMultiply()

template<typename T , std::size_t R, std::size_t N>
template<typename U >
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::ElementalMultiply ( const BasicTensor< U, R, N > &  rhs)
inlineconstexpr

Multiplies every entry in this tensor by the corresponding entry in the passed tensor (elementwise multiplication)

Template Parameters
UThe type of the entries of the right hand tensor
Parameters
rhsTensor to elementwise multiple with this tensor
Returns
this

◆ operator()() [1/2]

template<typename T , std::size_t R, std::size_t N>
template<typename... IDX>
constexpr std::enable_if_t<sizeof...(IDX) == R, T&> ptems::BasicTensor< T, R, N >::operator() ( IDX...  idx)
inlineconstexpr

Gets a mutable reference to the specified entry of the tensor.

Can be used to set an entry.

Tensor<3,3,3> tensor;
tensor(0,0,0) = 0;
Note
This method only exists if passed the same number of indices as the order of the tensor
Exceptions
std::out_of_rangeIf idx >= N (checked for each corresponding entry)
Template Parameters
IDXType of the indices, must be convertible to std::size_t
Parameters
idxIndex for each dimension of the tensor
Returns
The value in the specified entry of the tensor

◆ operator()() [2/2]

template<typename T , std::size_t R, std::size_t N>
template<typename... IDX>
constexpr std::enable_if_t<sizeof...(IDX) == R, T> ptems::BasicTensor< T, R, N >::operator() ( IDX...  idx) const
inlineconstexpr

Gets the value in the specified entry of the tensor.

Note
This method only exists if passed the same number of indices as the order of the tensor
Exceptions
std::out_of_rangeIf idx >= N (checked for each corresponding entry)
Template Parameters
IDXType of the indices, must be convertible to std::size_t
Parameters
idxIndex for each dimension of the tensor
Returns
The value in the specified entry of the tensor

◆ operator*=()

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator*= ( rhs)
inlineconstexpr

Multiplies every entry of this tensor by the specified constant.

Parameters
rhsValue to multiple with every entry
Returns
this

◆ operator+=() [1/2]

template<typename T , std::size_t R, std::size_t N>
template<typename U >
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator+= ( const BasicTensor< U, R, N > &  rhs)
inlineconstexpr

Adds the specified tensor elementwise to this tensor.

Template Parameters
UThe type of the entries of the right hand tensor
Parameters
rhsTensor to add
Returns
this

◆ operator+=() [2/2]

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator+= ( rhs)
inlineconstexpr

Adds the specified constant to every entry of this tensor.

Parameters
rhsValue to add to entries
Returns
this

◆ operator-()

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor ptems::BasicTensor< T, R, N >::operator- ( ) const
inlineconstexpr

Gets a tensor containing the negation of this tensor.

Returns
Tensor containing the negation of every entry of this tensor

◆ operator-=() [1/2]

template<typename T , std::size_t R, std::size_t N>
template<typename U >
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator-= ( const BasicTensor< U, R, N > &  rhs)
inlineconstexpr

Subtracts the specified tensor elementwise from this tensor.

Template Parameters
UThe type of the entries of the right hand tensor
Parameters
rhsTensor to subtract
Returns
this

◆ operator-=() [2/2]

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator-= ( rhs)
inlineconstexpr

Subtracts the specified constant to every entry of this tensor.

Parameters
rhsValue to subtract from entries
Returns
this

◆ operator/=()

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator/= ( rhs)
inlineconstexpr

Divides every entry of this tensor by the specified constant.

Parameters
rhsValue to divide every entry by
Returns
this

◆ operator=() [1/2]

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator= ( const BasicTensor< T, R, N > &  rhs)
inlineconstexpr

Sets this tensor equal to the specified tensor.

Parameters
rhsTensor to copy
Returns
this

◆ operator=() [2/2]

template<typename T , std::size_t R, std::size_t N>
constexpr BasicTensor& ptems::BasicTensor< T, R, N >::operator= ( rhs)
inlineconstexpr

Sets all entries in the tensor equal to the specified constant.

Parameters
rhsValue to set all entries to
Returns
this

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