All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecEvalExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECEVALEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <cmath>
60 #include <blaze/util/Assert.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 SVECEVALEXPR
73 //
74 //=================================================================================================
75 
76 //*************************************************************************************************
83 template< typename VT // Type of the sparse vector
84  , bool TF > // Transpose flag
85 class SVecEvalExpr : public SparseVector< SVecEvalExpr<VT,TF>, TF >
86  , private VecEvalExpr
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 SVecEvalExpr( const VT& sv )
115  : sv_( sv ) // Sparse vector of the 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  //**********************************************************************************************
167  template< typename T >
168  inline bool canAlias( const T* alias ) const {
169  return sv_.canAlias( alias );
170  }
171  //**********************************************************************************************
172 
173  //**********************************************************************************************
179  template< typename T >
180  inline bool isAliased( const T* alias ) const {
181  return sv_.isAliased( alias );
182  }
183  //**********************************************************************************************
184 
185  //**********************************************************************************************
190  inline bool canSMPAssign() const {
191  return sv_.canSMPAssign();
192  }
193  //**********************************************************************************************
194 
195  private:
196  //**Member variables****************************************************************************
198  //**********************************************************************************************
199 
200  //**Assignment to dense vectors*****************************************************************
212  template< typename VT2 > // Type of the target dense vector
213  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
214  {
216 
217  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
218 
219  assign( ~lhs, rhs.sv_ );
220  }
222  //**********************************************************************************************
223 
224  //**Assignment to sparse vectors****************************************************************
236  template< typename VT2 > // Type of the target sparse vector
237  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
238  {
240 
241  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
242 
243  assign( ~lhs, rhs.sv_ );
244  }
246  //**********************************************************************************************
247 
248  //**Addition assignment to dense vectors********************************************************
260  template< typename VT2 > // Type of the target dense vector
261  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
262  {
264 
265  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
266 
267  addAssign( ~lhs, rhs.sv_ );
268  }
270  //**********************************************************************************************
271 
272  //**Addition assignment to sparse vectors*******************************************************
284  template< typename VT2 > // Type of the target sparse vector
285  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
286  {
288 
289  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
290 
291  addAssign( ~lhs, rhs.sv_ );
292  }
294  //**********************************************************************************************
295 
296  //**Subtraction assignment to dense vectors*****************************************************
308  template< typename VT2 > // Type of the target dense vector
309  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
310  {
312 
313  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
314 
315  subAssign( ~lhs, rhs.sv_ );
316  }
318  //**********************************************************************************************
319 
320  //**Subtraction assignment to sparse vectors****************************************************
332  template< typename VT2 > // Type of the target sparse vector
333  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
334  {
336 
337  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
338 
339  subAssign( ~lhs, rhs.sv_ );
340  }
342  //**********************************************************************************************
343 
344  //**Multiplication assignment to dense vectors**************************************************
356  template< typename VT2 > // Type of the target dense vector
357  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
358  {
360 
361  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
362 
363  multAssign( ~lhs, rhs.sv_ );
364  }
366  //**********************************************************************************************
367 
368  //**Multiplication assignment to sparse vectors*************************************************
380  template< typename VT2 > // Type of the target sparse vector
381  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
382  {
384 
385  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
386 
387  multAssign( ~lhs, rhs.sv_ );
388  }
390  //**********************************************************************************************
391 
392  //**SMP assignment to dense vectors*************************************************************
404  template< typename VT2 > // Type of the target dense vector
405  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
406  {
408 
409  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
410 
411  smpAssign( ~lhs, rhs.sv_ );
412  }
414  //**********************************************************************************************
415 
416  //**SMP assignment to sparse vectors************************************************************
428  template< typename VT2 > // Type of the target sparse vector
429  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
430  {
432 
433  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
434 
435  smpAssign( ~lhs, rhs.sv_ );
436  }
438  //**********************************************************************************************
439 
440  //**SMP addition assignment to dense vectors****************************************************
452  template< typename VT2 > // Type of the target dense vector
453  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
454  {
456 
457  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
458 
459  smpAddAssign( ~lhs, rhs.sv_ );
460  }
462  //**********************************************************************************************
463 
464  //**SMP addition assignment to sparse vectors***************************************************
476  template< typename VT2 > // Type of the target sparse vector
477  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
478  {
480 
481  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
482 
483  smpAddAssign( ~lhs, rhs.sv_ );
484  }
486  //**********************************************************************************************
487 
488  //**SMP subtraction assignment to dense vectors*************************************************
500  template< typename VT2 > // Type of the target dense vector
501  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
502  {
504 
505  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
506 
507  smpSubAssign( ~lhs, rhs.sv_ );
508  }
510  //**********************************************************************************************
511 
512  //**SMP subtraction assignment to sparse vectors************************************************
524  template< typename VT2 > // Type of the target sparse vector
525  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
526  {
528 
529  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
530 
531  smpSubAssign( ~lhs, rhs.sv_ );
532  }
534  //**********************************************************************************************
535 
536  //**SMP multiplication assignment to dense vectors**********************************************
548  template< typename VT2 > // Type of the target dense vector
549  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
550  {
552 
553  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
554 
555  smpMultAssign( ~lhs, rhs.sv_ );
556  }
558  //**********************************************************************************************
559 
560  //**SMP multiplication assignment to sparse vectors*********************************************
572  template< typename VT2 > // Type of the target sparse vector
573  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
574  {
576 
577  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
578 
579  smpMultAssign( ~lhs, rhs.sv_ );
580  }
582  //**********************************************************************************************
583 
584  //**Compile time checks*************************************************************************
589  //**********************************************************************************************
590 };
591 //*************************************************************************************************
592 
593 
594 
595 
596 //=================================================================================================
597 //
598 // GLOBAL FUNCTIONS
599 //
600 //=================================================================================================
601 
602 //*************************************************************************************************
619 template< typename VT // Type of the dense vector
620  , bool TF > // Transpose flag
622 {
624 
625  return SVecEvalExpr<VT,TF>( ~sv );
626 }
627 //*************************************************************************************************
628 
629 
630 
631 
632 //=================================================================================================
633 //
634 // GLOBAL RESTRUCTURING FUNCTIONS
635 //
636 //=================================================================================================
637 
638 //*************************************************************************************************
649 template< typename VT // Type of the sparse vector
650  , bool TF > // Transpose flag
651 inline const SVecEvalExpr<VT,TF> eval( const SVecEvalExpr<VT,TF>& sv )
652 {
653  return sv;
654 }
656 //*************************************************************************************************
657 
658 
659 
660 
661 //=================================================================================================
662 //
663 // SIZE SPECIALIZATIONS
664 //
665 //=================================================================================================
666 
667 //*************************************************************************************************
669 template< typename VT, bool TF >
670 struct Size< SVecEvalExpr<VT,TF> >
671  : public Size<VT>
672 {};
674 //*************************************************************************************************
675 
676 
677 
678 
679 //=================================================================================================
680 //
681 // EXPRESSION TRAIT SPECIALIZATIONS
682 //
683 //=================================================================================================
684 
685 //*************************************************************************************************
687 template< typename VT >
688 struct SVecEvalExprTrait< SVecEvalExpr<VT,false> >
689 {
690  public:
691  //**********************************************************************************************
692  typedef typename SelectType< IsSparseVector<VT>::value && IsColumnVector<VT>::value
693  , SVecEvalExpr<VT,false>
694  , INVALID_TYPE >::Type Type;
695  //**********************************************************************************************
696 };
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
703 template< typename VT >
704 struct TSVecEvalExprTrait< SVecEvalExpr<VT,true> >
705 {
706  public:
707  //**********************************************************************************************
708  typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value
709  , SVecEvalExpr<VT,true>
710  , INVALID_TYPE >::Type Type;
711  //**********************************************************************************************
712 };
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
719 template< typename VT, bool TF, bool AF >
720 struct SubvectorExprTrait< SVecEvalExpr<VT,TF>, AF >
721 {
722  public:
723  //**********************************************************************************************
724  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
725  //**********************************************************************************************
726 };
728 //*************************************************************************************************
729 
730 } // namespace blaze
731 
732 #endif
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecEvalExpr.h:93
BLAZE_ALWAYS_INLINE 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:879
Operand sv_
Sparse vector of the evaluation expression.
Definition: SVecEvalExpr.h:197
Header file for the SparseVector base class.
Header file for the IsRowVector type trait.
Expression object for the forced evaluation of sparse vectors.The SVecEvalExpr class represents the c...
Definition: Forward.h:113
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecEvalExpr.h:146
Header file for the Computation base class.
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: SVecEvalExpr.h:92
Header file for the VecEvalExpr base class.
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecEvalExpr.h:95
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SVecEvalExpr.h:190
Constraint on the data type.
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
BLAZE_ALWAYS_INLINE 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:635
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
Constraint on the data type.
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecEvalExpr.h:136
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2475
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
EnableIf< IsDenseMatrix< MT1 > >::Type 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 IsSparseVector type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type 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
Utility type for generic codes.
SVecEvalExpr(const VT &sv)
Constructor for the SVecEvalExpr class.
Definition: SVecEvalExpr.h:114
BLAZE_ALWAYS_INLINE 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:742
Header file for the EvalExprTrait class template.
Header file for the TSVecEvalExprTrait class template.
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecEvalExpr.h:180
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:677
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecEvalExpr.h:98
VT::ElementType ElementType
Resulting element type.
Definition: SVecEvalExpr.h:94
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecEvalExpr.h:101
Header file for the IsComputation type trait class.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecEvalExpr.h:156
EnableIf< IsDenseMatrix< MT1 > >::Type 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
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:2473
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecEvalExpr.h:125
Header file for the SVecEvalExprTrait class template.
SVecEvalExpr< VT, TF > This
Type of this SVecEvalExpr instance.
Definition: SVecEvalExpr.h:91
Header file for the IsColumnVector type trait.
EnableIf< IsDenseVector< VT1 > >::Type 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:189
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: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.
BLAZE_ALWAYS_INLINE 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:849
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecEvalExpr.h:168