CPP Linear Algebra ToolBox  0.1.0
LTMatrix Class Reference

A class describing a Lower Triangular Matrix. Lower triangular matrix are Matrix of dimension \(n\times n\) satisfying. More...

#include <lowerTriangularMatrix.h>

Inheritance diagram for LTMatrix:
Collaboration diagram for LTMatrix:

Public Member Functions

 LTMatrix ()
 Construct a new LTMatrix object. Default Constructor, call parent Matrix constructor. More...
 
 LTMatrix (uint16_t, uint16_t)
 Construct a new LTMatrix object. Represent a general rectangular lower triangular matrix.
More...
 
 LTMatrix (uint16_t)
 Construct a new LTMatrix object. Represent a basic square lower triangular matrix. Data are stored as follows: data[0] = l_{11}, data[1,2] = [l_{21}, l_{22}], ... More...
 
 LTMatrix (const LTMatrix &)
 Construct a new LTMatrix object Copy constructor. More...
 
 ~LTMatrix ()
 
uint16_t max_col_from_row (uint16_t) const
 A method to compute the maximum colum index with non-zero data for a given row \(i\). Works for a general rectangular lower triangular matrix \(L\) of dimension \((m\times n)\) with \(m\geq n\). With C++ indexing convention, the result is given by. More...
 
double & operator() (uint32_t) const
 
double & operator() (uint16_t, uint16_t) const
 
LTMatrixoperator= (const LTMatrix &)
 
LTMatrix operator- () const
 
- Public Member Functions inherited from Matrix
 Matrix ()
 Construct a Matrix object. Default constructor. Set number of rows and number of columns to 0. Set data pointer to NULL. More...
 
 Matrix (uint16_t, uint16_t)
 Construct a Matrix object. Construct a matrix of size n rows times m columns. More...
 
 Matrix (const Matrix &)
 Construct a Matrix object. Copy contructor. More...
 
virtual ~Matrix ()
 Destroy the Matrix object. More...
 
uint16_t get_n_rows () const
 Accessor to the number of rows. More...
 
uint16_t get_n_cols () const
 Accessor to the number of columns. More...
 
uint32_t get_n_elements () const
 Accessor to the number of elements. More...
 
bool is_square () const
 Test if a matrix has a square shape. More...
 
Vector row (uint16_t) const
 Extract row from Matrix. More...
 
Vector col (uint16_t) const
 Extract column from Matrix. More...
 
double 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) More...
 
double 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) More...
 
double 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. More...
 
Matrix transpose () const
 Compute the transpose Matrix of a Matrix object. More...
 
double & operator() (uint32_t) const
 Overload operator (i) More...
 
double & operator() (uint16_t, uint16_t) const
 Overload operator (i,j). More...
 
Matrixoperator= (const Matrix &)
 Overload assignement operator. More...
 
Matrixoperator+= (const Matrix &)
 Overload operator +=. More...
 
Matrixoperator-= (const Matrix &)
 Overload operator -=. More...
 
Matrix operator- () const
 Overload unary operator -. More...
 

Static Public Member Functions

static double tr (const LTMatrix &)
 
static double det (const LTMatrix &)
 
static LTMatrix zeros (uint16_t)
 
static LTMatrix ones (uint16_t)
 
static LTMatrix rand (uint16_t)
 
static LTMatrix rand (uint16_t, uint16_t)
 
- Static Public Member Functions inherited from Matrix
static Matrix zeros (uint16_t, uint16_t)
 Construct a matrix object of dimension n times m filled with zeros. More...
 
static Matrix ones (uint16_t, uint16_t)
 Construct a matrix object of dimension n times m filled with ones. More...
 
static Matrix rand (uint16_t, uint16_t)
 Construct a matrix object of dimension n times m filled with random values sampled from 0. to 1. More...
 
static Matrix hilbert (uint16_t, uint16_t)
 Construct an Hilbert matrix. More...
 
static Matrix vandermonde (const Vector &, uint16_t)
 Construct a Vandermonde matrix. See https://en.wikipedia.org/wiki/Vandermonde_matrix. More...
 
static Matrix outer (const Vector &, const Vector &)
 Overload operator * between two vectors to compute their outer product. More...
 
static Matrix matmul (const Matrix &, MATRIX_TRANSPOSE, const Matrix &, MATRIX_TRANSPOSE)
 Compute the product of two matrices combined with their transposition. More...
 

Friends

LTMatrix operator* (const LTMatrix &, const LTMatrix &)
 Product of Lower Triangular Matrices. For \(L_1\) and \(L_2\) two lower triangular matrices of dimension \((n,n)\), we have. More...
 
Vector operator* (const LTMatrix &, const Vector &)
 
LTMatrix operator* (const double, const LTMatrix &)
 
LTMatrix operator* (const LTMatrix &, const double)
 
LTMatrix operator+ (const LTMatrix &, const LTMatrix &)
 
LTMatrix operator+ (const double, const LTMatrix &)
 
LTMatrix operator+ (const LTMatrix &, const double)
 
LTMatrix operator- (const LTMatrix &, const LTMatrix &)
 
LTMatrix operator- (const LTMatrix &, const double)
 
LTMatrix operator- (const double, const LTMatrix &)
 
LTMatrix operator/ (const LTMatrix &, const double)
 
std::ostream & operator<< (std::ostream &, const LTMatrix &)
 

Additional Inherited Members

- Protected Member Functions inherited from Matrix
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...
 
