5 #ifndef BPP_NUMERIC_MATRIX_MATRIX_H 6 #define BPP_NUMERIC_MATRIX_MATRIX_H 11 #include "../../Clonable.h" 12 #include "../NumConstants.h" 13 #include "../NumTools.h" 14 #include "../VectorExceptions.h" 21 template<
class Scalar>
35 virtual const Scalar&
operator()(
size_t i,
size_t j)
const = 0;
42 virtual Scalar&
operator()(
size_t i,
size_t j) = 0;
52 if (NumTools::abs<double>(static_cast<double>(
operator()(i, j)) - static_cast<double>(m(i, j))) > threshold)
return false;
69 virtual std::vector<Scalar>
row(
size_t i)
const = 0;
74 virtual std::vector<Scalar>
col(
size_t j)
const = 0;
81 virtual void resize(
size_t nRows,
size_t nCols) = 0;
91 template<
class Scalar>
96 std::vector< std::vector<Scalar>>
m_;
103 for (
size_t i = 0; i < nRow; i++)
113 for (
size_t i = 0; i < nr; i++)
116 for (
size_t j = 0; j < nc; j++)
128 for (
size_t i = 0; i < nr; i++)
131 for (
size_t j = 0; j < nc; j++)
144 const Scalar&
operator()(
size_t i,
size_t j)
const {
return m_[i][j]; }
152 std::vector<Scalar>
row(
size_t i)
const 159 const std::vector<Scalar>&
getRow(
size_t i)
const 169 std::vector<Scalar>
col(
size_t j)
const 179 for (
size_t i = 0; i < nRows; i++)
185 void addRow(
const std::vector<Scalar>& newRow)
189 m_.push_back(newRow);
199 template<
class Scalar>
204 std::vector< std::vector<Scalar>>
m_;
211 for (
size_t i = 0; i < nCol; i++)
221 for (
size_t i = 0; i < nc; i++)
224 for (
size_t j = 0; j < nr; j++)
236 for (
size_t i = 0; i < nc; i++)
239 for (
size_t j = 0; j < nr; j++)
252 const Scalar&
operator()(
size_t i,
size_t j)
const {
return m_[j][i]; }
260 std::vector<Scalar>
row(
size_t i)
const 267 const std::vector<Scalar>&
getCol(
size_t i)
const 277 std::vector<Scalar>
col(
size_t j)
const 287 for (
size_t i = 0; i < nCols; i++)
293 void addCol(
const std::vector<Scalar>& newCol)
297 m_.push_back(newCol);
317 template<
class Scalar>
322 std::vector<Scalar>
m_;
332 cols_(0) { resize_(0, 0); }
339 cols_(nCol) { resize_(nRow, nCol); }
343 for (
size_t i = 0; i < rows_; i++)
345 for (
size_t j = 0; j < cols_; j++)
347 m_[i * cols_ + j] = m(i, j);
356 m_.resize(rows_ * cols_);
357 for (
size_t i = 0; i < rows_; i++)
359 for (
size_t j = 0; j < cols_; j++)
361 m_[i * cols_ + j] = m(i, j);
376 const Scalar&
operator()(
size_t i,
size_t j)
const {
return m_[i * cols_ + j]; }
378 Scalar&
operator()(
size_t i,
size_t j) {
return m_[i * cols_ + j]; }
384 std::vector<Scalar>
row(
size_t i)
const 394 std::vector<Scalar>
col(
size_t j)
const 412 resize(nRows, nCols,
true);
458 void resize(
size_t nRows,
size_t nCols,
bool keepValues)
463 resize_(nRows, nCols);
466 for (
size_t i = 0; i < nRows; i++)
468 for (
size_t j = 0; j < nCols; j++)
489 m_.resize(nRows * nCols);
495 template<
class Scalar>
504 if (m1(i, j) != m2(i, j))
511 #endif // BPP_NUMERIC_MATRIX_MATRIX_H void resize(size_t nRows, size_t nCols)
Resize the matrix.
The matrix template interface.
size_t getNumberOfRows() const
Scalar & operator()(size_t i, size_t j)
RowMatrix & operator=(const Matrix< Scalar > &m)
void resize(size_t nRows, size_t nCols, bool keepValues)
Resize the matrix.
LinearMatrix & operator=(const Matrix< Scalar > &m)
virtual void resize(size_t nRows, size_t nCols)=0
Resize the matrix.
const Scalar & operator()(size_t i, size_t j) const
size_t getNumberOfRows() const
std::vector< Scalar > & getRow(size_t i)
ColMatrix * clone() const
Create a copy of this object and send a pointer to it.
Scalar & operator()(size_t i, size_t j)
void resize_(size_t nRows, size_t nCols)
Internal basic resize fonctionnalities.
LinearMatrix(size_t nRow, size_t nCol)
build a nRow x nCol matrix.
const Scalar & operator()(size_t i, size_t j) const
std::vector< Scalar > col(size_t j) const
size_t getNumberOfColumns() const
Matrix storage in one vector.
std::vector< std::vector< Scalar > > m_
RowMatrix(const Matrix< Scalar > &m)
std::vector< Scalar > col(size_t j) const
void resize(size_t nRows, size_t nCols)
Resize the matrix.
virtual const Scalar & operator()(size_t i, size_t j) const =0
ColMatrix & operator=(const Matrix< Scalar > &m)
Matrix storage by column.
RowMatrix * clone() const
Create a copy of this object and send a pointer to it.
ColMatrix(size_t nRow, size_t nCol)
size_t getNumberOfColumns() const
virtual size_t getNumberOfColumns() const =0
virtual std::vector< Scalar > col(size_t j) const =0
void addCol(const std::vector< Scalar > &newCol)
void resize(size_t nRows, size_t nCols)
Resize the matrix.
bool operator==(const Matrix< Scalar > &m1, const Matrix< Scalar > &m2)
LinearMatrix()
Build a 0 x 0 matrix.
const std::vector< Scalar > & getCol(size_t i) const
The Clonable interface (allow an object to be cloned).
size_t getNumberOfRows() const
LinearMatrix * clone() const
Create a copy of this object and send a pointer to it.
std::vector< Scalar > row(size_t i) const
virtual std::vector< Scalar > row(size_t i) const =0
std::vector< Scalar > col(size_t j) const
const std::vector< Scalar > & getRow(size_t i) const
void addRow(const std::vector< Scalar > &newRow)
std::vector< Scalar > row(size_t i) const
ColMatrix(const Matrix< Scalar > &m)
std::vector< Scalar > & getCol(size_t i)
RowMatrix(size_t nRow, size_t nCol)
virtual size_t getNumberOfRows() const =0
Scalar & operator()(size_t i, size_t j)
std::vector< std::vector< Scalar > > m_
virtual bool equals(const Matrix &m, double threshold=NumConstants::TINY())
const Scalar & operator()(size_t i, size_t j) const
LinearMatrix(const Matrix< Scalar > &m)
virtual ~LinearMatrix()
Destructor.
size_t getNumberOfColumns() const
std::vector< Scalar > row(size_t i) const
Exception thrown when a dimension problem occured.