maliput
Matrix< N > Class Template Reference

Detailed Description

template<std::size_t N>
class maliput::math::Matrix< N >

A squared N-dimensional matrix.

Template Parameters
NIndicates the dimension of the matrix. Dimension must be 1x1 or greater.

#include <include/maliput/math/matrix.h>

Public Member Functions

 Matrix ()=default
 Constructs a N x N matrix filled with zeros. More...
 
 Matrix (const std::initializer_list< double > &values)
 Constructs a N x N matrix from a list of double. More...
 
 Matrix (const std::initializer_list< Vector< N >> &rows)
 Constructs a N x N matrix from a list of Vector<N>. More...
 
 Matrix (std::array< Vector< N >, N > rows)
 Constructs a N x N matrix from an array of Vector<N>. More...
 
 Matrix (const Matrix< N > &other)=default
 Copy constructor. More...
 
 Matrix (Matrix< N > &&other)=default
 Move constructor. More...
 
const Vector< N > row (std::size_t index) const
 Returns the index-th row of the matrix. More...
 
const Vector< N > col (std::size_t index) const
 Returns the index-th column of the matrix. More...
 
Matrix< N > transpose () const
 
Matrix< N - 1 > reduce (std::size_t row, std::size_t col) const
 Reduce the matrix's dimension. More...
 
double cofactor (std::size_t row, std::size_t col) const
 Calculates the cofactor of the element at row and col. More...
 
double determinant () const
 Computes the determinant. More...
 
bool is_singular () const
 Determine the singularity. More...
 
Matrix< N > cofactor () const
 
Matrix< N > adjoint () const
 
Matrix< N > inverse () const
 
std::string to_str () const
 
Matrix< N > & operator= (const Matrix< N > &other)
 Assignment operator overload. More...
 
Matrix< N > & operator= (const Matrix< N > &&other)
 Move assignment operator overload. More...
 
const Vector< N > & operator[] (std::size_t index) const
 Constant subscripting array operator overload. More...
 
Vector< N > & operator[] (std::size_t index)
 Subscripting array operator overload. More...
 
bool operator== (const Matrix< N > &matrix) const
 Equality operator overload. More...
 
bool operator!= (const Matrix< N > &matrix) const
 Inequality operator overload. More...
 
Matrix< N > operator+ (const Matrix< N > &matrix) const
 Add operator overload. More...
 
Matrix< N > operator- (const Matrix< N > &matrix) const
 Substract operator overload. More...
 
Matrix< N > operator* (const Matrix< N > &matrix) const
 Product operator overload between Matrix<N>s. More...
 
Matrix< N > operator/ (double k) const
 Divide operator overload between this and a scalar. More...
 
double cofactor (std::size_t row, std::size_t col) const
 

Static Public Member Functions

static Matrix< N > Identity ()
 

Static Public Attributes

static constexpr double kTolerance = 1e-15
 Tolerance value to determine the singularity of the matrix. More...
 

Friends

template<std::size_t N_>
Matrix< N_ > operator* (const Matrix< N_ > &matrix, double k)
 Product operator overload between a Matrix<N> and a scalar. More...
 
template<std::size_t N_>
Matrix< N_ > operator* (double k, const Matrix< N_ > &matrix)
 Product operator overload between a scalar and a Matrix<N>. More...
 
template<std::size_t N_>
std::ostream & operator<< (std::ostream &os, const Matrix< N_ > &matrix)
 Serialization operator overload. More...
 

Constructor & Destructor Documentation

◆ Matrix() [1/6]

Matrix ( )
default

Constructs a N x N matrix filled with zeros.

◆ Matrix() [2/6]

Matrix ( const std::initializer_list< double > &  values)

Constructs a N x N matrix from a list of double.

Parameters
valuesElements of the matrix. The size of values must match NxN. Elements will fill the matrix's rows from top to bottom.
Exceptions
common::assertion_errorWhen N is not positive.
common::assertion_errorWhen values size is not NxN.

◆ Matrix() [3/6]

Matrix ( const std::initializer_list< Vector< N >> &  rows)

Constructs a N x N matrix from a list of Vector<N>.

Parameters
rowsRows of the matrix. The size of rows must be N. It fills the matrix from the 0-th to N-1-th.
Exceptions
common::assertion_errorWhen rows size is not N.

◆ Matrix() [4/6]

Matrix ( std::array< Vector< N >, N >  rows)

Constructs a N x N matrix from an array of Vector<N>.

Parameters
rowsRows of the matrix. The size of rows must match with N. It fills the matrix from top to bottom.

◆ Matrix() [5/6]

Matrix ( const Matrix< N > &  other)
default

Copy constructor.

◆ Matrix() [6/6]

Matrix ( Matrix< N > &&  other)
default

