bpp-core3  3.0.0
bpp::LinearMatrix< Scalar > Class Template Reference

Matrix storage in one vector. More...

#include <Bpp/Numeric/Matrix/Matrix.h>

+ Inheritance diagram for bpp::LinearMatrix< Scalar >:
+ Collaboration diagram for bpp::LinearMatrix< Scalar >:

Public Member Functions

 LinearMatrix ()
 Build a 0 x 0 matrix. More...
 
 LinearMatrix (size_t nRow, size_t nCol)
 build a nRow x nCol matrix. More...
 
 LinearMatrix (const Matrix< Scalar > &m)
 
LinearMatrixoperator= (const Matrix< Scalar > &m)
 
virtual ~LinearMatrix ()
 Destructor. More...
 
LinearMatrixclone () const
 Create a copy of this object and send a pointer to it. More...
 
const Scalar & operator() (size_t i, size_t j) const
 
Scalar & operator() (size_t i, size_t j)
 
size_t getNumberOfRows () const
 
size_t getNumberOfColumns () const
 
std::vector< Scalar > row (size_t i) const
 
std::vector< Scalar > col (size_t j) const
 
void resize (size_t nRows, size_t nCols)
 Resize the matrix. More...
 
void resize (size_t nRows, size_t nCols, bool keepValues)
 Resize the matrix. More...
 
virtual bool equals (const Matrix &m, double threshold=NumConstants::TINY())
 

Private Member Functions

void resize_ (size_t nRows, size_t nCols)
 Internal basic resize fonctionnalities. More...
 

Private Attributes

std::vector< Scalar > m_
 
size_t rows_
 
size_t cols_
 

Detailed Description

template<class Scalar>
class bpp::LinearMatrix< Scalar >

Matrix storage in one vector.

This Matrix is a simple vector of Scalar of size n x m. Element access is in $O(1)$ but resizing the matrix while keeping the old values is in $O(nm)$.

Basic usage:

LinearMatrix<int> m(3, 2); // Create a 3x2 matrix of int
m(1, 2) = 5; // Set the value of element at row = 1, col = 2 to 5
int x = m(0, 1); // Get the value of element at row = 0, col = 1;
Author
Sylvain Gaillard

Definition at line 318 of file Matrix.h.

Constructor & Destructor Documentation

◆ LinearMatrix() [1/3]

template<class Scalar>
bpp::LinearMatrix< Scalar >::LinearMatrix ( )
inline

Build a 0 x 0 matrix.

Definition at line 330 of file Matrix.h.

◆ LinearMatrix() [2/3]

template<class Scalar>
bpp::LinearMatrix< Scalar >::LinearMatrix ( size_t  nRow,
size_t  nCol 
)
inline

build a nRow x nCol matrix.

Definition at line 337 of file Matrix.h.

◆ LinearMatrix() [3/3]

template<class Scalar>
bpp::LinearMatrix< Scalar >::LinearMatrix ( const Matrix< Scalar > &  m)
inline

Definition at line 341 of file Matrix.h.

◆ ~LinearMatrix()

template<class Scalar>
virtual bpp::LinearMatrix< Scalar >::~LinearMatrix ( )
inlinevirtual

Destructor.

Definition at line 371 of file Matrix.h.

Member Function Documentation

◆ clone()

template<class Scalar>
LinearMatrix* bpp::LinearMatrix< Scalar >::clone ( ) const
inlinevirtual

Create a copy of this object and send a pointer to it.

Returns
A pointer toward the copy object.

Implements bpp::Clonable.

Definition at line 374 of file Matrix.h.

◆ col()

template<class Scalar>
std::vector<Scalar> bpp::LinearMatrix< Scalar >::col ( size_t  j) const
inlinevirtual
Returns
the column at position j as a vector.
Parameters
jThe index of the column.

Implements bpp::Matrix< Scalar >.

Definition at line 394 of file Matrix.h.

References bpp::Matrix< Scalar >::getNumberOfRows(), and bpp::Matrix< Scalar >::operator()().

◆ equals()

template<class Scalar>
virtual bool bpp::Matrix< Scalar >::equals ( const Matrix< Scalar > &  m,
double  threshold = NumConstants::TINY() 
)
inlinevirtualinherited

◆ getNumberOfColumns()

template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::getNumberOfColumns ( ) const
inlinevirtual
Returns
The number of columns.

Implements bpp::Matrix< Scalar >.

Definition at line 382 of file Matrix.h.

