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/Exception.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  //**At function*********************************************************************************
142  inline ReturnType at( size_t index ) const {
143  if( index >= dv_.size() ) {
144  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
145  }
146  return (*this)[index];
147  }
148  //**********************************************************************************************
149 
150  //**Size function*******************************************************************************
155  inline size_t size() const {
156  return dv_.size();
157  }
158  //**********************************************************************************************
159 
160  //**Operand access******************************************************************************
165  inline Operand operand() const {
166  return dv_;
167  }
168  //**********************************************************************************************
169 
170  //**********************************************************************************************
176  template< typename T >
177  inline bool canAlias( const T* alias ) const {
178  return dv_.canAlias( alias );
179  }
180  //**********************************************************************************************
181 
182  //**********************************************************************************************
188  template< typename T >
189  inline bool isAliased( const T* alias ) const {
190  return dv_.isAliased( alias );
191  }
192  //**********************************************************************************************
193 
194  //**********************************************************************************************
199  inline bool isAligned() const {
200  return dv_.isAligned();
201  }
202  //**********************************************************************************************
203 
204  //**********************************************************************************************
209  inline bool canSMPAssign() const {
210  return dv_.canSMPAssign();
211  }
212  //**********************************************************************************************
213 
214  private:
215  //**Member variables****************************************************************************
216  Operand dv_;
217  //**********************************************************************************************
218 
219  //**Assignment to dense vectors*****************************************************************
231  template< typename VT2 > // Type of the target dense vector
232  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
233  {
235 
236  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
237 
238  assign( ~lhs, rhs.dv_ );
239  }
241  //**********************************************************************************************
242 
243  //**Assignment to sparse vectors****************************************************************
255  template< typename VT2 > // Type of the target sparse vector
256  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
257  {
259 
260  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
261 
262  assign( ~lhs, rhs.dv_ );
263  }
265  //**********************************************************************************************
266 
267  //**Addition assignment to dense vectors********************************************************
279  template< typename VT2 > // Type of the target dense vector
280  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
281  {
283 
284  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
285 
286  addAssign( ~lhs, rhs.dv_ );
287  }
289  //**********************************************************************************************
290 
291  //**Addition assignment to sparse vectors*******************************************************
303  template< typename VT2 > // Type of the target sparse vector
304  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
305  {
307 
308  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
309 
310  addAssign( ~lhs, rhs.dv_ );
311  }
313  //**********************************************************************************************
314 
315  //**Subtraction assignment to dense vectors*****************************************************
327  template< typename VT2 > // Type of the target dense vector
328  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
329  {
331 
332  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
333 
334  subAssign( ~lhs, rhs.dv_ );
335  }
337  //**********************************************************************************************
338 
339  //**Subtraction assignment to sparse vectors****************************************************
351  template< typename VT2 > // Type of the target sparse vector
352  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
353  {
355 
356  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
357 
358  subAssign( ~lhs, rhs.dv_ );
359  }
361  //**********************************************************************************************
362 
363  //**Multiplication assignment to dense vectors**************************************************
375  template< typename VT2 > // Type of the target dense vector
376  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
377  {
379 
380  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
381 
382  multAssign( ~lhs, rhs.dv_ );
383  }
385  //**********************************************************************************************
386 
387  //**Multiplication assignment to sparse vectors*************************************************
399  template< typename VT2 > // Type of the target sparse vector
400  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
401  {
403 
404  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
405 
406  multAssign( ~lhs, rhs.dv_ );
407  }
409  //**********************************************************************************************
410 
411  //**SMP assignment to dense vectors*************************************************************
423  template< typename VT2 > // Type of the target dense vector
424  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
425  {
427 
428  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
429 
430  smpAssign( ~lhs, rhs.dv_ );
431  }
433  //**********************************************************************************************
434 
435  //**SMP assignment to sparse vectors************************************************************
447  template< typename VT2 > // Type of the target sparse vector
448  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
449  {
451 
452  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
453 
454  smpAssign( ~lhs, rhs.dv_ );
455  }
457  //**********************************************************************************************
458 
459  //**SMP addition assignment to dense vectors****************************************************
471  template< typename VT2 > // Type of the target dense vector
472  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
473  {
475 
476  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
477 
478  smpAddAssign( ~lhs, rhs.dv_ );
479  }
481  //**********************************************************************************************
482 
483  //**SMP addition assignment to sparse vectors***************************************************
495  template< typename VT2 > // Type of the target sparse vector
496  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
497  {
499 
500  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
501 
502  smpAddAssign( ~lhs, rhs.dv_ );
503  }
505  //**********************************************************************************************
506 
507  //**SMP subtraction assignment to dense vectors*************************************************
519  template< typename VT2 > // Type of the target dense vector
520  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
521  {
523 
524  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
525 
526  smpSubAssign( ~lhs, rhs.dv_ );
527  }
529  //**********************************************************************************************
530 
531  //**SMP subtraction assignment to sparse vectors************************************************
543  template< typename VT2 > // Type of the target sparse vector
544  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
545  {
547 
548  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
549 
550  smpSubAssign( ~lhs, rhs.dv_ );
551  }
553  //**********************************************************************************************
554 
555  //**SMP multiplication assignment to dense vectors**********************************************
567  template< typename VT2 > // Type of the target dense vector
568  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
569  {
571 
572  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
573 
574  smpMultAssign( ~lhs, rhs.dv_ );
575  }
577  //**********************************************************************************************
578 
579  //**SMP multiplication assignment to sparse vectors*********************************************
591  template< typename VT2 > // Type of the target sparse vector
592  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
593  {
595 
596  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
597 
598  smpMultAssign( ~lhs, rhs.dv_ );
599  }
601  //**********************************************************************************************
602 
603  //**Compile time checks*************************************************************************
608  //**********************************************************************************************
609 };
610 //*************************************************************************************************
611 
612 
613 
614 
615 //=================================================================================================
616 //
617 // GLOBAL FUNCTIONS
618 //
619 //=================================================================================================
620 
621 //*************************************************************************************************
638 template< typename VT // Type of the dense vector
639  , bool TF > // Transpose flag
640 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
641 {
643 
644  return DVecEvalExpr<VT,TF>( ~dv );
645 }
646 //*************************************************************************************************
647 
648 
649 
650 
651 //=================================================================================================
652 //
653 // GLOBAL RESTRUCTURING FUNCTIONS
654 //
655 //=================================================================================================
656 
657 //*************************************************************************************************
668 template< typename VT // Type of the dense vector
669  , bool TF > // Transpose flag
670 inline const DVecEvalExpr<VT,TF> eval( const DVecEvalExpr<VT,TF>& dv )
671 {
672  return dv;
673 }
675 //*************************************************************************************************
676 
677 
678 
679 
680 //=================================================================================================
681 //
682 // SIZE SPECIALIZATIONS
683 //
684 //=================================================================================================
685 
686 //*************************************************************************************************
688 template< typename VT, bool TF >
689 struct Size< DVecEvalExpr<VT,TF> > : public Size<VT>
690 {};
692 //*************************************************************************************************
693 
694 
695 
696 
697 //=================================================================================================
698 //
699 // ISALIGNED SPECIALIZATIONS
700 //
701 //=================================================================================================
702 
703 //*************************************************************************************************
705 template< typename VT, bool TF >
706 struct IsAligned< DVecEvalExpr<VT,TF> > : public IsTrue< IsAligned<VT>::value >
707 {};
709 //*************************************************************************************************
710 
711 
712 
713 
714 //=================================================================================================
715 //
716 // EXPRESSION TRAIT SPECIALIZATIONS
717 //
718 //=================================================================================================
719 
720 //*************************************************************************************************
722 template< typename VT >
723 struct DVecEvalExprTrait< DVecEvalExpr<VT,false> >
724 {
725  public:
726  //**********************************************************************************************
727  typedef typename SelectType< IsDenseVector<VT>::value && IsColumnVector<VT>::value
728  , DVecEvalExpr<VT,false>
729  , INVALID_TYPE >::Type Type;
730  //**********************************************************************************************
731 };
733 //*************************************************************************************************
734 
735 
736 //*************************************************************************************************
738 template< typename VT >
739 struct TDVecEvalExprTrait< DVecEvalExpr<VT,true> >
740 {
741  public:
742  //**********************************************************************************************
743  typedef typename SelectType< IsDenseVector<VT>::value && IsRowVector<VT>::value
744  , DVecEvalExpr<VT,true>
745  , INVALID_TYPE >::Type Type;
746  //**********************************************************************************************
747 };
749 //*************************************************************************************************
750 
751 
752 //*************************************************************************************************
754 template< typename VT, bool TF, bool AF >
755 struct SubvectorExprTrait< DVecEvalExpr<VT,TF>, AF >
756 {
757  public:
758  //**********************************************************************************************
759  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
760  //**********************************************************************************************
761 };
763 //*************************************************************************************************
764 
765 } // namespace blaze
766 
767 #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:165
VT::ElementType ElementType
Resulting element type.
Definition: DVecEvalExpr.h:95
Header file for basic type definitions.
Base class for all vector evaluation expression templates.The VecEvalExpr class serves as a tag for a...
Definition: VecEvalExpr.h:65
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:216
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
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:129
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
size_t size() const
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:155
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
Header file for the IsAligned type trait.
Constraint on the data type.
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:142
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2585
Constraint on the data type.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
EnableIf< IsDenseMatrix< MT1 > >::Type smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:189
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
Utility type for generic codes.
Header file for the DVecEvalExprTrait class template.
Header file for the EvalExprTrait class template.
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:96
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:703
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:177
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:209
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
EnableIf< IsDenseMatrix< MT1 > >::Type smpAddAssign(Matrix< 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:129
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
#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:2583
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:199
Header file for exception macros.
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
EnableIf< IsDenseVector< VT1 > >::Type smpMultAssign(Vector< 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:189
Header file for the Size type trait.
#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:81
#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.