All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
55 #include <blaze/util/Assert.h>
56 #include <blaze/util/EmptyType.h>
57 #include <blaze/util/EnableIf.h>
59 #include <blaze/util/SelectType.h>
60 #include <blaze/util/Types.h>
62 
63 
64 namespace blaze {
65 
66 //=================================================================================================
67 //
68 // CLASS SVECTRANSEXPR
69 //
70 //=================================================================================================
71 
72 //*************************************************************************************************
79 template< typename VT // Type of the sparse vector
80  , bool TF > // Transpose flag
81 class SVecTransExpr : public SparseVector< SVecTransExpr<VT,TF>, TF >
82  , private VecTransExpr
83  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
84 {
85  private:
86  //**Type definitions****************************************************************************
87  typedef typename VT::CompositeType CT;
88  //**********************************************************************************************
89 
90  //**********************************************************************************************
92 
98  enum { useAssign = RequiresEvaluation<VT>::value };
99  //**********************************************************************************************
100 
101  //**********************************************************************************************
103  template< typename VT2 >
105  struct UseAssign {
106  enum { value = useAssign };
107  };
109  //**********************************************************************************************
110 
111  public:
112  //**Type definitions****************************************************************************
114  typedef typename VT::TransposeType ResultType;
115  typedef typename VT::ResultType TransposeType;
116  typedef typename VT::ElementType ElementType;
117  typedef typename VT::ReturnType ReturnType;
118 
121 
123  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
124  //**********************************************************************************************
125 
126  //**ConstIterator class definition**************************************************************
130  {
131  public:
132  //**Type definitions*************************************************************************
135 
136  typedef std::forward_iterator_tag IteratorCategory;
137  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
138  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
139  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
140  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
141 
142  // STL iterator requirements
148  //*******************************************************************************************
149 
150  //**Constructor******************************************************************************
154  : it_( it ) // Iterator over the elements of the sparse vector expression
155  {}
156  //*******************************************************************************************
157 
158  //**Prefix increment operator****************************************************************
164  ++it_;
165  return *this;
166  }
167  //*******************************************************************************************
168 
169  //**Element access operator******************************************************************
174  inline const ValueType operator*() const {
175  return *it_;
176  }
177  //*******************************************************************************************
178 
179  //**Element access operator******************************************************************
184  inline const ConstIterator* operator->() const {
185  return this;
186  }
187  //*******************************************************************************************
188 
189  //**Value function***************************************************************************
194  inline ReturnType value() const {
195  return it_->value();
196  }
197  //*******************************************************************************************
198 
199  //**Index function***************************************************************************
204  inline size_t index() const {
205  return it_->index();
206  }
207  //*******************************************************************************************
208 
209  //**Equality operator************************************************************************
215  inline bool operator==( const ConstIterator& rhs ) const {
216  return it_ == rhs.it_;
217  }
218  //*******************************************************************************************
219 
220  //**Inequality operator**********************************************************************
226  inline bool operator!=( const ConstIterator& rhs ) const {
227  return it_ != rhs.it_;
228  }
229  //*******************************************************************************************
230 
231  //**Subtraction operator*********************************************************************
237  inline DifferenceType operator-( const ConstIterator& rhs ) const {
238  return it_ - rhs.it_;
239  }
240  //*******************************************************************************************
241 
242  private:
243  //**Member variables*************************************************************************
245  //*******************************************************************************************
246  };
247  //**********************************************************************************************
248 
249  //**Constructor*********************************************************************************
254  explicit inline SVecTransExpr( const VT& sv )
255  : sv_( sv ) // Sparse vector of the transposition expression
256  {}
257  //**********************************************************************************************
258 
259  //**Subscript operator**************************************************************************
265  inline ReturnType operator[]( size_t index ) const {
266  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
267  return sv_[index];
268  }
269  //**********************************************************************************************
270 
271  //**Begin function******************************************************************************
276  inline ConstIterator begin() const {
277  return ConstIterator( sv_.begin() );
278  }
279  //**********************************************************************************************
280 
281  //**End function********************************************************************************
286  inline ConstIterator end() const {
287  return ConstIterator( sv_.end() );
288  }
289  //**********************************************************************************************
290 
291  //**Size function*******************************************************************************
296  inline size_t size() const {
297  return sv_.size();
298  }
299  //**********************************************************************************************
300 
301  //**NonZeros function***************************************************************************
306  inline size_t nonZeros() const {
307  return sv_.nonZeros();
308  }
309  //**********************************************************************************************
310 
311  //**Operand access******************************************************************************
316  inline Operand operand() const {
317  return sv_;
318  }
319  //**********************************************************************************************
320 
321  //**********************************************************************************************
327  template< typename T >
328  inline bool canAlias( const T* alias ) const {
329  return sv_.canAlias( alias );
330  }
331  //**********************************************************************************************
332 
333  //**********************************************************************************************
339  template< typename T >
340  inline bool isAliased( const T* alias ) const {
341  return sv_.isAliased( alias );
342  }
343  //**********************************************************************************************
344 
345  private:
346  //**Member variables****************************************************************************
348  //**********************************************************************************************
349 
350  //**Assignment to dense vectors*****************************************************************
364  template< typename VT2 > // Type of the target dense vector
365  friend inline typename EnableIf< UseAssign<VT2> >::Type
366  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
367  {
369 
370  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
371 
372  DVecTransposer<VT2,!TF> tmp( ~lhs );
373  assign( tmp, rhs.sv_ );
374  }
376  //**********************************************************************************************
377 
378  //**Assignment to sparse vectors****************************************************************
392  template< typename VT2 > // Type of the target sparse vector
393  friend inline typename EnableIf< UseAssign<VT2> >::Type
394  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
395  {
397 
398  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
399 
400  SVecTransposer<VT2,!TF> tmp( ~lhs );
401  assign( tmp, rhs.sv_ );
402  }
404  //**********************************************************************************************
405 
406  //**Addition assignment to dense vectors********************************************************
420  template< typename VT2 > // Type of the target dense vector
421  friend inline typename EnableIf< UseAssign<VT2> >::Type
422  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
423  {
425 
426  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
427 
428  DVecTransposer<VT2,!TF> tmp( ~lhs );
429  addAssign( tmp, rhs.sv_ );
430  }
432  //**********************************************************************************************
433 
434  //**Addition assignment to sparse vectors*******************************************************
435  // No special implementation for the addition assignment to sparse vectors.
436  //**********************************************************************************************
437 
438  //**Subtraction assignment to dense vectors*****************************************************
452  template< typename VT2 > // Type of the target dense vector
453  friend inline typename EnableIf< UseAssign<VT2> >::Type
454  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
455  {
457 
458  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
459 
460  DVecTransposer<VT2,!TF> tmp( ~lhs );
461  subAssign( tmp, rhs.sv_ );
462  }
464  //**********************************************************************************************
465 
466  //**Subtraction assignment to sparse vectors****************************************************
467  // No special implementation for the subtraction assignment to sparse vectors.
468  //**********************************************************************************************
469 
470  //**Multiplication assignment to dense vectors**************************************************
484  template< typename VT2 > // Type of the target dense vector
485  friend inline typename EnableIf< UseAssign<VT2> >::Type
486  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
487  {
489 
490  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
491 
492  DVecTransposer<VT2,!TF> tmp( ~lhs );
493  multAssign( tmp, rhs.sv_ );
494  }
496  //**********************************************************************************************
497 
498  //**Multiplication assignment to sparse vectors*************************************************
499  // No special implementation for the multiplication assignment to sparse vectors.
500  //**********************************************************************************************
501 
502  //**Trans function******************************************************************************
520  template< typename VT2 // Type of the sparse vector
521  , bool TF2 > // Transpose flag of the sparse vector
522  friend inline Operand trans( const SVecTransExpr<VT2,TF2>& sv )
523  {
525 
526  return sv.sv_;
527  }
529  //**********************************************************************************************
530 
531  //**Compile time checks*************************************************************************
535  //**********************************************************************************************
536 };
537 //*************************************************************************************************
538 
539 
540 
541 
542 //=================================================================================================
543 //
544 // GLOBAL OPERATORS
545 //
546 //=================================================================================================
547 
548 //*************************************************************************************************
567 template< typename VT // Type of the sparse vector
568  , bool TF > // Transpose flag
570 {
572 
573  return SVecTransExpr<VT,!TF>( ~sv );
574 }
575 //*************************************************************************************************
576 
577 
578 
579 
580 //=================================================================================================
581 //
582 // EXPRESSION TRAIT SPECIALIZATIONS
583 //
584 //=================================================================================================
585 
586 //*************************************************************************************************
588 template< typename VT, bool TF >
589 struct SubvectorExprTrait< SVecTransExpr<VT,TF> >
590 {
591  public:
592  //**********************************************************************************************
593  typedef typename TransExprTrait< typename SubvectorExprTrait<const VT>::Type >::Type Type;
594  //**********************************************************************************************
595 };
597 //*************************************************************************************************
598 
599 } // namespace blaze
600 
601 #endif
RemoveReference< Operand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: SVecTransExpr.h:134
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransExpr.h:286
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:296
Header file for the SparseVector base class.
ConstIterator(IteratorType it)
Constructor for the ConstIterator class.
Definition: SVecTransExpr.h:153
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:446
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTransExpr.h:163
IteratorCategory iterator_category
The iterator category.
Definition: SVecTransExpr.h:143
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:123
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:117
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:306
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
ValueType value_type
Type of the underlying pointers.
Definition: SVecTransExpr.h:144
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:347
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:118
Header file for the Computation base class.
Header file for the RequiresEvaluation type trait.
IteratorType it_
Iterator over the elements of the sparse vector expression.
Definition: SVecTransExpr.h:244
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:328
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:115
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTransExpr.h:147
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:114
Expression object for the transposition of a dense vector.The DVecTransposer class is a wrapper objec...
Definition: DVecTransposer.h:71
size_t index() const
Access to the current index of the sparse element.
Definition: SVecTransExpr.h:204
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
ConstIterator begin() const
Returns an iterator to the first non-zero element of the sparse vector.
Definition: SVecTransExpr.h:276
VT::CompositeType CT
Composite type of the sparse vector expression.
Definition: SVecTransExpr.h:87
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 transposer.
ReferenceType reference
Reference return type.
Definition: SVecTransExpr.h:146
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
const ValueType operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecTransExpr.h:174
Iterator over the elements of the sparse vector absolute value expression.
Definition: SVecTransExpr.h:129
SelectType< useAssign, const ResultType, const SVecTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:120
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
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:119
VT::ElementType ElementType
Resulting element type.
Definition: SVecTransExpr.h:116
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
std::iterator_traits< IteratorType >::value_type ValueType
Type of the underlying pointers.
Definition: SVecTransExpr.h:137
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:265
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
std::iterator_traits< IteratorType >::difference_type DifferenceType
Difference between two iterators.
Definition: SVecTransExpr.h:140
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.
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTransExpr.h:194
Header file for the EnableIf class template.
std::iterator_traits< IteratorType >::pointer PointerType
Pointer return type.
Definition: SVecTransExpr.h:138
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTransExpr.h:215
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2374
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for the VecTransExpr base class.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SVecTransExpr.h:226
Header file for run time assertion macros.
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SVecTransExpr.h:237
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
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
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
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:340
Header file for the TransExprTrait class template.
PointerType pointer
Pointer return type.
Definition: SVecTransExpr.h:145
SVecTransExpr(const VT &sv)
Constructor for the SVecTransExpr class.
Definition: SVecTransExpr.h:254
Header file for the RemoveReference type trait.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecTransExpr.h:316
Header file for the sparse vector transposer.
SVecTransExpr< VT, TF > This
Type of this SVecTransExpr instance.
Definition: SVecTransExpr.h:113
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
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTransExpr.h:136
Header file for basic type definitions.
Header file for the SubvectorExprTrait class template.
const ConstIterator * operator->() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecTransExpr.h:184
Header file for the empty type.
#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
std::iterator_traits< IteratorType >::reference ReferenceType
Reference return type.
Definition: SVecTransExpr.h:139
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.