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>
56 #include <blaze/util/mpl/If.h>
57 #include <blaze/util/Types.h>
58 
59 
60 namespace blaze {
61 
62 //=================================================================================================
63 //
64 // CLASS DVECSERIALEXPR
65 //
66 //=================================================================================================
67 
68 //*************************************************************************************************
75 template< typename VT // Type of the dense vector
76  , bool TF > // Transpose flag
78  : public VecSerialExpr< DenseVector< DVecSerialExpr<VT,TF>, TF > >
79  , private Computation
80 {
81  public:
82  //**Type definitions****************************************************************************
88 
90  using CompositeType = const ResultType;
91 
93  using Operand = If_< IsExpression<VT>, const VT, const VT& >;
94  //**********************************************************************************************
95 
96  //**Compilation flags***************************************************************************
98  enum : bool { simdEnabled = false };
99 
101  enum : bool { smpAssignable = VT::smpAssignable };
102  //**********************************************************************************************
103 
104  //**Constructor*********************************************************************************
109  explicit inline DVecSerialExpr( const VT& dv ) noexcept
110  : dv_( dv ) // Dense vector of the serial 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  //**Conversion operator*************************************************************************
166  inline operator Operand() const noexcept {
167  return dv_;
168  }
169  //**********************************************************************************************
170 
171  //**********************************************************************************************
177  template< typename T >
178  inline bool canAlias( const T* alias ) const noexcept {
179  return dv_.canAlias( alias );
180  }
181  //**********************************************************************************************
182 
183  //**********************************************************************************************
189  template< typename T >
190  inline bool isAliased( const T* alias ) const noexcept {
191  return dv_.isAliased( alias );
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
200  inline bool isAligned() const noexcept {
201  return dv_.isAligned();
202  }
203  //**********************************************************************************************
204 
205  //**********************************************************************************************
210  inline bool canSMPAssign() const noexcept {
211  return dv_.canSMPAssign();
212  }
213  //**********************************************************************************************
214 
215  private:
216  //**Member variables****************************************************************************
218  //**********************************************************************************************
219 
220  //**Assignment to dense vectors*****************************************************************
232  template< typename VT2 > // Type of the target dense vector
233  friend inline void assign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
234  {
236 
237  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
238 
239  assign( ~lhs, rhs.dv_ );
240  }
242  //**********************************************************************************************
243 
244  //**Assignment to sparse vectors****************************************************************
256  template< typename VT2 > // Type of the target sparse vector
257  friend inline void assign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
258  {
260 
261  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
262 
263  assign( ~lhs, rhs.dv_ );
264  }
266  //**********************************************************************************************
267 
268  //**Addition assignment to dense vectors********************************************************
280  template< typename VT2 > // Type of the target dense vector
281  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
282  {
284 
285  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
286 
287  addAssign( ~lhs, rhs.dv_ );
288  }
290  //**********************************************************************************************
291 
292  //**Addition assignment to sparse vectors*******************************************************
304  template< typename VT2 > // Type of the target sparse vector
305  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
306  {
308 
309  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
310 
311  addAssign( ~lhs, rhs.dv_ );
312  }
314  //**********************************************************************************************
315 
316  //**Subtraction assignment to dense vectors*****************************************************
329  template< typename VT2 > // Type of the target dense vector
330  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
331  {
333 
334  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
335 
336  subAssign( ~lhs, rhs.dv_ );
337  }
339  //**********************************************************************************************
340 
341  //**Subtraction assignment to sparse vectors****************************************************
354  template< typename VT2 > // Type of the target sparse vector
355  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
356  {
358 
359  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
360 
361  subAssign( ~lhs, rhs.dv_ );
362  }
364  //**********************************************************************************************
365 
366  //**Multiplication assignment to dense vectors**************************************************
379  template< typename VT2 > // Type of the target dense vector
380  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
381  {
383 
384  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
385 
386  multAssign( ~lhs, rhs.dv_ );
387  }
389  //**********************************************************************************************
390 
391  //**Multiplication assignment to sparse vectors*************************************************
404  template< typename VT2 > // Type of the target sparse vector
405  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
406  {
408 
409  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
410 
411  multAssign( ~lhs, rhs.dv_ );
412  }
414  //**********************************************************************************************
415 
416  //**Division assignment to dense vectors********************************************************
428  template< typename VT2 > // Type of the target dense vector
429  friend inline void divAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
430  {
432 
433  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
434 
435  divAssign( ~lhs, rhs.dv_ );
436  }
438  //**********************************************************************************************
439 
440  //**Division assignment to sparse vectors*******************************************************
452  template< typename VT2 > // Type of the target sparse vector
453  friend inline void divAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
454  {
456 
457  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
458 
459  divAssign( ~lhs, rhs.dv_ );
460  }
462  //**********************************************************************************************
463 
464  //**SMP assignment to dense vectors*************************************************************
476  template< typename VT2 > // Type of the target dense vector
477  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
478  {
480 
481  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
482 
483  assign( ~lhs, rhs.dv_ );
484  }
486  //**********************************************************************************************
487 
488  //**SMP assignment to sparse vectors************************************************************
500  template< typename VT2 > // Type of the target sparse vector
501  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
502  {
504 
505  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
506 
507  assign( ~lhs, rhs.dv_ );
508  }
510  //**********************************************************************************************
511 
512  //**SMP addition assignment to dense vectors****************************************************
525  template< typename VT2 > // Type of the target dense vector
526  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
527  {
529 
530  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
531 
532  addAssign( ~lhs, rhs.dv_ );
533  }
535  //**********************************************************************************************
536 
537  //**SMP addition assignment to sparse vectors***************************************************
550  template< typename VT2 > // Type of the target sparse vector
551  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
552  {
554 
555  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
556 
557  addAssign( ~lhs, rhs.dv_ );
558  }
560  //**********************************************************************************************
561 
562  //**SMP subtraction assignment to dense vectors*************************************************
575  template< typename VT2 > // Type of the target dense vector
576  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
577  {
579 
580  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
581 
582  subAssign( ~lhs, rhs.dv_ );
583  }
585  //**********************************************************************************************
586 
587  //**SMP subtraction assignment to sparse vectors************************************************
600  template< typename VT2 > // Type of the target sparse vector
601  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
602  {
604 
605  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
606 
607  subAssign( ~lhs, rhs.dv_ );
608  }
610  //**********************************************************************************************
611 
612  //**SMP multiplication assignment to dense vectors**********************************************
625  template< typename VT2 > // Type of the target dense vector
626  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
627  {
629 
630  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
631 
632  multAssign( ~lhs, rhs.dv_ );
633  }
635  //**********************************************************************************************
636 
637  //**SMP multiplication assignment to sparse vectors*********************************************
650  template< typename VT2 > // Type of the target sparse vector
651  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
652  {
654 
655  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
656 
657  multAssign( ~lhs, rhs.dv_ );
658  }
660  //**********************************************************************************************
661 
662  //**SMP division assignment to dense vectors****************************************************
675  template< typename VT2 > // Type of the target dense vector
676  friend inline void smpDivAssign( DenseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
677  {
679 
680  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
681 
682  divAssign( ~lhs, rhs.dv_ );
683  }
685  //**********************************************************************************************
686 
687  //**SMP division assignment to sparse vectors***************************************************
700  template< typename VT2 > // Type of the target sparse vector
701  friend inline void smpDivAssign( SparseVector<VT2,TF>& lhs, const DVecSerialExpr& rhs )
702  {
704 
705  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
706 
707  divAssign( ~lhs, rhs.dv_ );
708  }
710  //**********************************************************************************************
711 
712  //**Compile time checks*************************************************************************
717  //**********************************************************************************************
718 };
719 //*************************************************************************************************
720 
721 
722 
723 
724 //=================================================================================================
725 //
726 // GLOBAL FUNCTIONS
727 //
728 //=================================================================================================
729 
730 //*************************************************************************************************
747 template< typename VT // Type of the dense vector
748  , bool TF > // Transpose flag
749 inline decltype(auto) serial( const DenseVector<VT,TF>& dv )
750 {
752 
753  using ReturnType = const DVecSerialExpr<VT,TF>;
754  return ReturnType( ~dv );
755 }
756 //*************************************************************************************************
757 
758 
759 
760 
761 //=================================================================================================
762 //
763 // GLOBAL RESTRUCTURING FUNCTIONS
764 //
765 //=================================================================================================
766 
767 //*************************************************************************************************
778 template< typename VT // Type of the dense vector
779  , bool TF > // Transpose flag
780 inline decltype(auto) serial( const DVecSerialExpr<VT,TF>& dv )
781 {
782  return dv;
783 }
785 //*************************************************************************************************
786 
787 
788 
789 
790 //=================================================================================================
791 //
792 // SIZE SPECIALIZATIONS
793 //
794 //=================================================================================================
795 
796 //*************************************************************************************************
798 template< typename VT, bool TF >
799 struct Size< DVecSerialExpr<VT,TF>, 0UL >
800  : public Size<VT,0UL>
801 {};
803 //*************************************************************************************************
804 
805 
806 
807 
808 //=================================================================================================
809 //
810 // ISALIGNED SPECIALIZATIONS
811 //
812 //=================================================================================================
813 
814 //*************************************************************************************************
816 template< typename VT, bool TF >
817 struct IsAligned< DVecSerialExpr<VT,TF> >
818  : public IsAligned<VT>
819 {};
821 //*************************************************************************************************
822 
823 } // namespace blaze
824 
825 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:77
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:120
Header file for basic type definitions.
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:84
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
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:217
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:93
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:156
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:210
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
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:178
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:76
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:87
DVecSerialExpr(const VT &dv) noexcept
Constructor for the DVecSerialExpr class.
Definition: DVecSerialExpr.h:109
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:200
Header file for run time assertion macros.
ElementType_< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:86
const ResultType CompositeType
Data type for composite expression templates.
Definition: DVecSerialExpr.h:90
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: DVecSerialExpr.h:190
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:85
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:816
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DVecSerialExpr.h:146
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
#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 vectors and matrices.The Size type trait evaluates the size of...
Definition: Size.h:80
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: DVecSerialExpr.h:133
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
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.