MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | Related Functions | List of all members
mgx::util::Matrix< nRows, nCols, T > Class Template Reference

Class representing a fixed-size matrix. More...

#include <Matrix.hpp>

Public Types

typedef T value_type
 
typedef T & reference_type
 
typedef const T & const_reference_type
 
typedef T * pointer_type
 
typedef const T * const_pointer_type
 
typedef T * iterator
 
typedef const T * const_iterator
 

Public Member Functions

CU_HOST_DEVICE Matrix (void)
 Create a matrix filled with 0s.
 
template<typename T1 >
CU_HOST_DEVICE Matrix (const Matrix< nRows, nCols, T1 > &mat)
 Copy a matrix. More...
 
template<typename T1 >
CU_HOST_DEVICE Matrix (const Vector< nCols, T1 > *vecs)
 Fill the matrix with the array of vectors. More...
 
template<typename T1 >
CU_HOST_DEVICE Matrix (const T1 *values, MatrixLayout layout=C_STYLE)
 Fill in the matrix with the values. More...
 
CU_HOST_DEVICE Matrix (const T *values, MatrixLayout layout=C_STYLE)
 Fill in the matrix with the values. More...
 
CU_HOST_DEVICE Matrix (const T &value)
 Create a diagonal matrix. More...
 
CU_HOST_DEVICE const T * c_data () const
 Returns a constant raw pointer on the data. More...
 
CU_HOST_DEVICE T * data ()
 Returns a raw pointer on the data. More...
 
CU_HOST_DEVICE Matrix operator- (void) const
 Matrix subtraction.
 
CU_HOST_DEVICE Matrix operator+ (const Matrix &mat) const
 Matrix addition. More...
 
CU_HOST_DEVICE Matrix operator- (const Matrix &mat) const
 
CU_HOST_DEVICE Matrix operator* (const T &scalar) const
 Matrix-scalar multiplication.
 
CU_HOST_DEVICE Matrix operator/ (const T &scalar) const
 Matrix-scalar division.
 
CU_HOST_DEVICE Vector< nRows, T > operator* (const Vector< nCols, T > &vec) const
 Matrix*Column Vector.
 
CU_HOST_DEVICE Matrixoperator= (const Matrix &mat)
 
CU_HOST_DEVICE Matrixoperator+= (const Matrix &mat)
 
CU_HOST_DEVICE Matrixoperator-= (const Matrix &mat)
 
CU_HOST_DEVICE Matrixoperator*= (const T &scalar)
 
CU_HOST_DEVICE Matrixoperator/= (const T &scalar)
 
CU_HOST_DEVICE Matrixoperator*= (const Matrix &mat)
 
bool operator== (const Matrix &mat) const
 
CU_HOST_DEVICE bool operator!= (const Matrix &mat) const
 
CU_HOST_DEVICE Vector< nCols, T > & operator[] (size_t idx)
 Returns the nth row. More...
 
CU_HOST_DEVICE Vector< nCols, T > operator[] (size_t idx) const
 Returns the nth row. More...
 
CU_HOST_DEVICE T & operator() (size_t i, size_t j)
 Return the value at row i, column j.
 
CU_HOST_DEVICE T operator() (size_t i, size_t j) const
 Return the value at row i, column j.
 
CU_HOST_DEVICE Matrixzero (void)
 Set the matrix to all zero.
 
CU_HOST_DEVICE Matrixoperator= (const T &value)
 Set the matrix to a diagonal matrix. More...
 
CU_HOST_DEVICE Matrix< nCols,
nRows, T > 
operator~ ()
 Transpose the matrix.
 
CU_HOST_DEVICE T trace () const
 Trace of the matrix.
 
CU_HOST_DEVICE void fillArray (T *array, MatrixLayout layout=C_STYLE)
 
CU_HOST_DEVICE Vector< nRows, T > diag () const
 Return the diagonal vector, if the matrix is square.
 

Static Public Member Functions

static CU_HOST_DEVICE Vector
< 2, size_t > 
size ()
 Returns the size of the matrix. More...
 
static CU_HOST_DEVICE size_t nbRows ()
 Returns the number of rows of the matrix.
 
static CU_HOST_DEVICE size_t nbColumns ()
 Returns the number of columns of the matrix.
 
static CU_HOST_DEVICE Matrix identity ()
 Returns an identity matrix.
 
static CU_HOST_DEVICE Matrix
< 3, 3, T > 
rotation (const Vector< 3, T > &direction, T angle)
 Creates the 3x3 matrix corresponding to a rotation. More...
 