Referenced by bpp::LinearMatrix< Scalar >::resize().

◆ getNumberOfRows()

template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::getNumberOfRows ( ) const
inlinevirtual
Returns
The number of rows.

Implements bpp::Matrix< Scalar >.

Definition at line 380 of file Matrix.h.

Referenced by bpp::LinearMatrix< Scalar >::resize().

◆ operator()() [1/2]

template<class Scalar>
const Scalar& bpp::LinearMatrix< Scalar >::operator() ( size_t  i,
size_t  j 
) const
inlinevirtual
Returns
$m_{i,j}$.
Parameters
irow index.
jcolumn index.

Implements bpp::Matrix< Scalar >.

Definition at line 376 of file Matrix.h.

◆ operator()() [2/2]

template<class Scalar>
Scalar& bpp::LinearMatrix< Scalar >::operator() ( size_t  i,
size_t  j 
)
inlinevirtual
Returns
$m_{i,j}$.
Parameters
irow index.
jcolumn index.

Implements bpp::Matrix< Scalar >.

Definition at line 378 of file Matrix.h.

◆ operator=()

template<class Scalar>
LinearMatrix& bpp::LinearMatrix< Scalar >::operator= ( const Matrix< Scalar > &  m)
inline

◆ resize() [1/2]

template<class Scalar>
void bpp::LinearMatrix< Scalar >::resize ( size_t  nRows,
size_t  nCols 
)
inlinevirtual

Resize the matrix.

Parameters
nRowsThe new number of rows.
nColsThe new number of columns.

This method resize the matrix keeping old data in place.

See also
LinearMatrix::resize(size_t nRow, size_t nCol, bool keepValues)

Implements bpp::Matrix< Scalar >.

Definition at line 410 of file Matrix.h.

References bpp::Matrix< Scalar >::resize().

◆ resize() [2/2]

template<class Scalar>
void bpp::LinearMatrix< Scalar >::resize ( size_t  nRows,
size_t  nCols,
bool  keepValues 
)
inline

Resize the matrix.

This task may be memory consumming if keepValues is true because it use a copy of the input matrix to keep trace of the values.

Parameters
nRowsthe new number of rows
nColsthe new number of columns
keepValuesif old values must be kept in the resized matrix. If keepValues = false, old values are still in the matrix but not at the same positions. For instance:
LinearMatrix<int> m(3, 2);
for (size_t i = 0 ; i < m.getNumberOfRows() ; i++) {
for (size_t j = 0 ; j < m.getNumberOfColumns() ; j++) {
m(i, j) = i * m.nCols() + j + 1;
}
}
// 3x2
// [
// [1, 2]
// [3, 4]
// [5, 6]
// ]
LinearMatrix<int> m2 = m;
m2.resize(2, 4, false); // resize the matrix with keepValues = false
// 2x4
// [
// [1, 2, 3, 4]
// [5, 6, 0, 0]
// ]
LinearMatrix<int> m3 = m;
m3.resize(2, 4, true); // resize the matrix with keepValues = true
// 2x4
// [
// [1, 2, 0, 0]
// [3, 4, 0, 0]
// ]

Definition at line 458 of file Matrix.h.

References bpp::LinearMatrix< Scalar >::getNumberOfColumns(), bpp::LinearMatrix< Scalar >::getNumberOfRows(), and bpp::Matrix< Scalar >::operator()().

◆ resize_()

template<class Scalar>
void bpp::LinearMatrix< Scalar >::resize_ ( size_t  nRows,
size_t  nCols 
)
inlineprivate

Internal basic resize fonctionnalities.

Definition at line 487 of file Matrix.h.

◆ row()

template<class Scalar>
std::vector<Scalar> bpp::LinearMatrix< Scalar >::row ( size_t  i) const
inlinevirtual
Returns
the row at position i as a vector.
Parameters
iThe index of the row.

Implements bpp::Matrix< Scalar >.

Definition at line 384 of file Matrix.h.

References bpp::Matrix< Scalar >::getNumberOfColumns(), and bpp::Matrix< Scalar >::operator()().

Member Data Documentation

◆ cols_

template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::cols_
private

Definition at line 324 of file Matrix.h.

◆ m_

template<class Scalar>
std::vector<Scalar> bpp::LinearMatrix< Scalar >::m_
private

Definition at line 322 of file Matrix.h.

◆ rows_

template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::rows_
private

Definition at line 323 of file Matrix.h.


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