The Vish Visualization Shell 0.3
Vish
Public Types | Public Member Functions | Related Symbols | List of all members
Eagle::Matrix< R, C, Value > Class Template Reference

Simple matrix class for performing fast operations on matrices of sizes known at compile-time. More...

#include <elementary/eagle/Matrix.hpp>

Inheritance diagram for Eagle::Matrix< R, C, Value >:
Eagle::Vector< Value, R *C > Eagle::FixedArray< value, N > Eagle::Quadratic< N, value > Eagle::Quadratic< 2, float > Eagle::Quadratic< 3, float > Eagle::Quadratic< 4, float > Eagle::GaussSolver< N, value >

Public Types

using Matrix_t = Matrix
 Matrix type.
 
- Public Types inherited from Eagle::Vector< Value, R *C >
enum  
 The number of elements in this array.
 
- Public Types inherited from Eagle::FixedArray< value, N >
typedef FlattenedArray_t::value_type Element_t
 The maximally reduced type of elements stored here.
 
typedef GetFixedArrayType< value >::result_t ElementAsFixedArray_t
 Element type as fixed array, if it is convertible to a fixed array.
 
typedef FixedArray FixedArray_t
 Exporting the type definition of this array cass type.
 
typedef FixedArrayFlattener< FixedArrayOfElements_tFixedArrayFlattener_t
 Internal helper class.
 
typedef FixedArray< ElementAsFixedArray_t, N > FixedArrayOfElements_t
 If the value is derived from a fixed array type itself, then the FixedArrayOfElements_t is an FixedArray<FixedArray<>> type.
 
typedef FixedArrayFlattener_t::result_t FlattenedArray_t
 Reduction of this array type, if it is nested, to an flattened type which contains elementary types.
 
typedef value value_type
 Export the type of the respective element value type.
 

Public Member Functions

constexpr const Matrix_tmatrix () const
 yield matrix here, useful for derived classes.
 
Constructors
constexpr Matrix ()
 Default constructor.
 
constexpr Matrix (const Matrix &M)
 Copy constructor.
 
constexpr Matrix (const Base_t &V)
 Construct matrix from linear vector.
 
template<class T >
constexpr Matrix (const std::array< T, 16 > &Init)
 Construct matrix from initializer list.
 
- Public Member Functions inherited from Eagle::Vector< Value, R *C >
Base_tfixed_array ()
 Provide access to the base class, writable.
 
const Base_tfixed_array () const
 Provide access to the base class, read-only.
 
Vectoroperator*= (const Value &value)
 Self-multiplication.
 
Vectoroperator+= (const Vector &v)
 Self-addition.
 
Vector operator- () const
 Unary minus.
 
Vectoroperator-= (const Vector &v)
 Self-subtraction.
 
Vectoroperator/= (const Value &value)
 Self-division.
 
Assignment< Vector, 0 > operator= (const scalar &x)
 Assign first element with scalar and use consecutive comma expressions for assignment of further elements As such a Vector may be assigned as.
 
Vectoroperator= (const Vector &src)
 Assignment operator.
 
void set (const V &value)
 Assign all values to the same scalar.
 
constexpr Vector ()
 Default constructor.
 
 Vector (const FixedArray< AType, n > &l, const FixedArray< BType, n > &r, const Operator< CompType > &Op)
 Computational constructor for binary operations on two fixed arrays, calls the Operator's ternary() member function for each element.
 
 Vector (const FixedArray< AType, n > &l, const Operator< CompType > &, const ScalarType &scalar)
 Computational constructor from vector with scalar, calls the Operator's ternary() member function for each element and the scalar as its 3rd argument.
 
 Vector (const FixedArray< InputType, SIZE > &V)
 Type conversion constructor.
 
 Vector (const Indicable &I, const AnyType &)
 Construct from indicable object, i.e.
 
 Vector (const Operator< CompType > &, const ScalarType &scalar, const FixedArray< AType, n > &v)
 Computational constructor from scalar with vector calls the Operator's ternary() member function for each element and the scalar as its 2nd argument.
 
