12#ifndef BELFEM_CL_AR_MATRIX_HPP
13#define BELFEM_CL_AR_MATRIX_HPP
27 template<
typename T >
52 const size_t aNumCols ) :
53 mMatrix( aNumRows, aNumCols ) {}
58 const size_t aNumCols,
60 mMatrix( aNumRows, aNumCols )
67 Matrix(
const std::initializer_list<std::initializer_list<T> > & aInitList )
68 : mMatrix( aInitList )
76 : mMatrix( aExpression ) {}
80 template<
typename ET,
typename OP >
81 Matrix(
const arma::Op<ET, OP> & aExpression )
82 : mMatrix( aExpression ) {}
90 mMatrix( aMatrix.mMatrix )
97 mMatrix( std::move( aMatrix.mMatrix ) )
118 return mMatrix.memptr();
126 return mMatrix.memptr();
158 mMatrix.fill( aValue );
164 set_size(
const size_t aNumRows,
const size_t aNumCols )
166 mMatrix.set_size( aNumRows, aNumCols );
172 set_size(
const size_t aNumRows,
const size_t aNumCols,
const T & aValue )
174 this->
set_size( aNumRows, aNumCols );
175 this->
fill( aValue );
185 return mMatrix.n_rows;
193 return mMatrix.n_cols;
204 return mMatrix.n_elem;
216 return mMatrix.n_rows;
229 if (
this != & aMatrix )
231 mMatrix = std::move( aMatrix.mMatrix );
242 if (
this != &aMatrix )
244 mMatrix = aMatrix.mMatrix;
259 "Row index %lu out of bounds, which must be smaller than %lu.",
260 (
long unsigned int ) aRowIndex,
261 (
long unsigned int ) this->
n_rows() );
264 "Col index %lu out of bounds, which must be smaller than %lu.",
265 (
long unsigned int ) aColIndex,
266 (
long unsigned int ) this->
n_cols() );
268 return mMatrix( aRowIndex, aColIndex );
276 virtual inline const T &
277 operator()(
const size_t aRowIndex,
const size_t aColIndex )
const
280 "Row index %lu out of bounds, which must be smaller than %lu.",
281 (
long unsigned int ) aRowIndex,
282 (
long unsigned int ) this->
n_rows() );
285 "Col index %lu out of bounds, which must be smaller than %lu.",
286 (
long unsigned int ) aColIndex,
287 (
long unsigned int ) this->
n_cols() );
289 return mMatrix( aRowIndex, aColIndex );
297 row(
const size_t aRowIndex )
298 ->decltype( mMatrix.row( aRowIndex ) )
301 "Row index %lu out of bounds, which must be less than %lu.",
302 (
long unsigned int ) aRowIndex,
303 (
long unsigned int ) this->
n_rows() );
305 return mMatrix.row( aRowIndex );
311 row(
const size_t aRowIndex )
const
312 ->decltype( mMatrix.row( aRowIndex ) )
315 "Row index %lu out of bounds, which must be less than %lu.",
316 (
long unsigned int ) aRowIndex,
317 (
long unsigned int ) this->
n_rows() );
319 return mMatrix.row( aRowIndex );
325 col(
const size_t aColIndex )
326 ->decltype( mMatrix.col( aColIndex ) )
329 "Col index %lu out of bounds, which must be less than %lu.",
330 (
long unsigned int ) aColIndex,
331 (
long unsigned int ) this->
n_cols() );
333 return mMatrix.col( aColIndex );
339 col(
const size_t aColIndex )
const
340 ->decltype( mMatrix.col( aColIndex ) )
343 "Col index %lu out of bounds, which must be less than %lu.",
344 (
long unsigned int ) aColIndex,
345 (
long unsigned int ) this->
n_cols() );
347 return mMatrix.col( aColIndex );
354 const size_t aFirstCol,
355 const size_t aLastRow,
356 const size_t aLastCol )
357 ->
decltype( mMatrix.submat( aFirstRow, aFirstCol, aLastRow, aLastCol ) )
360 "First row index %lu out of bounds, which must be less than %lu.",
361 (
long unsigned int ) aFirstRow,
362 (
long unsigned int ) this->
n_rows() );
365 "Last row index %lu out of bounds, which must be less than %lu.",
366 (
long unsigned int ) aLastRow,
367 (
long unsigned int ) this->
n_rows() );
370 "First col index %lu out of bounds, which must be less than %lu.",
371 (
long unsigned int ) aFirstCol,
372 (
long unsigned int ) this->
n_cols() );
375 "Last col index %lu out of bounds, which must be less than %lu.",
376 (
long unsigned int ) aLastCol,
377 (
long unsigned int ) this->
n_cols() );
379 return mMatrix.submat( aFirstRow, aFirstCol, aLastRow, aLastCol );
386 const size_t aFirstCol,
387 const size_t aLastRow,
388 const size_t aLastCol )
const
389 ->
decltype( mMatrix.submat( aFirstRow, aFirstCol, aLastRow, aLastCol ) )
392 "First row index %lu out of bounds, which must be less than %lu.",
393 (
long unsigned int ) aFirstRow,
394 (
long unsigned int ) this->
n_rows() );
397 "Last row index %lu out of bounds, which must be less than %lu.",
398 (
long unsigned int ) aLastRow,
399 (
long unsigned int ) this->
n_rows() );
402 "First col index %lu out of bounds, which must be less than %lu.",
403 (
long unsigned int ) aFirstCol,
404 (
long unsigned int ) this->
n_cols() );
407 "Last col index %lu out of bounds, which must be less than %lu.",
408 (
long unsigned int ) aLastCol,
409 (
long unsigned int ) this->
n_cols() );
411 return mMatrix.submat( aFirstRow, aFirstCol, aLastRow, aLastCol );
417 set_row(
const size_t aRowIndex,
const Vector <T> & aVector )
421 "Wrong length of vector : %lu ( expect %lu )",
422 (
long unsigned int ) aVector.
length(),
423 (
long unsigned int ) this->n_cols() );
428 template <
typename ET >
430 set_row(
const size_t aColIndex,
const ET & aExpression )
432 this->
row( aColIndex ) = aExpression;
438 set_col(
const size_t aColIndex,
const Vector <T> & aVector )
442 "Wrong length of vector : %lu ( expect %lu )",
443 (
long unsigned int ) aVector.
length(),
444 (
long unsigned int ) this->n_rows() );
449 template <
typename ET >
451 set_col(
const size_t aColIndex,
const ET & aExpression )
453 this->
col( aColIndex ) = aExpression;
467 this->
fill( aValue );
476 template <
typename ET >
480 mMatrix = aExpression;
507 mMatrix += aMatrix.matrix_data();
516 mMatrix += aExpression;
536 mMatrix -= aMatrix.matrix_data();
545 mMatrix -= aExpression;
565 mMatrix *= aMatrix.matrix_data();
574 mMatrix *= aExpression;
594 print(
const std::string aLabel=
"Matrix" )
const;
602#pragma GCC diagnostic push
603#pragma GCC diagnostic ignored "-Wformat"
605 template <
typename T >
void
608 FILE * tOutFile = stdout;
610 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
615 uint tRows = tThis.n_rows();
616 uint tCols = tThis.n_cols();
618 for(
uint i=0; i< tRows; ++i )
620 for(
uint j=0; j< tCols; ++j )
624 fprintf( tOutFile,
"%d, ", (
int ) tThis( i, j ) );
628 fprintf( tOutFile,
"%d; ", (
int ) tThis( i, j ) );
634 fprintf( tOutFile,
"...\n" );
638 fprintf( tOutFile,
"];\n" );
649 FILE * tOutFile = stdout;
651 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
658 for(
uint i=0; i< tRows; ++i )
660 for(
uint j=0; j< tCols; ++j )
664 fprintf( tOutFile,
"%+.15e, ", (
double ) tThis( i, j ) );
668 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i, j ) );
674 fprintf( tOutFile,
"...\n" );
678 fprintf( tOutFile,
"];\n" );
685#pragma GCC diagnostic pop
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Dense column-major matrix.
Definition cl_BZ_Matrix.hpp:28
Matrix< T > & operator=(Matrix< T > &&aMatrix) noexcept
move assignment operator
Definition cl_AR_Matrix.hpp:227
size_t spacing() const
inter-column stride of the data container ( the leading dimension in BLAS terms; here always n_rows )
Definition cl_AR_Matrix.hpp:214
Matrix< T > & operator+=(const T &aValue)
Definition cl_AR_Matrix.hpp:489
auto col(const size_t aColIndex) const -> decltype(mMatrix.col(aColIndex))
Definition cl_AR_Matrix.hpp:339
void set_size(const size_t aNumRows, const size_t aNumCols, const T &aValue)
Definition cl_AR_Matrix.hpp:172
virtual ~Matrix()=default
empty destructor
auto col(const size_t aColIndex) -> decltype(mMatrix.col(aColIndex))
Definition cl_AR_Matrix.hpp:325
auto submat(const size_t aFirstRow, const size_t aFirstCol, const size_t aLastRow, const size_t aLastCol) const -> decltype(mMatrix.submat(aFirstRow, aFirstCol, aLastRow, aLastCol))
Definition cl_AR_Matrix.hpp:385
const MatrixType & matrix_data() const
Definition cl_AR_Matrix.hpp:146
void fill(const T &aValue)
Definition cl_AR_Matrix.hpp:156
auto submat(const size_t aFirstRow, const size_t aFirstCol, const size_t aLastRow, const size_t aLastCol) -> decltype(mMatrix.submat(aFirstRow, aFirstCol, aLastRow, aLastCol))
Definition cl_AR_Matrix.hpp:353
auto row(const size_t aRowIndex) -> decltype(mMatrix.row(aRowIndex))
Definition cl_AR_Matrix.hpp:297
Matrix< T > & operator/=(const T &aValue)
Definition cl_AR_Matrix.hpp:583
Matrix(const size_t aNumRows, const size_t aNumCols)
Definition cl_AR_Matrix.hpp:51
void set_row(const size_t aRowIndex, const Vector< T > &aVector)
Definition cl_AR_Matrix.hpp:417
MatrixType & matrix_data()
Definition cl_AR_Matrix.hpp:135
size_t capacity() const
The logical element count n_rows() * n_cols() ( Armadillo's n_elem ).
Definition cl_AR_Matrix.hpp:202
Matrix< T > & operator-=(const T &aValue)
Definition cl_AR_Matrix.hpp:525
Matrix(const MatrixType &aExpression)
Definition cl_AR_Matrix.hpp:75
Matrix< T > & operator-=(const MatrixType &aExpression)
Definition cl_AR_Matrix.hpp:543
Matrix(const arma::Op< ET, OP > &aExpression)
Definition cl_AR_Matrix.hpp:81
void set_size(const size_t aNumRows, const size_t aNumCols)
Definition cl_AR_Matrix.hpp:164
size_t n_rows() const
Definition cl_AR_Matrix.hpp:183
void set_col(const size_t aColIndex, const Vector< T > &aVector)
Definition cl_AR_Matrix.hpp:438
Matrix(const Matrix< T > &aMatrix)
copy constructor
Definition cl_AR_Matrix.hpp:89
Matrix< T > & operator=(const Matrix< T > &aMatrix)
copy assignment operator
Definition cl_AR_Matrix.hpp:240
T & operator()(const size_t aRowIndex, const size_t aColIndex)
access operator ( writable version )
Definition cl_AR_Matrix.hpp:256
void set_row(const size_t aColIndex, const ET &aExpression)
Definition cl_AR_Matrix.hpp:430
arma::Mat< T > MatrixType
Definition cl_AR_Matrix.hpp:34
Matrix< T > & operator=(const T &aValue)
Fill with value.
Definition cl_AR_Matrix.hpp:465
Matrix< T > & operator-=(const Matrix< T > &aMatrix)
Definition cl_AR_Matrix.hpp:534
virtual const T & operator()(const size_t aRowIndex, const size_t aColIndex) const
access operator ( const version )
Definition cl_AR_Matrix.hpp:277
size_t n_cols() const
Definition cl_AR_Matrix.hpp:191
Matrix(Matrix< T > &&aMatrix) noexcept
move constructor
Definition cl_AR_Matrix.hpp:96
Matrix(const std::initializer_list< std::initializer_list< T > > &aInitList)
Definition cl_AR_Matrix.hpp:67
Matrix< T > & operator+=(T &aValue)
Definition cl_AR_Matrix.hpp:496
Matrix< T > & operator*=(const MatrixType &aExpression)
Definition cl_AR_Matrix.hpp:572
Matrix< T > & operator+=(const MatrixType &aExpression)
Definition cl_AR_Matrix.hpp:514
Matrix< T > & operator*=(const Matrix< T > &aMatrix)
Definition cl_AR_Matrix.hpp:563
Matrix< T > & operator*=(const T &aValue)
Definition cl_AR_Matrix.hpp:554
const T * data() const
Definition cl_AR_Matrix.hpp:124
void print(const std::string aLabel="Matrix") const
Definition cl_AR_Matrix.hpp:606
Matrix(const size_t aNumRows, const size_t aNumCols, const T aValue)
Definition cl_AR_Matrix.hpp:57
T * data()
Returns a borrowed raw buffer under the layout contract stated in cl_Matrix.hpp; may be nullptr when ...
Definition cl_AR_Matrix.hpp:116
Matrix< T > & operator+=(const Matrix< T > &aMatrix)
Definition cl_AR_Matrix.hpp:505
Matrix< T > & operator=(const ET &aExpression)
Fill with expression.
Definition cl_AR_Matrix.hpp:478
void set_col(const size_t aColIndex, const ET &aExpression)
Definition cl_AR_Matrix.hpp:451
auto row(const size_t aRowIndex) const -> decltype(mMatrix.row(aRowIndex))
Definition cl_AR_Matrix.hpp:311
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:235
VectorType & vector_data()
expose the underlying matrix implementation ( writable version )
Definition cl_AR_Vector.hpp:182
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30