#include <Tensor.h>
Public Member Functions | |
TensorGeneric () | |
initialize the tensor to zero More... | |
TensorGeneric (const VectorGeneric< n > &v1, const VectorGeneric< m > &v2) | |
initialize a tensor as an external product of two Vector More... | |
template<typename... Args> | |
TensorGeneric (double first, Args... arg) | |
Constructor accepting n*m double parameters. More... | |
double | determinant () const |
returns the determinant More... | |
double | determinant () const |
VectorGeneric< n > | getCol (unsigned j) const |
get j-th column More... | |
VectorGeneric< m > | getRow (unsigned i) const |
get i-th row More... | |
TensorGeneric | inverse () const |
return the matrix inverse More... | |
TensorGeneric< 3, 3 > | inverse () const |
double & | operator() (unsigned i, unsigned j) |
access element More... | |
const double & | operator() (unsigned i, unsigned j) const |
access element More... | |
TensorGeneric & | operator*= (double) |
multiply More... | |
TensorGeneric | operator+ () const |
return +t More... | |
TensorGeneric & | operator+= (const TensorGeneric< n, m > &b) |
increment More... | |
TensorGeneric | operator- () const |
return -t More... | |
TensorGeneric & | operator-= (const TensorGeneric< n, m > &b) |
decrement More... | |
TensorGeneric & | operator/= (double) |
divide More... | |
Row | operator[] (unsigned i) |
access element (with [][] syntax) More... | |
Const_row | operator[] (unsigned i) const |
access element (with [][] syntax) More... | |
TensorGeneric & | setCol (unsigned j, const VectorGeneric< n > &c) |
set j-th column More... | |
TensorGeneric & | setRow (unsigned i, const VectorGeneric< m > &r) |
set i-th row More... | |
TensorGeneric< m, n > | transpose () const |
return the transpose matrix More... | |
void | zero () |
set it to zero More... | |
Static Public Member Functions | |
static TensorGeneric< n, n > | identity () |
return an identity tensor More... | |
Private Member Functions | |
void | auxiliaryConstructor () |
Auxiliary private function for constructor. More... | |
template<typename... Args> | |
void | auxiliaryConstructor (double first, Args... arg) |
Auxiliary private function for constructor. More... | |
Private Attributes | |
std::array< double, n *m > | d |
Friends | |
TensorGeneric< 3, 3 > | dcrossDv1 (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &) |
TensorGeneric< 3, 3 > | dcrossDv2 (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &) |
TensorGeneric< 3, 3 > | deriNorm (const VectorGeneric< 3 > &, const TensorGeneric< 3, 3 > &) |
Derivative of a normalized vector. More... | |
double | determinant (const TensorGeneric< 3, 3 > &) |
returns the determinant of a tensor More... | |
template<unsigned n_, unsigned m_> | |
void | diagMatSym (const TensorGeneric< n_, n_ > &, VectorGeneric< m_ > &evals, TensorGeneric< m_, n_ > &evec) |
Diagonalize tensor. More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | extProduct (const VectorGeneric< n > &, const VectorGeneric< m > &) |
returns the transpose of a tensor (same as TensorGeneric(const VectorGeneric&,const VectorGeneric&)) More... | |
TensorGeneric< 3, 3 > | inverse (const TensorGeneric< 3, 3 > &) |
returns the inverse of a tensor (same as inverse()) More... | |
template<unsigned n_, unsigned m_, unsigned l_> | |
TensorGeneric< n_, l_ > | matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &) |
matrix-matrix multiplication More... | |
template<unsigned n_, unsigned m_, unsigned l_, unsigned i_> | |
TensorGeneric< n_, i_ > | matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &, const TensorGeneric< l_, i_ > &) |
matrix-matrix-matrix multiplication More... | |
template<unsigned n_, unsigned m_, unsigned l_> | |
VectorGeneric< n_ > | matmul (const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &, const VectorGeneric< l_ > &) |
matrix-matrix-vector multiplication More... | |
template<unsigned n_, unsigned m_> | |
VectorGeneric< n_ > | matmul (const TensorGeneric< n_, m_ > &, const VectorGeneric< m_ > &) |
matrix-vector multiplication More... | |
template<unsigned n_, unsigned m_> | |
VectorGeneric< n_ > | matmul (const VectorGeneric< m_ > &, const TensorGeneric< m_, n_ > &) |
vector-matrix multiplication More... | |
template<unsigned n_, unsigned m_, unsigned l_> | |
VectorGeneric< l_ > | matmul (const VectorGeneric< n_ > &, const TensorGeneric< n_, m_ > &, const TensorGeneric< m_, l_ > &) |
vector-matrix-matrix multiplication More... | |
template<unsigned n_, unsigned m_> | |
double | matmul (const VectorGeneric< n_ > &, const TensorGeneric< n_, m_ > &, const VectorGeneric< m_ > &) |
vector-matrix-vector multiplication More... | |
template<unsigned n_> | |
double | matmul (const VectorGeneric< n_ > &, const VectorGeneric< n_ > &) |
vector-vector multiplication (maps to dotProduct) More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | operator* (const TensorGeneric< n_, m_ > &, double s) |
scale the tensor by a factor s More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | operator* (double, const TensorGeneric< n_, m_ > &) |
scale the tensor by a factor s More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | operator+ (const TensorGeneric< n_, m_ > &, const TensorGeneric< n_, m_ > &) |
return t1+t2 More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | operator- (const TensorGeneric< n_, m_ > &, const TensorGeneric< n_, m_ > &) |
return t1+t2 More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | operator/ (const TensorGeneric< n_, m_ > &, double s) |
scale the tensor by a factor 1/s More... | |
template<unsigned n_, unsigned m_> | |
std::ostream & | operator<< (std::ostream &os, const TensorGeneric< n_, m_ > &) |
<< operator. More... | |
template<unsigned n_, unsigned m_> | |
TensorGeneric< n_, m_ > | transpose (const TensorGeneric< m_, n_ > &) |
returns the transpose of a tensor (same as transpose()) More... | |
TensorGeneric< 3, 3 > | VcrossTensor (const TensorGeneric< 3, 3 > &, const VectorGeneric< 3 > &) |
TensorGeneric< 3, 3 > | VcrossTensor (const VectorGeneric< 3 > &, const TensorGeneric< 3, 3 > &) |
Class implementing fixed size matrices of doubles
n | The number rows |
m | The number columns |
This class implements a matrix of doubles with size fixed at compile time. It is useful for small fixed size objects (e.g. 3x3 tensors) as it does not waste space to store the vector size. Moreover, as the compiler knows the size, it can be completely opimized inline. Most of the loops are explicitly unrolled using PLMD::LoopUnroller class Matrix elements are initialized to zero by default. Notice that this means that constructor is a bit slow. This point might change in future if we find performance issues. It takes advantage of MatrixSquareBracketsAccess to provide both () and [] syntax for access. Several functions are declared as friends even if not necessary so as to properly appear in Doxygen documentation.
Aliases are defined to simplify common declarations (Tensor, Tensor2d, Tensor3d, Tensor4d). Also notice that some operations are only available for 3x3 tensors.
Example of usage
#include "Tensor.h" using namespace PLMD; int main(){ Tensor a; TensorGeneric<3,2> b; TensorGeneric<3,2> c=matmul(a,b); return 0; }
PLMD::TensorGeneric< n, m >::TensorGeneric | ( | double | first, |
Args... | arg | ||
) |
Constructor accepting n*m double parameters.
Can be used as Tensor<2,2>(1.0,2.0,3.0,4.0) In case a wrong number of parameters is given, a static assertion will fail.
PLMD::TensorGeneric< n, m >::TensorGeneric |
initialize the tensor to zero
PLMD::TensorGeneric< n, m >::TensorGeneric | ( | const VectorGeneric< n > & | v1, |
const VectorGeneric< m > & | v2 | ||
) |
initialize a tensor as an external product of two Vector
|
private |
Auxiliary private function for constructor.
|
private |
Auxiliary private function for constructor.
double PLMD::TensorGeneric< n, m >::determinant | ( | ) | const |
returns the determinant
|
inline |
VectorGeneric< n > PLMD::TensorGeneric< n, m >::getCol | ( | unsigned | j | ) | const |
get j-th column
VectorGeneric< m > PLMD::TensorGeneric< n, m >::getRow | ( | unsigned | i | ) | const |
get i-th row
|
inlinestatic |
return an identity tensor
TensorGeneric PLMD::TensorGeneric< n, m >::inverse | ( | ) | const |
return the matrix inverse
|
inline |
double & PLMD::TensorGeneric< n, m >::operator() | ( | unsigned | i, |
unsigned | j | ||
) |
access element
const double & PLMD::TensorGeneric< n, m >::operator() | ( | unsigned | i, |
unsigned | j | ||
) | const |
access element
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator*= | ( | double | s | ) |
multiply
TensorGeneric< n, m > PLMD::TensorGeneric< n, m >::operator+ |
return +t
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator+= | ( | const TensorGeneric< n, m > & | b | ) |
increment
TensorGeneric< n, m > PLMD::TensorGeneric< n, m >::operator- |
return -t
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator-= | ( | const TensorGeneric< n, m > & | b | ) |
decrement
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::operator/= | ( | double | s | ) |
divide
|
inherited |
access element (with [][] syntax)
|
inherited |
access element (with [][] syntax)
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::setCol | ( | unsigned | j, |
const VectorGeneric< n > & | c | ||
) |
set j-th column
TensorGeneric< n, m > & PLMD::TensorGeneric< n, m >::setRow | ( | unsigned | i, |
const VectorGeneric< m > & | r | ||
) |
set i-th row
TensorGeneric< m, n > PLMD::TensorGeneric< n, m >::transpose |
return the transpose matrix
void PLMD::TensorGeneric< n, m >::zero |
set it to zero
|
friend |
|
friend |
|
friend |
Derivative of a normalized vector.
|
friend |
returns the determinant of a tensor
|
friend |
Diagonalize tensor.
Syntax is the same as Matrix::diagMat. In addition, it is possible to call if with m_ smaller than n_. In this case, only the first (smaller) m_ eigenvalues and eigenvectors are retrieved. If case lapack fails (info!=0) it throws an exception. Notice that tensor is assumed to be symmetric!!!
|
friend |
returns the transpose of a tensor (same as TensorGeneric(const VectorGeneric&,const VectorGeneric&))
|
friend |
returns the inverse of a tensor (same as inverse())
|
friend |
matrix-matrix multiplication
|
friend |
matrix-matrix-matrix multiplication
|
friend |
matrix-matrix-vector multiplication
|
friend |
matrix-vector multiplication
|
friend |
vector-matrix multiplication
|
friend |
vector-matrix-matrix multiplication
|
friend |
vector-matrix-vector multiplication
|
friend |
vector-vector multiplication (maps to dotProduct)
|
friend |
scale the tensor by a factor s
|
friend |
scale the tensor by a factor s
|
friend |
return t1+t2
|
friend |
return t1+t2
|
friend |
scale the tensor by a factor 1/s
|
friend |
<< operator.
Allows printing tensor t
with std::cout<<t;
|
friend |
returns the transpose of a tensor (same as transpose())
|
friend |
|
friend |
|
private |
Hosted by GitHub
![]() |
![]() |