SVecSerialExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECSERIALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECSERIALEXPR_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>
63 #include <blaze/util/InvalidType.h>
64 #include <blaze/util/mpl/And.h>
65 #include <blaze/util/mpl/If.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS SVECSERIALEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT // Type of the sparse vector
85  , bool TF > // Transpose flag
86 class SVecSerialExpr : public SparseVector< SVecSerialExpr<VT,TF>, TF >
87  , private VecSerialExpr
88  , private Computation
89 {
90  public:
91  //**Type definitions****************************************************************************
97 
99  typedef const ResultType CompositeType;
100 
102  typedef If_< IsExpression<VT>, const VT, const VT& > Operand;
103  //**********************************************************************************************
104 
105  //**Compilation flags***************************************************************************
107  enum : bool { smpAssignable = VT::smpAssignable };
108  //**********************************************************************************************
109 
110  //**Constructor*********************************************************************************
115  explicit inline SVecSerialExpr( const VT& sv ) noexcept
116  : sv_( sv ) // Sparse vector of the serial evaluation expression
117  {}
118  //**********************************************************************************************
119 
120  //**Subscript operator**************************************************************************
126  inline ReturnType operator[]( size_t index ) const {
127  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
128  return sv_[index];
129  }
130  //**********************************************************************************************
131 
132  //**At function*********************************************************************************
139  inline ReturnType at( size_t index ) const {
140  if( index >= sv_.size() ) {
141  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
142  }
143  return (*this)[index];
144  }
145  //**********************************************************************************************
146 
147  //**Size function*******************************************************************************
152  inline size_t size() const noexcept {
153  return sv_.size();
154  }
155  //**********************************************************************************************
156 
157  //**NonZeros function***************************************************************************
162  inline size_t nonZeros() const {
163  return sv_.nonZeros();
164  }
165  //**********************************************************************************************
166 
167  //**Operand access******************************************************************************
172  inline Operand operand() const noexcept {
173  return sv_;
174  }
175  //**********************************************************************************************
176 
177  //**Conversion operator*************************************************************************
182  inline operator Operand() const noexcept {
183  return sv_;
184  }
185  //**********************************************************************************************
186 
187  //**********************************************************************************************
193  template< typename T >
194  inline bool canAlias( const T* alias ) const noexcept {
195  return sv_.canAlias( alias );
196  }
197  //**********************************************************************************************
198 
199  //**********************************************************************************************
205  template< typename T >
206  inline bool isAliased( const T* alias ) const noexcept {
207  return sv_.isAliased( alias );
208  }
209  //**********************************************************************************************
210 
211  //**********************************************************************************************
216  inline bool canSMPAssign() const noexcept {
217  return sv_.canSMPAssign();
218  }
219  //**********************************************************************************************
220 
221  private:
222  //**Member variables****************************************************************************
223  Operand sv_;
224  //**********************************************************************************************
225 
226  //**Assignment to dense vectors*****************************************************************
238  template< typename VT2 > // Type of the target dense vector
239  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
240  {
242 
243  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
244 
245  assign( ~lhs, rhs.sv_ );
246  }
248  //**********************************************************************************************
249 
250  //**Assignment to sparse vectors****************************************************************
262  template< typename VT2 > // Type of the target sparse vector
263  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
264  {
266 
267  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
268 
269  assign( ~lhs, rhs.sv_ );
270  }
272  //**********************************************************************************************
273 
274  //**Addition assignment to dense vectors********************************************************
286  template< typename VT2 > // Type of the target dense vector
287  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
288  {
290 
291  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
292 
293  addAssign( ~lhs, rhs.sv_ );
294  }
296  //**********************************************************************************************
297 
298  //**Addition assignment to sparse vectors*******************************************************
310  template< typename VT2 > // Type of the target sparse vector
311  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
312  {
314 
315  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
316 
317  addAssign( ~lhs, rhs.sv_ );
318  }
320  //**********************************************************************************************
321 
322  //**Subtraction assignment to dense vectors*****************************************************
335  template< typename VT2 > // Type of the target dense vector
336  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
337  {
339 
340  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
341 
342  subAssign( ~lhs, rhs.sv_ );
343  }
345  //**********************************************************************************************
346 
347  //**Subtraction assignment to sparse vectors****************************************************
360  template< typename VT2 > // Type of the target sparse vector
361  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
362  {
364 
365  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
366 
367  subAssign( ~lhs, rhs.sv_ );
368  }
370  //**********************************************************************************************
371 
372  //**Multiplication assignment to dense vectors**************************************************
385  template< typename VT2 > // Type of the target dense vector
386  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
387  {
389 
390  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
391 
392  multAssign( ~lhs, rhs.sv_ );
393  }
395  //**********************************************************************************************
396 
397  //**Multiplication assignment to sparse vectors*************************************************
410  template< typename VT2 > // Type of the target sparse vector
411  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
412  {
414 
415  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
416 
417  multAssign( ~lhs, rhs.sv_ );
418  }
420  //**********************************************************************************************
421 
422  //**SMP assignment to dense vectors*************************************************************
434  template< typename VT2 > // Type of the target dense vector
435  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
436  {
438 
439  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
440 
441  assign( ~lhs, rhs.sv_ );
442  }
444  //**********************************************************************************************
445 
446  //**SMP assignment to sparse vectors************************************************************
458  template< typename VT2 > // Type of the target sparse vector
459  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
460  {
462 
463  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
464 
465  assign( ~lhs, rhs.sv_ );
466  }
468  //**********************************************************************************************
469 
470  //**SMP addition assignment to dense vectors****************************************************
483  template< typename VT2 > // Type of the target dense vector
484  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
485  {
487 
488  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
489 
490  addAssign( ~lhs, rhs.sv_ );
491  }
493  //**********************************************************************************************
494 
495  //**SMP addition assignment to sparse vectors***************************************************
508  template< typename VT2 > // Type of the target sparse vector
509  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
510  {
512 
513  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
514 
515  addAssign( ~lhs, rhs.sv_ );
516  }
518  //**********************************************************************************************
519 
520  //**SMP subtraction assignment to dense vectors*************************************************
533  template< typename VT2 > // Type of the target dense vector
534  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
535  {
537 
538  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
539 
540  subAssign( ~lhs, rhs.sv_ );
541  }
543  //**********************************************************************************************
544 
545  //**SMP subtraction assignment to sparse vectors************************************************
558  template< typename VT2 > // Type of the target sparse vector
559  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
560  {
562 
563  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
564 
565  subAssign( ~lhs, rhs.sv_ );
566  }
568  //**********************************************************************************************
569 
570  //**SMP multiplication assignment to dense vectors**********************************************
583  template< typename VT2 > // Type of the target dense vector
584  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
585  {
587 
588  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
589 
590  multAssign( ~lhs, rhs.sv_ );
591  }
593  //**********************************************************************************************
594 
595  //**SMP multiplication assignment to sparse vectors*********************************************
608  template< typename VT2 > // Type of the target sparse vector
609  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
610  {
612 
613  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
614 
615  multAssign( ~lhs, rhs.sv_ );
616  }
618  //**********************************************************************************************
619 
620  //**Compile time checks*************************************************************************
625  //**********************************************************************************************
626 };
627 //*************************************************************************************************
628 
629 
630 
631 
632 //=================================================================================================
633 //
634 // GLOBAL FUNCTIONS
635 //
636 //=================================================================================================
637 
638 //*************************************************************************************************
655 template< typename VT // Type of the dense vector
656  , bool TF > // Transpose flag
658 {
660 
661  return SVecSerialExpr<VT,TF>( ~sv );
662 }
663 //*************************************************************************************************
664 
665 
666 
667 
668 //=================================================================================================
669 //
670 // GLOBAL RESTRUCTURING FUNCTIONS
671 //
672 //=================================================================================================
673 
674 //*************************************************************************************************
685 template< typename VT // Type of the sparse vector
686  , bool TF > // Transpose flag
687 inline const SVecSerialExpr<VT,TF> serial( const SVecSerialExpr<VT,TF>& sv )
688 {
689  return sv;
690 }
692 //*************************************************************************************************
693 
694 
695 
696 
697 //=================================================================================================
698 //
699 // SIZE SPECIALIZATIONS
700 //
701 //=================================================================================================
702 
703 //*************************************************************************************************
705 template< typename VT, bool TF >
706 struct Size< SVecSerialExpr<VT,TF> > : public Size<VT>
707 {};
709 //*************************************************************************************************
710 
711 
712 
713 
714 //=================================================================================================
715 //
716 // EXPRESSION TRAIT SPECIALIZATIONS
717 //
718 //=================================================================================================
719 
720 //*************************************************************************************************
722 template< typename VT >
723 struct SVecSerialExprTrait< SVecSerialExpr<VT,false> >
724 {
725  public:
726  //**********************************************************************************************
729  , INVALID_TYPE >;
730  //**********************************************************************************************
731 };
733 //*************************************************************************************************
734 
735 
736 //*************************************************************************************************
738 template< typename VT >
739 struct TSVecSerialExprTrait< SVecSerialExpr<VT,true> >
740 {
741  public:
742  //**********************************************************************************************
745  , INVALID_TYPE >;
746  //**********************************************************************************************
747 };
749 //*************************************************************************************************
750 
751 
752 //*************************************************************************************************
754 template< typename VT, bool TF, bool AF >
755 struct SubvectorExprTrait< SVecSerialExpr<VT,TF>, AF >
756 {
757  public:
758  //**********************************************************************************************
760  //**********************************************************************************************
761 };
763 //*************************************************************************************************
764 
765 } // namespace blaze
766 
767 #endif
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 auxiliary alias declarations.
Evaluation of the expression type type of a subvector operation.Via this type trait it is possible to...
Definition: SubvectorExprTrait.h:79
SVecSerialExpr< VT, TF > This
Type of this SVecSerialExpr instance.
Definition: SVecSerialExpr.h:92
Header file for basic type definitions.
Header file for the SparseVector base class.
If_< IsExpression< VT >, const VT, const VT &> Operand
Composite data type of the sparse vector expression.
Definition: SVecSerialExpr.h:102
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
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.
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.
SVecSerialExpr(const VT &sv) noexcept
Constructor for the SVecSerialExpr class.
Definition: SVecSerialExpr.h:115
bool isAliased(const T *alias) const noexcept
Returns whether the expression is aliased with the given address alias.
Definition: SVecSerialExpr.h:206
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
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSerialExpr.h:162
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSerialExpr.h:99
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSerialExpr.h:126
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
ReturnType at(size_t index) const
Checked access to the vector elements.
Definition: SVecSerialExpr.h:139
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
Operand operand() const noexcept
Returns the sparse vector operand.
Definition: SVecSerialExpr.h:172
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:61
Header file for the SerialExprTrait class template.
Constraint on the data type.
Header file for the SVecSerialExprTrait class template.
Compile time check for column vector types.This type trait tests whether or not the given template ar...
Definition: IsColumnVector.h:80
bool canSMPAssign() const noexcept
Returns whether the expression can be used in SMP assignments.
Definition: SVecSerialExpr.h:216
Header file for the exception macros of the math module.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Expression object for the forced serial evaluation of sparse vectors.The SVecSerialExpr class represe...
Definition: Forward.h:130
ReturnType_< VT > ReturnType
Return type for expression template evaluations.
Definition: SVecSerialExpr.h:96
Header file for the VecSerialExpr base class.
Header file for the IsSparseVector type trait.
Header file for run time assertion macros.
Utility type for generic codes.
ResultType_< VT > ResultType
Result type for expression template evaluations.
Definition: SVecSerialExpr.h:93
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
Header file for the TSVecSerialExprTrait class template.
#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
bool canAlias(const T *alias) const noexcept
Returns whether the expression can alias with the given address alias.
Definition: SVecSerialExpr.h:194
ElementType_< VT > ElementType
Resulting element type.
Definition: SVecSerialExpr.h:95
Operand sv_
Sparse vector of the serial evaluation expression.
Definition: SVecSerialExpr.h:223
TransposeType_< VT > TransposeType
Transpose type for expression template evaluations.
Definition: SVecSerialExpr.h:94
Header file for the IsComputation type trait class.
Compile time evaluation of the size of a vector.The Size type trait evaluates the size of the given v...
Definition: Size.h:75
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:120
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: SVecSerialExpr.h:152
Evaluation of the expression type of a sparse vector serial evaluation operation.Via this type trait ...
Definition: SVecSerialExprTrait.h:74
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.
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
Evaluation of the expression type of a sparse vector serial evaluation operation.Via this type trait ...
Definition: TSVecSerialExprTrait.h:74
Header file for the IsExpression type trait class.
Header file for the function trace functionality.