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>
53 #include <blaze/util/Assert.h>
55 #include <blaze/util/mpl/If.h>
56 #include <blaze/util/Types.h>
57 
58 
59 namespace blaze {
60 
61 //=================================================================================================
62 //
63 // CLASS DVECSERIALEXPR
64 //
65 //=================================================================================================
66 
67 //*************************************************************************************************
74 template< typename VT // Type of the dense vector
75  , bool TF > // Transpose flag
77  : public VecSerialExpr< DenseVector< DVecSerialExpr<VT,TF>, TF > >
78  , private Computation
79 {
80  public:
81  //**Type definitions****************************************************************************
88 
90  using CompositeType = const ResultType;
91 
93  using Operand = If_t< IsExpression_v<VT>, const VT, const VT& >;
94  //**********************************************************************************************
95 
96  //**Compilation flags***************************************************************************
98  static constexpr bool simdEnabled = false;
99 
101  static constexpr bool smpAssignable = VT::smpAssignable;
102  //**********************************************************************************************
103 
104  //**Constructor*********************************************************************************
109  explicit inline 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 // ISALIGNED SPECIALIZATIONS
793 //
794 //=================================================================================================
795 
796 //*************************************************************************************************
798 template< typename VT, bool TF >
799 struct IsAligned< DVecSerialExpr<VT,TF> >
800  : public IsAligned<VT>
801 {};
803 //*************************************************************************************************
804 
805 } // namespace blaze
806 
807 #endif
Expression object for the forced serial evaluation of dense vectors.The DVecSerialExpr class represen...
Definition: DVecSerialExpr.h:76
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
If_t< IsExpression_v< VT >, const VT, const VT &> Operand
Composite data type of the dense vector expression.
Definition: DVecSerialExpr.h:93
Header file for basic type definitions.
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias declaration for the If class template.The If_t alias declaration provides a convenien...
Definition: If.h:109
ResultType_t< VT > ResultType
Result type for expression template evaluations.
Definition: DVecSerialExpr.h:84
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.The ResultType_t alias declaration provides ...
Definition: Aliases.h:390
static constexpr bool simdEnabled
Compilation switch for the expression template evaluation strategy.
Definition: DVecSerialExpr.h:98
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Base class for all vector serial evaluation expression templates.The VecSerialExpr class serves as a ...
Definition: VecSerialExpr.h:67
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::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.The ReturnType_t alias declaration provides ...
Definition: Aliases.h:410
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.The ElementType_t alias declaration provide...
Definition: Aliases.h:170
auto smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:220
Operand operand() const noexcept
Returns the dense vector operand.
Definition: DVecSerialExpr.h:156
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
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the IsAligned type trait.
Constraint on the data type.
static constexpr bool smpAssignable
Compilation switch for the expression template assignment strategy.
Definition: DVecSerialExpr.h:101
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: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
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.The TransposeType_t alias declaration pro...
Definition: Aliases.h:470
Header file for run time assertion macros.
TransposeType_t< VT > TransposeType
Transpose type for expression template evaluations.
Definition: DVecSerialExpr.h:85
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
auto smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:131
#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
auto smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:100
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
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:3081
#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
ElementType_t< VT > ElementType
Resulting element type.
Definition: DVecSerialExpr.h:86
ReturnType_t< VT > ReturnType
Return type for expression template evaluations.
Definition: DVecSerialExpr.h:87
auto smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs) -> EnableIf_t< IsDenseMatrix_v< MT1 > >
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:162
Base class for all compute expression templates.The Computation class serves as a tag for all computa...
Definition: Computation.h:66
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:138
#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
auto smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs) -> EnableIf_t< IsDenseVector_v< VT1 > >
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:191
Header file for the IsExpression type trait class.
Header file for the function trace functionality.