Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::Matrix< M, N, T > Struct Template Reference

Generic fixed-size dense matrix class using a row-major storage format. More...

#include <mitsuba/core/matrix.h>

Public Member Functions

 Matrix ()
 Construct a new MxN matrix without initializing it. More...
 
 Matrix (T value)
 Initialize the matrix with constant entries. More...
 
 Matrix (const T _m[M][N])
 Initialize the matrix from a given MxN array. More...
 
 Matrix (const T _m[M *N])
 Initialize the matrix from a given (flat) MxN array in row-major order. More...
 
 Matrix (Stream *stream)
 Unserialize a matrix from a stream. More...
 
 Matrix (const Matrix &mtx)
 Copy constructor. More...
 
void setIdentity ()
 Initialize with the identity matrix. More...
 
void setZero ()
 Initialize with zeroes. More...
 
T & operator() (int i, int j)
 Indexing operator. More...
 
const T & operator() (int i, int j) const
 Indexing operator (const verions) More...
 
bool operator== (const Matrix &mat) const
 Equality operator. More...
 
bool operator!= (const Matrix &mat) const
 Inequality operator. More...
 
Matrixoperator= (const Matrix &mat)
 Assignment operator. More...
 
Matrix operator+ (const Matrix &mat) const
 Matrix addition (returns a temporary) More...
 
Matrix operator+ (T value) const
 Matrix-scalar addition (returns a temporary) More...
 
const Matrixoperator+= (const Matrix &mat)
 Matrix addition. More...
 
const Matrixoperator+= (T value)
 Matrix-scalar addition. More...
 
Matrix operator- (const Matrix &mat) const
 Matrix subtraction (returns a temporary) More...
 
Matrix operator- (T value) const
 Matrix-scalar subtraction (returns a temporary) More...
 
const Matrixoperator-= (const Matrix &mat)
 Matrix subtraction. More...
 
const Matrixoperator- (T value)
 Matrix-scalar subtraction. More...
 
const Matrixoperator-= (T value)
 Matrix-scalar addition. More...
 
Matrix operator- () const
 Component-wise negation. More...
 
Matrix operator* (T value) const
 Scalar multiplication (creates a temporary) More...
 
const Matrixoperator*= (T value)
 Scalar multiplication. More...
 
Matrix operator/ (T value) const
 Scalar division (creates a temporary) More...
 
const Matrixoperator/= (T value)
 Scalar division. More...
 
const Matrixoperator*= (const Matrix &mat)
 Matrix multiplication (for square matrices) More...
 
Float trace () const
 Compute the trace of a square matrix. More...
 
Float frob () const
 Compute the Frobenius norm. More...
 
bool lu (Matrix &LU, int piv[M], int &pivsign) const
 Compute the LU decomposition of a matrix. More...
 
bool chol (Matrix &L) const
 
template<int K>
void cholSolve (const Matrix< M, K, T > &B, Matrix< M, K, T > &X) const
 
template<int K>
void luSolve (const Matrix< M, K, T > &B, Matrix< M, K, T > &X, int piv[M]) const
 
luDet (int pivsign) const
 Compute the determinant of a decomposed matrix created by lu() More...
 
cholDet () const
 Compute the determinant of a decomposed matrix created by chol() More...
 
bool isZero () const
 Check if the matrix is identically zero. More...
 
bool isIdentity () const
 Test if this is the identity matrix. More...
 
det () const
 Compute the determinant of a square matrix (internally creates a LU decomposition) More...
 
bool invert (Matrix &target) const
 Compute the inverse of a square matrix using the Gauss-Jordan algorithm. More...
 
void symEig (Matrix &Q, T d[M]) const
 Perform a symmetric eigendecomposition of a square matrix into Q and D. More...
 
void transpose (Matrix< N, M, T > &target) const
 Compute the transpose of this matrix. More...
 
void serialize (Stream *stream) const
 Serialize the matrix to a stream. More...
 
std::string toString () const
 Return a string representation. More...
 
template<int K>
void cholSolve (const Matrix< M, K, T > &B, Matrix< M, K, T > &X) const
 
template<int K>
void luSolve (const Matrix< M, K, T > &B, Matrix< M, K, T > &X, int piv[M]) const
 

Public Attributes

m [M][N]
 

Static Protected Member Functions

static void tred2 (T V[M][N], T d[N], T e[N])
 Symmetric Householder reduction to tridiagonal form. More...
 
