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 <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
61 #include <blaze/util/Assert.h>
64 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/mpl/And.h>
66 #include <blaze/util/mpl/If.h>
67 #include <blaze/util/Types.h>
68 
69 
70 namespace blaze {
71 
72 //=================================================================================================
73 //
74 // CLASS DVECEVALEXPR
75 //
76 //=================================================================================================
77 
78 //*************************************************************************************************
85 template< typename VT // Type of the dense vector
86  , bool TF > // Transpose flag
87 class DVecEvalExpr : public DenseVector< DVecEvalExpr<VT,TF>, TF >
88  , private VecEvalExpr
89  , private Computation
90 {
91  public:
92  //**Type definitions****************************************************************************
98 
100  typedef const ResultType CompositeType;
101 
103  typedef If_< IsExpression<VT>, const VT, const VT& > Operand;
104  //**********************************************************************************************
105 
106  //**Compilation flags***************************************************************************
108  enum : bool { simdEnabled = false };
109 
111  enum : bool { smpAssignable = VT::smpAssignable };
112  //**********************************************************************************************
113 
114  //**Constructor*********************************************************************************
119  explicit inline DVecEvalExpr( const VT& dv ) noexcept
120  : dv_( dv ) // Dense vector of the evaluation expression
121  {}
122  //**********************************************************************************************
123 
124  //**Subscript operator**************************************************************************
130  inline ReturnType operator[]( size_t index ) const {
131  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
132  return dv_[index];
133  }
134  //**********************************************************************************************
135 
136  //**At function*********************************************************************************
143  inline ReturnType at( size_t index ) const {
144  if( index >= dv_.size() ) {
145  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
146  }
147  return (*this)[index];
148  }
149  //**********************************************************************************************
150 
151  //**Size function*******************************************************************************
156  inline size_t size() const noexcept {
157  return dv_.size();
158  }
159  //**********************************************************************************************
160 
161  //**Operand access******************************************************************************
166  inline Operand operand() const noexcept {
167  return dv_;
168  }
169  //**********************************************************************************************
170 
171  //**********************************************************************************************
177  template< typename T >
178  inline bool canAlias( const T* alias ) const noexcept {
179  return dv_.canAlias( alias );
180  }
181  //**********************************************************************************************
182 
183  //**********************************************************************************************
189  template< typename T >
190  inline bool isAliased( const T* alias ) const noexcept {
191  return dv_.isAliased( alias );
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
200  inline bool isAligned() const noexcept {
201  return dv_.isAligned();
202  }
203  //**********************************************************************************************
204 
205  //**********************************************************************************************
210  inline bool canSMPAssign() const noexcept {
211  return dv_.canSMPAssign();
212  }
213  //**********************************************************************************************
214 
215  private:
216  //**Member variables****************************************************************************
217  Operand dv_;
218  //**********************************************************************************************
219 
220  //**Assignment to dense vectors*****************************************************************
232  template< typename VT2 > // Type of the target dense vector
233  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
234  {
236 
237  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
238 
239  assign( ~lhs, rhs.dv_ );
240  }
242  //**********************************************************************************************
243 
244  //**Assignment to sparse vectors****************************************************************
256  template< typename VT2 > // Type of the target sparse vector
257  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
258  {
260 
261  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
262 
263  assign( ~lhs, rhs.dv_ );
264  }
266  //**********************************************************************************************
267 
268  //**Addition assignment to dense vectors********************************************************
280  template< typename VT2 > // Type of the target dense vector
281  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
282  {
284 
285  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
286 
287  addAssign( ~lhs, rhs.dv_ );
288  }
290  //**********************************************************************************************
291 
292  //**Addition assignment to sparse vectors*******************************************************
304  template< typename VT2 > // Type of the target sparse vector
305  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
306  {
308 
309  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
310 
311  addAssign( ~lhs, rhs.dv_ );
312  }
314  //**********************************************************************************************
315 
316  //**Subtraction assignment to dense vectors*****************************************************
328  template< typename VT2 > // Type of the target dense vector
329  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
330  {
332 
333  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
334 
335  subAssign( ~lhs, rhs.dv_ );
336  }
338  //**********************************************************************************************
339 
340  //**Subtraction assignment to sparse vectors****************************************************
352  template< typename VT2 > // Type of the target sparse vector
353  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
354  {
356 
357  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
358 
359  subAssign( ~lhs, rhs.dv_ );
360  }
362  //**********************************************************************************************
363 
364  //**Multiplication assignment to dense vectors**************************************************
376  template< typename VT2 > // Type of the target dense vector
377  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
378  {
380 
381  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
382 
383  multAssign( ~lhs, rhs.dv_ );
384  }
386  //**********************************************************************************************
387 
388  //**Multiplication assignment to sparse vectors*************************************************
400  template< typename VT2 > // Type of the target sparse vector
401  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
402  {
404 
405  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
406 
407  multAssign( ~lhs, rhs.dv_ );
408  }
410  //**********************************************************************************************
411 
412  //**Division assignment to dense vectors********************************************************
424  template< typename VT2 > // Type of the target dense vector
425  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
426  {
428 
429  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
430 
431  divAssign( ~lhs, rhs.dv_ );
432  }
434  //**********************************************************************************************
435 
436  //**Division assignment to sparse vectors*******************************************************
448  template< typename VT2 > // Type of the target sparse vector
449  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
450  {
452 
453  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
454 
455  divAssign( ~lhs, rhs.dv_ );
456  }
458  //**********************************************************************************************
459 
460  //**SMP assignment to dense vectors*************************************************************
472  template< typename VT2 > // Type of the target dense vector
473  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
474  {
476 
477  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
478 
479  smpAssign( ~lhs, rhs.dv_ );
480  }
482  //**********************************************************************************************
483 
484  //**SMP assignment to sparse vectors************************************************************
496  template< typename VT2 > // Type of the target sparse vector
497  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
498  {
500 
501  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
502 
503  smpAssign( ~lhs, rhs.dv_ );
504  }
506  //**********************************************************************************************
507 
508  //**SMP addition assignment to dense vectors****************************************************
520  template< typename VT2 > // Type of the target dense vector
521  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
522  {
524 
525  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
526 
527  smpAddAssign( ~lhs, rhs.dv_ );
528  }
530  //**********************************************************************************************
531 
532  //**SMP addition assignment to sparse vectors***************************************************
544  template< typename VT2 > // Type of the target sparse vector
545  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
546  {
548 
549  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
550 
551  smpAddAssign( ~lhs, rhs.dv_ );
552  }
554  //**********************************************************************************************
555 
556  //**SMP subtraction assignment to dense vectors*************************************************
568  template< typename VT2 > // Type of the target dense vector
569  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
570  {
572 
573  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
574 
575  smpSubAssign( ~lhs, rhs.dv_ );
576  }
578  //**********************************************************************************************
579 
580  //**SMP subtraction assignment to sparse vectors************************************************
592  template< typename VT2 > // Type of the target sparse vector
593  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
594  {
596 
597  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
598 
599  smpSubAssign( ~lhs, rhs.dv_ );
600  }
602  //**********************************************************************************************
603 
604  //**SMP multiplication assignment to dense vectors**********************************************
616  template< typename VT2 > // Type of the target dense vector
617  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
618  {
620 
621  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
622 
623  smpMultAssign( ~lhs, rhs.dv_ );
624  }
626  //**********************************************************************************************
627 
628  //**SMP multiplication assignment to sparse vectors*********************************************
640  template< typename VT2 > // Type of the target sparse vector
641  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
642  {
644 
645  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
646 
647  smpMultAssign( ~lhs, rhs.dv_ );
648  }
650  //**********************************************************************************************
651 
652  //**SMP division assignment to dense vectors****************************************************
664  template< typename VT2 > // Type of the target dense vector
665  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
666  {
668 
669  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
670 
671  smpDivAssign( ~lhs, rhs.dv_ );
672  }
674  //**********************************************************************************************
675 
676  //**SMP division assignment to sparse vectors***************************************************
688  template< typename VT2 > // Type of the target sparse vector
689  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
690  {
692 
693  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
694 
695  smpDivAssign( ~lhs, rhs.dv_ );
696  }
698  //**********************************************************************************************
699 
700  //**Compile time checks*************************************************************************
705  //**********************************************************************************************
706 };
707 //*************************************************************************************************
708 
709 
710 
711 
712 //=================================================================================================
713 //
714 // GLOBAL FUNCTIONS
715 //
716 //=================================================================================================
717 
718 //*************************************************************************************************
735 template< typename VT // Type of the dense vector
736  , bool TF > // Transpose flag
737 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
738 {
740 
741  return DVecEvalExpr<VT,TF>( ~dv );
742 }
743 //*************************************************************************************************
744 
745 
746 
747 
748 //=================================================================================================
749 //
750 // GLOBAL RESTRUCTURING FUNCTIONS
751 //
752 //=================================================================================================
753 
754 //*************************************************************************************************
765 template< typename VT // Type of the dense vector
766  , bool TF > // Transpose flag
767 inline const DVecEvalExpr<VT,TF> eval( const DVecEvalExpr<VT,TF>& dv )
768 {
769  return dv;
770 }
772 //*************************************************************************************************
773 
774 
775 
776 
777 //=================================================================================================
778 //
779 // SIZE SPECIALIZATIONS
780 //
781 //=================================================================================================
782 
783 //*************************************************************************************************
785 template< typename VT, bool TF >
786 struct Size< DVecEvalExpr<VT,TF> > : public Size<VT>
787 {};
789 //*************************************************************************************************
790 
791 
792 
793 
794 //=================================================================================================
795 //
796 // ISALIGNED SPECIALIZATIONS
797 //
798 //=================================================================================================
799 
800 //*************************************************************************************************
802 template< typename VT, bool TF >
803 struct IsAligned< DVecEvalExpr<VT,TF> >
804  : public BoolConstant< IsAligned<VT>::value >
805 {};
807 //*************************************************************************************************
808 
809 
810 
811 
812 //=================================================================================================
813 //
814 // EXPRESSION TRAIT SPECIALIZATIONS
815 //
816 //=================================================================================================
817 
818 //*************************************************************************************************
820 template< typename VT >
821 struct DVecEvalExprTrait< DVecEvalExpr<VT,false> >
822 {
823  public:
824  //**********************************************************************************************
827  , INVALID_TYPE >;
828  //**********************************************************************************************
829 };
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
836 template< typename VT >
837 struct TDVecEvalExprTrait< DVecEvalExpr<VT,true> >
838 {
839  public:
840  //**********************************************************************************************
843  , INVALID_TYPE >;
844  //**********************************************************************************************
845 };
847 //*************************************************************************************************
848 
849 
850 //*************************************************************************************************
852 template< typename VT, bool TF, bool AF >
853 struct SubvectorExprTrait< DVecEvalExpr<VT,TF>, AF >
854 {
855  public:
856  //**********************************************************************************************
858  //**********************************************************************************************
859 };
861 //*************************************************************************************************
862 
863 } // namespace blaze
864 
865 #endif
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:100
Compile time check for row vector types.This type trait tests whether or not the given template argum...
Definition: IsRowVector.h:80
Header file for auxiliary alias declarations.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:130
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:79
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
EnableIf_< IsDenseMatrix< MT1 > > 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
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
Header file for the IsRowVector type trait.
EnableIf_< IsDenseVector< VT1 > > 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:193
Header file for the And class template.
Header file for the DenseVector base class.
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:103
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecEvalExpr.h:166
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:156
Header file for the Computation base class.
typename EvalExprTrait< T >::Type EvalExprTrait_
Auxiliary alias declaration for the EvalExprTrait class template.The EvalExprTrait_ alias declaration...
Definition: EvalExprTrait.h:142
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:210
Header file for the VecEvalExpr base class.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
EnableIf_< IsDenseMatrix< MT1 > > 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
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:217
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Compile time check for the alignment of data types.This type trait tests whether the given data type ...
Definition: IsAligned.h:87
Expression object for the forced evaluation of dense vectors.The DVecEvalExpr class represents the co...
Definition: DVecEvalExpr.h:87
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
EnableIf_< IsDenseMatrix< MT1 > > 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
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:190
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
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.
Compile time check for column vector types.This type trait tests whether or not the given template ar...
Definition: IsColumnVector.h:80
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:94
Constraint on the data type.
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecEvalExpr.h:96
Evaluation of the expression type of a dense vector evaluation operation.Via this type trait it is po...
Definition: DVecEvalExprTrait.h:74
Header file for run time assertion macros.
Utility type for generic codes.
Header file for the DVecEvalExprTrait class template.
DVecEvalExpr(const VT &dv) noexcept
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:119
Header file for the EvalExprTrait class template.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:160
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:200
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:143
EnableIf_< IsDenseVector< VT1 > > smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:222
Evaluation of the expression type of a dense vector evaluation operation.Via this type trait it is po...
Definition: TDVecEvalExprTrait.h:74
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:93
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:61
DVecEvalExpr< VT, TF > This
Type of this DVecEvalExpr instance.
Definition: DVecEvalExpr.h:93
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:178
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:75
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:120
Header file for the IntegralConstant class template.
Header file for the SubvectorExprTrait class template.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
Header file for the IsColumnVector type trait.
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:63
#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
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:97
Header file for the IsExpression type trait class.
Header file for the function trace functionality.
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:95