Ocean
Ocean::MatrixT< T > Class Template Reference

This class implements a matrix with arbitrary size. More...

Inheritance diagram for Ocean::MatrixT< T >:

Public Types

enum  MatrixProperty { MP_UNKNOWN , MP_SYMMETRIC }
 Definition of specific properties of matrices. More...
 
typedef T Type
 Definition of the used data type. More...
 

Public Member Functions

 MatrixT ()=default
 Creates a new matrix with no size. More...
 
 MatrixT (const size_t rows, const size_t columns)
 Creates a new matrix with defined rows and columns. More...
 
 MatrixT (const size_t rows, const size_t columns, bool toIdentity)
 Creates a new matrix with defined rows and columns. More...
 
 MatrixT (const size_t rows, const size_t columns, const T value)
 Creates a new matrix with defined rows and columns. More...
 
 MatrixT (const size_t rows, const size_t columns, const T *source)
 Creates a new matrix with defined rows and columns. More...
 
 MatrixT (const size_t rows, const size_t columns, const T *source, const bool valuesRowAligned)
 Creates a new matrix with defined rows and columns. More...
 
 MatrixT (const size_t rows, const size_t columns, const MatrixT< T > &diagonal)
 Creates a new matrix with defined rows and columns and initializes the diagonal with small sub matrices. More...
 
 MatrixT (const size_t rows, const size_t columns, const MatrixT< T > &subMatrix, const size_t row, const size_t column, const T value=T(0.0))
 Creates a new matrix with defined rows and columns and a given sub-matrix. More...
 
 MatrixT (const MatrixT< T > &matrix)
 Copies a matrix. More...
 
 MatrixT (MatrixT< T > &&matrix) noexcept
 Move constructor. More...
 
 ~MatrixT ()
 Destructs a matrix and releases the elements. More...
 
size_t rows () const
 Returns the count of rows. More...
 
size_t columns () const
 Returns the count of columns. More...
 
size_t elements () const
 Returns the number of entire elements, which is the product of rows and columns. More...
 
MatrixT< T > inverted () const
 Returns the inverted of this matrix. More...
 
bool invert ()
 Inverts this matrix. More...
 
MatrixT< T > transposed () const
 Returns the transposed of this matrix. More...
 
void transpose ()
 Transposes this matrix. More...
 
MatrixT< T > selfSquareMatrix () const
 Returns the matrix product of this matrix and the transposed matrix of this matrix. More...
 
MatrixT< T > selfTransposedSquareMatrix () const
 Returns the matrix product of transposed matrix of this matrix and this matrix. More...
 
void selfTransposedSquareMatrix (MatrixT< T > &result) const
 Returns the matrix product of transposed matrix of this matrix and this matrix. More...
 
void weightedSelfTransposedSquareMatrix (const MatrixT< T > &weightDiagonal, MatrixT< T > &result) const
 Returns the matrix product of transposed matrix of this matrix and this matrix and applies a further squared diagonal weighting matrix. More...
 
bool selfSquareDiagonalMatrixMultiply (const MatrixT< T > &right, MatrixT< T > &result) const
 Interprets this matrix as diagonal matrix and multiplies a second matrix on the right of the interpreted diagonal matrix. More...
 
bool selfSquareDiagonalMatrixMultiply (const MatrixT< T > &weightDiagonal, const MatrixT< T > &right, MatrixT< T > &result) const
 Interprets this matrix as diagonal matrix and multiplies a second matrix on the right of the interpreted diagonal matrix. More...
 
MatrixT< T > transposedMultiply (const MatrixT< T > &right) const
 Multiplies this transposed matrix with a second matrix. More...
 
void transposedMultiply (const MatrixT< T > &right, MatrixT< T > &result) const
 Multiplies this transposed matrix with a second matrix. More...
 
bool solve (const MatrixT< T > &b, MatrixT< T > &x, const MatrixProperty matrixProperty=MP_UNKNOWN) const
 Solves the given linear system. More...
 
template<MatrixProperty tMatrixProperty>
bool solve (const MatrixT< T > &b, MatrixT< T > &x) const
 Solves the given linear system. More...
 
bool solve (const T *b, T *x, const MatrixProperty matrixProperty=MP_UNKNOWN) const
 Solves the given linear system. More...
 
template<MatrixProperty tMatrixProperty>
bool solve (const T *b, T *x) const
 Solves the given linear system. More...
 
bool nonNegativeMatrixFactorization (MatrixT< T > &subcomponents, MatrixT< T > &weights, const size_t components=0u, const unsigned int iterations=100u, const T convergenceThreshold=T(0.0001)) const
 Performs a non-negative matrix factorization with multiplicative update rules V = W * H, V is a matrix containing non-negative values
