All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SMatTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTRANSEXPR_H_
23 #define _BLAZE_MATH_EXPRESSIONS_SMATTRANSEXPR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <iterator>
31 #include <boost/type_traits/remove_reference.hpp>
43 #include <blaze/util/Assert.h>
45 #include <blaze/util/EmptyType.h>
46 #include <blaze/util/EnableIf.h>
47 #include <blaze/util/SelectType.h>
48 #include <blaze/util/Types.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // CLASS SMATTRANSEXPR
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
66 template< typename MT // Type of the sparse matrix
67  , bool SO > // Storage order
68 class SMatTransExpr : public SparseMatrix< SMatTransExpr<MT,SO>, SO >
69  , private Expression
70  , private SelectType< IsComputation<MT>::value, Computation, EmptyType >::Type
71 {
72  private:
73  //**Type definitions****************************************************************************
74  typedef typename MT::ResultType RT;
75  typedef typename MT::CompositeType CT;
76  //**********************************************************************************************
77 
78  //**********************************************************************************************
80 
86  enum { useAssign = RequiresEvaluation<MT>::value };
87  //**********************************************************************************************
88 
89  //**********************************************************************************************
91 
92  template< typename MT2 >
93  struct UseAssign {
94  enum { value = useAssign };
95  };
97  //**********************************************************************************************
98 
99  public:
100  //**Type definitions****************************************************************************
102  typedef typename MT::TransposeType ResultType;
103  typedef typename MT::OppositeType OppositeType;
104  typedef typename MT::ResultType TransposeType;
105  typedef typename MT::ElementType ElementType;
106  typedef typename MT::ReturnType ReturnType;
107 
110 
112  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
113  //**********************************************************************************************
114 
115  //**Compilation flags***************************************************************************
117  enum { canAlias = 1 };
118  //**********************************************************************************************
119 
120  //**ConstIterator class definition**************************************************************
124  {
125  public:
126  //**Type definitions*************************************************************************
128  typedef typename boost::remove_reference<Operand>::type::ConstIterator IteratorType;
129 
130  typedef std::forward_iterator_tag IteratorCategory;
131  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
132  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
133  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
134  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
135 
136  // STL iterator requirements
142  //*******************************************************************************************
143 
144  //**Constructor******************************************************************************
148  : it_( it ) // Iterator over the elements of the sparse matrix expression
149  {}
150  //*******************************************************************************************
151 
152  //**Prefix increment operator****************************************************************
158  ++it_;
159  return *this;
160  }
161  //*******************************************************************************************
162 
163  //**Element access operator******************************************************************
168  inline const ValueType operator*() const {
169  return *it_;
170  }
171  //*******************************************************************************************
172 
173  //**Element access operator******************************************************************
178  inline const IteratorType operator->() const {
179  return it_;
180  }
181  //*******************************************************************************************
182 
183  //**Value function***************************************************************************
188  inline ReturnType value() const {
189  return it_->value();
190  }
191  //*******************************************************************************************
192 
193  //**Index function***************************************************************************
198  inline size_t index() const {
199  return it_->index();
200  }
201  //*******************************************************************************************
202 
203  //**Equality operator************************************************************************
209  inline bool operator==( const ConstIterator& rhs ) const {
210  return it_ == rhs.it_;
211  }
212  //*******************************************************************************************
213 
214  //**Inequality operator**********************************************************************
220  inline bool operator!=( const ConstIterator& rhs ) const {
221  return it_ != rhs.it_;
222  }
223  //*******************************************************************************************
224 
225  //**Subtraction operator*********************************************************************
231  inline DifferenceType operator-( const ConstIterator& rhs ) const {
232  return it_ - rhs.it_;
233  }
234  //*******************************************************************************************
235 
236  private:
237  //**Member variables*************************************************************************
239  //*******************************************************************************************
240  };
241  //**********************************************************************************************
242 
243  //**Constructor*********************************************************************************
248  explicit inline SMatTransExpr( const MT& sm )
249  : sm_( sm )
250  {}
251  //**********************************************************************************************
252 
253  //**Access operator*****************************************************************************
260  inline ReturnType operator()( size_t i, size_t j ) const {
261  BLAZE_INTERNAL_ASSERT( i < sm_.columns(), "Invalid row access index" );
262  BLAZE_INTERNAL_ASSERT( j < sm_.rows() , "Invalid column access index" );
263  return sm_(j,i);
264  }
265  //**********************************************************************************************
266 
267  //**Begin function******************************************************************************
273  inline ConstIterator begin( size_t i ) const {
274  return sm_.begin(i);
275  }
276  //**********************************************************************************************
277 
278  //**End function********************************************************************************
284  inline ConstIterator end( size_t i ) const {
285  return sm_.end(i);
286  }
287  //**********************************************************************************************
288 
289  //**Rows function*******************************************************************************
294  inline size_t rows() const {
295  return sm_.columns();
296  }
297  //**********************************************************************************************
298 
299  //**Columns function****************************************************************************
304  inline size_t columns() const {
305  return sm_.rows();
306  }
307  //**********************************************************************************************
308 
309  //**NonZeros function***************************************************************************
314  inline size_t nonZeros() const {
315  return sm_.nonZeros();
316  }
317  //**********************************************************************************************
318 
319  //**Operand access******************************************************************************
324  inline Operand operand() const {
325  return sm_;
326  }
327  //**********************************************************************************************
328 
329  //**********************************************************************************************
335  template< typename T >
336  inline bool isAliased( const T* alias ) const {
337  return sm_.isAliased( alias );
338  }
339  //**********************************************************************************************
340 
341  private:
342  //**Member variables****************************************************************************
344  //**********************************************************************************************
345 
346  //**Assignment to dense matrices****************************************************************
360  template< typename MT2 // Type of the target dense matrix
361  , bool SO2 > // Storage order of the target dense matrix
362  friend inline typename EnableIf< UseAssign<MT2> >::Type
363  assign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
364  {
365  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
366  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
367 
368  DMatTransposer<MT2,!SO2> tmp( ~lhs );
369  assign( tmp, rhs.sm_ );
370  }
372  //**********************************************************************************************
373 
374  //**Assignment to sparse matrices***************************************************************
388  template< typename MT2 // Type of the target sparse matrix
389  , bool SO2 > // Storage order of the target sparse matrix
390  friend inline typename EnableIf< UseAssign<MT2> >::Type
391  assign( SparseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
392  {
393  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
394  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
395 
396  SMatTransposer<MT2,!SO2> tmp( ~lhs );
397  assign( tmp, rhs.sm_ );
398  }
400  //**********************************************************************************************
401 
402  //**Addition assignment to dense matrices*******************************************************
416  template< typename MT2 // Type of the target dense matrix
417  , bool SO2 > // Storage order of the target dense matrix
418  friend inline typename EnableIf< UseAssign<MT2> >::Type
419  addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
420  {
421  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
422  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
423 
424  DMatTransposer<MT2,!SO2> tmp( ~lhs );
425  addAssign( tmp, rhs.sm_ );
426  }
428  //**********************************************************************************************
429 
430  //**Addition assignment to sparse matrices******************************************************
431  // No special implementation for the addition assignment to sparse matrices.
432  //**********************************************************************************************
433 
434  //**Subtraction assignment to dense matrices****************************************************
448  template< typename MT2 // Type of the target dense matrix
449  , bool SO2 > // Storage order of the target dense matrix
450  friend inline typename EnableIf< UseAssign<MT2> >::Type
451  subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
452  {
453  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
454  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
455 
456  DMatTransposer<MT2,!SO2> tmp( ~lhs );
457  subAssign( tmp, rhs.sm_ );
458  }
460  //**********************************************************************************************
461 
462  //**Subtraction assignment to sparse matrices***************************************************
463  // No special implementation for the subtraction assignment to sparse matrices.
464  //**********************************************************************************************
465 
466  //**Multiplication assignment to dense matrices*************************************************
467  // No special implementation for the multiplication assignment to dense matrices.
468  //**********************************************************************************************
469 
470  //**Multiplication assignment to sparse matrices************************************************
471  // No special implementation for the multiplication assignment to sparse matrices.
472  //**********************************************************************************************
473 
474  //**Trans function******************************************************************************
490  template< typename MT2 // Type of the sparse matrix
491  , bool SO2 > // Storage order of the sparse matrix
492  friend inline Operand trans( const SMatTransExpr<MT2,SO2>& sm )
493  {
494  return sm.sm_;
495  }
497  //**********************************************************************************************
498 
499  //**Compile time checks*************************************************************************
504  //**********************************************************************************************
505 };
506 //*************************************************************************************************
507 
508 
509 
510 
511 //=================================================================================================
512 //
513 // GLOBAL OPERATORS
514 //
515 //=================================================================================================
516 
517 //*************************************************************************************************
532 template< typename MT // Type of the sparse matrix
533  , bool SO > // Storage order
535 {
536  return SMatTransExpr<MT,!SO>( ~sm );
537 }
538 //*************************************************************************************************
539 
540 } // namespace blaze
541 
542 #endif