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  //**Serial evaluation strategy******************************************************************
92 
98  enum { useAssign = RequiresEvaluation<VT>::value };
99 
101  template< typename VT2 >
103  struct UseAssign {
104  enum { value = useAssign };
105  };
107  //**********************************************************************************************
108 
109  //**Parallel evaluation strategy****************************************************************
111 
116  template< typename VT2 >
117  struct UseSMPAssign {
118  enum { value = VT2::smpAssignable && useAssign };
119  };
121  //**********************************************************************************************
122 
123  public:
124  //**Type definitions****************************************************************************
126  typedef typename VT::TransposeType ResultType;
127  typedef typename VT::ResultType TransposeType;
128  typedef typename VT::ElementType ElementType;
129  typedef typename VT::ReturnType ReturnType;
130 
133 
135  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
136  //**********************************************************************************************
137 
138  //**Compilation flags***************************************************************************
140  enum { smpAssignable = VT::smpAssignable };
141  //**********************************************************************************************
142 
143  //**ConstIterator class definition**************************************************************
147  {
148  public:
149  //**Type definitions*************************************************************************
152 
153  typedef std::forward_iterator_tag IteratorCategory;
154  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
155  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
156  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
157  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
158 
159  // STL iterator requirements
165  //*******************************************************************************************
166 
167  //**Constructor******************************************************************************
171  : it_( it ) // Iterator over the elements of the sparse vector expression
172  {}
173  //*******************************************************************************************
174 
175  //**Prefix increment operator****************************************************************
181  ++it_;
182  return *this;
183  }
184  //*******************************************************************************************
185 
186  //**Element access operator******************************************************************
191  inline const ValueType operator*() const {
192  return *it_;
193  }
194  //*******************************************************************************************
195 
196  //**Element access operator******************************************************************
201  inline const ConstIterator* operator->() const {
202  return this;
203  }
204  //*******************************************************************************************
205 
206  //**Value function***************************************************************************
211  inline ReturnType value() const {
212  return it_->value();
213  }
214  //*******************************************************************************************
215 
216  //**Index function***************************************************************************
221  inline size_t index() const {
222  return it_->index();
223  }
224  //*******************************************************************************************
225 
226  //**Equality operator************************************************************************
232  inline bool operator==( const ConstIterator& rhs ) const {
233  return it_ == rhs.it_;
234  }
235  //*******************************************************************************************
236 
237  //**Inequality operator**********************************************************************
243  inline bool operator!=( const ConstIterator& rhs ) const {
244  return it_ != rhs.it_;
245  }
246  //*******************************************************************************************
247 
248  //**Subtraction operator*********************************************************************
254  inline DifferenceType operator-( const ConstIterator& rhs ) const {
255  return it_ - rhs.it_;
256  }
257  //*******************************************************************************************
258 
259  private:
260  //**Member variables*************************************************************************
262  //*******************************************************************************************
263  };
264  //**********************************************************************************************
265 
266  //**Constructor*********************************************************************************
271  explicit inline SVecTransExpr( const VT& sv )
272  : sv_( sv ) // Sparse vector of the transposition expression
273  {}
274  //**********************************************************************************************
275 
276  //**Subscript operator**************************************************************************
282  inline ReturnType operator[]( size_t index ) const {
283  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
284  return sv_[index];
285  }
286  //**********************************************************************************************
287 
288  //**Begin function******************************************************************************
293  inline ConstIterator begin() const {
294  return ConstIterator( sv_.begin() );
295  }
296  //**********************************************************************************************
297 
298  //**End function********************************************************************************
303  inline ConstIterator end() const {
304  return ConstIterator( sv_.end() );
305  }
306  //**********************************************************************************************
307 
308  //**Size function*******************************************************************************
313  inline size_t size() const {
314  return sv_.size();
315  }
316  //**********************************************************************************************
317 
318  //**NonZeros function***************************************************************************
323  inline size_t nonZeros() const {
324  return sv_.nonZeros();
325  }
326  //**********************************************************************************************
327 
328  //**Operand access******************************************************************************
333  inline Operand operand() const {
334  return sv_;
335  }
336  //**********************************************************************************************
337 
338  //**********************************************************************************************
344  template< typename T >
345  inline bool canAlias( const T* alias ) const {
346  return sv_.canAlias( alias );
347  }
348  //**********************************************************************************************
349 
350  //**********************************************************************************************
356  template< typename T >
357  inline bool isAliased( const T* alias ) const {
358  return sv_.isAliased( alias );
359  }
360  //**********************************************************************************************
361 
362  //**********************************************************************************************
367  inline bool canSMPAssign() const {
368  return sv_.canSMPAssign();
369  }
370  //**********************************************************************************************
371 
372  private:
373  //**Member variables****************************************************************************
375  //**********************************************************************************************
376 
377  //**Assignment to dense vectors*****************************************************************
391  template< typename VT2 > // Type of the target dense vector
392  friend inline typename EnableIf< UseAssign<VT2> >::Type
393  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
394  {
396 
397  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
398 
399  DVecTransposer<VT2,!TF> tmp( ~lhs );
400  assign( tmp, rhs.sv_ );
401  }
403  //**********************************************************************************************
404 
405  //**Assignment to sparse vectors****************************************************************
419  template< typename VT2 > // Type of the target sparse vector
420  friend inline typename EnableIf< UseAssign<VT2> >::Type
421  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
422  {
424 
425  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
426 
427  SVecTransposer<VT2,!TF> tmp( ~lhs );
428  assign( tmp, rhs.sv_ );
429  }
431  //**********************************************************************************************
432 
433  //**Addition assignment to dense vectors********************************************************
447  template< typename VT2 > // Type of the target dense vector
448  friend inline typename EnableIf< UseAssign<VT2> >::Type
449  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
450  {
452 
453  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
454 
455  DVecTransposer<VT2,!TF> tmp( ~lhs );
456  addAssign( tmp, rhs.sv_ );
457  }
459  //**********************************************************************************************
460 
461  //**Addition assignment to sparse vectors*******************************************************
462  // No special implementation for the addition assignment to sparse vectors.
463  //**********************************************************************************************
464 
465  //**Subtraction assignment to dense vectors*****************************************************
479  template< typename VT2 > // Type of the target dense vector
480  friend inline typename EnableIf< UseAssign<VT2> >::Type
481  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
482  {
484 
485  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
486 
487  DVecTransposer<VT2,!TF> tmp( ~lhs );
488  subAssign( tmp, rhs.sv_ );
489  }
491  //**********************************************************************************************
492 
493  //**Subtraction assignment to sparse vectors****************************************************
494  // No special implementation for the subtraction assignment to sparse vectors.
495  //**********************************************************************************************
496 
497  //**Multiplication assignment to dense vectors**************************************************
511  template< typename VT2 > // Type of the target dense vector
512  friend inline typename EnableIf< UseAssign<VT2> >::Type
513  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
514  {
516 
517  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
518 
519  DVecTransposer<VT2,!TF> tmp( ~lhs );
520  multAssign( tmp, rhs.sv_ );
521  }
523  //**********************************************************************************************
524 
525  //**Multiplication assignment to sparse vectors*************************************************
526  // No special implementation for the multiplication assignment to sparse vectors.
527  //**********************************************************************************************
528 
529  //**SMP assignment to dense vectors*************************************************************
543  template< typename VT2 > // Type of the target dense vector
544  friend inline typename EnableIf< UseSMPAssign<VT2> >::Type
545  smpAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
546  {
548 
549  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
550 
551  DVecTransposer<VT2,!TF> tmp( ~lhs );
552  smpAssign( tmp, rhs.sv_ );
553  }
555  //**********************************************************************************************
556 
557  //**SMP assignment to sparse vectors************************************************************
571  template< typename VT2 > // Type of the target sparse vector
572  friend inline typename EnableIf< UseSMPAssign<VT2> >::Type
573  smpAssign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
574  {
576 
577  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
578 
579  SVecTransposer<VT2,!TF> tmp( ~lhs );
580  smpAssign( tmp, rhs.sv_ );
581  }
583  //**********************************************************************************************
584 
585  //**SMP addition assignment to dense vectors****************************************************
599  template< typename VT2 > // Type of the target dense vector
600  friend inline typename EnableIf< UseSMPAssign<VT2> >::Type
601  smpAddAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
602  {
604 
605  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
606 
607  DVecTransposer<VT2,!TF> tmp( ~lhs );
608  smpAddAssign( tmp, rhs.sv_ );
609  }
611  //**********************************************************************************************
612 
613  //**SMP addition assignment to sparse vectors***************************************************
614  // No special implementation for the SMP addition assignment to sparse vectors.
615  //**********************************************************************************************
616 
617  //**SMP subtraction assignment to dense vectors*************************************************
631  template< typename VT2 > // Type of the target dense vector
632  friend inline typename EnableIf< UseSMPAssign<VT2> >::Type
633  smpSubAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
634  {
636 
637  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
638 
639  DVecTransposer<VT2,!TF> tmp( ~lhs );
640  smpSubAssign( tmp, rhs.sv_ );
641  }
643  //**********************************************************************************************
644 
645  //**SMP subtraction assignment to sparse vectors************************************************
646  // No special implementation for the SMP subtraction assignment to sparse vectors.
647  //**********************************************************************************************
648 
649  //**SMP multiplication assignment to dense vectors**********************************************
664  template< typename VT2 > // Type of the target dense vector
665  friend inline typename EnableIf< UseSMPAssign<VT2> >::Type
666  smpMultAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
667  {
669 
670  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
671 
672  DVecTransposer<VT2,!TF> tmp( ~lhs );
673  smpMultAssign( tmp, rhs.sv_ );
674  }
676  //**********************************************************************************************
677 
678  //**SMP multiplication assignment to sparse vectors*********************************************
679  // No special implementation for the SMP multiplication assignment to sparse vectors.
680  //**********************************************************************************************
681 
682  //**Trans function******************************************************************************
700  template< typename VT2 // Type of the sparse vector
701  , bool TF2 > // Transpose flag of the sparse vector
702  friend inline Operand trans( const SVecTransExpr<VT2,TF2>& sv )
703  {
705 
706  return sv.sv_;
707  }
709  //**********************************************************************************************
710 
711  //**Compile time checks*************************************************************************
715  //**********************************************************************************************
716 };
717 //*************************************************************************************************
718 
719 
720 
721 
722 //=================================================================================================
723 //
724 // GLOBAL OPERATORS
725 //
726 //=================================================================================================
727 
728 //*************************************************************************************************
747 template< typename VT // Type of the sparse vector
748  , bool TF > // Transpose flag
750 {
752 
753  return SVecTransExpr<VT,!TF>( ~sv );
754 }
755 //*************************************************************************************************
756 
757 
758 
759 
760 //=================================================================================================
761 //
762 // EXPRESSION TRAIT SPECIALIZATIONS
763 //
764 //=================================================================================================
765 
766 //*************************************************************************************************
768 template< typename VT, bool TF, bool AF >
769 struct SubvectorExprTrait< SVecTransExpr<VT,TF>, AF >
770 {
771  public:
772  //**********************************************************************************************
773  typedef typename TransExprTrait< typename SubvectorExprTrait<const VT,AF>::Type >::Type Type;
774  //**********************************************************************************************
775 };
777 //*************************************************************************************************
778 
779 } // namespace blaze
780 
781 #endif
RemoveReference< Operand >::Type::ConstIterator IteratorType
Iterator type of the sparse vector expression.
Definition: SVecTransExpr.h:151
ConstIterator end() const
Returns an iterator just past the last non-zero element of the sparse vector.
Definition: SVecTransExpr.h:303
size_t size() const
Returns the current size/dimension of the vector.
Definition: SVecTransExpr.h:313
Header file for the SparseVector base class.
ConstIterator(IteratorType it)
Constructor for the ConstIterator class.
Definition: SVecTransExpr.h:170
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
ConstIterator & operator++()
Pre-increment operator.
Definition: SVecTransExpr.h:180
IteratorCategory iterator_category
The iterator category.
Definition: SVecTransExpr.h:160
SelectType< IsExpression< VT >::value, const VT, const VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SVecTransExpr.h:135
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
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SVecTransExpr.h:129
size_t nonZeros() const
Returns the number of non-zero elements in the sparse vector.
Definition: SVecTransExpr.h:323
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
ValueType value_type
Type of the underlying pointers.
Definition: SVecTransExpr.h:161
Operand sv_
Sparse vector of the transposition expression.
Definition: SVecTransExpr.h:374
Expression object for sparse vector transpositions.The SVecTransExpr class represents the compile tim...
Definition: Forward.h:122
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:261
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SVecTransExpr.h:345
VT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: SVecTransExpr.h:127
DifferenceType difference_type
Difference between two iterators.
Definition: SVecTransExpr.h:164
VT::TransposeType ResultType
Result type for expression template evaluations.
Definition: SVecTransExpr.h:126
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:221
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 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:293
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:163
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
const ValueType operator*() const
Direct access to the sparse vector element at the current iterator position.
Definition: SVecTransExpr.h:191
Iterator over the elements of the sparse vector absolute value expression.
Definition: SVecTransExpr.h:146
SelectType< useAssign, const ResultType, const SVecTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SVecTransExpr.h:132
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
Expression object for the transposition of a sparse vector.The SVecTransposer class is a wrapper obje...
Definition: Forward.h:123
VT::ElementType ElementType
Resulting element type.
Definition: SVecTransExpr.h:128
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:154
ReturnType operator[](size_t index) const
Subscript operator for the direct access to the vector elements.
Definition: SVecTransExpr.h:282
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2405
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
std::iterator_traits< IteratorType >::difference_type DifferenceType
Difference between two iterators.
Definition: SVecTransExpr.h:157
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.
ReturnType value() const
Access to the current value of the sparse element.
Definition: SVecTransExpr.h:211
Header file for the EnableIf class template.
std::iterator_traits< IteratorType >::pointer PointerType
Pointer return type.
Definition: SVecTransExpr.h:155
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
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SVecTransExpr.h:232
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
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:243
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:254
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
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:331
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SVecTransExpr.h:357
Header file for the TransExprTrait class template.
PointerType pointer
Pointer return type.
Definition: SVecTransExpr.h:162
SVecTransExpr(const VT &sv)
Constructor for the SVecTransExpr class.
Definition: SVecTransExpr.h:271
Header file for the RemoveReference type trait.
Operand operand() const
Returns the sparse vector operand.
Definition: SVecTransExpr.h:333
Header file for the sparse vector transposer.
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:907
SVecTransExpr< VT, TF > This
Type of this SVecTransExpr instance.
Definition: SVecTransExpr.h:125
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
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SVecTransExpr.h:153
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SVecTransExpr.h:367
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:201
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:156
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.