This matrix is V, and will be factorized into two matrices W (weights) and H (subcomponents). More...
 
bool eigenSystem (MatrixT< T > &values, MatrixT< T > &vectors) const
 Computes the eigen system of this matrix. More...
 
bool singularValueDecomposition (MatrixT< T > &u, MatrixT< T > &w, MatrixT< T > &v) const
 Computes the singular value decomposition for this matrix. More...
 
bool qrDecomposition (MatrixT< T > &qMatrix, MatrixT< T > *rMatrix=nullptr) const
 Computes the QR decomposition for this matrix [m x n] while m >= n must hold. More...
 
bool choleskyDecomposition (MatrixT< T > &lMatrix) const
 Computes the Cholesky decomposition for this square matrix [m x m]. More...
 
MatrixT< T > pseudoInverted (const T epsilon=NumericT< T >::eps()) const
 Returns the pseudo inverse of this matrix by application of the singular value decomposition. More...
 
size_t rank () const
 Computes the rank of this matrix. More...
 
MatrixT< T > row (const size_t index) const
 Returns a row of the matrix. More...
 
MatrixT< T > vector (const size_t column) const
 Returns a column vector of the matrix. More...
 
MatrixT< T > diagonal () const
 Returns a vector containing the values of the diagonal. More...
 
norm () const
 Determines the L1 norm (sum of absolute elements) of this matrix. More...
 
sum () const
 Determines the sum of all elements of this matrix. More...
 
MatrixT< T > subMatrix (const size_t row, const size_t column, const size_t rows, const size_t columns)
 Returns a sub matrix of this one. More...
 
void multiplyRow (const size_t row, const T scalar)
 Multiplies a row with a scalar. More...
 
void multiplyColumn (const size_t column, const T scalar)
 Multiplies a column with a scalar. More...
 
void resize (const size_t rows, const size_t columns)
 Resizes this matrix. More...
 
bool isEqual (const MatrixT< T > &matrix, const T eps=NumericT< T >::eps()) const
 Returns whether two matrices are almost identical up to a specified epsilon. More...
 
bool isSymmetric (const T eps=NumericT< T >::eps()) const
 Returns whether this matrix is symmetric (and whether this matrix is a square matrix). More...
 
const T * data () const
 Returns a pointer to the internal values. More...
 
T * data ()
 Returns a pointer to the internal values. More...
 
MatrixT< T > & operator= (const MatrixT< T > &matrix)
 Assigns a matrix to this one. More...
 
MatrixT< T > & operator= (MatrixT< T > &&matrix) noexcept
 Move assign operator. More...
 
bool operator== (const MatrixT< T > &right) const
 Returns whether two matrices are identical up to a small epsilon. More...
 
bool operator!= (const MatrixT< T > &right) const
 Returns whether two matrices are not identical up to a small epsilon. More...
 
MatrixT< T > operator+ (const MatrixT< T > &right) const
 Adds two matrices. More...
 
MatrixT< T > & operator+= (const MatrixT< T > &right)
 Adds and assigns two matrices. More...
 
MatrixT< T > operator- (const MatrixT< T > &right) const
 Subtracts two matrices. More...
 
MatrixT< T > & operator-= (const MatrixT< T > &right)
 Subtracts and assigns two matrices. More...
 
MatrixT< T > operator* (const MatrixT< T > &right) const
 Multiplies two matrices. More...
 
MatrixT< T > operator* (const T scalar) const
 Multiplies the matrix with a scalar. More...
 
MatrixT< T > & operator*= (const MatrixT< T > &right)
 Multiplies and assigns two matrices. More...
 
MatrixT< T > & operator*= (const T scalar)
 Multiplies this matrix by a scalar. More...
 
const T * operator[] (const size_t row) const
 Returns the pointer to the elements of a specified row. More...
 
T * operator[] (const size_t row)
 Element operator for the row aligned elements. More...
 
operator() (const size_t row, const size_t column) const
 Element operator allowing to access a specific elements of this matrix. More...
 
T & operator() (const size_t row, const size_t column)
 Element operator allowing to access a specific elements of this matrix. More...
 
operator() (const size_t index) const
 Element operator for the row aligned elements. More...
 
T & operator() (const size_t index)
 Element operator for the row aligned elements. More...
 
 operator bool () const
 Returns whether the matrix holds at least one element. More...
 

Static Public Member Functions

static size_t rank (const T *data, const size_t rows, const size_t columns)
 Computes the rank of given matrix data. More...
 

Protected Member Functions

void swapRows (const size_t row0, const size_t row1)
 Swaps two rows. More...
 
