libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
crn::Matrix< T > Class Template Reference

Base matrix class. More...

#include <CRNMatrix.h>

+ Inheritance diagram for crn::Matrix< T >:
+ Collaboration diagram for crn::Matrix< T >:

Public Member Functions

 Matrix (size_t nrow, size_t ncol, const T &value=T(0))
 Constructor. More...
 
 Matrix (const std::vector< std::vector< T >> &m)
 Constructor from std::vector matrix. More...
 
 Matrix (const std::vector< T > &vect, Orientation ori=Orientation::VERTICAL)
 Constructor from std::vector 1D vector. More...
 
 Matrix (std::vector< T > &&vect, Orientation ori=Orientation::VERTICAL)
 Constructor from std::vector 1D vector. More...
 
virtual ~Matrix () override=default
 Destructor. More...
 
 Matrix (const Matrix &)=default
 
template<typename Y >
 Matrix (const Matrix< Y > &m)
 
 Matrix (Matrix &&)=default
 
Matrixoperator= (const Matrix &)=default
 
Matrixoperator= (Matrix &&)=default
 
void Swap (Matrix &m)
 
size_t GetRows () const noexcept
 Returns the number of rows. More...
 
size_t GetCols () const noexcept
 Returns the number of columns. More...
 
const T & At (size_t pos) const noexcept
 
T & At (size_t pos) noexcept
 
const T & At (size_t r, size_t c) const noexcept
 
T & At (size_t r, size_t c) noexcept
 
void SetAll (const T &v)
 Set all elements. More...
 
void Negative ()
 Change sign for all elements. More...
 
void SetRow (size_t r, const std::vector< T > &row)
 Sets the values of a row. More...
 
void SetColum (size_t c, const std::vector< T > &col)
 Sets the values of a column. More...
 
void IncreaseElement (size_t r, size_t c, const T &delta)
 Increases the value of an element. More...
 
void IncreaseRow (size_t r, const T &v)
 Increase one row from matrix. More...
 
void IncreaseColumn (size_t c, const T &v)
 Increase one column from matrix. More...
 
Matrixoperator+= (const Matrix &m)
 
Matrixoperator-= (const Matrix &m)
 
Matrixoperator*= (const Matrix &m)
 
bool operator== (const Matrix &m) const
 
bool operator!= (const Matrix &m) const
 
Matrixoperator*= (double d)
 Scaling. More...
 
Matrixoperator/= (double d)
 Scaling. More...
 
void MultRow (size_t r, double v)
 Scale one row from matrix. More...
 
void MultColumn (size_t c, double v)
 Scale one column from matrix. More...
 
void CenterColumns ()
 Centers all columns by subtracting the mean for each column. More...
 
void ReduceColumns (bool centered=true)
 Reduces all columns by dividing by the standard deviation of each column. More...
 
void SwapRows (size_t r1, size_t r2)
 Swap two rows in matrix. More...
 
void SwapColumns (size_t c1, size_t c2)
 Swap two columns in matrix. More...
 
void NormalizeForConvolution ()
 Normalizes the matrix to be used for convolution. More...
 
TypeInfo< T >::SumType CumulateCells () const
 
GetMin () const
 
GetMax () const
 
std::pair< size_t, size_t > Argmin () const
 
std::pair< size_t, size_t > Argmax () const
 
Matrix MakeTranspose ()
 Create transposition. More...
 
virtual MatrixTranspose ()
 Inplace transposition. More...
 
Matrix MakeRowAsColumn (size_t r) const
 Creates a column matrix from a row. More...
 
Matrix MakeRow (size_t r) const
 Extract a row from current matrix. More...
 
Matrix MakeColumn (size_t k) const
 Extracts one column from matrix. More...
 
size_t ArgmaxInRow (size_t r) const
 Returns the row index of the maximal element in a row. More...
 
size_t ArgmaxInColumn (size_t c) const
 Returns the row index of the maximal element in a column. More...
 
size_t CountNullCellsInRow (size_t r) const
 Counts null cells in row. More...
 
size_t CountNullCellsInColumn (size_t c) const
 Counts null cells in column. More...
 
size_t CountNullCells () const
 
Matrix MakeColumnMeans () const
 
Matrix MakeColumnDeviations (const Matrix &means) const
 
Matrix MakeColumnDeviations (bool zero_means=false) const
 standard deviation of patterns stored as the rows of a data matrix More...
 
Matrix MakeCovariance () const
 
T * operator[] (size_t r)
 Returns a row. More...
 
