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>
44 #include <blaze/math/Aliases.h>
47 #include <blaze/math/Exception.h>
62 #include <blaze/util/Assert.h>
65 #include <blaze/util/InvalidType.h>
67 #include <blaze/util/mpl/And.h>
68 #include <blaze/util/mpl/If.h>
69 #include <blaze/util/Types.h>
70 
71 
72 namespace blaze {
73 
74 //=================================================================================================
75 //
76 // CLASS DVECEVALEXPR
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
87 template< typename VT // Type of the dense vector
88  , bool TF > // Transpose flag
89 class DVecEvalExpr : public DenseVector< DVecEvalExpr<VT,TF>, TF >
90  , private VecEvalExpr
91  , private Computation
92 {
93  public:
94  //**Type definitions****************************************************************************
100 
102  typedef const ResultType CompositeType;
103 
105  typedef If_< IsExpression<VT>, const VT, const VT& > Operand;
106  //**********************************************************************************************
107 
108  //**Compilation flags***************************************************************************
110  enum : bool { simdEnabled = false };
111 
113  enum : bool { smpAssignable = VT::smpAssignable };
114  //**********************************************************************************************
115 
116  //**Constructor*********************************************************************************
121  explicit inline DVecEvalExpr( const VT& dv ) noexcept
122  : dv_( dv ) // Dense vector of the evaluation expression
123  {}
124  //**********************************************************************************************
125 
126  //**Subscript operator**************************************************************************
132  inline ReturnType operator[]( size_t index ) const {
133  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
134  return dv_[index];
135  }
136  //**********************************************************************************************
137 
138  //**At function*********************************************************************************
145  inline ReturnType at( size_t index ) const {
146  if( index >= dv_.size() ) {
147  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
148  }
149  return (*this)[index];
150  }
151  //**********************************************************************************************
152 
153  //**Size function*******************************************************************************
158  inline size_t size() const noexcept {
159  return dv_.size();
160  }
161  //**********************************************************************************************
162 
163  //**Operand access******************************************************************************
168  inline Operand operand() const noexcept {
169  return dv_;
170  }
171  //**********************************************************************************************
172 
173  //**********************************************************************************************
179  template< typename T >
180  inline bool canAlias( const T* alias ) const noexcept {
181  return dv_.canAlias( alias );
182  }
183  //**********************************************************************************************
184 
185  //**********************************************************************************************
191  template< typename T >
192  inline bool isAliased( const T* alias ) const noexcept {
193  return dv_.isAliased( alias );
194  }
195  //**********************************************************************************************
196 
197  //**********************************************************************************************
202  inline bool isAligned() const noexcept {
203  return dv_.isAligned();
204  }
205  //**********************************************************************************************
206 
207  //**********************************************************************************************
212  inline bool canSMPAssign() const noexcept {
213  return dv_.canSMPAssign();
214  }
215  //**********************************************************************************************
216 
217  private:
218  //**Member variables****************************************************************************
219  Operand dv_;
220  //**********************************************************************************************
221 
222  //**Assignment to dense vectors*****************************************************************
234  template< typename VT2 > // Type of the target dense vector
235  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
236  {
238 
239  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
240 
241  assign( ~lhs, rhs.dv_ );
242  }
244  //**********************************************************************************************
245 
246  //**Assignment to sparse vectors****************************************************************
258  template< typename VT2 > // Type of the target sparse vector
259  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
260  {
262 
263  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
264 
265  assign( ~lhs, rhs.dv_ );
266  }
268  //**********************************************************************************************
269 
270  //**Addition assignment to dense vectors********************************************************
282  template< typename VT2 > // Type of the target dense vector
283  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
284  {
286 
287  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
288 
289  addAssign( ~lhs, rhs.dv_ );
290  }
292  //**********************************************************************************************
293 
294  //**Addition assignment to sparse vectors*******************************************************
306  template< typename VT2 > // Type of the target sparse vector
307  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
308  {
310 
311  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
312 
313  addAssign( ~lhs, rhs.dv_ );
314  }
316  //**********************************************************************************************
317 
318  //**Subtraction assignment to dense vectors*****************************************************
330  template< typename VT2 > // Type of the target dense vector
331  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
332  {
334 
335  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
336 
337  subAssign( ~lhs, rhs.dv_ );
338  }
340  //**********************************************************************************************
341 
342  //**Subtraction assignment to sparse vectors****************************************************
354  template< typename VT2 > // Type of the target sparse vector
355  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
356  {
358 
359  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
360 
361  subAssign( ~lhs, rhs.dv_ );
362  }
364  //**********************************************************************************************
365 
366  //**Multiplication assignment to dense vectors**************************************************
378  template< typename VT2 > // Type of the target dense vector
379  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
380  {
382 
383  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
384 
385  multAssign( ~lhs, rhs.dv_ );
386  }
388  //**********************************************************************************************
389 
390  //**Multiplication assignment to sparse vectors*************************************************
402  template< typename VT2 > // Type of the target sparse vector
403  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
404  {
406 
407  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
408 
409  multAssign( ~lhs, rhs.dv_ );
410  }
412  //**********************************************************************************************
413 
414  //**Division assignment to dense vectors********************************************************
426  template< typename VT2 > // Type of the target dense vector
427  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
428  {
430 
431  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
432 
433  divAssign( ~lhs, rhs.dv_ );
434  }
436  //**********************************************************************************************
437 
438  //**Division assignment to sparse vectors*******************************************************
450  template< typename VT2 > // Type of the target sparse vector
451  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
452  {
454 
455  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
456 
457  divAssign( ~lhs, rhs.dv_ );
458  }
460  //**********************************************************************************************
461 
462  //**SMP assignment to dense vectors*************************************************************
474  template< typename VT2 > // Type of the target dense vector
475  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
476  {
478 
479  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
480 
481  smpAssign( ~lhs, rhs.dv_ );
482  }
484  //**********************************************************************************************
485 
486  //**SMP assignment to sparse vectors************************************************************
498  template< typename VT2 > // Type of the target sparse vector
499  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
500  {
502 
503  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
504 
505  smpAssign( ~lhs, rhs.dv_ );
506  }
508  //**********************************************************************************************
509 
510  //**SMP addition assignment to dense vectors****************************************************
522  template< typename VT2 > // Type of the target dense vector
523  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
524  {
526 
527  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
528 
529  smpAddAssign( ~lhs, rhs.dv_ );
530  }
532  //**********************************************************************************************
533 
534  //**SMP addition assignment to sparse vectors***************************************************
546  template< typename VT2 > // Type of the target sparse vector
547  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
548  {
550 
551  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
552 
553  smpAddAssign( ~lhs, rhs.dv_ );
554  }
556  //**********************************************************************************************
557 
558  //**SMP subtraction assignment to dense vectors*************************************************
570  template< typename VT2 > // Type of the target dense vector
571  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
572  {
574 
575  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
576 
577  smpSubAssign( ~lhs, rhs.dv_ );
578  }
580  //**********************************************************************************************
581 
582  //**SMP subtraction assignment to sparse vectors************************************************
594  template< typename VT2 > // Type of the target sparse vector
595  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
596  {
598 
599  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
600 
601  smpSubAssign( ~lhs, rhs.dv_ );
602  }
604  //**********************************************************************************************
605 
606  //**SMP multiplication assignment to dense vectors**********************************************
618  template< typename VT2 > // Type of the target dense vector
619  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
620  {
622 
623  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
624 
625  smpMultAssign( ~lhs, rhs.dv_ );
626  }
628  //**********************************************************************************************
629 
630  //**SMP multiplication assignment to sparse vectors*********************************************
642  template< typename VT2 > // Type of the target sparse vector
643  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
644  {
646 
647  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
648 
649  smpMultAssign( ~lhs, rhs.dv_ );
650  }
652  //**********************************************************************************************
653 
654  //**SMP division assignment to dense vectors****************************************************
666  template< typename VT2 > // Type of the target dense vector
667  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
668  {
670 
671  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
672 
673  smpDivAssign( ~lhs, rhs.dv_ );
674  }
676  //**********************************************************************************************
677 
678  //**SMP division assignment to sparse vectors***************************************************
690  template< typename VT2 > // Type of the target sparse vector
691  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
692  {
694 
695  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
696 
697  smpDivAssign( ~lhs, rhs.dv_ );
698  }
700  //**********************************************************************************************
701 
702  //**Compile time checks*************************************************************************
707  //**********************************************************************************************
708 };
709 //*************************************************************************************************
710 
711 
712 
713 
714 //=================================================================================================
715 //
716 // GLOBAL FUNCTIONS
717 //
718 //=================================================================================================
719 
720 //*************************************************************************************************
737 template< typename VT // Type of the dense vector
738  , bool TF > // Transpose flag
739 inline const DVecEvalExpr<VT,TF> eval( const DenseVector<VT,TF>& dv )
740 {
742 
743  return DVecEvalExpr<VT,TF>( ~dv );
744 }
745 //*************************************************************************************************
746 
747 
748 
749 
750 //=================================================================================================
751 //
752 // GLOBAL RESTRUCTURING FUNCTIONS
753 //
754 //=================================================================================================
755 
756 //*************************************************************************************************
767 template< typename VT // Type of the dense vector
768  , bool TF > // Transpose flag
769 inline const DVecEvalExpr<VT,TF> eval( const DVecEvalExpr<VT,TF>& dv )
770 {
771  return dv;
772 }
774 //*************************************************************************************************
775 
776 
777 
778 
779 //=================================================================================================
780 //
781 // SIZE SPECIALIZATIONS
782 //
783 //=================================================================================================
784 
785 //*************************************************************************************************
787 template< typename VT, bool TF >
788 struct Size< DVecEvalExpr<VT,TF> > : public Size<VT>
789 {};
791 //*************************************************************************************************
792 
793 
794 
795 
796 //=================================================================================================
797 //
798 // ISALIGNED SPECIALIZATIONS
799 //
800 //=================================================================================================
801 
802 //*************************************************************************************************
804 template< typename VT, bool TF >
805 struct IsAligned< DVecEvalExpr<VT,TF> >
806  : public BoolConstant< IsAligned<VT>::value >
807 {};
809 //*************************************************************************************************
810 
811 
812 
813 
814 //=================================================================================================
815 //
816 // EXPRESSION TRAIT SPECIALIZATIONS
817 //
818 //=================================================================================================
819 
820 //*************************************************************************************************
822 template< typename VT >
823 struct DVecEvalExprTrait< DVecEvalExpr<VT,false> >
824 {
825  public:
826  //**********************************************************************************************
827  using Type = If_< And< IsDenseVector<VT>, IsColumnVector<VT> >
828  , DVecEvalExpr<VT,false>
829  , INVALID_TYPE >;
830  //**********************************************************************************************
831 };
833 //*************************************************************************************************
834 
835 
836 //*************************************************************************************************
838 template< typename VT >
839 struct TDVecEvalExprTrait< DVecEvalExpr<VT,true> >
840 {
841  public:
842  //**********************************************************************************************
843  using Type = If_< And< IsDenseVector<VT>, IsRowVector<VT> >
844  , DVecEvalExpr<VT,true>
845  , INVALID_TYPE >;
846  //**********************************************************************************************
847 };
849 //*************************************************************************************************
850 
851 
852 //*************************************************************************************************
854 template< typename VT, bool TF, bool AF >
855 struct SubvectorExprTrait< DVecEvalExpr<VT,TF>, AF >
856 {
857  public:
858  //**********************************************************************************************
859  using Type = EvalExprTrait_< SubvectorExprTrait_<const VT,AF> >;
860  //**********************************************************************************************
861 };
863 //*************************************************************************************************
864 
865 } // namespace blaze
866 
867 #endif
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:102
Header file for auxiliary alias declarations.
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
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.
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:158
If_< IsExpression< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:105
Header file for the Computation base class.
Header file for the VecEvalExpr base class.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:180
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
Constraint on the data type.
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:219
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Expression object for the forced evaluation of dense vectors.The DVecEvalExpr class represents the co...
Definition: DVecEvalExpr.h:89
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecEvalExpr.h:132
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
#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.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:212
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:96
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:145
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:202
Constraint on the data type.
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecEvalExpr.h:168
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:98
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:121
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
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
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:705
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:100
Header file for the IsDenseVector type trait.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:192
#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:95
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:110
#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
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:99
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:97