void swapColumns (const size_t column0, const size_t column1)
 Swaps two columns. More...
 
void addRows (const size_t targetRow, const size_t sourceRow, const T scalar)
 Adds a multiple of a row to another one. More...
 
void elementwiseMultiplication (const MatrixT< T > &multiplier)
 Performs an element-wise matrix multiplication meaning that each element of this matrix will be multiplied by a corresponding element from 'multiplier'. More...
 
void elementwiseDivision (const MatrixT< T > &denominator)
 Performs an element-wise matrix division meaning that each element of this matrix will be divided by a corresponding element from 'denominator'. More...
 

Protected Attributes

size_t rows_ = 0
 Number of rows. More...
 
size_t columns_ = 0
 Number of columns. More...
 
T * values_ = nullptr
 Elements of the matrix. More...
 

Detailed Description

template<typename T>
class Ocean::MatrixT< T >

This class implements a matrix with arbitrary size.

The elements of this matrix are stored in a row aligned order.
That means that elements are stored in the following pattern:

|  0  1   2   3   4  ...  c-1 |
|  c c+1 c+2 c+3 c+4 ...      |
| ...                         |
Template Parameters
TData type of matrix elements
See also
Matrix, MatrixF, MatrixD, StaticMatrix, SparseMatrix, SquareMatrix2, SquareMatrix3, SquareMatrix4.

Member Typedef Documentation

◆ Type

template<typename T >
typedef T Ocean::MatrixT< T >::Type

Definition of the used data type.

Member Enumeration Documentation

◆ MatrixProperty

template<typename T >
enum Ocean::MatrixT::MatrixProperty

Definition of specific properties of matrices.

Enumerator
MP_UNKNOWN 

No specific property known.

MP_SYMMETRIC 

The matrix is symmetric.

Constructor & Destructor Documentation

