Image Component Library (ICL)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
icl::math::DynMatrix< T > Struct Template Reference

Highly flexible and optimized matrix class implementation. More...

#include <DynMatrix.h>

Inheritance diagram for icl::math::DynMatrix< T >:
icl::math::DynColVector< T > icl::math::DynRowVector< T >

Classes

struct  col_iterator
 Internal column iterator struct (using height-stride) More...
 
class  DynMatrixColumn
 Internally used Utility structure referencing a matrix column shallowly. More...
 

Public Types

typedef T * iterator
 default iterator type (just a data-pointer) More...
 
typedef const T * const_iterator
 dafault const_iterator type (just a data-pointer) More...
 
typedef T * row_iterator
 comples row_iterator type More...
 
typedef const T * const_row_iterator
 complex const_row_iterator type More...
 
typedef const col_iterator const_col_iterator
 const column iterator typedef More...
 
typedef void(* GESDD) (const char *, const int *, const int *, T *, const int *, T *, T *, const int *, T *, const int *, T *, const int *, int *, int *)
 
typedef void(* CBLAS_GEMM) (CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, T, const T *, int, const T *, int, T, T *, int)
 

Public Member Functions

 DynMatrix (const DynMatrixColumn &column)
 creates a column matrix from given column of other matrix More...
 
 DynMatrix ()
 Default empty constructor creates a null-matrix. More...
 
 DynMatrix (unsigned int cols, unsigned int rows, const T &initValue=0)
 Create a dyn matrix with given dimensions (and optional initialValue) More...
 
 DynMatrix (unsigned int cols, unsigned int rows, T *data, bool deepCopy=true)
 Create a matrix with given data. More...
 
 DynMatrix (unsigned int cols, unsigned int rows, const T *data)
 Create a matrix with given data (const version: deepCopy only) More...
 
 DynMatrix (const DynMatrix &other)
 Default copy constructor. More...
 
 DynMatrix (const std::string &filename)
 creates a new DynMatrix from given csv filename More...
 
void saveCSV (const std::string &filename)
 writes the current matrix to a csv file More...
 
bool isNull () const
 returns with this matrix has a valid data pointer More...
 
 ~DynMatrix ()
 Destructor (deletes data if no wrapped shallowly) More...
 
DynMatrixoperator= (const DynMatrix &other)
 Assignment operator (using deep/shallow-copy) More...
 
void setBounds (unsigned int cols, unsigned int rows, bool holdContent=false, const T &initializer=0)
 resets matrix dimensions More...
 
bool isSimilar (const DynMatrix &other, T tollerance=T(0.0001)) const
 tests weather a matrix is enough similar to another matrix More...
 
bool operator== (const DynMatrix &other) const
 elementwise comparison (==) More...
 
bool operator!= (const DynMatrix &other) const
 elementwise comparison (!=) More...
 
DynMatrix operator * (T f) const
 Multiply elements with scalar. More...
 
DynMatrixmult (T f, DynMatrix &dst) const
 Multiply elements with scalar (in source destination fashion) More...
 
DynMatrixoperator *= (T f)
 Multiply elements with scalar (inplace) More...
 
DynMatrix operator/ (T f) const
 Device elements by scalar. More...
 
DynMatrixoperator/= (T f)
 Device elements by scalar (inplace) More...
 
DynMatrixmult (const DynMatrix &m, DynMatrix &dst) const
 Matrix multiplication (in source destination fashion) [IPP-Supported]. More...
 
DynMatrixelementwise_mult (const DynMatrix &m, DynMatrix &dst) const
 Elementwise matrix multiplication (in source destination fashion) [IPP-Supported]. More...
 
DynMatrix elementwise_mult (const DynMatrix &m) const
 Elementwise matrix multiplication (without destination matrix) [IPP-Supported]. More...
 
DynMatrixelementwise_div (const DynMatrix &m, DynMatrix &dst) const
 Elementwise division (in source destination fashion) [IPP-Supported]. More...
 
DynMatrix elementwise_div (const DynMatrix &m) const
 Elementwise matrix multiplication (without destination matrix) [IPP-Supported]. More...
 
DynMatrix operator * (const DynMatrix &m) const
 Essential matrix multiplication [IPP-Supported]. More...
 
DynMatrixoperator *= (const DynMatrix &m)
 inplace matrix multiplication applying this = this*m [IPP-Supported] More...
 
DynMatrix operator/ (const DynMatrix &m) const
 inplace matrix devision (calling this/m.inv()) [IPP-Supported] More...
 
