Public Member Functions | Protected Attributes | Friends | List of all members
mirtk::Matrix Class Reference

#include <Matrix.h>

Inheritance diagram for mirtk::Matrix:
Inheritance graph
Collaboration diagram for mirtk::Matrix:
Collaboration graph

Public Member Functions

MatrixAddToCol (int, double)
 Add scalar to values in specified column.
 
MatrixAddToRow (int, double)
 Add scalar to values in specified row.
 
MatrixAdjugate (double &)
 Adjugate matrix and return determinant.
 
void Clear ()
 Free memory.
 
double * Col (int c)
 Get pointer to matrix entries in specified column.
 
const double * Col (int c) const
 Get pointer to matrix entries in specified column.
 
int ColIndex (int) const
 Get column index of element given its linear index.
 
double ColMax (int) const
 Maximum value in specified column.
 
double ColMean (int) const
 Mean of row values in specified column.
 
double ColMin (int) const
 Minimum value in specified column.
 
void ColRange (int, double &, double &) const
 Minimum and maximum value in specified column.
 
int Cols () const
 Get number of columns.
 
double ColStd (int) const
 Standard deviation of row values in specified column.
 
double ColSum (int) const
 Sum of row values in specified column.
 
double ColVar (int) const
 Variance of row values in specified column.
 
double Det () const
 Calculate determinant of matrix.
 
double Det3x3 () const
 Calculate determinant of a 3x3 matrix.
 
bool Eigenvalues (Matrix &, Vector &, Matrix &) const
 
Matrix Exp () const
 
double Get (int) const
 Get value of element with specified linear index.
 
double Get (int, int) const
 Get value of element in specified row and column.
 
double * GetPointerToElements (int r=0, int c=0)
 
const double * GetPointerToElements (int r=0, int c=0) const
 
MatrixIdent ()
 Set to identity matrix.
 
void Import (const char *, int, int)
 Import matrix from text file (requires no. of expected rows and cols)
 
int Index (int, int) const
 Get linear index of element given its row and column indices.
 
void Initialize (int, int=-1, double *=NULL)
 Initialize matrix with number of rows and columns.
 
Matrix Inverse (bool use_svd_if_singular=true) const
 Get inverse matrix.
 
MatrixInvert (bool use_svd_if_singular=true)
 Invert matrix.
 
bool IsDiagonalizable () const
 Whether matrix is diagonalizable.
 
bool IsIdentity () const
 Returns true if the matrix is an identity matrix.
 
bool IsSquare () const
 Whether matrix is square.
 
bool IsSymmetric () const
 Whether matrix is symmetric.
 
void LeastSquaresFit (const Vector &, Vector &) const
 Calculate least square fit via SVD.
 
Matrix Log () const
 Matrix logarithm.
 
void LU (Matrix &, Matrix &, double &) const
 Calculate LU decomposition of square matrix.
 
void MakeSymmetric ()
 Make square matrix symmetric by adding its transpose and divide by 2.
 
 Matrix ()
 Default constructor.
 
 Matrix (int, int=-1, double *=NULL)
 Constructor for given number of rows and columns.
 
 Matrix (const Vector &)
 Convert column vector to matrix.
 
 Matrix (const PointSet &, bool twoD=false)
 
 Matrix (const Matrix &)
 Copy constructor.
 
 Matrix (const Matrix3x3 &)
 Construct from 3x3 matrix.
 
double Norm () const
 Calculate norm of matrix.
 
int NumberOfElements () const
 Get number of elements.
 
Matrix operator! ()
 Matrix inversion operator.
 
bool operator!= (const Matrix &) const
 Matrix inequality.
 
Array< int > operator!= (double) const
 
double & operator() (int)
 Get reference to element with specified linear index.
 
const double & operator() (int) const
 Get const reference to element with specified linear index.
 
double & operator() (int, int)
 Get reference to element in specified row and column.
 
const double & operator() (int, int) const
 Get const reference to element in specified row and column.
 
Matrix operator() (int, int, int, int) const
 Get submatrix.
 
void operator() (Matrix &, int, int)
 Set submatrix.
 
Matrix operator* (double) const
 Return result of multiplication with a double.
 
Vector operator* (const Vector &) const
 Right-multiply matrix with vector.
 
Matrix operator* (const Matrix &) const
 Return result of matrix multiplication.
 
