All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <cmath>
39 #include <blaze/util/Assert.h>
41 #include <blaze/util/EnableIf.h>
42 #include <blaze/util/SelectType.h>
43 #include <blaze/util/Types.h>
44 
45 
46 namespace blaze {
47 
48 //=================================================================================================
49 //
50 // CLASS DVECEVALEXPR
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
61 template< typename VT // Type of the dense vector
62  , bool TF > // Transpose flag
63 class DVecEvalExpr : public DenseVector< DVecEvalExpr<VT,TF>, TF >
64  , private Expression
65  , private Computation
66 {
67  public:
68  //**Type definitions****************************************************************************
70  typedef typename VT::ResultType ResultType;
71  typedef typename VT::TransposeType TransposeType;
72  typedef typename VT::ElementType ElementType;
73  typedef typename VT::ReturnType ReturnType;
74 
76  typedef const ResultType CompositeType;
77 
79  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
80  //**********************************************************************************************
81 
82  //**Compilation flags***************************************************************************
84  enum { vectorizable = 0 };
85 
87  enum { canAlias = CanAlias<VT>::value };
88  //**********************************************************************************************
89 
90  //**Constructor*********************************************************************************
95  explicit inline DVecEvalExpr( const VT& dv )
96  : dv_( dv ) // Dense vector of the evaluation expression
97  {}
98  //**********************************************************************************************
99 
100  //**Subscript operator**************************************************************************
106  inline ReturnType operator[]( size_t index ) const {
107  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
108  return dv_[index];
109  }
110  //**********************************************************************************************
111 
112  //**Size function*******************************************************************************
117  inline size_t size() const {
118  return dv_.size();
119  }
120  //**********************************************************************************************
121 
122  //**Operand access******************************************************************************
127  inline Operand operand() const {
128  return dv_;
129  }
130  //**********************************************************************************************
131 
132  //**********************************************************************************************
138  template< typename T >
139  inline bool isAliased( const T* alias ) const {
140  return CanAlias<VT>::value && dv_.isAliased( alias );
141  }
142  //**********************************************************************************************
143 
144  private:
145  //**Member variables****************************************************************************
147  //**********************************************************************************************
148 
149  //**Assignment to dense vectors*****************************************************************
163  template< typename VT2 > // Type of the target dense vector
164  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
165  {
166  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
167 
168  assign( ~lhs, rhs.dv_ );
169  }
171  //**********************************************************************************************
172 
173  //**Assignment to sparse vectors****************************************************************
187  template< typename VT2 > // Type of the target sparse vector
188  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
189  {
190  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
191 
192  assign( ~lhs, rhs.dv_ );
193  }
195  //**********************************************************************************************
196 
197  //**Addition assignment to dense vectors********************************************************
211  template< typename VT2 > // Type of the target dense vector
212  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
213  {
214  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
215 
216  addAssign( ~lhs, rhs.dv_ );
217  }
219  //**********************************************************************************************
220 
221  //**Addition assignment to sparse vectors*******************************************************
235  template< typename VT2 > // Type of the target sparse vector
236  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
237  {
238  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
239 
240  addAssign( ~lhs, rhs.dv_ );
241  }
243  //**********************************************************************************************
244 
245  //**Subtraction assignment to dense vectors*****************************************************
259  template< typename VT2 > // Type of the target dense vector
260  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
261  {
262  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
263 
264  subAssign( ~lhs, rhs.dv_ );
265  }
267  //**********************************************************************************************
268 
269  //**Subtraction assignment to sparse vectors****************************************************
283  template< typename VT2 > // Type of the target sparse vector
284  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
285  {
286  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
287 
288  subAssign( ~lhs, rhs.dv_ );
289  }
291  //**********************************************************************************************
292 
293  //**Multiplication assignment to dense vectors**************************************************
307  template< typename VT2 > // Type of the target dense vector
308  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
309  {
310  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
311 
312  multAssign( ~lhs, rhs.dv_ );
313  }
315  //**********************************************************************************************
316 
317  //**Multiplication assignment to sparse vectors*************************************************
331  template< typename VT2 > // Type of the target sparse vector
332  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
333  {
334  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
335 
336  multAssign( ~lhs, rhs.dv_ );
337  }
339  //**********************************************************************************************
340 
341  //**Compile time checks*************************************************************************
346  //**********************************************************************************************
347 };
348 //*************************************************************************************************
349 
350 
351 
352 
353 //=================================================================================================
354 //
355 // GLOBAL OPERATORS
356 //
357 //=================================================================================================
358 
359 //*************************************************************************************************
376 template< typename VT // Type of the dense vector
377  , bool TF > // Transpose flag
378 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
379 {
380  return DVecEvalExpr<VT,TF>( ~dv );
381 }
382 //*************************************************************************************************
383 
384 } // namespace blaze
385 
386 #endif