SMatTransposer.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTRANSPOSER_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATTRANSPOSER_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Aliases.h>
46 #include <blaze/math/Exception.h>
51 #include <blaze/util/Assert.h>
52 #include <blaze/util/Types.h>
53 
54 
55 namespace blaze {
56 
57 //=================================================================================================
58 //
59 // CLASS SMATTRANSPOSER
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
69 template< typename MT // Type of the sparse matrix
70  , bool SO > // Storage order
71 class SMatTransposer
72  : public SparseMatrix< SMatTransposer<MT,SO>, SO >
73 {
74  public:
75  //**Type definitions****************************************************************************
78  using OppositeType = MT;
82  using CompositeType = const This&;
87  //**********************************************************************************************
88 
89  //**Compilation flags***************************************************************************
91 
94  enum : bool { smpAssignable = MT::smpAssignable };
95  //**********************************************************************************************
96 
97  //**Constructor*********************************************************************************
102  explicit inline SMatTransposer( MT& sm ) noexcept
103  : sm_( sm ) // The sparse matrix operand
104  {}
105  //**********************************************************************************************
106 
107  //**Access operator*****************************************************************************
114  inline ConstReference operator()( size_t i, size_t j ) const {
115  BLAZE_INTERNAL_ASSERT( i < sm_.columns(), "Invalid row access index" );
116  BLAZE_INTERNAL_ASSERT( j < sm_.rows() , "Invalid column access index" );
117  return const_cast<const MT&>( sm_ )(j,i);
118  }
119  //**********************************************************************************************
120 
121  //**At function*********************************************************************************
129  inline ConstReference at( size_t i, size_t j ) const {
130  if( i >= sm_.columns() ) {
131  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
132  }
133  if( j >= sm_.rows() ) {
134  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
135  }
136  return (*this)(i,j);
137  }
138  //**********************************************************************************************
139 
140  //**Begin function******************************************************************************
151  inline Iterator begin( size_t i ) {
152  return sm_.begin(i);
153  }
154  //**********************************************************************************************
155 
156  //**Begin function******************************************************************************
167  inline ConstIterator begin( size_t i ) const {
168  return sm_.cbegin(i);
169  }
170  //**********************************************************************************************
171 
172  //**Cbegin function*****************************************************************************
183  inline ConstIterator cbegin( size_t i ) const {
184  return sm_.cbegin(i);
185  }
186  //**********************************************************************************************
187 
188  //**End function********************************************************************************
199  inline Iterator end( size_t i ) {
200  return sm_.end(i);
201  }
202  //**********************************************************************************************
203 
204  //**End function********************************************************************************
215  inline ConstIterator end( size_t i ) const {
216  return sm_.cend(i);
217  }
218  //**********************************************************************************************
219 
220  //**Cend function*******************************************************************************
231  inline ConstIterator cend( size_t i ) const {
232  return sm_.cend(i);
233  }
234  //**********************************************************************************************
235 
236  //**Rows function*******************************************************************************
241  inline size_t rows() const noexcept {
242  return sm_.columns();
243  }
244  //**********************************************************************************************
245 
246  //**Columns function****************************************************************************
251  inline size_t columns() const noexcept {
252  return sm_.rows();
253  }
254  //**********************************************************************************************
255 
256  //**Capacity function***************************************************************************
261  inline size_t capacity() const noexcept {
262  return sm_.capacity();
263  }
264  //**********************************************************************************************
265 
266  //**Capacity function***************************************************************************
272  inline size_t capacity( size_t i ) const noexcept {
273  return sm_.capacity( i );
274  }
275  //**********************************************************************************************
276 
277  //**NonZeros function***************************************************************************
282  inline size_t nonZeros() const {
283  return sm_.nonZeros();
284  }
285  //**********************************************************************************************
286 
287  //**NonZeros function***************************************************************************
293  inline size_t nonZeros( size_t i ) const {
294  return sm_.nonZeros( i );
295  }
296  //**********************************************************************************************
297 
298  //**Reset function******************************************************************************
303  inline void reset() {
304  return sm_.reset();
305  }
306  //**********************************************************************************************
307 
308  //**Insert function*****************************************************************************
321  inline Iterator insert( size_t i, size_t j, const ElementType& value ) {
322  return sm_.insert( j, i, value );
323  }
324  //**********************************************************************************************
325 
326  //**Reserve function****************************************************************************
336  inline void reserve( size_t nonzeros ) {
337  sm_.reserve( nonzeros );
338  }
339  //**********************************************************************************************
340 
341  //**Reserve function****************************************************************************
355  inline void reserve( size_t i, size_t nonzeros ) {
356  sm_.reserve( i, nonzeros );
357  }
358  //**********************************************************************************************
359 
360  //**Append function*****************************************************************************
387  inline void append( size_t i, size_t j, const ElementType& value, bool check=false ) {
388  sm_.append( j, i, value, check );
389  }
390  //**********************************************************************************************
391 
392  //**Finalize function***************************************************************************
405  inline void finalize( size_t i ) {
406  sm_.finalize( i );
407  }
408  //**********************************************************************************************
409 
410  //**IsIntact function***************************************************************************
415  inline bool isIntact() const noexcept {
416  using blaze::isIntact;
417  return isIntact( sm_ );
418  }
419  //**********************************************************************************************
420 
421  //**********************************************************************************************
427  template< typename Other > // Data type of the foreign expression
428  inline bool canAlias( const Other* alias ) const noexcept
429  {
430  return sm_.canAlias( alias );
431  }
432  //**********************************************************************************************
433 
434  //**********************************************************************************************
440  template< typename Other > // Data type of the foreign expression
441  inline bool isAliased( const Other* alias ) const noexcept
442  {
443  return sm_.isAliased( alias );
444  }
445  //**********************************************************************************************
446 
447  //**CanSMPAssign function***********************************************************************
452  inline bool canSMPAssign() const noexcept
453  {
454  return sm_.canSMPAssign();
455  }
456  //**********************************************************************************************
457 
458  //**Transpose assignment of matrices************************************************************
469  template< typename MT2 // Type of the right-hand side matrix
470  , bool SO2 > // Storage order of the right-hand side matrix
471  inline void assign( const Matrix<MT2,SO2>& rhs )
472  {
473  sm_.assign( trans( ~rhs ) );
474  }
475  //**********************************************************************************************
476 
477  private:
478  //**Member variables****************************************************************************
479  MT& sm_;
480  //**********************************************************************************************
481 
482  //**Compile time checks*************************************************************************
487  //**********************************************************************************************
488 };
489 //*************************************************************************************************
490 
491 
492 
493 
494 //=================================================================================================
495 //
496 // GLOBAL OPERATORS
497 //
498 //=================================================================================================
499 
500 //*************************************************************************************************
508 template< typename MT // Type of the sparse matrix
509  , bool SO > // Storage order
510 inline void reset( SMatTransposer<MT,SO>& m )
511 {
512  m.reset();
513 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
526 template< typename MT // Type of the sparse matrix
527  , bool SO > // Storage order
528 inline bool isIntact( const SMatTransposer<MT,SO>& m ) noexcept
529 {
530  return m.isIntact();
531 }
533 //*************************************************************************************************
534 
535 
536 
537 
538 //=================================================================================================
539 //
540 // SUBMATRIXTRAIT SPECIALIZATIONS
541 //
542 //=================================================================================================
543 
544 //*************************************************************************************************
546 template< typename MT, bool SO, size_t... CSAs >
547 struct SubmatrixTrait< SMatTransposer<MT,SO>, CSAs... >
548 {
549  using Type = SubmatrixTrait_< ResultType_< SMatTransposer<MT,SO> >, CSAs... >;
550 };
552 //*************************************************************************************************
553 
554 
555 
556 
557 //=================================================================================================
558 //
559 // ROWSTRAIT SPECIALIZATIONS
560 //
561 //=================================================================================================
562 
563 //*************************************************************************************************
565 template< typename MT, bool SO, size_t... CRAs >
566 struct RowsTrait< SMatTransposer<MT,SO>, CRAs... >
567 {
568  using Type = RowsTrait_< ResultType_< SMatTransposer<MT,SO> >, CRAs... >;
569 };
571 //*************************************************************************************************
572 
573 
574 
575 
576 //=================================================================================================
577 //
578 // COLUMNSTRAIT SPECIALIZATIONS
579 //
580 //=================================================================================================
581 
582 //*************************************************************************************************
584 template< typename MT, bool SO, size_t... CCAs >
585 struct ColumnsTrait< SMatTransposer<MT,SO>, CCAs... >
586 {
587  using Type = ColumnsTrait_< ResultType_< SMatTransposer<MT,SO> >, CCAs... >;
588 };
590 //*************************************************************************************************
591 
592 } // namespace blaze
593 
594 #endif
size_t capacity(size_t i) const noexcept
Returns the current capacity of the specified row/column.
Definition: SMatTransposer.h:272
Constraint on the data type.
Header file for auxiliary alias declarations.
Header file for basic type definitions.
ReturnType_< MT > ReturnType
Return type for expression template evaluations.
Definition: SMatTransposer.h:81
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTransposer.h:129
Base template for the SubmatrixTrait class.
Definition: SubmatrixTrait.h:109
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:231
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:81
SMatTransposer(MT &sm) noexcept
Constructor for the SMatTransposer class.
Definition: SMatTransposer.h:102
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: SMatTransposer.h:441
MT OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTransposer.h:78
Iterator_< MT > Iterator
Iterator over non-constant elements.
Definition: SMatTransposer.h:85
Constraints on the storage order of matrix types.
typename SubmatrixTrait< MT, CSAs... >::Type SubmatrixTrait_
Auxiliary alias declaration for the SubmatrixTrait type trait.The SubmatrixTrait_ alias declaration p...
Definition: SubmatrixTrait.h:145
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTransposer.h:251
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
bool isIntact() const noexcept
Returns whether the invariants of the matrix are intact.
Definition: SMatTransposer.h:415
Base template for the RowsTrait class.
Definition: RowsTrait.h:109
MT & sm_
The sparse matrix operand.
Definition: SMatTransposer.h:479
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:363
Header file for the SparseMatrix base class.
void reserve(size_t i, size_t nonzeros)
Setting the minimum capacity of a specific row/column of the sparse matrix.
Definition: SMatTransposer.h:355
size_t nonZeros() const
Returns the number of non-zero elements in the matrix.
Definition: SMatTransposer.h:282
typename ColumnsTrait< MT, CCAs... >::Type ColumnsTrait_
Auxiliary alias declaration for the ColumnsTrait type trait.The ColumnsTrait_ alias declaration provi...
Definition: ColumnsTrait.h:145
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:151
ConstReference operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTransposer.h:114
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Reference_< MT > Reference
Reference to a non-constant matrix value.
Definition: SMatTransposer.h:83
void reset()
Resets the matrix elements.
Definition: SMatTransposer.h:303
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:167
Header file for the exception macros of the math module.
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:215
ConstIterator cbegin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:183
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:303
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: SMatTransposer.h:336
typename RowsTrait< MT, CRAs... >::Type RowsTrait_
Auxiliary alias declaration for the RowsTrait type trait.The RowsTrait_ alias declaration provides a ...
Definition: RowsTrait.h:145
ConstIterator_< MT > ConstIterator
Iterator over constant elements.
Definition: SMatTransposer.h:86
TransposeType_< MT > ResultType
Result type for expression template evaluations.
Definition: SMatTransposer.h:77
ElementType_< MT > ElementType
Resulting element type.
Definition: SMatTransposer.h:80
Expression object for the transposition of a sparse matrix.The SMatTransposer class is a wrapper obje...
Definition: Forward.h:124
Header file for run time assertion macros.
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: SMatTransposer.h:428
ResultType_< MT > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTransposer.h:79
Header file for the submatrix trait.
Header file for the columns trait.
void append(size_t i, size_t j, const ElementType &value, bool check=false)
Appending an element to the specified row/column of the sparse matrix.
Definition: SMatTransposer.h:387
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:199
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTransposer.h:241
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:101
Iterator insert(size_t i, size_t j, const ElementType &value)
Inserting an element into the sparse matrix.
Definition: SMatTransposer.h:321
ConstReference_< MT > ConstReference
Reference to a constant matrix value.
Definition: SMatTransposer.h:84
void assign(const Matrix< MT2, SO2 > &rhs)
Implementation of the transpose assignment of a matrix.
Definition: SMatTransposer.h:471
typename T::Iterator Iterator_
Alias declaration for nested Iterator type definitions.The Iterator_ alias declaration provides a con...
Definition: Aliases.h:183
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: SMatTransposer.h:405
Header file for the rows trait.
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:789
Base template for the ColumnsTrait class.
Definition: ColumnsTrait.h:109
size_t capacity() const noexcept
Returns the maximum capacity of the matrix.
Definition: SMatTransposer.h:261
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row/column.
Definition: SMatTransposer.h:293
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:423
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: SMatTransposer.h:452
#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:61