Blaze  3.6
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>
53 #include <blaze/util/Assert.h>
55 #include <blaze/util/mpl/If.h>
56 #include <blaze/util/Types.h>
57 
58 
59 namespace blaze {
60 
61 //=================================================================================================
62 //
63 // CLASS DVECEVALEXPR
64 //
65 //=================================================================================================
66 
67 //*************************************************************************************************
74 template< typename VT // Type of the dense vector
75  , bool TF > // Transpose flag
77  : public VecEvalExpr< DenseVector< DVecEvalExpr<VT,TF>, TF > >
78  , private Computation
79 {
80  public:
81  //**Type definitions****************************************************************************
88 
90  using CompositeType = const ResultType;
91 
93  using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
94  //**********************************************************************************************
95 
96  //**Compilation flags***************************************************************************
98  static constexpr bool simdEnabled = false;
99 
101  static constexpr bool smpAssignable = VT::smpAssignable;
102  //**********************************************************************************************
103 
104  //**Constructor*********************************************************************************
109  explicit inline DVecEvalExpr( const VT& dv ) noexcept
110  : dv_( dv ) // Dense vector of the evaluation expression
111  {}
112  //**********************************************************************************************
113 
114  //**Subscript operator**************************************************************************
120  inline ReturnType operator[]( size_t index ) const {
121  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
122  return dv_[index];
123  }
124  //**********************************************************************************************
125 
126  //**At function*********************************************************************************
133  inline ReturnType at( size_t index ) const {
134  if( index >= dv_.size() ) {
135  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
136  }
137  return (*this)[index];
138  }
139  //**********************************************************************************************
140 
141  //**Size function*******************************************************************************
146  inline size_t size() const noexcept {
147  return dv_.size();
148  }
149  //**********************************************************************************************
150 
151  //**Operand access******************************************************************************
156  inline Operand operand() const noexcept {
157  return dv_;
158  }
159  //**********************************************************************************************
160 
161  //**********************************************************************************************
167  template< typename T >
168  inline bool canAlias( const T* alias ) const noexcept {
169  return dv_.canAlias( alias );
170  }
171  //**********************************************************************************************
172 
173  //**********************************************************************************************
179  template< typename T >
180  inline bool isAliased( const T* alias ) const noexcept {
181  return dv_.isAliased( alias );
182  }
183  //**********************************************************************************************
184 
185  //**********************************************************************************************
190  inline bool isAligned() const noexcept {
191  return dv_.isAligned();
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
200  inline bool canSMPAssign() const noexcept {
201  return dv_.canSMPAssign();
202  }
203  //**********************************************************************************************
204 
205  private:
206  //**Member variables****************************************************************************
208  //**********************************************************************************************
209 
210  //**Assignment to dense vectors*****************************************************************
222  template< typename VT2 > // Type of the target dense vector
223  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
224  {
226 
227  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
228 
229  assign( ~lhs, rhs.dv_ );
230  }
232  //**********************************************************************************************
233 
234  //**Assignment to sparse vectors****************************************************************
246  template< typename VT2 > // Type of the target sparse vector
247  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
248  {
250 
251  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
252 
253  assign( ~lhs, rhs.dv_ );
254  }
256  //**********************************************************************************************
257 
258  //**Addition assignment to dense vectors********************************************************
270  template< typename VT2 > // Type of the target dense vector
271  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
272  {
274 
275  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
276 
277  addAssign( ~lhs, rhs.dv_ );
278  }
280  //**********************************************************************************************
281 
282  //**Addition assignment to sparse vectors*******************************************************
294  template< typename VT2 > // Type of the target sparse vector
295  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
296  {
298 
299  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
300 
301  addAssign( ~lhs, rhs.dv_ );
302  }
304  //**********************************************************************************************
305 
306  //**Subtraction assignment to dense vectors*****************************************************
318  template< typename VT2 > // Type of the target dense vector
319  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
320  {
322 
323  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
324 
325  subAssign( ~lhs, rhs.dv_ );
326  }
328  //**********************************************************************************************
329 
330  //**Subtraction assignment to sparse vectors****************************************************
342  template< typename VT2 > // Type of the target sparse vector
343  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
344  {
346 
347  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
348 
349  subAssign( ~lhs, rhs.dv_ );
350  }
352  //**********************************************************************************************
353 
354  //**Multiplication assignment to dense vectors**************************************************
366  template< typename VT2 > // Type of the target dense vector
367  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
368  {
370 
371  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
372 
373  multAssign( ~lhs, rhs.dv_ );
374  }
376  //**********************************************************************************************
377 
378  //**Multiplication assignment to sparse vectors*************************************************
390  template< typename VT2 > // Type of the target sparse vector
391  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
392  {
394 
395  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
396 
397  multAssign( ~lhs, rhs.dv_ );
398  }
400  //**********************************************************************************************
401 
402  //**Division assignment to dense vectors********************************************************
414  template< typename VT2 > // Type of the target dense vector
415  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
416  {
418 
419  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
420 
421  divAssign( ~lhs, rhs.dv_ );
422  }
424  //**********************************************************************************************
425 
426  //**Division assignment to sparse vectors*******************************************************
438  template< typename VT2 > // Type of the target sparse vector
439  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
440  {
442 
443  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
444 
445  divAssign( ~lhs, rhs.dv_ );
446  }
448  //**********************************************************************************************
449 
450  //**SMP assignment to dense vectors*************************************************************
462  template< typename VT2 > // Type of the target dense vector
463  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
464  {
466 
467  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
468 
469  smpAssign( ~lhs, rhs.dv_ );
470  }
472  //**********************************************************************************************
473 
474  //**SMP assignment to sparse vectors************************************************************
486  template< typename VT2 > // Type of the target sparse vector
487  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
488  {
490 
491  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
492 
493  smpAssign( ~lhs, rhs.dv_ );
494  }
496  //**********************************************************************************************
497 
498  //**SMP addition assignment to dense vectors****************************************************
510  template< typename VT2 > // Type of the target dense vector
511  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
512  {
514 
515  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
516 
517  smpAddAssign( ~lhs, rhs.dv_ );
518  }
520  //**********************************************************************************************
521 
522  //**SMP addition assignment to sparse vectors***************************************************
534  template< typename VT2 > // Type of the target sparse vector
535  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
536  {
538 
539  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
540 
541  smpAddAssign( ~lhs, rhs.dv_ );
542  }
544  //**********************************************************************************************
545 
546  //**SMP subtraction assignment to dense vectors*************************************************
558  template< typename VT2 > // Type of the target dense vector
559  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
560  {
562 
563  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
564 
565  smpSubAssign( ~lhs, rhs.dv_ );
566  }
568  //**********************************************************************************************
569 
570  //**SMP subtraction assignment to sparse vectors************************************************
582  template< typename VT2 > // Type of the target sparse vector
583  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
584  {
586 
587  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
588 
589  smpSubAssign( ~lhs, rhs.dv_ );
590  }
592  //**********************************************************************************************
593 
594  //**SMP multiplication assignment to dense vectors**********************************************
606  template< typename VT2 > // Type of the target dense vector
607  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
608  {
610 
611  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
612 
613  smpMultAssign( ~lhs, rhs.dv_ );
614  }
616  //**********************************************************************************************
617 
618  //**SMP multiplication assignment to sparse vectors*********************************************
630  template< typename VT2 > // Type of the target sparse vector
631  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
632  {
634 
635  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
636 
637  smpMultAssign( ~lhs, rhs.dv_ );
638  }
640  //**********************************************************************************************
641 
642  //**SMP division assignment to dense vectors****************************************************
654  template< typename VT2 > // Type of the target dense vector
655  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
656  {
658 
659  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
660 
661  smpDivAssign( ~lhs, rhs.dv_ );
662  }
664  //**********************************************************************************************
665 
666  //**SMP division assignment to sparse vectors***************************************************
678  template< typename VT2 > // Type of the target sparse vector
679  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecEvalExpr& rhs )
680  {
682 
683  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
684 
685  smpDivAssign( ~lhs, rhs.dv_ );
686  }
688  //**********************************************************************************************
689 
690  //**Compile time checks*************************************************************************
695  //**********************************************************************************************
696 };
697 //*************************************************************************************************
698 
699 
700 
701 
702 //=================================================================================================
703 //
704 // GLOBAL FUNCTIONS
705 //
706 //=================================================================================================
707 
708 //*************************************************************************************************
725 template< typename VT // Type of the dense vector
726  , bool TF > // Transpose flag
727 inline decltype(auto) eval( const DenseVector<VT,TF>& dv )
728 {
730 
731  using ReturnType = const DVecEvalExpr<VT,TF>;
732  return ReturnType( ~dv );
733 }
734 //*************************************************************************************************
735 
736 
737 
738 
739 //=================================================================================================
740 //
741 // GLOBAL RESTRUCTURING FUNCTIONS
742 //
743 //=================================================================================================
744 
745 //*************************************************************************************************
756 template< typename VT // Type of the dense vector
757  , bool TF > // Transpose flag
758 inline decltype(auto) eval( const DVecEvalExpr<VT,TF>& dv )
759 {
760  return dv;
761 }
763 //*************************************************************************************************
764 
765 
766 
767 
768 //=================================================================================================
769 //
770 // ISALIGNED SPECIALIZATIONS
771 //
772 //=================================================================================================
773 
774 //*************************************************************************************************
776 template< typename VT, bool TF >
777 struct IsAligned< DVecEvalExpr<VT,TF> >
778  : public IsAligned<VT>
779 {};
781 //*************************************************************************************************
782 
783 } // namespace blaze
784 
785 #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:120
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
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecEvalExpr.h:84
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
Header file for the DenseVector base class.
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecEvalExpr.h:156
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecEvalExpr.h:146
Header file for the Computation base class.
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecEvalExpr.h:200
Header file for the VecEvalExpr base class.
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
auto smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:220
Operand dv_
Dense vector of the evaluation expression.
Definition: DVecEvalExpr.h:207
Expression object for the forced evaluation of dense vectors.The DVecEvalExpr class represents the co...
Definition: DVecEvalExpr.h:76
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecEvalExpr.h:180
#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
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
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:786
Constraint on the data type.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecEvalExpr.h:101
Header file for the exception macros of the math module.
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecEvalExpr.h:98
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecEvalExpr.h:86
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
If_t< IsExpression_v< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecEvalExpr.h:93
DVecEvalExpr(const VT &dv) noexcept
Constructor for the DVecEvalExpr class.
Definition: DVecEvalExpr.h:109
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecEvalExpr.h:190
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecEvalExpr.h:133
ReturnType_t< VT > ReturnType
Return 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
Header file for all forward declarations for expression class templates.
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
#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
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecEvalExpr.h:168
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:146
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecEvalExpr.h:85
#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,...
Definition: Assert.h:101
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector.
Definition: DenseVector.h:191
Header file for the IsExpression type trait class.
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecEvalExpr.h:90
Header file for the function trace functionality.