constexpr Vector (const std::initializer_list< InputType > &Init)
 Construct from a initialization array.
 
 Vector (const Value &a)
 Convenience Constructor: initialize the first element.
 
 Vector (const Value &a, const Value &b)
 Convenience Constructor: initialize the first two elements.
 
 Vector (const Value &a, const Value &b, const Value &c)
 Convenience Constructor: initialize the first three elements.
 
 Vector (const Value &a, const Value &b, const Value &c, const Value &d)
 Convenience Constructor: initialize the first four elements.
 
 Vector (const Vector &l, const Vector &r, const Operator< CompType > &)
 Computational constructor for binary operations on two vectors calls the Operator's ternary() member function for each element.
 
 Vector (const Vector &NV, const Sub &, const Sub &)
 Computational constructor for unary minus.
 
constexpr Vector (const Vector &v)
 Copy constructor.
 
 Vector (const Vector &v, const Operator<'-'> &)
 Unitary minus computational constructor Applies the unitary minus to each element.
 
 Vector (const Vector< InputType, SIZE > &V)
 Type conversion constructor.
 
- Public Member Functions inherited from Eagle::FixedArray< value, N >
void expandMinMax (FixedArray &MinValues, FixedArray &MaxValues) const
 Expand a range given by MinValues,MaxValues to include the values of this array, done per component.
 
constexpr FixedArray () noexcept
 Default constructor.
 
template<class AType , class BType , OperatorID_t CompType>
constexpr FixedArray (const FixedArray< AType, N > &l, const FixedArray< BType, N > &r, const Operator< CompType > &)
 Computational constructor for binary operations on two fixed arrays, calls the Operator's ternary() member function for each element.
 
template<typename T , dimension_t M>
constexpr FixedArray (const FixedArray< T, M > &F, const T &DefaultValue)
 Construct array from another array type of variable length.
 
template<typename T >
constexpr FixedArray (const FixedArray< T, N > &F)
 Automatic type conversion function.
 
template<typename T , typename ConversionFunctor >
constexpr FixedArray (const FixedArray< T, N > &F, const ConversionFunctor &CF, const FA_CONVERT &)
 Construct array from another array type of same length.
 
template<class InitType >
constexpr FixedArray (const std::initializer_list< InitType > &Init)
 Construct from a initialization array.
 
constexpr FixedArray (const value &a)
 Convenience Constructor: initialize the first element.
 
constexpr FixedArray (const value &a, const value &b)
 Convenience Constructor: initialize the first two elements.
 
 FixedArray (const value &a, const value &b, const value &c)
 Convenience Constructor: initialize the first three elements.
 
constexpr FixedArray (const value &a, const value &b, const value &c, const value &d)
 Convenience Constructor: initialize the first four elements.
 
constexpr FixedArray (const value &a, const value &b, const value &c, const value &d, const value &e)
 Convenience Constructor: initialize the first five elements.
 
constexpr value & get (int i)
 writable element access
 
constexpr const value & get (int i) const
 read-only element access
 
template<int subsize, int offset>
constexpr const FixedArray< value, subsize > * get_subarray () const
 Helper class for retrieve a subset of the current array.
 
constexpr const FixedArray< value, SIZE-1 > & get_subdim () const
 Mainly introduced because of Interpolate::operator[].
 
const FixedArray_tgetFixedArray () const noexcept
 convenience function for base classes
 
FixedArray_tgetFixedArray () noexcept
 convenience function for base classes
 
constexpr value getMax () const
 Compute the maximum element value of this array.
 
constexpr value getMin () const
 Compute the maximum element value of this array.
 
template<typename T >
constexpr bool operator!= (const FixedArray< T, N > &F) const
 Compare two arrays.
 
template<typename T >
constexpr bool operator== (const FixedArray< T, N > &F) const
 Compare two arrays.
 
constexpr value & operator[] (int i)
 writeable element access operator
 
constexpr const value & operator[] (int i) const
 read-only element access operator
 
