All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SMatTransExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTRANSEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATTRANSEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
59 #include <blaze/util/Assert.h>
61 #include <blaze/util/EmptyType.h>
62 #include <blaze/util/EnableIf.h>
64 #include <blaze/util/SelectType.h>
65 #include <blaze/util/Types.h>
67 
68 
69 namespace blaze {
70 
71 //=================================================================================================
72 //
73 // CLASS SMATTRANSEXPR
74 //
75 //=================================================================================================
76 
77 //*************************************************************************************************
84 template< typename MT // Type of the sparse matrix
85  , bool SO > // Storage order
86 class SMatTransExpr : public SparseMatrix< SMatTransExpr<MT,SO>, SO >
87  , private MatTransExpr
88  , private SelectType< IsComputation<MT>::value, Computation, EmptyType >::Type
89 {
90  private:
91  //**Type definitions****************************************************************************
92  typedef typename MT::ResultType RT;
93  typedef typename MT::CompositeType CT;
94  //**********************************************************************************************
95 
96  //**********************************************************************************************
98 
104  enum { useAssign = RequiresEvaluation<MT>::value };
105  //**********************************************************************************************
106 
107  //**********************************************************************************************
109  template< typename MT2 >
111  struct UseAssign {
112  enum { value = useAssign };
113  };
115  //**********************************************************************************************
116 
117  public:
118  //**Type definitions****************************************************************************
120  typedef typename MT::TransposeType ResultType;
121  typedef typename MT::OppositeType OppositeType;
122  typedef typename MT::ResultType TransposeType;
123  typedef typename MT::ElementType ElementType;
124  typedef typename MT::ReturnType ReturnType;
125 
128 
130  typedef typename SelectType< IsExpression<MT>::value, const MT, const MT& >::Type Operand;
131  //**********************************************************************************************
132 
133  //**ConstIterator class definition**************************************************************
137  {
138  public:
139  //**Type definitions*************************************************************************
142 
143  typedef std::forward_iterator_tag IteratorCategory;
144  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
145  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
146  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
147  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
148 
149  // STL iterator requirements
155  //*******************************************************************************************
156 
157  //**Constructor******************************************************************************
161  : it_( it ) // Iterator over the elements of the sparse matrix expression
162  {}
163  //*******************************************************************************************
164 
165  //**Prefix increment operator****************************************************************
171  ++it_;
172  return *this;
173  }
174  //*******************************************************************************************
175 
176  //**Element access operator******************************************************************
181  inline const ValueType operator*() const {
182  return *it_;
183  }
184  //*******************************************************************************************
185 
186  //**Element access operator******************************************************************
191  inline const IteratorType operator->() const {
192  return it_;
193  }
194  //*******************************************************************************************
195 
196  //**Value function***************************************************************************
201  inline ReturnType value() const {
202  return it_->value();
203  }
204  //*******************************************************************************************
205 
206  //**Index function***************************************************************************
211  inline size_t index() const {
212  return it_->index();
213  }
214  //*******************************************************************************************
215 
216  //**Equality operator************************************************************************
222  inline bool operator==( const ConstIterator& rhs ) const {
223  return it_ == rhs.it_;
224  }
225  //*******************************************************************************************
226 
227  //**Inequality operator**********************************************************************
233  inline bool operator!=( const ConstIterator& rhs ) const {
234  return it_ != rhs.it_;
235  }
236  //*******************************************************************************************
237 
238  //**Subtraction operator*********************************************************************
244  inline DifferenceType operator-( const ConstIterator& rhs ) const {
245  return it_ - rhs.it_;
246  }
247  //*******************************************************************************************
248 
249  private:
250  //**Member variables*************************************************************************
252  //*******************************************************************************************
253  };
254  //**********************************************************************************************
255 
256  //**Compilation flags***************************************************************************
258  enum { smpAssignable = MT::smpAssignable };
259  //**********************************************************************************************
260 
261  //**Constructor*********************************************************************************
266  explicit inline SMatTransExpr( const MT& sm )
267  : sm_( sm )
268  {}
269  //**********************************************************************************************
270 
271  //**Access operator*****************************************************************************
278  inline ReturnType operator()( size_t i, size_t j ) const {
279  BLAZE_INTERNAL_ASSERT( i < sm_.columns(), "Invalid row access index" );
280  BLAZE_INTERNAL_ASSERT( j < sm_.rows() , "Invalid column access index" );
281  return sm_(j,i);
282  }
283  //**********************************************************************************************
284 
285  //**Begin function******************************************************************************
291  inline ConstIterator begin( size_t i ) const {
292  return sm_.begin(i);
293  }
294  //**********************************************************************************************
295 
296  //**End function********************************************************************************
302  inline ConstIterator end( size_t i ) const {
303  return sm_.end(i);
304  }
305  //**********************************************************************************************
306 
307  //**Rows function*******************************************************************************
312  inline size_t rows() const {
313  return sm_.columns();
314  }
315  //**********************************************************************************************
316 
317  //**Columns function****************************************************************************
322  inline size_t columns() const {
323  return sm_.rows();
324  }
325  //**********************************************************************************************
326 
327  //**NonZeros function***************************************************************************
332  inline size_t nonZeros() const {
333  return sm_.nonZeros();
334  }
335  //**********************************************************************************************
336 
337  //**Operand access******************************************************************************
342  inline Operand operand() const {
343  return sm_;
344  }
345  //**********************************************************************************************
346 
347  //**********************************************************************************************
353  template< typename T >
354  inline bool canAlias( const T* alias ) const {
355  return sm_.canAlias( alias );
356  }
357  //**********************************************************************************************
358 
359  //**********************************************************************************************
365  template< typename T >
366  inline bool isAliased( const T* alias ) const {
367  return sm_.isAliased( alias );
368  }
369  //**********************************************************************************************
370 
371  //**********************************************************************************************
376  inline bool canSMPAssign() const {
377  return sm_.canSMPAssign();
378  }
379  //**********************************************************************************************
380 
381  private:
382  //**Member variables****************************************************************************
384  //**********************************************************************************************
385 
386  //**Assignment to dense matrices****************************************************************
400  template< typename MT2 // Type of the target dense matrix
401  , bool SO2 > // Storage order of the target dense matrix
402  friend inline typename EnableIf< UseAssign<MT2> >::Type
403  assign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
404  {
406 
407  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
408  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
409 
410  DMatTransposer<MT2,!SO2> tmp( ~lhs );
411  assign( tmp, rhs.sm_ );
412  }
414  //**********************************************************************************************
415 
416  //**Assignment to sparse matrices***************************************************************
430  template< typename MT2 // Type of the target sparse matrix
431  , bool SO2 > // Storage order of the target sparse matrix
432  friend inline typename EnableIf< UseAssign<MT2> >::Type
433  assign( SparseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
434  {
436 
437  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
438  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
439 
440  SMatTransposer<MT2,!SO2> tmp( ~lhs );
441  assign( tmp, rhs.sm_ );
442  }
444  //**********************************************************************************************
445 
446  //**Addition assignment to dense matrices*******************************************************
460  template< typename MT2 // Type of the target dense matrix
461  , bool SO2 > // Storage order of the target dense matrix
462  friend inline typename EnableIf< UseAssign<MT2> >::Type
463  addAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
464  {
466 
467  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
468  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
469 
470  DMatTransposer<MT2,!SO2> tmp( ~lhs );
471  addAssign( tmp, rhs.sm_ );
472  }
474  //**********************************************************************************************
475 
476  //**Addition assignment to sparse matrices******************************************************
477  // No special implementation for the addition assignment to sparse matrices.
478  //**********************************************************************************************
479 
480  //**Subtraction assignment to dense matrices****************************************************
494  template< typename MT2 // Type of the target dense matrix
495  , bool SO2 > // Storage order of the target dense matrix
496  friend inline typename EnableIf< UseAssign<MT2> >::Type
497  subAssign( DenseMatrix<MT2,SO2>& lhs, const SMatTransExpr& rhs )
498  {
500 
501  BLAZE_INTERNAL_ASSERT( (~lhs).rows() == rhs.rows() , "Invalid number of rows" );
502  BLAZE_INTERNAL_ASSERT( (~lhs).columns() == rhs.columns(), "Invalid number of columns" );
503 
504  DMatTransposer<MT2,!SO2> tmp( ~lhs );
505  subAssign( tmp, rhs.sm_ );
506  }
508  //**********************************************************************************************
509 
510  //**Subtraction assignment to sparse matrices***************************************************
511  // No special implementation for the subtraction assignment to sparse matrices.
512  //**********************************************************************************************
513 
514  //**Multiplication assignment to dense matrices*************************************************
515  // No special implementation for the multiplication assignment to dense matrices.
516  //**********************************************************************************************
517 
518  //**Multiplication assignment to sparse matrices************************************************
519  // No special implementation for the multiplication assignment to sparse matrices.
520  //**********************************************************************************************
521 
522  //**Trans function******************************************************************************
538  template< typename MT2 // Type of the sparse matrix
539  , bool SO2 > // Storage order of the sparse matrix
540  friend inline Operand trans( const SMatTransExpr<MT2,SO2>& sm )
541  {
543 
544  return sm.sm_;
545  }
547  //**********************************************************************************************
548 
549  //**Compile time checks*************************************************************************
554  //**********************************************************************************************
555 };
556 //*************************************************************************************************
557 
558 
559 
560 
561 //=================================================================================================
562 //
563 // GLOBAL OPERATORS
564 //
565 //=================================================================================================
566 
567 //*************************************************************************************************
582 template< typename MT // Type of the sparse matrix
583  , bool SO > // Storage order
585 {
587 
588  return SMatTransExpr<MT,!SO>( ~sm );
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // EXPRESSION TRAIT SPECIALIZATIONS
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
603 template< typename MT, bool SO, bool AF >
604 struct SubmatrixExprTrait< SMatTransExpr<MT,SO>, AF >
605 {
606  public:
607  //**********************************************************************************************
608  typedef typename TransExprTrait< typename SubmatrixExprTrait<const MT,AF>::Type >::Type Type;
609  //**********************************************************************************************
610 };
612 //*************************************************************************************************
613 
614 
615 //*************************************************************************************************
617 template< typename MT, bool SO >
618 struct RowExprTrait< SMatTransExpr<MT,SO> >
619 {
620  public:
621  //**********************************************************************************************
622  typedef typename TransExprTrait< typename ColumnExprTrait<const MT>::Type >::Type Type;
623  //**********************************************************************************************
624 };
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
631 template< typename MT, bool SO >
632 struct ColumnExprTrait< SMatTransExpr<MT,SO> >
633 {
634  public:
635  //**********************************************************************************************
636  typedef typename TransExprTrait< typename RowExprTrait<const MT>::Type >::Type Type;
637  //**********************************************************************************************
638 };
640 //*************************************************************************************************
641 
642 } // namespace blaze
643 
644 #endif
Header file for the sparse matrix transposer.
bool operator!=(const ConstIterator &rhs) const
Inequality comparison between two ConstIterator objects.
Definition: SMatTransExpr.h:233
RemoveReference< Operand >::Type::ConstIterator IteratorType
Iterator type of the sparse matrix expression.
Definition: SMatTransExpr.h:141
MT::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTransExpr.h:121
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransExpr.h:291
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:751
PointerType pointer
Pointer return type.
Definition: SMatTransExpr.h:152
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_WITH_STORAGE_ORDER(T, SO)
Constraint on the data type.In case the given data type T is not a dense or sparse matrix type and in...
Definition: StorageOrder.h:242
Header file for the MatTransExpr base class.
Iterator over the elements of the sparse matrix transposition expression.
Definition: SMatTransExpr.h:136
Header file for the ColumnExprTrait class template.
MT::CompositeType CT
Composite type of the sparse matrix expression.
Definition: SMatTransExpr.h:93
Operand sm_
Sparse matrix of the transposition expression.
Definition: SMatTransExpr.h:383
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
DifferenceType operator-(const ConstIterator &rhs) const
Calculating the number of elements between two expression iterators.
Definition: SMatTransExpr.h:244
Header file for the Computation base class.
MT::ResultType RT
Result type of the sparse matrix expression.
Definition: SMatTransExpr.h:92
Header file for the RequiresEvaluation type trait.
std::iterator_traits< IteratorType >::value_type ValueType
Type of the underlying pointers.
Definition: SMatTransExpr.h:144
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2380
ReferenceType reference
Reference return type.
Definition: SMatTransExpr.h:153
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:104
Constraint on the data type.
Header file for the SparseMatrix base class.
Constraint on the data type.
std::iterator_traits< IteratorType >::difference_type DifferenceType
Difference between two iterators.
Definition: SMatTransExpr.h:147
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
MT::ResultType TransposeType
Transpose type for expression template evaluations.
Definition: SMatTransExpr.h:122
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SMatTransExpr.h:124
MT::TransposeType ResultType
Result type for expression template evaluations.
Definition: SMatTransExpr.h:120
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
std::iterator_traits< IteratorType >::reference ReferenceType
Reference return type.
Definition: SMatTransExpr.h:146
bool canAlias(const T *alias) const
Returns whether the expression can alias with the given address alias.
Definition: SMatTransExpr.h:354
SMatTransExpr(const MT &sm)
Constructor for the SMatTransExpr class.
Definition: SMatTransExpr.h:266
IteratorType it_
Iterator over the elements of the sparse matrix expression.
Definition: SMatTransExpr.h:251
MT::ElementType ElementType
Resulting element type.
Definition: SMatTransExpr.h:123
IteratorCategory iterator_category
The iterator category.
Definition: SMatTransExpr.h:150
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:179
size_t columns() const
Returns the current number of columns of the matrix.
Definition: SMatTransExpr.h:322
Expression object for the transposition of a dense matrix.The DMatTransposer class is a wrapper objec...
Definition: DMatTransposer.h:71
ConstIterator(IteratorType it)
Constructor for the ConstIterator class.
Definition: SMatTransExpr.h:160
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2381
Constraints on the storage order of matrix types.
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
Header file for the SelectType class template.
Header file for the RowExprTrait class template.
Header file for all forward declarations for expression class templates.
Header file for the EnableIf class template.
Header file for the dense matrix transposer.
const IteratorType operator->() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatTransExpr.h:191
Expression object for the transposition of a sparse matrix.The SMatTransposer class is a wrapper obje...
Definition: Forward.h:100
ReturnType operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTransExpr.h:278
Header file for the SubmatrixExprTrait class template.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
SelectType< IsExpression< MT >::value, const MT, const MT & >::Type Operand
Composite data type of the sparse matrix expression.
Definition: SMatTransExpr.h:130
Header file for run time assertion macros.
bool canSMPAssign() const
Returns whether the expression can be used in SMP assignments.
Definition: SMatTransExpr.h:376
SelectType< useAssign, const ResultType, const SMatTransExpr & >::Type CompositeType
Data type for composite expression templates.
Definition: SMatTransExpr.h:127
SMatTransExpr< MT, SO > This
Type of this SMatTransExpr instance.
Definition: SMatTransExpr.h:119
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:209
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:239
std::iterator_traits< IteratorType >::pointer PointerType
Pointer return type.
Definition: SMatTransExpr.h:145
Header file for the TransExprTrait class template.
Operand operand() const
Returns the sparse matrix operand.
Definition: SMatTransExpr.h:342
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: SMatTransExpr.h:332
size_t rows() const
Returns the current number of rows of the matrix.
Definition: SMatTransExpr.h:312
Header file for the RemoveReference type trait.
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SMatTransExpr.h:143
DifferenceType difference_type
Difference between two iterators.
Definition: SMatTransExpr.h:154
ReturnType value() const
Access to the current value of the sparse element.
Definition: SMatTransExpr.h:201
size_t index() const
Access to the current index of the sparse element.
Definition: SMatTransExpr.h:211
bool operator==(const ConstIterator &rhs) const
Equality comparison between two ConstIterator objects.
Definition: SMatTransExpr.h:222
Header file for the IsComputation type trait class.
#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
Expression object for sparse matrix transpositions.The SMatTransExpr class represents the compile tim...
Definition: Forward.h:99
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransExpr.h:302
Header file for basic type definitions.
const ValueType operator*() const
Direct access to the sparse matrix element at the current iterator position.
Definition: SMatTransExpr.h:181
ValueType value_type
Type of the underlying pointers.
Definition: SMatTransExpr.h:151
ConstIterator & operator++()
Pre-increment operator.
Definition: SMatTransExpr.h:170
bool isAliased(const T *alias) const
Returns whether the expression is aliased with the given address alias.
Definition: SMatTransExpr.h:366
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
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.