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>
54 #include <blaze/util/Assert.h>
57 #include <blaze/util/InvalidType.h>
58 #include <blaze/util/mpl/If.h>
59 #include <blaze/util/Types.h>
60 
61 
62 namespace blaze {
63 
64 //=================================================================================================
65 //
66 // CLASS DVECEVALEXPR
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
77 template< typename VT // Type of the dense vector
78  , bool TF > // Transpose flag
80  : public VecEvalExpr< DenseVector< DVecEvalExpr<VT,TF>, TF > >
81  , private Computation
82 {
83  public:
84  //**Type definitions****************************************************************************
90 
92  using CompositeType = const ResultType;
93 
95  using Operand = If_< IsExpression<VT>, const VT, const VT& >;
96  //**********************************************************************************************
97 
98  //**Compilation flags***************************************************************************
100  enum : bool { simdEnabled = false };
101 
103  enum : bool { smpAssignable = VT::smpAssignable };
104  //**********************************************************************************************
105 
106  //**Constructor*********************************************************************************
111  explicit inline DVecEvalExpr( const VT& dv ) noexcept
112  : dv_( dv ) // Dense vector of the evaluation expression
113  {}
114  //**********************************************************************************************
115 
116  //**Subscript operator**************************************************************************
122  inline ReturnType operator[]( size_t index ) const {
123  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
124  return dv_[index];
125  }
126  //**********************************************************************************************
127 
128  //**At function*********************************************************************************
135  inline ReturnType at( size_t index ) const {
136  if( index >= dv_.size() ) {
137  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
138  }
139  return (*this)[index];
140  }
141  //**********************************************************************************************
142 
143  //**Size function*******************************************************************************
148  inline size_t size() const noexcept {
149  return dv_.size();
150  }
151  //**********************************************************************************************
152 
153  //**Operand access******************************************************************************
158  inline Operand operand() const noexcept {
159  return dv_;
160  }
161  //**********************************************************************************************
162 
163  //**********************************************************************************************
169  template< typename T >
170  inline bool canAlias( const T* alias ) const noexcept {
171  return dv_.canAlias( alias );
172  }
173  //**********************************************************************************************
174 
175  //**********************************************************************************************
181  template< typename T >
182  inline bool isAliased( const T* alias ) const noexcept {
183  return dv_.isAliased( alias );
184  }
185  //**********************************************************************************************
186 
187  //**********************************************************************************************
192  inline bool isAligned() const noexcept {
193  return dv_.isAligned();
194  }
195  //**********************************************************************************************
196 
197  //**********************************************************************************************
202  inline bool canSMPAssign() const noexcept {
203  return dv_.canSMPAssign();
204  }
205  //**********************************************************************************************
206 
207  private:
208  //**Member variables****************************************************************************
210  //**********************************************************************************************
211 
212  //**Assignment to dense vectors*****************************************************************
224  template< typename VT2 > // Type of the target dense vector
225  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
226  {
228 
229  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
230 
231  assign( ~lhs, rhs.dv_ );
232  }
234  //**********************************************************************************************
235 
236  //**Assignment to sparse vectors****************************************************************
248  template< typename VT2 > // Type of the target sparse vector
249  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
250  {
252 
253  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
254 
255  assign( ~lhs, rhs.dv_ );
256  }
258  //**********************************************************************************************
259 
260  //**Addition assignment to dense vectors********************************************************
272  template< typename VT2 > // Type of the target dense vector
273  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
274  {
276 
277  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
278 
279  addAssign( ~lhs, rhs.dv_ );
280  }
282  //**********************************************************************************************
283 
284  //**Addition assignment to sparse vectors*******************************************************
296  template< typename VT2 > // Type of the target sparse vector
297  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
298  {
300 
301  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
302 
303  addAssign( ~lhs, rhs.dv_ );
304  }
306  //**********************************************************************************************
307 
308  //**Subtraction assignment to dense vectors*****************************************************
320  template< typename VT2 > // Type of the target dense vector
321  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
322  {
324 
325  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
326 
327  subAssign( ~lhs, rhs.dv_ );
328  }
330  //**********************************************************************************************
331 
332  //**Subtraction assignment to sparse vectors****************************************************
344  template< typename VT2 > // Type of the target sparse vector
345  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
346  {
348 
349  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
350 
351  subAssign( ~lhs, rhs.dv_ );
352  }
354  //**********************************************************************************************
355 
356  //**Multiplication assignment to dense vectors**************************************************
368  template< typename VT2 > // Type of the target dense vector
369  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
370  {
372 
373  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
374 
375  multAssign( ~lhs, rhs.dv_ );
376  }
378  //**********************************************************************************************
379 
380  //**Multiplication assignment to sparse vectors*************************************************
392  template< typename VT2 > // Type of the target sparse vector
393  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
394  {
396 
397  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
398 
399  multAssign( ~lhs, rhs.dv_ );
400  }
402  //**********************************************************************************************
403 
404  //**Division assignment to dense vectors********************************************************
416  template< typename VT2 > // Type of the target dense vector
417  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
418  {
420 
421  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
422 
423  divAssign( ~lhs, rhs.dv_ );
424  }
426  //**********************************************************************************************
427 
428  //**Division assignment to sparse vectors*******************************************************
440  template< typename VT2 > // Type of the target sparse vector
441  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
442  {
444 
445  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
446 
447  divAssign( ~lhs, rhs.dv_ );
448  }
450  //**********************************************************************************************
451 
452  //**SMP assignment to dense vectors*************************************************************
464  template< typename VT2 > // Type of the target dense vector
465  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
466  {
468 
469  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
470 
471  smpAssign( ~lhs, rhs.dv_ );
472  }
474  //**********************************************************************************************
475 
476  //**SMP assignment to sparse vectors************************************************************
488  template< typename VT2 > // Type of the target sparse vector
489  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
490  {
492 
493  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
494 
495  smpAssign( ~lhs, rhs.dv_ );
496  }
498  //**********************************************************************************************
499 
500  //**SMP addition assignment to dense vectors****************************************************
512  template< typename VT2 > // Type of the target dense vector
513  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
514  {
516 
517  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
518 
519  smpAddAssign( ~lhs, rhs.dv_ );
520  }
522  //**********************************************************************************************
523 
524  //**SMP addition assignment to sparse vectors***************************************************
536  template< typename VT2 > // Type of the target sparse vector
537  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
538  {
540 
541  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
542 
543  smpAddAssign( ~lhs, rhs.dv_ );
544  }
546  //**********************************************************************************************
547 
548  //**SMP subtraction assignment to dense vectors*************************************************
560  template< typename VT2 > // Type of the target dense vector
561  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
562  {
564 
565  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
566 
567  smpSubAssign( ~lhs, rhs.dv_ );
568  }
570  //**********************************************************************************************
571 
572  //**SMP subtraction assignment to sparse vectors************************************************
584  template< typename VT2 > // Type of the target sparse vector
585  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
586  {
588 
589  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
590 
591  smpSubAssign( ~lhs, rhs.dv_ );
592  }
594  //**********************************************************************************************
595 
596  //**SMP multiplication assignment to dense vectors**********************************************
608  template< typename VT2 > // Type of the target dense vector
609  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
610  {
612 
613  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
614 
615  smpMultAssign( ~lhs, rhs.dv_ );
616  }
618  //**********************************************************************************************
619 
620  //**SMP multiplication assignment to sparse vectors*********************************************
632  template< typename VT2 > // Type of the target sparse vector
633  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
634  {
636 
637  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
638 
639  smpMultAssign( ~lhs, rhs.dv_ );
640  }
642  //**********************************************************************************************
643 
644  //**SMP division assignment to dense vectors****************************************************
656  template< typename VT2 > // Type of the target dense vector
657  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
658  {
660 
661  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
662 
663  smpDivAssign( ~lhs, rhs.dv_ );
664  }
666  //**********************************************************************************************
667 
668  //**SMP division assignment to sparse vectors***************************************************
680  template< typename VT2 > // Type of the target sparse vector
681  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
682  {
684 
685  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
686 
687  smpDivAssign( ~lhs, rhs.dv_ );
688  }
690  //**********************************************************************************************
691 
692  //**Compile time checks*************************************************************************
697  //**********************************************************************************************
698 };
699 //*************************************************************************************************
700 
701 
702 
703 
704 //=================================================================================================
705 //
706 // GLOBAL FUNCTIONS
707 //
708 //=================================================================================================
709 
710 //*************************************************************************************************
727 template< typename VT // Type of the dense vector
728  , bool TF > // Transpose flag
729 inline decltype(auto) eval( const DenseVector<VT,TF>& dv )
730 {
732 
733  using ReturnType = const DVecEvalExpr<VT,TF>;
734  return ReturnType( ~dv );
735 }
736 //*************************************************************************************************
737 
738 
739 
740 
741 //=================================================================================================
742 //
743 // GLOBAL RESTRUCTURING FUNCTIONS
744 //
745 //=================================================================================================
746 
747 //*************************************************************************************************
758 template< typename VT // Type of the dense vector
759  , bool TF > // Transpose flag
760 inline decltype(auto) eval( const DVecEvalExpr<VT,TF>& dv )
761 {
762  return dv;
763 }
765 //*************************************************************************************************
766 
767 
768 
769 
770 //=================================================================================================
771 //
772 // SIZE SPECIALIZATIONS
773 //
774 //=================================================================================================
775 
776 //*************************************************************************************************
778 template< typename VT, bool TF >
779 struct Size< DVecEvalExpr<VT,TF> >
780  : public Size<VT>
781 {};
783 //*************************************************************************************************
784 
785 
786 
787 
788 //=================================================================================================
789 //
790 // ISALIGNED SPECIALIZATIONS
791 //
792 //=================================================================================================
793 
794 //*************************************************************************************************
796 template< typename VT, bool TF >
797 struct IsAligned< DVecEvalExpr<VT,TF> >
798  : public BoolConstant< IsAligned<VT>::value >
799 {};
801 //*************************************************************************************************
802 
803 } // namespace blaze
804 
805 #endif
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:122
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:66
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:164
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
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 DenseVector base class.
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecEvalExpr.h:158
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:148
Header file for the Computation base class.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:202
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:343
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:133
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:86
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:209
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
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:79
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecEvalExpr.h:89
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:102
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:182
#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
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.
decltype(auto) eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:797
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.
Header file for run time assertion macros.
Utility type for generic codes.
DVecEvalExpr(const VT &dv) noexcept
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:111
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:154
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:192
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:135
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
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:87
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3082
#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
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecEvalExpr.h:88
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:170
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:74
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Header file for the IntegralConstant class template.
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:95
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
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
Header file for the IsExpression type trait class.
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:92
Header file for the function trace functionality.