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;
51 const size_t aNumCols ) :
52 mMatrix( aNumRows, aNumCols ) {}
57 const size_t aNumCols,
59 mMatrix( aNumRows, aNumCols, aValue )
64 Matrix(
const std::initializer_list<std::initializer_list<T> > & aInitList )
65 : mMatrix( aInitList )
73 : mMatrix( aExpression ) {}
80 template<
typename MT,
bool SO >
81 Matrix(
const blaze::Matrix< MT, SO > & aExpression )
82 : mMatrix( aExpression ) {}
89 template<
typename VT >
90 Matrix(
const blaze::DenseVector< VT, false > & aExpression )
92 const VT & tVector =
static_cast< const VT&
>( aExpression );
93 mMatrix.resize( tVector.size(), 1UL,
false );
95 for (
size_t k = 0; k < tVector.size(); ++k )
97 mMatrix( k, 0 ) = tVector[ k ];
106 template<
typename VT >
107 Matrix(
const blaze::DenseVector< VT, true > & aExpression )
109 const VT & tVector =
static_cast< const VT&
>( aExpression );
110 mMatrix.resize( 1UL, tVector.size(),
false );
112 for (
size_t k = 0; k < tVector.size(); ++k )
114 mMatrix( 0, k ) = tVector[ k ];
124 mMatrix( aMatrix.mMatrix )
131 mMatrix( std::move( aMatrix.mMatrix ) )
151 return mMatrix.data();
159 return mMatrix.data();
197 set_size(
const size_t aNumRows,
const size_t aNumCols )
199 mMatrix.resize( aNumRows, aNumCols,
false );
205 set_size(
const size_t aNumRows,
const size_t aNumCols,
const T & aValue )
207 this->
set_size( aNumRows, aNumCols );
208 this->
fill( aValue );
218 return mMatrix.rows();
226 return mMatrix.columns();
237 return mMatrix.capacity();
250 return mMatrix.spacing();
263 if (
this != & aMatrix )
265 mMatrix = std::move( aMatrix.mMatrix );
276 if (
this != &aMatrix )
278 mMatrix = aMatrix.mMatrix;
292 "Row index %lu out of bounds, which must be smaller than %lu.",
293 (
long unsigned int ) aRowIndex,
294 (
long unsigned int ) this->
n_rows() );
297 "Col index %lu out of bounds, which must be smaller than %lu.",
298 (
long unsigned int ) aColIndex,
299 (
long unsigned int ) this->
n_cols() );
301 return mMatrix( aRowIndex, aColIndex );
309 virtual inline const T &
310 operator()(
const size_t aRowIndex,
const size_t aColIndex )
const
313 "Row index %lu out of bounds, which must be smaller than %lu.",
314 (
long unsigned int ) aRowIndex,
315 (
long unsigned int ) this->
n_rows() );
318 "Col index %lu out of bounds, which must be smaller than %lu.",
319 (
long unsigned int ) aColIndex,
320 (
long unsigned int ) this->
n_cols() );
322 return mMatrix( aRowIndex, aColIndex );
330 row(
const size_t aRowIndex )
331 ->decltype( blaze::row( mMatrix, aRowIndex ) )
334 "Row index %lu out of bounds, which must be less than %lu.",
335 (
long unsigned int ) aRowIndex,
336 (
long unsigned int ) this->
n_rows() );
338 return blaze::row( mMatrix, aRowIndex );
344 row(
const size_t aRowIndex )
const
345 ->decltype( blaze::row( mMatrix, aRowIndex ) )
348 "Row index %lu out of bounds, which must be less than %lu.",
349 (
long unsigned int ) aRowIndex,
350 (
long unsigned int ) this->
n_rows() );
352 return blaze::row( mMatrix, aRowIndex );
358 col(
const size_t aColIndex )
359 ->decltype( blaze::column( mMatrix, aColIndex ) )
362 "Col index %lu out of bounds, which must be less than %lu.",
363 (
long unsigned int ) aColIndex,
364 (
long unsigned int ) this->
n_cols() );
366 return blaze::column( mMatrix, aColIndex );
372 col(
const size_t aColIndex )
const
373 ->decltype( blaze::column( mMatrix, aColIndex ) )
376 "Col index %lu out of bounds, which must be less than %lu.",
377 (
long unsigned int ) aColIndex,
378 (
long unsigned int ) this->
n_cols() );
380 return blaze::column( mMatrix, aColIndex );
387 const size_t aFirstCol,
388 const size_t aLastRow,
389 const size_t aLastCol )
390 ->
decltype( blaze::submatrix( mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol ) )
393 "First row index %lu out of bounds, which must be less than %lu.",
394 (
long unsigned int ) aFirstRow,
395 (
long unsigned int ) this->
n_rows() );
398 "Last row index %lu out of bounds, which must be less than %lu.",
399 (
long unsigned int ) aLastRow,
400 (
long unsigned int ) this->
n_rows() );
403 "First col index %lu out of bounds, which must be less than %lu.",
404 (
long unsigned int ) aFirstCol,
405 (
long unsigned int ) this->
n_cols() );
408 "Last col index %lu out of bounds, which must be less than %lu.",
409 (
long unsigned int ) aLastCol,
410 (
long unsigned int ) this->
n_cols() );
414 return blaze::submatrix( mMatrix, aFirstRow, aFirstCol,
415 aLastRow - aFirstRow + 1, aLastCol - aFirstCol + 1 );
422 const size_t aFirstCol,
423 const size_t aLastRow,
424 const size_t aLastCol )
const
425 ->
decltype( blaze::submatrix( mMatrix, aFirstRow, aFirstCol, aLastRow, aLastCol ) )
428 "First row index %lu out of bounds, which must be less than %lu.",
429 (
long unsigned int ) aFirstRow,
430 (
long unsigned int ) this->
n_rows() );
433 "Last row index %lu out of bounds, which must be less than %lu.",
434 (
long unsigned int ) aLastRow,
435 (
long unsigned int ) this->
n_rows() );
438 "First col index %lu out of bounds, which must be less than %lu.",
439 (
long unsigned int ) aFirstCol,
440 (
long unsigned int ) this->
n_cols() );
443 "Last col index %lu out of bounds, which must be less than %lu.",
444 (
long unsigned int ) aLastCol,
445 (
long unsigned int ) this->
n_cols() );
449 return blaze::submatrix( mMatrix, aFirstRow, aFirstCol,
450 aLastRow - aFirstRow + 1, aLastCol - aFirstCol + 1 );
456 set_row(
const size_t aRowIndex,
const Vector <T> & aVector )
461 "Wrong length of vector : %lu ( expect %lu )",
462 (
long unsigned int ) aVector.
length(),
463 (
long unsigned int ) this->n_cols() );
466 const T * tSource = aVector.
data();
469 for( std::size_t k=0; k<aVector.
length(); ++k )
471 mMatrix( aRowIndex, k ) = tSource[ k ];
477 template <
typename ET >
479 set_row(
const size_t aRowIndex,
const ET & aExpression )
481 this->
row( aRowIndex ) = aExpression;
487 set_col(
const size_t aColIndex,
const Vector <T> & aVector )
491 "Wrong length of vector : %lu ( expect %lu )",
492 (
long unsigned int ) aVector.
length(),
493 (
long unsigned int ) this->n_rows() );
496 this->col( aColIndex ).data() );
499 template <
typename ET >
501 set_col(
const size_t aRowIndex,
const ET & aExpression )
503 this->
col( aRowIndex ) = aExpression;
516 this->
fill( aValue );
525 template <
typename MT,
bool SO >
527 operator=(
const blaze::Matrix< MT, SO > & aExpression )
529 mMatrix = aExpression;
538 template <
typename VT >
540 operator=(
const blaze::DenseVector< VT, false > & aExpression )
542 const VT & tVector =
static_cast< const VT&
>( aExpression );
543 mMatrix.resize( tVector.size(), 1UL,
false );
545 for (
size_t k = 0; k < tVector.size(); ++k )
547 mMatrix( k, 0 ) = tVector[ k ];
557 template <
typename VT >
559 operator=(
const blaze::DenseVector< VT, true > & aExpression )
561 const VT & tVector =
static_cast< const VT&
>( aExpression );
562 mMatrix.resize( 1UL, tVector.size(),
false );
564 for (
size_t k = 0; k < tVector.size(); ++k )
566 mMatrix( 0, k ) = tVector[ k ];
594 template <
typename MT,
bool SO >
596 operator+=(
const blaze::Matrix< MT, SO > & aExpression )
598 mMatrix += aExpression;
626 template <
typename MT,
bool SO >
628 operator-=(
const blaze::Matrix< MT, SO > & aExpression )
630 mMatrix -= aExpression;
639 mMatrix -= aExpression;
667 template <
typename MT,
bool SO >
669 operator*=(
const blaze::Matrix< MT, SO > & aExpression )
671 mMatrix *= aExpression;
680 mMatrix *= aExpression;
701 print(
const std::string aLabel=
"Matrix" )
const;
708#pragma GCC diagnostic push
709#pragma GCC diagnostic ignored "-Wformat"
711 template <
typename T >
void
714 FILE * tOutFile = stdout;
716 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
724 for(
uint i=0; i< tRows; ++i )
726 for(
uint j=0; j< tCols; ++j )
730 fprintf( tOutFile,
"%d, ", (
int ) tThis( i, j ) );
734 fprintf( tOutFile,
"%d; ", (
int ) tThis( i, j ) );
740 fprintf( tOutFile,
"...\n" );
744 fprintf( tOutFile,
"];\n" );
755 FILE * tOutFile = stdout;
757 fprintf( tOutFile,
"%s = [ ... \n", aLabel.c_str() );
764 for(
uint i=0; i< tRows; ++i )
766 for(
uint j=0; j< tCols; ++j )
770 fprintf( tOutFile,
"%+.15e, ", (
double ) tThis( i, j ) );
774 fprintf( tOutFile,
"%+.15e; ", (
double ) tThis( i, j ) );
780 fprintf( tOutFile,
"...\n" );
784 fprintf( tOutFile,
"];\n" );
790#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:261
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:248
Matrix< T > & operator+=(const T &aValue)
Definition cl_BZ_Matrix.hpp:576
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:386
void set_size(const size_t aNumRows, const size_t aNumCols, const T &aValue)
Definition cl_BZ_Matrix.hpp:205
virtual ~Matrix()=default
empty destructor
Matrix< T > & operator=(const blaze::DenseVector< VT, false > &aExpression)
Fill with column vector expression.
Definition cl_BZ_Matrix.hpp:540
auto col(const size_t aColIndex) -> decltype(mMatrix.col(aColIndex))
Definition cl_AR_Matrix.hpp:325
const MatrixType & matrix_data() const
Definition cl_BZ_Matrix.hpp:179
void fill(const T &aValue)
Definition cl_BZ_Matrix.hpp:189
auto row(const size_t aRowIndex) -> decltype(mMatrix.row(aRowIndex))
Definition cl_AR_Matrix.hpp:297
Matrix< T > & operator/=(const T &aValue)
Definition cl_BZ_Matrix.hpp:690
Matrix(const size_t aNumRows, const size_t aNumCols)
Definition cl_BZ_Matrix.hpp:50
Matrix< T > & operator=(const blaze::Matrix< MT, SO > &aExpression)
Fill with matrix expression.
Definition cl_BZ_Matrix.hpp:527
void set_row(const size_t aRowIndex, const Vector< T > &aVector)
Definition cl_BZ_Matrix.hpp:456
MatrixType & matrix_data()
Definition cl_BZ_Matrix.hpp:168
size_t capacity() const
The allocated element count, which may exceed spacing() * n_cols() after a resize shrinks the matrix.
Definition cl_BZ_Matrix.hpp:235
Matrix< T > & operator-=(const T &aValue)
Definition cl_BZ_Matrix.hpp:608
Matrix(const MatrixType &aExpression)
Definition cl_BZ_Matrix.hpp:72
auto row(const size_t aRowIndex) const -> decltype(blaze::row(mMatrix, aRowIndex))
Definition cl_BZ_Matrix.hpp:344
void set_row(const size_t aRowIndex, const ET &aExpression)
Definition cl_BZ_Matrix.hpp:479
void set_size(const size_t aNumRows, const size_t aNumCols)
Definition cl_BZ_Matrix.hpp:197
size_t n_rows() const
Definition cl_BZ_Matrix.hpp:216
Matrix(const blaze::DenseVector< VT, true > &aExpression)
Constructor from row vector expression.
Definition cl_BZ_Matrix.hpp:107
void set_col(const size_t aColIndex, const Vector< T > &aVector)
Definition cl_BZ_Matrix.hpp:487
Matrix(const Matrix< T > &aMatrix)
copy constructor
Definition cl_BZ_Matrix.hpp:123
Matrix< T > & operator=(const Matrix< T > &aMatrix)
copy assignment operator
Definition cl_BZ_Matrix.hpp:274
T & operator()(const size_t aRowIndex, const size_t aColIndex)
access operator ( writable version )
Definition cl_BZ_Matrix.hpp:289
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:372
Matrix(const blaze::Matrix< MT, SO > &aExpression)
Constructor from matrix expression.
Definition cl_BZ_Matrix.hpp:81
Matrix< T > & operator=(const T &aValue)
Fill with value.
Definition cl_BZ_Matrix.hpp:514
Matrix< T > & operator-=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:617
virtual const T & operator()(const size_t aRowIndex, const size_t aColIndex) const
access operator ( const version )
Definition cl_BZ_Matrix.hpp:310
size_t n_cols() const
Definition cl_BZ_Matrix.hpp:224
Matrix(Matrix< T > &&aMatrix) noexcept
move constructor
Definition cl_BZ_Matrix.hpp:130
Matrix(const std::initializer_list< std::initializer_list< T > > &aInitList)
Definition cl_BZ_Matrix.hpp:64
void set_col(const size_t aRowIndex, const ET &aExpression)
Definition cl_BZ_Matrix.hpp:501
Matrix(const blaze::DenseVector< VT, false > &aExpression)
Constructor from column vector expression.
Definition cl_BZ_Matrix.hpp:90
auto col(const size_t aColIndex) -> decltype(blaze::column(mMatrix, aColIndex))
Definition cl_BZ_Matrix.hpp:358
Matrix< T > & operator*=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:658
Matrix< T > & operator=(const blaze::DenseVector< VT, true > &aExpression)
Fill with row vector expression.
Definition cl_BZ_Matrix.hpp:559
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:421
Matrix< T > & operator*=(const T &aValue)
Definition cl_BZ_Matrix.hpp:649
const T * data() const
Definition cl_BZ_Matrix.hpp:157
void print(const std::string aLabel="Matrix") const
auto row(const size_t aRowIndex) -> decltype(blaze::row(mMatrix, aRowIndex))
Definition cl_BZ_Matrix.hpp:330
Matrix(const size_t aNumRows, const size_t aNumCols, const T aValue)
Definition cl_BZ_Matrix.hpp:56
T * data()
Returns a borrowed raw buffer under the layout contract stated in cl_Matrix.hpp; may be nullptr when ...
Definition cl_BZ_Matrix.hpp:149
Matrix< T > & operator+=(const Matrix< T > &aMatrix)
Definition cl_BZ_Matrix.hpp:585
T * data()
Returns a borrowed raw buffer under the layout contract stated in cl_Vector.hpp; may be nullptr when ...
Definition cl_AR_Vector.hpp:163
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:235
USER GUIDES:
Definition cl_Capacitor.cpp:16
unsigned int uint
Definition typedefs.hpp:30