All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <cmath>
59 #include <blaze/util/Assert.h>
61 #include <blaze/util/EnableIf.h>
62 #include <blaze/util/InvalidType.h>
64 #include <blaze/util/SelectType.h>
65 #include <blaze/util/Types.h>
66 
67 
68 namespace blaze {
69 
70 //=================================================================================================
71 //
72 // CLASS SVECSERIALEXPR
73 //
74 //=================================================================================================
75 
76 //*************************************************************************************************
83 template< typename VT // Type of the sparse vector
84  , bool TF > // Transpose flag
85 class SVecSerialExpr : public SparseVector< SVecSerialExpr<VT,TF>, TF >
86  , private VecSerialExpr
87  , private Computation
88 {
89  public:
90  //**Type definitions****************************************************************************
92  typedef typename VT::ResultType ResultType;
93  typedef typename VT::TransposeType TransposeType;
94  typedef typename VT::ElementType ElementType;
95  typedef typename VT::ReturnType ReturnType;
96 
98  typedef const ResultType CompositeType;
99 
101  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
102  //**********************************************************************************************
103 
104  //**Compilation flags***************************************************************************
106  enum { smpAssignable = VT::smpAssignable };
107  //**********************************************************************************************
108 
109  //**Constructor*********************************************************************************
114  explicit inline SVecSerialExpr( const VT& sv )
115  : sv_( sv ) // Sparse vector of the serial evaluation expression
116  {}
117  //**********************************************************************************************
118 
119  //**Subscript operator**************************************************************************
125  inline ReturnType operator[]( size_t index ) const {
126  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
127  return sv_[index];
128  }
129  //**********************************************************************************************
130 
131  //**Size function*******************************************************************************
136  inline size_t size() const {
137  return sv_.size();
138  }
139  //**********************************************************************************************
140 
141  //**NonZeros function***************************************************************************
146  inline size_t nonZeros() const {
147  return sv_.nonZeros();
148  }
149  //**********************************************************************************************
150 
151  //**Operand access******************************************************************************
156  inline Operand operand() const {
157  return sv_;
158  }
159  //**********************************************************************************************
160 
161  //**Conversion operator*************************************************************************
166  inline operator Operand() const {
167  return sv_;
168  }
169  //**********************************************************************************************
170 
171  //**********************************************************************************************
177  template< typename T >
178  inline bool canAlias( const T* alias ) const {
179  return sv_.canAlias( alias );
180  }
181  //**********************************************************************************************
182 
183  //**********************************************************************************************
189  template< typename T >
190  inline bool isAliased( const T* alias ) const {
191  return sv_.isAliased( alias );
192  }
193  //**********************************************************************************************
194 
195  //**********************************************************************************************
200  inline bool canSMPAssign() const {
201  return sv_.canSMPAssign();
202  }
203  //**********************************************************************************************
204 
205  private:
206  //**Member variables****************************************************************************
208  //**********************************************************************************************
209 
210  //**Assignment to dense vectors*****************************************************************
222  template< typename VT2 > // Type of the target dense vector
223  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
224  {
226 
227  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
228 
229  assign( ~lhs, rhs.sv_ );
230  }
232  //**********************************************************************************************
233 
234  //**Assignment to sparse vectors****************************************************************
246  template< typename VT2 > // Type of the target sparse vector
247  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
248  {
250 
251  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
252 
253  assign( ~lhs, rhs.sv_ );
254  }
256  //**********************************************************************************************
257 
258  //**Addition assignment to dense vectors********************************************************
270  template< typename VT2 > // Type of the target dense vector
271  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
272  {
274 
275  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
276 
277  addAssign( ~lhs, rhs.sv_ );
278  }
280  //**********************************************************************************************
281 
282  //**Addition assignment to sparse vectors*******************************************************
294  template< typename VT2 > // Type of the target sparse vector
295  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
296  {
298 
299  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
300 
301  addAssign( ~lhs, rhs.sv_ );
302  }
304  //**********************************************************************************************
305 
306  //**Subtraction assignment to dense vectors*****************************************************
319  template< typename VT2 > // Type of the target dense vector
320  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
321  {
323 
324  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
325 
326  subAssign( ~lhs, rhs.sv_ );
327  }
329  //**********************************************************************************************
330 
331  //**Subtraction assignment to sparse vectors****************************************************
344  template< typename VT2 > // Type of the target sparse vector
345  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
346  {
348 
349  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
350 
351  subAssign( ~lhs, rhs.sv_ );
352  }
354  //**********************************************************************************************
355 
356  //**Multiplication assignment to dense vectors**************************************************
369  template< typename VT2 > // Type of the target dense vector
370  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
371  {
373 
374  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
375 
376  multAssign( ~lhs, rhs.sv_ );
377  }
379  //**********************************************************************************************
380 
381  //**Multiplication assignment to sparse vectors*************************************************
394  template< typename VT2 > // Type of the target sparse vector
395  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
396  {
398 
399  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
400 
401  multAssign( ~lhs, rhs.sv_ );
402  }
404  //**********************************************************************************************
405 
406  //**SMP assignment to dense vectors*************************************************************
418  template< typename VT2 > // Type of the target dense vector
419  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
420  {
422 
423  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
424 
425  assign( ~lhs, rhs.sv_ );
426  }
428  //**********************************************************************************************
429 
430  //**SMP assignment to sparse vectors************************************************************
442  template< typename VT2 > // Type of the target sparse vector
443  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
444  {
446 
447  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
448 
449  assign( ~lhs, rhs.sv_ );
450  }
452  //**********************************************************************************************
453 
454  //**SMP addition assignment to dense vectors****************************************************
467  template< typename VT2 > // Type of the target dense vector
468  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
469  {
471 
472  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
473 
474  addAssign( ~lhs, rhs.sv_ );
475  }
477  //**********************************************************************************************
478 
479  //**SMP addition assignment to sparse vectors***************************************************
492  template< typename VT2 > // Type of the target sparse vector
493  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
494  {
496 
497  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
498 
499  addAssign( ~lhs, rhs.sv_ );
500  }
502  //**********************************************************************************************
503 
504  //**SMP subtraction assignment to dense vectors*************************************************
517  template< typename VT2 > // Type of the target dense vector
518  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
519  {
521 
522  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
523 
524  subAssign( ~lhs, rhs.sv_ );
525  }
527  //**********************************************************************************************
528 
529  //**SMP subtraction assignment to sparse vectors************************************************
542  template< typename VT2 > // Type of the target sparse vector
543  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
544  {
546 
547  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
548 
549  subAssign( ~lhs, rhs.sv_ );
550  }
552  //**********************************************************************************************
553 
554  //**SMP multiplication assignment to dense vectors**********************************************
567  template< typename VT2 > // Type of the target dense vector
568  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
569  {
571 
572  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
573 
574  multAssign( ~lhs, rhs.sv_ );
575  }
577  //**********************************************************************************************
578 
579  //**SMP multiplication assignment to sparse vectors*********************************************
592  template< typename VT2 > // Type of the target sparse vector
593  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecSerialExpr& rhs )
594  {
596 
597  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
598 
599  multAssign( ~lhs, rhs.sv_ );
600  }
602  //**********************************************************************************************
603 
604  //**Compile time checks*************************************************************************
609  //**********************************************************************************************
610 };
611 //*************************************************************************************************
612 
613 
614 
615 
616 //=================================================================================================
617 //
618 // GLOBAL FUNCTIONS
619 //
620 //=================================================================================================
621 
622 //*************************************************************************************************
639 template< typename VT // Type of the dense vector
640  , bool TF > // Transpose flag
642 {
644 
645  return SVecSerialExpr<VT,TF>( ~sv );
646 }
647 //*************************************************************************************************
648 
649 
650 
651 
652 //=================================================================================================
653 //
654 // GLOBAL RESTRUCTURING FUNCTIONS
655 //
656 //=================================================================================================
657 
658 //*************************************************************************************************
669 template< typename VT // Type of the sparse vector
670  , bool TF > // Transpose flag
671 inline const SVecSerialExpr<VT,TF> serial( const SVecSerialExpr<VT,TF>& sv )
672 {
673  return sv;
674 }
676 //*************************************************************************************************
677 
678 
679 
680 
681 //=================================================================================================
682 //
683 // EXPRESSION TRAIT SPECIALIZATIONS
684 //
685 //=================================================================================================
686 
687 //*************************************************************************************************
689 template< typename VT >
690 struct SVecSerialExprTrait< SVecSerialExpr<VT,false> >
691 {
692  public:
693  //**********************************************************************************************
694  typedef typename SelectType< IsSparseVector<VT>::value && IsColumnVector<VT>::value
695  , SVecSerialExpr<VT,false>
696  , INVALID_TYPE >::Type Type;
697  //**********************************************************************************************
698 };
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
705 template< typename VT >
706 struct TSVecSerialExprTrait< SVecSerialExpr<VT,true> >
707 {
708  public:
709  //**********************************************************************************************
710  typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value
711  , SVecSerialExpr<VT,true>
712  , INVALID_TYPE >::Type Type;
713  //**********************************************************************************************
714 };
716 //*************************************************************************************************
717 
718 
719 //*************************************************************************************************
721 template< typename VT, bool TF, bool AF >
722 struct SubvectorExprTrait< SVecSerialExpr<VT,TF>, AF >
723 {
724  public:
725  //**********************************************************************************************
726  typedef typename SerialExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
727  //**********************************************************************************************
728 };
730 //*************************************************************************************************
731 
732 } // namespace blaze
733 
734 #endif
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecSerialExpr.h:93
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecSerialExpr.h:190
Header file for the SparseVector base class.
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:152
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: SVecSerialExpr.h:92
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecSerialExpr.h:146
void smpMultAssign(DenseVector< 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:179
Header file for the IsRowVector type trait.
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecSerialExpr.h:136
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Header file for the Computation base class.
SVecSerialExpr< VT, TF > This
Type of this SVecSerialExpr instance.
Definition: SVecSerialExpr.h:91
Constraint on the data type.
void smpAddAssign(DenseMatrix< 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:122
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
SVecSerialExpr(const VT &sv)
Constructor for the SVecSerialExpr class.
Definition: SVecSerialExpr.h:114
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:271
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#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:79
Header file for the SerialExprTrait class template.
Constraint on the data type.
Header file for the SVecSerialExprTrait class template.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2405
Operand sv_
Sparse vector of the serial evaluation expression.
Definition: SVecSerialExpr.h:207
Operand operand() const
Returns the sparse vector operand.
Definition: SVecSerialExpr.h:156
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecSerialExpr.h:95
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:361
Header file for the SelectType class template.
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:116
Header file for the EnableIf class template.
VT::ElementType ElementType
Resulting element type.
Definition: SVecSerialExpr.h:94
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:92
Header file for the VecSerialExpr base class.
Header file for the IsSparseVector type trait.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SVecSerialExpr.h:200
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
Header file for run time assertion macros.
Utility type for generic codes.
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecSerialExpr.h:101
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:301
Header file for the TSVecSerialExprTrait class template.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:331
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecSerialExpr.h:98
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecSerialExpr.h:125
Header file for the IsComputation type trait class.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
Header file for basic type definitions.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecSerialExpr.h:178
Header file for the SubvectorExprTrait class template.
Header file for the IsColumnVector 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:238
#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 FunctionTrace class.