Easy3D 2.5.3
Matrix< FT > Class Template Reference

A matrix representation, which supports dynamic sizes. More...

#include <easy3d/core/matrix.h>

Public Member Functions

 Matrix ()
 
 Matrix (const Matrix< FT > &A)
 
 Matrix (int rows, int cols, const FT &x=FT(0))
 
 Matrix (int rows, int cols, const std::vector< FT > &array)
 
 Matrix (int rows, int cols, const FT *array)
 
Matrix< FT > & operator= (const Matrix< FT > &A)
 Assign A to this matrix. More...
 
Matrix< FT > & operator= (const FT &x)
 Assign x to every entry of this matrix. More...
 
FT * operator[] (int row)
 Return the row_th row as a 1D array. More...
 
const FT * operator[] (int row) const
 Return the row_th row as a 1D array (const version).
 
FT & operator() (int row, int col)
 Return the element at (row, col).
 
const FT & operator() (int row, int col) const
 Return the element at (row, col) (const version).
 
void set (int row, int col, FT v)
 Set the value of the element at (row, col).
 
const FT & get (int row, int col) const
 Get the value of the element at (row, col).
 
FT * data ()
 
const FT * data () const
 
int rows () const
 Return the number of rows.
 
int cols () const
 Return the number of columns.
 
Matrix< FT > & resize (int rows, int cols)
 Change the size/dimension of the matrix. More...
 
std::vector< FT > get_row (int row) const
 Get the matrix's row vector as a 1D array. More...
 
std::vector< FT > get_column (int col) const
 Get the matrix's column vector as a 1D array. More...
 
void set_row (const std::vector< FT > &v, int row)
 Set the matrix's row vector. More...
 
void set_column (const std::vector< FT > &v, int col)
 Set the matrix's column vector. More...
 
void load_zero ()
 Set all elements to zero. More...
 
void load_identity (FT v=FT(1))
 
Matrix< FT > transpose () const
 Return the transposed matrix.
 
Matrix< FT > inverse () const
 Return the inverse of the matrix (for positive square matrices only)
 
FT determinant () const
 Return the determinant of the matrix (for square matrices only)
 
FT trace () const
 
Matrix< FT > & operator+= (const FT &v)
 computed assignment. Add each element by v More...
 
Matrix< FT > & operator-= (const FT &v)
 computed assignment. Subtract each element by v More...
 
template<typename FT2 >
Matrix< FT > & operator*= (const FT2 &v)
 computed assignment. Multiply each element by v More...
 
template<typename FT2 >
Matrix< FT > & operator/= (const FT2 &v)
 computed assignment. Divide each element by v More...
 
Matrix< FT > & operator+= (const Matrix< FT > &A)
 computed assignment. Add A to this matrix.
 
Matrix< FT > & operator-= (const Matrix< FT > &)
 computed assignment. Subtract A from this matrix.
 

Detailed Description

template<typename FT>
class easy3d::Matrix< FT >

A matrix representation, which supports dynamic sizes.

Attention
Matrix has a row-major storage.
Note
The matrix classes in #include <easy3d/core/mat.h> has their dimensions templated. So their dimensions must be constant and known at the compile time. In contrast, this matrix can have dynamic dimensions.

Constructor & Destructor Documentation

◆ Matrix() [1/5]

Default constructor (that constructs an empty matrix).

constructors and destructor

◆ Matrix() [2/5]

Matrix ( const Matrix< FT > &  A)

Copy constructor (i.e., construct a matrix from another matrix). The new matrix will be the same as the input matrix.

Parameters
AInput matrix.

◆ Matrix() [3/5]

Matrix ( int  rows,
int  cols,
const FT &  x = FT(0) 
)

Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize all entries to zero.

Parameters
rowsNumber of rows
colsNumber of columns.
xDefault value of each element of the matrix.

◆ Matrix() [4/5]

Matrix ( int  rows,
int  cols,
const std::vector< FT > &  array 
)

Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize the matrix from an array. The first row of the matrix will be initialized by the first cols elements of the array. Then the second row will be initialized by the next cols elements of the array, and so on.

Parameters
rowsNumber of rows
colsNumber of columns.
arrayAn array containing at least (rows * cols) elements. @Attention: Matrices are stored internally as row-major.

◆ Matrix() [5/5]

Matrix ( int  rows,
int  cols,
const FT *  array 
)

This is an override of the above constructor. Construct a matrix by specifying its dimension (i.e., number of rows and number of columns) and initialize the matrix from an array. The first row of the matrix will be initialized by the first cols elements of the array. Then the second row will be initialized by the next cols elements of the array, and so on.

Parameters
rowsNumber of rows
colsNumber of columns.
arrayThe pointer to the first element of an array used to initialize the matrix. It must have at least (rows * cols) elements. @Attention: Matrices are stored internally as row-major.

Member Function Documentation

◆ data() [1/2]

FT * data ( )
inline

Return the data of the matrix as a 1D array. Attention: Matrices are stored internally as row-major (i.e., the rows are concatenated in the returned array).

◆ data() [2/2]

const FT * data ( ) const
inline

Return the data of the matrix as a 1D array (const version). Attention: Matrices are stored internally as row-major (i.e., the rows are concatenated in the returned array).

◆ get_column()

std::vector< FT > get_column ( int  col) const

Get the matrix's column vector as a 1D array.

get the matrix's column vector

◆ get_row()

std::vector< FT > get_row ( int  row) const

Get the matrix's row vector as a 1D array.

get the matrix's row vector

◆ load_identity()

void load_identity ( FT  v = FT(1))
inline

Make this matrix identity (i.e., all elements on the diagonal have a value of 1).

Note
This function also allow to set the elements on the diagonal to have values other than 1.

Sets the matrix to identity This sets all coefficients of this matrix to be equal to nROW x nCOL identity matrix.

◆ load_zero()

void load_zero
inline

Set all elements to zero.

Clears the matrix This resets all values to 0 (zero)

◆ operator*=()

Matrix< FT > & operator*= ( const FT2 &  x)

computed assignment. Multiply each element by v

compound assignment operators *=

◆ operator+=()

Matrix< FT > & operator+= ( const FT &  x)

computed assignment. Add each element by v

compound assignment operators +=

◆ operator-=()

Matrix< FT > & operator-= ( const FT &  x)

computed assignment. Subtract each element by v

compound assignment operators -=

◆ operator/=()

Matrix< FT > & operator/= ( const FT2 &  x)

computed assignment. Divide each element by v

compound assignment operators /=

◆ operator=() [1/2]

Matrix< FT > & operator= ( const FT &  x)
inline

Assign x to every entry of this matrix.

overload evaluate operator = from scalar to matrix

◆ operator=() [2/2]

Matrix< FT > & operator= ( const Matrix< FT > &  A)

Assign A to this matrix.

overload evaluate operator = from matrix to matrix

◆ operator[]()

FT * operator[] ( int  row)
inline

Return the row_th row as a 1D array.

overload operator [] for 0-offset access

◆ resize()

Matrix< FT > & resize ( int  rows,
int  cols 
)

Change the size/dimension of the matrix.

reallocate matrix's size

◆ set_column()

void set_column ( const std::vector< FT > &  v,
int  col 
)

Set the matrix's column vector.

set the matrix's column vector

◆ set_row()

void set_row ( const std::vector< FT > &  v,
int  row 
)

Set the matrix's row vector.

set the matrix's row vector

◆ trace()

FT trace

Return the trace of this matrix, i.e. the sum of the coefficients on the main diagonal.

Note
: the matrix can be of any dimension, not necessarily square.

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