All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SVecTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_SVECTRANSEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <iterator>
31 #include <boost/type_traits/remove_reference.hpp>
42 #include <blaze/util/Assert.h>
43 #include <blaze/util/EmptyType.h>
44 #include <blaze/util/EnableIf.h>
45 #include <blaze/util/SelectType.h>
46 #include <blaze/util/Types.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS SVECTRANSEXPR
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
64 template< typename VT // Type of the sparse vector
65  , bool TF > // Transpose flag
66 class SVecTransExpr : public SparseVector< SVecTransExpr<VT,TF>, TF >
67  , private Expression
68  , private SelectType< IsComputation<VT>::value, Computation, EmptyType >::Type
69 {
70  private:
71  //**Type definitions****************************************************************************
72  typedef typename VT::CompositeType CT;
73  //**********************************************************************************************
74 
75  //**********************************************************************************************
77 
83  enum { useAssign = RequiresEvaluation<VT>::value };
84  //**********************************************************************************************
85 
86  //**********************************************************************************************
88 
89  template< typename VT2 >
90  struct UseAssign {
91  enum { value = useAssign };
92  };
94  //**********************************************************************************************
95 
96  public:
97  //**Type definitions****************************************************************************
99  typedef typename VT::TransposeType ResultType;
100  typedef typename VT::ResultType TransposeType;
101  typedef typename VT::ElementType ElementType;
102  typedef typename VT::ReturnType ReturnType;
103 
106 
108  typedef typename SelectType< IsExpression<VT>::value, const VT, const VT& >::Type Operand;
109  //**********************************************************************************************
110 
111  //**Compilation flags***************************************************************************
113  enum { canAlias = CanAlias<VT>::value };
114  //**********************************************************************************************
115 
116  //**ConstIterator class definition**************************************************************
120  {
121  public:
122  //**Type definitions*************************************************************************
124  typedef typename boost::remove_reference<Operand>::type::ConstIterator IteratorType;
125 
126  typedef std::forward_iterator_tag IteratorCategory;
127  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
128  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
129  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
130  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
131 
132  // STL iterator requirements
138  //*******************************************************************************************
139 
140  //**Constructor******************************************************************************
144  : it_( it ) // Iterator over the elements of the sparse vector expression
145  {}
146  //*******************************************************************************************
147 
148  //**Prefix increment operator****************************************************************
154  ++it_;
155  return *this;
156  }
157  //*******************************************************************************************
158 
159  //**Element access operator******************************************************************
164  inline const ValueType operator*() const {
165  return *it_;
166  }
167  //*******************************************************************************************
168 
169  //**Element access operator******************************************************************
174  inline const ConstIterator* operator->() const {
175  return this;
176  }
177  //*******************************************************************************************
178 
179  //**Value function***************************************************************************
184  inline ReturnType value() const {
185  return it_->value();
186  }
187  //*******************************************************************************************
188 
189  //**Index function***************************************************************************
194  inline size_t index() const {
195  return it_->index();
196  }
197  //*******************************************************************************************
198 
199  //**Equality operator************************************************************************
205  inline bool operator==( const ConstIterator& rhs ) const {
206  return it_ == rhs.it_;
207  }
208  //*******************************************************************************************
209 
210  //**Inequality operator**********************************************************************
216  inline bool operator!=( const ConstIterator& rhs ) const {
217  return it_ != rhs.it_;
218  }
219  //*******************************************************************************************
220 
221  //**Subtraction operator*********************************************************************
227  inline DifferenceType operator-( const ConstIterator& rhs ) const {
228  return it_ - rhs.it_;
229  }
230  //*******************************************************************************************
231 
232  private:
233  //**Member variables*************************************************************************
235  //*******************************************************************************************
236  };
237  //**********************************************************************************************
238 
239  //**Constructor*********************************************************************************
244  explicit inline SVecTransExpr( const VT& sv )
245  : sv_( sv ) // Sparse vector of the transposition expression
246  {}
247  //**********************************************************************************************
248 
249  //**Subscript operator**************************************************************************
255  inline ReturnType operator[]( size_t index ) const {
256  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
257  return sv_[index];
258  }
259  //**********************************************************************************************
260 
261  //**Begin function******************************************************************************
266  inline ConstIterator begin() const {
267  return ConstIterator( sv_.begin() );
268  }
269  //**********************************************************************************************
270 
271  //**End function********************************************************************************
276  inline ConstIterator end() const {
277  return ConstIterator( sv_.end() );
278  }
279  //**********************************************************************************************
280 
281  //**Size function*******************************************************************************
286  inline size_t size() const {
287  return sv_.size();
288  }
289  //**********************************************************************************************
290 
291  //**NonZeros function***************************************************************************
296  inline size_t nonZeros() const {
297  return sv_.nonZeros();
298  }
299  //**********************************************************************************************
300 
301  //**Operand access******************************************************************************
306  inline Operand operand() const {
307  return sv_;
308  }
309  //**********************************************************************************************
310 
311  //**********************************************************************************************
317  template< typename T >
318  inline bool isAliased( const T* alias ) const {
319  return CanAlias<VT>::value && sv_.isAliased( alias );
320  }
321  //**********************************************************************************************
322 
323  private:
324  //**Member variables****************************************************************************
326  //**********************************************************************************************
327 
328  //**Assignment to dense vectors*****************************************************************
342  template< typename VT2 > // Type of the target dense vector
343  friend inline typename EnableIf< UseAssign<VT2> >::Type
344  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
345  {
346  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
347 
348  DVecTransposer<VT2,!TF> tmp( ~lhs );
349  assign( tmp, rhs.sv_ );
350  }
352  //**********************************************************************************************
353 
354  //**Assignment to sparse vectors****************************************************************
368  template< typename VT2 > // Type of the target sparse vector
369  friend inline typename EnableIf< UseAssign<VT2> >::Type
370  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
371  {
372  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
373 
374  SVecTransposer<VT2,!TF> tmp( ~lhs );
375  assign( tmp, rhs.sv_ );
376  }
378  //**********************************************************************************************
379 
380  //**Addition assignment to dense vectors********************************************************
394  template< typename VT2 > // Type of the target dense vector
395  friend inline typename EnableIf< UseAssign<VT2> >::Type
396  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
397  {
398  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
399 
400  DVecTransposer<VT2,!TF> tmp( ~lhs );
401  addAssign( tmp, rhs.sv_ );
402  }
404  //**********************************************************************************************
405 
406  //**Addition assignment to sparse vectors*******************************************************
407  // No special implementation for the addition assignment to sparse vectors.
408  //**********************************************************************************************
409 
410  //**Subtraction assignment to dense vectors*****************************************************
424  template< typename VT2 > // Type of the target dense vector
425  friend inline typename EnableIf< UseAssign<VT2> >::Type
426  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
427  {
428  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
429 
430  DVecTransposer<VT2,!TF> tmp( ~lhs );
431  subAssign( tmp, rhs.sv_ );
432  }
434  //**********************************************************************************************
435 
436  //**Subtraction assignment to sparse vectors****************************************************
437  // No special implementation for the subtraction assignment to sparse vectors.
438  //**********************************************************************************************
439 
440  //**Multiplication assignment to dense vectors**************************************************
454  template< typename VT2 > // Type of the target dense vector
455  friend inline typename EnableIf< UseAssign<VT2> >::Type
456  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
457  {
458  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
459 
460  DVecTransposer<VT2,!TF> tmp( ~lhs );
461  multAssign( tmp, rhs.sv_ );
462  }
464  //**********************************************************************************************
465 
466  //**Multiplication assignment to sparse vectors*************************************************
467  // No special implementation for the multiplication assignment to sparse vectors.
468  //**********************************************************************************************
469 
470  //**Trans function******************************************************************************
488  template< typename VT2 // Type of the sparse vector
489  , bool TF2 > // Transpose flag of the sparse vector
490  friend inline Operand trans( const SVecTransExpr<VT2,TF2>& sv )
491  {
492  return sv.sv_;
493  }
495  //**********************************************************************************************
496 
497  //**Compile time checks*************************************************************************
501  //**********************************************************************************************
502 };
503 //*************************************************************************************************
504 
505 
506 
507 
508 //=================================================================================================
509 //
510 // GLOBAL OPERATORS
511 //
512 //=================================================================================================
513 
514 //*************************************************************************************************
533 template< typename VT // Type of the sparse vector
534  , bool TF > // Transpose flag
536 {
537  return SVecTransExpr<VT,!TF>( ~sv );
538 }
539 //*************************************************************************************************
540 
541 } // namespace blaze
542 
543 #endif