All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DVecEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECEVALEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <cmath>
60 #include <blaze/util/Assert.h>
62 #include <blaze/util/EnableIf.h>
63 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/SelectType.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS DVECEVALEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT // Type of the dense vector
85  , bool TF > // Transpose flag
86 class DVecEvalExpr : public DenseVector< DVecEvalExpr<VT,TF>, TF >
87  , private VecEvalExpr
88  , private Computation
89 {
90  public:
91  //**Type definitions****************************************************************************
93  typedef typename VT::ResultType ResultType;
94  typedef typename VT::TransposeType TransposeType;
95  typedef typename VT::ElementType ElementType;
96  typedef typename VT::ReturnType ReturnType;
97 
99  typedef const ResultType CompositeType;
100 
102  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
103  //**********************************************************************************************
104 
105  //**Compilation flags***************************************************************************
107  enum { vectorizable = 0 };
108 
110  enum { smpAssignable = VT::smpAssignable };
111  //**********************************************************************************************
112 
113  //**Constructor*********************************************************************************
118  explicit inline DVecEvalExpr( const VT& dv )
119  : dv_( dv ) // Dense vector of the evaluation expression
120  {}
121  //**********************************************************************************************
122 
123  //**Subscript operator**************************************************************************
129  inline ReturnType operator[]( size_t index ) const {
130  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
131  return dv_[index];
132  }
133  //**********************************************************************************************
134 
135  //**Size function*******************************************************************************
140  inline size_t size() const {
141  return dv_.size();
142  }
143  //**********************************************************************************************
144 
145  //**Operand access******************************************************************************
150  inline Operand operand() const {
151  return dv_;
152  }
153  //**********************************************************************************************
154 
155  //**********************************************************************************************
161  template< typename T >
162  inline bool canAlias( const T* alias ) const {
163  return dv_.canAlias( alias );
164  }
165  //**********************************************************************************************
166 
167  //**********************************************************************************************
173  template< typename T >
174  inline bool isAliased( const T* alias ) const {
175  return dv_.isAliased( alias );
176  }
177  //**********************************************************************************************
178 
179  //**********************************************************************************************
184  inline bool isAligned() const {
185  return dv_.isAligned();
186  }
187  //**********************************************************************************************
188 
189  //**********************************************************************************************
194  inline bool canSMPAssign() const {
195  return dv_.canSMPAssign();
196  }
197  //**********************************************************************************************
198 
199  private:
200  //**Member variables****************************************************************************
202  //**********************************************************************************************
203 
204  //**Assignment to dense vectors*****************************************************************
216  template< typename VT2 > // Type of the target dense vector
217  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
218  {
220 
221  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
222 
223  assign( ~lhs, rhs.dv_ );
224  }
226  //**********************************************************************************************
227 
228  //**Assignment to sparse vectors****************************************************************
240  template< typename VT2 > // Type of the target sparse vector
241  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
242  {
244 
245  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
246 
247  assign( ~lhs, rhs.dv_ );
248  }
250  //**********************************************************************************************
251 
252  //**Addition assignment to dense vectors********************************************************
264  template< typename VT2 > // Type of the target dense vector
265  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
266  {
268 
269  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
270 
271  addAssign( ~lhs, rhs.dv_ );
272  }
274  //**********************************************************************************************
275 
276  //**Addition assignment to sparse vectors*******************************************************
288  template< typename VT2 > // Type of the target sparse vector
289  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
290  {
292 
293  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
294 
295  addAssign( ~lhs, rhs.dv_ );
296  }
298  //**********************************************************************************************
299 
300  //**Subtraction assignment to dense vectors*****************************************************
312  template< typename VT2 > // Type of the target dense vector
313  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
314  {
316 
317  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
318 
319  subAssign( ~lhs, rhs.dv_ );
320  }
322  //**********************************************************************************************
323 
324  //**Subtraction assignment to sparse vectors****************************************************
336  template< typename VT2 > // Type of the target sparse vector
337  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
338  {
340 
341  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
342 
343  subAssign( ~lhs, rhs.dv_ );
344  }
346  //**********************************************************************************************
347 
348  //**Multiplication assignment to dense vectors**************************************************
360  template< typename VT2 > // Type of the target dense vector
361  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
362  {
364 
365  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
366 
367  multAssign( ~lhs, rhs.dv_ );
368  }
370  //**********************************************************************************************
371 
372  //**Multiplication assignment to sparse vectors*************************************************
384  template< typename VT2 > // Type of the target sparse vector
385  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
386  {
388 
389  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
390 
391  multAssign( ~lhs, rhs.dv_ );
392  }
394  //**********************************************************************************************
395 
396  //**SMP assignment to dense vectors*************************************************************
408  template< typename VT2 > // Type of the target dense vector
409  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
410  {
412 
413  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
414 
415  smpAssign( ~lhs, rhs.dv_ );
416  }
418  //**********************************************************************************************
419 
420  //**SMP assignment to sparse vectors************************************************************
432  template< typename VT2 > // Type of the target sparse vector
433  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
434  {
436 
437  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
438 
439  smpAssign( ~lhs, rhs.dv_ );
440  }
442  //**********************************************************************************************
443 
444  //**SMP addition assignment to dense vectors****************************************************
456  template< typename VT2 > // Type of the target dense vector
457  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
458  {
460 
461  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
462 
463  smpAddAssign( ~lhs, rhs.dv_ );
464  }
466  //**********************************************************************************************
467 
468  //**SMP addition assignment to sparse vectors***************************************************
480  template< typename VT2 > // Type of the target sparse vector
481  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
482  {
484 
485  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
486 
487  smpAddAssign( ~lhs, rhs.dv_ );
488  }
490  //**********************************************************************************************
491 
492  //**SMP subtraction assignment to dense vectors*************************************************
504  template< typename VT2 > // Type of the target dense vector
505  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
506  {
508 
509  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
510 
511  smpSubAssign( ~lhs, rhs.dv_ );
512  }
514  //**********************************************************************************************
515 
516  //**SMP subtraction assignment to sparse vectors************************************************
528  template< typename VT2 > // Type of the target sparse vector
529  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
530  {
532 
533  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
534 
535  smpSubAssign( ~lhs, rhs.dv_ );
536  }
538  //**********************************************************************************************
539 
540  //**SMP multiplication assignment to dense vectors**********************************************
552  template< typename VT2 > // Type of the target dense vector
553  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
554  {
556 
557  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
558 
559  smpMultAssign( ~lhs, rhs.dv_ );
560  }
562  //**********************************************************************************************
563 
564  //**SMP multiplication assignment to sparse vectors*********************************************
576  template< typename VT2 > // Type of the target sparse vector
577  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
578  {
580 
581  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
582 
583  smpMultAssign( ~lhs, rhs.dv_ );
584  }
586  //**********************************************************************************************
587 
588  //**Compile time checks*************************************************************************
593  //**********************************************************************************************
594 };
595 //*************************************************************************************************
596 
597 
598 
599 
600 //=================================================================================================
601 //
602 // GLOBAL FUNCTIONS
603 //
604 //=================================================================================================
605 
606 //*************************************************************************************************
623 template< typename VT // Type of the dense vector
624  , bool TF > // Transpose flag
625 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
626 {
628 
629  return DVecEvalExpr<VT,TF>( ~dv );
630 }
631 //*************************************************************************************************
632 
633 
634 
635 
636 //=================================================================================================
637 //
638 // GLOBAL RESTRUCTURING FUNCTIONS
639 //
640 //=================================================================================================
641 
642 //*************************************************************************************************
653 template< typename VT // Type of the dense vector
654  , bool TF > // Transpose flag
655 inline const DVecEvalExpr<VT,TF> eval( const DVecEvalExpr<VT,TF>& dv )
656 {
657  return dv;
658 }
660 //*************************************************************************************************
661 
662 
663 
664 
665 //=================================================================================================
666 //
667 // EXPRESSION TRAIT SPECIALIZATIONS
668 //
669 //=================================================================================================
670 
671 //*************************************************************************************************
673 template< typename VT >
674 struct DVecEvalExprTrait< DVecEvalExpr<VT,false> >
675 {
676  public:
677  //**********************************************************************************************
678  typedef typename SelectType< IsDenseVector<VT>::value && IsColumnVector<VT>::value
679  , DVecEvalExpr<VT,false>
680  , INVALID_TYPE >::Type Type;
681  //**********************************************************************************************
682 };
684 //*************************************************************************************************
685 
686 
687 //*************************************************************************************************
689 template< typename VT >
690 struct TDVecEvalExprTrait< DVecEvalExpr<VT,true> >
691 {
692  public:
693  //**********************************************************************************************
694  typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value
695  , DVecEvalExpr<VT,true>
696  , INVALID_TYPE >::Type Type;
697  //**********************************************************************************************
698 };
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
705 template< typename VT, bool TF, bool AF >
706 struct SubvectorExprTrait< DVecEvalExpr<VT,TF>, AF >
707 {
708  public:
709  //**********************************************************************************************
710  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
711  //**********************************************************************************************
712 };
714 //*************************************************************************************************
715 
716 } // namespace blaze
717 
718 #endif
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:99
Operand operand() const
Returns the dense vector operand.
Definition: DVecEvalExpr.h:150
VT::ElementType ElementType
Resulting element type.
Definition: DVecEvalExpr.h:95
Base class for all vector evaluation expression templates.The VecEvalExpr class serves as a tag for a...
Definition: VecEvalExpr.h:65
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:151
void smpMultAssign(DenseVector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:178
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:102
Header file for the IsRowVector type trait.
Header file for the DenseVector base class.
Header file for the Computation base class.
Header file for the VecEvalExpr base class.
Constraint on the data type.
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:201
void smpAddAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:121
Expression object for the forced evaluation of dense vectors.The DVecEvalExpr class represents the co...
Definition: DVecEvalExpr.h:86
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the dense vector SMP implementation.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:129
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:140
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Header file for the TDVecEvalExprTrait class template.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:269
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:91
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:174
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Header file for run time assertion macros.
Utility type for generic codes.
Header file for the DVecEvalExprTrait class template.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the EvalExprTrait class template.
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:96
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
DVecEvalExpr(const VT &dv)
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:118
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:584
Header file for the IsDenseVector type trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:162
DVecEvalExpr< VT, TF > This
Type of this DVecEvalExpr instance.
Definition: DVecEvalExpr.h:92
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:194
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
Header file for the sparse vector SMP implementation.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
bool isAligned() const
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:184
Header file for the IsColumnVector type trait.
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:93
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:94
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:238
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.