static CU_HOST_DEVICE Matrix
< 4, 4, T > 
rotation (const Vector< 4, T > &direction, T angle)
 Creates the 4x4 matrix corresponding to a rotation. More...
 

Static Public Attributes

static const size_t numcols
 
static const size_t numrows
 

Friends

CU_HOST_DEVICE friend Matrix operator* (const T &scalar, const Matrix &mat)
 Matrix-scalar multiplication.
 
QTextStreamoperator<< (QTextStream &out, const Matrix &mat)
 
QTextStreamoperator>> (QTextStream &in, Matrix &mat)
 
CU_HOST_DEVICE friend
std::ostream & 
operator<< (std::ostream &out, const Matrix &mat)
 
CU_HOST_DEVICE friend
std::istream & 
operator>> (std::istream &in, Matrix &mat)
 

Related Functions

(Note that these are not member functions.)

template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Vector< nCols, T > operator* (const Vector< nCols, T > &vec, const Matrix< nRows, nCols, T > &mat)
 Row-Vector - Matrix multipliation.
 
template<size_t nRows, size_t nSize, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
operator* (const Matrix< nRows, nSize, T > &mat1, const Matrix< nSize, nCols, T > &mat2)
 Matrix multiplication.
 
template<typename T >
T CU_HOST_DEVICE det (const Matrix< 1, 1, T > &mat)
 Determinant of the matrix.
 
template<typename T >
T CU_HOST_DEVICE det (const Matrix< 2, 2, T > &mat)
 Determinant of the matrix.
 
template<typename T >
T CU_HOST_DEVICE det (const Matrix< 3, 3, T > &mat)
 Determinant of the matrix.
 
template<size_t nRows, typename T >
T CU_HOST_DEVICE det (const Matrix< nRows, nRows, T > &mat)
 Determinant of the matrix. More...
 
template<size_t nRows, typename T >
CU_HOST_DEVICE T cofactor (const Matrix< nRows, nRows, T > &mat, size_t i, size_t j)
 Returns the cofactor of the matrix for position (i,j)
 
template<typename T >
CU_HOST_DEVICE Matrix< 1, 1, T > inverse (const Matrix< 1, 1, T > &mat)
 Inverse the matrix.
 
template<typename T >
CU_HOST_DEVICE Matrix< 2, 2, T > inverse (const Matrix< 2, 2, T > &mat)
 Inverse the matrix.
 
template<typename T >
CU_HOST_DEVICE Matrix< 3, 3, T > inverse (const Matrix< 3, 3, T > &mat)
 Inverse the matrix.
 
template<typename T >
CU_HOST_DEVICE Matrix< 4, 4, T > inverse (const Matrix< 4, 4, T > &mat)
 Inverse the matrix.
 