DynMatrixoperator/= (const DynMatrix &m) const
 inplace matrix devision (calling this/m.inv()) (inplace) More...
 
DynMatrix operator+ (const T &t) const
 adds a scalar to each element More...
 
DynMatrix operator- (const T &t) const
 substacts a scalar from each element More...
 
DynMatrixoperator+= (const T &t)
 adds a scalar to each element (inplace) More...
 
DynMatrixoperator-= (const T &t)
 substacts a scalar from each element (inplace) More...
 
DynMatrix operator+ (const DynMatrix &m) const
 Matrix addition. More...
 
DynMatrix operator- (const DynMatrix &m) const
 Matrix substraction. More...
 
DynMatrixoperator+= (const DynMatrix &m)
 Matrix addition (inplace) More...
 
DynMatrixoperator-= (const DynMatrix &m)
 Matrix substraction (inplace) More...
 
T & operator() (unsigned int col, unsigned int row)
 element access operator (x,y)-access index begin 0! More...
 
const T & operator() (unsigned int col, unsigned int row) const
 element access operator (x,y)-access index begin 0! (const) More...
 
T & at (unsigned int col, unsigned int row)
 element access with index check More...
 
const T & at (unsigned int col, unsigned int row) const
 element access with index check (const) More...
 
T & operator[] (unsigned int idx)
 linear access to actual data array More...
 
const T & operator[] (unsigned int idx) const
 linear access to actual data array (const) More...
 
norm (double l=2) const
 applies an L_l norm on the matrix elements (all elements are treated as vector) More...
 
sqrDistanceTo (const DynMatrix &other) const
 returns the squared distance of the inner data vectors (linearly interpreted) (IPP accelerated) More...
 
distanceTo (const DynMatrix &other) const
 returns the distance of the inner data vectors (linearly interpreted) (IPP accelerated) More...
 
unsigned int rows () const
 height of the matrix (number of rows) More...
 
unsigned int cols () const
 width of the matrix (number of columns) More...
 
T * data ()
 internal data pointer More...
 
const T * data () const
 internal data pointer (const) More...
 
unsigned int dim () const
 matrix dimension (width*height) or (cols*rows) More...
 
int stride0 () const
 returns sizeof (T)*dim() More...
 
int stride1 () const
 returns sizeof(T)*cols() More...
 
int stride2 () const
 returns sizeof (T) More...
 
DynMatrixoperator= (const DynMatrixColumn &col)
 
iterator begin ()
 returns an iterator to the begin of internal data array More...
 
iterator end ()
 returns an iterator to the end of internal data array More...
 
const_iterator begin () const
 returns an iterator to the begin of internal data array (const) More...
 
const_iterator end () const
 returns an iterator to the end of internal data array (const) More...
 
col_iterator col_begin (unsigned int col)
 returns an iterator running through a certain matrix column More...
 
col_iterator col_end (unsigned int col)
 returns an iterator end of a certain matrix column More...
 
const_col_iterator col_begin (unsigned int col) const
 returns an iterator running through a certain matrix column (const) More...
 
const_col_iterator col_end (unsigned int col) const
 returns an iterator end of a certain matrix column (const) More...
 
row_iterator row_begin (unsigned int row)
 returns an iterator running through a certain matrix row More...
 
row_iterator row_end (unsigned int row)
 returns an iterator of a certains row's end More...
 
const_row_iterator row_begin (unsigned int row) const
 returns an iterator running through a certain matrix row (const) More...
 
const_row_iterator row_end (unsigned int row) const
 returns an iterator of a certains row's end (const) More...
 
DynMatrix row (int row)
 Extracts a shallow copied matrix row. More...
 
const DynMatrix row (int row) const
 Extracts a shallow copied matrix row (const) More...
 
DynMatrixColumn col (int col)
 Extracts a shallow copied matrix column. More...
 
const DynMatrixColumn col (int col) const
 
void decompose_QR (DynMatrix &Q, DynMatrix &R) const
 applies QR-decomposition using stabilized Gram-Schmidt orthonormalization (only for icl32f and icl64f) More...
 
void decompose_RQ (DynMatrix &R, DynMatrix &Q) const
 applies RQ-decomposition (by exploiting implemnetation of QR-decomposition) (only for icl32f, and icl64f) More...
 
void decompose_LU (DynMatrix &L, DynMatrix &U, T zeroThreshold=T(1E-16)) const
 applies LU-decomposition (without using partial pivoting) (only for icl32f and icl64f) More...
 