Matrixoperator*= (double)
 Multiplication with a double.
 
Matrixoperator*= (const Matrix &)
 Matrix multiplication operator.
 
Matrix operator+ (double) const
 Return result of addition of a double.
 
Matrix operator+ (const Matrix &) const
 Return result of matrix addition.
 
Matrixoperator+= (double)
 Addition of a double.
 
Matrixoperator+= (const Matrix &)
 Matrix addition operator.
 
Matrix operator- (double) const
 Return result of subtraction of a double.
 
Matrix operator- (const Matrix &) const
 Return result of matrix subtraction.
 
Matrixoperator-= (double)
 Subtraction of a double.
 
Matrixoperator-= (const Matrix &)
 Matrix subtraction operator.
 
Matrix operator/ (double) const
 Return result of division by a double.
 
Matrixoperator/= (double)
 Division by a double.
 
Array< int > operator< (double) const
 
Array< int > operator<= (double) const
 
Matrixoperator= (double)
 Assign scalar value to all elements.
 
Matrixoperator= (const Matrix &)
 Assignment operator.
 
Matrixoperator= (const Matrix3x3 &)
 Assignment operator.
 
bool operator== (const Matrix &) const
 Matrix equality.
 
Array< int > operator== (double) const
 
Array< int > operator> (double) const
 
Array< int > operator>= (double) const
 
Matrix operator~ ()
 Matrix transpose operator.
 
MatrixPermuteCols (Array< int >)
 Permute columns.
 
MatrixPermuteRows (Array< int >)
 Permute rows.
 
void Print (Indent=0) const
 Print matrix.
 
void Print (ostream &, Indent=0) const
 Print matrix.
 
Matrix PseudoInverse () const
 Get pseudo inverse of matrix.
 
MatrixPseudoInvert ()
 Invert matrix using pseudo inverse.
 
void Put (int, double)
 Set value of element with specified linear index.
 
void Put (int, int, double)
 Set value of element in specified row and column.
 
double * RawPointer (int r=0, int c=0)
 Get pointer to linear memory which stores matrix elements in column-major order.
 
const double * RawPointer (int r=0, int c=0) const
 Get pointer to linear memory which stores matrix elements in column-major order.
 
void Read (const char *)
 Read matrix from file.
 
void Resize (int, int=-1)
 Resize matrix preserving existing entries.
 
int RowIndex (int) const
 Get row index of element given its linear index.
 
double RowMax (int) const
 Maximum value in specified row.
 
double RowMean (int) const
 Mean of column values in specified row.
 
double RowMin (int) const
 Minimum value in specified row.
 
void RowRange (int, double &, double &) const
 Minimum and maximum value in specified row.
 
int Rows () const
 Get number of rows.
 
double RowStd (int) const
 Standard deviation of column values in specified row.
 
double RowSum (int) const
 Sum of column values in specified row.
 
double RowVar (int) const
 Variance of column values in specified row.
 
MatrixScaleCol (int, double)
 Scale column by a scalar.
 
MatrixScaleRow (int, double)
 Scale row by a scalar.
 
Pair< int, int > Size () const
 Get matrix size in each dimension.
 
Matrix Sqrt () const
 Matrix square root.
 
void SubIndex (int, int &, int &) const
 Get row and column index of element given its linear index.
 
Pair< int, int > SubIndex (int) const
 Get row and column index of element given its linear index.
 
void SVD (Matrix &, Vector &, Matrix &) const
 Calculate singular value decomposition.
 
Matrix SVDInverse () const
 Get inverse of (singular) matrix using SVD.
 
MatrixSVDInvert ()
 Invert (singular) matrix using SVD.
 
void SymmetricEigen (Matrix &, Vector &) const
 Calculate eigendecomposition of symmetric matrix.
 
Matrix3x3 To3x3 () const
 Get upper left 3x3 sub-matrix.
 
double Trace () const
 Calculate trace of matrix.
 
MatrixTranspose ()
 Transpose matrix.
 
Matrix Transposed () const
 Get transposed matrix.
 
void Write (const char *) const
 Write matrix to file.
 
bool WriteMAT (const char *, const char *="A") const
 
void Zero ()
 Set elements to zero.
 
 ~Matrix ()
 Destructor.
 
- Public Member Functions inherited from mirtk::Object
virtual const char * NameOfClass () const =0
 Get name of class, which this object is an instance of.
 