const T * operator[] (size_t r) const
 Returns a row. More...
 
const std::vector< T > & Std () const &noexcept
 
std::vector< T > Std ()&&
 
template<typename IMG >
IMG ToImage () const
 Converts to image. More...
 
String ToString () const
 Prints matrix into a string. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Protected Types

using datatype = std::vector< T >
 

Protected Member Functions

bool areValidIndexes (size_t r, size_t c) const
 checks the validity of indexes More...
 

Protected Attributes

datatype data
 
size_t rows
 
size_t cols
 

Detailed Description

template<typename T>
class crn::Matrix< T >

Base matrix class.

Matrix

Author
Yann LEYDIER
Date
Dec 2014
Version
0.1

Definition at line 43 of file CRNMatrix.h.

Member Typedef Documentation

template<typename T>
using crn::Matrix< T >::datatype = std::vector<T>
protected

Internal data representation

Definition at line 692 of file CRNMatrix.h.

Constructor & Destructor Documentation

template<typename T>
crn::Matrix< T >::Matrix ( size_t  nrow,
size_t  ncol,
const T &  value = T(0) 
)
inline

Constructor.

Exceptions
ExceptionDomainwidth or height is null
Parameters
[in]nrownumber or rows
[in]ncolnumber of columns
[in]valuedefault value for elements

Definition at line 52 of file CRNMatrix.h.

template<typename T>
crn::Matrix< T >::Matrix ( const std::vector< std::vector< T >> &  m)
inline

Constructor from std::vector matrix.

Exceptions
ExceptionDimensionempty matrix
ExceptionInvalidArgumentthe argument is not a matrix
Parameters
[in]ma matrix

Definition at line 64 of file CRNMatrix.h.

template<typename T>
crn::Matrix< T >::Matrix ( const std::vector< T > &  vect,
Orientation  ori = Orientation::VERTICAL 
)
inline

Constructor from std::vector 1D vector.

Exceptions
ExceptionDimensionempty matrix
ExceptionInvalidArgumentinvalid orientation
Parameters
[in]vecta vector
[in]oriVERTICAL to create a column vector, HORIZONTAL to create a line vector

Definition at line 88 of file CRNMatrix.h.

template<typename T>
crn::Matrix< T >::Matrix ( std::vector< T > &&  vect,
Orientation  ori = Orientation::VERTICAL 
)
inline

Constructor from std::vector 1D vector.

Exceptions
ExceptionDimensionempty matrix
ExceptionInvalidArgumentinvalid orientation
Parameters
[in]vecta vector
[in]oriVERTICAL to create a column vector, HORIZONTAL to create a line vector

Definition at line 114 of file CRNMatrix.h.

template<typename T>
virtual crn::Matrix< T >::~Matrix ( )
overridevirtualdefault

Destructor.

template<typename T>
crn::Matrix< T >::Matrix ( const Matrix< T > &  )
default
template<typename T>
template<typename Y >
crn::Matrix< T >::Matrix ( const Matrix< Y > &  m)
inline

Definition at line 137 of file CRNMatrix.h.

template<typename T>
crn::Matrix< T >::Matrix ( Matrix< T > &&  )
default

Member Function Documentation

template<typename T>
bool crn::Matrix< T >::areValidIndexes ( size_t  r,
size_t  c 
) const
inlineprotected

checks the validity of indexes

Definition at line 690 of file CRNMatrix.h.

template<typename T>
std::pair<size_t, size_t> crn::Matrix< T >::Argmax ( ) const
inline
Returns
row and column number of the maximal element in the matrix

Definition at line 451 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::ArgmaxInColumn ( size_t  c) const
inline

Returns the row index of the maximal element in a column.

Exceptions
ExceptionDomainrow out of bounds
Returns
the index of the maximal element in the column

Definition at line 538 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::ArgmaxInRow ( size_t  r) const
inline

Returns the row index of the maximal element in a row.

Exceptions
ExceptionDomainrow out of bounds
Returns
the index of the maximal element in the row

Definition at line 527 of file CRNMatrix.h.

template<typename T>
std::pair<size_t, size_t> crn::Matrix< T >::Argmin ( ) const
inline
Returns
row and column number of the minimal element in the matrix

Definition at line 444 of file CRNMatrix.h.

template<typename T>
const T& crn::Matrix< T >::At ( size_t  pos) const
inlinenoexcept

Definition at line 165 of file CRNMatrix.h.

