Blaze 3.9
DMatEvalExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATEVALEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATEVALEXPR_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 DMATEVALEXPR
64//
65//=================================================================================================
66
67//*************************************************************************************************
74template< typename MT // Type of the dense matrix
75 , bool SO > // Storage order
77 : public MatEvalExpr< DenseMatrix< DMatEvalExpr<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 DMatEvalExpr( const MT& dm ) noexcept
115 : dm_( dm ) // Dense matrix of the 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 //**********************************************************************************************
188 template< typename T >
189 inline bool canAlias( const T* alias ) const noexcept {
190 return dm_.canAlias( alias );
191 }
192 //**********************************************************************************************
193
194 //**********************************************************************************************
200 template< typename T >
201 inline bool isAliased( const T* alias ) const noexcept {
202 return dm_.isAliased( alias );
203 }
204 //**********************************************************************************************
205
206 //**********************************************************************************************
211 inline bool isAligned() const noexcept {
212 return dm_.isAligned();
213 }
214 //**********************************************************************************************
215
216 //**********************************************************************************************
221 inline bool canSMPAssign() const noexcept {
222 return dm_.canSMPAssign();
223 }
224 //**********************************************************************************************
225
226 private:
227 //**Member variables****************************************************************************
229 //**********************************************************************************************
230
231 //**Assignment to dense matrices****************************************************************
243 template< typename MT2 // Type of the target dense matrix
244 , bool SO2 > // Storage order of the target dense matrix
245 friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
246 {
248
249 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
250 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
251
252 assign( *lhs, rhs.dm_ );
253 }
255 //**********************************************************************************************
256
257 //**Assignment to sparse matrices***************************************************************
269 template< typename MT2 // Type of the target sparse matrix
270 , bool SO2 > // Storage order of the target dense matrix
271 friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
272 {
274
275 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
276 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
277
278 assign( *lhs, rhs.dm_ );
279 }
281 //**********************************************************************************************
282
283 //**Addition assignment to dense matrices*******************************************************
295 template< typename MT2 // Type of the target dense matrix
296 , bool SO2 > // Storage order of the target dense matrix
297 friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
298 {
300
301 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
302 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
303
304 addAssign( *lhs, rhs.dm_ );
305 }
307 //**********************************************************************************************
308
309 //**Addition assignment to sparse matrices******************************************************
321 template< typename MT2 // Type of the target sparse matrix
322 , bool SO2 > // Storage order of the target dense matrix
323 friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
324 {
326
327 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
328 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
329
330 addAssign( *lhs, rhs.dm_ );
331 }
333 //**********************************************************************************************
334
335 //**Subtraction assignment to dense matrices****************************************************
347 template< typename MT2 // Type of the target dense matrix
348 , bool SO2 > // Storage order of the target dense matrix
349 friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
350 {
352
353 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
354 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
355
356 subAssign( *lhs, rhs.dm_ );
357 }
359 //**********************************************************************************************
360
361 //**Subtraction assignment to sparse matrices***************************************************
373 template< typename MT2 // Type of the target sparse matrix
374 , bool SO2 > // Storage order of the target dense matrix
375 friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
376 {
378
379 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
380 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
381
382 subAssign( *lhs, rhs.dm_ );
383 }
385 //**********************************************************************************************
386
387 //**Schur product assignment to dense matrices**************************************************
399 template< typename MT2 // Type of the target dense matrix
400 , bool SO2 > // Storage order of the target dense matrix
401 friend inline void schurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
402 {
404
405 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
406 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
407
408 schurAssign( *lhs, rhs.dm_ );
409 }
411 //**********************************************************************************************
412
413 //**Schur product assignment to sparse matrices*************************************************
425 template< typename MT2 // Type of the target sparse matrix
426 , bool SO2 > // Storage order of the target dense matrix
427 friend inline void schurAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
428 {
430
431 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
432 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
433
434 schurAssign( *lhs, rhs.dm_ );
435 }
437 //**********************************************************************************************
438
439 //**Multiplication assignment to dense matrices*************************************************
451 template< typename MT2 // Type of the target dense matrix
452 , bool SO2 > // Storage order of the target dense matrix
453 friend inline void multAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
454 {
456
457 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
458 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
459
460 multAssign( *lhs, rhs.dm_ );
461 }
463 //**********************************************************************************************
464
465 //**Multiplication assignment to sparse matrices************************************************
477 template< typename MT2 // Type of the target sparse matrix
478 , bool SO2 > // Storage order of the target dense matrix
479 friend inline void multAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
480 {
482
483 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
484 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
485
486 multAssign( *lhs, rhs.dm_ );
487 }
489 //**********************************************************************************************
490
491 //**SMP assignment to dense matrices************************************************************
503 template< typename MT2 // Type of the target dense matrix
504 , bool SO2 > // Storage order of the target dense matrix
505 friend inline void smpAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
506 {
508
509 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
510 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
511
512 smpAssign( *lhs, rhs.dm_ );
513 }
515 //**********************************************************************************************
516
517 //**SMP assignment to sparse matrices***********************************************************
529 template< typename MT2 // Type of the target sparse matrix
530 , bool SO2 > // Storage order of the target dense matrix
531 friend inline void smpAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
532 {
534
535 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
536 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
537
538 smpAssign( *lhs, rhs.dm_ );
539 }
541 //**********************************************************************************************
542
543 //**SMP addition assignment to dense matrices***************************************************
555 template< typename MT2 // Type of the target dense matrix
556 , bool SO2 > // Storage order of the target dense matrix
557 friend inline void smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
558 {
560
561 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
562 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
563
564 smpAddAssign( *lhs, rhs.dm_ );
565 }
567 //**********************************************************************************************
568
569 //**SMP addition assignment to sparse matrices**************************************************
581 template< typename MT2 // Type of the target sparse matrix
582 , bool SO2 > // Storage order of the target dense matrix
583 friend inline void smpAddAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
584 {
586
587 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
588 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
589
590 smpAddAssign( *lhs, rhs.dm_ );
591 }
593 //**********************************************************************************************
594
595 //**SMP subtraction assignment to dense matrices************************************************
607 template< typename MT2 // Type of the target dense matrix
608 , bool SO2 > // Storage order of the target dense matrix
609 friend inline void smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
610 {
612
613 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
614 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
615
616 smpSubAssign( *lhs, rhs.dm_ );
617 }
619 //**********************************************************************************************
620
621 //**SMP subtraction assignment to sparse matrices***********************************************
633 template< typename MT2 // Type of the target sparse matrix
634 , bool SO2 > // Storage order of the target dense matrix
635 friend inline void smpSubAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
636 {
638
639 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
640 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
641
642 smpSubAssign( *lhs, rhs.dm_ );
643 }
645 //**********************************************************************************************
646
647 //**SMP Schur product assignment to dense matrices**********************************************
659 template< typename MT2 // Type of the target dense matrix
660 , bool SO2 > // Storage order of the target dense matrix
661 friend inline void smpSchurAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
662 {
664
665 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
666 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
667
668 smpSchurAssign( *lhs, rhs.dm_ );
669 }
671 //**********************************************************************************************
672
673 //**SMP Schur product assignment to sparse matrices*********************************************
685 template< typename MT2 // Type of the target sparse matrix
686 , bool SO2 > // Storage order of the target dense matrix
687 friend inline void smpSchurAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
688 {
690
691 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
692 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
693
694 smpSchurAssign( *lhs, rhs.dm_ );
695 }
697 //**********************************************************************************************
698
699 //**SMP multiplication assignment to dense matrices*********************************************
712 template< typename MT2 // Type of the target dense matrix
713 , bool SO2 > // Storage order of the target dense matrix
714 friend inline void smpMultAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
715 {
717
718 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
719 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
720
721 smpMultAssign( *lhs, rhs.dm_ );
722 }
724 //**********************************************************************************************
725
726 //**SMP multiplication assignment to sparse matrices********************************************
739 template< typename MT2 // Type of the target sparse matrix
740 , bool SO2 > // Storage order of the target dense matrix
741 friend inline void smpMultAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
742 {
744
745 BLAZE_INTERNAL_ASSERT( (*lhs).rows() == rhs.rows() , "Invalid number of rows" );
746 BLAZE_INTERNAL_ASSERT( (*lhs).columns() == rhs.columns(), "Invalid number of columns" );
747
748 smpMultAssign( *lhs, rhs.dm_ );
749 }
751 //**********************************************************************************************
752
753 //**Compile time checks*************************************************************************
758 //**********************************************************************************************
759};
760//*************************************************************************************************
761
762
763
764
765//=================================================================================================
766//
767// GLOBAL FUNCTIONS
768//
769//=================================================================================================
770
771//*************************************************************************************************
788template< typename MT // Type of the dense matrix
789 , bool SO > // Storage order
790inline decltype(auto) eval( const DenseMatrix<MT,SO>& dm )
791{
793
794 using ReturnType = const DMatEvalExpr<MT,SO>;
795 return ReturnType( *dm );
796}
797//*************************************************************************************************
798
799
800
801
802//=================================================================================================
803//
804// ISALIGNED SPECIALIZATIONS
805//
806//=================================================================================================
807
808//*************************************************************************************************
810template< typename MT, bool SO >
811struct IsAligned< DMatEvalExpr<MT,SO> >
812 : public IsAligned<MT>
813{};
815//*************************************************************************************************
816
817} // namespace blaze
818
819#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 evaluation of dense matrices.
Definition: DMatEvalExpr.h:79
ElementType_t< MT > ElementType
Resulting element type.
Definition: DMatEvalExpr.h:91
ReturnType at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: DMatEvalExpr.h:141
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatEvalExpr.h:211
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: DMatEvalExpr.h:92
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DMatEvalExpr.h:103
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatEvalExpr.h:95
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatEvalExpr.h:126
Operand operand() const noexcept
Returns the dense matrix operand.
Definition: DMatEvalExpr.h:177
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DMatEvalExpr.h:201
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DMatEvalExpr.h:189
TransposeType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: DMatEvalExpr.h:90
DMatEvalExpr(const MT &dm) noexcept
Constructor for the DMatEvalExpr class.
Definition: DMatEvalExpr.h:114
If_t< IsExpression_v< MT >, const MT, const MT & > Operand
Composite data type of the dense matrix expression.
Definition: DMatEvalExpr.h:98
OppositeType_t< MT > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatEvalExpr.h:89
Operand dm_
Dense matrix of the evaluation expression.
Definition: DMatEvalExpr.h:228
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DMatEvalExpr.h:157
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DMatEvalExpr.h:221
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DMatEvalExpr.h:167
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DMatEvalExpr.h:106
ResultType_t< MT > ResultType
Result type for expression template evaluations.
Definition: DMatEvalExpr.h:88
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 MatEvalExpr base class.
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:790
#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 evaluation expression templates.
Definition: MatEvalExpr.h:69
Header file for basic type definitions.