virtual ParameterList Parameter () const
 Get parameter name/value pairs.
 
bool Parameter (const ParameterList &)
 Set parameters from name/value pairs.
 
virtual bool Set (const char *name, const char *value)
 
virtual ~Object ()
 Destructor.
 

Protected Attributes

int _cols
 Number of colums.
 
double ** _matrix
 Matrix values.
 
bool _owner
 Whether this instance owns the memory of the matrix elements.
 
int _rows
 Number of rows.
 

Friends

ostream & operator<< (ostream &, const Matrix &)
 Interface to output stream.
 
Cofstreamoperator<< (Cofstream &, const Matrix &)
 Interface to output stream.
 
istream & operator>> (istream &, Matrix &)
 Interface to input stream.
 
Cifstreamoperator>> (Cifstream &, Matrix &)
 Interface to input stream.
 

Additional Inherited Members

- Static Public Member Functions inherited from mirtk::Object
static const char * NameOfType ()
 Get name of this class type.
 
- Protected Member Functions inherited from mirtk::Object
template<typename... Args>
void Throw (ErrorType err, const char *func, Args... args) const
 
- Static Protected Member Functions inherited from mirtk::Object
template<typename... Args>
static void ThrowStatic (ErrorType err, const char *cls, const char *func, Args... args)
 

Detailed Description

Dense matrix

See also
SparseMatrix

Definition at line 48 of file Matrix.h.

Constructor & Destructor Documentation

§ Matrix()

mirtk::Matrix::Matrix ( const PointSet ,
bool  twoD = false 
)

Convert point set to (n x 3) or (n x 2) matrix

Parameters
[in]twoDDiscard z coordinate.

Member Function Documentation

§ Eigenvalues()

bool mirtk::Matrix::Eigenvalues ( Matrix ,
Vector ,
Matrix  
) const

Calculate eigenvalues and eigenvectors of matrix

This function chooses the appropriate algorithm according to matrix properties.

Returns
Whether eigenvalue decomposition exists. If false, squared singular values are returned.

§ Exp()

Matrix mirtk::Matrix::Exp ( ) const

Matrix exponential via Pade approximation (cf. Golub and Van Loan, Matrix Computations, Algorithm 11.3-1)

§ GetPointerToElements() [1/2]

double * mirtk::Matrix::GetPointerToElements ( int  r = 0,
int  c = 0 
)
inline

Get pointer to linear memory which stores matrix elements in column-major order

Deprecated:
Use RawPointer instead.

Definition at line 614 of file Matrix.h.

§ GetPointerToElements() [2/2]

const double * mirtk::Matrix::GetPointerToElements ( int  r = 0,
int  c = 0 
) const
inline

Get pointer to linear memory which stores matrix elements in column-major order

Deprecated:
Use RawPointer instead.

Definition at line 620 of file Matrix.h.

§ operator!=()

Array< int > mirtk::Matrix::operator!= ( double  x) const
inline

Find elements with value not equal to specified value

Returns
Sorted linear indices of found elements

Definition at line 842 of file Matrix.h.

§ operator<()

Array< int > mirtk::Matrix::operator< ( double  x) const
inline

Find elements with value less than specified value

Returns
Sorted linear indices of found elements

Definition at line 854 of file Matrix.h.

§ operator<=()

Array< int > mirtk::Matrix::operator<= ( double  x) const
inline

Find elements with value less or equal than specified value

Returns
Sorted linear indices of found elements

Definition at line 866 of file Matrix.h.

§ operator==()

Array< int > mirtk::Matrix::operator== ( double  x) const
inline

Find elements with specific value

Returns
Sorted linear indices of found elements

Definition at line 830 of file Matrix.h.

§ operator>()

Array< int > mirtk::Matrix::operator> ( double  x) const
inline

Find elements with value greater than specified value

Returns
Sorted linear indices of found elements

Definition at line 878 of file Matrix.h.

§ operator>=()

Array< int > mirtk::Matrix::operator>= ( double  x) const
inline

Find elements with value greater or equal than specified value

Returns
Sorted linear indices of found elements

Definition at line 890 of file Matrix.h.

§ WriteMAT()

bool mirtk::Matrix::WriteMAT ( const char *  ,
const char *  = "A" 
) const

Write dense matrix to MAT-file

Note
Use only when MIRTK_Numerics_WITH_MATLAB is 1.

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