Easy3D 2.6.1
Loading...
Searching...
No Matches
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.
 
Matrix< FT > & operator= (const FT &x)
 Assign x to every entry of this matrix.
 
FT * operator[] (int row)
 Return the row_th row as a 1D array.
 
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.
 
std::vector< FT > get_row (int row) const
 Get the matrix's row vector as a 1D array.
 
std::vector< FT > get_column (int col) const
 Get the matrix's column vector as a 1D array.
 
void set_row (const std::vector< FT > &v, int row)
 Set the matrix's row vector.
 
void set_column (const std::vector< FT > &v, int col)
 Set the matrix's column vector.
 
void load_zero ()
 Set all elements to zero.
 
void load_identity (FT v=FT(1))
 
void load_random ()
 Set all elements to a random value (in the range [0.0, 1.0])
 
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
 
Matrix< FT > & operator-= (const FT &v)
 computed assignment. Subtract each element by v
 
template<typename FT2>
Matrix< FT > & operator*= (const FT2 &v)
 computed assignment. Multiply each element by v
 
template<typename FT2>
Matrix< FT > & operator/= (const FT2 &v)
 computed assignment. Divide each element by v
 
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 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]

template<typename FT>
Matrix ( )

Default constructor (that constructs an empty matrix).

constructors and destructor

◆ Matrix() [2/5]

template<typename FT>
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]

template<typename FT>
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]

template<typename FT>
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]

template<typename FT>
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]

template<typename FT>
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]

template<typename FT>
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()

template<typename FT>
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()

template<typename FT>
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()

template<typename FT>
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()

template<typename FT>
void load_zero ( )
inline

Set all elements to zero.

Clears the matrix such that all values are set to 0 (zero)

◆ operator*=()

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

computed assignment. Multiply each element by v

compound assignment operators *=

◆ operator+=()

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

computed assignment. Add each element by v

compound assignment operators +=

◆ operator-=()

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

computed assignment. Subtract each element by v

compound assignment operators -=

◆ operator/=()

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

computed assignment. Divide each element by v

compound assignment operators /=

◆ operator=() [1/2]

template<typename FT>
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]

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

Assign A to this matrix.

overload evaluate operator = from matrix to matrix

◆ operator[]()

template<typename FT>
FT * operator[] ( int row)
inline

Return the row_th row as a 1D array.

overload operator [] for 0-offset access

◆ resize()

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

Change the size/dimension of the matrix.

reallocate matrix's size

◆ set_column()

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

Set the matrix's column vector.

set the matrix's column vector

◆ set_row()

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

Set the matrix's row vector.

set the matrix's row vector

◆ trace()

template<typename FT>
FT trace ( ) const

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: