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>
41 #include <blaze/util/Assert.h>
43 #include <blaze/util/EnableIf.h>
44 #include <blaze/util/SelectType.h>
45 #include <blaze/util/Types.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS SMATEVALEXPR
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
63 template< typename MT // Type of the sparse matrix
64  , bool SO > // Storage order
65 class SMatEvalExpr : public SparseMatrix< SMatEvalExpr<MT,SO>, SO >
66  , private Expression
67  , private Computation
68 {
69  public:
70  //**Type definitions****************************************************************************
72  typedef typename MT::ResultType ResultType;
73  typedef typename MT::OppositeType OppositeType;
74  typedef typename MT::TransposeType TransposeType;
75  typedef typename MT::ElementType ElementType;
76  typedef typename MT::ReturnType ReturnType;
77 
79  typedef const ResultType CompositeType;
80 
82  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
83  //**********************************************************************************************
84 
85  //**Compilation flags***************************************************************************
88  //**********************************************************************************************
89 
90  //**Constructor*********************************************************************************
95  explicit inline SMatEvalExpr( const MT& sm )
96  : sm_( sm ) // Sparse 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 < sm_.rows() , "Invalid row access index" );
109  BLAZE_INTERNAL_ASSERT( j < sm_.columns(), "Invalid column access index" );
110  return sm_(i,j);
111  }
112  //**********************************************************************************************
113 
114  //**Rows function*******************************************************************************
119  inline size_t rows() const {
120  return sm_.rows();
121  }
122  //**********************************************************************************************
123 
124  //**Columns function****************************************************************************
129  inline size_t columns() const {
130  return sm_.columns();
131  }
132  //**********************************************************************************************
133 
134  //**NonZeros function***************************************************************************
139  inline size_t nonZeros() const {
140  return sm_.nonZeros();
141  }
142  //**********************************************************************************************
143 
144  //**NonZeros function***************************************************************************
150  inline size_t nonZeros( size_t i ) const {
151  return sm_.nonZeros(i);
152  }
153  //**********************************************************************************************
154 
155  //**Operand access******************************************************************************
160  inline Operand operand() const {
161  return sm_;
162  }
163  //**********************************************************************************************
164 
165  //**********************************************************************************************
171  template< typename T >
172  inline bool isAliased( const T* alias ) const {
174  !RequiresEvaluation<MT>::value && sm_.isAliased( alias );
175  }
176  //**********************************************************************************************
177 
178  private:
179  //**Member variables****************************************************************************
181  //**********************************************************************************************
182 
183  //**Assignment to dense matrices****************************************************************
195  template< typename MT2 // Type of the target dense matrix
196  , bool SO2 > // Storage order of the target dense matrix
197  friend inline void assign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
198  {
199  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
200  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
201 
202  assign( ~lhs, rhs.sm_ );
203  }
205  //**********************************************************************************************
206 
207  //**Assignment to sparse matrices***************************************************************
219  template< typename MT2 // Type of the target sparse matrix
220  , bool SO2 > // Storage order of the target sparse matrix
221  friend inline void assign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
222  {
223  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
224  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
225 
226  assign( ~lhs, rhs.sm_ );
227  }
229  //**********************************************************************************************
230 
231  //**Addition 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 addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
246  {
247  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
248  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
249 
250  addAssign( ~lhs, rhs.sm_ );
251  }
253  //**********************************************************************************************
254 
255  //**Addition assignment to sparse matrices******************************************************
267  template< typename MT2 // Type of the target sparse matrix
268  , bool SO2 > // Storage order of the target sparse matrix
269  friend inline void addAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
270  {
271  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
272  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
273 
274  addAssign( ~lhs, rhs.sm_ );
275  }
277  //**********************************************************************************************
278 
279  //**Subtraction assignment to dense matrices****************************************************
291  template< typename MT2 // Type of the target dense matrix
292  , bool SO2 > // Storage order of the target dense matrix
293  friend inline void subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
294  {
295  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
296  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
297 
298  subAssign( ~lhs, rhs.sm_ );
299  }
301  //**********************************************************************************************
302 
303  //**Subtraction assignment to sparse matrices***************************************************
315  template< typename MT2 // Type of the target sparse matrix
316  , bool SO2 > // Storage order of the target sparse matrix
317  friend inline void subAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
318  {
319  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
320  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
321 
322  subAssign( ~lhs, rhs.sm_ );
323  }
325  //**********************************************************************************************
326 
327  //**Multiplication assignment to dense matrices*************************************************
339  template< typename MT2 // Type of the target dense matrix
340  , bool SO2 > // Storage order of the target dense matrix
341  friend inline void multAssign( DenseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
342  {
343  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
344  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
345 
346  multAssign( ~lhs, rhs.sm_ );
347  }
349  //**********************************************************************************************
350 
351  //**Multiplication assignment to sparse matrices************************************************
363  template< typename MT2 // Type of the target sparse matrix
364  , bool SO2 > // Storage order of the target sparse matrix
365  friend inline void multAssign( SparseMatrix<MT2,SO2>& lhs, const SMatEvalExpr& rhs )
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  multAssign( ~lhs, rhs.sm_ );
371  }
373  //**********************************************************************************************
374 
375  //**Compile time checks*************************************************************************
380  //**********************************************************************************************
381 };
382 //*************************************************************************************************
383 
384 
385 
386 
387 //=================================================================================================
388 //
389 // GLOBAL OPERATORS
390 //
391 //=================================================================================================
392 
393 //*************************************************************************************************
410 template< typename MT // Type of the sparse matrix
411  , bool SO > // Storage order
413 {
414  return SMatEvalExpr<MT,SO>( ~sm );
415 }
416 //*************************************************************************************************
417 
418 } // namespace blaze
419 
420 #endif