Blaze 3.9
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>
50#include <blaze/util/Assert.h>
51#include <blaze/util/Types.h>
52
53
54namespace blaze {
55
56//=================================================================================================
57//
58// CLASS SMATTRANSPOSER
59//
60//=================================================================================================
61
62//*************************************************************************************************
68template< typename MT // Type of the sparse matrix
69 , bool SO > // Storage order
71 : public SparseMatrix< SMatTransposer<MT,SO>, SO >
72{
73 public:
74 //**Type definitions****************************************************************************
78 using OppositeType = MT;
82 using CompositeType = const This&;
87 //**********************************************************************************************
88
89 //**Compilation flags***************************************************************************
91
94 static constexpr 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//*************************************************************************************************
508template< typename MT // Type of the sparse matrix
509 , bool SO > // Storage order
510inline bool isIntact( const SMatTransposer<MT,SO>& m ) noexcept
511{
512 return m.isIntact();
513}
515//*************************************************************************************************
516
517
518
519
520//=================================================================================================
521//
522// SIZE SPECIALIZATIONS
523//
524//=================================================================================================
525
526//*************************************************************************************************
528template< typename MT, bool SO >
529struct Size< SMatTransposer<MT,SO>, 0UL >
530 : public Size<MT,0UL>
531{};
532
533template< typename MT, bool SO >
534struct Size< SMatTransposer<MT,SO>, 1UL >
535 : public Size<MT,1UL>
536{};
538//*************************************************************************************************
539
540
541
542
543//=================================================================================================
544//
545// MAXSIZE SPECIALIZATIONS
546//
547//=================================================================================================
548
549//*************************************************************************************************
551template< typename MT, bool SO >
552struct MaxSize< SMatTransposer<MT,SO>, 0UL >
553 : public MaxSize<MT,0UL>
554{};
555
556template< typename MT, bool SO >
557struct MaxSize< SMatTransposer<MT,SO>, 1UL >
558 : public MaxSize<MT,1UL>
559{};
561//*************************************************************************************************
562
563} // namespace blaze
564
565#endif
Header file for auxiliary alias declarations.
typename T::ConstReference ConstReference_t
Alias declaration for nested ConstReference type definitions.
Definition: Aliases.h:170
typename T::ReturnType ReturnType_t
Alias declaration for nested ReturnType type definitions.
Definition: Aliases.h:470
typename T::ResultType ResultType_t
Alias declaration for nested ResultType type definitions.
Definition: Aliases.h:450
typename T::ElementType ElementType_t
Alias declaration for nested ElementType type definitions.
Definition: Aliases.h:190
typename T::Iterator Iterator_t
Alias declaration for nested Iterator type definitions.
Definition: Aliases.h:210
typename T::ConstIterator ConstIterator_t
Alias declaration for nested ConstIterator type definitions.
Definition: Aliases.h:130
typename T::Reference Reference_t
Alias declaration for nested Reference type definitions.
Definition: Aliases.h:390
typename T::TransposeType TransposeType_t
Alias declaration for nested TransposeType type definitions.
Definition: Aliases.h:550
Header file for run time assertion macros.
Header file for the MaxSize type trait.
Constraints on the storage order of matrix types.
Base class for matrices.
Definition: Matrix.h:85
Expression object for the transposition of a sparse matrix.
Definition: SMatTransposer.h:72
MT OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTransposer.h:78
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:231
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: SMatTransposer.h:405
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: SMatTransposer.h:94
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
void reset()
Resets the matrix elements.
Definition: SMatTransposer.h:303
ElementType_t< MT > ElementType
Resulting element type.
Definition: SMatTransposer.h:80
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:199
ResultType_t< MT > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTransposer.h:79
ConstReference_t< MT > ConstReference
Reference to a constant matrix value.
Definition: SMatTransposer.h:84
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTransposer.h:251
ReturnType_t< MT > ReturnType
Return type for expression template evaluations.
Definition: SMatTransposer.h:81
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row/column.
Definition: SMatTransposer.h:293
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:167
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
TransposeType_t< MT > ResultType
Result type for expression template evaluations.
Definition: SMatTransposer.h:77
Reference_t< MT > Reference
Reference to a non-constant matrix value.
Definition: SMatTransposer.h:83
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: SMatTransposer.h:441
void assign(const Matrix< MT2, SO2 > &rhs)
Implementation of the transpose assignment of a matrix.
Definition: SMatTransposer.h:471
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:151
Iterator insert(size_t i, size_t j, const ElementType &value)
Inserting an element into the sparse matrix.
Definition: SMatTransposer.h:321
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:215
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: SMatTransposer.h:452
Iterator_t< MT > Iterator
Iterator over non-constant elements.
Definition: SMatTransposer.h:85
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTransposer.h:241
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: SMatTransposer.h:428
size_t capacity(size_t i) const noexcept
Returns the current capacity of the specified row/column.
Definition: SMatTransposer.h:272
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTransposer.h:129
ConstIterator_t< MT > ConstIterator
Iterator over constant elements.
Definition: SMatTransposer.h:86
bool isIntact() const noexcept
Returns whether the invariants of the matrix are intact.
Definition: SMatTransposer.h:415
ConstIterator cbegin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:183
size_t nonZeros() const
Returns the number of non-zero elements in the matrix.
Definition: SMatTransposer.h:282
size_t capacity() const noexcept
Returns the maximum capacity of the matrix.
Definition: SMatTransposer.h:261
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: SMatTransposer.h:336
MT & sm_
The sparse matrix operand.
Definition: SMatTransposer.h:479
SMatTransposer(MT &sm) noexcept
Constructor for the SMatTransposer class.
Definition: SMatTransposer.h:102
ConstReference operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTransposer.h:114
Base class for sparse matrices.
Definition: SparseMatrix.h:77
Constraint on the data type.
Header file for the SparseMatrix base class.
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
Header file for the exception macros of the math module.
Header file for the Size type trait.
Header file for basic type definitions.