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>
38 #include <blaze/util/Assert.h>
40 #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 VecEvalExpr
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  //**********************************************************************************************
86 
87  //**Constructor*********************************************************************************
92  explicit inline DVecEvalExpr( const VT& dv )
93  : dv_( dv ) // Dense vector of the evaluation expression
94  {}
95  //**********************************************************************************************
96 
97  //**Subscript operator**************************************************************************
103  inline ReturnType operator[]( size_t index ) const {
104  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
105  return dv_[index];
106  }
107  //**********************************************************************************************
108 
109  //**Size function*******************************************************************************
114  inline size_t size() const {
115  return dv_.size();
116  }
117  //**********************************************************************************************
118 
119  //**Operand access******************************************************************************
124  inline Operand operand() const {
125  return dv_;
126  }
127  //**********************************************************************************************
128 
129  //**********************************************************************************************
135  template< typename T >
136  inline bool canAlias( const T* alias ) const {
137  return dv_.canAlias( alias );
138  }
139  //**********************************************************************************************
140 
141  //**********************************************************************************************
147  template< typename T >
148  inline bool isAliased( const T* alias ) const {
149  return dv_.isAliased( alias );
150  }
151  //**********************************************************************************************
152 
153  private:
154  //**Member variables****************************************************************************
156  //**********************************************************************************************
157 
158  //**Assignment to dense vectors*****************************************************************
172  template< typename VT2 > // Type of the target dense vector
173  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
174  {
176 
177  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
178 
179  assign( ~lhs, rhs.dv_ );
180  }
182  //**********************************************************************************************
183 
184  //**Assignment to sparse vectors****************************************************************
198  template< typename VT2 > // Type of the target sparse vector
199  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
200  {
202 
203  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
204 
205  assign( ~lhs, rhs.dv_ );
206  }
208  //**********************************************************************************************
209 
210  //**Addition assignment to dense vectors********************************************************
224  template< typename VT2 > // Type of the target dense vector
225  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
226  {
228 
229  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
230 
231  addAssign( ~lhs, rhs.dv_ );
232  }
234  //**********************************************************************************************
235 
236  //**Addition assignment to sparse vectors*******************************************************
250  template< typename VT2 > // Type of the target sparse vector
251  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
252  {
254 
255  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
256 
257  addAssign( ~lhs, rhs.dv_ );
258  }
260  //**********************************************************************************************
261 
262  //**Subtraction assignment to dense vectors*****************************************************
276  template< typename VT2 > // Type of the target dense vector
277  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
278  {
280 
281  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
282 
283  subAssign( ~lhs, rhs.dv_ );
284  }
286  //**********************************************************************************************
287 
288  //**Subtraction assignment to sparse vectors****************************************************
302  template< typename VT2 > // Type of the target sparse vector
303  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
304  {
306 
307  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
308 
309  subAssign( ~lhs, rhs.dv_ );
310  }
312  //**********************************************************************************************
313 
314  //**Multiplication assignment to dense vectors**************************************************
328  template< typename VT2 > // Type of the target dense vector
329  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
330  {
332 
333  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
334 
335  multAssign( ~lhs, rhs.dv_ );
336  }
338  //**********************************************************************************************
339 
340  //**Multiplication assignment to sparse vectors*************************************************
354  template< typename VT2 > // Type of the target sparse vector
355  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
356  {
358 
359  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
360 
361  multAssign( ~lhs, rhs.dv_ );
362  }
364  //**********************************************************************************************
365 
366  //**Compile time checks*************************************************************************
371  //**********************************************************************************************
372 };
373 //*************************************************************************************************
374 
375 
376 
377 
378 //=================================================================================================
379 //
380 // GLOBAL OPERATORS
381 //
382 //=================================================================================================
383 
384 //*************************************************************************************************
401 template< typename VT // Type of the dense vector
402  , bool TF > // Transpose flag
403 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
404 {
406 
407  return DVecEvalExpr<VT,TF>( ~dv );
408 }
409 //*************************************************************************************************
410 
411 } // namespace blaze
412 
413 #endif