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>
62 #include <blaze/util/Assert.h>
64 #include <blaze/util/EnableIf.h>
65 #include <blaze/util/InvalidType.h>
67 #include <blaze/util/SelectType.h>
68 #include <blaze/util/Types.h>
69 
70 
71 namespace blaze {
72 
73 //=================================================================================================
74 //
75 // CLASS SVECEVALEXPR
76 //
77 //=================================================================================================
78 
79 //*************************************************************************************************
86 template< typename VT // Type of the sparse vector
87  , bool TF > // Transpose flag
88 class SVecEvalExpr : public SparseVector< SVecEvalExpr<VT,TF>, TF >
89  , private VecEvalExpr
90  , private Computation
91 {
92  public:
93  //**Type definitions****************************************************************************
95  typedef typename VT::ResultType ResultType;
96  typedef typename VT::TransposeType TransposeType;
97  typedef typename VT::ElementType ElementType;
98  typedef typename VT::ReturnType ReturnType;
99 
101  typedef const ResultType CompositeType;
102 
104  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
105  //**********************************************************************************************
106 
107  //**Compilation flags***************************************************************************
109  enum { smpAssignable = VT::smpAssignable };
110  //**********************************************************************************************
111 
112  //**Constructor*********************************************************************************
117  explicit inline SVecEvalExpr( const VT& sv )
118  : sv_( sv ) // Sparse vector of the evaluation expression
119  {}
120  //**********************************************************************************************
121 
122  //**Subscript operator**************************************************************************
128  inline ReturnType operator[]( size_t index ) const {
129  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
130  return sv_[index];
131  }
132  //**********************************************************************************************
133 
134  //**Size function*******************************************************************************
139  inline size_t size() const {
140  return sv_.size();
141  }
142  //**********************************************************************************************
143 
144  //**NonZeros function***************************************************************************
149  inline size_t nonZeros() const {
150  return sv_.nonZeros();
151  }
152  //**********************************************************************************************
153 
154  //**Operand access******************************************************************************
159  inline Operand operand() const {
160  return sv_;
161  }
162  //**********************************************************************************************
163 
164  //**********************************************************************************************
170  template< typename T >
171  inline bool canAlias( const T* alias ) const {
172  return sv_.canAlias( alias );
173  }
174  //**********************************************************************************************
175 
176  //**********************************************************************************************
182  template< typename T >
183  inline bool isAliased( const T* alias ) const {
184  return sv_.isAliased( alias );
185  }
186  //**********************************************************************************************
187 
188  //**********************************************************************************************
193  inline bool canSMPAssign() const {
194  return sv_.canSMPAssign();
195  }
196  //**********************************************************************************************
197 
198  private:
199  //**Member variables****************************************************************************
201  //**********************************************************************************************
202 
203  //**Assignment to dense vectors*****************************************************************
215  template< typename VT2 > // Type of the target dense vector
216  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
217  {
219 
220  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
221 
222  assign( ~lhs, rhs.sv_ );
223  }
225  //**********************************************************************************************
226 
227  //**Assignment to sparse vectors****************************************************************
239  template< typename VT2 > // Type of the target sparse vector
240  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
241  {
243 
244  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
245 
246  assign( ~lhs, rhs.sv_ );
247  }
249  //**********************************************************************************************
250 
251  //**Addition assignment to dense vectors********************************************************
263  template< typename VT2 > // Type of the target dense vector
264  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
265  {
267 
268  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
269 
270  addAssign( ~lhs, rhs.sv_ );
271  }
273  //**********************************************************************************************
274 
275  //**Addition assignment to sparse vectors*******************************************************
287  template< typename VT2 > // Type of the target sparse vector
288  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
289  {
291 
292  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
293 
294  addAssign( ~lhs, rhs.sv_ );
295  }
297  //**********************************************************************************************
298 
299  //**Subtraction assignment to dense vectors*****************************************************
311  template< typename VT2 > // Type of the target dense vector
312  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
313  {
315 
316  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
317 
318  subAssign( ~lhs, rhs.sv_ );
319  }
321  //**********************************************************************************************
322 
323  //**Subtraction assignment to sparse vectors****************************************************
335  template< typename VT2 > // Type of the target sparse vector
336  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
337  {
339 
340  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
341 
342  subAssign( ~lhs, rhs.sv_ );
343  }
345  //**********************************************************************************************
346 
347  //**Multiplication assignment to dense vectors**************************************************
359  template< typename VT2 > // Type of the target dense vector
360  friend inline void multAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
361  {
363 
364  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
365 
366  multAssign( ~lhs, rhs.sv_ );
367  }
369  //**********************************************************************************************
370 
371  //**Multiplication assignment to sparse vectors*************************************************
383  template< typename VT2 > // Type of the target sparse vector
384  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
385  {
387 
388  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
389 
390  multAssign( ~lhs, rhs.sv_ );
391  }
393  //**********************************************************************************************
394 
395  //**SMP assignment to dense vectors*************************************************************
407  template< typename VT2 > // Type of the target dense vector
408  friend inline void smpAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
409  {
411 
412  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
413 
414  smpAssign( ~lhs, rhs.sv_ );
415  }
417  //**********************************************************************************************
418 
419  //**SMP assignment to sparse vectors************************************************************
431  template< typename VT2 > // Type of the target sparse vector
432  friend inline void smpAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
433  {
435 
436  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
437 
438  smpAssign( ~lhs, rhs.sv_ );
439  }
441  //**********************************************************************************************
442 
443  //**SMP addition assignment to dense vectors****************************************************
455  template< typename VT2 > // Type of the target dense vector
456  friend inline void smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
457  {
459 
460  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
461 
462  smpAddAssign( ~lhs, rhs.sv_ );
463  }
465  //**********************************************************************************************
466 
467  //**SMP addition assignment to sparse vectors***************************************************
479  template< typename VT2 > // Type of the target sparse vector
480  friend inline void smpAddAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
481  {
483 
484  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
485 
486  smpAddAssign( ~lhs, rhs.sv_ );
487  }
489  //**********************************************************************************************
490 
491  //**SMP subtraction assignment to dense vectors*************************************************
503  template< typename VT2 > // Type of the target dense vector
504  friend inline void smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
505  {
507 
508  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
509 
510  smpSubAssign( ~lhs, rhs.sv_ );
511  }
513  //**********************************************************************************************
514 
515  //**SMP subtraction assignment to sparse vectors************************************************
527  template< typename VT2 > // Type of the target sparse vector
528  friend inline void smpSubAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
529  {
531 
532  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
533 
534  smpSubAssign( ~lhs, rhs.sv_ );
535  }
537  //**********************************************************************************************
538 
539  //**SMP multiplication assignment to dense vectors**********************************************
551  template< typename VT2 > // Type of the target dense vector
552  friend inline void smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
553  {
555 
556  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
557 
558  smpMultAssign( ~lhs, rhs.sv_ );
559  }
561  //**********************************************************************************************
562 
563  //**SMP multiplication assignment to sparse vectors*********************************************
575  template< typename VT2 > // Type of the target sparse vector
576  friend inline void smpMultAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
577  {
579 
580  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
581 
582  smpMultAssign( ~lhs, rhs.sv_ );
583  }
585  //**********************************************************************************************
586 
587  //**Compile time checks*************************************************************************
592  //**********************************************************************************************
593 };
594 //*************************************************************************************************
595 
596 
597 
598 
599 //=================================================================================================
600 //
601 // GLOBAL FUNCTIONS
602 //
603 //=================================================================================================
604 
605 //*************************************************************************************************
622 template< typename VT // Type of the dense vector
623  , bool TF > // Transpose flag
625 {
627 
628  return SVecEvalExpr<VT,TF>( ~sv );
629 }
630 //*************************************************************************************************
631 
632 
633 
634 
635 //=================================================================================================
636 //
637 // GLOBAL RESTRUCTURING FUNCTIONS
638 //
639 //=================================================================================================
640 
641 //*************************************************************************************************
652 template< typename VT // Type of the sparse vector
653  , bool TF > // Transpose flag
654 inline const SVecEvalExpr<VT,TF> eval( const SVecEvalExpr<VT,TF>& sv )
655 {
656  return sv;
657 }
659 //*************************************************************************************************
660 
661 
662 
663 
664 //=================================================================================================
665 //
666 // EXPRESSION TRAIT SPECIALIZATIONS
667 //
668 //=================================================================================================
669 
670 //*************************************************************************************************
672 template< typename VT >
673 struct SVecEvalExprTrait< SVecEvalExpr<VT,false> >
674 {
675  public:
676  //**********************************************************************************************
677  typedef typename SelectType< IsSparseVector<VT>::value && IsColumnVector<VT>::value
678  , SVecEvalExpr<VT,false>
679  , INVALID_TYPE >::Type Type;
680  //**********************************************************************************************
681 };
683 //*************************************************************************************************
684 
685 
686 //*************************************************************************************************
688 template< typename VT >
689 struct TSVecEvalExprTrait< SVecEvalExpr<VT,true> >
690 {
691  public:
692  //**********************************************************************************************
693  typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value
694  , SVecEvalExpr<VT,true>
695  , INVALID_TYPE >::Type Type;
696  //**********************************************************************************************
697 };
699 //*************************************************************************************************
700 
701 
702 //*************************************************************************************************
704 template< typename VT, bool TF, bool AF >
705 struct SubvectorExprTrait< SVecEvalExpr<VT,TF>, AF >
706 {
707  public:
708  //**********************************************************************************************
709  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
710  //**********************************************************************************************
711 };
713 //*************************************************************************************************
714 
715 } // namespace blaze
716 
717 #endif
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecEvalExpr.h:96
Operand sv_
Sparse vector of the evaluation expression.
Definition: SVecEvalExpr.h:200
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:151
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:178
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:110
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecEvalExpr.h:149
Header file for the Computation base class.
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: SVecEvalExpr.h:95
Header file for the RequiresEvaluation type trait.
Header file for the VecEvalExpr base class.
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecEvalExpr.h:98
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SVecEvalExpr.h:193
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:121
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the dense vector SMP implementation.
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:179
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:139
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
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:269
Header file for the SelectType class template.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
Header file for the EnableIf class template.
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:91
Header file for the IsSparseVector type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Header file for run time assertion macros.
Utility type for generic codes.
SVecEvalExpr(const VT &sv)
Constructor for the SVecEvalExpr class.
Definition: SVecEvalExpr.h:117
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:209
Header file for the EvalExprTrait 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:239
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:183
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:584
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecEvalExpr.h:101
VT::ElementType ElementType
Resulting element type.
Definition: SVecEvalExpr.h:97
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecEvalExpr.h:104
Header file for the IsComputation type trait class.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecEvalExpr.h:159
Header file for the sparse vector SMP implementation.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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:2379
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:128
Header file for the SVecEvalExprTrait class template.
SVecEvalExpr< VT, TF > This
Type of this SVecEvalExpr instance.
Definition: SVecEvalExpr.h:94
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.
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecEvalExpr.h:171