Move constructor.

Member Function Documentation

◆ adjoint()

Matrix< N > adjoint
Returns
The adjoint matrix.
Exceptions
common::assertion_errorWhen N is one.

◆ cofactor() [1/3]

Matrix< N > cofactor
Returns
The cofactor matrix.
Exceptions
common::assertion_errorWhen N is one.

◆ cofactor() [2/3]

double cofactor ( std::size_t  row,
std::size_t  col 
) const

Calculates the cofactor of the element at row and col.

Parameters
rowIndex of the matrix's rows. It must be in [0, N).
colIndex of the matrix's cols. It must be in [0, N).
Returns
The cofactor value.
Exceptions
common::assertion_errorWhen row or col are not in [0, N).
common::assertion_errorWhen N is one.

◆ cofactor() [3/3]

double cofactor ( std::size_t  row,
std::size_t  col 
) const

◆ col()

const Vector< N > col ( std::size_t  index) const

Returns the index-th column of the matrix.

Parameters
indexColumn number. It must be in [0, N).
Returns
A Vector<N>.
Exceptions
common::assertion_errorWhen index is not in the range [0, N).

◆ determinant()

double determinant

Computes the determinant.

Returns
The determinant value.

◆ Identity()

Matrix< N > Identity
static
Returns
A N x N identity matrix.

◆ inverse()

Matrix< N > inverse
Returns
The inverse matrix.
Exceptions
common::assertion_errorWhen matrix is singular.

◆ is_singular()

bool is_singular

Determine the singularity.

Returns
True when this matrix is singular.

◆ operator!=()

bool operator!= ( const Matrix< N > &  matrix) const

Inequality operator overload.

◆ operator*()

Matrix< N > operator* ( const Matrix< N > &  matrix) const

Product operator overload between Matrix<N>s.

◆ operator+()

Matrix< N > operator+ ( const Matrix< N > &  matrix) const

Add operator overload.

◆ operator-()

Matrix< N > operator- ( const Matrix< N > &  matrix) const

Substract operator overload.

◆ operator/()

Matrix< N > operator/ ( double  k) const

Divide operator overload between this and a scalar.

◆ operator=() [1/2]

Matrix< N > & operator= ( const Matrix< N > &&  other)

Move assignment operator overload.

Parameters
otherMatrix<N> object.

◆ operator=() [2/2]

Matrix< N > & operator= ( const Matrix< N > &  other)

Assignment operator overload.

Parameters
otherMatrix<N> object.

◆ operator==()

bool operator== ( const Matrix< N > &  matrix) const

Equality operator overload.

◆ operator[]() [1/2]

Vector< N > & operator[] ( std::size_t  index)

Subscripting array operator overload.

Parameters
indexThe index of the matrix row. It must be in [0, N).
Returns
A mutable reference to the row at index.
Exceptions
common::assertion_errorWhen index is out of range.

◆ operator[]() [2/2]

const Vector< N > & operator[] ( std::size_t  index) const

Constant subscripting array operator overload.

Parameters
indexThe index of the matrix row. It must be in [0, N).
Returns
A constant reference of the row at index.
Exceptions
common::assertion_errorWhen index is out of range.

◆ reduce()

Matrix< N - 1 > reduce ( std::size_t  row,
std::size_t  col 
) const

Reduce the matrix's dimension.

N must be at least 2 to be reducible.

Parameters
rowIs the number of the row to be removed. It must be in [0, N).
colIs the number of the column to be removed. It must be in [0, N).
Returns
A Matrix<N-1> which is the result of removing the row-th row and col-th column.
Exceptions
common::assertion_errorWhen row or col are not in [0, N).
common::assertion_errorWhen N is less than two.

◆ row()

const Vector< N > row ( std::size_t  index) const

Returns the index-th row of the matrix.

Parameters
indexRow number. It must be in [0, N).
Returns
A Vector<N>.
Exceptions
common::assertion_errorWhen index is not in the range [0, N).

◆ to_str()

std::string to_str
Returns
A string representation of the matrix.

◆ transpose()

Matrix< N > transpose
Returns
A Matrix<N> whose elements match this transpose.

Friends And Related Function Documentation

◆ operator* [1/2]

Matrix<N_> operator* ( const Matrix< N_ > &  matrix,
double  k 
)
friend

Product operator overload between a Matrix<N> and a scalar.

◆ operator* [2/2]

Matrix<N_> operator* ( double  k,
const Matrix< N_ > &  matrix 
)
friend

Product operator overload between a scalar and a Matrix<N>.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Matrix< N_ > &  matrix 
)
friend

Serialization operator overload.

Member Data Documentation

◆ kTolerance

constexpr double kTolerance = 1e-15
staticconstexpr

Tolerance value to determine the singularity of the matrix.


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