bpp-core  2.1.0
 All Classes Namespaces Files Functions Variables Typedefs Friends
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 233 of file Matrix.h.

Constructor & Destructor Documentation

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

Build a 0 x 0 matrix.

Definition at line 245 of file Matrix.h.

References bpp::LinearMatrix< Scalar >::resize_().

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

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

build a nRow x nCol matrix.

Definition at line 252 of file Matrix.h.

References bpp::LinearMatrix< Scalar >::resize_().

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

Destructor.

Definition at line 288 of file Matrix.h.

Member Function Documentation

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 291 of file Matrix.h.

References bpp::LinearMatrix< Scalar >::LinearMatrix().

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 311 of file Matrix.h.

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

template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::getNumberOfColumns ( ) const
inlinevirtual
template<class Scalar>
size_t bpp::LinearMatrix< Scalar >::getNumberOfRows ( ) const
inlinevirtual
template<class Scalar>
const Scalar& bpp::LinearMatrix< Scalar >::operator() ( size_t  i,
size_t  j 
) const
inlinevirtual
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 295 of file Matrix.h.

References bpp::LinearMatrix< Scalar >::cols_, and bpp::LinearMatrix< Scalar >::m_.

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 327 of file Matrix.h.

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 375 of file Matrix.h.

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

template<class Scalar>
void bpp::LinearMatrix< Scalar >::resize_ ( size_t  nRows,
size_t  nCols 
)
inlineprivate
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 301 of file Matrix.h.

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

Member Data Documentation

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

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