Peano
Loading...
Searching...
No Matches
tarch::la Namespace Reference

My collection of tiny vector operations. More...

Namespaces

namespace  tests

Data Structures

class  DynamicMatrix
 My standard matrix is a matrix where the size is fixed at compile time. More...
class  Matrix
 Static (i.e. More...
class  ShallowMatrix
 Shallow matrix wrapping an existing array. More...
struct  SmartPointerVector
 Simple SmartPointerVector class. More...
struct  Vector
 Simple vector class. More...
struct  VectorCompare
 Comparison operator for boolean vectors. More...

Functions

DynamicMatrix transpose (const DynamicMatrix &matrix)
template<int Rows, int Cols, typename Scalar>
void modifiedGramSchmidt (Matrix< Rows, Cols, Scalar > A, Matrix< Rows, Cols, Scalar > &Q, Matrix< Cols, Cols, Scalar > &R)
 Produces an economy-size QR decomposition of a matrix A, A is changed.
void modifiedGramSchmidt (DynamicMatrix A, DynamicMatrix &Q, DynamicMatrix &R)
template<int Rows, typename Scalar>
void lu (Matrix< Rows, Rows, Scalar > &A, Vector< Rows, int > &pivots)
 Performs an in-situ LU-decomposition of the square matrix A.
template<int Rows, typename Scalar>
void lu (Matrix< Rows, Rows, Scalar > &A)
 In-situ LU without pivoting.
template<int Rows, typename Scalar>
Vector< Rows, Scalar > backSubstitution (const Matrix< Rows, Rows, Scalar > &R, const Vector< Rows, Scalar > &f)
 Back substitution following LU decomposition.
void backSubstitution (const DynamicMatrix &R, const double *f, double *x)
DynamicMatrix invertUpperTriangular (const DynamicMatrix &R)
template<int Rows, typename Scalar>
Matrix< Rows, Rows, Scalar > invert (const Matrix< Rows, Rows, Scalar > &M)
 Invert matrix with LU decomposition.
template<typename Scalar>
Matrix< 2, 2, Scalar > invert (const Matrix< 2, 2, Scalar > &M)
 Specialisation of inversion.
template<typename Scalar>
Matrix< 3, 3, Scalar > invert (const Matrix< 3, 3, Scalar > &M)
 Specialisation of inversion.
template<typename Scalar>
double det (const Matrix< 2, 2, Scalar > &R)
template<typename Scalar>
double det (const Matrix< 3, 3, Scalar > &R)
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > buildMatrix (const Scalar *values)
 Deep copy builder function.
template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > multiply (const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
 Performs a matrix x matrix multiplication.
template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > multiplyComponents (const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > operator* (const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
template<int Rows, int Cols, typename Scalar>
bool operator== (const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
 Bitwise comparison of the components of two matrices on equality.
template<int Rows, int Cols, typename Scalar>
bool equals (const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Compares to matrices on equality by means of a numerical accuracy.
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > operator+ (const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > operator- (const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs)
template<int Rows, int Cols, typename Scalar>
std::pair< int, int > equalsReturnIndex (const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Return Index of element which is not equals.
template<int Rows, int Cols, typename Scalar>
Scalar sum (const Matrix< Rows, Cols, Scalar > &matrix)
 Computes the sum of all entries of the matrix.
template<int Rows, int Cols, typename Scalar>
Matrix< Cols, Rows, Scalar > transpose (const Matrix< Rows, Cols, Scalar > &matrix)
template<int Rows, typename Scalar>
static Matrix< Rows, Rows, Scalar > identity ()
 Returns the identity matrix.
template<int Rows, typename Scalar>
Vector< Rows, Scalar > diag (const Matrix< Rows, Rows, Scalar > &matrix)
 Extract diagonal vector from matrix.
template<int Rows, int Cols, typename Scalar>
Vector< Cols, Scalar > row (const Matrix< Rows, Cols, Scalar > &matrix, int whichRow)
 Extract row from matrix.
template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > col (const Matrix< Rows, Cols, Scalar > &matrix, int whichColumn)
 Extract row from matrix.
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > invertEntries (const Matrix< Rows, Cols, Scalar > &matrix)
 Inverts each individual entry.
template<int Rows, int Cols, typename Scalar>
Scalar frobeniusNorm (const Matrix< Rows, Cols, Scalar > &matrix)
template<int Rows, int Cols, typename Scalar>
Scalar elementMax (const Matrix< Rows, Cols, Scalar > &matrix)
 Max norm.
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > & operator*= (Matrix< Rows, Cols, Scalar > &matrix, const Scalar &scalar)
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > operator* (const Matrix< Rows, Cols, Scalar > &matrix, const Scalar &scalar)
 Multiplies every component of the matrix with the scalar.
template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > operator* (const Scalar &scalar, const Matrix< Rows, Cols, Scalar > &matrix)
 Multiplies every component of the matrix with the scalar.
template<int Rows, int Cols>
Matrix< Rows, Cols, std::complex< double > > operator* (const double &scalar, const Matrix< Rows, Cols, std::complex< double > > &matrix)
template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > multiply (const Matrix< Rows, Cols, Scalar > &matrix, const Vector< Cols, Scalar > &vector)
 Performs a matrix x vector multiplication.
template<int Rows, int Cols, typename Scalar>
void matVec (const Matrix< Rows, Cols, Scalar > &matrix, Scalar alpha, const Vector< Cols, Scalar > &v, Vector< Rows, Scalar > &r)
 Compute r = r + alpha * M * v in-situ.
template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > operator* (const Matrix< Rows, Cols, Scalar > &matrix, const Vector< Cols, Scalar > &vector)
 Performs a matrix x vector multiplication.
template<int Size, typename Scalar>
Matrix< Size, Size, Scalar > outerDot (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Outer dot product.
double relativeEpsNormalisedAgainstValueGreaterOne (double valueA, double valueB=std::numeric_limits< double >::min(), double eps=NUMERICAL_ZERO_DIFFERENCE)
 Determine a relative tolerance from one or two values.
double relativeEps (double valueA, double valueB=std::numeric_limits< double >::min(), double eps=NUMERICAL_ZERO_DIFFERENCE)
 Determine a relative tolerance from one or two values.
double max (double a, double b, double c)
 I need the maximum of three values all the time, to I decided to write a function for this.
double pow (double base, double exponent)
 Wrapper around std::pow which is redirected to Intel's implementation on Intel machines.
double convertAbsoluteIntoRelativeValue (double referenceValue, double value)
 Convert an absolute value into a relative one.
template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > multiply (const ShallowMatrix< Rows, Cols, Scalar > &matrix, const Vector< Cols, Scalar > &vector)
 Performs a matrix x vector multiplication.
template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > multiply (const ShallowMatrix< Rows, Cols, Scalar > &matrix, const SmartPointerVector< Cols, Scalar > &vector)
template<typename NewScalarType, int Size, typename Scalar>
tarch::la::SmartPointerVector< Size, NewScalarType > convertScalar (const tarch::la::SmartPointerVector< Size, Scalar > &SmartPointerVector)
template<typename NewScalarType, int Size, typename Scalar>
tarch::la::Vector< Size, NewScalarType > convertScalar (const tarch::la::Vector< Size, Scalar > &vector)
 Convert the scalar type underlying a vector.
template<int Size, typename Scalar>
Scalar norm1 (const Vector< Size, Scalar > &vector)
 Computes the 1-norm of the vector, i.e.
template<int Size>
double norm1 (const Vector< Size, std::complex< double > > &vector)
 Specialisation that is different to standard definition.
template<int Size, typename Scalar>
Scalar norm2 (const Vector< Size, Scalar > &vector)
 Computes the 2-norm of the vector, i.e.
template<int Size, typename Scalar>
Scalar norm2Squared (const Vector< Size, Scalar > &vector)
template<int Size>
double norm2 (const Vector< Size, std::complex< double > > &vector)
 Specialisation that is different to standard definition.
template<int Size>
double norm2Squared (const Vector< Size, std::complex< double > > &vector)
template<int Size, typename Scalar>
Scalar normMax (const Vector< Size, Scalar > &vector)
 Computes the max-norm of the vector.
template<int Size>
double normMax (const Vector< Size, std::complex< double > > &vector)
 Specialisation that is different to standard definition.
template<int Size, typename Scalar>
Vector< Size, Scalar > abs (const Vector< Size, Scalar > &vector)
 Computes the absolute component values of the vector, creating a temporary vector to hold the result.
template<int Size>
Vector< Size, double > abs (const Vector< Size, std::complex< double > > &vector)
 Specialisation that is different to standard definition.
template<int Size, typename Scalar>
Scalar sum (const Vector< Size, Scalar > &vector)
 Sums up the component values of the vector.
template<int Size, typename Scalar>
Scalar volume (const Vector< Size, Scalar > &vector)
 Computes the volume of the tetrahedron spanned by the Cartesian unit vectors scaled by the corresponding components of the given vector.
template<int Size, typename Scalar>
bool allEntriesAreTheSame (const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
Scalar average (const Vector< Size, Scalar > &vector)
 Computes the volume of the tetrahedron spanned by the Cartesian unit vectors scaled by the corresponding components of the given vector.
template<int Size, typename Scalar>
int indexMax (const Vector< Size, Scalar > &vector)
 Returns the index of the element with maximal value (NOT absolute value).
template<int Size, typename Scalar>
int indexMin (const Vector< Size, Scalar > &vector)
 Returns the index of the element with minimal value (NOT absolute value).
template<int Size, typename Scalar>
Scalar max (const Vector< Size, Scalar > &vector)
 Returns the element with maximal value (NOT absolute value).
template<int Size, typename Scalar>
Scalar maxAbs (const Vector< Size, Scalar > &vector)
 Returns the element with maximal absolute value.
template<int Size, typename Scalar>
Scalar min (const Vector< Size, Scalar > &vector)
 Returns the element with minimal value (NOT absolute value).
template<int Size, typename Scalar>
Vector< Size, Scalar > invertEntries (const Vector< Size, Scalar > &vector)
template<int Size>
Vector< Size, double > real (const Vector< Size, std::complex< double > > &vector)
template<int Size>
Vector< Size, double > imag (const Vector< Size, std::complex< double > > &vector)
template<int Size>
double maxReal (const Vector< Size, std::complex< double > > &vector)
template<int Size>
double maxImag (const Vector< Size, std::complex< double > > &vector)
template<int Size, typename Scalar>
bool contains (const Vector< Size, Scalar > &vector, const Scalar &value)
template<int Size, typename Scalar>
int count (const Vector< Size, Scalar > &vector, const Scalar &value)
template<int Size, typename Scalar>
int isEntryNan (const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
int isEntryFinite (const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
std::vector< Scalar > toSTLVector (const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator*= (Vector< Size, Scalar > &vector, const Scalar &scalar)
 Multiplies every component of the vector with the scalar and assigns the result to the vector.
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator/= (Vector< Size, Scalar > &vector, const Scalar &scalar)
 Divides every component of the vector by the scalar and assigns the result to the vector.
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator+= (Vector< Size, Scalar > &vector, const Scalar &scalar)
 Adds every component of the vector to the scalar and assigns the result to the vector.
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator-= (Vector< Size, Scalar > &vector, const Scalar &scalar)
 Subtracts the scalar from every component of the vector and assigns the result to the vector.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator* (const Vector< Size, Scalar > &vector, const Scalar &scalar)
 Multiplies every component of the vector with the scalar and returns the result.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator* (const Scalar &scalar, const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
Vector< Size, Scalar > operator/ (const Vector< Size, Scalar > &vector, const Scalar &scalar)
 Divides every component of the vector by the scalar and returns the result.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator+ (const Vector< Size, Scalar > &vector, const Scalar &scalar)
 Adds the scalar to every component of the vector and returns the result.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator+ (const Scalar &scalar, const Vector< Size, Scalar > &vector)
template<int Size, typename Scalar>
Vector< Size, Scalar > operator- (const Vector< Size, Scalar > &vector, const Scalar &scalar)
 Subtracts the scalar from every component of the vector and returns the result.
template<int Size, typename Scalar>
bool equals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 !
template<int Size, typename Scalar>
bool oneEquals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneGreater (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneGreaterEquals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool allGreater (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool allGreaterEquals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneSmaller (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneSmallerEquals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool allSmaller (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool allSmallerEquals (const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size>
bool equals (const Vector< Size, int > &lhs, const int &cmp)
 Specialisation for int.
template<int Size>
bool oneEquals (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool oneGreater (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool oneGreaterEquals (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool oneSmaller (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool oneSmallerEquals (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool allGreater (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool allGreaterEquals (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool allSmaller (const Vector< Size, int > &lhs, const int &cmp)
template<int Size>
bool allSmallerEquals (const Vector< Size, int > &lhs, const int &cmp)
template<int Size, typename Scalar>
Vector< Size, Scalar > remainder (const Vector< Size, Scalar > &vector, double h)
 Return the remainder of a division.
template<int SizeLhs, int SizeRhs, typename Scalar>
Vector< SizeLhs, Scalar > slice (const Vector< SizeRhs, Scalar > &vector, int fromIndex, int stride=1)
 Returns subpart of the vector.
template<int SizeLhs, int SizeRhs, typename Scalar>
void slice (Vector< SizeLhs, Scalar > &toVector, const Vector< SizeRhs, Scalar > &fromVector, int fromIndexInToVector, int strideInToVector=1)
 Setter.
template<int SizeLhs, int SizeRhs, typename Scalar>
Vector< SizeLhs, Scalar > expandOrSlice (const Vector< SizeRhs, Scalar > &vector)
 Take a scalar or vector and map it onto a vector.
template<int SizeLhs, typename Scalar>
Vector< SizeLhs, Scalar > expandOrSlice (const Scalar &scalar)
 Delegates to slice().
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator+= (Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Adds rVector to lVector and assigns the result to lVector.
template<int Size, typename Scalar>
Vector< Size, Scalar > & operator-= (Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Subtracts rVector from lVector and assigns the result to lVector.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator+ (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Adds rVector to lVector.
template<int Size, typename Scalar>
Vector< Size, Scalar > operator- (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Subtracts rVector from lVector.
template<int Size, typename Scalar>
Vector< Size, Scalar > multiplyComponents (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Multiplies every component of the vectors with each other and writes the results into result.
template<int Size, typename Scalar>
Scalar operator* (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Performs the dot (=inner) product of two vectors.
template<int Size, typename Scalar>
Scalar dot (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Performs the dot (=inner) product of two vectors.
template<int Size, typename Scalar>
Scalar innerDot (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Performs the dot (=inner) product of two vectors.
template<typename Scalar>
Vector< 3, Scalar > cross (const Vector< 3, Scalar > &lhs, const Vector< 3, Scalar > &rhs)
 Performs the cross product of two 3D vectors into result.
template<int Size, typename Scalar>
bool equals (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Compares to vectors on equality by means of a numerical accuracy.
template<int Size, typename Scalar>
bool firstGreater (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Compares sequentially every component pair of lVector and rVector, and stops as soon as one is greater than the other.
template<int Size, typename Scalar>
bool oneGreater (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Returns true, if one component of lVector is greater than the corresponding component in rVector up to numerical accuracy.
template<int Size, typename Scalar>
bool oneGreaterEquals (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Returns true, if one component of lVector is greater or equals than the corresponding component in rVector up to numerical accuracy.
template<int Size, typename Scalar>
bool allGreater (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Returns true, if all components of lVector are greater than the corresponding components in rVector up to numerical accuracy.
template<int Size, typename Scalar>
bool allGreaterEquals (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Returns true, if all components of lVector are greater or equals than the corresponding components in rVector up to numerical accuracy.
template<int Size, typename Scalar>
bool allSmaller (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool allSmallerEquals (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneSmaller (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
bool oneSmallerEquals (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
template<int Size, typename Scalar>
Vector< Size, Scalar > max (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Component-wise max evaluation.
template<int Size, typename Scalar>
Vector< Size, Scalar > min (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Component-wise min evaluation.
template<int Size, typename Scalar>
bool operator== (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Bit-wise comparison of the components of two vectors for equality.
template<int Size, typename Scalar>
bool operator!= (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs)
 Bit-wise comparison of the components of two vectors for inequality.
template<int Size, typename Scalar>
int equalsReturnIndex (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
 Return Index of element which is not equals.
template<int Size>
int equalsReturnIndex (const Vector< Size, int > &lhs, const Vector< Size, int > &rhs)
template<int Size>
int countEqualEntries (const Vector< Size, int > &lhs, const Vector< Size, int > &rhs)
 Run through both vectors and count how many entries are the same.
template<int Size, typename Scalar>
int countEqualEntries (const Vector< Size, Scalar > &lhs, const Vector< Size, Scalar > &rhs, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)

Variables

constexpr double PI = 3.1415926535897932384626433832795028841972
constexpr double E = 2.7182818284590452353602874713526624977572
constexpr double NUMERICAL_ZERO_DIFFERENCE = 1.0e-8

Detailed Description

My collection of tiny vector operations.

The coolest thing about this one is that it supports Matlab/Python-ensque vector notations. Otherwise, it is pretty trivial.

Function Documentation

◆ abs() [1/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::abs ( const Vector< Size, Scalar > & vector)

Computes the absolute component values of the vector, creating a temporary vector to hold the result.

Returns
A copy of the temporary holding the result.

◆ abs() [2/2]

template<int Size>
Vector< Size, double > tarch::la::abs ( const Vector< Size, std::complex< double > > & vector)

Specialisation that is different to standard definition.

Works as result type is not part of the signature

◆ allEntriesAreTheSame()

template<int Size, typename Scalar>
bool tarch::la::allEntriesAreTheSame ( const Vector< Size, Scalar > & vector)

◆ allGreater() [1/3]

template<int Size>
bool tarch::la::allGreater ( const Vector< Size, int > & lhs,
const int & cmp )

◆ allGreater() [2/3]

template<int Size, typename Scalar>
bool tarch::la::allGreater ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ allGreater() [3/3]

template<int Size, typename Scalar>
bool tarch::la::allGreater ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Returns true, if all components of lVector are greater than the corresponding components in rVector up to numerical accuracy.

Parameters
toleranceAbsolute tolerance. If you prefer to use a relative measure, you might want to use tarch::la::relativeEps()

References NUMERICAL_ZERO_DIFFERENCE.

◆ allGreaterEquals() [1/3]

template<int Size>
bool tarch::la::allGreaterEquals ( const Vector< Size, int > & lhs,
const int & cmp )

◆ allGreaterEquals() [2/3]

template<int Size, typename Scalar>
bool tarch::la::allGreaterEquals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ allGreaterEquals() [3/3]

template<int Size, typename Scalar>
bool tarch::la::allGreaterEquals ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Returns true, if all components of lVector are greater or equals than the corresponding components in rVector up to numerical accuracy.

References NUMERICAL_ZERO_DIFFERENCE.

◆ allSmaller() [1/3]

template<int Size>
bool tarch::la::allSmaller ( const Vector< Size, int > & lhs,
const int & cmp )

◆ allSmaller() [2/3]

template<int Size, typename Scalar>
bool tarch::la::allSmaller ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ allSmaller() [3/3]

template<int Size, typename Scalar>
bool tarch::la::allSmaller ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ allSmallerEquals() [1/3]

template<int Size>
bool tarch::la::allSmallerEquals ( const Vector< Size, int > & lhs,
const int & cmp )

◆ allSmallerEquals() [2/3]

template<int Size, typename Scalar>
bool tarch::la::allSmallerEquals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ allSmallerEquals() [3/3]

template<int Size, typename Scalar>
bool tarch::la::allSmallerEquals ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ average()

template<int Size, typename Scalar>
Scalar tarch::la::average ( const Vector< Size, Scalar > & vector)

Computes the volume of the tetrahedron spanned by the Cartesian unit vectors scaled by the corresponding components of the given vector.

◆ backSubstitution() [1/2]

void tarch::la::backSubstitution ( const DynamicMatrix & R,
const double * f,
double * x )

◆ backSubstitution() [2/2]

template<int Rows, typename Scalar>
Vector< Rows, Scalar > tarch::la::backSubstitution ( const Matrix< Rows, Rows, Scalar > & R,
const Vector< Rows, Scalar > & f )

Back substitution following LU decomposition.

Accepts an upper triangular matrix and a rhs. It then returns the solution x to \( Rx=f \) i.e. \( x=R^{-1}f \). We assume that R is a proper, non-normalised upper triangular matrix. It does not have to have 1s on the diagonals.

Parameters
Rthe upper matrix from the LU decomposition

◆ buildMatrix()

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::buildMatrix ( const Scalar * values)

Deep copy builder function.

Become friend of builder mechanism.

We faced issues with some compiler versions with offering a constructor that simply takes a pointer to scalars. Further to that, it is not clear if such a constructor would create a deep copy or a shallow copy. Therefore, I decided to introduce an explicit builder function.

◆ col()

template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > tarch::la::col ( const Matrix< Rows, Cols, Scalar > & matrix,
int whichColumn )

◆ contains()

template<int Size, typename Scalar>
bool tarch::la::contains ( const Vector< Size, Scalar > & vector,
const Scalar & value )

◆ convertAbsoluteIntoRelativeValue()

double tarch::la::convertAbsoluteIntoRelativeValue ( double referenceValue,
double value )

Convert an absolute value into a relative one.

That is if the referenceValue is smaller than one, then we do nothing. Otherwise, we divide the absolute value by the reference value.

◆ convertScalar() [1/2]

template<typename NewScalarType, int Size, typename Scalar>
tarch::la::SmartPointerVector< Size, NewScalarType > tarch::la::convertScalar ( const tarch::la::SmartPointerVector< Size, Scalar > & SmartPointerVector)

◆ convertScalar() [2/2]

template<typename NewScalarType, int Size, typename Scalar>
tarch::la::Vector< Size, NewScalarType > tarch::la::convertScalar ( const tarch::la::Vector< Size, Scalar > & vector)

Convert the scalar type underlying a vector.

This routine takes a vector of size Size over type Scalar and returns a new vector of the same size but with type NewScalarType. A typical usage looks similar to

tarch::la::Vector< Dimensions, double > converted =
tarch::la::SmartPointerVector< Size, NewScalarType > convertScalar(const tarch::la::SmartPointerVector< Size, Scalar > &SmartPointerVector)

The conversion assumes that C++ natively supports a conversion from Scalar to NewScalarType. We do not employ any explicit typecasting under the hood.

◆ count()

template<int Size, typename Scalar>
int tarch::la::count ( const Vector< Size, Scalar > & vector,
const Scalar & value )

◆ countEqualEntries() [1/2]

template<int Size>
int tarch::la::countEqualEntries ( const Vector< Size, int > & lhs,
const Vector< Size, int > & rhs )

Run through both vectors and count how many entries are the same.

◆ countEqualEntries() [2/2]

template<int Size, typename Scalar>
int tarch::la::countEqualEntries ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ cross()

template<typename Scalar>
Vector< 3, Scalar > tarch::la::cross ( const Vector< 3, Scalar > & lhs,
const Vector< 3, Scalar > & rhs )

Performs the cross product of two 3D vectors into result.

◆ det() [1/2]

template<typename Scalar>
double tarch::la::det ( const Matrix< 2, 2, Scalar > & R)

◆ det() [2/2]

template<typename Scalar>
double tarch::la::det ( const Matrix< 3, 3, Scalar > & R)

◆ diag()

template<int Rows, typename Scalar>
Vector< Rows, Scalar > tarch::la::diag ( const Matrix< Rows, Rows, Scalar > & matrix)

Extract diagonal vector from matrix.

◆ dot()

template<int Size, typename Scalar>
Scalar tarch::la::dot ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Performs the dot (=inner) product of two vectors.

For the outer dot product consult the file MatrixVectorOperations.h.

◆ elementMax()

template<int Rows, int Cols, typename Scalar>
Scalar tarch::la::elementMax ( const Matrix< Rows, Cols, Scalar > & matrix)

Max norm.

◆ equals() [1/4]

template<int Rows, int Cols, typename Scalar>
bool tarch::la::equals ( const Matrix< Rows, Cols, Scalar > & lhs,
const Matrix< Rows, Cols, Scalar > & rhs,
const Scalar & tolerance = NUMERICAL_ZERO_DIFFERENCE )

Compares to matrices on equality by means of a numerical accuracy.

References NUMERICAL_ZERO_DIFFERENCE.

Referenced by tarch::la::DynamicMatrix::operator==(), exahype2::removeTimeStepAccumulationErrorsFromCell(), and exahype2::runTimeStepOnCell().

Here is the caller graph for this function:

◆ equals() [2/4]

template<int Size>
bool tarch::la::equals ( const Vector< Size, int > & lhs,
const int & cmp )

Specialisation for int.

◆ equals() [3/4]

template<int Size, typename Scalar>
bool tarch::la::equals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

!

!! Vectorisation remark

The Intel compiler refuses to vectorise these code fragments if they exit early. As a consequence, we have to remove early exit instructions though they might be faster for very long vectors. In Peano, vectors typically are pretty short and thus we have no early exit condition if you use the Intel compiler.

References NUMERICAL_ZERO_DIFFERENCE.

◆ equals() [4/4]

template<int Size, typename Scalar>
bool tarch::la::equals ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Compares to vectors on equality by means of a numerical accuracy.

Parameters
toleranceAbsolute tolerance. If you prefer to use a relative measure, you might want to use tarch::la::relativeEps()

References NUMERICAL_ZERO_DIFFERENCE.

◆ equalsReturnIndex() [1/3]

template<int Rows, int Cols, typename Scalar>
std::pair< int, int > tarch::la::equalsReturnIndex ( const Matrix< Rows, Cols, Scalar > & lhs,
const Matrix< Rows, Cols, Scalar > & rhs,
const Scalar & tolerance = NUMERICAL_ZERO_DIFFERENCE )

Return Index of element which is not equals.

References NUMERICAL_ZERO_DIFFERENCE.

◆ equalsReturnIndex() [2/3]

template<int Size>
int tarch::la::equalsReturnIndex ( const Vector< Size, int > & lhs,
const Vector< Size, int > & rhs )

◆ equalsReturnIndex() [3/3]

template<int Size, typename Scalar>
int tarch::la::equalsReturnIndex ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Return Index of element which is not equals.

References NUMERICAL_ZERO_DIFFERENCE.

◆ expandOrSlice() [1/2]

template<int SizeLhs, typename Scalar>
Vector< SizeLhs, Scalar > tarch::la::expandOrSlice ( const Scalar & scalar)

Delegates to slice().

See also
expandOrSlice()

◆ expandOrSlice() [2/2]

template<int SizeLhs, int SizeRhs, typename Scalar>
Vector< SizeLhs, Scalar > tarch::la::expandOrSlice ( const Vector< SizeRhs, Scalar > & vector)

Take a scalar or vector and map it onto a vector.

expandOrSlice() is a variant of the slice() operation that I need within for loops, e.g.. It is either given a scalar or a vector with N' entries, and it delivers a vector with N entries. N<N'. That is, if we hand in a scalar, expandOrSlice() expands it into a proper vector. It maps expandOrSlide() onto the constructor with one scalar argument. If we pass in a vector, it slices, i.e. takes the first N entries of this vector to create a new one. The case distinction is realised via overloading.

This version here equals slice().

◆ firstGreater()

template<int Size, typename Scalar>
bool tarch::la::firstGreater ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Compares sequentially every component pair of lVector and rVector, and stops as soon as one is greater than the other.

Defines an absolute pairwise ordering between (unequal) vectors.

Parameters
toleranceAbsolute tolerance. If you prefer to use a relative measure, you might want to use tarch::la::relativeEps()

References NUMERICAL_ZERO_DIFFERENCE.

Referenced by tarch::la::VectorCompare< N >::operator()().

Here is the caller graph for this function:

◆ frobeniusNorm()

template<int Rows, int Cols, typename Scalar>
Scalar tarch::la::frobeniusNorm ( const Matrix< Rows, Cols, Scalar > & matrix)

◆ identity()

template<int Rows, typename Scalar>
Matrix< Rows, Rows, Scalar > tarch::la::identity ( )
static

Returns the identity matrix.

◆ imag()

template<int Size>
Vector< Size, double > tarch::la::imag ( const Vector< Size, std::complex< double > > & vector)

◆ indexMax()

template<int Size, typename Scalar>
int tarch::la::indexMax ( const Vector< Size, Scalar > & vector)

Returns the index of the element with maximal value (NOT absolute value).

◆ indexMin()

template<int Size, typename Scalar>
int tarch::la::indexMin ( const Vector< Size, Scalar > & vector)

Returns the index of the element with minimal value (NOT absolute value).

◆ innerDot()

template<int Size, typename Scalar>
Scalar tarch::la::innerDot ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Performs the dot (=inner) product of two vectors.

For the outer dot product consult the file MatrixVectorOperations.h.

◆ invert() [1/3]

template<typename Scalar>
Matrix< 2, 2, Scalar > tarch::la::invert ( const Matrix< 2, 2, Scalar > & M)

Specialisation of inversion.

This one inverts directly and is usually faster than BLAS.

◆ invert() [2/3]

template<typename Scalar>
Matrix< 3, 3, Scalar > tarch::la::invert ( const Matrix< 3, 3, Scalar > & M)

Specialisation of inversion.

This one inverts directly and is usually faster than BLAS.

◆ invert() [3/3]

template<int Rows, typename Scalar>
Matrix< Rows, Rows, Scalar > tarch::la::invert ( const Matrix< Rows, Rows, Scalar > & M)

Invert matrix with LU decomposition.

We first invoke the LU decomposition through a call to lu(). After that, we compute the mat vec and return the result. This is not an optimised version in any way. For small matrices, it should be pretty fast. For larger matrices, you might want to consider the Lapack version available through the alternative invert() version.

◆ invertEntries() [1/2]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::invertEntries ( const Matrix< Rows, Cols, Scalar > & matrix)

Inverts each individual entry.

Works if and only if the matrix does not contain any zeroes, as this routine yields

\( A_{ij} \gets A_{ij}^{-1} \)

which is not \( A^{-1} \). If you want to have the inverse, you have to look, for example, into LUDecomposition.

See also
tarch::la::invert()

◆ invertEntries() [2/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::invertEntries ( const Vector< Size, Scalar > & vector)

◆ invertUpperTriangular()

DynamicMatrix tarch::la::invertUpperTriangular ( const DynamicMatrix & R)

◆ isEntryFinite()

template<int Size, typename Scalar>
int tarch::la::isEntryFinite ( const Vector< Size, Scalar > & vector)

◆ isEntryNan()

template<int Size, typename Scalar>
int tarch::la::isEntryNan ( const Vector< Size, Scalar > & vector)

◆ lu() [1/2]

template<int Rows, typename Scalar>
void tarch::la::lu ( Matrix< Rows, Rows, Scalar > & A)

In-situ LU without pivoting.

See the other LU routine.

◆ lu() [2/2]

template<int Rows, typename Scalar>
void tarch::la::lu ( Matrix< Rows, Rows, Scalar > & A,
Vector< Rows, int > & pivots )

Performs an in-situ LU-decomposition of the square matrix A.

Returns pivot values, too. The storage format is normalised such that the diagonal values of the lower triangular matrix are one.

◆ matVec()

template<int Rows, int Cols, typename Scalar>
void tarch::la::matVec ( const Matrix< Rows, Cols, Scalar > & matrix,
Scalar alpha,
const Vector< Cols, Scalar > & v,
Vector< Rows, Scalar > & r )

Compute r = r + alpha * M * v in-situ.

◆ max() [1/3]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::max ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Component-wise max evaluation.

◆ max() [2/3]

template<int Size, typename Scalar>
Scalar tarch::la::max ( const Vector< Size, Scalar > & vector)

Returns the element with maximal value (NOT absolute value).

◆ max() [3/3]

double tarch::la::max ( double a,
double b,
double c )

I need the maximum of three values all the time, to I decided to write a function for this.

◆ maxAbs()

template<int Size, typename Scalar>
Scalar tarch::la::maxAbs ( const Vector< Size, Scalar > & vector)

Returns the element with maximal absolute value.

◆ maxImag()

template<int Size>
double tarch::la::maxImag ( const Vector< Size, std::complex< double > > & vector)

◆ maxReal()

template<int Size>
double tarch::la::maxReal ( const Vector< Size, std::complex< double > > & vector)

◆ min() [1/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::min ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Component-wise min evaluation.

◆ min() [2/2]

template<int Size, typename Scalar>
Scalar tarch::la::min ( const Vector< Size, Scalar > & vector)

Returns the element with minimal value (NOT absolute value).

Referenced by exaparty::kernels::legacy::updateSmoothingLengthAndRerunIfRequired().

Here is the caller graph for this function:

◆ modifiedGramSchmidt() [1/2]

void tarch::la::modifiedGramSchmidt ( DynamicMatrix A,
DynamicMatrix & Q,
DynamicMatrix & R )

◆ modifiedGramSchmidt() [2/2]

template<int Rows, int Cols, typename Scalar>
void tarch::la::modifiedGramSchmidt ( Matrix< Rows, Cols, Scalar > A,
Matrix< Rows, Cols, Scalar > & Q,
Matrix< Cols, Cols, Scalar > & R )

Produces an economy-size QR decomposition of a matrix A, A is changed.

Preconditions:

  • The column vectors of A have to be linear independent.
  • If A has n columns and m rows, then:
    • n <= m for A
    • Q has to have same size than A
    • R has to be a n * n matrix

Postconditions:

  • A is changed
  • Q holds an orthonormal basis of range(A) in its column vectors.
  • R is an upper triangular matrix, with all main diagonal element unequal to zero iff A has full rank.

The algorithm is taken from the book Numerical Mathematics, Second Edition, by Alfio Querteroni, Riccardo Sacco, and Fausto Saleri, Springer, 2007, pages 85-87.

Classic usage:

modifiedGramSchmidt(M, Q, R); tarch::la::Vector<9, double> p = tarch::la::backSubstitution(R,tarch::la::transpose(Q)*f);

◆ multiply() [1/4]

template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > tarch::la::multiply ( const Matrix< Rows, Cols, Scalar > & matrix,
const Vector< Cols, Scalar > & vector )

Performs a matrix x vector multiplication.

The result vector has to be created outside and given as a parameter.

◆ multiply() [2/4]

template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::multiply ( const Matrix< Rows, X, Scalar > & lhs,
const Matrix< X, Cols, Scalar > & rhs )

Performs a matrix x matrix multiplication.

The resulting matrix has to be created outside and given as a parameter.

◆ multiply() [3/4]

template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > tarch::la::multiply ( const ShallowMatrix< Rows, Cols, Scalar > & matrix,
const SmartPointerVector< Cols, Scalar > & vector )

◆ multiply() [4/4]

template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > tarch::la::multiply ( const ShallowMatrix< Rows, Cols, Scalar > & matrix,
const Vector< Cols, Scalar > & vector )

Performs a matrix x vector multiplication.

The result vector has to be created outside and given as a parameter.

◆ multiplyComponents() [1/2]

template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::multiplyComponents ( const Matrix< Rows, X, Scalar > & lhs,
const Matrix< X, Cols, Scalar > & rhs )

◆ multiplyComponents() [2/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::multiplyComponents ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Multiplies every component of the vectors with each other and writes the results into result.

◆ norm1() [1/2]

template<int Size, typename Scalar>
Scalar tarch::la::norm1 ( const Vector< Size, Scalar > & vector)

Computes the 1-norm of the vector, i.e.

it sums up abs. component values.

◆ norm1() [2/2]

template<int Size>
double tarch::la::norm1 ( const Vector< Size, std::complex< double > > & vector)

Specialisation that is different to standard definition.

Works as result type is not part of the signature

◆ norm2() [1/2]

template<int Size, typename Scalar>
Scalar tarch::la::norm2 ( const Vector< Size, Scalar > & vector)

Computes the 2-norm of the vector, i.e.

it takes the square-root of summed up squared component values.

◆ norm2() [2/2]

template<int Size>
double tarch::la::norm2 ( const Vector< Size, std::complex< double > > & vector)

Specialisation that is different to standard definition.

Works as result type is not part of the signature

◆ norm2Squared() [1/2]

template<int Size, typename Scalar>
Scalar tarch::la::norm2Squared ( const Vector< Size, Scalar > & vector)

◆ norm2Squared() [2/2]

template<int Size>
double tarch::la::norm2Squared ( const Vector< Size, std::complex< double > > & vector)

◆ normMax() [1/2]

template<int Size, typename Scalar>
Scalar tarch::la::normMax ( const Vector< Size, Scalar > & vector)

Computes the max-norm of the vector.

◆ normMax() [2/2]

template<int Size>
double tarch::la::normMax ( const Vector< Size, std::complex< double > > & vector)

Specialisation that is different to standard definition.

Works as result type is not part of the signature

◆ oneEquals() [1/2]

template<int Size>
bool tarch::la::oneEquals ( const Vector< Size, int > & lhs,
const int & cmp )

◆ oneEquals() [2/2]

template<int Size, typename Scalar>
bool tarch::la::oneEquals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneGreater() [1/3]

template<int Size>
bool tarch::la::oneGreater ( const Vector< Size, int > & lhs,
const int & cmp )

◆ oneGreater() [2/3]

template<int Size, typename Scalar>
bool tarch::la::oneGreater ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneGreater() [3/3]

template<int Size, typename Scalar>
bool tarch::la::oneGreater ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Returns true, if one component of lVector is greater than the corresponding component in rVector up to numerical accuracy.

Parameters
toleranceAbsolute tolerance. If you prefer to use a relative measure, you might want to use tarch::la::relativeEps()

References NUMERICAL_ZERO_DIFFERENCE.

◆ oneGreaterEquals() [1/3]

template<int Size>
bool tarch::la::oneGreaterEquals ( const Vector< Size, int > & lhs,
const int & cmp )

◆ oneGreaterEquals() [2/3]

template<int Size, typename Scalar>
bool tarch::la::oneGreaterEquals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneGreaterEquals() [3/3]

template<int Size, typename Scalar>
bool tarch::la::oneGreaterEquals ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

Returns true, if one component of lVector is greater or equals than the corresponding component in rVector up to numerical accuracy.

References NUMERICAL_ZERO_DIFFERENCE.

◆ oneSmaller() [1/3]

template<int Size>
bool tarch::la::oneSmaller ( const Vector< Size, int > & lhs,
const int & cmp )

◆ oneSmaller() [2/3]

template<int Size, typename Scalar>
bool tarch::la::oneSmaller ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneSmaller() [3/3]

template<int Size, typename Scalar>
bool tarch::la::oneSmaller ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneSmallerEquals() [1/3]

template<int Size>
bool tarch::la::oneSmallerEquals ( const Vector< Size, int > & lhs,
const int & cmp )

◆ oneSmallerEquals() [2/3]

template<int Size, typename Scalar>
bool tarch::la::oneSmallerEquals ( const Vector< Size, Scalar > & lhs,
const Scalar & cmp,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ oneSmallerEquals() [3/3]

template<int Size, typename Scalar>
bool tarch::la::oneSmallerEquals ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs,
const Scalar tolerance = NUMERICAL_ZERO_DIFFERENCE )

◆ operator!=()

template<int Size, typename Scalar>
bool tarch::la::operator!= ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Bit-wise comparison of the components of two vectors for inequality.

This method should not be used for floating-point valued vectors. Instead, !equals() is the suitable comparison.

◆ operator*() [1/8]

template<int Rows, int Cols>
Matrix< Rows, Cols, std::complex< double > > tarch::la::operator* ( const double & scalar,
const Matrix< Rows, Cols, std::complex< double > > & matrix )

◆ operator*() [2/8]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::operator* ( const Matrix< Rows, Cols, Scalar > & matrix,
const Scalar & scalar )

Multiplies every component of the matrix with the scalar.

No temporary objects are created during the operation.

◆ operator*() [3/8]

template<int Rows, int Cols, typename Scalar>
Vector< Rows, Scalar > tarch::la::operator* ( const Matrix< Rows, Cols, Scalar > & matrix,
const Vector< Cols, Scalar > & vector )

Performs a matrix x vector multiplication.

The result vector is created inside, multiply is used to execute the multiplication.

◆ operator*() [4/8]

template<int Rows, int Cols, int X, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::operator* ( const Matrix< Rows, X, Scalar > & lhs,
const Matrix< X, Cols, Scalar > & rhs )

◆ operator*() [5/8]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::operator* ( const Scalar & scalar,
const Matrix< Rows, Cols, Scalar > & matrix )

Multiplies every component of the matrix with the scalar.

No temporary objects are created during the operation.

◆ operator*() [6/8]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator* ( const Scalar & scalar,
const Vector< Size, Scalar > & vector )

◆ operator*() [7/8]

template<int Size, typename Scalar>
Scalar tarch::la::operator* ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Performs the dot (=inner) product of two vectors.

For the outer dot product consult the file MatrixVectorOperations.h.

◆ operator*() [8/8]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator* ( const Vector< Size, Scalar > & vector,
const Scalar & scalar )

Multiplies every component of the vector with the scalar and returns the result.

A temporary vector is created during the operation and copied as result.

◆ operator*=() [1/2]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > & tarch::la::operator*= ( Matrix< Rows, Cols, Scalar > & matrix,
const Scalar & scalar )

◆ operator*=() [2/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator*= ( Vector< Size, Scalar > & vector,
const Scalar & scalar )

Multiplies every component of the vector with the scalar and assigns the result to the vector.

No temporary objects are created during the operation.

◆ operator+() [1/4]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::operator+ ( const Matrix< Rows, Cols, Scalar > & lhs,
const Matrix< Rows, Cols, Scalar > & rhs )

◆ operator+() [2/4]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator+ ( const Scalar & scalar,
const Vector< Size, Scalar > & vector )

◆ operator+() [3/4]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator+ ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Adds rVector to lVector.

A temporary vector is created and copied to store return back the result.

◆ operator+() [4/4]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator+ ( const Vector< Size, Scalar > & vector,
const Scalar & scalar )

Adds the scalar to every component of the vector and returns the result.

A temporary vector is created during the operation and copied as result.

◆ operator+=() [1/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator+= ( Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Adds rVector to lVector and assigns the result to lVector.

No temporary vector is created.

◆ operator+=() [2/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator+= ( Vector< Size, Scalar > & vector,
const Scalar & scalar )

Adds every component of the vector to the scalar and assigns the result to the vector.

No temporary objects are created during the operation.

◆ operator-() [1/3]

template<int Rows, int Cols, typename Scalar>
Matrix< Rows, Cols, Scalar > tarch::la::operator- ( const Matrix< Rows, Cols, Scalar > & lhs,
const Matrix< Rows, Cols, Scalar > & rhs )

◆ operator-() [2/3]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator- ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Subtracts rVector from lVector.

A temporary vector is created and copied to store return back the result.

◆ operator-() [3/3]

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator- ( const Vector< Size, Scalar > & vector,
const Scalar & scalar )

Subtracts the scalar from every component of the vector and returns the result.

A temporary vector is created during the operation and copied as result.

◆ operator-=() [1/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator-= ( Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Subtracts rVector from lVector and assigns the result to lVector.

No temporary vector is created.

◆ operator-=() [2/2]

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator-= ( Vector< Size, Scalar > & vector,
const Scalar & scalar )

Subtracts the scalar from every component of the vector and assigns the result to the vector.

No temporary objects are created during the operation.

◆ operator/()

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::operator/ ( const Vector< Size, Scalar > & vector,
const Scalar & scalar )

Divides every component of the vector by the scalar and returns the result.

A temporary vector is created during the operation and copied as result.

◆ operator/=()

template<int Size, typename Scalar>
Vector< Size, Scalar > & tarch::la::operator/= ( Vector< Size, Scalar > & vector,
const Scalar & scalar )

Divides every component of the vector by the scalar and assigns the result to the vector.

No temporary objects are created during the operation.

◆ operator==() [1/2]

template<int Rows, int Cols, typename Scalar>
bool tarch::la::operator== ( const Matrix< Rows, Cols, Scalar > & lhs,
const Matrix< Rows, Cols, Scalar > & rhs )

Bitwise comparison of the components of two matrices on equality.

◆ operator==() [2/2]

template<int Size, typename Scalar>
bool tarch::la::operator== ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Bit-wise comparison of the components of two vectors for equality.

This method should not be used for floating-point valued vectors. Instead, equals() is the suitable comparison.

◆ outerDot()

template<int Size, typename Scalar>
Matrix< Size, Size, Scalar > tarch::la::outerDot ( const Vector< Size, Scalar > & lhs,
const Vector< Size, Scalar > & rhs )

Outer dot product.

◆ pow()

double tarch::la::pow ( double base,
double exponent )

Wrapper around std::pow which is redirected to Intel's implementation on Intel machines.

◆ real()

template<int Size>
Vector< Size, double > tarch::la::real ( const Vector< Size, std::complex< double > > & vector)

◆ relativeEps()

double tarch::la::relativeEps ( double valueA,
double valueB = std::numeric_limits< double >::min(),
double eps = NUMERICAL_ZERO_DIFFERENCE )

Determine a relative tolerance from one or two values.

This routine takes eps and scales it with the maximum of the absolute values of the arguments.

The version with two arguments can be seen as wrapper around a 'scalar' relativeEps() variant which forwards the bigger value. This is very often used in combination with the greater and smaller macros, where you wanna compare prescribing a comparison tolerance.

If you have only one argument, set valueB=valueA.

References NUMERICAL_ZERO_DIFFERENCE.

◆ relativeEpsNormalisedAgainstValueGreaterOne()

double tarch::la::relativeEpsNormalisedAgainstValueGreaterOne ( double valueA,
double valueB = std::numeric_limits< double >::min(),
double eps = NUMERICAL_ZERO_DIFFERENCE )

Determine a relative tolerance from one or two values.

This routine equals relativeEps, but if the normalisation quantities become smaller than 1.0, then we pick eps instead of eps times this value smaller than 1.0. So basically the normalisation with valueA (and valueB) kicks in iff the bigger value of the two is bigger than 1.0.

References NUMERICAL_ZERO_DIFFERENCE.

◆ remainder()

template<int Size, typename Scalar>
Vector< Size, Scalar > tarch::la::remainder ( const Vector< Size, Scalar > & vector,
double h )

Return the remainder of a division.

Per component x_i, the function computes x_i/h and then returns the remaining fraction of x_i which did not fit into h. The function therefore resembles modulo.

◆ row()

template<int Rows, int Cols, typename Scalar>
Vector< Cols, Scalar > tarch::la::row ( const Matrix< Rows, Cols, Scalar > & matrix,
int whichRow )

◆ slice() [1/2]

template<int SizeLhs, int SizeRhs, typename Scalar>
Vector< SizeLhs, Scalar > tarch::la::slice ( const Vector< SizeRhs, Scalar > & vector,
int fromIndex,
int stride = 1 )

Returns subpart of the vector.

The name is due to historical reasons and compability with Bernhard Gatzhammer's PreCiSE code. But the implementation is extended such that one can also retrieve discontinuous parts of a vector.

!!! Examples

Take first 3 element from a vector:

Vector< SizeLhs, Scalar > slice(const Vector< SizeRhs, Scalar > &vector, int fromIndex, int stride=1)
Returns subpart of the vector.

Take the elements 2,3,5,6 from a vector:

tarch::la::slice<3>(myVector,2,2)

◆ slice() [2/2]

template<int SizeLhs, int SizeRhs, typename Scalar>
void tarch::la::slice ( Vector< SizeLhs, Scalar > & toVector,
const Vector< SizeRhs, Scalar > & fromVector,
int fromIndexInToVector,
int strideInToVector = 1 )

Setter.

◆ sum() [1/2]

template<int Rows, int Cols, typename Scalar>
Scalar tarch::la::sum ( const Matrix< Rows, Cols, Scalar > & matrix)

Computes the sum of all entries of the matrix.

◆ sum() [2/2]

template<int Size, typename Scalar>
Scalar tarch::la::sum ( const Vector< Size, Scalar > & vector)

Sums up the component values of the vector.

◆ toSTLVector()

template<int Size, typename Scalar>
std::vector< Scalar > tarch::la::toSTLVector ( const Vector< Size, Scalar > & vector)

◆ transpose() [1/2]

DynamicMatrix tarch::la::transpose ( const DynamicMatrix & matrix)

◆ transpose() [2/2]

template<int Rows, int Cols, typename Scalar>
Matrix< Cols, Rows, Scalar > tarch::la::transpose ( const Matrix< Rows, Cols, Scalar > & matrix)

◆ volume()

template<int Size, typename Scalar>
Scalar tarch::la::volume ( const Vector< Size, Scalar > & vector)

Computes the volume of the tetrahedron spanned by the Cartesian unit vectors scaled by the corresponding components of the given vector.

Variable Documentation

◆ E

double tarch::la::E = 2.7182818284590452353602874713526624977572
constexpr

Definition at line 13 of file Scalar.h.

◆ NUMERICAL_ZERO_DIFFERENCE

◆ PI

double tarch::la::PI = 3.1415926535897932384626433832795028841972
constexpr

Definition at line 12 of file Scalar.h.