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>
54 #include <blaze/util/Assert.h>
57 #include <blaze/util/InvalidType.h>
58 #include <blaze/util/mpl/If.h>
59 #include <blaze/util/Types.h>
60 
61 
62 namespace blaze {
63 
64 //=================================================================================================
65 //
66 // CLASS DVECSERIALEXPR
67 //
68 //=================================================================================================
69 
70 //*************************************************************************************************
77 template< typename VT // Type of the dense vector
78  , bool TF > // Transpose flag
80  : public VecSerialExpr< DenseVector< DVecSerialExpr<VT,TF>, TF > >
81  , private Computation
82 {
83  public:
84  //**Type definitions****************************************************************************
90 
92  using CompositeType = const ResultType;
93 
95  using Operand = If_< IsExpression<VT>, const VT, const VT& >;
96  //**********************************************************************************************
97 
98  //**Compilation flags***************************************************************************
100  enum : bool { simdEnabled = false };
101 
103  enum : bool { smpAssignable = VT::smpAssignable };
104  //**********************************************************************************************
105 
106  //**Constructor*********************************************************************************
111  explicit inline DVecSerialExpr( const VT& dv ) noexcept
112  : dv_( dv ) // Dense vector of the serial evaluation expression
113  {}
114  //**********************************************************************************************
115 
116  //**Subscript operator**************************************************************************
122  inline ReturnType operator[]( size_t index ) const {
123  BLAZE_INTERNAL_ASSERT( index < dv_.size(), "Invalid vector access index" );
124  return dv_[index];
125  }
126  //**********************************************************************************************
127 
128  //**At function*********************************************************************************
135  inline ReturnType at( size_t index ) const {
136  if( index >= dv_.size() ) {
137  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
138  }
139  return (*this)[index];
140  }
141  //**********************************************************************************************
142 
143  //**Size function*******************************************************************************
148  inline size_t size() const noexcept {
149  return dv_.size();
150  }
151  //**********************************************************************************************
152 
153  //**Operand access******************************************************************************
158  inline Operand operand() const noexcept {
159  return dv_;
160  }
161  //**********************************************************************************************
162 
163  //**Conversion operator*************************************************************************
168  inline operator 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****************************************************************************
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 DVecSerialExpr& 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 DVecSerialExpr& 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 DVecSerialExpr& 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 DVecSerialExpr& 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*****************************************************
331  template< typename VT2 > // Type of the target dense vector
332  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
333  {
335 
336  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
337 
338  subAssign( ~lhs, rhs.dv_ );
339  }
341  //**********************************************************************************************
342 
343  //**Subtraction assignment to sparse vectors****************************************************
356  template< typename VT2 > // Type of the target sparse vector
357  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
358  {
360 
361  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
362 
363  subAssign( ~lhs, rhs.dv_ );
364  }
366  //**********************************************************************************************
367 
368  //**Multiplication assignment to dense vectors**************************************************
381  template< typename VT2 > // Type of the target dense vector
382  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
383  {
385 
386  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
387 
388  multAssign( ~lhs, rhs.dv_ );
389  }
391  //**********************************************************************************************
392 
393  //**Multiplication assignment to sparse vectors*************************************************
406  template< typename VT2 > // Type of the target sparse vector
407  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
408  {
410 
411  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
412 
413  multAssign( ~lhs, rhs.dv_ );
414  }
416  //**********************************************************************************************
417 
418  //**Division assignment to dense vectors********************************************************
430  template< typename VT2 > // Type of the target dense vector
431  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
432  {
434 
435  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
436 
437  divAssign( ~lhs, rhs.dv_ );
438  }
440  //**********************************************************************************************
441 
442  //**Division assignment to sparse vectors*******************************************************
454  template< typename VT2 > // Type of the target sparse vector
455  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
456  {
458 
459  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
460 
461  divAssign( ~lhs, rhs.dv_ );
462  }
464  //**********************************************************************************************
465 
466  //**SMP assignment to dense vectors*************************************************************
478  template< typename VT2 > // Type of the target dense vector
479  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
480  {
482 
483  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
484 
485  assign( ~lhs, rhs.dv_ );
486  }
488  //**********************************************************************************************
489 
490  //**SMP assignment to sparse vectors************************************************************
502  template< typename VT2 > // Type of the target sparse vector
503  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
504  {
506 
507  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
508 
509  assign( ~lhs, rhs.dv_ );
510  }
512  //**********************************************************************************************
513 
514  //**SMP addition assignment to dense vectors****************************************************
527  template< typename VT2 > // Type of the target dense vector
528  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
529  {
531 
532  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
533 
534  addAssign( ~lhs, rhs.dv_ );
535  }
537  //**********************************************************************************************
538 
539  //**SMP addition assignment to sparse vectors***************************************************
552  template< typename VT2 > // Type of the target sparse vector
553  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
554  {
556 
557  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
558 
559  addAssign( ~lhs, rhs.dv_ );
560  }
562  //**********************************************************************************************
563 
564  //**SMP subtraction assignment to dense vectors*************************************************
577  template< typename VT2 > // Type of the target dense vector
578  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
579  {
581 
582  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
583 
584  subAssign( ~lhs, rhs.dv_ );
585  }
587  //**********************************************************************************************
588 
589  //**SMP subtraction assignment to sparse vectors************************************************
602  template< typename VT2 > // Type of the target sparse vector
603  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
604  {
606 
607  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
608 
609  subAssign( ~lhs, rhs.dv_ );
610  }
612  //**********************************************************************************************
613 
614  //**SMP multiplication assignment to dense vectors**********************************************
627  template< typename VT2 > // Type of the target dense vector
628  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
629  {
631 
632  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
633 
634  multAssign( ~lhs, rhs.dv_ );
635  }
637  //**********************************************************************************************
638 
639  //**SMP multiplication assignment to sparse vectors*********************************************
652  template< typename VT2 > // Type of the target sparse vector
653  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
654  {
656 
657  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
658 
659  multAssign( ~lhs, rhs.dv_ );
660  }
662  //**********************************************************************************************
663 
664  //**SMP division assignment to dense vectors****************************************************
677  template< typename VT2 > // Type of the target dense vector
678  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
679  {
681 
682  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
683 
684  divAssign( ~lhs, rhs.dv_ );
685  }
687  //**********************************************************************************************
688 
689  //**SMP division assignment to sparse vectors***************************************************
702  template< typename VT2 > // Type of the target sparse vector
703  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
704  {
706 
707  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
708 
709  divAssign( ~lhs, rhs.dv_ );
710  }
712  //**********************************************************************************************
713 
714  //**Compile time checks*************************************************************************
719  //**********************************************************************************************
720 };
721 //*************************************************************************************************
722 
723 
724 
725 
726 //=================================================================================================
727 //
728 // GLOBAL FUNCTIONS
729 //
730 //=================================================================================================
731 
732 //*************************************************************************************************
749 template< typename VT // Type of the dense vector
750  , bool TF > // Transpose flag
751 inline decltype(auto) serial( const DenseVector<VT,TF>& dv )
752 {
754 
755  using ReturnType = const DVecSerialExpr<VT,TF>;
756  return ReturnType( ~dv );
757 }
758 //*************************************************************************************************
759 
760 
761 
762 
763 //=================================================================================================
764 //
765 // GLOBAL RESTRUCTURING FUNCTIONS
766 //
767 //=================================================================================================
768 
769 //*************************************************************************************************
780 template< typename VT // Type of the dense vector
781  , bool TF > // Transpose flag
782 inline decltype(auto) serial( const DVecSerialExpr<VT,TF>& dv )
783 {
784  return dv;
785 }
787 //*************************************************************************************************
788 
789 
790 
791 
792 //=================================================================================================
793 //
794 // SIZE SPECIALIZATIONS
795 //
796 //=================================================================================================
797 
798 //*************************************************************************************************
800 template< typename VT, bool TF >
801 struct Size< DVecSerialExpr<VT,TF> >
802  : public Size<VT>
803 {};
805 //*************************************************************************************************
806 
807 
808 
809 
810 //=================================================================================================
811 //
812 // ISALIGNED SPECIALIZATIONS
813 //
814 //=================================================================================================
815 
816 //*************************************************************************************************
818 template< typename VT, bool TF >
819 struct IsAligned< DVecSerialExpr<VT,TF> >
820  : public BoolConstant< IsAligned<VT>::value >
821 {};
823 //*************************************************************************************************
824 
825 } // namespace blaze
826 
827 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:79
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:122
Header file for basic type definitions.
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:86
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:164
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
Base class for all vector serial evaluation expression templates.The VecSerialExpr class serves as a ...
Definition: VecSerialExpr.h:67
EnableIf_< IsDenseVector< VT1 > > smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:193
Header file for the DenseVector base class.
Header file for the Computation base class.
Operand dv_
Dense vector of the serial evaluation expression.
Definition: DVecSerialExpr.h:219
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:133
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:95
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecSerialExpr.h:158
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:212
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:180
EnableIf_< IsDenseMatrix< MT1 > > smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:102
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Header file for the IsAligned type trait.
Constraint on the data type.
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.
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:89
DVecSerialExpr(const VT &dv) noexcept
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:111
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:202
Header file for run time assertion macros.
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:88
Utility type for generic codes.
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:92
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:192
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
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:94
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:87
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:819
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:148
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3082
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:61
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:74
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:135
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Header file for the IntegralConstant class template.
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
Header file for the Size type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the IsExpression type trait class.
Header file for the function trace functionality.