template<typename T>
T& crn::Matrix< T >::At ( size_t  pos)
inlinenoexcept

Definition at line 166 of file CRNMatrix.h.

template<typename T>
const T& crn::Matrix< T >::At ( size_t  r,
size_t  c 
) const
inlinenoexcept

Definition at line 167 of file CRNMatrix.h.

template<typename T>
T& crn::Matrix< T >::At ( size_t  r,
size_t  c 
)
inlinenoexcept

Definition at line 168 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::CenterColumns ( )
inline

Centers all columns by subtracting the mean for each column.

Definition at line 342 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::CountNullCells ( ) const
inline
Returns
number of null cells in matrix

Definition at line 585 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::CountNullCellsInColumn ( size_t  c) const
inline

Counts null cells in column.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]ccolumn index
Returns
the number of null cells in a given column

Definition at line 573 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::CountNullCellsInRow ( size_t  r) const
inline

Counts null cells in row.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]rrow index
Returns
the number of null cells in a given row

Definition at line 561 of file CRNMatrix.h.

template<typename T>
TypeInfo<T>::SumType crn::Matrix< T >::CumulateCells ( ) const
inline
Returns
the sum of the elements

Definition at line 422 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::GetCols ( ) const
inlinenoexcept

Returns the number of columns.

Returns
The number of columns.

Definition at line 163 of file CRNMatrix.h.

template<typename T>
T crn::Matrix< T >::GetMax ( ) const
inline
Returns
the maximal value in the matrix

Definition at line 438 of file CRNMatrix.h.

template<typename T>
T crn::Matrix< T >::GetMin ( ) const
inline
Returns
the minimal value in the matrix

Definition at line 432 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::GetRows ( ) const
inlinenoexcept

Returns the number of rows.

Returns
The number of rows.

Definition at line 157 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::IncreaseColumn ( size_t  c,
const T &  v 
)
inline

Increase one column from matrix.

Exceptions
ExceptionDomaincolumn out of bounds
Parameters
[in]ccolumn index
[in]vterm to add to column

Definition at line 255 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::IncreaseElement ( size_t  r,
size_t  c,
const T &  delta 
)
inline

Increases the value of an element.

Exceptions
ExceptionDomainindex out of range
Parameters
[in]rrow index
[in]ccolumn index
[in]deltato add

Definition at line 230 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::IncreaseRow ( size_t  r,
const T &  v 
)
inline

Increase one row from matrix.

Exceptions
ExceptionDomainrow out of bounds
Parameters
[in]rrow index
[in]vterm to add to row

Definition at line 242 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeColumn ( size_t  k) const
inline

Extracts one column from matrix.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]kcolumn index
Returns
the column as a new matrix

Definition at line 513 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeColumnDeviations ( const Matrix< T > &  means) const
inline
Returns
standard deviation of patterns stored as the rows of a data matrix

Definition at line 602 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeColumnDeviations ( bool  zero_means = false) const
inline

standard deviation of patterns stored as the rows of a data matrix

Parameters
[in]zero_meansindicate if mean values are considered as null or to be computed

Definition at line 615 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeColumnMeans ( ) const
inline
Returns
mean of patterns stored as the rows of a data matrix as a column vector

Definition at line 591 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeCovariance ( ) const
inline
Returns
the covariance matrix

Definition at line 624 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeRow ( size_t  r) const
inline

Extract a row from current matrix.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]rrow index
Returns
the new row matrix

Definition at line 501 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeRowAsColumn ( size_t  r) const
inline

Creates a column matrix from a row.

Exceptions
ExceptionDomainrow out of bounds
Parameters
[in]rrow index
Returns
a new column matrix containing the transposed selected row

Definition at line 489 of file CRNMatrix.h.

template<typename T>
Matrix crn::Matrix< T >::MakeTranspose ( )
inline

Create transposition.

Returns
a new transposed matrix

Definition at line 460 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::MultColumn ( size_t  c,
double  v 
)
inline

Scale one column from matrix.

Exceptions
ExceptionDomaincolumn out of bounds
Parameters
[in]ccolumn index
[in]vratio to scale cells of column

Definition at line 333 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::MultRow ( size_t  r,
double  v 
)
inline

Scale one row from matrix.

Exceptions
ExceptionDomainrow out of bounds
Parameters
[in]rrow index
[in]vratio to scale cells of row

Definition at line 320 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::Negative ( )
inline

Change sign for all elements.

Definition at line 182 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::NormalizeForConvolution ( )
inline

Normalizes the matrix to be used for convolution.