static void tql2 (T V[M][N], T d[N], T e[N])
 Symmetric tridiagonal QL algorithm. More...
 

Detailed Description

template<int M, int N, typename T>
struct mitsuba::Matrix< M, N, T >

Generic fixed-size dense matrix class using a row-major storage format.

Constructor & Destructor Documentation

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( )
inline

Construct a new MxN matrix without initializing it.

This constructor is useful when the matrix will either not be used at all (it might be part of a larger data structure) or initialized at a later point in time. Always make sure that one of the two is the case! Otherwise your program will do computations involving uninitialized memory, which will probably lead to a difficult-to-find bug.

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( value)
inlineexplicit

Initialize the matrix with constant entries.

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( const T  _m[M][N])
inlineexplicit

Initialize the matrix from a given MxN array.

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( const T  _m[M *N])
inlineexplicit

Initialize the matrix from a given (flat) MxN array in row-major order.

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( Stream stream)
inlineexplicit

Unserialize a matrix from a stream.

template<int M, int N, typename T>
mitsuba::Matrix< M, N, T >::Matrix ( const Matrix< M, N, T > &  mtx)
inline

Copy constructor.

Member Function Documentation

template<int M, int N, typename T>
MTS_NAMESPACE_BEGIN bool Matrix< M, N, T >::chol ( Matrix< M, N, T > &  L) const

Compute the Cholesky decomposition of a symmetric positive definite matrix