- Protected Attributes inherited from Matrix
uint16_t n_rows
 
uint16_t n_cols
 
uint32_t n_elements
 
double * data
 

Detailed Description

A class describing a Lower Triangular Matrix. Lower triangular matrix are Matrix of dimension \(n\times n\) satisfying.

\[ L_{ij} = \left\{\begin{array}{rl} 0&\textrm{if}\quad j> i \\ 0 &\textrm{otherwise} \end{array}\right. \]

Todo:

check that calling operator L(i,j) calls the newt implementation of the at function.

Extend the definition to \(n\times m\), with \(n>m\), matrices.

Constructor & Destructor Documentation

◆ LTMatrix() [1/4]

LTMatrix::LTMatrix ( )

Construct a new LTMatrix object. Default Constructor, call parent Matrix constructor.

◆ LTMatrix() [2/4]

LTMatrix::LTMatrix ( uint16_t  m,
uint16_t  n 
)

Construct a new LTMatrix object. Represent a general rectangular lower triangular matrix.

Parameters
mNumber of row of the matrix, must be greater or equal than \(n\),
nNumber of colum of the matrix, must be greater or equal than \(1\).

◆ LTMatrix() [3/4]

LTMatrix::LTMatrix ( uint16_t  n)

Construct a new LTMatrix object. Represent a basic square lower triangular matrix. Data are stored as follows: data[0] = l_{11}, data[1,2] = [l_{21}, l_{22}], ...

Parameters
nDimension of the matrix (must be greater or equal than \(1\)).

◆ LTMatrix() [4/4]

LTMatrix::LTMatrix ( const LTMatrix in)

Construct a new LTMatrix object Copy constructor.

Parameters
inLower triangular matrix to be copied.

◆ ~LTMatrix()

LTMatrix::~LTMatrix ( )

Member Function Documentation

◆ det()

double LTMatrix::det ( const LTMatrix L)
static

◆ max_col_from_row()

uint16_t LTMatrix::max_col_from_row ( uint16_t  i) const

A method to compute the maximum colum index with non-zero data for a given row \(i\). Works for a general rectangular lower triangular matrix \(L\) of dimension \((m\times n)\) with \(m\geq n\). With C++ indexing convention, the result is given by.

\[ j_{\max}(i)=\min(i, n-1),\quad\forall\,0\leq i< m \]

Parameters
iRow index, must be between \(0\) and \(m-1\).
Returns
uint16_t \(j_{\max}(i)\) maximum index of a column with non-zeros data.

◆ ones()

LTMatrix LTMatrix::ones ( uint16_t  n)
static

◆ operator()() [1/2]

double & LTMatrix::operator() ( uint16_t  i,
uint16_t  j 
) const

◆ operator()() [2/2]

double & LTMatrix::operator() ( uint32_t  n) const

◆ operator-()

LTMatrix LTMatrix::operator- ( ) const

◆ operator=()

LTMatrix & LTMatrix::operator= ( const LTMatrix L)

◆ rand() [1/2]

LTMatrix LTMatrix::rand ( uint16_t  n)
static

◆ rand() [2/2]

LTMatrix LTMatrix::rand ( uint16_t  m,
uint16_t  n 
)
static

◆ tr()

double LTMatrix::tr ( const LTMatrix L)
static

◆ zeros()

LTMatrix LTMatrix::zeros ( uint16_t  n)
static

Friends And Related Function Documentation

◆ operator* [1/4]

LTMatrix operator* ( const double  k,
const LTMatrix L 
)
friend

◆ operator* [2/4]

LTMatrix operator* ( const LTMatrix L,
const double  k 
)
friend

◆ operator* [3/4]

LTMatrix operator* ( const LTMatrix lhs,
const LTMatrix rhs 
)
friend

Product of Lower Triangular Matrices. For \(L_1\) and \(L_2\) two lower triangular matrices of dimension \((n,n)\), we have.

\[ (L_1L_2)_{i,j} = \sum_{k=j}^{i} (L_1)_{ik}(L_2)_{kj} ,\quad \forall\, j \leq i \]

Parameters
lhsLeft hand side, a lower triangular matrix of size : \((n, n)\)
rhsRight hand side, a lower triangular matrix of size : \((n, n)\)
Returns
LTMatrix Product lhs and rhs stored as a new lower triangular matrix object
Warning
lhs and rhs must be square (and thus of the same dimensions) lower triangular matrices in order for the product to make sense.

◆ operator* [4/4]

Vector operator* ( const LTMatrix lhs,
const Vector rhs 
)
friend

◆ operator+ [1/3]

LTMatrix operator+ ( const double  k,
const LTMatrix L 
)
friend

◆ operator+ [2/3]

LTMatrix operator+ ( const LTMatrix L,
const double  k 
)
friend

◆ operator+ [3/3]

LTMatrix operator+ ( const LTMatrix lhs,
const LTMatrix rhs 
)
friend

◆ operator- [1/3]

LTMatrix operator- ( const double  k,
const LTMatrix L 
)
friend

◆ operator- [2/3]

LTMatrix operator- ( const LTMatrix L,
const double  k 
)
friend

◆ operator- [3/3]

LTMatrix operator- ( const LTMatrix lhs,
const LTMatrix rhs 
)
friend

◆ operator/

LTMatrix operator/ ( const LTMatrix L,
const double  k 
)
friend

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const LTMatrix L 
)
friend

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