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>
46 #include <blaze/util/Assert.h>
48 #include <blaze/util/EmptyType.h>
49 #include <blaze/util/EnableIf.h>
51 #include <blaze/util/SelectType.h>
52 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS SMATTRANSEXPR
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
70 template< typename MT // Type of the sparse matrix
71  , bool SO > // Storage order
72 class SMatTransExpr : public SparseMatrix< SMatTransExpr<MT,SO>, SO >
73  , private Expression
74  , private SelectType< IsComputation<MT>::value, Computation, EmptyType >::Type
75 {
76  private:
77  //**Type definitions****************************************************************************
78  typedef typename MT::ResultType RT;
79  typedef typename MT::CompositeType CT;
80  //**********************************************************************************************
81 
82  //**********************************************************************************************
84 
90  enum { useAssign = RequiresEvaluation<MT>::value };
91  //**********************************************************************************************
92 
93  //**********************************************************************************************
95 
96  template< typename MT2 >
97  struct UseAssign {
98  enum { value = useAssign };
99  };
101  //**********************************************************************************************
102 
103  public:
104  //**Type definitions****************************************************************************
106  typedef typename MT::TransposeType ResultType;
107  typedef typename MT::OppositeType OppositeType;
108  typedef typename MT::ResultType TransposeType;
109  typedef typename MT::ElementType ElementType;
110  typedef typename MT::ReturnType ReturnType;
111 
114 
116  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
117  //**********************************************************************************************
118 
119  //**ConstIterator class definition**************************************************************
123  {
124  public:
125  //**Type definitions*************************************************************************
127  typedef typename boost::remove_reference<Operand>::type::ConstIterator IteratorType;
128 
129  typedef std::forward_iterator_tag IteratorCategory;
130  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
131  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
132  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
133  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
134 
135  // STL iterator requirements
141  //*******************************************************************************************
142 
143  //**Constructor******************************************************************************
147  : it_( it ) // Iterator over the elements of the sparse matrix expression
148  {}
149  //*******************************************************************************************
150 
151  //**Prefix increment operator****************************************************************
157  ++it_;
158  return *this;
159  }
160  //*******************************************************************************************
161 
162  //**Element access operator******************************************************************
167  inline const ValueType operator*() const {
168  return *it_;
169  }
170  //*******************************************************************************************
171 
172  //**Element access operator******************************************************************
177  inline const IteratorType operator->() const {
178  return it_;
179  }
180  //*******************************************************************************************
181 
182  //**Value function***************************************************************************
187  inline ReturnType value() const {
188  return it_->value();
189  }
190  //*******************************************************************************************
191 
192  //**Index function***************************************************************************
197  inline size_t index() const {
198  return it_->index();
199  }
200  //*******************************************************************************************
201 
202  //**Equality operator************************************************************************
208  inline bool operator==( const ConstIterator& rhs ) const {
209  return it_ == rhs.it_;
210  }
211  //*******************************************************************************************
212 
213  //**Inequality operator**********************************************************************
219  inline bool operator!=( const ConstIterator& rhs ) const {
220  return it_ != rhs.it_;
221  }
222  //*******************************************************************************************
223 
224  //**Subtraction operator*********************************************************************
230  inline DifferenceType operator-( const ConstIterator& rhs ) const {
231  return it_ - rhs.it_;
232  }
233  //*******************************************************************************************
234 
235  private:
236  //**Member variables*************************************************************************
238  //*******************************************************************************************
239  };
240  //**********************************************************************************************
241 
242  //**Constructor*********************************************************************************
247  explicit inline SMatTransExpr( const MT& sm )
248  : sm_( sm )
249  {}
250  //**********************************************************************************************
251 
252  //**Access operator*****************************************************************************
259  inline ReturnType operator()( size_t i, size_t j ) const {
260  BLAZE_INTERNAL_ASSERT( i < sm_.columns(), "Invalid row access index" );
261  BLAZE_INTERNAL_ASSERT( j < sm_.rows() , "Invalid column access index" );
262  return sm_(j,i);
263  }
264  //**********************************************************************************************
265 
266  //**Begin function******************************************************************************
272  inline ConstIterator begin( size_t i ) const {
273  return sm_.begin(i);
274  }
275  //**********************************************************************************************
276 
277  //**End function********************************************************************************
283  inline ConstIterator end( size_t i ) const {
284  return sm_.end(i);
285  }
286  //**********************************************************************************************
287 
288  //**Rows function*******************************************************************************
293  inline size_t rows() const {
294  return sm_.columns();
295  }
296  //**********************************************************************************************
297 
298  //**Columns function****************************************************************************
303  inline size_t columns() const {
304  return sm_.rows();
305  }
306  //**********************************************************************************************
307 
308  //**NonZeros function***************************************************************************
313  inline size_t nonZeros() const {
314  return sm_.nonZeros();
315  }
316  //**********************************************************************************************
317 
318  //**Operand access******************************************************************************
323  inline Operand operand() const {
324  return sm_;
325  }
326  //**********************************************************************************************
327 
328  //**********************************************************************************************
334  template< typename T >
335  inline bool canAlias( const T* alias ) const {
336  return sm_.canAlias( alias );
337  }
338  //**********************************************************************************************
339 
340  //**********************************************************************************************
346  template< typename T >
347  inline bool isAliased( const T* alias ) const {
348  return sm_.isAliased( alias );
349  }
350  //**********************************************************************************************
351 
352  private:
353  //**Member variables****************************************************************************
355  //**********************************************************************************************
356 
357  //**Assignment to dense matrices****************************************************************
371  template< typename MT2 // Type of the target dense matrix
372  , bool SO2 > // Storage order of the target dense matrix
373  friend inline typename EnableIf< UseAssign<MT2> >::Type
374  assign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
375  {
377 
378  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
379  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
380 
381  DMatTransposer<MT2,!SO2> tmp( ~lhs );
382  assign( tmp, rhs.sm_ );
383  }
385  //**********************************************************************************************
386 
387  //**Assignment to sparse matrices***************************************************************
401  template< typename MT2 // Type of the target sparse matrix
402  , bool SO2 > // Storage order of the target sparse matrix
403  friend inline typename EnableIf< UseAssign<MT2> >::Type
404  assign( SparseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
405  {
407 
408  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
409  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
410 
411  SMatTransposer<MT2,!SO2> tmp( ~lhs );
412  assign( tmp, rhs.sm_ );
413  }
415  //**********************************************************************************************
416 
417  //**Addition assignment to dense matrices*******************************************************
431  template< typename MT2 // Type of the target dense matrix
432  , bool SO2 > // Storage order of the target dense matrix
433  friend inline typename EnableIf< UseAssign<MT2> >::Type
434  addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
435  {
437 
438  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
439  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
440 
441  DMatTransposer<MT2,!SO2> tmp( ~lhs );
442  addAssign( tmp, rhs.sm_ );
443  }
445  //**********************************************************************************************
446 
447  //**Addition assignment to sparse matrices******************************************************
448  // No special implementation for the addition assignment to sparse matrices.
449  //**********************************************************************************************
450 
451  //**Subtraction assignment to dense matrices****************************************************
465  template< typename MT2 // Type of the target dense matrix
466  , bool SO2 > // Storage order of the target dense matrix
467  friend inline typename EnableIf< UseAssign<MT2> >::Type
468  subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
469  {
471 
472  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
473  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
474 
475  DMatTransposer<MT2,!SO2> tmp( ~lhs );
476  subAssign( tmp, rhs.sm_ );
477  }
479  //**********************************************************************************************
480 
481  //**Subtraction assignment to sparse matrices***************************************************
482  // No special implementation for the subtraction assignment to sparse matrices.
483  //**********************************************************************************************
484 
485  //**Multiplication assignment to dense matrices*************************************************
486  // No special implementation for the multiplication assignment to dense matrices.
487  //**********************************************************************************************
488 
489  //**Multiplication assignment to sparse matrices************************************************
490  // No special implementation for the multiplication assignment to sparse matrices.
491  //**********************************************************************************************
492 
493  //**Trans function******************************************************************************
509  template< typename MT2 // Type of the sparse matrix
510  , bool SO2 > // Storage order of the sparse matrix
511  friend inline Operand trans( const SMatTransExpr<MT2,SO2>& sm )
512  {
514 
515  return sm.sm_;
516  }
518  //**********************************************************************************************
519 
520  //**Compile time checks*************************************************************************
525  //**********************************************************************************************
526 };
527 //*************************************************************************************************
528 
529 
530 
531 
532 //=================================================================================================
533 //
534 // GLOBAL OPERATORS
535 //
536 //=================================================================================================
537 
538 //*************************************************************************************************
553 template< typename MT // Type of the sparse matrix
554  , bool SO > // Storage order
556 {
558 
559  return SMatTransExpr<MT,!SO>( ~sm );
560 }
561 //*************************************************************************************************
562 
563 
564 //*************************************************************************************************
576 template< typename MT // Type of the sparse matrix
577  , bool SO > // Storage order
578 inline typename RowExprTrait< SMatTransExpr<MT,SO> >::Type
579  row( const SMatTransExpr<MT,SO>& sm, size_t index )
580 {
582 
583  return trans( column( sm.operand(), index ) );
584 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
601 template< typename MT // Type of the sparse matrix
602  , bool SO > // Storage order
603 inline typename ColumnExprTrait< SMatTransExpr<MT,SO> >::Type
604  column( const SMatTransExpr<MT,SO>& sm, size_t index )
605 {
607 
608  return trans( row( sm.operand(), index ) );
609 }
611 //*************************************************************************************************
612 
613 
614 
615 
616 //=================================================================================================
617 //
618 // EXPRESSION TRAIT SPECIALIZATIONS
619 //
620 //=================================================================================================
621 
622 //*************************************************************************************************
624 template< typename MT, bool SO >
625 struct RowExprTrait< SMatTransExpr<MT,SO> >
626 {
627  public:
628  //**********************************************************************************************
629  typedef typename TransExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
630  //**********************************************************************************************
631 };
633 //*************************************************************************************************
634 
635 
636 //*************************************************************************************************
638 template< typename MT, bool SO >
639 struct ColumnExprTrait< SMatTransExpr<MT,SO> >
640 {
641  public:
642  //**********************************************************************************************
643  typedef typename TransExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
644  //**********************************************************************************************
645 };
647 //*************************************************************************************************
648 
649 } // namespace blaze
650 
651 #endif