All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMatEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATEVALEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_DMATEVALEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <cmath>
38 #include <blaze/util/Assert.h>
40 #include <blaze/util/EnableIf.h>
41 #include <blaze/util/SelectType.h>
42 #include <blaze/util/Types.h>
43 
44 
45 namespace blaze {
46 
47 //=================================================================================================
48 //
49 // CLASS DMATEVALEXPR
50 //
51 //=================================================================================================
52 
53 //*************************************************************************************************
60 template< typename MT // Type of the dense matrix
61  , bool SO > // Storage order
62 class DMatEvalExpr : public DenseMatrix< DMatEvalExpr<MT,SO>, SO >
63  , private Expression
64  , private Computation
65 {
66  public:
67  //**Type definitions****************************************************************************
69  typedef typename MT::ResultType ResultType;
70  typedef typename MT::OppositeType OppositeType;
71  typedef typename MT::TransposeType TransposeType;
72  typedef typename MT::ElementType ElementType;
73  typedef typename MT::ReturnType ReturnType;
74 
76  typedef const ResultType CompositeType;
77 
79  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
80  //**********************************************************************************************
81 
82  //**Compilation flags***************************************************************************
84  enum { vectorizable = 0 };
85 
87  enum { canAlias = CanAlias<MT>::value };
88  //**********************************************************************************************
89 
90  //**Constructor*********************************************************************************
95  explicit inline DMatEvalExpr( const MT& dm )
96  : dm_( dm ) // Dense matrix of the evaluation expression
97  {}
98  //**********************************************************************************************
99 
100  //**Access operator*****************************************************************************
107  inline ReturnType operator()( size_t i, size_t j ) const {
108  BLAZE_INTERNAL_ASSERT( i < dm_.rows() , "Invalid row access index" );
109  BLAZE_INTERNAL_ASSERT( j < dm_.columns(), "Invalid column access index" );
110  return dm_(i,j);
111  }
112  //**********************************************************************************************
113 
114  //**Rows function*******************************************************************************
119  inline size_t rows() const {
120  return dm_.rows();
121  }
122  //**********************************************************************************************
123 
124  //**Columns function****************************************************************************
129  inline size_t columns() const {
130  return dm_.columns();
131  }
132  //**********************************************************************************************
133 
134  //**Operand access******************************************************************************
139  inline Operand operand() const {
140  return dm_;
141  }
142  //**********************************************************************************************
143 
144  //**********************************************************************************************
150  template< typename T >
151  inline bool isAliased( const T* alias ) const {
152  return CanAlias<MT>::value && dm_.isAliased( alias );
153  }
154  //**********************************************************************************************
155 
156  private:
157  //**Member variables****************************************************************************
159  //**********************************************************************************************
160 
161  //**Assignment to dense matrices****************************************************************
173  template< typename MT2 // Type of the target dense matrix
174  , bool SO2 > // Storage order of the target dense matrix
175  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
176  {
177  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
178  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
179 
180  assign( ~lhs, rhs.dm_ );
181  }
183  //**********************************************************************************************
184 
185  //**Assignment to sparse matrices***************************************************************
197  template< typename MT2 // Type of the target sparse matrix
198  , bool SO2 > // Storage order of the target dense matrix
199  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
200  {
201  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
202  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
203 
204  assign( ~lhs, rhs.dm_ );
205  }
207  //**********************************************************************************************
208 
209  //**Addition assignment to dense matrices*******************************************************
221  template< typename MT2 // Type of the target dense matrix
222  , bool SO2 > // Storage order of the target dense matrix
223  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
224  {
225  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
226  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
227 
228  addAssign( ~lhs, rhs.dm_ );
229  }
231  //**********************************************************************************************
232 
233  //**Addition assignment to sparse matrices******************************************************
245  template< typename MT2 // Type of the target sparse matrix
246  , bool SO2 > // Storage order of the target dense matrix
247  friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
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  addAssign( ~lhs, rhs.dm_ );
253  }
255  //**********************************************************************************************
256 
257  //**Subtraction assignment to dense matrices****************************************************
269  template< typename MT2 // Type of the target dense matrix
270  , bool SO2 > // Storage order of the target dense matrix
271  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
272  {
273  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
274  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
275 
276  subAssign( ~lhs, rhs.dm_ );
277  }
279  //**********************************************************************************************
280 
281  //**Subtraction assignment to sparse matrices***************************************************
293  template< typename MT2 // Type of the target sparse matrix
294  , bool SO2 > // Storage order of the target dense matrix
295  friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
296  {
297  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
298  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
299 
300  subAssign( ~lhs, rhs.dm_ );
301  }
303  //**********************************************************************************************
304 
305  //**Multiplication assignment to dense matrices*************************************************
306  // No special implementation for the multiplication assignment to dense matrices.
307  //**********************************************************************************************
308 
309  //**Multiplication assignment to sparse matrices************************************************
310  // No special implementation for the multiplication assignment to sparse matrices.
311  //**********************************************************************************************
312 
313  //**Compile time checks*************************************************************************
318  //**********************************************************************************************
319 };
320 //*************************************************************************************************
321 
322 
323 
324 
325 //=================================================================================================
326 //
327 // GLOBAL OPERATORS
328 //
329 //=================================================================================================
330 
331 //*************************************************************************************************
348 template< typename MT // Type of the dense matrix
349  , bool SO > // Storage order
350 inline const DMatEvalExpr<MT,SO> eval( const DenseMatrix<MT,SO>& dm )
351 {
352  return DMatEvalExpr<MT,SO>( ~dm );
353 }
354 //*************************************************************************************************
355 
356 } // namespace blaze
357 
358 #endif