DVecSerialExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECSERIALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DVECSERIALEXPR_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 DVECSERIALEXPR
77 //
78 //=================================================================================================
79 
80 //*************************************************************************************************
87 template< typename VT // Type of the dense vector
88  , bool TF > // Transpose flag
89 class DVecSerialExpr : public DenseVector< DVecSerialExpr<VT,TF>, TF >
90  , private VecSerialExpr
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 DVecSerialExpr( const VT& dv ) noexcept
122  : dv_( dv ) // Dense vector of the serial 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  //**Conversion operator*************************************************************************
178  inline operator Operand() const noexcept {
179  return dv_;
180  }
181  //**********************************************************************************************
182 
183  //**********************************************************************************************
189  template< typename T >
190  inline bool canAlias( const T* alias ) const noexcept {
191  return dv_.canAlias( alias );
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
201  template< typename T >
202  inline bool isAliased( const T* alias ) const noexcept {
203  return dv_.isAliased( alias );
204  }
205  //**********************************************************************************************
206 
207  //**********************************************************************************************
212  inline bool isAligned() const noexcept {
213  return dv_.isAligned();
214  }
215  //**********************************************************************************************
216 
217  //**********************************************************************************************
222  inline bool canSMPAssign() const noexcept {
223  return dv_.canSMPAssign();
224  }
225  //**********************************************************************************************
226 
227  private:
228  //**Member variables****************************************************************************
229  Operand dv_;
230  //**********************************************************************************************
231 
232  //**Assignment to dense vectors*****************************************************************
244  template< typename VT2 > // Type of the target dense vector
245  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
246  {
248 
249  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
250 
251  assign( ~lhs, rhs.dv_ );
252  }
254  //**********************************************************************************************
255 
256  //**Assignment to sparse vectors****************************************************************
268  template< typename VT2 > // Type of the target sparse vector
269  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
270  {
272 
273  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
274 
275  assign( ~lhs, rhs.dv_ );
276  }
278  //**********************************************************************************************
279 
280  //**Addition assignment to dense vectors********************************************************
292  template< typename VT2 > // Type of the target dense vector
293  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
294  {
296 
297  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
298 
299  addAssign( ~lhs, rhs.dv_ );
300  }
302  //**********************************************************************************************
303 
304  //**Addition assignment to sparse vectors*******************************************************
316  template< typename VT2 > // Type of the target sparse vector
317  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
318  {
320 
321  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
322 
323  addAssign( ~lhs, rhs.dv_ );
324  }
326  //**********************************************************************************************
327 
328  //**Subtraction assignment to dense vectors*****************************************************
341  template< typename VT2 > // Type of the target dense vector
342  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
343  {
345 
346  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
347 
348  subAssign( ~lhs, rhs.dv_ );
349  }
351  //**********************************************************************************************
352 
353  //**Subtraction assignment to sparse vectors****************************************************
366  template< typename VT2 > // Type of the target sparse vector
367  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
368  {
370 
371  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
372 
373  subAssign( ~lhs, rhs.dv_ );
374  }
376  //**********************************************************************************************
377 
378  //**Multiplication assignment to dense vectors**************************************************
391  template< typename VT2 > // Type of the target dense vector
392  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
393  {
395 
396  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
397 
398  multAssign( ~lhs, rhs.dv_ );
399  }
401  //**********************************************************************************************
402 
403  //**Multiplication assignment to sparse vectors*************************************************
416  template< typename VT2 > // Type of the target sparse vector
417  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
418  {
420 
421  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
422 
423  multAssign( ~lhs, rhs.dv_ );
424  }
426  //**********************************************************************************************
427 
428  //**Division assignment to dense vectors********************************************************
440  template< typename VT2 > // Type of the target dense vector
441  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
442  {
444 
445  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
446 
447  divAssign( ~lhs, rhs.dv_ );
448  }
450  //**********************************************************************************************
451 
452  //**Division assignment to sparse vectors*******************************************************
464  template< typename VT2 > // Type of the target sparse vector
465  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
466  {
468 
469  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
470 
471  divAssign( ~lhs, rhs.dv_ );
472  }
474  //**********************************************************************************************
475 
476  //**SMP assignment to dense vectors*************************************************************
488  template< typename VT2 > // Type of the target dense vector
489  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
490  {
492 
493  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
494 
495  assign( ~lhs, rhs.dv_ );
496  }
498  //**********************************************************************************************
499 
500  //**SMP assignment to sparse vectors************************************************************
512  template< typename VT2 > // Type of the target sparse vector
513  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
514  {
516 
517  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
518 
519  assign( ~lhs, rhs.dv_ );
520  }
522  //**********************************************************************************************
523 
524  //**SMP addition assignment to dense vectors****************************************************
537  template< typename VT2 > // Type of the target dense vector
538  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
539  {
541 
542  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
543 
544  addAssign( ~lhs, rhs.dv_ );
545  }
547  //**********************************************************************************************
548 
549  //**SMP addition assignment to sparse vectors***************************************************
562  template< typename VT2 > // Type of the target sparse vector
563  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
564  {
566 
567  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
568 
569  addAssign( ~lhs, rhs.dv_ );
570  }
572  //**********************************************************************************************
573 
574  //**SMP subtraction assignment to dense vectors*************************************************
587  template< typename VT2 > // Type of the target dense vector
588  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
589  {
591 
592  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
593 
594  subAssign( ~lhs, rhs.dv_ );
595  }
597  //**********************************************************************************************
598 
599  //**SMP subtraction assignment to sparse vectors************************************************
612  template< typename VT2 > // Type of the target sparse vector
613  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
614  {
616 
617  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
618 
619  subAssign( ~lhs, rhs.dv_ );
620  }
622  //**********************************************************************************************
623 
624  //**SMP multiplication assignment to dense vectors**********************************************
637  template< typename VT2 > // Type of the target dense vector
638  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
639  {
641 
642  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
643 
644  multAssign( ~lhs, rhs.dv_ );
645  }
647  //**********************************************************************************************
648 
649  //**SMP multiplication assignment to sparse vectors*********************************************
662  template< typename VT2 > // Type of the target sparse vector
663  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
664  {
666 
667  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
668 
669  multAssign( ~lhs, rhs.dv_ );
670  }
672  //**********************************************************************************************
673 
674  //**SMP division assignment to dense vectors****************************************************
687  template< typename VT2 > // Type of the target dense vector
688  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
689  {
691 
692  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
693 
694  divAssign( ~lhs, rhs.dv_ );
695  }
697  //**********************************************************************************************
698 
699  //**SMP division assignment to sparse vectors***************************************************
712  template< typename VT2 > // Type of the target sparse vector
713  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
714  {
716 
717  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
718 
719  divAssign( ~lhs, rhs.dv_ );
720  }
722  //**********************************************************************************************
723 
724  //**Compile time checks*************************************************************************
729  //**********************************************************************************************
730 };
731 //*************************************************************************************************
732 
733 
734 
735 
736 //=================================================================================================
737 //
738 // GLOBAL FUNCTIONS
739 //
740 //=================================================================================================
741 
742 //*************************************************************************************************
759 template< typename VT // Type of the dense vector
760  , bool TF > // Transpose flag
762 {
764 
765  return DVecSerialExpr<VT,TF>( ~dv );
766 }
767 //*************************************************************************************************
768 
769 
770 
771 
772 //=================================================================================================
773 //
774 // GLOBAL RESTRUCTURING FUNCTIONS
775 //
776 //=================================================================================================
777 
778 //*************************************************************************************************
789 template< typename VT // Type of the dense vector
790  , bool TF > // Transpose flag
791 inline const DVecSerialExpr<VT,TF> serial( const DVecSerialExpr<VT,TF>& dv )
792 {
793  return dv;
794 }
796 //*************************************************************************************************
797 
798 
799 
800 
801 //=================================================================================================
802 //
803 // SIZE SPECIALIZATIONS
804 //
805 //=================================================================================================
806 
807 //*************************************************************************************************
809 template< typename VT, bool TF >
810 struct Size< DVecSerialExpr<VT,TF> > : public Size<VT>
811 {};
813 //*************************************************************************************************
814 
815 
816 
817 
818 //=================================================================================================
819 //
820 // ISALIGNED SPECIALIZATIONS
821 //
822 //=================================================================================================
823 
824 //*************************************************************************************************
826 template< typename VT, bool TF >
827 struct IsAligned< DVecSerialExpr<VT,TF> >
828  : public BoolConstant< IsAligned<VT>::value >
829 {};
831 //*************************************************************************************************
832 
833 
834 
835 
836 //=================================================================================================
837 //
838 // EXPRESSION TRAIT SPECIALIZATIONS
839 //
840 //=================================================================================================
841 
842 //*************************************************************************************************
844 template< typename VT >
845 struct DVecSerialExprTrait< DVecSerialExpr<VT,false> >
846 {
847  public:
848  //**********************************************************************************************
849  using Type = If_< And< IsDenseVector<VT>, IsColumnVector<VT> >
850  , DVecSerialExpr<VT,false>
851  , INVALID_TYPE >;
852  //**********************************************************************************************
853 };
855 //*************************************************************************************************
856 
857 
858 //*************************************************************************************************
860 template< typename VT >
861 struct TDVecSerialExprTrait< DVecSerialExpr<VT,true> >
862 {
863  public:
864  //**********************************************************************************************
865  using Type = If_< And< IsDenseVector<VT>, IsRowVector<VT> >
866  , DVecSerialExpr<VT,true>
867  , INVALID_TYPE >;
868  //**********************************************************************************************
869 };
871 //*************************************************************************************************
872 
873 
874 //*************************************************************************************************
876 template< typename VT, bool TF, bool AF >
877 struct SubvectorExprTrait< DVecSerialExpr<VT,TF>, AF >
878 {
879  public:
880  //**********************************************************************************************
881  using Type = SerialExprTrait_< SubvectorExprTrait_<const VT,AF> >;
882  //**********************************************************************************************
883 };
885 //*************************************************************************************************
886 
887 } // namespace blaze
888 
889 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:89
Header file for the TDVecSerialExprTrait class template.
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:98
Header file for auxiliary alias declarations.
Header file for basic type definitions.
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
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecSerialExpr.h:190
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:97
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecSerialExpr.h:168
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:102
Base class for all vector serial evaluation expression templates.The VecSerialExpr class serves as a ...
Definition: VecSerialExpr.h:65
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.
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:723
Header file for the Computation base class.
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:229
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
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecSerialExpr.h:222
Constraint on the data type.
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
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
#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
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:96
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:145
Header file for the IsAligned type trait.
Header file for the SerialExprTrait class template.
Constraint on the data type.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecSerialExpr.h:212
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:158
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.
DVecSerialExpr(const VT &dv) noexcept
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:121
Header file for the VecSerialExpr base class.
Header file for run time assertion macros.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:202
Utility type for generic codes.
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
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:100
If_< IsExpression< VT >, const VT, const VT & > Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:105
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
Header file for the DVecSerialExprTrait class template.
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:99
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.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSerialExpr.h:132
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.
DVecSerialExpr< VT, TF > This
Type of this DVecSerialExpr instance.
Definition: DVecSerialExpr.h:95
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.
Header file for the FunctionTrace class.