All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_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 SVECEVALEXPR
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
63 template< typename VT // Type of the sparse vector
64  , bool TF > // Transpose flag
65 class SVecEvalExpr : public SparseVector< SVecEvalExpr<VT,TF>, TF >
66  , private Expression
67  , private Computation
68 {
69  public:
70  //**Type definitions****************************************************************************
72  typedef typename VT::ResultType ResultType;
73  typedef typename VT::TransposeType TransposeType;
74  typedef typename VT::ElementType ElementType;
75  typedef typename VT::ReturnType ReturnType;
76 
78  typedef const ResultType CompositeType;
79 
81  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
82  //**********************************************************************************************
83 
84  //**Compilation flags***************************************************************************
87  //**********************************************************************************************
88 
89  //**Constructor*********************************************************************************
94  explicit inline SVecEvalExpr( const VT& sv )
95  : sv_( sv ) // Sparse vector of the evaluation expression
96  {}
97  //**********************************************************************************************
98 
99  //**Subscript operator**************************************************************************
105  inline ReturnType operator[]( size_t index ) const {
106  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
107  return sv_[index];
108  }
109  //**********************************************************************************************
110 
111  //**Size function*******************************************************************************
116  inline size_t size() const {
117  return sv_.size();
118  }
119  //**********************************************************************************************
120 
121  //**NonZeros function***************************************************************************
126  inline size_t nonZeros() const {
127  return sv_.nonZeros();
128  }
129  //**********************************************************************************************
130 
131  //**Operand access******************************************************************************
136  inline Operand operand() const {
137  return sv_;
138  }
139  //**********************************************************************************************
140 
141  //**********************************************************************************************
147  template< typename T >
148  inline bool isAliased( const T* alias ) const {
150  !RequiresEvaluation<VT>::value && sv_.isAliased( alias );
151  }
152  //**********************************************************************************************
153 
154  private:
155  //**Member variables****************************************************************************
157  //**********************************************************************************************
158 
159  //**Assignment to dense vectors*****************************************************************
173  template< typename VT2 > // Type of the target dense vector
174  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
175  {
176  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
177 
178  assign( ~lhs, rhs.sv_ );
179  }
181  //**********************************************************************************************
182 
183  //**Assignment to sparse vectors****************************************************************
197  template< typename VT2 > // Type of the target sparse vector
198  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
199  {
200  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
201 
202  assign( ~lhs, rhs.sv_ );
203  }
205  //**********************************************************************************************
206 
207  //**Addition assignment to dense vectors********************************************************
221  template< typename VT2 > // Type of the target dense vector
222  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
223  {
224  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
225 
226  addAssign( ~lhs, rhs.sv_ );
227  }
229  //**********************************************************************************************
230 
231  //**Addition assignment to sparse vectors*******************************************************
245  template< typename VT2 > // Type of the target sparse vector
246  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
247  {
248  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
249 
250  addAssign( ~lhs, rhs.sv_ );
251  }
253  //**********************************************************************************************
254 
255  //**Subtraction assignment to dense vectors*****************************************************
269  template< typename VT2 > // Type of the target dense vector
270  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
271  {
272  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
273 
274  subAssign( ~lhs, rhs.sv_ );
275  }
277  //**********************************************************************************************
278 
279  //**Subtraction assignment to sparse vectors****************************************************
293  template< typename VT2 > // Type of the target sparse vector
294  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
295  {
296  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
297 
298  subAssign( ~lhs, rhs.sv_ );
299  }
301  //**********************************************************************************************
302 
303  //**Multiplication assignment to dense vectors**************************************************
317  template< typename VT2 > // Type of the target dense vector
318  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
319  {
320  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
321 
322  multAssign( ~lhs, rhs.sv_ );
323  }
325  //**********************************************************************************************
326 
327  //**Multiplication assignment to sparse vectors*************************************************
341  template< typename VT2 > // Type of the target sparse vector
342  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
343  {
344  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
345 
346  multAssign( ~lhs, rhs.sv_ );
347  }
349  //**********************************************************************************************
350 
351  //**Compile time checks*************************************************************************
356  //**********************************************************************************************
357 };
358 //*************************************************************************************************
359 
360 
361 
362 
363 //=================================================================================================
364 //
365 // GLOBAL OPERATORS
366 //
367 //=================================================================================================
368 
369 //*************************************************************************************************
386 template< typename VT // Type of the dense vector
387  , bool TF > // Transpose flag
389 {
390  return SVecEvalExpr<VT,TF>( ~sv );
391 }
392 //*************************************************************************************************
393 
394 } // namespace blaze
395 
396 #endif