◆ MatrixT() [1/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( )
default

Creates a new matrix with no size.

◆ MatrixT() [2/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns 
)

Creates a new matrix with defined rows and columns.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix

◆ MatrixT() [3/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
bool  toIdentity 
)

Creates a new matrix with defined rows and columns.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix
toIdentityDetermines whether the matrix will be initialized with as entity matrix or zero matrix.

◆ MatrixT() [4/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
const T  value 
)

Creates a new matrix with defined rows and columns.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix
valueThe value that every matrix element will be set to

◆ MatrixT() [5/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
const T *  source 
)

Creates a new matrix with defined rows and columns.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix
sourceElements to be copied into this matrix

◆ MatrixT() [6/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
const T *  source,
const bool  valuesRowAligned 
)

Creates a new matrix with defined rows and columns.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix
sourceElements to be copied into this matrix
valuesRowAlignedTrue, if the given values are stored in a row aligned order (which is the default case for this matrix); False, if the values are stored in a column aligned order

◆ MatrixT() [7/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
const MatrixT< T > &  diagonal 
)

Creates a new matrix with defined rows and columns and initializes the diagonal with small sub matrices.

The number of columns of the given diagonal vector matrix defines the size of the small sub matrices.
The number of rows of the diagonal vector matrix must be a multiple of the number of rows.

Parameters
rowsThe rows of the new matrix
columnsThe columns of the new matrix
diagonalThe diagonal vector matrix holding the new diagonal sub matrices

◆ MatrixT() [8/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const size_t  rows,
const size_t  columns,
const MatrixT< T > &  subMatrix,
const size_t  row,
const size_t  column,
const T  value = T(0.0) 
)

Creates a new matrix with defined rows and columns and a given sub-matrix.

The given sub-matrix can be larger than the new matrix as elements not fitting into the new matrix will be skipped.
All remaining elements of the matrix will be set to the specified value.

Parameters
rowsThe number of rows the new matrix will have, with range [1, infinity)
columnsThe number of columns the new matrix will have, with range [1, infinity)
subMatrixThe sub-matrix from which the elements will be copied into the new matrix
rowThe row at which the sub-matrix will be placed in the new matrix, with range [0, rows - 1]
columnThe column at which the sub-matrix will be placed in the new matrix, with range [0, columns - 1]
valueThe value which will be used to fill the remaining matrix elements, with range (-infinity, infinity)

◆ MatrixT() [9/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( const MatrixT< T > &  matrix)

Copies a matrix.

Parameters
matrixThe matrix to copy

◆ MatrixT() [10/10]

template<typename T >
Ocean::MatrixT< T >::MatrixT ( MatrixT< T > &&  matrix)
noexcept

Move constructor.

Parameters
matrixThe matrix to be moved

◆ ~MatrixT()

template<typename T >
Ocean::MatrixT< T >::~MatrixT ( )

Destructs a matrix and releases the elements.

Member Function Documentation

◆ addRows()

template<typename T >
void Ocean::MatrixT< T >::addRows ( const size_t  targetRow,
const size_t  sourceRow,
const T  scalar 
)
protected

Adds a multiple of a row to another one.

Parameters
targetRowThe index of the target row to which the multiple of the source row will be added, with range [0, rows())
sourceRowThe index of the source row, with range [0, rows())
scalarThe scalar to multiply the source elements with

◆ choleskyDecomposition()

template<typename T >
bool Ocean::MatrixT< T >::choleskyDecomposition ( MatrixT< T > &  lMatrix) const

Computes the Cholesky decomposition for this square matrix [m x m].

This matrix is decomposed into M = L * L^T, where L is a lower triangular matrix [m x m].

Parameters
lMatrixResulting L matrix, the lower triangle matrix
Returns
True, if succeeded

◆ columns()

template<typename T >
size_t Ocean::MatrixT< T >::columns
inline

Returns the count of columns.

Returns
Columns of the matrix, with range [0, infinity)

◆ data() [1/2]

template<typename T >
T * Ocean::MatrixT< T >::data
inline

Returns a pointer to the internal values.

Returns
Pointer to the internal values

◆ data() [2/2]

template<typename T >
const T * Ocean::MatrixT< T >::data
inline

Returns a pointer to the internal values.

Returns
Pointer to the internal values

◆ diagonal()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::diagonal ( ) const

Returns a vector containing the values of the diagonal.

Returns
Vector with diagonal values

◆ eigenSystem()

template<typename T >
bool Ocean::MatrixT< T >::eigenSystem ( MatrixT< T > &  values,
MatrixT< T > &  vectors 
) const

Computes the eigen system of this matrix.

The function determines values and vectors that: matrix * vectors = vectors * diagonal(values).
Beware: The eigen values are not ordered!

Parameters
valuesVector with resulting eigen values
vectorsMatrix with resulting eigen vectors as columns
Returns
True, if succeeded

◆ elements()

template<typename T >
size_t Ocean::MatrixT< T >::elements
inline

Returns the number of entire elements, which is the product of rows and columns.

Returns
Number of elements, with range [0, infinity)

◆ elementwiseDivision()

template<typename T >
void Ocean::MatrixT< T >::elementwiseDivision ( const MatrixT< T > &  denominator)
protected

Performs an element-wise matrix division meaning that each element of this matrix will be divided by a corresponding element from 'denominator'.

Parameters
denominatorThe matrix providing the denominator elements, with same size as this matrix

◆ elementwiseMultiplication()

template<typename T >
void Ocean::MatrixT< T >::elementwiseMultiplication ( const MatrixT< T > &  multiplier)
protected

Performs an element-wise matrix multiplication meaning that each element of this matrix will be multiplied by a corresponding element from 'multiplier'.

Parameters
multiplierThe matrix providing the multiplication elements, with same size as this matrix, all elements must not be zero

◆ invert()

template<typename T >
bool Ocean::MatrixT< T >::invert ( )

Inverts this matrix.

Returns
True, if the matrix is not singular.
See also
inverted().

◆ inverted()

template<typename T >
MatrixT< T > Ocean::MatrixT< T >::inverted
inline

Returns the inverted of this matrix.

Beware: This function does not throw an exception if the matrix cannot be inverted.
Thus, ensure that the matrix is invertible before calling this function.
This matrix is invertible e.g., if the matrix is square and has full rank (rank() == rows() && rank() == columns()).
Even better: avoid the usage of this function and call invert() instead.
In case, this matrix is not invertible, this matrix will be returned instead.

Returns
Inverted matrix
See also
invert(), rank().

◆ isEqual()

template<typename T >
bool Ocean::MatrixT< T >::isEqual ( const MatrixT< T > &  matrix,
const T  eps = NumericT< T >::eps() 
) const

Returns whether two matrices are almost identical up to a specified epsilon.

Parameters
matrixSecond matrix that will be checked
epsThe epsilon threshold to be used, with range [0, infinity)
Returns
True, if so

◆ isSymmetric()

template<typename T >
bool Ocean::MatrixT< T >::isSymmetric ( const T  eps = NumericT< T >::eps()) const

Returns whether this matrix is symmetric (and whether this matrix is a square matrix).

Beware: An empty matrix (without any rows or columns) is symmetric.

Parameters
epsThe epsilon threshold to be used, with range [0, infinity)
Returns
True, if so

◆ multiplyColumn()

template<typename T >
void Ocean::MatrixT< T >::multiplyColumn ( const size_t  column,
const T  scalar 
)

Multiplies a column with a scalar.

Beware: No range check will be done!

Parameters
columnThe column to multiply, with range [0, columns() - 1]
scalarThe scalar to multiply, with range (-infinity, infinity)

◆ multiplyRow()

template<typename T >
void Ocean::MatrixT< T >::multiplyRow ( const size_t  row,
const T  scalar 
)

Multiplies a row with a scalar.

Beware: No range check will be done!

Parameters
rowThe row to multiply, with range [0, rows() - 1]
scalarThe scalar to multiply, with range (-infinity, infinity)

◆ nonNegativeMatrixFactorization()

template<typename T >
bool Ocean::MatrixT< T >::nonNegativeMatrixFactorization ( MatrixT< T > &  subcomponents,
MatrixT< T > &  weights,
const size_t  components = 0u,
const unsigned int  iterations = 100u,
const T  convergenceThreshold = T(0.0001) 
) const

Performs a non-negative matrix factorization with multiplicative update rules V = W * H, V is a matrix containing non-negative values
This matrix is V, and will be factorized into two matrices W (weights) and H (subcomponents).

Parameters
subcomponentsSolution matrix containing base component vectors
weightsSolution matrix containing weights to the component vectors
componentsNumber of base component vectors (Number of components is usually much smaller than its rank). If set to 0, the rank of matrix is used [0, rank]
iterationsNumber of iterations maximal performed [1, infinity)
convergenceThresholdDifferential threshold aborting the calculation (0, infinity)
Returns
True, if succeeded

◆ norm()

template<typename T >
T Ocean::MatrixT< T >::norm
inline

Determines the L1 norm (sum of absolute elements) of this matrix.

Returns
Matrix norm

◆ operator bool()

template<typename T >
Ocean::MatrixT< T >::operator bool
inlineexplicit

Returns whether the matrix holds at least one element.

Returns
True, if so

◆ operator!=()

template<typename T >
bool Ocean::MatrixT< T >::operator!= ( const MatrixT< T > &  right) const
inline

Returns whether two matrices are not identical up to a small epsilon.

Parameters
rightThe right matrix
Returns
True, if so

◆ operator()() [1/4]

template<typename T >
T & Ocean::MatrixT< T >::operator() ( const size_t  index)
inline

Element operator for the row aligned elements.

Parameters
indexThe index of the element to return, with range [0, elements())
Returns
Specified element

◆ operator()() [2/4]

template<typename T >
T Ocean::MatrixT< T >::operator() ( const size_t  index) const
inline

Element operator for the row aligned elements.

Parameters
indexThe index of the element to return, with range [0, elements())
Returns
Specified element

◆ operator()() [3/4]

template<typename T >
T & Ocean::MatrixT< T >::operator() ( const size_t  row,
const size_t  column 
)
inline

Element operator allowing to access a specific elements of this matrix.

Parameters
rowThe row of the element to return, with range [0, rows())
columnThe column of the element to return, with range [0, columns())
Returns
Specified element

◆ operator()() [4/4]

template<typename T >
T Ocean::MatrixT< T >::operator() ( const size_t  row,
const size_t  column 
) const
inline

Element operator allowing to access a specific elements of this matrix.

Parameters
rowThe row of the element to return, with range [0, rows())
columnThe column of the element to return, with range [0, columns())
Returns
Specified element

◆ operator*() [1/2]

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::operator* ( const MatrixT< T > &  right) const

Multiplies two matrices.

Parameters
rightThe right matrix
Returns
Resulting matrix

◆ operator*() [2/2]

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::operator* ( const T  scalar) const

Multiplies the matrix with a scalar.

Parameters
scalarThe scalar to multiply
Returns
Resulting matrix

◆ operator*=() [1/2]

template<typename T >
MatrixT< T > & Ocean::MatrixT< T >::operator*= ( const MatrixT< T > &  right)
inline

Multiplies and assigns two matrices.

Parameters
rightThe right matrix
Returns
Reference to this matrix

◆ operator*=() [2/2]

template<typename T >
MatrixT<T>& Ocean::MatrixT< T >::operator*= ( const T  scalar)

Multiplies this matrix by a scalar.

Parameters
scalarThe scalar to multiply
Returns
Reference to this matrix

◆ operator+()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::operator+ ( const MatrixT< T > &  right) const

Adds two matrices.

Parameters
rightThe right matrix
Returns
Sum matrix

◆ operator+=()

template<typename T >
MatrixT<T>& Ocean::MatrixT< T >::operator+= ( const MatrixT< T > &  right)

Adds and assigns two matrices.

Parameters
rightThe right matrix
Returns
Reference to this matrix

◆ operator-()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::operator- ( const MatrixT< T > &  right) const

Subtracts two matrices.

Parameters
rightThe right matrix
Returns
Subtracted matrix

◆ operator-=()

template<typename T >
MatrixT<T>& Ocean::MatrixT< T >::operator-= ( const MatrixT< T > &  right)

Subtracts and assigns two matrices.

Parameters
rightThe right matrix
Returns
Reference to this matrix

◆ operator=() [1/2]

template<typename T >
MatrixT<T>& Ocean::MatrixT< T >::operator= ( const MatrixT< T > &  matrix)

Assigns a matrix to this one.

Parameters
matrixThe matrix to assign
Returns
Reference to this matrix

◆ operator=() [2/2]

template<typename T >
MatrixT<T>& Ocean::MatrixT< T >::operator= ( MatrixT< T > &&  matrix)
noexcept

Move assign operator.

Parameters
matrixThe matrix to moved
Returns
Reference to this matrix

◆ operator==()

template<typename T >
bool Ocean::MatrixT< T >::operator== ( const MatrixT< T > &  right) const
inline

Returns whether two matrices are identical up to a small epsilon.

Parameters
rightThe right matrix
Returns
True, if so

◆ operator[]() [1/2]

template<typename T >
T * Ocean::MatrixT< T >::operator[] ( const size_t  row)
inline

Element operator for the row aligned elements.

Parameters
rowIndex of the element to return, with range [0, rows())
Returns
Specified element

◆ operator[]() [2/2]

template<typename T >
const T * Ocean::MatrixT< T >::operator[] ( const size_t  row) const
inline

Returns the pointer to the elements of a specified row.

Parameters
rowIndex of the row to return, with range [0, rows())
Returns
Specified row

◆ pseudoInverted()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::pseudoInverted ( const T  epsilon = NumericT< T >::eps()) const

Returns the pseudo inverse of this matrix by application of the singular value decomposition.

Parameters
epsilonThe tolerance value, with range [0, infinity)
Returns
The resulting pseudo inverted matrix

◆ qrDecomposition()

template<typename T >
bool Ocean::MatrixT< T >::qrDecomposition ( MatrixT< T > &  qMatrix,
MatrixT< T > *  rMatrix = nullptr 
) const

Computes the QR decomposition for this matrix [m x n] while m >= n must hold.

This matrix is decomposed into two matrices as follows: q * r, where q is a orthogonal [m x m] matrix (m * m^T = I), and r is a upper triangular matrix [m x n].

Parameters
qMatrixResulting q matrix, containing the null space in the last (m - rank) columns, the size of the matrix will be adjusted internally
rMatrixOptional resulting r matrix, upper triangle matrix, the size of the matrix will be adjusted internally, nullptr if the matrix is not needed
Returns
True, if succeeded

◆ rank() [1/2]

template<typename T >
size_t Ocean::MatrixT< T >::rank
inline

Computes the rank of this matrix.

The matrix must be valid.

Returns
The matrix's rank with range [0, min(rows(), columns())]

◆ rank() [2/2]

template<typename T >
static size_t Ocean::MatrixT< T >::rank ( const T *  data,
const size_t  rows,
const size_t  columns 
)
static

Computes the rank of given matrix data.

Parameters
dataThe elements of the matrix for which the rank will be calculated, provided in a row aligned order, must be valid
rowsThe number of rows of the provided matrix, with range [1, infinity)
columnsThe number of columns of the provided matrix, with range [1, infinity)
Returns
The matrix's rank with range [0, min(rows, columns)]

◆ resize()

template<typename T >
void Ocean::MatrixT< T >::resize ( const size_t  rows,
const size_t  columns 
)

Resizes this matrix.

Parameters
rowsNumber of rows of the resized matrix
columnsNumber of columns of the resized matrix

◆ row()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::row ( const size_t  index) const

Returns a row of the matrix.

Parameters
indexThe index of the row to receive, with range [0, rows())
Returns
Entire row

◆ rows()

template<typename T >
size_t Ocean::MatrixT< T >::rows
inline

Returns the count of rows.

Returns
Rows of the matrix, with range [0, infinity)

◆ selfSquareDiagonalMatrixMultiply() [1/2]

template<typename T >
bool Ocean::MatrixT< T >::selfSquareDiagonalMatrixMultiply ( const MatrixT< T > &  right,
MatrixT< T > &  result 
) const

Interprets this matrix as diagonal matrix and multiplies a second matrix on the right of the interpreted diagonal matrix.

The square sub matrices size is defined by the number of columns of this matrix.
Thus the number of rows must be a multiple of the number of columns of this matrix.
Actually, the following matrix will be returned: result = diag(*this) * right.

Parameters
rightThe right matrix to be multiplied with the interpreted diagonal matrix
resultResulting matrix
Returns
True, if succeeded

◆ selfSquareDiagonalMatrixMultiply() [2/2]

template<typename T >
bool Ocean::MatrixT< T >::selfSquareDiagonalMatrixMultiply ( const MatrixT< T > &  weightDiagonal,
const MatrixT< T > &  right,
MatrixT< T > &  result 
) const

Interprets this matrix as diagonal matrix and multiplies a second matrix on the right of the interpreted diagonal matrix.

Further, a diagonal weighting vector is applied.
The square sub matrices size is defined by the number of columns of this matrix.
Thus the number of rows must be a multiple of the number of columns of this matrix.
Actually, the following matrix will be returned: result = diag(*this) * diag(weightDiagonal) * right.

Parameters
rightThe right matrix to be multiplied with the interpreted diagonal matrix
weightDiagonalWeight vector defining the diagonal of the weighting matrix, with one column
resultResulting matrix
Returns
True, if succeeded

◆ selfSquareMatrix()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::selfSquareMatrix ( ) const

Returns the matrix product of this matrix and the transposed matrix of this matrix.


The result will be a square matrix with size: rows() x rows().
Actually, the following matrix will be returned: (*this) * (*this).transposed().

Returns
Resulting matrix

◆ selfTransposedSquareMatrix() [1/2]

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::selfTransposedSquareMatrix ( ) const

Returns the matrix product of transposed matrix of this matrix and this matrix.


The result will be a square matrix with size: columns() x columns().
Actually, the following matrix will be returned: (*this).transposed() * (*this).

Returns
Resulting matrix

◆ selfTransposedSquareMatrix() [2/2]

template<typename T >
void Ocean::MatrixT< T >::selfTransposedSquareMatrix ( MatrixT< T > &  result) const

Returns the matrix product of transposed matrix of this matrix and this matrix.


The result will be a square matrix with size: columns() x columns().
Actually, the following matrix will be returned: (*this).transposed() * (*this).

Parameters
resultResulting matrix

◆ singularValueDecomposition()

template<typename T >
bool Ocean::MatrixT< T >::singularValueDecomposition ( MatrixT< T > &  u,
MatrixT< T > &  w,
MatrixT< T > &  v 
) const

Computes the singular value decomposition for this matrix.

This matrix is decomposed into three matrices as follows: u * w * v.transposed().
The diagonal values of w are ordered in descending order already.

Parameters
uResulting u matrix
wResulting w vector holding the values of the diagonal matrix
vResulting v matrix
Returns
True, if succeeded

◆ solve() [1/4]

template<typename T >
template<typename MatrixT< T >::MatrixProperty tMatrixProperty>
bool Ocean::MatrixT< T >::solve ( const MatrixT< T > &  b,
MatrixT< T > &  x 
) const
inline

Solves the given linear system.

M * x = b, with M and b known and M is a square matrix
This matrix is M, the given vector is b and the result will be x.
Note: If a non-square matrix should be solved, use: (M.transposed() * M) * x = M.transposed() * b

Parameters
bVector defining the linear system, with size columns() x 1
xSolution vector receiving the solution if existing, with size columns() x 1
Returns
True, if succeeded
Template Parameters
tMatrixPropertyThe property of the matrix allowing to improve the solving performance and stability, MP_UNKNOWN to apply a standard solving

◆ solve() [2/4]

template<typename T >
bool Ocean::MatrixT< T >::solve ( const MatrixT< T > &  b,
MatrixT< T > &  x,
const MatrixProperty  matrixProperty = MP_UNKNOWN 
) const
inline

Solves the given linear system.

M * x = b, with M and b known and M is a square matrix
This matrix is M, the given vector is b and the result will be x.
Note: If a non-square matrix should be solved, use: (M.transposed() * M) * x = M.transposed() * b

Parameters
bVector defining the linear system, with size columns() x 1
xSolution vector receiving the solution if existing, with size columns() x 1
matrixPropertyThe property of the matrix allowing to improve the solving performance and stability, MP_UNKNOWN to apply a standard solving
Returns
True, if succeeded

◆ solve() [3/4]

template<typename T >
template<MatrixProperty tMatrixProperty>
bool Ocean::MatrixT< T >::solve ( const T *  b,
T *  x 
) const

Solves the given linear system.

M * x = b, with M and b known and M is a square matrix
This matrix is M, the given vector is b and the result will be x..
Note: If a non-square matrix should be solved, use: (M.transposed() * M) * x = M.transposed() * b

Parameters
bPointer to the vector defining the linear system, ensure that the number of provided values is equal to columns()
xPointer to the solution vector receiving the solution if existing, ensure that the number of elements is equal to columns()
Returns
True, if succeeded
Template Parameters
tMatrixPropertyThe property of the matrix allowing to improve the solving performance and stability, MP_UNKNOWN to apply a standard solving

◆ solve() [4/4]

template<typename T >
bool Ocean::MatrixT< T >::solve ( const T *  b,
T *  x,
const MatrixProperty  matrixProperty = MP_UNKNOWN 
) const
inline

Solves the given linear system.

M * x = b, with M and b known and M is a square matrix
This matrix is M, the given vector is b and the result will be x..
Note: If a non-square matrix should be solved, use: (M.transposed() * M) * x = M.transposed() * b

Parameters
bPointer to the vector defining the linear system, ensure that the number of provided values is equal to columns()
xPointer to the solution vector receiving the solution if existing, ensure that the number of elements is equal to columns()
matrixPropertyThe property of the matrix allowing to improve the solving performance and stability, MP_UNKNOWN to apply a standard solving
Returns
True, if succeeded

◆ subMatrix()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::subMatrix ( const size_t  row,
const size_t  column,
const size_t  rows,
const size_t  columns 
)

Returns a sub matrix of this one.

Parameters
rowThe start row at which the sub matrix will start, with range [0, row() - 1]
columnThe start column at which the sub matrix will start, with range [0, columns() - 1]
rowsThe number of rows in the sub matrix, with range [1, rows() - row]
columnsThe number of columns in the sub matrix, with range [1, columns() - row]
Returns
The resulting sub matrix

◆ sum()

template<typename T >
T Ocean::MatrixT< T >::sum
inline

Determines the sum of all elements of this matrix.

Returns
Matrix sum

◆ swapColumns()

template<typename T >
void Ocean::MatrixT< T >::swapColumns ( const size_t  column0,
const size_t  column1 
)
protected

Swaps two columns.

Parameters
column0The index of the first column to be swapped, with range [0, columns())
column1The index of the second column to be swapped, with range [0, columns())

◆ swapRows()

template<typename T >
void Ocean::MatrixT< T >::swapRows ( const size_t  row0,
const size_t  row1 
)
protected

Swaps two rows.

Parameters
row0The index of the first row to be swapped, with range [0, rows())
row1The index of the second row to be swapped, with range [0, rows())

◆ transpose()

template<typename T >
void Ocean::MatrixT< T >::transpose
inline

Transposes this matrix.

◆ transposed()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::transposed ( ) const

Returns the transposed of this matrix.

Returns
Transposed matrix

◆ transposedMultiply() [1/2]

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::transposedMultiply ( const MatrixT< T > &  right) const

Multiplies this transposed matrix with a second matrix.

Actually, the following matrix will be returned: (*this).transposed() * right.
The resulting matrix will have the size: columns() x right.columns().

Parameters
rightMatrix to multiply
Returns
Matrix product

◆ transposedMultiply() [2/2]

template<typename T >
void Ocean::MatrixT< T >::transposedMultiply ( const MatrixT< T > &  right,
MatrixT< T > &  result 
) const

Multiplies this transposed matrix with a second matrix.

Actually, the following matrix will be returned: (*this).transposed() * right.
The resulting matrix will have the size: columns() x right.columns().

Parameters
rightMatrix to multiply
resultResulting matrix product

◆ vector()

template<typename T >
MatrixT<T> Ocean::MatrixT< T >::vector ( const size_t  column) const

Returns a column vector of the matrix.

Parameters
columnThe column to receive the vector from, with range [0, columns())
Returns
Column vector

◆ weightedSelfTransposedSquareMatrix()

template<typename T >
void Ocean::MatrixT< T >::weightedSelfTransposedSquareMatrix ( const MatrixT< T > &  weightDiagonal,
MatrixT< T > &  result 
) const

Returns the matrix product of transposed matrix of this matrix and this matrix and applies a further squared diagonal weighting matrix.


The result will be a square matrix with size: columns() x columns().
Actually, the following matrix will be returned: (*this).transposed() * diag(weightDiagonal) * (*this).

Parameters
weightDiagonalWeight vector defining the diagonal of the weighting matrix, with one column
resultResulting matrix

Field Documentation

◆ columns_

template<typename T >
size_t Ocean::MatrixT< T >::columns_ = 0
protected

Number of columns.

◆ rows_

template<typename T >
size_t Ocean::MatrixT< T >::rows_ = 0
protected

Number of rows.

◆ values_

template<typename T >
T* Ocean::MatrixT< T >::values_ = nullptr
protected

Elements of the matrix.


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