Definition at line 409 of file CRNMatrix.h.

template<typename T>
bool crn::Matrix< T >::operator!= ( const Matrix< T > &  m) const
inline

Definition at line 298 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator*= ( const Matrix< T > &  m)
inline

Definition at line 279 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator*= ( double  d)
inline

Scaling.

Scale all the cells of the matrix by a given factor

Parameters
[in]dscaling factor

Definition at line 306 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator+= ( const Matrix< T > &  m)
inline

Definition at line 263 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator-= ( const Matrix< T > &  m)
inline

Definition at line 271 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator/= ( double  d)
inline

Scaling.

Scale all the cells of the matrix by a given factor

Parameters
[in]factorscaling factor

Definition at line 313 of file CRNMatrix.h.

template<typename T>
Matrix& crn::Matrix< T >::operator= ( const Matrix< T > &  )
default
template<typename T>
Matrix& crn::Matrix< T >::operator= ( Matrix< T > &&  )
default
template<typename T>
bool crn::Matrix< T >::operator== ( const Matrix< T > &  m) const
inline

Definition at line 292 of file CRNMatrix.h.

template<typename T>
T* crn::Matrix< T >::operator[] ( size_t  r)
inline

Returns a row.

Parameters
[in]rThe row number.
Returns
A pointer to the row.

Definition at line 648 of file CRNMatrix.h.

template<typename T>
const T* crn::Matrix< T >::operator[] ( size_t  r) const
inline

Returns a row.

Parameters
[in]rThe row number.
Returns
A pointer to the row.

Definition at line 655 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::ReduceColumns ( bool  centered = true)
inline

Reduces all columns by dividing by the standard deviation of each column.

Parameters
[in]centeredare the data centered?

Definition at line 358 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::SetAll ( const T &  v)
inline

Set all elements.

Parameters
[in]vvalue to set all cells

Definition at line 173 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::SetColum ( size_t  c,
const std::vector< T > &  col 
)
inline

Sets the values of a column.

Exceptions
ExceptionDomainindex out of range
ExceptionDimensionargument has incorrect size
Parameters
[in]ccolumn index
[in]colthe column to copy

Definition at line 213 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::SetRow ( size_t  r,
const std::vector< T > &  row 
)
inline

Sets the values of a row.

Exceptions
ExceptionDomainindex out of range
ExceptionDimensionargument has incorrect size
Parameters
[in]rrow index
[in]rowthe row to copy

Definition at line 196 of file CRNMatrix.h.

template<typename T>
const std::vector<T>& crn::Matrix< T >::Std ( ) const
inlinenoexcept
Returns
the content as a std::vector

Definition at line 658 of file CRNMatrix.h.

template<typename T>
std::vector<T> crn::Matrix< T >::Std ( )
inline
Returns
the content as a std::vector

Definition at line 660 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::Swap ( Matrix< T > &  m)
inline

Definition at line 146 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::SwapColumns ( size_t  c1,
size_t  c2 
)
inline

Swap two columns in matrix.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]c1one column index
[in]c2another column index

Definition at line 399 of file CRNMatrix.h.

template<typename T>
void crn::Matrix< T >::SwapRows ( size_t  r1,
size_t  r2 
)
inline

Swap two rows in matrix.

Exceptions
ExceptionDomainindex out of bounds
Parameters
[in]r1one row index
[in]r2another row index

Definition at line 385 of file CRNMatrix.h.

template<typename T>
template<typename IMG >
IMG crn::Matrix< T >::ToImage ( ) const
inline

Converts to image.

Definition at line 663 of file CRNMatrix.h.

template<typename T>
String crn::Matrix< T >::ToString ( ) const
inline

Prints matrix into a string.

Returns
a string containing the matrix values

Definition at line 673 of file CRNMatrix.h.

template<typename T>
virtual Matrix& crn::Matrix< T >::Transpose ( )
inlinevirtual

Inplace transposition.

Returns
a reference to self

Reimplemented in crn::SquareMatrixDouble.

Definition at line 472 of file CRNMatrix.h.

Member Data Documentation

template<typename T>
size_t crn::Matrix< T >::cols
protected

dimensions of the matrix

Definition at line 694 of file CRNMatrix.h.

template<typename T>
datatype crn::Matrix< T >::data
protected

rows, cols

Definition at line 693 of file CRNMatrix.h.

template<typename T>
size_t crn::Matrix< T >::rows
protected

Definition at line 694 of file CRNMatrix.h.


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