Parameters
LTarget matrix (a lower triangular matrix such that A=L*L')
Returns
false If the matrix is not symmetric positive definite. Based on the implementation in JAMA.
template<int M, int N, typename T>
T Matrix< M, N, T >::cholDet ( ) const

Compute the determinant of a decomposed matrix created by chol()

template<int M, int N, typename T>
template<int K>
void mitsuba::Matrix< M, N, T >::cholSolve ( const Matrix< M, K, T > &  B,
Matrix< M, K, T > &  X 
) const
template<int M, int N, typename T>
template<int K>
void mitsuba::Matrix< M, N, T >::cholSolve ( const Matrix< M, K, T > &  B,
Matrix< M, K, T > &  X 
) const

Solve A*X==B, where this is a Cholesky decomposition of A created by chol()

Parameters
BA matrix with as many rows as A and any number of columns
XA matrix such that L*L'*X == B

Based on the implementation in JAMA.

template<int M, int N, typename T>
T mitsuba::Matrix< M, N, T >::det ( ) const
inline

Compute the determinant of a square matrix (internally creates a LU decomposition)

template<int M, int N, typename T>
Float mitsuba::Matrix< M, N, T >::frob ( ) const
inline

Compute the Frobenius norm.

template<int M, int N, typename T>
bool Matrix< M, N, T >::invert ( Matrix< M, N, T > &  target) const

Compute the inverse of a square matrix using the Gauss-Jordan algorithm.

template<int M, int N, typename T>
bool mitsuba::Matrix< M, N, T >::isIdentity ( ) const
inline

Test if this is the identity matrix.

template<int M, int N, typename T>
bool mitsuba::Matrix< M, N, T >::isZero ( ) const
inline

Check if the matrix is identically zero.

template<int M, int N, typename T>
bool Matrix< M, N, T >::lu ( Matrix< M, N, T > &  LU,
int  piv[M],
int &  pivsign 
) const

Compute the LU decomposition of a matrix.

For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U,

and a permutation vector piv of length m so that A(piv,:) = L*U. If m < n, then L is m-by-m and U is m-by-n.

The LU decomposition with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the

LU decomposition is in the solution of square systems of simultaneous linear equations.

Parameters
Targetmatrix (the L and U parts will be stored together in a packed format)
pivStorage for the permutation created by the pivoting
pivsignSign of the permutation
Returns
true if the matrix was nonsingular.

Based on the implementation in JAMA.

template<int M, int N, typename T>
T Matrix< M, N, T >::luDet ( int  pivsign) const

Compute the determinant of a decomposed matrix created by lu()

Parameters
pivsignThe sign of the pivoting permutation returned by lu()

Based on the implementation in JAMA.

template<int M, int N, typename T>
template<int K>
void mitsuba::Matrix< M, N, T >::luSolve ( const Matrix< M, K, T > &  B,
Matrix< M, K, T > &  X,
int  piv[M] 
) const
template<int M, int N, typename T>
template<int K>
void mitsuba::Matrix< M, N, T >::luSolve ( const Matrix< M, K, T > &  B,
Matrix< M, K, T > &  X,
int  piv[M] 
) const

Solve A*X==B, where this is a LU decomposition of A created by lu()

Parameters
BA matrix with as many rows as A and any number of columns
XA matrix such that L*U*X == B(piv, :)
pivPivot vector returned by lu()

Based on the implementation in JAMA.

template<int M, int N, typename T>
bool mitsuba::Matrix< M, N, T >::operator!= ( const Matrix< M, N, T > &  mat) const
inline

Inequality operator.

template<int M, int N, typename T>
T& mitsuba::Matrix< M, N, T >::operator() ( int  i,
int  j 
)
inline

Indexing operator.

template<int M, int N, typename T>
const T& mitsuba::Matrix< M, N, T >::operator() ( int  i,
int  j 
) const
inline

Indexing operator (const verions)

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator* ( value) const
inline

Scalar multiplication (creates a temporary)

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator*= ( value)
inline

Scalar multiplication.

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator*= ( const Matrix< M, N, T > &  mat)
inline

Matrix multiplication (for square matrices)

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator+ ( const Matrix< M, N, T > &  mat) const
inline

Matrix addition (returns a temporary)

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator+ ( value) const
inline

Matrix-scalar addition (returns a temporary)

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator+= ( const Matrix< M, N, T > &  mat)
inline

Matrix addition.

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator+= ( value)
inline

Matrix-scalar addition.

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator- ( const Matrix< M, N, T > &  mat) const
inline

Matrix subtraction (returns a temporary)

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator- ( value) const
inline

Matrix-scalar subtraction (returns a temporary)

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator- ( value)
inline

Matrix-scalar subtraction.

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator- ( ) const
inline

Component-wise negation.

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator-= ( const Matrix< M, N, T > &  mat)
inline

Matrix subtraction.

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator-= ( value)
inline

Matrix-scalar addition.

template<int M, int N, typename T>
Matrix mitsuba::Matrix< M, N, T >::operator/ ( value) const
inline

Scalar division (creates a temporary)

template<int M, int N, typename T>
const Matrix& mitsuba::Matrix< M, N, T >::operator/= ( value)
inline

Scalar division.

template<int M, int N, typename T>
Matrix& mitsuba::Matrix< M, N, T >::operator= ( const Matrix< M, N, T > &  mat)
inline

Assignment operator.

template<int M, int N, typename T>
bool mitsuba::Matrix< M, N, T >::operator== ( const Matrix< M, N, T > &  mat) const
inline

Equality operator.

template<int M, int N, typename T>
void mitsuba::Matrix< M, N, T >::serialize ( Stream stream) const
inline

Serialize the matrix to a stream.

template<int M, int N, typename T>
void mitsuba::Matrix< M, N, T >::setIdentity ( )
inline

Initialize with the identity matrix.

template<int M, int N, typename T>
void mitsuba::Matrix< M, N, T >::setZero ( )
inline

Initialize with zeroes.

template<int M, int N, typename T>
void mitsuba::Matrix< M, N, T >::symEig ( Matrix< M, N, T > &  Q,
d[M] 
) const
inline

Perform a symmetric eigendecomposition of a square matrix into Q and D.

Based on the implementation in JAMA.

template<int M, int N, typename T>
std::string mitsuba::Matrix< M, N, T >::toString ( ) const
inline

Return a string representation.

template<int M, int N, typename T>
void Matrix< M, N, T >::tql2 ( V[M][N],
d[N],
e[N] 
)
staticprotected

Symmetric tridiagonal QL algorithm.

template<int M, int N, typename T>
Float mitsuba::Matrix< M, N, T >::trace ( ) const
inline

Compute the trace of a square matrix.

template<int M, int N, typename T>
void mitsuba::Matrix< M, N, T >::transpose ( Matrix< N, M, T > &  target) const
inline

Compute the transpose of this matrix.

template<int M, int N, typename T>
void Matrix< M, N, T >::tred2 ( V[M][N],
d[N],
e[N] 
)
staticprotected

Symmetric Householder reduction to tridiagonal form.

Member Data Documentation

template<int M, int N, typename T>
T mitsuba::Matrix< M, N, T >::m[M][N]

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