constexpr value * ptr (int i=0) noexcept
 Return a pointer to the ith element, no range checking.
 
template<class Value >
constexpr void set (const Value &x)
 Set all array elements to the same value.
 
void setFromArray (const value *x, int length=SIZE, int offset=0)
 Set all array elements to an array's element value.
 
void sort (FixedArray< int, N > &I) const
 Sort the elements of an array into the index array.
 

Related Symbols

(Note that these are not member symbols.)

template<int N, class value >
void UnsortedEigenVectors (LowerTriangular< N, value > &A, Quadratic< N, value > &RRmatrix, Row< N, value > &E, double precision=1E-10)
 Eigenvalues and eigenvectors of a real symmetric matrix.
 

Arithmetic operations

typedef Operator<' *'> Mult
 Computational constructor argument for multiplicative operations.
 
typedef Operator<'~'> TransposeOperation
 Computational constructor argument for transpose operations.
 
constexpr Matrix (const Matrix &A, const Value &V, const Operator<' *'> &M)
 Computational constructor for multiplying matrix by scalar.
 
constexpr Matrix (const Value &V, const Matrix &A, const Operator<' *'> &M)
 Computational constructor for multiplying scalar by matrix.
 
constexpr Matrix (const Matrix &A, const Value &V, const Operator<'/'> &Op)
 Computational constructor for dividing matrix by scalar.
 
constexpr Matrix (const Matrix &A, const Matrix &B, const Operator<'+'> &Op)
 Computational constructor for matrix addition.
 
constexpr Matrix (const Matrix &A, const Matrix &B, const Operator<'-'> &Op)
 Computational constructor for matrix subtraction.
 
template<class AType , class BType , OperatorID_t CompType>
constexpr Matrix (const FixedArray< AType, R *C > &l, const FixedArray< BType, R *C > &r, const Operator< CompType > &Op)
 Generic computational constructor for two arrays of size compatible with the matrix.
 
template<class Type >
constexpr Matrix (const FixedArray< Type, R *C > &Data)
 Explicit constructor from arbitrary compatible type.
 
template<class ValueType , OperatorID_t CompType>
constexpr Matrix (const FixedArray< ValueType, R > &l, const Operator< CompType > &Op, const Value &scalar)
 Generic computational constructor for vector/scalar operations.
 
template<class ValueType , OperatorID_t CompType>
constexpr Matrix (const Operator< CompType > &Op, const Value &scalar, const FixedArray< ValueType, R > &l)
 Generic computational constructor for scalar/vector operations.
 
constexpr Matrix (const Matrix &A, const Operator<'-'> &Op)
 Computational constructor for unary minus.
 
template<dimension_t M, class ValueA , class ValueB >
constexpr Matrix (const Matrix< R, M, ValueA > &A, const Matrix< M, C, ValueB > &B, const Operator<' *'> &)
 Matrix multiplication $ A B$.
 
template<dimension_t M, class ValueA , class ValueB >
constexpr Matrix (const Matrix< R, M, ValueA > &A, const Matrix< C, M, ValueB > &B, const Operator<' *','~'> &)
 Transposed matrix multiplication $ A B^{\tau}$.
 
template<dimension_t M>
constexpr Matrix (const Matrix< R, M, Value > &A, const Matrix< C, M, Value > &B, const Mult &, const TransposeOperation &)
 Matrix multiplication $ A B^t$ with transpose of matrix B.
 
template<dimension_t M>
constexpr Matrix (const Matrix< M, R, Value > &A, const Matrix< M, C, Value > &B, const TransposeOperation &, const Mult &)
 Matrix multiplication $ A^t B$ with transpose of matrix A.
 
constexpr Matrix (const Matrix< R, C, Value > &A, const LowerTriangular< C, Value > &B, const Mult &)
 Matrix multiplication $ A B$ where B is a symmetric matrix stored in lower triangular form.
 
constexpr Matrix (const Matrix< C, R, Value > &A, const LowerTriangular< C, Value > &B, const TransposeOperation &, const Mult &)
 Matrix multiplication $ A^t B$ where B is a symmetric matrix stored in lower triangular form.
 
