All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <cmath>
62 #include <blaze/util/Assert.h>
64 #include <blaze/util/EnableIf.h>
65 #include <blaze/util/InvalidType.h>
67 #include <blaze/util/SelectType.h>
68 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS DMATEVALEXPR
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
86 template< typename MT // Type of the dense matrix
87  , bool SO > // Storage order
88 class DMatEvalExpr : public DenseMatrix< DMatEvalExpr<MT,SO>, SO >
89  , private MatEvalExpr
90  , private Computation
91 {
92  public:
93  //**Type definitions****************************************************************************
95  typedef typename MT::ResultType ResultType;
96  typedef typename MT::OppositeType OppositeType;
97  typedef typename MT::TransposeType TransposeType;
98  typedef typename MT::ElementType ElementType;
99  typedef typename MT::ReturnType ReturnType;
100 
102  typedef const ResultType CompositeType;
103 
105  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
106  //**********************************************************************************************
107 
108  //**Compilation flags***************************************************************************
110  enum { vectorizable = 0 };
111 
113  enum { smpAssignable = MT::smpAssignable };
114  //**********************************************************************************************
115 
116  //**Constructor*********************************************************************************
121  explicit inline DMatEvalExpr( const MT& dm )
122  : dm_( dm ) // Dense matrix of the evaluation expression
123  {}
124  //**********************************************************************************************
125 
126  //**Access operator*****************************************************************************
133  inline ReturnType operator()( size_t i, size_t j ) const {
134  BLAZE_INTERNAL_ASSERT( i < dm_.rows() , "Invalid row access index" );
135  BLAZE_INTERNAL_ASSERT( j < dm_.columns(), "Invalid column access index" );
136  return dm_(i,j);
137  }
138  //**********************************************************************************************
139 
140  //**Rows function*******************************************************************************
145  inline size_t rows() const {
146  return dm_.rows();
147  }
148  //**********************************************************************************************
149 
150  //**Columns function****************************************************************************
155  inline size_t columns() const {
156  return dm_.columns();
157  }
158  //**********************************************************************************************
159 
160  //**Operand access******************************************************************************
165  inline Operand operand() const {
166  return dm_;
167  }
168  //**********************************************************************************************
169 
170  //**********************************************************************************************
176  template< typename T >
177  inline bool canAlias( const T* alias ) const {
178  return dm_.canAlias( alias );
179  }
180  //**********************************************************************************************
181 
182  //**********************************************************************************************
188  template< typename T >
189  inline bool isAliased( const T* alias ) const {
190  return dm_.isAliased( alias );
191  }
192  //**********************************************************************************************
193 
194  //**********************************************************************************************
199  inline bool isAligned() const {
200  return dm_.isAligned();
201  }
202  //**********************************************************************************************
203 
204  //**********************************************************************************************
209  inline bool canSMPAssign() const {
210  return dm_.canSMPAssign();
211  }
212  //**********************************************************************************************
213 
214  private:
215  //**Member variables****************************************************************************
217  //**********************************************************************************************
218 
219  //**Assignment to dense matrices****************************************************************
231  template< typename MT2 // Type of the target dense matrix
232  , bool SO2 > // Storage order of the target dense matrix
233  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
234  {
236 
237  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
238  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
239 
240  assign( ~lhs, rhs.dm_ );
241  }
243  //**********************************************************************************************
244 
245  //**Assignment to sparse matrices***************************************************************
257  template< typename MT2 // Type of the target sparse matrix
258  , bool SO2 > // Storage order of the target dense matrix
259  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
260  {
262 
263  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
264  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
265 
266  assign( ~lhs, rhs.dm_ );
267  }
269  //**********************************************************************************************
270 
271  //**Addition assignment to dense matrices*******************************************************
283  template< typename MT2 // Type of the target dense matrix
284  , bool SO2 > // Storage order of the target dense matrix
285  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
286  {
288 
289  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
290  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
291 
292  addAssign( ~lhs, rhs.dm_ );
293  }
295  //**********************************************************************************************
296 
297  //**Addition assignment to sparse matrices******************************************************
309  template< typename MT2 // Type of the target sparse matrix
310  , bool SO2 > // Storage order of the target dense matrix
311  friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
312  {
314 
315  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
316  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
317 
318  addAssign( ~lhs, rhs.dm_ );
319  }
321  //**********************************************************************************************
322 
323  //**Subtraction assignment to dense matrices****************************************************
335  template< typename MT2 // Type of the target dense matrix
336  , bool SO2 > // Storage order of the target dense matrix
337  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
338  {
340 
341  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
342  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
343 
344  subAssign( ~lhs, rhs.dm_ );
345  }
347  //**********************************************************************************************
348 
349  //**Subtraction assignment to sparse matrices***************************************************
361  template< typename MT2 // Type of the target sparse matrix
362  , bool SO2 > // Storage order of the target dense matrix
363  friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
364  {
366 
367  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
368  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
369 
370  subAssign( ~lhs, rhs.dm_ );
371  }
373  //**********************************************************************************************
374 
375  //**Multiplication assignment to dense matrices*************************************************
376  // No special implementation for the multiplication assignment to dense matrices.
377  //**********************************************************************************************
378 
379  //**Multiplication assignment to sparse matrices************************************************
380  // No special implementation for the multiplication assignment to sparse matrices.
381  //**********************************************************************************************
382 
383  //**SMP assignment to dense matrices************************************************************
395  template< typename MT2 // Type of the target dense matrix
396  , bool SO2 > // Storage order of the target dense matrix
397  friend inline void smpAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
398  {
400 
401  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
402  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
403 
404  smpAssign( ~lhs, rhs.dm_ );
405  }
407  //**********************************************************************************************
408 
409  //**SMP assignment to sparse matrices***********************************************************
421  template< typename MT2 // Type of the target sparse matrix
422  , bool SO2 > // Storage order of the target dense matrix
423  friend inline void smpAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
424  {
426 
427  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
428  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
429 
430  smpAssign( ~lhs, rhs.dm_ );
431  }
433  //**********************************************************************************************
434 
435  //**SMP addition assignment to dense matrices***************************************************
447  template< typename MT2 // Type of the target dense matrix
448  , bool SO2 > // Storage order of the target dense matrix
449  friend inline void smpAddAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
450  {
452 
453  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
454  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
455 
456  smpAddAssign( ~lhs, rhs.dm_ );
457  }
459  //**********************************************************************************************
460 
461  //**SMP addition assignment to sparse matrices**************************************************
473  template< typename MT2 // Type of the target sparse matrix
474  , bool SO2 > // Storage order of the target dense matrix
475  friend inline void smpAddAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
476  {
478 
479  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
480  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
481 
482  smpAddAssign( ~lhs, rhs.dm_ );
483  }
485  //**********************************************************************************************
486 
487  //**SMP subtraction assignment to dense matrices************************************************
499  template< typename MT2 // Type of the target dense matrix
500  , bool SO2 > // Storage order of the target dense matrix
501  friend inline void smpSubAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
502  {
504 
505  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
506  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
507 
508  smpSubAssign( ~lhs, rhs.dm_ );
509  }
511  //**********************************************************************************************
512 
513  //**SMP subtraction assignment to sparse matrices***********************************************
525  template< typename MT2 // Type of the target sparse matrix
526  , bool SO2 > // Storage order of the target dense matrix
527  friend inline void smpSubAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
528  {
530 
531  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
532  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
533 
534  smpSubAssign( ~lhs, rhs.dm_ );
535  }
537  //**********************************************************************************************
538 
539  //**Multiplication assignment to dense matrices*************************************************
540  // No special implementation for the multiplication assignment to dense matrices.
541  //**********************************************************************************************
542 
543  //**Multiplication assignment to sparse matrices************************************************
544  // No special implementation for the multiplication assignment to sparse matrices.
545  //**********************************************************************************************
546 
547  //**Compile time checks*************************************************************************
552  //**********************************************************************************************
553 };
554 //*************************************************************************************************
555 
556 
557 
558 
559 //=================================================================================================
560 //
561 // GLOBAL FUNCTIONS
562 //
563 //=================================================================================================
564 
565 //*************************************************************************************************
582 template< typename MT // Type of the dense matrix
583  , bool SO > // Storage order
584 inline const DMatEvalExpr<MT,SO> eval( const DenseMatrix<MT,SO>& dm )
585 {
587 
588  return DMatEvalExpr<MT,SO>( ~dm );
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // GLOBAL RESTRUCTURING FUNCTIONS
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
612 template< typename MT // Type of the dense matrix
613  , bool SO > // Storage order
614 inline const DMatEvalExpr<MT,SO> eval( const DMatEvalExpr<MT,SO>& dm )
615 {
616  return dm;
617 }
619 //*************************************************************************************************
620 
621 
622 
623 
624 //=================================================================================================
625 //
626 // EXPRESSION TRAIT SPECIALIZATIONS
627 //
628 //=================================================================================================
629 
630 //*************************************************************************************************
632 template< typename MT >
633 struct DMatEvalExprTrait< DMatEvalExpr<MT,false> >
634 {
635  public:
636  //**********************************************************************************************
637  typedef typename SelectType< IsDenseMatrix<MT>::value && IsRowMajorMatrix<MT>::value
638  , DMatEvalExpr<MT,false>
639  , INVALID_TYPE >::Type Type;
640  //**********************************************************************************************
641 };
643 //*************************************************************************************************
644 
645 
646 //*************************************************************************************************
648 template< typename MT >
649 struct TDMatEvalExprTrait< DMatEvalExpr<MT,true> >
650 {
651  public:
652  //**********************************************************************************************
653  typedef typename SelectType< IsDenseMatrix<MT>::value && IsColumnMajorMatrix<MT>::value
654  , DMatEvalExpr<MT,true>
655  , INVALID_TYPE >::Type Type;
656  //**********************************************************************************************
657 };
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
664 template< typename MT, bool SO, bool AF >
665 struct SubmatrixExprTrait< DMatEvalExpr<MT,SO>, AF >
666 {
667  public:
668  //**********************************************************************************************
669  typedef typename EvalExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type >::Type Type;
670  //**********************************************************************************************
671 };
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
678 template< typename MT, bool SO >
679 struct RowExprTrait< DMatEvalExpr<MT,SO> >
680 {
681  public:
682  //**********************************************************************************************
683  typedef typename EvalExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
684  //**********************************************************************************************
685 };
687 //*************************************************************************************************
688 
689 
690 //*************************************************************************************************
692 template< typename MT, bool SO >
693 struct ColumnExprTrait< DMatEvalExpr<MT,SO> >
694 {
695  public:
696  //**********************************************************************************************
697  typedef typename EvalExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
698  //**********************************************************************************************
699 };
701 //*************************************************************************************************
702 
703 } // namespace blaze
704 
705 #endif
Header file for the DMatEvalExprTrait class template.
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:242
size_t rows() const
Returns the current number of rows of the matrix.
Definition: DMatEvalExpr.h:145
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
Header file for the ColumnExprTrait class template.
Header file for the IsColumnMajorMatrix type trait.
Header file for the sparse matrix SMP implementation.
Header file for the MatEvalExpr base class.
Header file for the Computation base class.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2380
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
Operand operand() const
Returns the dense matrix operand.
Definition: DMatEvalExpr.h:165
Constraint on the data type.
void smpAddAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:121
DMatEvalExpr< MT, SO > This
Type of this DMatEvalExpr instance.
Definition: DMatEvalExpr.h:94
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: DMatEvalExpr.h:105
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
DMatEvalExpr(const MT &dm)
Constructor for the DMatEvalExpr class.
Definition: DMatEvalExpr.h:121
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: DMatEvalExpr.h:199
Header file for the dense matrix SMP implementation.
Header file for the DenseMatrix base class.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
MT::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: DMatEvalExpr.h:96
const ResultType CompositeType
Data type for composite expression templates.
Definition: DMatEvalExpr.h:102
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Constraints on the storage order of matrix types.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DMatEvalExpr.h:177
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Header file for the IsDenseMatrix type trait.
Header file for the EnableIf class template.
Operand dm_
Dense matrix of the evaluation expression.
Definition: DMatEvalExpr.h:216
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DMatEvalExpr.h:99
MT::ElementType ElementType
Resulting element type.
Definition: DMatEvalExpr.h:98
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Header file for run time assertion macros.
Utility type for generic codes.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the EvalExprTrait class template.
Base class for all matrix evaluation expression templates.The MatEvalExpr class serves as a tag for a...
Definition: MatEvalExpr.h:65
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DMatEvalExpr.h:189
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:584
Header file for the IsRowMajorMatrix type trait.
MT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DMatEvalExpr.h:97
Expression object for the forced evaluation of dense matrices.The DMatEvalExpr class represents the c...
Definition: DMatEvalExpr.h:88
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DMatEvalExpr.h:209
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
Header file for the TDMatEvalExprTrait class template.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
Header file for basic type definitions.
size_t columns() const
Returns the current number of columns of the matrix.
Definition: DMatEvalExpr.h:155
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: DMatEvalExpr.h:133
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
MT::ResultType ResultType
Result type for expression template evaluations.
Definition: DMatEvalExpr.h:95
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.