DynMatrix solve_upper_triangular (const DynMatrix &b) const
 solves Mx=b for M=*this (only if M is a squared upper triangular matrix) (only for icl32f and icl64f) More...
 
DynMatrix solve_lower_triangular (const DynMatrix &b) const
 solves Mx=b for M=*this (only if M is a squared lower triangular matrix) (only for icl32f and icl64f) More...
 
DynMatrix solve (const DynMatrix &b, const std::string &method="lu", T zeroThreshold=T(1E-16))
 solves Mx=b for M=*this (only for icl32f and icl64f) More...
 
DynMatrix inv () const
 invert the matrix (only for icl32f and icl64f) More...
 
void eigen (DynMatrix &eigenvectors, DynMatrix &eigenvalues) const
 Extracts the matrix's eigenvalues and eigenvectors. More...
 
void svd (DynMatrix &U, DynMatrix &S, DynMatrix &V) const
 Computes Singular Value Decomposition of a matrix - decomposes A into USV'. More...
 
DynMatrix pinv (bool useSVD=false, T zeroThreshold=T(1E-16)) const
 calculates the Moore-Penrose pseudo-inverse (only implemented for icl32f and icl64f) More...
 
DynMatrix big_matrix_pinv (T zeroThreshold=T(1E-16)) const
 calculates the Moore-Penrose pseudo-inverse (specialized for big matrices) More...
 
DynMatrix big_matrix_pinv (T zeroThreshold, GESDD gesdd, CBLAS_GEMM cblas_gemm) const
 
det () const
 matrix determinant (only for icl32f and icl64f) More...
 
DynMatrix transp () const
 matrix transposed More...
 
const DynMatrix< T > shallowTransposed () const
 returns a shallow transposed copy of this matrix (dimensions are swapped, data is not re-aranged) (const) More...
 
const DynMatrix< T > shallowTransposed ()
 returns a shallow transposed copy of this matrix (dimensions are swapped, data is not re-aranged) More...
 
void reshape (int newCols, int newRows)
 resets the matrix dimensions without changing the content More...
 
element_wise_inner_product (const DynMatrix< T > &other) const
 inner product of data pointers (not matrix-mulitiplication) More...
 
DynMatrix< T > dot (const DynMatrix< T > &M) const
 returns the inner product of two matrices (i.e. dot-product) More...
 
DynMatrix< T > diag () const
 returns diagonal-elements as column-vector More...
 
trace () const
 computes the sum of all diagonal elements More...
 
cond (const double p=2) const
 computes the condition of a matrix More...
 
T * set_data (T *newData)
 sets new data internally and returns old data pointer (for experts only!) More...
 

Static Public Member Functions

static DynMatrix< T > loadCSV (const std::string &filename)
 loads a dynmatrix from given CSV file More...
 
static DynMatrix< T > cross (const DynMatrix< T > &x, const DynMatrix< T > &y)
 computes the cross product More...
 
static DynMatrix id (unsigned int dim)
 creates a dim-D identity Matrix More...
 

Private Member Functions

void row_check (unsigned int row) const
 
void col_check (unsigned int col) const
 
void idx_check (unsigned int col, unsigned int row) const
 
void idx_check (unsigned int idx) const
 

Private Attributes

int m_rows
 
int m_cols
 
T * m_data
 
bool m_ownData
 

Detailed Description

template<class T>
struct icl::math::DynMatrix< T >

Highly flexible and optimized matrix class implementation.

In contrast to the FixedMatrix template class, the DynMatrix instances are dynamically sized at runtime The template class is instantiated for the common ICL types uint8_t, int16_t, int32_t, float and double

Member Typedef Documentation

◆ CBLAS_GEMM

template<class T>
typedef void(* icl::math::DynMatrix< T >::CBLAS_GEMM) (CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, T, const T *, int, const T *, int, T, T *, int)

◆ const_col_iterator

template<class T>
typedef const col_iterator icl::math::DynMatrix< T >::const_col_iterator

const column iterator typedef

◆ const_iterator

template<class T>
typedef const T* icl::math::DynMatrix< T >::const_iterator

dafault const_iterator type (just a data-pointer)

◆ const_row_iterator

template<class T>
typedef const T* icl::math::DynMatrix< T >::const_row_iterator

complex const_row_iterator type

◆ GESDD

template<class T>
typedef void(* icl::math::DynMatrix< T >::GESDD) (const char *, const int *, const int *, T *, const int *, T *, T *, const int *, T *, const int *, T *, const int *, int *, int *)

◆ iterator

