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>
41 #include <blaze/util/Assert.h>
43 #include <blaze/util/EnableIf.h>
45 #include <blaze/util/SelectType.h>
46 #include <blaze/util/Types.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS DMATEVALEXPR
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
64 template< typename MT // Type of the dense matrix
65  , bool SO > // Storage order
66 class DMatEvalExpr : public DenseMatrix< DMatEvalExpr<MT,SO>, SO >
67  , private Expression
68  , private Computation
69 {
70  public:
71  //**Type definitions****************************************************************************
73  typedef typename MT::ResultType ResultType;
74  typedef typename MT::OppositeType OppositeType;
75  typedef typename MT::TransposeType TransposeType;
76  typedef typename MT::ElementType ElementType;
77  typedef typename MT::ReturnType ReturnType;
78 
80  typedef const ResultType CompositeType;
81 
83  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
84  //**********************************************************************************************
85 
86  //**Compilation flags***************************************************************************
88  enum { vectorizable = 0 };
89  //**********************************************************************************************
90 
91  //**Constructor*********************************************************************************
96  explicit inline DMatEvalExpr( const MT& dm )
97  : dm_( dm ) // Dense matrix of the evaluation expression
98  {}
99  //**********************************************************************************************
100 
101  //**Access operator*****************************************************************************
108  inline ReturnType operator()( size_t i, size_t j ) const {
109  BLAZE_INTERNAL_ASSERT( i < dm_.rows() , "Invalid row access index" );
110  BLAZE_INTERNAL_ASSERT( j < dm_.columns(), "Invalid column access index" );
111  return dm_(i,j);
112  }
113  //**********************************************************************************************
114 
115  //**Rows function*******************************************************************************
120  inline size_t rows() const {
121  return dm_.rows();
122  }
123  //**********************************************************************************************
124 
125  //**Columns function****************************************************************************
130  inline size_t columns() const {
131  return dm_.columns();
132  }
133  //**********************************************************************************************
134 
135  //**Operand access******************************************************************************
140  inline Operand operand() const {
141  return dm_;
142  }
143  //**********************************************************************************************
144 
145  //**********************************************************************************************
151  template< typename T >
152  inline bool canAlias( const T* alias ) const {
153  return dm_.canAlias( alias );
154  }
155  //**********************************************************************************************
156 
157  //**********************************************************************************************
163  template< typename T >
164  inline bool isAliased( const T* alias ) const {
165  return dm_.isAliased( alias );
166  }
167  //**********************************************************************************************
168 
169  private:
170  //**Member variables****************************************************************************
172  //**********************************************************************************************
173 
174  //**Assignment to dense matrices****************************************************************
186  template< typename MT2 // Type of the target dense matrix
187  , bool SO2 > // Storage order of the target dense matrix
188  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
189  {
191 
192  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
193  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
194 
195  assign( ~lhs, rhs.dm_ );
196  }
198  //**********************************************************************************************
199 
200  //**Assignment to sparse matrices***************************************************************
212  template< typename MT2 // Type of the target sparse matrix
213  , bool SO2 > // Storage order of the target dense matrix
214  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
215  {
217 
218  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
219  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
220 
221  assign( ~lhs, rhs.dm_ );
222  }
224  //**********************************************************************************************
225 
226  //**Addition assignment to dense matrices*******************************************************
238  template< typename MT2 // Type of the target dense matrix
239  , bool SO2 > // Storage order of the target dense matrix
240  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
241  {
243 
244  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
245  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
246 
247  addAssign( ~lhs, rhs.dm_ );
248  }
250  //**********************************************************************************************
251 
252  //**Addition assignment to sparse matrices******************************************************
264  template< typename MT2 // Type of the target sparse matrix
265  , bool SO2 > // Storage order of the target dense matrix
266  friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
267  {
269 
270  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
271  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
272 
273  addAssign( ~lhs, rhs.dm_ );
274  }
276  //**********************************************************************************************
277 
278  //**Subtraction assignment to dense matrices****************************************************
290  template< typename MT2 // Type of the target dense matrix
291  , bool SO2 > // Storage order of the target dense matrix
292  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
293  {
295 
296  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
297  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
298 
299  subAssign( ~lhs, rhs.dm_ );
300  }
302  //**********************************************************************************************
303 
304  //**Subtraction assignment to sparse matrices***************************************************
316  template< typename MT2 // Type of the target sparse matrix
317  , bool SO2 > // Storage order of the target dense matrix
318  friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const DMatEvalExpr& rhs )
319  {
321 
322  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
323  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
324 
325  subAssign( ~lhs, rhs.dm_ );
326  }
328  //**********************************************************************************************
329 
330  //**Multiplication assignment to dense matrices*************************************************
331  // No special implementation for the multiplication assignment to dense matrices.
332  //**********************************************************************************************
333 
334  //**Multiplication assignment to sparse matrices************************************************
335  // No special implementation for the multiplication assignment to sparse matrices.
336  //**********************************************************************************************
337 
338  //**Compile time checks*************************************************************************
343  //**********************************************************************************************
344 };
345 //*************************************************************************************************
346 
347 
348 
349 
350 //=================================================================================================
351 //
352 // GLOBAL OPERATORS
353 //
354 //=================================================================================================
355 
356 //*************************************************************************************************
373 template< typename MT // Type of the dense matrix
374  , bool SO > // Storage order
375 inline const DMatEvalExpr<MT,SO> eval( const DenseMatrix<MT,SO>& dm )
376 {
378 
379  return DMatEvalExpr<MT,SO>( ~dm );
380 }
381 //*************************************************************************************************
382 
383 
384 //*************************************************************************************************
396 template< typename MT // Type of the dense matrix
397  , bool SO > // Storage order
398 inline typename RowExprTrait< DMatEvalExpr<MT,SO> >::Type
399  row( const DMatEvalExpr<MT,SO>& dm, size_t index )
400 {
402 
403  return eval( row( dm.operand(), index ) );
404 }
406 //*************************************************************************************************
407 
408 
409 //*************************************************************************************************
421 template< typename MT // Type of the dense matrix
422  , bool SO > // Storage order
423 inline typename ColumnExprTrait< DMatEvalExpr<MT,SO> >::Type
424  column( const DMatEvalExpr<MT,SO>& dm, size_t index )
425 {
427 
428  return eval( column( dm.operand(), index ) );
429 }
431 //*************************************************************************************************
432 
433 
434 
435 
436 //=================================================================================================
437 //
438 // EXPRESSION TRAIT SPECIALIZATIONS
439 //
440 //=================================================================================================
441 
442 //*************************************************************************************************
444 template< typename MT, bool SO >
445 struct RowExprTrait< DMatEvalExpr<MT,SO> >
446 {
447  public:
448  //**********************************************************************************************
449  typedef typename EvalExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
450  //**********************************************************************************************
451 };
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
458 template< typename MT, bool SO >
459 struct ColumnExprTrait< DMatEvalExpr<MT,SO> >
460 {
461  public:
462  //**********************************************************************************************
463  typedef typename EvalExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
464  //**********************************************************************************************
465 };
467 //*************************************************************************************************
468 
469 } // namespace blaze
470 
471 #endif