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/EnableIf.h>
63 #include <blaze/util/InvalidType.h>
65 #include <blaze/util/SelectType.h>
66 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS SVECEVALEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename VT // Type of the sparse vector
85  , bool TF > // Transpose flag
86 class SVecEvalExpr : public SparseVector< SVecEvalExpr<VT,TF>, TF >
87  , private VecEvalExpr
88  , private Computation
89 {
90  public:
91  //**Type definitions****************************************************************************
93  typedef typename VT::ResultType ResultType;
94  typedef typename VT::TransposeType TransposeType;
95  typedef typename VT::ElementType ElementType;
96  typedef typename VT::ReturnType ReturnType;
97 
99  typedef const ResultType CompositeType;
100 
102  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
103  //**********************************************************************************************
104 
105  //**Constructor*********************************************************************************
110  explicit inline SVecEvalExpr( const VT& sv )
111  : sv_( sv ) // Sparse vector of the evaluation expression
112  {}
113  //**********************************************************************************************
114 
115  //**Subscript operator**************************************************************************
121  inline ReturnType operator[]( size_t index ) const {
122  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
123  return sv_[index];
124  }
125  //**********************************************************************************************
126 
127  //**Size function*******************************************************************************
132  inline size_t size() const {
133  return sv_.size();
134  }
135  //**********************************************************************************************
136 
137  //**NonZeros function***************************************************************************
142  inline size_t nonZeros() const {
143  return sv_.nonZeros();
144  }
145  //**********************************************************************************************
146 
147  //**Operand access******************************************************************************
152  inline Operand operand() const {
153  return sv_;
154  }
155  //**********************************************************************************************
156 
157  //**********************************************************************************************
163  template< typename T >
164  inline bool canAlias( const T* alias ) const {
165  return sv_.canAlias( alias );
166  }
167  //**********************************************************************************************
168 
169  //**********************************************************************************************
175  template< typename T >
176  inline bool isAliased( const T* alias ) const {
177  return sv_.isAliased( alias );
178  }
179  //**********************************************************************************************
180 
181  private:
182  //**Member variables****************************************************************************
184  //**********************************************************************************************
185 
186  //**Assignment to dense vectors*****************************************************************
200  template< typename VT2 > // Type of the target dense vector
201  friend inline void assign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
202  {
204 
205  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
206 
207  assign( ~lhs, rhs.sv_ );
208  }
210  //**********************************************************************************************
211 
212  //**Assignment to sparse vectors****************************************************************
226  template< typename VT2 > // Type of the target sparse vector
227  friend inline void assign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
228  {
230 
231  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
232 
233  assign( ~lhs, rhs.sv_ );
234  }
236  //**********************************************************************************************
237 
238  //**Addition assignment to dense vectors********************************************************
252  template< typename VT2 > // Type of the target dense vector
253  friend inline void addAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
254  {
256 
257  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
258 
259  addAssign( ~lhs, rhs.sv_ );
260  }
262  //**********************************************************************************************
263 
264  //**Addition assignment to sparse vectors*******************************************************
278  template< typename VT2 > // Type of the target sparse vector
279  friend inline void addAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
280  {
282 
283  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
284 
285  addAssign( ~lhs, rhs.sv_ );
286  }
288  //**********************************************************************************************
289 
290  //**Subtraction assignment to dense vectors*****************************************************
304  template< typename VT2 > // Type of the target dense vector
305  friend inline void subAssign( DenseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
306  {
308 
309  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
310 
311  subAssign( ~lhs, rhs.sv_ );
312  }
314  //**********************************************************************************************
315 
316  //**Subtraction assignment to sparse vectors****************************************************
330  template< typename VT2 > // Type of the target sparse vector
331  friend inline void subAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
332  {
334 
335  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
336 
337  subAssign( ~lhs, rhs.sv_ );
338  }
340  //**********************************************************************************************
341 
342  //**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*************************************************
382  template< typename VT2 > // Type of the target sparse vector
383  friend inline void multAssign( SparseVector<VT2,TF>& lhs, const SVecEvalExpr& rhs )
384  {
386 
387  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
388 
389  multAssign( ~lhs, rhs.sv_ );
390  }
392  //**********************************************************************************************
393 
394  //**Compile time checks*************************************************************************
399  //**********************************************************************************************
400 };
401 //*************************************************************************************************
402 
403 
404 
405 
406 //=================================================================================================
407 //
408 // GLOBAL FUNCTIONS
409 //
410 //=================================================================================================
411 
412 //*************************************************************************************************
429 template< typename VT // Type of the dense vector
430  , bool TF > // Transpose flag
432 {
434 
435  return SVecEvalExpr<VT,TF>( ~sv );
436 }
437 //*************************************************************************************************
438 
439 
440 
441 
442 //=================================================================================================
443 //
444 // GLOBAL RESTRUCTURING FUNCTIONS
445 //
446 //=================================================================================================
447 
448 //*************************************************************************************************
459 template< typename VT // Type of the sparse vector
460  , bool TF > // Transpose flag
461 inline const SVecEvalExpr<VT,TF> eval( const SVecEvalExpr<VT,TF>& sv )
462 {
463  return sv;
464 }
466 //*************************************************************************************************
467 
468 
469 
470 
471 //=================================================================================================
472 //
473 // EXPRESSION TRAIT SPECIALIZATIONS
474 //
475 //=================================================================================================
476 
477 //*************************************************************************************************
479 template< typename VT >
480 struct SVecEvalExprTrait< SVecEvalExpr<VT,false> >
481 {
482  public:
483  //**********************************************************************************************
484  typedef typename SelectType< IsSparseVector<VT>::value && IsColumnVector<VT>::value
485  , SVecEvalExpr<VT,false>
486  , INVALID_TYPE >::Type Type;
487  //**********************************************************************************************
488 };
490 //*************************************************************************************************
491 
492 
493 //*************************************************************************************************
495 template< typename VT >
496 struct TSVecEvalExprTrait< SVecEvalExpr<VT,true> >
497 {
498  public:
499  //**********************************************************************************************
500  typedef typename SelectType< IsSparseVector<VT>::value && IsRowVector<VT>::value
501  , SVecEvalExpr<VT,true>
502  , INVALID_TYPE >::Type Type;
503  //**********************************************************************************************
504 };
506 //*************************************************************************************************
507 
508 
509 //*************************************************************************************************
511 template< typename VT, bool TF >
512 struct SubvectorExprTrait< SVecEvalExpr<VT,TF> >
513 {
514  public:
515  //**********************************************************************************************
516  typedef typename EvalExprTrait< typename SubvectorExprTrait<const VT>::Type >::Type Type;
517  //**********************************************************************************************
518 };
520 //*************************************************************************************************
521 
522 } // namespace blaze
523 
524 #endif
VT::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SVecEvalExpr.h:94
Operand sv_
Sparse vector of the evaluation expression.
Definition: SVecEvalExpr.h:183
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:110
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecEvalExpr.h:142
Header file for the Computation base class.
VT::ResultType ResultType
Result type for expression template evaluations.
Definition: SVecEvalExpr.h:93
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:96
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
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:132
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2372
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2373
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.
Header file for the IsSparseVector type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Header file for run time assertion macros.
Utility type for generic codes.
SVecEvalExpr(const VT &sv)
Constructor for the SVecEvalExpr class.
Definition: SVecEvalExpr.h:110
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:176
const DMatEvalExpr< MT, SO > eval(const DenseMatrix< MT, SO > &dm)
Forces the evaluation of the given dense matrix expression dm.
Definition: DMatEvalExpr.h:395
const ResultType CompositeType
Data type for composite expression templates.
Definition: SVecEvalExpr.h:99
VT::ElementType ElementType
Resulting element type.
Definition: SVecEvalExpr.h:95
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecEvalExpr.h:102
Header file for the IsComputation type trait class.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecEvalExpr.h:152
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:2370
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:121
Header file for the SVecEvalExprTrait class template.
SVecEvalExpr< VT, TF > This
Type of this SVecEvalExpr instance.
Definition: SVecEvalExpr.h:92
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:164