template<class T>
typedef T* icl::math::DynMatrix< T >::iterator

default iterator type (just a data-pointer)

◆ row_iterator

template<class T>
typedef T* icl::math::DynMatrix< T >::row_iterator

comples row_iterator type

Constructor & Destructor Documentation

◆ DynMatrix() [1/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( const DynMatrixColumn column)

creates a column matrix from given column of other matrix

◆ DynMatrix() [2/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( )
inline

Default empty constructor creates a null-matrix.

◆ DynMatrix() [3/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( unsigned int  cols,
unsigned int  rows,
const T &  initValue = 0 
)
inline

Create a dyn matrix with given dimensions (and optional initialValue)

◆ DynMatrix() [4/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( unsigned int  cols,
unsigned int  rows,
T *  data,
bool  deepCopy = true 
)
inline

Create a matrix with given data.

Data can be wrapped deeply or shallowly. If the latter is true, given data pointer will not be released in the destructor

◆ DynMatrix() [5/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( unsigned int  cols,
unsigned int  rows,
const T *  data 
)
inline

Create a matrix with given data (const version: deepCopy only)

◆ DynMatrix() [6/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( const DynMatrix< T > &  other)
inline

Default copy constructor.

◆ DynMatrix() [7/7]

template<class T>
icl::math::DynMatrix< T >::DynMatrix ( const std::string &  filename)
inline

creates a new DynMatrix from given csv filename

See also
DynMatrix<T>::loadCSV

◆ ~DynMatrix()

template<class T>
icl::math::DynMatrix< T >::~DynMatrix ( )
inline

Destructor (deletes data if no wrapped shallowly)

Member Function Documentation

◆ at() [1/2]

template<class T>
T& icl::math::DynMatrix< T >::at ( unsigned int  col,
unsigned int  row 
)
inline

element access with index check

◆ at() [2/2]

template<class T>
const T& icl::math::DynMatrix< T >::at ( unsigned int  col,
unsigned int  row 
) const
inline

element access with index check (const)

◆ begin() [1/2]

template<class T>
iterator icl::math::DynMatrix< T >::begin ( )
inline

returns an iterator to the begin of internal data array

◆ begin() [2/2]

template<class T>
const_iterator icl::math::DynMatrix< T >::begin ( ) const
inline

returns an iterator to the begin of internal data array (const)

◆ big_matrix_pinv() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::big_matrix_pinv ( zeroThreshold = T(1E-16)) const

calculates the Moore-Penrose pseudo-inverse (specialized for big matrices)

Calculate pseudo inverse of given matrix using Intel MKL if possible. Based on singular value decomposition (SVD) and divide & conquer.

Parameters
zeroThresholdsingular values below threshold are set to zero
Returns
pseudo inverse

◆ big_matrix_pinv() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::big_matrix_pinv ( zeroThreshold,
GESDD  gesdd,
CBLAS_GEMM  cblas_gemm 
) const

◆ col() [1/2]

template<class T>
DynMatrixColumn icl::math::DynMatrix< T >::col ( int  col)
inline

Extracts a shallow copied matrix column.

◆ col() [2/2]

template<class T>
const DynMatrixColumn icl::math::DynMatrix< T >::col ( int  col) const
inline

◆ col_begin() [1/2]

template<class T>
col_iterator icl::math::DynMatrix< T >::col_begin ( unsigned int  col)
inline

returns an iterator running through a certain matrix column

◆ col_begin() [2/2]

template<class T>
const_col_iterator icl::math::DynMatrix< T >::col_begin ( unsigned int  col) const
inline

returns an iterator running through a certain matrix column (const)

◆ col_check()

template<class T>
void icl::math::DynMatrix< T >::col_check ( unsigned int  col) const
inlineprivate

◆ col_end() [1/2]

template<class T>
col_iterator icl::math::DynMatrix< T >::col_end ( unsigned int  col)
inline

returns an iterator end of a certain matrix column

◆ col_end() [2/2]

template<class T>
const_col_iterator icl::math::DynMatrix< T >::col_end ( unsigned int  col) const
inline

returns an iterator end of a certain matrix column (const)

◆ cols()

template<class T>
unsigned int icl::math::DynMatrix< T >::cols ( ) const
inline

width of the matrix (number of columns)

◆ cond()

template<class T>
T icl::math::DynMatrix< T >::cond ( const double  p = 2) const
inline

computes the condition of a matrix

◆ cross()

template<class T>
static DynMatrix<T> icl::math::DynMatrix< T >::cross ( const DynMatrix< T > &  x,
const DynMatrix< T > &  y 
)
inlinestatic

computes the cross product

◆ data() [1/2]

template<class T>
T* icl::math::DynMatrix< T >::data ( )
inline

internal data pointer

◆ data() [2/2]

template<class T>
const T* icl::math::DynMatrix< T >::data ( ) const
inline

internal data pointer (const)

◆ decompose_LU()

template<class T>
void icl::math::DynMatrix< T >::decompose_LU ( DynMatrix< T > &  L,
DynMatrix< T > &  U,
zeroThreshold = T(1E-16) 
) const

applies LU-decomposition (without using partial pivoting) (only for icl32f and icl64f)

Even though, implementation also works for non-sqared matrices, it's not recommended to apply this function on non-sqared matrices

◆ decompose_QR()

template<class T>
void icl::math::DynMatrix< T >::decompose_QR ( DynMatrix< T > &  Q,
DynMatrix< T > &  R 
) const

applies QR-decomposition using stabilized Gram-Schmidt orthonormalization (only for icl32f and icl64f)

◆ decompose_RQ()

template<class T>
void icl::math::DynMatrix< T >::decompose_RQ ( DynMatrix< T > &  R,
DynMatrix< T > &  Q 
) const

applies RQ-decomposition (by exploiting implemnetation of QR-decomposition) (only for icl32f, and icl64f)

◆ det()

template<class T>
T icl::math::DynMatrix< T >::det ( ) const

matrix determinant (only for icl32f and icl64f)

◆ diag()

template<class T>
DynMatrix<T> icl::math::DynMatrix< T >::diag ( ) const
inline

returns diagonal-elements as column-vector

◆ dim()

template<class T>
unsigned int icl::math::DynMatrix< T >::dim ( ) const
inline

matrix dimension (width*height) or (cols*rows)

◆ distanceTo()

template<class T>
T icl::math::DynMatrix< T >::distanceTo ( const DynMatrix< T > &  other) const
inline

returns the distance of the inner data vectors (linearly interpreted) (IPP accelerated)

◆ dot()

template<class T>
DynMatrix<T> icl::math::DynMatrix< T >::dot ( const DynMatrix< T > &  M) const
inline

returns the inner product of two matrices (i.e. dot-product)

A.dot(B) is equivalent to A.transp() * B TODO: optimize implementation (current implementation is A.transp() * B)

◆ eigen()

template<class T>
void icl::math::DynMatrix< T >::eigen ( DynMatrix< T > &  eigenvectors,
DynMatrix< T > &  eigenvalues 
) const

Extracts the matrix's eigenvalues and eigenvectors.

This function only works on squared symmetric matrices. Resulting eigenvalues are ordered in descending order. The destination matrices' sizes are adapted automatically.

The function is only available for icl32f and icl64f and it is IPP-accelerated in case of having Intel-IPP-Support. The Fallback implementation was basically taken from the Visualization Toolkit VTK (Version 5.6.0)

Note: There is no internal check if the matrix is really symmetric. If it is not symmetric, the behaviour of this function is not predictable

Parameters
eigenvectorscontains the resulting eigenvectors in it's columns
eigenvaluesbecomes a N-dimensional column vector which ith element is the eigenvalue that corresponds to the ith column of eigenvectors

◆ element_wise_inner_product()

template<class T>
T icl::math::DynMatrix< T >::element_wise_inner_product ( const DynMatrix< T > &  other) const
inline

inner product of data pointers (not matrix-mulitiplication)

computes the inner-product of data vectors

◆ elementwise_div() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::elementwise_div ( const DynMatrix< T > &  m,
DynMatrix< T > &  dst 
) const
inline

Elementwise division (in source destination fashion) [IPP-Supported].

◆ elementwise_div() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::elementwise_div ( const DynMatrix< T > &  m) const
inline

Elementwise matrix multiplication (without destination matrix) [IPP-Supported].

◆ elementwise_mult() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::elementwise_mult ( const DynMatrix< T > &  m,
DynMatrix< T > &  dst 
) const
inline

Elementwise matrix multiplication (in source destination fashion) [IPP-Supported].

◆ elementwise_mult() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::elementwise_mult ( const DynMatrix< T > &  m) const
inline

Elementwise matrix multiplication (without destination matrix) [IPP-Supported].

◆ end() [1/2]

template<class T>
iterator icl::math::DynMatrix< T >::end ( )
inline

returns an iterator to the end of internal data array

◆ end() [2/2]

template<class T>
const_iterator icl::math::DynMatrix< T >::end ( ) const
inline

returns an iterator to the end of internal data array (const)

◆ id()

template<class T>
static DynMatrix icl::math::DynMatrix< T >::id ( unsigned int  dim)
inlinestatic

creates a dim-D identity Matrix

◆ idx_check() [1/2]

template<class T>
void icl::math::DynMatrix< T >::idx_check ( unsigned int  col,
unsigned int  row 
) const
inlineprivate

◆ idx_check() [2/2]

template<class T>
void icl::math::DynMatrix< T >::idx_check ( unsigned int  idx) const
inlineprivate

◆ inv()

template<class T>
DynMatrix icl::math::DynMatrix< T >::inv ( ) const

invert the matrix (only for icl32f and icl64f)

◆ isNull()

template<class T>
bool icl::math::DynMatrix< T >::isNull ( ) const
inline

returns with this matrix has a valid data pointer

◆ isSimilar()

template<class T>
bool icl::math::DynMatrix< T >::isSimilar ( const DynMatrix< T > &  other,
tollerance = T(0.0001) 
) const
inline

tests weather a matrix is enough similar to another matrix

◆ loadCSV()

template<class T>
static DynMatrix<T> icl::math::DynMatrix< T >::loadCSV ( const std::string &  filename)
static

loads a dynmatrix from given CSV file

supported types T are all icl8u, icl16s, icl32s, icl32f, icl64f. Each row of the CSV file becomes a matrix row. The column delimiter is ',' Rows, that begin with '#' or with ' ' or that have no length are ignored

◆ mult() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::mult ( f,
DynMatrix< T > &  dst 
) const
inline

Multiply elements with scalar (in source destination fashion)

◆ mult() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::mult ( const DynMatrix< T > &  m,
DynMatrix< T > &  dst 
) const
inline

Matrix multiplication (in source destination fashion) [IPP-Supported].

◆ norm()

template<class T>
T icl::math::DynMatrix< T >::norm ( double  l = 2) const
inline

applies an L_l norm on the matrix elements (all elements are treated as vector)

◆ operator *() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator * ( f) const
inline

Multiply elements with scalar.

◆ operator *() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator * ( const DynMatrix< T > &  m) const
inline

Essential matrix multiplication [IPP-Supported].

◆ operator *=() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator *= ( f)
inline

Multiply elements with scalar (inplace)

◆ operator *=() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator *= ( const DynMatrix< T > &  m)
inline

inplace matrix multiplication applying this = this*m [IPP-Supported]

◆ operator!=()

template<class T>
bool icl::math::DynMatrix< T >::operator!= ( const DynMatrix< T > &  other) const
inline

elementwise comparison (!=)

◆ operator()() [1/2]

template<class T>
T& icl::math::DynMatrix< T >::operator() ( unsigned int  col,
unsigned int  row 
)
inline

element access operator (x,y)-access index begin 0!

◆ operator()() [2/2]

template<class T>
const T& icl::math::DynMatrix< T >::operator() ( unsigned int  col,
unsigned int  row 
) const
inline

element access operator (x,y)-access index begin 0! (const)

◆ operator+() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator+ ( const T &  t) const
inline

adds a scalar to each element

◆ operator+() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator+ ( const DynMatrix< T > &  m) const
inline

Matrix addition.

◆ operator+=() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator+= ( const T &  t)
inline

adds a scalar to each element (inplace)

◆ operator+=() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator+= ( const DynMatrix< T > &  m)
inline

Matrix addition (inplace)

◆ operator-() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator- ( const T &  t) const
inline

substacts a scalar from each element

◆ operator-() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator- ( const DynMatrix< T > &  m) const
inline

Matrix substraction.

◆ operator-=() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator-= ( const T &  t)
inline

substacts a scalar from each element (inplace)

◆ operator-=() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator-= ( const DynMatrix< T > &  m)
inline

Matrix substraction (inplace)

◆ operator/() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator/ ( f) const
inline

Device elements by scalar.

◆ operator/() [2/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::operator/ ( const DynMatrix< T > &  m) const
inline

inplace matrix devision (calling this/m.inv()) [IPP-Supported]

◆ operator/=() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator/= ( f)
inline

Device elements by scalar (inplace)

◆ operator/=() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator/= ( const DynMatrix< T > &  m) const
inline

inplace matrix devision (calling this/m.inv()) (inplace)

◆ operator=() [1/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator= ( const DynMatrix< T > &  other)
inline

Assignment operator (using deep/shallow-copy)

In general, the assignment operator applys a deep copy only in case of (*this) is not initialized and other is a shallow copy, (*this) will also become a shallow copy of the data referenced by other

◆ operator=() [2/2]

template<class T>
DynMatrix& icl::math::DynMatrix< T >::operator= ( const DynMatrixColumn col)
inline

◆ operator==()

template<class T>
bool icl::math::DynMatrix< T >::operator== ( const DynMatrix< T > &  other) const
inline

elementwise comparison (==)

◆ operator[]() [1/2]

template<class T>
T& icl::math::DynMatrix< T >::operator[] ( unsigned int  idx)
inline

linear access to actual data array

◆ operator[]() [2/2]

template<class T>
const T& icl::math::DynMatrix< T >::operator[] ( unsigned int  idx) const
inline

linear access to actual data array (const)

◆ pinv()

template<class T>
DynMatrix icl::math::DynMatrix< T >::pinv ( bool  useSVD = false,
zeroThreshold = T(1E-16) 
) const

calculates the Moore-Penrose pseudo-inverse (only implemented for icl32f and icl64f)

Internally, this functions can use either a QR-decomposition based approach, or it can use SVD. QR-Decomposition is already much more stable than the naiv approach pinv(X) = X*(X*X')^(-1)

return R.inv() * Q.transp();

The QR-decomposition based approach does not use the zeroThreshold variable.

If useSVD is set to true, internally an SVD based approach is used:

DynMatrix S,v,D; svd_dyn(*this,U,s,V);

DynMatrix S(s.rows(),s.rows(),0.0f); for(unsigned int i=0;i<s.rows();++i){ S(i,i) = (fabs(s[i]) > zeroThreshold) ? 1.0/s[i] : 0; } return V * S * U.transp();

◆ reshape()

template<class T>
void icl::math::DynMatrix< T >::reshape ( int  newCols,
int  newRows 
)
inline

resets the matrix dimensions without changing the content

This methods can only be used in case of cols()*rows() equals to newCols*newRows. If this dependency is fulfilled, only the matrix's m_cols and m_rows member variables are adapted according to the new values. The internal data is not touched at all, so the matrix's internal row-major data order is not affected.

This method can particularly be used to cheaply convert a row-vector matrix into a column vector matrix.

◆ row() [1/2]

template<class T>
DynMatrix icl::math::DynMatrix< T >::row ( int  row)
inline

Extracts a shallow copied matrix row.

◆ row() [2/2]

template<class T>
const DynMatrix icl::math::DynMatrix< T >::row ( int  row) const
inline

Extracts a shallow copied matrix row (const)

◆ row_begin() [1/2]

template<class T>
row_iterator icl::math::DynMatrix< T >::row_begin ( unsigned int  row)
inline

returns an iterator running through a certain matrix row

◆ row_begin() [2/2]

template<class T>
const_row_iterator icl::math::DynMatrix< T >::row_begin ( unsigned int  row) const
inline

returns an iterator running through a certain matrix row (const)

◆ row_check()

template<class T>
void icl::math::DynMatrix< T >::row_check ( unsigned int  row) const
inlineprivate

◆ row_end() [1/2]

template<class T>
row_iterator icl::math::DynMatrix< T >::row_end ( unsigned int  row)
inline

returns an iterator of a certains row's end

◆ row_end() [2/2]

template<class T>
const_row_iterator icl::math::DynMatrix< T >::row_end ( unsigned int  row) const
inline

returns an iterator of a certains row's end (const)

◆ rows()

template<class T>
unsigned int icl::math::DynMatrix< T >::rows ( ) const
inline

height of the matrix (number of rows)

◆ saveCSV()

template<class T>
void icl::math::DynMatrix< T >::saveCSV ( const std::string &  filename)

writes the current matrix to a csv file

supported types T are all icl8u, icl16s, icl32s, icl32f, icl64f

◆ set_data()

template<class T>
T* icl::math::DynMatrix< T >::set_data ( T *  newData)
inline

sets new data internally and returns old data pointer (for experts only!)

◆ setBounds()

template<class T>
void icl::math::DynMatrix< T >::setBounds ( unsigned int  cols,
unsigned int  rows,
bool  holdContent = false,
const T &  initializer = 0 
)
inline

resets matrix dimensions

◆ shallowTransposed() [1/2]

template<class T>
const DynMatrix<T> icl::math::DynMatrix< T >::shallowTransposed ( ) const
inline

returns a shallow transposed copy of this matrix (dimensions are swapped, data is not re-aranged) (const)

This is usually only useful for transposing row- to colume vectors and vice versa.

◆ shallowTransposed() [2/2]

template<class T>
const DynMatrix<T> icl::math::DynMatrix< T >::shallowTransposed ( )
inline

returns a shallow transposed copy of this matrix (dimensions are swapped, data is not re-aranged)

◆ solve()

template<class T>
DynMatrix icl::math::DynMatrix< T >::solve ( const DynMatrix< T > &  b,
const std::string &  method = "lu",
zeroThreshold = T(1E-16) 
)

solves Mx=b for M=*this (only for icl32f and icl64f)

solves Mx=b using one of the following algorithms

Parameters
b
method"lu" (default) using LU-decomposition "svd" (using svd-based pseudo-inverse) "qr" (using QR-decomposition based pseudo-inverse) "inv" (using matrix inverse)

Benchmarks

While LU decomposition based solving provides the worst results, it is also the fastest method in general. Only in case of having very small matrices (e.g. 4x4), other methods are faster. A double precision random N by N system is solved up to an accuracy of about 10e-5 if LU decomposition is used. All other methods provide accuracies of about 10e-14 in case of double precision.

Here are some benchmarks for double precision: 10.000 times 4x4 matrix: inv 16.2 ms lu 26.7 ms qr 105 ms svd 142 ms 10.000 times 5x5 matrix: inv 20.2 ms lu 30.2 ms qr 148 ms svd 131 ms 10.000 times 6x6 matrix: inv 26.9 ms lu 35.6 ms qr 206 ms svd 192 ms 10.000 times 4x4 matrix: inv 448 ms lu 42 ms qr 642 ms svd 237 ms 10.000 times 10x10 matrix: inv 2200 ms lu 75 ms qr 3000 ms svd 495 ms 10 times 50x50 matrix: note: here we have inv and qr in seconds and only 10 trials! inv 5.7 s lu 2.5 ms qr 4.6 s svd 23.4 ms

Parameters
zeroThreshold

◆ solve_lower_triangular()

template<class T>
DynMatrix icl::math::DynMatrix< T >::solve_lower_triangular ( const DynMatrix< T > &  b) const

solves Mx=b for M=*this (only if M is a squared lower triangular matrix) (only for icl32f and icl64f)

◆ solve_upper_triangular()

template<class T>
DynMatrix icl::math::DynMatrix< T >::solve_upper_triangular ( const DynMatrix< T > &  b) const

solves Mx=b for M=*this (only if M is a squared upper triangular matrix) (only for icl32f and icl64f)

◆ sqrDistanceTo()

template<class T>
T icl::math::DynMatrix< T >::sqrDistanceTo ( const DynMatrix< T > &  other) const
inline

returns the squared distance of the inner data vectors (linearly interpreted) (IPP accelerated)

◆ stride0()

template<class T>
int icl::math::DynMatrix< T >::stride0 ( ) const
inline

returns sizeof (T)*dim()

◆ stride1()

template<class T>
int icl::math::DynMatrix< T >::stride1 ( ) const
inline

returns sizeof(T)*cols()

◆ stride2()

template<class T>
int icl::math::DynMatrix< T >::stride2 ( ) const
inline

returns sizeof (T)

◆ svd()

template<class T>
void icl::math::DynMatrix< T >::svd ( DynMatrix< T > &  U,
DynMatrix< T > &  S,
DynMatrix< T > &  V 
) const

Computes Singular Value Decomposition of a matrix - decomposes A into USV'.

Internaly, this function will always use double values. Other types are converted internally. This funciton is only instantiated for icl32f and icl64f.

Parameters
Uis filled column-wise with the eigenvectors of AA'
Sis filled with the singular values of A (s is a ColumnVector and not diagonal matrix)
Vis filled column-wise with the eigenvectors of A'A (in V, V is stored not V')
See also
icl::svd_dyn

◆ trace()

template<class T>
T icl::math::DynMatrix< T >::trace ( ) const
inline

computes the sum of all diagonal elements

◆ transp()

template<class T>
DynMatrix icl::math::DynMatrix< T >::transp ( ) const
inline

matrix transposed

Member Data Documentation

◆ m_cols

template<class T>
int icl::math::DynMatrix< T >::m_cols
private

◆ m_data

template<class T>
T* icl::math::DynMatrix< T >::m_data
private

◆ m_ownData

template<class T>
bool icl::math::DynMatrix< T >::m_ownData
private

◆ m_rows

template<class T>
int icl::math::DynMatrix< T >::m_rows
private

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