constexpr const Column< R, Value > & column (int i) const
 Return the ith column of this matrix.
 
constexpr Column< R, Value > & column (int i)
 Return the ith column of this matrix, writeable.
 
constexpr Value & operator() (dimension_t row, dimension_t column)
 Access element for writing.
 
constexpr const Value & operator() (dimension_t row, dimension_t column) const
 Element access operation for reading.
 
constexpr Row_t row (dimension_t rowNr)
 Return writable reference to the ith row of this matrix.
 
constexpr const Row_t row (dimension_t rowNr) const
 Return read-only reference to the ith row of this matrix.
 
constexpr const auto operator[] (dimension_t r) const
 Allow nested access to matrix elements via bracket operator.
 
constexpr auto & operator[] (dimension_t r)
 Allow nested access to matrix elements via bracket operator.
 
constexpr Matrix operator+ (const Matrix &A, const Matrix &B)
 Add matrices.
 
template<dimension_t M>
constexpr Matrix operator* (const Matrix< R, M, Value > &A, const Matrix< M, C, Value > &B)
 Matrix product.
 
template<dimension_t M, class ValueA , class ValueB >
constexpr Matrix matrix_mult (const Matrix< R, M, ValueA > &A, const Matrix< M, C, ValueB > &B)
 Matrix product, version as function.
 
template<dimension_t M, class ValueA , class ValueB >
constexpr Matrix matrix_mult_transp (const Matrix< R, M, ValueA > &A, const Matrix< C, M, ValueB > &B)
 Transposed matrix product, version as function.
 

Additional Inherited Members

- Static Public Member Functions inherited from Eagle::FixedArray< value, N >
template<typename T , typename ConversionFunctor >
static constexpr FixedArray convert (const FixedArray< T, N > &F, const ConversionFunctor &CF)
 Perform a type conversion on a given fixed array into another basis type:
 
static constexpr dimension_t size ()
 The number of elements here.
 
- Protected Attributes inherited from Eagle::FixedArray< value, N >
value data [SIZE]
 The actual data values, intentional no-initialization for data member, which increases performance on vector creation.
 

Detailed Description

template<dimension_t R, dimension_t C, class Value>
class Eagle::Matrix< R, C, Value >

Simple matrix class for performing fast operations on matrices of sizes known at compile-time.

All operations are implemented as inline functions using computational constructors, such that simple operations don't require any temporaries. However, advanced techniques like expression templates are not employed here, so complex operations may require temporary objects. The intentional use are small, fast operations with compile time check of operational consistency.

Parameters
Rrows
Ccolumns

The layout is given as (column,row) indexing according to a matrix A as

\[
        A =
    \begin{pmatrix}
    A_{0,0} & \dots & A_{c-1,0} \\
    &\dots& \\
    A_{0,r-1} & \dots & A_{c-1,r-1}
    \end{pmatrix}
    \]

. The elements are stored compatible with OpenGL, see e.g. https://www.geeks3d.com/20141114/glsl-4x4-matrix-mat4-fields/ . A Matrix is therefore a collection of columns and is like an array of column vectors. A column can be referenced without copy and can be modified (in contrast to rows, which requires a copy).

Be alert that initialization from an initializer list looks transposed, see the

See also
Matrix.cpp text example:
{0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15
};
Simple matrix class for performing fast operations on matrices of sizes known at compile-time.
Definition Matrix.hpp:440
is the matrix

\[
        A =
    \begin{pmatrix}
0 & 4 & 8 & 12  \\
1 & 5 & 9 & 13  \\
2 & 6 & 10 & 14  \\
3 & 7 & 11 & 15  \\
    \end{pmatrix}
    \]

.
LowerTriangular, Matrix, Row, Column

Constructor & Destructor Documentation

◆ Matrix() [1/6]

