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 <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
61 #include <blaze/util/Assert.h>
64 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/mpl/And.h>
66 #include <blaze/util/mpl/If.h>
67 #include <blaze/util/Types.h>
68 
69 
70 namespace blaze {
71 
72 //=================================================================================================
73 //
74 // CLASS DVECSERIALEXPR
75 //
76 //=================================================================================================
77 
78 //*************************************************************************************************
85 template< typename VT // Type of the dense vector
86  , bool TF > // Transpose flag
87 class DVecSerialExpr : public DenseVector< DVecSerialExpr<VT,TF>, TF >
88  , private VecSerialExpr
89  , private Computation
90 {
91  public:
92  //**Type definitions****************************************************************************
98 
100  typedef const ResultType CompositeType;
101 
103  typedef If_< IsExpression<VT>, const VT, const VT& > Operand;
104  //**********************************************************************************************
105 
106  //**Compilation flags***************************************************************************
108  enum : bool { simdEnabled = false };
109 
111  enum : bool { smpAssignable = VT::smpAssignable };
112  //**********************************************************************************************
113 
114  //**Constructor*********************************************************************************
119  explicit inline DVecSerialExpr( const VT& dv ) noexcept
120  : dv_( dv ) // Dense vector of the serial evaluation expression
121  {}
122  //**********************************************************************************************
123 
124  //**Subscript operator**************************************************************************
130  inline ReturnType operator[]( size_t index ) const {
131  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
132  return dv_[index];
133  }
134  //**********************************************************************************************
135 
136  //**At function*********************************************************************************
143  inline ReturnType at( size_t index ) const {
144  if( index >= dv_.size() ) {
145  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
146  }
147  return (*this)[index];
148  }
149  //**********************************************************************************************
150 
151  //**Size function*******************************************************************************
156  inline size_t size() const noexcept {
157  return dv_.size();
158  }
159  //**********************************************************************************************
160 
161  //**Operand access******************************************************************************
166  inline Operand operand() const noexcept {
167  return dv_;
168  }
169  //**********************************************************************************************
170 
171  //**Conversion operator*************************************************************************
176  inline operator Operand() const noexcept {
177  return dv_;
178  }
179  //**********************************************************************************************
180 
181  //**********************************************************************************************
187  template< typename T >
188  inline bool canAlias( const T* alias ) const noexcept {
189  return dv_.canAlias( alias );
190  }
191  //**********************************************************************************************
192 
193  //**********************************************************************************************
199  template< typename T >
200  inline bool isAliased( const T* alias ) const noexcept {
201  return dv_.isAliased( alias );
202  }
203  //**********************************************************************************************
204 
205  //**********************************************************************************************
210  inline bool isAligned() const noexcept {
211  return dv_.isAligned();
212  }
213  //**********************************************************************************************
214 
215  //**********************************************************************************************
220  inline bool canSMPAssign() const noexcept {
221  return dv_.canSMPAssign();
222  }
223  //**********************************************************************************************
224 
225  private:
226  //**Member variables****************************************************************************
227  Operand dv_;
228  //**********************************************************************************************
229 
230  //**Assignment to dense vectors*****************************************************************
242  template< typename VT2 > // Type of the target dense vector
243  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
244  {
246 
247  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
248 
249  assign( ~lhs, rhs.dv_ );
250  }
252  //**********************************************************************************************
253 
254  //**Assignment to sparse vectors****************************************************************
266  template< typename VT2 > // Type of the target sparse vector
267  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
268  {
270 
271  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
272 
273  assign( ~lhs, rhs.dv_ );
274  }
276  //**********************************************************************************************
277 
278  //**Addition assignment to dense vectors********************************************************
290  template< typename VT2 > // Type of the target dense vector
291  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
292  {
294 
295  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
296 
297  addAssign( ~lhs, rhs.dv_ );
298  }
300  //**********************************************************************************************
301 
302  //**Addition assignment to sparse vectors*******************************************************
314  template< typename VT2 > // Type of the target sparse vector
315  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
316  {
318 
319  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
320 
321  addAssign( ~lhs, rhs.dv_ );
322  }
324  //**********************************************************************************************
325 
326  //**Subtraction assignment to dense vectors*****************************************************
339  template< typename VT2 > // Type of the target dense vector
340  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
341  {
343 
344  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
345 
346  subAssign( ~lhs, rhs.dv_ );
347  }
349  //**********************************************************************************************
350 
351  //**Subtraction assignment to sparse vectors****************************************************
364  template< typename VT2 > // Type of the target sparse vector
365  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
366  {
368 
369  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
370 
371  subAssign( ~lhs, rhs.dv_ );
372  }
374  //**********************************************************************************************
375 
376  //**Multiplication assignment to dense vectors**************************************************
389  template< typename VT2 > // Type of the target dense vector
390  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
391  {
393 
394  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
395 
396  multAssign( ~lhs, rhs.dv_ );
397  }
399  //**********************************************************************************************
400 
401  //**Multiplication assignment to sparse vectors*************************************************
414  template< typename VT2 > // Type of the target sparse vector
415  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
416  {
418 
419  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
420 
421  multAssign( ~lhs, rhs.dv_ );
422  }
424  //**********************************************************************************************
425 
426  //**Division assignment to dense vectors********************************************************
438  template< typename VT2 > // Type of the target dense vector
439  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
440  {
442 
443  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
444 
445  divAssign( ~lhs, rhs.dv_ );
446  }
448  //**********************************************************************************************
449 
450  //**Division assignment to sparse vectors*******************************************************
462  template< typename VT2 > // Type of the target sparse vector
463  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
464  {
466 
467  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
468 
469  divAssign( ~lhs, rhs.dv_ );
470  }
472  //**********************************************************************************************
473 
474  //**SMP assignment to dense vectors*************************************************************
486  template< typename VT2 > // Type of the target dense vector
487  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
488  {
490 
491  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
492 
493  assign( ~lhs, rhs.dv_ );
494  }
496  //**********************************************************************************************
497 
498  //**SMP assignment to sparse vectors************************************************************
510  template< typename VT2 > // Type of the target sparse vector
511  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
512  {
514 
515  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
516 
517  assign( ~lhs, rhs.dv_ );
518  }
520  //**********************************************************************************************
521 
522  //**SMP addition assignment to dense vectors****************************************************
535  template< typename VT2 > // Type of the target dense vector
536  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
537  {
539 
540  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
541 
542  addAssign( ~lhs, rhs.dv_ );
543  }
545  //**********************************************************************************************
546 
547  //**SMP addition assignment to sparse vectors***************************************************
560  template< typename VT2 > // Type of the target sparse vector
561  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
562  {
564 
565  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
566 
567  addAssign( ~lhs, rhs.dv_ );
568  }
570  //**********************************************************************************************
571 
572  //**SMP subtraction assignment to dense vectors*************************************************
585  template< typename VT2 > // Type of the target dense vector
586  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
587  {
589 
590  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
591 
592  subAssign( ~lhs, rhs.dv_ );
593  }
595  //**********************************************************************************************
596 
597  //**SMP subtraction assignment to sparse vectors************************************************
610  template< typename VT2 > // Type of the target sparse vector
611  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
612  {
614 
615  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
616 
617  subAssign( ~lhs, rhs.dv_ );
618  }
620  //**********************************************************************************************
621 
622  //**SMP multiplication assignment to dense vectors**********************************************
635  template< typename VT2 > // Type of the target dense vector
636  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
637  {
639 
640  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
641 
642  multAssign( ~lhs, rhs.dv_ );
643  }
645  //**********************************************************************************************
646 
647  //**SMP multiplication assignment to sparse vectors*********************************************
660  template< typename VT2 > // Type of the target sparse vector
661  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
662  {
664 
665  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
666 
667  multAssign( ~lhs, rhs.dv_ );
668  }
670  //**********************************************************************************************
671 
672  //**SMP division assignment to dense vectors****************************************************
685  template< typename VT2 > // Type of the target dense vector
686  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
687  {
689 
690  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
691 
692  divAssign( ~lhs, rhs.dv_ );
693  }
695  //**********************************************************************************************
696 
697  //**SMP division assignment to sparse vectors***************************************************
710  template< typename VT2 > // Type of the target sparse vector
711  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
712  {
714 
715  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
716 
717  divAssign( ~lhs, rhs.dv_ );
718  }
720  //**********************************************************************************************
721 
722  //**Compile time checks*************************************************************************
727  //**********************************************************************************************
728 };
729 //*************************************************************************************************
730 
731 
732 
733 
734 //=================================================================================================
735 //
736 // GLOBAL FUNCTIONS
737 //
738 //=================================================================================================
739 
740 //*************************************************************************************************
757 template< typename VT // Type of the dense vector
758  , bool TF > // Transpose flag
760 {
762 
763  return DVecSerialExpr<VT,TF>( ~dv );
764 }
765 //*************************************************************************************************
766 
767 
768 
769 
770 //=================================================================================================
771 //
772 // GLOBAL RESTRUCTURING FUNCTIONS
773 //
774 //=================================================================================================
775 
776 //*************************************************************************************************
787 template< typename VT // Type of the dense vector
788  , bool TF > // Transpose flag
789 inline const DVecSerialExpr<VT,TF> serial( const DVecSerialExpr<VT,TF>& dv )
790 {
791  return dv;
792 }
794 //*************************************************************************************************
795 
796 
797 
798 
799 //=================================================================================================
800 //
801 // SIZE SPECIALIZATIONS
802 //
803 //=================================================================================================
804 
805 //*************************************************************************************************
807 template< typename VT, bool TF >
808 struct Size< DVecSerialExpr<VT,TF> > : public Size<VT>
809 {};
811 //*************************************************************************************************
812 
813 
814 
815 
816 //=================================================================================================
817 //
818 // ISALIGNED SPECIALIZATIONS
819 //
820 //=================================================================================================
821 
822 //*************************************************************************************************
824 template< typename VT, bool TF >
825 struct IsAligned< DVecSerialExpr<VT,TF> >
826  : public BoolConstant< IsAligned<VT>::value >
827 {};
829 //*************************************************************************************************
830 
831 
832 
833 
834 //=================================================================================================
835 //
836 // EXPRESSION TRAIT SPECIALIZATIONS
837 //
838 //=================================================================================================
839 
840 //*************************************************************************************************
842 template< typename VT >
843 struct DVecSerialExprTrait< DVecSerialExpr<VT,false> >
844 {
845  public:
846  //**********************************************************************************************
849  , INVALID_TYPE >;
850  //**********************************************************************************************
851 };
853 //*************************************************************************************************
854 
855 
856 //*************************************************************************************************
858 template< typename VT >
859 struct TDVecSerialExprTrait< DVecSerialExpr<VT,true> >
860 {
861  public:
862  //**********************************************************************************************
865  , INVALID_TYPE >;
866  //**********************************************************************************************
867 };
869 //*************************************************************************************************
870 
871 
872 //*************************************************************************************************
874 template< typename VT, bool TF, bool AF >
875 struct SubvectorExprTrait< DVecSerialExpr<VT,TF>, AF >
876 {
877  public:
878  //**********************************************************************************************
880  //**********************************************************************************************
881 };
883 //*************************************************************************************************
884 
885 } // namespace blaze
886 
887 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:87
Compile time check for row vector types.This type trait tests whether or not the given template argum...
Definition: IsRowVector.h:80
Header file for the TDVecSerialExprTrait class template.
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:96
Header file for auxiliary alias declarations.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: DVecSerialExpr.h:130
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:79
Header file for basic type definitions.
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
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:95
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:100
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:721
Header file for the Computation base class.
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:227
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
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecSerialExpr.h:166
Compile time check for the alignment of data types.This type trait tests whether the given data type ...
Definition: IsAligned.h:87
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: DVecSerialExpr.h:220
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: DVecSerialExpr.h:188
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
Evaluation of the expression type of a dense vector serial evaluation operation.Via this type trait i...
Definition: DVecSerialExprTrait.h:74
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:94
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.
Header file for the SerialExprTrait class template.
Constraint on the data type.
Compile time check for column vector types.This type trait tests whether or not the given template ar...
Definition: IsColumnVector.h:80
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:119
Header file for the VecSerialExpr base class.
bool isAligned() const noexcept
Returns whether the operands of the expression are properly aligned in memory.
Definition: DVecSerialExpr.h:210
Evaluation of the expression type of a dense vector serial evaluation operation.Via this type trait i...
Definition: TDVecSerialExprTrait.h:74
Header file for run time assertion macros.
Utility type for generic codes.
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:200
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
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:93
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:103
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:156
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:97
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:59
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:75
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:143
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:120
Header file for the IntegralConstant class template.
Header file for the SubvectorExprTrait class template.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
Header file for the IsColumnVector type trait.
DVecSerialExpr< VT, TF > This
Type of this DVecSerialExpr instance.
Definition: DVecSerialExpr.h:93
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
typename SerialExprTrait< T >::Type SerialExprTrait_
Auxiliary alias declaration for the SerialExprTrait class template.The SerialExprTrait_ alias declara...
Definition: SerialExprTrait.h:142
Header file for the IsExpression type trait class.
Header file for the function trace functionality.