All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SMatEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATEVALEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_SMATEVALEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <cmath>
42 #include <blaze/util/Assert.h>
44 #include <blaze/util/EnableIf.h>
46 #include <blaze/util/SelectType.h>
47 #include <blaze/util/Types.h>
48 
49 
50 namespace blaze {
51 
52 //=================================================================================================
53 //
54 // CLASS SMATEVALEXPR
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
65 template< typename MT // Type of the sparse matrix
66  , bool SO > // Storage order
67 class SMatEvalExpr : public SparseMatrix< SMatEvalExpr<MT,SO>, SO >
68  , private MatEvalExpr
69  , private Computation
70 {
71  public:
72  //**Type definitions****************************************************************************
74  typedef typename MT::ResultType ResultType;
75  typedef typename MT::OppositeType OppositeType;
76  typedef typename MT::TransposeType TransposeType;
77  typedef typename MT::ElementType ElementType;
78  typedef typename MT::ReturnType ReturnType;
79 
81  typedef const ResultType CompositeType;
82 
84  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
85  //**********************************************************************************************
86 
87  //**Constructor*********************************************************************************
92  explicit inline SMatEvalExpr( const MT& sm )
93  : sm_( sm ) // Sparse matrix of the evaluation expression
94  {}
95  //**********************************************************************************************
96 
97  //**Access operator*****************************************************************************
104  inline ReturnType operator()( size_t i, size_t j ) const {
105  BLAZE_INTERNAL_ASSERT( i < sm_.rows() , "Invalid row access index" );
106  BLAZE_INTERNAL_ASSERT( j < sm_.columns(), "Invalid column access index" );
107  return sm_(i,j);
108  }
109  //**********************************************************************************************
110 
111  //**Rows function*******************************************************************************
116  inline size_t rows() const {
117  return sm_.rows();
118  }
119  //**********************************************************************************************
120 
121  //**Columns function****************************************************************************
126  inline size_t columns() const {
127  return sm_.columns();
128  }
129  //**********************************************************************************************
130 
131  //**NonZeros function***************************************************************************
136  inline size_t nonZeros() const {
137  return sm_.nonZeros();
138  }
139  //**********************************************************************************************
140 
141  //**NonZeros function***************************************************************************
147  inline size_t nonZeros( size_t i ) const {
148  return sm_.nonZeros(i);
149  }
150  //**********************************************************************************************
151 
152  //**Operand access******************************************************************************
157  inline Operand operand() const {
158  return sm_;
159  }
160  //**********************************************************************************************
161 
162  //**********************************************************************************************
168  template< typename T >
169  inline bool canAlias( const T* alias ) const {
170  return sm_.canAlias( alias );
171  }
172  //**********************************************************************************************
173 
174  //**********************************************************************************************
180  template< typename T >
181  inline bool isAliased( const T* alias ) const {
182  return sm_.isAliased( alias );
183  }
184  //**********************************************************************************************
185 
186  private:
187  //**Member variables****************************************************************************
189  //**********************************************************************************************
190 
191  //**Assignment to dense matrices****************************************************************
203  template< typename MT2 // Type of the target dense matrix
204  , bool SO2 > // Storage order of the target dense matrix
205  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
206  {
208 
209  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
210  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
211 
212  assign( ~lhs, rhs.sm_ );
213  }
215  //**********************************************************************************************
216 
217  //**Assignment to sparse matrices***************************************************************
229  template< typename MT2 // Type of the target sparse matrix
230  , bool SO2 > // Storage order of the target sparse matrix
231  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
232  {
234 
235  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
236  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
237 
238  assign( ~lhs, rhs.sm_ );
239  }
241  //**********************************************************************************************
242 
243  //**Addition assignment to dense matrices*******************************************************
255  template< typename MT2 // Type of the target dense matrix
256  , bool SO2 > // Storage order of the target dense matrix
257  friend inline void addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
258  {
260 
261  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
262  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
263 
264  addAssign( ~lhs, rhs.sm_ );
265  }
267  //**********************************************************************************************
268 
269  //**Addition assignment to sparse matrices******************************************************
281  template< typename MT2 // Type of the target sparse matrix
282  , bool SO2 > // Storage order of the target sparse matrix
283  friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
284  {
286 
287  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
288  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
289 
290  addAssign( ~lhs, rhs.sm_ );
291  }
293  //**********************************************************************************************
294 
295  //**Subtraction assignment to dense matrices****************************************************
307  template< typename MT2 // Type of the target dense matrix
308  , bool SO2 > // Storage order of the target dense matrix
309  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
310  {
312 
313  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
314  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
315 
316  subAssign( ~lhs, rhs.sm_ );
317  }
319  //**********************************************************************************************
320 
321  //**Subtraction assignment to sparse matrices***************************************************
333  template< typename MT2 // Type of the target sparse matrix
334  , bool SO2 > // Storage order of the target sparse matrix
335  friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
336  {
338 
339  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
340  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
341 
342  subAssign( ~lhs, rhs.sm_ );
343  }
345  //**********************************************************************************************
346 
347  //**Multiplication assignment to dense matrices*************************************************
359  template< typename MT2 // Type of the target dense matrix
360  , bool SO2 > // Storage order of the target dense matrix
361  friend inline void multAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
362  {
364 
365  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
366  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
367 
368  multAssign( ~lhs, rhs.sm_ );
369  }
371  //**********************************************************************************************
372 
373  //**Multiplication assignment to sparse matrices************************************************
385  template< typename MT2 // Type of the target sparse matrix
386  , bool SO2 > // Storage order of the target sparse matrix
387  friend inline void multAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& 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  multAssign( ~lhs, rhs.sm_ );
395  }
397  //**********************************************************************************************
398 
399  //**Compile time checks*************************************************************************
404  //**********************************************************************************************
405 };
406 //*************************************************************************************************
407 
408 
409 
410 
411 //=================================================================================================
412 //
413 // GLOBAL OPERATORS
414 //
415 //=================================================================================================
416 
417 //*************************************************************************************************
434 template< typename MT // Type of the sparse matrix
435  , bool SO > // Storage order
437 {
439 
440  return SMatEvalExpr<MT,SO>( ~sm );
441 }
442 //*************************************************************************************************
443 
444 
445 
446 
447 //=================================================================================================
448 //
449 // EXPRESSION TRAIT SPECIALIZATIONS
450 //
451 //=================================================================================================
452 
453 //*************************************************************************************************
455 template< typename MT, bool SO >
456 struct RowExprTrait< SMatEvalExpr<MT,SO> >
457 {
458  public:
459  //**********************************************************************************************
460  typedef typename EvalExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
461  //**********************************************************************************************
462 };
464 //*************************************************************************************************
465 
466 
467 //*************************************************************************************************
469 template< typename MT, bool SO >
470 struct ColumnExprTrait< SMatEvalExpr<MT,SO> >
471 {
472  public:
473  //**********************************************************************************************
474  typedef typename EvalExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
475  //**********************************************************************************************
476 };
478 //*************************************************************************************************
479 
480 } // namespace blaze
481 
482 #endif