template<dimension_t R, dimension_t C, class Value >
template<dimension_t M, class ValueA , class ValueB >
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< R, M, ValueA > &  A,
const Matrix< M, C, ValueB > &  B,
const Operator<' *'> &   
)
inlineconstexpr

Matrix multiplication $ A B$.

@TODO Test matrix multiplication!!! @TODO Optimize for row-wise contraction!

\[
M_{rc} = \Sigma_m A_{rm} B_{mc}
\]

◆ Matrix() [2/6]

template<dimension_t R, dimension_t C, class Value >
template<dimension_t M, class ValueA , class ValueB >
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< R, M, ValueA > &  A,
const Matrix< C, M, ValueB > &  B,
const Operator<' *','~'> &   
)
inlineconstexpr

Transposed matrix multiplication $ A B^{\tau}$.

@TODO Test matrix multiplication!!! @TODO Optimize for row-wise contraction!

\[
M_{rc} = \Sigma_m A_{rm} B_{cm}
\]

◆ Matrix() [3/6]

template<dimension_t R, dimension_t C, class Value >
template<dimension_t M>
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< R, M, Value > &  A,
const Matrix< C, M, Value > &  B,
const Mult ,
const TransposeOperation  
)
inlineconstexpr

Matrix multiplication $ A B^t$ with transpose of matrix B.

Todo:
This code is UNTESTED! Verify before usage!

◆ Matrix() [4/6]

template<dimension_t R, dimension_t C, class Value >
template<dimension_t M>
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< M, R, Value > &  A,
const Matrix< M, C, Value > &  B,
const TransposeOperation ,
const Mult  
)
inlineconstexpr

Matrix multiplication $ A^t B$ with transpose of matrix A.

Todo:
This code is UNTESTED! Verify before usage!

◆ Matrix() [5/6]

template<dimension_t R, dimension_t C, class Value >
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< R, C, Value > &  A,
const LowerTriangular< C, Value > &  B,
const Mult  
)
inlineconstexpr

Matrix multiplication $ A B$ where B is a symmetric matrix stored in lower triangular form.

@TODO Optimize for symmetries on the operation!

◆ Matrix() [6/6]

template<dimension_t R, dimension_t C, class Value >
constexpr Eagle::Matrix< R, C, Value >::Matrix ( const Matrix< C, R, Value > &  A,
const LowerTriangular< C, Value > &  B,
const TransposeOperation ,
const Mult  
)
inlineconstexpr

Matrix multiplication $ A^t B$ where B is a symmetric matrix stored in lower triangular form.

@TODO Optimize for symmetries on the operation!

Member Function Documentation

◆ operator()()

template<dimension_t R, dimension_t C, class Value >
constexpr Value & Eagle::Matrix< R, C, Value >::operator() ( dimension_t  row,
dimension_t  column 
)
inlineconstexpr

Access element for writing.

The memory layout is set up according to

M[ i+j*ROWS ] = M[i][j].

such that linear access to the elements works through the comma assignment operator:

A = 1,0,0,
0,1,0,
0,0,1,
0,0,0;

References Eagle::Matrix< R, C, Value >::column(), and Eagle::Matrix< R, C, Value >::row().

◆ row() [1/2]

template<dimension_t R, dimension_t C, class Value >
constexpr Row_t Eagle::Matrix< R, C, Value >::row ( dimension_t  rowNr)
inlineconstexpr

Return writable reference to the ith row of this matrix.

Note that the result is not a vectorized vector (and thus not of type Row<>), because it is possibly not aligned as required by a vectorized vector.

Referenced by Eagle::Quadratic< N, Value >::GaussDecompose(), Eagle::Matrix< R, C, Value >::operator()(), and Eagle::Matrix< R, C, Value >::operator()().

◆ row() [2/2]

template<dimension_t R, dimension_t C, class Value >
constexpr const Row_t Eagle::Matrix< R, C, Value >::row ( dimension_t  rowNr) const
inlineconstexpr

Return read-only reference to the ith row of this matrix.

Note that the result is not a vectorized vector (and thus not of type Row<>), because it is possibly not aligned as required by a vectorized vector.