35 #ifndef _BLAZE_MATH_EXPRESSIONS_SMATTRANSPOSER_H_
36 #define _BLAZE_MATH_EXPRESSIONS_SMATTRANSPOSER_H_
74 class SMatTransposer :
public SparseMatrix< SMatTransposer<MT,SO>, SO >
96 enum :
bool { smpAssignable = MT::smpAssignable };
116 inline ConstReference
operator()(
size_t i,
size_t j )
const {
131 inline ConstReference
at(
size_t i,
size_t j )
const {
132 if( i >=
sm_.columns() ) {
135 if( j >=
sm_.rows() ) {
169 inline ConstIterator
begin(
size_t i )
const {
170 return sm_.cbegin(i);
185 inline ConstIterator
cbegin(
size_t i )
const {
186 return sm_.cbegin(i);
201 inline Iterator
end(
size_t i ) {
217 inline ConstIterator
end(
size_t i )
const {
233 inline ConstIterator
cend(
size_t i )
const {
245 template<
typename Other >
262 template<
typename Other >
277 inline size_t rows() const noexcept {
278 return sm_.columns();
298 return sm_.capacity();
308 inline size_t capacity(
size_t i )
const noexcept {
309 return sm_.capacity( i );
319 return sm_.nonZeros();
330 return sm_.nonZeros( i );
357 inline Iterator
insert(
size_t i,
size_t j,
const ElementType& value ) {
358 return sm_.insert( j, i, value );
373 sm_.reserve( nonzeros );
391 inline void reserve(
size_t i,
size_t nonzeros ) {
392 sm_.reserve( i, nonzeros );
423 inline void append(
size_t i,
size_t j,
const ElementType& value,
bool check=
false ) {
424 sm_.append( j, i, value, check );
462 template<
typename Other >
463 inline bool canAlias(
const Other* alias )
const noexcept
465 return sm_.canAlias( alias );
475 template<
typename Other >
476 inline bool isAliased(
const Other* alias )
const noexcept
478 return sm_.isAliased( alias );
489 return sm_.canSMPAssign();
504 template<
typename MT2 >
515 const size_t m(
rows() );
517 for(
size_t i=0UL; i<m; ++i ) {
518 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
519 sm_.append( element->index(), i, element->value() );
536 template<
typename MT2 >
547 const size_t m(
rows() );
551 std::vector<size_t> rowLengths( m, 0UL );
552 for(
size_t j=0UL; j<n; ++j ) {
553 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
554 ++rowLengths[element->index()];
558 for(
size_t i=0UL; i<m; ++i ) {
559 sm_.reserve( i, rowLengths[i] );
563 for(
size_t j=0UL; j<n; ++j ) {
564 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element ) {
565 sm_.append( j, element->index(), element->value() );
603 template<
typename MT >
626 enum :
bool { smpAssignable = MT::smpAssignable };
646 inline ConstReference
operator()(
size_t i,
size_t j )
const {
661 inline ConstReference
at(
size_t i,
size_t j )
const {
662 if( i >=
sm_.columns() ) {
665 if( j >=
sm_.rows() ) {
678 inline Iterator
begin(
size_t j ) {
689 inline ConstIterator
begin(
size_t j )
const {
690 return sm_.cbegin(j);
700 inline ConstIterator
cbegin(
size_t j )
const {
701 return sm_.cbegin(j);
711 inline Iterator
end(
size_t j ) {
722 inline ConstIterator
end(
size_t j )
const {
733 inline ConstIterator
cend(
size_t j )
const {
745 template<
typename Other >
762 template<
typename Other >
777 inline size_t rows() const noexcept {
778 return sm_.columns();
787 inline size_t columns() const noexcept {
797 inline size_t capacity() const noexcept {
798 return sm_.capacity();
808 inline size_t capacity(
size_t j )
const noexcept {
809 return sm_.capacity( j );
819 return sm_.nonZeros();
829 inline size_t nonZeros(
size_t j )
const {
830 return sm_.nonZeros( j );
839 inline void reset() {
857 inline Iterator
insert(
size_t i,
size_t j,
const ElementType& value ) {
858 return sm_.insert( j, i, value );
872 inline void reserve(
size_t nonzeros ) {
873 sm_.reserve( nonzeros );
888 inline void reserve(
size_t i,
size_t nonzeros ) {
889 sm_.reserve( i, nonzeros );
920 void append(
size_t i,
size_t j,
const ElementType& value,
bool check=
false ) {
921 sm_.append( j, i, value, check );
948 inline bool isIntact() const noexcept {
959 template<
typename Other >
960 inline bool canAlias(
const Other* alias )
const noexcept
962 return sm_.canAlias( alias );
972 template<
typename Other >
973 inline bool isAliased(
const Other* alias )
const noexcept
975 return sm_.isAliased( alias );
986 return sm_.canSMPAssign();
1001 template<
typename MT2 >
1002 inline void assign(
const SparseMatrix<MT2,false>& rhs )
1010 typedef ConstIterator_<MT2> RhsIterator;
1012 const size_t m(
rows() );
1016 std::vector<size_t> columnLengths( n, 0UL );
1017 for(
size_t i=0UL; i<m; ++i ) {
1018 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
1019 ++columnLengths[element->index()];
1023 for(
size_t j=0UL; j<n; ++j ) {
1024 sm_.reserve( j, columnLengths[j] );
1028 for(
size_t i=0UL; i<m; ++i ) {
1029 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element ) {
1030 sm_.append( element->index(), i, element->value() );
1047 template<
typename MT2 >
1048 inline void assign(
const SparseMatrix<MT2,true>& rhs )
1056 typedef ConstIterator_<MT2> RhsIterator;
1060 for(
size_t j=0UL; j<n; ++j ) {
1061 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
1062 sm_.append( j, element->index(), element->value() );
1101 template<
typename MT
1103 inline void reset( SMatTransposer<MT,SO>& m )
1119 template<
typename MT
1121 inline bool isIntact(
const SMatTransposer<MT,SO>& m ) noexcept
1123 return m.isIntact();
1139 template<
typename MT,
bool SO >
1140 struct SubmatrixTrait< SMatTransposer<MT,SO> >
1142 using Type = SubmatrixTrait_< ResultType_< SMatTransposer<MT,SO> > >;
ReturnType_< MT > ReturnType
Return type for expression template evaluations.
Definition: SMatTransposer.h:83
Constraint on the data type.
size_t capacity(size_t i) const noexcept
Returns the current capacity of the specified row/column.
Definition: SMatTransposer.h:308
Header file for auxiliary alias declarations.
ConstIterator_< MT > ConstIterator
Iterator over constant elements.
Definition: SMatTransposer.h:88
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
ConstReference operator()(size_t i, size_t j) const
2D-access to the matrix elements.
Definition: SMatTransposer.h:116
Header file for basic type definitions.
#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:104
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: SMatTransposer.h:287
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: SMatTransposer.h:476
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
ResultType_< MT > TransposeType
Transpose type for expression template evaluations.
Definition: SMatTransposer.h:81
EnableIf_< IsNumeric< Other >, SMatTransposer > & operator*=(Other rhs)
Multiplication assignment operator for the multiplication between a matrix and a scalar value ( )...
Definition: SMatTransposer.h:246
Constraints on the storage order of matrix types.
TransposeType_< MT > ResultType
Result type for expression template evaluations.
Definition: SMatTransposer.h:79
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
ConstReference at(size_t i, size_t j) const
Checked access to the matrix elements.
Definition: SMatTransposer.h:131
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: SMatTransposer.h:277
MT & sm_
The sparse matrix operand.
Definition: SMatTransposer.h:573
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:109
typename T::ReturnType ReturnType_
Alias declaration for nested ReturnType type definitions.The ReturnType_ alias declaration provides a...
Definition: Aliases.h:343
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:391
Constraint on the data type.
MT OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SMatTransposer.h:80
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:61
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:153
#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
void reset()
Resets the matrix elements.
Definition: SMatTransposer.h:339
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Iterator_< MT > Iterator
Iterator over non-constant elements.
Definition: SMatTransposer.h:87
Header file for the exception macros of the math module.
ConstIterator begin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:169
EnableIf_< IsNumeric< Other >, SMatTransposer > & operator/=(Other rhs)
Division assignment operator for the division of a matrix by a scalar value ( ).
Definition: SMatTransposer.h:263
ConstIterator end(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:217
typename T::Reference Reference_
Alias declaration for nested Reference type definitions.The Reference_ alias declaration provides a c...
Definition: Aliases.h:283
Header file for the EnableIf class template.
ConstReference_< MT > ConstReference
Reference to a constant matrix value.
Definition: SMatTransposer.h:86
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: SMatTransposer.h:372
size_t nonZeros() const
Returns the number of non-zero elements in the matrix.
Definition: SMatTransposer.h:318
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: SMatTransposer.h:487
void assign(const SparseMatrix< MT2, true > &rhs)
Implementation of the transpose assignment of a column-major sparse matrix.
Definition: SMatTransposer.h:537
Header file for the IsNumeric type trait.
void assign(const SparseMatrix< MT2, false > &rhs)
Implementation of the transpose assignment of a row-major sparse matrix.
Definition: SMatTransposer.h:505
Expression object for the transposition of a sparse matrix.The SMatTransposer class is a wrapper obje...
Definition: Forward.h:105
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:233
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:61
ConstIterator cbegin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SMatTransposer.h:185
Header file for run time assertion macros.
Header file for the submatrix trait.
SMatTransposer< MT, SO > This
Type of this SMatTransposer instance.
Definition: SMatTransposer.h:78
ElementType_< MT > ElementType
Resulting element type.
Definition: SMatTransposer.h:82
size_t nonZeros(size_t i) const
Returns the number of non-zero elements in the specified row/column.
Definition: SMatTransposer.h:329
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:423
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: SMatTransposer.h:201
bool isIntact() const noexcept
Returns whether the invariants of the matrix are intact.
Definition: SMatTransposer.h:451
Constraints on the storage order of matrix types.
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: SMatTransposer.h:463
Iterator insert(size_t i, size_t j, const ElementType &value)
Inserting an element into the sparse matrix.
Definition: SMatTransposer.h:357
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
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:441
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
Reference_< MT > Reference
Reference to a non-constant matrix value.
Definition: SMatTransposer.h:85
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:240
typename T::TransposeType TransposeType_
Alias declaration for nested TransposeType type definitions.The TransposeType_ alias declaration prov...
Definition: Aliases.h:403
const This & CompositeType
Data type for composite expression templates.
Definition: SMatTransposer.h:84
#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
size_t capacity() const noexcept
Returns the maximum capacity of the matrix.
Definition: SMatTransposer.h:297