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>
40 #include <blaze/util/Assert.h>
42 #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 VecEvalExpr
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  //**Constructor*********************************************************************************
89  explicit inline SVecEvalExpr( const VT& sv )
90  : sv_( sv ) // Sparse vector of the evaluation expression
91  {}
92  //**********************************************************************************************
93 
94  //**Subscript operator**************************************************************************
100  inline ReturnType operator[]( size_t index ) const {
101  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
102  return sv_[index];
103  }
104  //**********************************************************************************************
105 
106  //**Size function*******************************************************************************
111  inline size_t size() const {
112  return sv_.size();
113  }
114  //**********************************************************************************************
115 
116  //**NonZeros function***************************************************************************
121  inline size_t nonZeros() const {
122  return sv_.nonZeros();
123  }
124  //**********************************************************************************************
125 
126  //**Operand access******************************************************************************
131  inline Operand operand() const {
132  return sv_;
133  }
134  //**********************************************************************************************
135 
136  //**********************************************************************************************
142  template< typename T >
143  inline bool canAlias( const T* alias ) const {
144  return sv_.canAlias( alias );
145  }
146  //**********************************************************************************************
147 
148  //**********************************************************************************************
154  template< typename T >
155  inline bool isAliased( const T* alias ) const {
156  return sv_.isAliased( alias );
157  }
158  //**********************************************************************************************
159 
160  private:
161  //**Member variables****************************************************************************
163  //**********************************************************************************************
164 
165  //**Assignment to dense vectors*****************************************************************
179  template< typename VT2 > // Type of the target dense vector
180  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
181  {
183 
184  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
185 
186  assign( ~lhs, rhs.sv_ );
187  }
189  //**********************************************************************************************
190 
191  //**Assignment to sparse vectors****************************************************************
205  template< typename VT2 > // Type of the target sparse vector
206  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
207  {
209 
210  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
211 
212  assign( ~lhs, rhs.sv_ );
213  }
215  //**********************************************************************************************
216 
217  //**Addition assignment to dense vectors********************************************************
231  template< typename VT2 > // Type of the target dense vector
232  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
233  {
235 
236  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
237 
238  addAssign( ~lhs, rhs.sv_ );
239  }
241  //**********************************************************************************************
242 
243  //**Addition assignment to sparse vectors*******************************************************
257  template< typename VT2 > // Type of the target sparse vector
258  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
259  {
261 
262  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
263 
264  addAssign( ~lhs, rhs.sv_ );
265  }
267  //**********************************************************************************************
268 
269  //**Subtraction assignment to dense vectors*****************************************************
283  template< typename VT2 > // Type of the target dense vector
284  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
285  {
287 
288  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
289 
290  subAssign( ~lhs, rhs.sv_ );
291  }
293  //**********************************************************************************************
294 
295  //**Subtraction assignment to sparse vectors****************************************************
309  template< typename VT2 > // Type of the target sparse vector
310  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
311  {
313 
314  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
315 
316  subAssign( ~lhs, rhs.sv_ );
317  }
319  //**********************************************************************************************
320 
321  //**Multiplication assignment to dense vectors**************************************************
335  template< typename VT2 > // Type of the target dense vector
336  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
337  {
339 
340  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
341 
342  multAssign( ~lhs, rhs.sv_ );
343  }
345  //**********************************************************************************************
346 
347  //**Multiplication assignment to sparse vectors*************************************************
361  template< typename VT2 > // Type of the target sparse vector
362  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
363  {
365 
366  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
367 
368  multAssign( ~lhs, rhs.sv_ );
369  }
371  //**********************************************************************************************
372 
373  //**Compile time checks*************************************************************************
378  //**********************************************************************************************
379 };
380 //*************************************************************************************************
381 
382 
383 
384 
385 //=================================================================================================
386 //
387 // GLOBAL OPERATORS
388 //
389 //=================================================================================================
390 
391 //*************************************************************************************************
408 template< typename VT // Type of the dense vector
409  , bool TF > // Transpose flag
411 {
413 
414  return SVecEvalExpr<VT,TF>( ~sv );
415 }
416 //*************************************************************************************************
417 
418 } // namespace blaze
419 
420 #endif