12#ifndef BELFEM_CL_BZ_MATRIX_HPP
13#define BELFEM_CL_BZ_MATRIX_HPP
26 template<
typename T >
33 typedef blaze::DynamicMatrix< T, BLAZE_DEFAULT_STORAGE_ORDER >
MatrixType;
57 const size_t aNumCols ) :
58 mMatrix( aNumRows, aNumCols ) {}
66 const size_t aNumCols,
68 mMatrix( aNumRows, aNumCols, aValue )
76 Matrix(
const std::initializer_list<std::initializer_list<T> > & aInitList )
77 : mMatrix( aInitList )
88 : mMatrix( aExpression ) {}
95 template<
typename MT,
bool SO >
96 Matrix(
const blaze::Matrix< MT, SO > & aExpression )
97 : mMatrix( aExpression ) {}
104 template<
typename VT >
105 Matrix(
const blaze::DenseVector< VT, false > & aExpression )
107 const VT & tVector =
static_cast< const VT&
>( aExpression );
108 mMatrix.resize( tVector.size(), 1UL,
false );
110 for (
size_t k = 0; k < tVector.size(); ++k )
112 mMatrix( k, 0 ) = tVector[ k ];
121 template<
typename VT >
122 Matrix(
const blaze::DenseVector< VT, true > & aExpression )
124 const VT & tVector =
static_cast< const VT&
>( aExpression );
125 mMatrix.resize( 1UL, tVector.size(),
false );
127 for (
size_t k = 0; k < tVector.size(); ++k )
129 mMatrix( 0, k ) = tVector[ k ];
139 mMatrix( aMatrix.mMatrix )
146 mMatrix( std::move( aMatrix.mMatrix ) )
167 return mMatrix.data();
178 return mMatrix.data();
216 set_size(
const size_t aNumRows,
const size_t aNumCols )
218 mMatrix.resize( aNumRows, aNumCols,
false );
224 set_size(
const size_t aNumRows,
const size_t aNumCols,
const T & aValue )
226 this->
set_size( aNumRows, aNumCols );
227 this->
fill( aValue );
237 return mMatrix.rows();
245 return mMatrix.columns();
256 return mMatrix.capacity();
269 return mMatrix.spacing();
282 if (
this != & aMatrix )
284 mMatrix = std::move( aMatrix.mMatrix );
295 if (
this != &aMatrix )
297 mMatrix = aMatrix.mMatrix;
311 "Row index %lu out of bounds, which must be smaller than %lu.",
312 (
long unsigned int ) aRowIndex,
313 (
long unsigned int ) this->
n_rows() );
316 "Col index %lu out of bounds, which must be smaller than %lu.",
317 (
long unsigned int ) aColIndex,
318 (
long unsigned int ) this->
n_cols() );
320 return mMatrix( aRowIndex, aColIndex );
328 virtual inline const T &
329 operator()(
const size_t aRowIndex,
const size_t aColIndex )
const
332 "Row index %lu out of bounds, which must be smaller than %lu.",
333 (
long unsigned int ) aRowIndex,
334 (
long unsigned int ) this->
n_rows() );
337 "Col index %lu out of bounds, which must be smaller than %lu.",
338 (
long unsigned int ) aColIndex,
339 (
long unsigned int ) this->
n_cols() );
341 return mMatrix( aRowIndex, aColIndex );
349 row(
const size_t aRowIndex )
350 ->decltype( blaze::row( mMatrix, aRowIndex ) )
353 "Row index %lu out of bounds, which must be less than %lu.",
354 (
long unsigned int ) aRowIndex,
355 (
long unsigned int ) this->
n_rows() );
357 return blaze::row( mMatrix, aRowIndex );
363 row(
const size_t aRowIndex )
const
364 ->decltype( blaze::row( mMatrix, aRowIndex ) )
367 "Row index %lu out of bounds, which must be less than %lu.",
368 (
long unsigned int ) aRowIndex,
369 (
long unsigned int ) this->
n_rows() );
371 return blaze::row( mMatrix, aRowIndex );
377 col(
const size_t aColIndex )
378 ->decltype( blaze::column( mMatrix, aColIndex ) )
381 "Col index %lu out of bounds, which must be less than %lu.",
382 (
long unsigned int ) aColIndex,
383 (
long unsigned int ) this->
n_cols() );
385 return blaze::column( mMatrix, aColIndex );
391 col(
const size_t aColIndex )
const
392 ->decltype( blaze::column( mMatrix, aColIndex ) )
395 "Col index %lu out of bounds, which must be less than %lu.",
396 (
long unsigned int ) aColIndex,
397 (
long unsigned int ) this->
n_cols() );
399 return blaze::column( mMatrix, aColIndex );
406 const size_t aFirstCol,
407 const size_t aLastRow,
408 const size_t aLastCol )
409 ->
decltype( blaze::submatrix( mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol ) )
412 "First row index %lu out of bounds, which must be less than %lu.",
413 (
long unsigned int ) aFirstRow,
414 (
long unsigned int ) this->
n_rows() );
417 "Last row index %lu out of bounds, which must be less than %lu.",
418 (
long unsigned int ) aLastRow,
419 (
long unsigned int ) this->
n_rows() );
422 "First col index %lu out of bounds, which must be less than %lu.",
423 (
long unsigned int ) aFirstCol,
424 (
long unsigned int ) this->
n_cols() );
427 "Last col index %lu out of bounds, which must be less than %lu.",
428 (
long unsigned int ) aLastCol,
429 (
long unsigned int ) this->
n_cols() );
433 return blaze::submatrix( mMatrix, aFirstRow, aFirstCol,
434 aLastRow - aFirstRow + 1, aLastCol - aFirstCol + 1 );
441 const size_t aFirstCol,
442 const size_t aLastRow,
443 const size_t aLastCol )
const
444 ->
decltype( blaze::submatrix( mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol ) )
447 "First row index %lu out of bounds, which must be less than %lu.",
448 (
long unsigned int ) aFirstRow,
449 (
long unsigned int ) this->
n_rows() );
452 "Last row index %lu out of bounds, which must be less than %lu.",
453 (
long unsigned int ) aLastRow,
454 (
long unsigned int ) this->
n_rows() );
457 "First col index %lu out of bounds, which must be less than %lu.",
458 (
long unsigned int ) aFirstCol,
459 (
long unsigned int ) this->
n_cols() );
462 "Last col index %lu out of bounds, which must be less than %lu.",
463 (
long unsigned int ) aLastCol,
464 (
long unsigned int ) this->
n_cols() );
468 return blaze::submatrix( mMatrix, aFirstRow, aFirstCol,
469 aLastRow - aFirstRow + 1, aLastCol - aFirstCol + 1 );
475 set_row(
const size_t aRowIndex,
const Vector <T> & aVector )
480 "Wrong length of vector : %lu ( expect %lu )",
481 (
long unsigned int ) aVector.
length(),
482 (
long unsigned int ) this->n_cols() );
485 const T * tSource = aVector.
data();
488 for( std::size_t k=0; k<aVector.
length(); ++k )
490 mMatrix( aRowIndex, k ) = tSource[ k ];
496 template <
typename ET >
498 set_row(
const size_t aRowIndex,
const ET & aExpression )
500 this->
row( aRowIndex ) = aExpression;
506 set_col(
const size_t aColIndex,
const Vector <T> & aVector )
510 "Wrong length of vector : %lu ( expect %lu )",
511 (
long unsigned int ) aVector.
length(),
512 (
long unsigned int ) this->n_rows() );
515 this->col( aColIndex ).data() );
518 template <
typename ET >
520 set_col(
const size_t aRowIndex,
const ET & aExpression )
522 this->
col( aRowIndex ) = aExpression;
535 this->
fill( aValue );
544 template <
typename MT,
bool SO >
546 operator=(
const blaze::Matrix< MT, SO > & aExpression )
548 mMatrix = aExpression;
557 template <
typename VT >
559 operator=(
const blaze::DenseVector< VT, false > & aExpression )
561 const VT & tVector =
static_cast< const VT&
>( aExpression );
562 mMatrix.resize( tVector.size(), 1UL,
false );
564 for (
size_t k = 0; k < tVector.size(); ++k )
566 mMatrix( k, 0 ) = tVector[ k ];
576 template <
typename VT >
578 operator=(
const blaze::DenseVector< VT, true > & aExpression )
580 const VT & tVector =
static_cast< const VT&
>( aExpression );
581 mMatrix.resize( 1UL, tVector.size(),
false );
583 for (
size_t k = 0; k < tVector.size(); ++k )
585 mMatrix( 0, k ) = tVector[ k ];
613 template <
typename MT,
bool SO >
615 operator+=(
const blaze::Matrix< MT, SO > & aExpression )
617 mMatrix += aExpression;
645 template <
typename MT,
bool SO >
647 operator-=(
const blaze::Matrix< MT, SO > & aExpression )
649 mMatrix -= aExpression;
658 mMatrix -= aExpression;
686 template <
typename MT,
bool SO >
688 operator*=(
const blaze::Matrix< MT, SO > & aExpression )
690 mMatrix *= aExpression;
699 mMatrix *= aExpression;
720 print(
const std::string aLabel=
"Matrix" )
const;
727#pragma GCC diagnostic push
728#pragma GCC diagnostic ignored "-Wformat"
730 template <
typename T >
void
733 FILE * tOutFile = stdout;
735 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
743 for(
uint i=0; i< tRows; ++i )
745 for(
uint j=0; j< tCols; ++j )
749 fprintf( tOutFile,
"%d, ", (
int ) tThis( i, j ) );
753 fprintf( tOutFile,
"%d; ", (
int ) tThis( i, j ) );
759 fprintf( tOutFile,
"...\n" );
763 fprintf( tOutFile,
"];\n" );
774 FILE * tOutFile = stdout;
776 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
783 for(
uint i=0; i< tRows; ++i )
785 for(
uint j=0; j< tCols; ++j )
789 fprintf( tOutFile,
"%+.15e, ", (
double ) tThis( i, j ) );
793 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i, j ) );
799 fprintf( tOutFile,
"...\n" );
803 fprintf( tOutFile,
"];\n" );
809#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_BZ_Matrix.hpp:280
size_t spacing() const
inter-column stride of the data container ( the leading dimension in BLAS terms; exceeds n_rows when ...
Definition cl_BZ_Matrix.hpp:267
Matrix< T > & operator+=(const T &aValue)
Definition cl_BZ_Matrix.hpp:595
auto submat(const size_t aFirstRow, const size_t aFirstCol, const size_t aLastRow, const size_t aLastCol) -> decltype(blaze::submatrix(mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol))
Definition cl_BZ_Matrix.hpp:405
void set_size(const size_t aNumRows, const size_t aNumCols, const T &aValue)
Definition cl_BZ_Matrix.hpp:224
virtual ~Matrix()=default
empty destructor
Matrix< T > & operator=(const blaze::DenseVector< VT, false > &aExpression)
Fill with column vector expression.
Definition cl_BZ_Matrix.hpp:559
auto col(const size_t aColIndex) -> decltype(mMatrix.col(aColIndex))
Definition cl_AR_Matrix.hpp:347
const MatrixType & matrix_data() const
Definition cl_BZ_Matrix.hpp:198
void fill(const T &aValue)
Definition cl_BZ_Matrix.hpp:208
auto row(const size_t aRowIndex) -> decltype(mMatrix.row(aRowIndex))
Definition cl_AR_Matrix.hpp:319
Matrix< T > & operator/=(const T &aValue)
Definition cl_BZ_Matrix.hpp:709
Matrix(const size_t aNumRows, const size_t aNumCols)
Constructor without fill value.
Definition cl_BZ_Matrix.hpp:56
Matrix< T > & operator=(const blaze::Matrix< MT, SO > &aExpression)
Fill with matrix expression.
Definition cl_BZ_Matrix.hpp:546
void set_row(const size_t aRowIndex, const Vector< T > &aVector)
Definition cl_BZ_Matrix.hpp:475
MatrixType & matrix_data()
Definition cl_BZ_Matrix.hpp:187
size_t capacity() const
length of data container
Definition cl_BZ_Matrix.hpp:254
Matrix< T > & operator-=(const T &aValue)
Definition cl_BZ_Matrix.hpp:627
Matrix(const MatrixType &aExpression)
Constructor from expression.
Definition cl_BZ_Matrix.hpp:87
auto row(const size_t aRowIndex) const -> decltype(blaze::row(mMatrix, aRowIndex))
Definition cl_BZ_Matrix.hpp:363
Matrix(const size_t aNumRows, const size_t aNumCols, const real aValue)
Constructor with fill value.
Definition cl_BZ_Matrix.hpp:65
void set_row(const size_t aRowIndex, const ET &aExpression)
Definition cl_BZ_Matrix.hpp:498
void set_size(const size_t aNumRows, const size_t aNumCols)
Definition cl_BZ_Matrix.hpp:216
size_t n_rows() const
Definition cl_BZ_Matrix.hpp:235
Matrix(const blaze::DenseVector< VT, true > &aExpression)
Constructor from row vector expression.
Definition cl_BZ_Matrix.hpp:122
void set_col(const size_t aColIndex, const Vector< T > &aVector)
Definition cl_BZ_Matrix.hpp:506
Matrix(const Matrix< T > &aMatrix)
copy constructor
Definition cl_BZ_Matrix.hpp:138
Matrix< T > & operator=(const Matrix< T > &aMatrix)
copy assignment operator
Definition cl_BZ_Matrix.hpp:293
T & operator()(const size_t aRowIndex, const size_t aColIndex)
access operator ( writable version )
Definition cl_BZ_Matrix.hpp:308
arma::Mat< T > MatrixType
Definition cl_AR_Matrix.hpp:34
auto col(const size_t aColIndex) const -> decltype(blaze::column(mMatrix, aColIndex))
Definition cl_BZ_Matrix.hpp:391
Matrix(const blaze::Matrix< MT, SO > &aExpression)
Constructor from matrix expression.
Definition cl_BZ_Matrix.hpp:96
Matrix< T > & operator=(const T &aValue)
Fill with value.
Definition cl_BZ_Matrix.hpp:533
Matrix< T > & operator-=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:636
Matrix()=default
empty constructor
virtual const T & operator()(const size_t aRowIndex, const size_t aColIndex) const
access operator ( const version )
Definition cl_BZ_Matrix.hpp:329
size_t n_cols() const
Definition cl_BZ_Matrix.hpp:243
Matrix(Matrix< T > &&aMatrix) noexcept
move constructor
Definition cl_BZ_Matrix.hpp:145
Matrix(const std::initializer_list< std::initializer_list< T > > &aInitList)
Constructor with initializer list.
Definition cl_BZ_Matrix.hpp:76
void set_col(const size_t aRowIndex, const ET &aExpression)
Definition cl_BZ_Matrix.hpp:520
Matrix(const blaze::DenseVector< VT, false > &aExpression)
Constructor from column vector expression.
Definition cl_BZ_Matrix.hpp:105
auto col(const size_t aColIndex) -> decltype(blaze::column(mMatrix, aColIndex))
Definition cl_BZ_Matrix.hpp:377
Matrix< T > & operator*=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:677
Matrix< T > & operator=(const blaze::DenseVector< VT, true > &aExpression)
Fill with row vector expression.
Definition cl_BZ_Matrix.hpp:578
auto submat(const size_t aFirstRow, const size_t aFirstCol, const size_t aLastRow, const size_t aLastCol) const -> decltype(blaze::submatrix(mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol))
Definition cl_BZ_Matrix.hpp:440
Matrix< T > & operator*=(const T &aValue)
Definition cl_BZ_Matrix.hpp:668
const T * data() const
Definition cl_BZ_Matrix.hpp:176
void print(const std::string aLabel="Matrix") const
auto row(const size_t aRowIndex) -> decltype(blaze::row(mMatrix, aRowIndex))
Definition cl_BZ_Matrix.hpp:349
T * data()
Definition cl_BZ_Matrix.hpp:165
Matrix< T > & operator+=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:604
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_AR_Vector.hpp:182
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30
double real
Definition typedefs.hpp:36