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>
58 #include <blaze/util/Assert.h>
60 #include <blaze/util/EnableIf.h>
61 #include <blaze/util/InvalidType.h>
63 #include <blaze/util/SelectType.h>
64 #include <blaze/util/Types.h>
65 
66 
67 namespace blaze {
68 
69 //=================================================================================================
70 //
71 // CLASS DVECEVALEXPR
72 //
73 //=================================================================================================
74 
75 //*************************************************************************************************
82 template< typename VT // Type of the dense vector
83  , bool TF > // Transpose flag
84 class DVecEvalExpr : public DenseVector< DVecEvalExpr<VT,TF>, TF >
85  , private VecEvalExpr
86  , private Computation
87 {
88  public:
89  //**Type definitions****************************************************************************
91  typedef typename VT::ResultType ResultType;
92  typedef typename VT::TransposeType TransposeType;
93  typedef typename VT::ElementType ElementType;
94  typedef typename VT::ReturnType ReturnType;
95 
97  typedef const ResultType CompositeType;
98 
100  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
101  //**********************************************************************************************
102 
103  //**Compilation flags***************************************************************************
105  enum { vectorizable = 0 };
106 
108  enum { smpAssignable = VT::smpAssignable };
109  //**********************************************************************************************
110 
111  //**Constructor*********************************************************************************
116  explicit inline DVecEvalExpr( const VT& dv )
117  : dv_( dv ) // Dense vector of the evaluation expression
118  {}
119  //**********************************************************************************************
120 
121  //**Subscript operator**************************************************************************
127  inline ReturnType operator[]( size_t index ) const {
128  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
129  return dv_[index];
130  }
131  //**********************************************************************************************
132 
133  //**Size function*******************************************************************************
138  inline size_t size() const {
139  return dv_.size();
140  }
141  //**********************************************************************************************
142 
143  //**Operand access******************************************************************************
148  inline Operand operand() const {
149  return dv_;
150  }
151  //**********************************************************************************************
152 
153  //**********************************************************************************************
159  template< typename T >
160  inline bool canAlias( const T* alias ) const {
161  return dv_.canAlias( alias );
162  }
163  //**********************************************************************************************
164 
165  //**********************************************************************************************
171  template< typename T >
172  inline bool isAliased( const T* alias ) const {
173  return dv_.isAliased( alias );
174  }
175  //**********************************************************************************************
176 
177  //**********************************************************************************************
182  inline bool isAligned() const {
183  return dv_.isAligned();
184  }
185  //**********************************************************************************************
186 
187  //**********************************************************************************************
192  inline bool canSMPAssign() const {
193  return dv_.canSMPAssign();
194  }
195  //**********************************************************************************************
196 
197  private:
198  //**Member variables****************************************************************************
200  //**********************************************************************************************
201 
202  //**Assignment to dense vectors*****************************************************************
214  template< typename VT2 > // Type of the target dense vector
215  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
216  {
218 
219  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
220 
221  assign( ~lhs, rhs.dv_ );
222  }
224  //**********************************************************************************************
225 
226  //**Assignment to sparse vectors****************************************************************
238  template< typename VT2 > // Type of the target sparse vector
239  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
240  {
242 
243  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
244 
245  assign( ~lhs, rhs.dv_ );
246  }
248  //**********************************************************************************************
249 
250  //**Addition assignment to dense vectors********************************************************
262  template< typename VT2 > // Type of the target dense vector
263  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
264  {
266 
267  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
268 
269  addAssign( ~lhs, rhs.dv_ );
270  }
272  //**********************************************************************************************
273 
274  //**Addition assignment to sparse vectors*******************************************************
286  template< typename VT2 > // Type of the target sparse vector
287  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
288  {
290 
291  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
292 
293  addAssign( ~lhs, rhs.dv_ );
294  }
296  //**********************************************************************************************
297 
298  //**Subtraction assignment to dense vectors*****************************************************
310  template< typename VT2 > // Type of the target dense vector
311  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
312  {
314 
315  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
316 
317  subAssign( ~lhs, rhs.dv_ );
318  }
320  //**********************************************************************************************
321 
322  //**Subtraction assignment to sparse vectors****************************************************
334  template< typename VT2 > // Type of the target sparse vector
335  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
336  {
338 
339  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
340 
341  subAssign( ~lhs, rhs.dv_ );
342  }
344  //**********************************************************************************************
345 
346  //**Multiplication assignment to dense vectors**************************************************
358  template< typename VT2 > // Type of the target dense vector
359  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
360  {
362 
363  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
364 
365  multAssign( ~lhs, rhs.dv_ );
366  }
368  //**********************************************************************************************
369 
370  //**Multiplication assignment to sparse vectors*************************************************
382  template< typename VT2 > // Type of the target sparse vector
383  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
384  {
386 
387  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
388 
389  multAssign( ~lhs, rhs.dv_ );
390  }
392  //**********************************************************************************************
393 
394  //**SMP assignment to dense vectors*************************************************************
406  template< typename VT2 > // Type of the target dense vector
407  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
408  {
410 
411  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
412 
413  smpAssign( ~lhs, rhs.dv_ );
414  }
416  //**********************************************************************************************
417 
418  //**SMP assignment to sparse vectors************************************************************
430  template< typename VT2 > // Type of the target sparse vector
431  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
432  {
434 
435  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
436 
437  smpAssign( ~lhs, rhs.dv_ );
438  }
440  //**********************************************************************************************
441 
442  //**SMP addition assignment to dense vectors****************************************************
454  template< typename VT2 > // Type of the target dense vector
455  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
456  {
458 
459  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
460 
461  smpAddAssign( ~lhs, rhs.dv_ );
462  }
464  //**********************************************************************************************
465 
466  //**SMP addition assignment to sparse vectors***************************************************
478  template< typename VT2 > // Type of the target sparse vector
479  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
480  {
482 
483  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
484 
485  smpAddAssign( ~lhs, rhs.dv_ );
486  }
488  //**********************************************************************************************
489 
490  //**SMP subtraction assignment to dense vectors*************************************************
502  template< typename VT2 > // Type of the target dense vector
503  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
504  {
506 
507  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
508 
509  smpSubAssign( ~lhs, rhs.dv_ );
510  }
512  //**********************************************************************************************
513 
514  //**SMP subtraction assignment to sparse vectors************************************************
526  template< typename VT2 > // Type of the target sparse vector
527  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
528  {
530 
531  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
532 
533  smpSubAssign( ~lhs, rhs.dv_ );
534  }
536  //**********************************************************************************************
537 
538  //**SMP multiplication assignment to dense vectors**********************************************
550  template< typename VT2 > // Type of the target dense vector
551  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
552  {
554 
555  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
556 
557  smpMultAssign( ~lhs, rhs.dv_ );
558  }
560  //**********************************************************************************************
561 
562  //**SMP multiplication assignment to sparse vectors*********************************************
574  template< typename VT2 > // Type of the target sparse vector
575  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
576  {
578 
579  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
580 
581  smpMultAssign( ~lhs, rhs.dv_ );
582  }
584  //**********************************************************************************************
585 
586  //**Compile time checks*************************************************************************
591  //**********************************************************************************************
592 };
593 //*************************************************************************************************
594 
595 
596 
597 
598 //=================================================================================================
599 //
600 // GLOBAL FUNCTIONS
601 //
602 //=================================================================================================
603 
604 //*************************************************************************************************
621 template< typename VT // Type of the dense vector
622  , bool TF > // Transpose flag
623 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
624 {
626 
627  return DVecEvalExpr<VT,TF>( ~dv );
628 }
629 //*************************************************************************************************
630 
631 
632 
633 
634 //=================================================================================================
635 //
636 // GLOBAL RESTRUCTURING FUNCTIONS
637 //
638 //=================================================================================================
639 
640 //*************************************************************************************************
651 template< typename VT // Type of the dense vector
652  , bool TF > // Transpose flag
653 inline const DVecEvalExpr<VT,TF> eval( const DVecEvalExpr<VT,TF>& dv )
654 {
655  return dv;
656 }
658 //*************************************************************************************************
659 
660 
661 
662 
663 //=================================================================================================
664 //
665 // EXPRESSION TRAIT SPECIALIZATIONS
666 //
667 //=================================================================================================
668 
669 //*************************************************************************************************
671 template< typename VT >
672 struct DVecEvalExprTrait< DVecEvalExpr<VT,false> >
673 {
674  public:
675  //**********************************************************************************************
676  typedef typename SelectType< IsDenseVector<VT>::value && IsColumnVector<VT>::value
677  , DVecEvalExpr<VT,false>
678  , INVALID_TYPE >::Type Type;
679  //**********************************************************************************************
680 };
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
687 template< typename VT >
688 struct TDVecEvalExprTrait< DVecEvalExpr<VT,true> >
689 {
690  public:
691  //**********************************************************************************************
692  typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value
693  , DVecEvalExpr<VT,true>
694  , INVALID_TYPE >::Type Type;
695  //**********************************************************************************************
696 };
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
703 template< typename VT, bool TF, bool AF >
704 struct SubvectorExprTrait< DVecEvalExpr<VT,TF>, AF >
705 {
706  public:
707  //**********************************************************************************************
708  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
709  //**********************************************************************************************
710 };
712 //*************************************************************************************************
713 
714 } // namespace blaze
715 
716 #endif
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:97
Operand operand() const
Returns the dense vector operand.
Definition: DVecEvalExpr.h:148
VT::ElementType ElementType
Resulting element type.
Definition: DVecEvalExpr.h:93
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:152
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:179
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:100
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:199
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:122
Expression object for the forced evaluation of dense vectors.The DVecEvalExpr class represents the co...
Definition: DVecEvalExpr.h:84
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:127
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:138
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:271
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:2405
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
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:361
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:92
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:172
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
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:301
Header file for the EvalExprTrait class template.
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:94
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:331
DVecEvalExpr(const VT &dv)
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:116
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:672
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:160
DVecEvalExpr< VT, TF > This
Type of this DVecEvalExpr instance.
Definition: DVecEvalExpr.h:90
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:192
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#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:2403
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:182
Header file for the IsColumnVector type trait.
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:91
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:92
#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.