Blaze 3.9
DMatSerialExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATSERIALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATSERIALEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/math/Aliases.h>
53#include <blaze/util/Assert.h>
55#include <blaze/util/mpl/If.h>
56#include <blaze/util/Types.h>
57
58
59namespace blaze {
60
61//=================================================================================================
62//
63// CLASS DMATSERIALEXPR
64//
65//=================================================================================================
66
67//*************************************************************************************************
74template< typename MT // Type of the dense matrix
75 , bool SO > // Storage order
77 : public MatSerialExpr< DenseMatrix< DMatSerialExpr<MT,SO>, SO > >
78 , private Computation
79{
80 public:
81 //**Type definitions****************************************************************************
84
87
93
96
98 using Operand = If_t< IsExpression_v<MT>, const MT, const MT& >;
99 //**********************************************************************************************
100
101 //**Compilation flags***************************************************************************
103 static constexpr bool simdEnabled = false;
104
106 static constexpr bool smpAssignable = MT::smpAssignable;
107 //**********************************************************************************************
108
109 //**Constructor*********************************************************************************
114 explicit inline DMatSerialExpr( const MT& dm ) noexcept
115 : dm_( dm ) // Dense matrix of the serial evaluation expression
116 {}
117 //**********************************************************************************************
118
119 //**Access operator*****************************************************************************
126 inline ReturnType operator()( size_t i, size_t j ) const {
127 BLAZE_INTERNAL_ASSERT( i < dm_.rows() , "Invalid row access index" );
128 BLAZE_INTERNAL_ASSERT( j < dm_.columns(), "Invalid column access index" );
129 return dm_(i,j);
130 }
131 //**********************************************************************************************
132
133 //**At function*********************************************************************************
141 inline ReturnType at( size_t i, size_t j ) const {
142 if( i >= dm_.rows() ) {
143 BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
144 }
145 if( j >= dm_.columns() ) {
146 BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
147 }
148 return (*this)(i,j);
149 }
150 //**********************************************************************************************
151
152 //**Rows function*******************************************************************************
157 inline size_t rows() const noexcept {
158 return dm_.rows();
159 }
160 //**********************************************************************************************
161
162 //**Columns function****************************************************************************
167 inline size_t columns() const noexcept {
168 return dm_.columns();
169 }
170 //**********************************************************************************************
171
172 //**Operand access******************************************************************************
177 inline Operand operand() const noexcept {
178 return dm_;
179 }
180 //**********************************************************************************************
181
182 //**Conversion operator*************************************************************************
187 inline operator Operand() const noexcept {
188 return dm_;
189 }
190 //**********************************************************************************************
191
192 //**********************************************************************************************
198 template< typename T >
199 inline bool canAlias( const T* alias ) const noexcept {
200 return dm_.canAlias( alias );
201 }
202 //**********************************************************************************************
203
204 //**********************************************************************************************
210 template< typename T >
211 inline bool isAliased( const T* alias ) const noexcept {
212 return dm_.isAliased( alias );
213 }
214 //**********************************************************************************************
215
216 //**********************************************************************************************
221 inline bool isAligned() const noexcept {
222 return dm_.isAligned();
223 }
224 //**********************************************************************************************
225
226 //**********************************************************************************************
231 inline bool canSMPAssign() const noexcept {
232 return dm_.canSMPAssign();
233 }
234 //**********************************************************************************************
235
236 private:
237 //**Member variables****************************************************************************
239 //**********************************************************************************************
240
241 //**Assignment to dense matrices****************************************************************
253 template< typename MT2 // Type of the target dense matrix
254 , bool SO2 > // Storage order of the target dense matrix
255 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
256 {
258
259 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
260 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
261
262 assign( *lhs, rhs.dm_ );
263 }
265 //**********************************************************************************************
266
267 //**Assignment to sparse matrices***************************************************************
279 template< typename MT2 // Type of the target sparse matrix
280 , bool SO2 > // Storage order of the target dense matrix
281 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
282 {
284
285 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
286 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
287
288 assign( *lhs, rhs.dm_ );
289 }
291 //**********************************************************************************************
292
293 //**Addition assignment to dense matrices*******************************************************
305 template< typename MT2 // Type of the target dense matrix
306 , bool SO2 > // Storage order of the target dense matrix
307 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
308 {
310
311 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
312 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
313
314 addAssign( *lhs, rhs.dm_ );
315 }
317 //**********************************************************************************************
318
319 //**Addition assignment to sparse matrices******************************************************
331 template< typename MT2 // Type of the target sparse matrix
332 , bool SO2 > // Storage order of the target dense matrix
333 friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
334 {
336
337 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
338 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
339
340 addAssign( *lhs, rhs.dm_ );
341 }
343 //**********************************************************************************************
344
345 //**Subtraction assignment to dense matrices****************************************************
358 template< typename MT2 // Type of the target dense matrix
359 , bool SO2 > // Storage order of the target dense matrix
360 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
361 {
363
364 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
365 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
366
367 subAssign( *lhs, rhs.dm_ );
368 }
370 //**********************************************************************************************
371
372 //**Subtraction assignment to sparse matrices***************************************************
385 template< typename MT2 // Type of the target sparse matrix
386 , bool SO2 > // Storage order of the target dense matrix
387 friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
388 {
390
391 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
392 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
393
394 subAssign( *lhs, rhs.dm_ );
395 }
397 //**********************************************************************************************
398
399 //**Schur product assignment to dense matrices**************************************************
412 template< typename MT2 // Type of the target dense matrix
413 , bool SO2 > // Storage order of the target dense matrix
414 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
415 {
417
418 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
419 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
420
421 schurAssign( *lhs, rhs.dm_ );
422 }
424 //**********************************************************************************************
425
426 //**Schur product assignment to sparse matrices*************************************************
439 template< typename MT2 // Type of the target sparse matrix
440 , bool SO2 > // Storage order of the target dense matrix
441 friend inline void schurAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
442 {
444
445 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
446 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
447
448 schurAssign( *lhs, rhs.dm_ );
449 }
451 //**********************************************************************************************
452
453 //**Multiplication assignment to dense matrices*************************************************
466 template< typename MT2 // Type of the target dense matrix
467 , bool SO2 > // Storage order of the target dense matrix
468 friend inline void multAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
469 {
471
472 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
473 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
474
475 multAssign( *lhs, rhs.sm_ );
476 }
478 //**********************************************************************************************
479
480 //**Multiplication assignment to sparse matrices************************************************
493 template< typename MT2 // Type of the target sparse matrix
494 , bool SO2 > // Storage order of the target sparse matrix
495 friend inline void multAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
496 {
498
499 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
500 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
501
502 multAssign( *lhs, rhs.sm_ );
503 }
505 //**********************************************************************************************
506
507 //**SMP assignment to dense matrices************************************************************
519 template< typename MT2 // Type of the target dense matrix
520 , bool SO2 > // Storage order of the target dense matrix
521 friend inline void smpAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
522 {
524
525 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
526 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
527
528 assign( *lhs, rhs.dm_ );
529 }
531 //**********************************************************************************************
532
533 //**SMP assignment to sparse matrices***********************************************************
545 template< typename MT2 // Type of the target sparse matrix
546 , bool SO2 > // Storage order of the target dense matrix
547 friend inline void smpAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
548 {
550
551 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
552 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
553
554 assign( *lhs, rhs.dm_ );
555 }
557 //**********************************************************************************************
558
559 //**SMP addition assignment to dense matrices***************************************************
572 template< typename MT2 // Type of the target dense matrix
573 , bool SO2 > // Storage order of the target dense matrix
574 friend inline void smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
575 {
577
578 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
579 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
580
581 addAssign( *lhs, rhs.dm_ );
582 }
584 //**********************************************************************************************
585
586 //**SMP addition assignment to sparse matrices**************************************************
599 template< typename MT2 // Type of the target sparse matrix
600 , bool SO2 > // Storage order of the target dense matrix
601 friend inline void smpAddAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
602 {
604
605 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
606 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
607
608 addAssign( *lhs, rhs.dm_ );
609 }
611 //**********************************************************************************************
612
613 //**SMP subtraction assignment to dense matrices************************************************
626 template< typename MT2 // Type of the target dense matrix
627 , bool SO2 > // Storage order of the target dense matrix
628 friend inline void smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
629 {
631
632 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
633 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
634
635 subAssign( *lhs, rhs.dm_ );
636 }
638 //**********************************************************************************************
639
640 //**SMP subtraction assignment to sparse matrices***********************************************
653 template< typename MT2 // Type of the target sparse matrix
654 , bool SO2 > // Storage order of the target dense matrix
655 friend inline void smpSubAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
656 {
658
659 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
660 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
661
662 subAssign( *lhs, rhs.dm_ );
663 }
665 //**********************************************************************************************
666
667 //**SMP Schur product assignment to dense matrices**********************************************
680 template< typename MT2 // Type of the target dense matrix
681 , bool SO2 > // Storage order of the target dense matrix
682 friend inline void smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
683 {
685
686 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
687 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
688
689 schurAssign( *lhs, rhs.dm_ );
690 }
692 //**********************************************************************************************
693
694 //**SMP Schur product assignment to sparse matrices*********************************************
707 template< typename MT2 // Type of the target sparse matrix
708 , bool SO2 > // Storage order of the target dense matrix
709 friend inline void smpSchurAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
710 {
712
713 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
714 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
715
716 schurAssign( *lhs, rhs.dm_ );
717 }
719 //**********************************************************************************************
720
721 //**SMP multiplication assignment to dense matrices*********************************************
734 template< typename MT2 // Type of the target dense matrix
735 , bool SO2 > // Storage order of the target dense matrix
736 friend inline void smpMultAssign( DenseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
737 {
739
740 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
741 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
742
743 multAssign( *lhs, rhs.sm_ );
744 }
746 //**********************************************************************************************
747
748 //**SMP multiplication assignment to sparse matrices********************************************
761 template< typename MT2 // Type of the target sparse matrix
762 , bool SO2 > // Storage order of the target sparse matrix
763 friend inline void smpMultAssign( SparseMatrix<MT2,SO2>& lhs, const DMatSerialExpr& rhs )
764 {
766
767 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
768 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
769
770 multAssign( *lhs, rhs.sm_ );
771 }
773 //**********************************************************************************************
774
775 //**Compile time checks*************************************************************************
780 //**********************************************************************************************
781};
782//*************************************************************************************************
783
784
785
786
787//=================================================================================================
788//
789// GLOBAL FUNCTIONS
790//
791//=================================================================================================
792
793//*************************************************************************************************
810template< typename MT // Type of the dense matrix
811 , bool SO > // Storage order
812inline decltype(auto) serial( const DenseMatrix<MT,SO>& dm )
813{
815
816 using ReturnType = const DMatSerialExpr<MT,SO>;
817 return ReturnType( *dm );
818}
819//*************************************************************************************************
820
821
822
823
824//=================================================================================================
825//
826// ISALIGNED SPECIALIZATIONS
827//
828//=================================================================================================
829
830//*************************************************************************************************
832template< typename MT, bool SO >
833struct IsAligned< DMatSerialExpr<MT,SO> >
834 : public IsAligned<MT>
835{};
837//*************************************************************************************************
838
839} // namespace blaze
840
841#endif
Header file for auxiliary alias declarations.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::OppositeType OppositeType_t
Alias declaration for nested OppositeType type definitions.
Definition: Aliases.h:310
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the function trace functionality.
Header file for the If class template.
Header file for the IsAligned type trait.
Header file for the IsExpression type trait class.
Expression object for the forced serial evaluation of dense matrices.
Definition: DMatSerialExpr.h:79
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatSerialExpr.h:199
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatSerialExpr.h:98
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatSerialExpr.h:177
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatSerialExpr.h:141
DMatSerialExpr(const MT &dm) noexcept
Constructor for the DMatSerialExpr class.
Definition: DMatSerialExpr.h:114
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatSerialExpr.h:157
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatSerialExpr.h:90
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatSerialExpr.h:126
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatSerialExpr.h:88
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatSerialExpr.h:95
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatSerialExpr.h:92
Operand dm_
Dense matrix of the serial evaluation expression.
Definition: DMatSerialExpr.h:238
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatSerialExpr.h:89
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatSerialExpr.h:103
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatSerialExpr.h:231
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatSerialExpr.h:211
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatSerialExpr.h:221
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatSerialExpr.h:167
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatSerialExpr.h:106
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatSerialExpr.h:91
Base class for dense matrices.
Definition: DenseMatrix.h:82
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Header file for the Computation base class.
Header file for the DenseMatrix base class.
Header file for the MatSerialExpr base class.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: DenseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.
Definition: StorageOrder.h:63
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition: DenseVector.h:192
auto smpSchurAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP Schur product assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:194
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
typename If< Condition >::template Type< T1, T2 > If_t
Auxiliary alias template for the If class template.
Definition: If.h:108
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Constraints on the storage order of matrix types.
Header file for all forward declarations for expression class templates.
Base class for all compute expression templates.
Definition: Computation.h:68
Base class for all matrix serial evaluation expression templates.
Definition: MatSerialExpr.h:69
Header file for basic type definitions.