A class describing a Matrix object. Matrices are array of size (n,m) whre n and m are integer greater or equal than 1. Notice that in general a matrix is not square. Non specific structure is assumed. Square, Diagonal, Triangular, etc, have dedicated classes.
More...
#include <matrix.h>
|
double & | at (uint32_t) const |
| Helper to access the n-th stored value of a Matrix object. More...
|
|
double & | at (uint16_t, uint16_t) const |
| Access given element of a matrix. More...
|
|
void | show () const |
| Helper to display a Matrix object to the standart output stream. More...
|
|
void | default_data () |
| Fill the data array with zeros.
More...
|
|
|
bool | operator== (const Matrix &, const Matrix &) |
| Overload of operator == Two matrices are equal if and only they have the same dimensions and the same elements. More...
|
|
Matrix | operator* (const Matrix &, const Matrix &) |
| Overload operator * for multiplication of Matrices. More...
|
|
Vector | operator* (const Vector &, const Matrix &) |
| Overload operator * for left multiplication of covector with Matrix. More...
|
|
Vector | operator* (const Matrix &, const Vector &) |
| Overload operator * for right multiplication of Matrix with Vector. More...
|
|
Matrix | operator* (const double, const Matrix &) |
| Overload operator * for multiplication of a scalar with Matrix. More...
|
|
Matrix | operator* (const Matrix &, const double) |
| Overload operator * for multiplication of a Matrix with scalar. More...
|
|
Matrix | operator+ (const Matrix &, const Matrix &) |
| Overload operator + for addition of Matrices. More...
|
|
Matrix | operator+ (const double, const Matrix &) |
| Overload operator + for addition of scalar with Matrix. More...
|
|
Matrix | operator+ (const Matrix &, const double) |
| Overload operator + for addition of Matrix with scalar. More...
|
|
Matrix | operator- (const Matrix &, const Matrix &) |
| Overload operator - for soustraction of Matrices. More...
|
|
Matrix | operator- (const Matrix &, const double) |
| Overload operator - for soustraction of Matrix with scalar. More...
|
|
Matrix | operator- (const double, const Matrix &) |
| Overload operator - for soustraction of scalar with Matrix. More...
|
|
Matrix | operator/ (const Matrix &, const double) |
| Overload operator / for division of Matrix by scalar. More...
|
|
std::ostream & | operator<< (std::ostream &, const Matrix &) |
| Overload output stream operator for Matrix object. More...
|
|
A class describing a Matrix object. Matrices are array of size (n,m) whre n and m are integer greater or equal than 1. Notice that in general a matrix is not square. Non specific structure is assumed. Square, Diagonal, Triangular, etc, have dedicated classes.
- Warning
- Indices are 0-based (Math Formulae must be adapted consequently)
-
Maximum dimension of a Matrix is 65 535 times 65 535
◆ Matrix() [1/3]
Construct a Matrix object. Default constructor. Set number of rows and number of columns to 0. Set data pointer to NULL.
◆ Matrix() [2/3]
Matrix::Matrix |
( |
uint16_t |
m, |
|
|
uint16_t |
n |
|
) |
| |
Construct a Matrix object. Construct a matrix of size n rows times m columns.
- Parameters
-
m | number of rows (must be greater or equal than 1) |
n | number of colums (must be greater or equal than 1) |
◆ Matrix() [3/3]
Matrix::Matrix |
( |
const Matrix & |
in | ) |
|
Construct a Matrix object. Copy contructor.
- Parameters
-
◆ ~Matrix()
◆ at() [1/2]
double & Matrix::at |
( |
uint16_t |
i, |
|
|
uint16_t |
j |
|
) |
| const |
|
protected |
Access given element of a matrix.
- Parameters
-
i | Row number (must be greater or equal than 0) |
j | Column number (must be greater or equal than 0) |
- Returns
- double & Reference to the (i,j)-th element of the matrix
- Warning
- Indices are 0-based
◆ at() [2/2]
double & Matrix::at |
( |
uint32_t |
n | ) |
const |
|
protected |
Helper to access the n-th stored value of a Matrix object.
- Parameters
-
n | Index of the value (must be between 0 and n_elements-1) |
- Returns
- double& Reference to the n-th stored value of Matrix object.
◆ col()
Vector Matrix::col |
( |
uint16_t |
c | ) |
const |
Extract column from Matrix.
- Parameters
-
c | Column number must be between 0 and n_cols-1 |
- Returns
- Vector Vector of length n_rows containing the c-th column of the current Matrix object
◆ default_data()
void Matrix::default_data |
( |
| ) |
|
|
protected |
Fill the data array with zeros.
◆ get_n_cols()
uint16_t Matrix::get_n_cols |
( |
| ) |
const |
Accessor to the number of columns.
- Returns
- uint16_t Number of columns of the matrix (is greater or equal than 1)
◆ get_n_elements()
uint32_t Matrix::get_n_elements |
( |
| ) |
const |
Accessor to the number of elements.
- Returns
- uint32_t Number of elements strored in the matrix
◆ get_n_rows()
uint16_t Matrix::get_n_rows |
( |
| ) |
const |
Accessor to the number of rows.
- Returns
- uint16_t Number of rows of the matrix (is greater or equal than 1)
◆ hilbert()
Matrix Matrix::hilbert |
( |
uint16_t |
m, |
|
|
uint16_t |
n |
|
) |
| |
|
static |
Construct an Hilbert matrix.
- Parameters
-
m | Number of rows of the Matrix (must be greater or equal than 1). |
n | Number of cols of the Matrix (must be greater or equal than 1). |
- Returns
- Matrix A Matrix object whose coefficients are \(M_{ij} = \frac{1}{i+j-1}\)
◆ is_square()
bool Matrix::is_square |
( |
| ) |
const |
Test if a matrix has a square shape.
- Returns
- true If the Matrix object has teh same number of row and columns.
-
false Otherwise.
◆ matmul()
Compute the product of two matrices combined with their transposition.
- Parameters
-
A | Matrix object of dimension \((m_A,n_A)\) |
TRANSA | |
B | Matrix object of dimension \((m_B,n_B)\) |
TRANSB | |
- Returns
- Matrix
◆ norm1()
double Matrix::norm1 |
( |
| ) |
const |
Compute the norm-1 of a Matrix object. For a Matrix M of dimension \(n\times m\), its norm-1 is given by the maximum colum sum (in absolute value)
\[ \|M\|_1 = \max_{1\leq j\leq m} \sum_{i=1}^n |M_{ij}| \]
- Returns
- double Norm-1 of Matrix object
◆ normFrob()
double Matrix::normFrob |
( |
| ) |
const |
Compute the Frobenius norm of a Matrix object. For a Matrix M of dimension \(n\times m\), its Frobenius norm is given by the sum of its coefficient squared.
\[ \|M\|_{F} = \sum_{i=1}^n \sum_{j=1}^m M_{ij}^2 \]
- Returns
- double Frobenius norm of Matrix object
◆ normInf()
double Matrix::normInf |
( |
| ) |
const |
Compute the norm-Infinity of a Matrix object. For a Matrix M of dimension \(n\times m\), its norm-Infinity is given by the maximum row sum (in absolute value)
\[ \|M\|_{\infty} = \max_{1\leq i\leq n} \sum_{j=1}^m |M_{ij}| \]
- Returns
- double Norm-Infinity of Matrix object
◆ ones()
Matrix Matrix::ones |
( |
uint16_t |
m, |
|
|
uint16_t |
n |
|
) |
| |
|
static |
Construct a matrix object of dimension n times m filled with ones.
- Parameters
-
m | Number of rows of the Matrix (must be greater or equal than 1). |
n | Number of cols of the Matrix (must be greater or equal than 1). |
- Returns
- Matrix A Matrix object of size nxm filled with ones
◆ operator()() [1/2]
double & Matrix::operator() |
( |
uint16_t |
i, |
|
|
uint16_t |
j |
|
) |
| const |
Overload operator (i,j).
- Parameters
-
i | Row number (must be greater or equal than 0) |
j | Column number (must be gretaer or equal than 0) |
- Returns
- double & Reference to the (i,j)-th element of the matrix
- Warning
- Indices are 0-based
◆ operator()() [2/2]
double & Matrix::operator() |
( |
uint32_t |
n | ) |
const |
Overload operator (i)
- Parameters
-
n | Element number (must be between 0 and n_elements-1) |
- Returns
- double& Reference to the n-th stored element of the matrix
◆ operator+=()
Overload operator +=.
- Parameters
-
- Returns
- Matrix & Reference to Matrix object equal to this->data + B.data
- Warning
- B must have the same dimensions as the current Matrix object
◆ operator-()
Matrix Matrix::operator- |
( |
| ) |
const |
Overload unary operator -.
- Returns
- Matrix Object whose coefficients are the opposite of those of the current Matrix object.
◆ operator-=()
Overload operator -=.
- Parameters
-
- Returns
- Matrix & Reference to Matrix object equal to this->data - B.data
- Warning
- B must have the same dimensions as the current Matrix object
◆ operator=()
Overload assignement operator.
- Parameters
-
B | Right Hand Side, Matrix to be copied |
- Returns
- Matrix & A Matrix object copy of B.
◆ outer()
Overload operator * between two vectors to compute their outer product.
- Parameters
-
u | Vector object of dimension \(m\) (>0) |
v | Vector object of dimension \(n\) (>0) |
- Returns
- Matrix Matrix object M of dimension \(m\times n\) equal to M = u*v^T, i.e. \(M_{ij} = u_iv_j\).
◆ rand()
Matrix Matrix::rand |
( |
uint16_t |
m, |
|
|
uint16_t |
n |
|
) |
| |
|
static |
Construct a matrix object of dimension n times m filled with random values sampled from 0. to 1.
- Parameters
-
m | Number of rows of the Matrix (must be greater or equal than 1). |
n | Number of cols of the Matrix (must be greater or equal than 1). |
- Returns
- Matrix A Matrix object of size nxm filled with random values
◆ row()
Vector Matrix::row |
( |
uint16_t |
r | ) |
const |
Extract row from Matrix.
- Parameters
-
r | Row number must be between 0 and n_rows-1 |
- Returns
- Vector Vector of length n_cols containing the r-th row of the current Matrix object
◆ show()
void Matrix::show |
( |
| ) |
const |
|
protected |
Helper to display a Matrix object to the standart output stream.
◆ transpose()
Matrix Matrix::transpose |
( |
| ) |
const |
◆ vandermonde()
◆ zeros()
Matrix Matrix::zeros |
( |
uint16_t |
m, |
|
|
uint16_t |
n |
|
) |
| |
|
static |
Construct a matrix object of dimension n times m filled with zeros.
- Parameters
-
m | Number of rows of the Matrix (must be greater or equal than 1). |
n | Number of cols of the Matrix (must be greater or equal than 1). |
- Returns
- Matrix A Matrix object of size nxm filled with zeros
◆ operator* [1/5]
Overload operator * for multiplication of a scalar with Matrix.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are those of B multiplied by k
◆ operator* [2/5]
Overload operator * for multiplication of a Matrix with scalar.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are those of B multiplied by k
◆ operator* [3/5]
Overload operator * for multiplication of Matrices.
- Parameters
-
lhs | Left Hand Side |
rhs | Right Hand Side |
- Returns
- Matrix Matrix equal to lhs*rhs
- Warning
- lhs must have the same number of cols as the number of cols of rhs
◆ operator* [4/5]
Overload operator * for right multiplication of Matrix with Vector.
- Parameters
-
v | A Vector object of dimension n |
A | A Matrix object of dimension (m,n) |
- Returns
- Vector A Vector object of dimension m
- Warning
- Vector v must have the length equla to the number of columns of A
◆ operator* [5/5]
Overload operator * for left multiplication of covector with Matrix.
- Parameters
-
v | A Vector object of dimension n (actually a covector) |
A | A Matrix object of dimension (n,m) |
- Returns
- Vector A Vector object of dimension m (actually a covector)
- Warning
- Vector v must have the length equal to the number of rows of A
◆ operator+ [1/3]
Overload operator + for addition of scalar with Matrix.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are those of B plus k
◆ operator+ [2/3]
Overload operator + for addition of Matrix with scalar.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are those of B plus k
◆ operator+ [3/3]
Overload operator + for addition of Matrices.
- Parameters
-
lhs | Left Hand Side |
rhs | Right Hand Side |
- Returns
- Matrix Sum of lhs and rhs, i.e. lhs+rhs
- Warning
- lhs and rhs must have the same dimensions
◆ operator- [1/3]
Overload operator - for soustraction of scalar with Matrix.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are k minus B
◆ operator- [2/3]
Overload operator - for soustraction of Matrix with scalar.
- Parameters
-
- Returns
- Matrix Matrix whose coefficients are those of B minus k
◆ operator- [3/3]
Overload operator - for soustraction of Matrices.
- Parameters
-
lhs | Left Hand Side |
rhs | Right Hand Side |
- Returns
- Matrix Sum of lhs and rhs, i.e. lhs-rhs
- Warning
- lhs and rhs must have the same dimensions
◆ operator/
Overload operator / for division of Matrix by scalar.
- Parameters
-
B | A Matrix. |
k | A scalar (non-zero). |
- Returns
- Matrix Matrix whose coefficients are those of B divided by k
- Warning
- k must be non-zero.
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const Matrix & |
M |
|
) |
| |
|
friend |
Overload output stream operator for Matrix object.
- Parameters
-
os | Output stream. |
M | Matrix object. |
- Returns
- std::ostream & updated output stream
◆ operator==
Overload of operator == Two matrices are equal if and only they have the same dimensions and the same elements.
- Parameters
-
lhs | Left Hand Side |
rhs | Right Hand Side |
- Returns
- true if this matrix is equal to B
-
false if this matrix is different than B
◆ data
◆ n_cols
Number of columns.
- Warning
- Must be greater than 1
◆ n_elements
uint32_t Matrix::n_elements |
|
protected |
◆ n_rows
Number of rows.
- Warning
- Must be greater than 1
The documentation for this class was generated from the following files: