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>
40 #include <blaze/util/Assert.h>
41 #include <blaze/util/EmptyType.h>
42 #include <blaze/util/EnableIf.h>
44 #include <blaze/util/SelectType.h>
45 #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 VecTransExpr
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  //**ConstIterator class definition**************************************************************
115  {
116  public:
117  //**Type definitions*************************************************************************
120 
121  typedef std::forward_iterator_tag IteratorCategory;
122  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
123  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
124  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
125  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
126 
127  // STL iterator requirements
133  //*******************************************************************************************
134 
135  //**Constructor******************************************************************************
139  : it_( it ) // Iterator over the elements of the sparse vector expression
140  {}
141  //*******************************************************************************************
142 
143  //**Prefix increment operator****************************************************************
149  ++it_;
150  return *this;
151  }
152  //*******************************************************************************************
153 
154  //**Element access operator******************************************************************
159  inline const ValueType operator*() const {
160  return *it_;
161  }
162  //*******************************************************************************************
163 
164  //**Element access operator******************************************************************
169  inline const ConstIterator* operator->() const {
170  return this;
171  }
172  //*******************************************************************************************
173 
174  //**Value function***************************************************************************
179  inline ReturnType value() const {
180  return it_->value();
181  }
182  //*******************************************************************************************
183 
184  //**Index function***************************************************************************
189  inline size_t index() const {
190  return it_->index();
191  }
192  //*******************************************************************************************
193 
194  //**Equality operator************************************************************************
200  inline bool operator==( const ConstIterator& rhs ) const {
201  return it_ == rhs.it_;
202  }
203  //*******************************************************************************************
204 
205  //**Inequality operator**********************************************************************
211  inline bool operator!=( const ConstIterator& rhs ) const {
212  return it_ != rhs.it_;
213  }
214  //*******************************************************************************************
215 
216  //**Subtraction operator*********************************************************************
222  inline DifferenceType operator-( const ConstIterator& rhs ) const {
223  return it_ - rhs.it_;
224  }
225  //*******************************************************************************************
226 
227  private:
228  //**Member variables*************************************************************************
230  //*******************************************************************************************
231  };
232  //**********************************************************************************************
233 
234  //**Constructor*********************************************************************************
239  explicit inline SVecTransExpr( const VT& sv )
240  : sv_( sv ) // Sparse vector of the transposition expression
241  {}
242  //**********************************************************************************************
243 
244  //**Subscript operator**************************************************************************
250  inline ReturnType operator[]( size_t index ) const {
251  BLAZE_INTERNAL_ASSERT( index < sv_.size(), "Invalid vector access index" );
252  return sv_[index];
253  }
254  //**********************************************************************************************
255 
256  //**Begin function******************************************************************************
261  inline ConstIterator begin() const {
262  return ConstIterator( sv_.begin() );
263  }
264  //**********************************************************************************************
265 
266  //**End function********************************************************************************
271  inline ConstIterator end() const {
272  return ConstIterator( sv_.end() );
273  }
274  //**********************************************************************************************
275 
276  //**Size function*******************************************************************************
281  inline size_t size() const {
282  return sv_.size();
283  }
284  //**********************************************************************************************
285 
286  //**NonZeros function***************************************************************************
291  inline size_t nonZeros() const {
292  return sv_.nonZeros();
293  }
294  //**********************************************************************************************
295 
296  //**Operand access******************************************************************************
301  inline Operand operand() const {
302  return sv_;
303  }
304  //**********************************************************************************************
305 
306  //**********************************************************************************************
312  template< typename T >
313  inline bool canAlias( const T* alias ) const {
314  return sv_.canAlias( alias );
315  }
316  //**********************************************************************************************
317 
318  //**********************************************************************************************
324  template< typename T >
325  inline bool isAliased( const T* alias ) const {
326  return sv_.isAliased( alias );
327  }
328  //**********************************************************************************************
329 
330  private:
331  //**Member variables****************************************************************************
333  //**********************************************************************************************
334 
335  //**Assignment to dense vectors*****************************************************************
349  template< typename VT2 > // Type of the target dense vector
350  friend inline typename EnableIf< UseAssign<VT2> >::Type
351  assign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
352  {
354 
355  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
356 
357  DVecTransposer<VT2,!TF> tmp( ~lhs );
358  assign( tmp, rhs.sv_ );
359  }
361  //**********************************************************************************************
362 
363  //**Assignment to sparse vectors****************************************************************
377  template< typename VT2 > // Type of the target sparse vector
378  friend inline typename EnableIf< UseAssign<VT2> >::Type
379  assign( SparseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
380  {
382 
383  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
384 
385  SVecTransposer<VT2,!TF> tmp( ~lhs );
386  assign( tmp, rhs.sv_ );
387  }
389  //**********************************************************************************************
390 
391  //**Addition assignment to dense vectors********************************************************
405  template< typename VT2 > // Type of the target dense vector
406  friend inline typename EnableIf< UseAssign<VT2> >::Type
407  addAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
408  {
410 
411  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
412 
413  DVecTransposer<VT2,!TF> tmp( ~lhs );
414  addAssign( tmp, rhs.sv_ );
415  }
417  //**********************************************************************************************
418 
419  //**Addition assignment to sparse vectors*******************************************************
420  // No special implementation for the addition assignment to sparse vectors.
421  //**********************************************************************************************
422 
423  //**Subtraction assignment to dense vectors*****************************************************
437  template< typename VT2 > // Type of the target dense vector
438  friend inline typename EnableIf< UseAssign<VT2> >::Type
439  subAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
440  {
442 
443  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
444 
445  DVecTransposer<VT2,!TF> tmp( ~lhs );
446  subAssign( tmp, rhs.sv_ );
447  }
449  //**********************************************************************************************
450 
451  //**Subtraction assignment to sparse vectors****************************************************
452  // No special implementation for the subtraction assignment to sparse vectors.
453  //**********************************************************************************************
454 
455  //**Multiplication assignment to dense vectors**************************************************
469  template< typename VT2 > // Type of the target dense vector
470  friend inline typename EnableIf< UseAssign<VT2> >::Type
471  multAssign( DenseVector<VT2,TF>& lhs, const SVecTransExpr& rhs )
472  {
474 
475  BLAZE_INTERNAL_ASSERT( (~lhs).size() == rhs.size(), "Invalid vector sizes" );
476 
477  DVecTransposer<VT2,!TF> tmp( ~lhs );
478  multAssign( tmp, rhs.sv_ );
479  }
481  //**********************************************************************************************
482 
483  //**Multiplication assignment to sparse vectors*************************************************
484  // No special implementation for the multiplication assignment to sparse vectors.
485  //**********************************************************************************************
486 
487  //**Trans function******************************************************************************
505  template< typename VT2 // Type of the sparse vector
506  , bool TF2 > // Transpose flag of the sparse vector
507  friend inline Operand trans( const SVecTransExpr<VT2,TF2>& sv )
508  {
510 
511  return sv.sv_;
512  }
514  //**********************************************************************************************
515 
516  //**Compile time checks*************************************************************************
520  //**********************************************************************************************
521 };
522 //*************************************************************************************************
523 
524 
525 
526 
527 //=================================================================================================
528 //
529 // GLOBAL OPERATORS
530 //
531 //=================================================================================================
532 
533 //*************************************************************************************************
552 template< typename VT // Type of the sparse vector
553  , bool TF > // Transpose flag
555 {
557 
558  return SVecTransExpr<VT,!TF>( ~sv );
559 }
560 //*************************************************************************************************
561 
562 } // namespace blaze
563 
564 #endif