template<size_t nRows, typename T >
CU_HOST_DEVICE Matrix< nRows,
nRows, T > 
inverse (const Matrix< nRows, nRows, T > &mat)
 Inverse the matrix. More...
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nCols,
nRows, T > 
transpose (const Matrix< nRows, nCols, T > &mat)
 Transpose a matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE T norm (const Matrix< nRows, nCols, T > &mat)
 Return the norm of the matrix. More...
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE T normsq (const Matrix< nRows, nCols, T > &mat)
 Return the square norm of the matrix. More...
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (const T &(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(T), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(const T &), const Matrix< nRows, nCols, T > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (const T &(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(T1), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(const T1 &), const Matrix< nRows, nCols, T1 > &m)
 Apply a unary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(T, T), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (const T &(*fct)(const T &, const T &), const Matrix< nRows, nCols, T > &m1, const Matrix< nRows, nCols, T > &m2)
 Apply a binary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(T1, T2), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (T(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
 
template<size_t nRows, size_t nCols, typename T , typename T1 , typename T2 >
CU_HOST_DEVICE Matrix< nRows,
nCols, T > 
map (const T &(*fct)(const T1 &, const T2 &), const Matrix< nRows, nCols, T1 > &m1, const Matrix< nRows, nCols, T2 > &m2)
 Apply a binary function to each element of the matrix.
 

Detailed Description

template<size_t nRows, size_t nCols, typename T = double>
class mgx::util::Matrix< nRows, nCols, T >

Class representing a fixed-size matrix.

This class is optimized for small-sized matrix (3x3 or 4x4).

Constructor & Destructor Documentation

template<size_t nRows, size_t nCols, typename T = double>
template<typename T1 >
CU_HOST_DEVICE mgx::util::Matrix< nRows, nCols, T >::Matrix ( const Matrix< nRows, nCols, T1 > &  mat)
inline

Copy a matrix.

Can be used to cast a matrix onto another type.

template<size_t nRows, size_t nCols, typename T = double>
template<typename T1 >
CU_HOST_DEVICE mgx::util::Matrix< nRows, nCols, T >::Matrix ( const Vector< nCols, T1 > *  vecs)
inline

Fill the matrix with the array of vectors.

Parameters
vecsArray of nRows vectors.
template<size_t nRows, size_t nCols, typename T = double>
template<typename T1 >
CU_HOST_DEVICE mgx::util::Matrix< nRows, nCols, T >::Matrix ( const T1 *  values,
MatrixLayout  layout = C_STYLE 
)
inline

Fill in the matrix with the values.

Parameters
valuesnRows*nCols array. If c_style is true, values is rows first (i.e. the first values correspond to the first row). Otherwise, values are columns first.
c_styleDetermine the ordering of values.
template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE mgx::util::Matrix< nRows, nCols, T >::Matrix ( const T *  values,
MatrixLayout  layout = C_STYLE 
)
inline

Fill in the matrix with the values.

Parameters
valuesnRows*nCols array. If c_style is true, values is rows first (i.e. the first values correspond to the first row). Otherwise, values are columns first.
c_styleDetermine the ordering of values.
template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE mgx::util::Matrix< nRows, nCols, T >::Matrix ( const T &  value)
inline

Create a diagonal matrix.

Parameters
valueValue placed on the diagonal.

Member Function Documentation

template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE const T* mgx::util::Matrix< nRows, nCols, T >::c_data ( ) const
inline

Returns a constant raw pointer on the data.

The data are organised on by rows. (i.e. in the opposite order as OpenGL)

template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE T* mgx::util::Matrix< nRows, nCols, T >::data ( )
inline

Returns a raw pointer on the data.

The data are organised on by rows. (i.e. in the opposite order as OpenGL)

template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE Matrix mgx::util::Matrix< nRows, nCols, T >::operator+ ( const Matrix< nRows, nCols, T > &  mat) const
inline

Matrix addition.

Matrix subtraction

template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE Matrix& mgx::util::Matrix< nRows, nCols, T >::operator= ( const T &  value)
inline

Set the matrix to a diagonal matrix.

Parameters
valueValue to put on the diagonal
template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE Vector<nCols, T>& mgx::util::Matrix< nRows, nCols, T >::operator[] ( size_t  idx)
inline

Returns the nth row.

Parameters
idxIndex of the returned row
template<size_t nRows, size_t nCols, typename T = double>
CU_HOST_DEVICE Vector<nCols, T> mgx::util::Matrix< nRows, nCols, T >::operator[] ( size_t  idx) const
inline

Returns the nth row.

Parameters
idxIndex of the returned row
template<size_t nRows, size_t nCols, typename T = double>
static CU_HOST_DEVICE Matrix<3, 3, T> mgx::util::Matrix< nRows, nCols, T >::rotation ( const Vector< 3, T > &  direction,
angle 
)
inlinestatic

Creates the 3x3 matrix corresponding to a rotation.

Parameters
directionAxes of the rotation
angleAngle of the rotation
template<size_t nRows, size_t nCols, typename T = double>
static CU_HOST_DEVICE Matrix<4, 4, T> mgx::util::Matrix< nRows, nCols, T >::rotation ( const Vector< 4, T > &  direction,
angle 
)
inlinestatic

Creates the 4x4 matrix corresponding to a rotation.

Parameters
directionAxes of the rotation
angleAngle of the rotation
template<size_t nRows, size_t nCols, typename T = double>
static CU_HOST_DEVICE Vector<2, size_t> mgx::util::Matrix< nRows, nCols, T >::size ( )
inlinestatic

Returns the size of the matrix.

First element is number of rows, second is number of columns

Friends And Related Function Documentation

template<size_t nRows, typename T >
T CU_HOST_DEVICE det ( const Matrix< nRows, nRows, T > &  mat)
related

Determinant of the matrix.

Warning
the method used is $O(n^3)$ complexity !
template<size_t nRows, typename T >
CU_HOST_DEVICE Matrix< nRows, nRows, T > inverse ( const Matrix< nRows, nRows, T > &  mat)
related

Inverse the matrix.

Warning
This algorithm is sub-optimal
template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE T norm ( const Matrix< nRows, nCols, T > &  mat)
related

Return the norm of the matrix.

The norm is defined as the square-root of the sum of the square of the values.

template<size_t nRows, size_t nCols, typename T >
CU_HOST_DEVICE T normsq ( const Matrix< nRows, nCols, T > &  mat)
related

Return the square norm of the matrix.

See Also
norm(const Matrix&)

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