35 #ifndef _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_ 92 template<
typename T1,
typename T2,
bool SO >
93 inline bool operator==(
const SparseMatrix<T1,false>& lhs,
const SparseMatrix<T2,false>& rhs );
95 template<
typename T1,
typename T2,
bool SO >
96 inline bool operator==(
const SparseMatrix<T1,true>& lhs,
const SparseMatrix<T2,true>& rhs );
98 template<
typename T1,
typename T2,
bool SO >
99 inline bool operator==(
const SparseMatrix<T1,SO>& lhs,
const SparseMatrix<T2,!SO>& rhs );
101 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
102 inline bool operator!=(
const SparseMatrix<T1,SO1>& lhs,
const SparseMatrix<T2,SO2>& rhs );
115 template<
typename T1
134 for(
size_t i=0UL; i<A.rows(); ++i )
136 const LhsConstIterator lend( A.end(i) );
137 const RhsConstIterator rend( B.end(i) );
139 LhsConstIterator lelem( A.begin(i) );
140 RhsConstIterator relem( B.begin(i) );
142 while( lelem != lend && relem != rend )
144 if( lelem->index() < relem->index() ) {
149 else if( lelem->index() > relem->index() ) {
154 else if( !
equal( lelem->value(), relem->value() ) ) {
163 while( lelem != lend ) {
169 while( relem != rend ) {
189 template<
typename T1
208 for(
size_t j=0UL; j<A.columns(); ++j )
210 const LhsConstIterator lend( A.end(j) );
211 const RhsConstIterator rend( B.end(j) );
213 LhsConstIterator lelem( A.begin(j) );
214 RhsConstIterator relem( B.begin(j) );
216 while( lelem != lend && relem != rend )
218 if( lelem->index() < relem->index() ) {
223 else if( lelem->index() > relem->index() ) {
228 else if( !
equal( lelem->value(), relem->value() ) ) {
237 while( lelem != lend ) {
243 while( relem != rend ) {
263 template<
typename T1
269 return ( ~lhs == tmp );
282 template<
typename T1
288 return !( lhs == rhs );
304 template<
typename MT,
bool SO >
307 template<
bool RF,
typename MT,
bool SO >
310 template<
bool RF,
typename MT,
bool SO >
313 template<
bool RF,
typename MT,
bool SO >
316 template<
bool RF,
typename MT,
bool SO >
319 template<
bool RF,
typename MT,
bool SO >
322 template<
bool RF,
typename MT,
bool SO >
325 template<
bool RF,
typename MT,
bool SO >
328 template<
bool RF,
typename MT,
bool SO >
331 template<
bool RF,
typename MT,
bool SO >
334 template<
bool RF,
typename MT,
bool SO >
337 template<
bool RF,
typename MT,
bool SO >
340 template<
typename MT,
bool SO >
343 template<
typename MT,
bool SO >
369 template<
typename MT
379 for(
size_t i=0UL; i<A.rows(); ++i ) {
380 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
381 if(
isnan( element->value() ) )
return true;
385 for(
size_t j=0UL; j<A.columns(); ++j ) {
386 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
387 if(
isnan( element->value() ) )
return true;
452 for(
size_t i=0UL; i<A.rows(); ++i ) {
453 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
455 const size_t j( element->index() );
457 if( i == j || isDefault<RF>( element->value() ) )
461 if( pos == A.end(j) || !equal<RF>( pos->value(), element->value() ) )
467 for(
size_t j=0UL; j<A.columns(); ++j ) {
468 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
470 const size_t i( element->index() );
472 if( j == i || isDefault<RF>( element->value() ) )
476 if( pos == A.end(i) || !equal<RF>( pos->value(), element->value() ) )
546 for(
size_t i=0UL; i<A.rows(); ++i ) {
547 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
549 const size_t j( element->index() );
551 if( isDefault<RF>( element->value() ) )
554 if( i == j && !isReal<RF>( element->value() ) )
558 if( pos == A.end(j) || !equal<RF>( pos->value(),
conj( element->value() ) ) )
564 for(
size_t j=0UL; j<A.columns(); ++j ) {
565 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
567 const size_t i( element->index() );
569 if( isDefault<RF>( element->value() ) )
572 if( j == i && !isReal<RF>( element->value() ) )
576 if( pos == A.end(i) || !equal<RF>( pos->value(),
conj( element->value() ) ) )
610 for(
size_t i=ibegin; i<iend; ++i ) {
612 if( !isDefault<RF>( element->value() ) )
646 for(
size_t j=jbegin; j<jend; ++j ) {
648 if( !isDefault<RF>( element->value() ) )
680 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
682 if( (~sm).
nonZeros() != maxElements )
684 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
685 for(
ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
686 if( !isDefault<RF>( element->value() ) )
697 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
698 for(
ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
699 if( element->value() != cmp )
732 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
734 if( (~sm).
nonZeros() != maxElements )
736 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
737 for(
ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
738 if( !isDefault<RF>( element->value() ) )
749 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
750 for(
ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
751 if( element->value() != cmp )
806 ( (~sm).
rows() == 1UL && (~sm).
columns() == 1UL ) )
876 if( (~sm).
rows() < 2UL )
882 for(
size_t i=0UL; i<A.rows()-1UL; ++i ) {
883 for(
ConstIterator element=A.lowerBound(i,i+1UL); element!=A.end(i); ++element )
885 if( !isDefault<RF>( element->value() ) )
891 for(
size_t j=1UL; j<A.columns(); ++j ) {
892 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
894 if( element->index() >= j )
897 if( !isDefault<RF>( element->value() ) )
970 for(
size_t i=0UL; i<A.rows(); ++i )
974 if( element == A.end(i) || element->index() != i || !isOne<RF>( element->value() ) )
979 for( ; element!=A.end(i); ++element ) {
980 if( !isZero<RF>( element->value() ) )
986 for(
size_t j=0UL; j<A.columns(); ++j )
988 bool hasDiagonalElement(
false );
990 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
992 if( element->index() >= j ) {
993 if( element->index() != j || !isOne<RF>( element->value() ) )
995 hasDiagonalElement =
true;
999 if( !isZero<RF>( element->value() ) )
1003 if( !hasDiagonalElement ) {
1077 for(
size_t i=0UL; i<A.rows(); ++i ) {
1078 for(
ConstIterator element=A.lowerBound(i,i); element!=A.end(i); ++element )
1080 if( !isDefault<RF>( element->value() ) )
1086 for(
size_t j=0UL; j<A.columns(); ++j ) {
1087 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1089 if( element->index() > j )
1092 if( !isDefault<RF>( element->value() ) )
1163 if( (~sm).
rows() < 2UL )
1169 for(
size_t i=1UL; i<A.rows(); ++i ) {
1170 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1172 if( element->index() >= i )
1175 if( !isDefault<RF>( element->value() ) )
1181 for(
size_t j=0UL; j<A.columns()-1UL; ++j ) {
1182 for(
ConstIterator element=A.lowerBound(j+1UL,j); element!=A.end(j); ++element )
1184 if( !isDefault<RF>( element->value() ) )
1257 for(
size_t i=0UL; i<A.rows(); ++i )
1259 bool hasDiagonalElement(
false );
1261 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1263 if( element->index() >= i ) {
1264 if( element->index() != i || !isOne<RF>( element->value() ) )
1266 hasDiagonalElement =
true;
1269 else if( !isZero<RF>( element->value() ) ) {
1274 if( !hasDiagonalElement ) {
1280 for(
size_t j=0UL; j<A.columns(); ++j )
1284 if( element == A.end(j) || element->index() != j || !isOne<RF>( element->value() ) )
1289 for( ; element!=A.end(j); ++element ) {
1290 if( !isZero<RF>( element->value() ) )
1364 for(
size_t i=0UL; i<A.rows(); ++i ) {
1365 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1367 if( element->index() > i )
1370 if( !isDefault<RF>( element->value() ) )
1376 for(
size_t j=0UL; j<A.columns(); ++j ) {
1377 for(
ConstIterator element=A.lowerBound(j,j); element!=A.end(j); ++element )
1379 if( !isDefault<RF>( element->value() ) )
1450 if( (~sm).
rows() < 2UL )
1456 for(
size_t i=0UL; i<A.rows(); ++i ) {
1457 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1458 if( element->index() != i && !isDefault<RF>( element->value() ) )
1463 for(
size_t j=0UL; j<A.columns(); ++j ) {
1464 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1465 if( element->index() != j && !isDefault<RF>( element->value() ) )
1538 for(
size_t i=0UL; i<A.rows(); ++i )
1540 bool hasDiagonalElement(
false );
1542 for(
ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1544 if( element->index() == i ) {
1545 if( !isOne<RF>( element->value() ) )
1547 hasDiagonalElement =
true;
1549 else if( !isZero<RF>( element->value() ) ) {
1554 if( !hasDiagonalElement ) {
1560 for(
size_t j=0UL; j<A.columns(); ++j )
1562 bool hasDiagonalElement(
false );
1564 for(
ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1566 if( element->index() == j ) {
1567 if( !isOne<RF>( element->value() ) )
1569 hasDiagonalElement =
true;
1571 else if( !isZero<RF>( element->value() ) ) {
1576 if( !hasDiagonalElement ) {
1599 template<
typename MT
1611 const size_t nonzeros( A.nonZeros() );
1613 if( nonzeros == 0UL ) {
1618 if( nonzeros == A.rows() * A.columns() ) {
1619 minimum = A.begin( 0UL )->value();
1622 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1624 for(
size_t i=0UL; i<index; ++i ) {
1627 for( ; element!=
end; ++element )
1628 minimum =
min( minimum, element->value() );
1648 template<
typename MT
1660 const size_t nonzeros( A.nonZeros() );
1662 if( nonzeros == 0UL ) {
1667 if( nonzeros == A.rows() * A.columns() ) {
1668 maximum = A.begin( 0UL )->value();
1671 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1673 for(
size_t i=0UL; i<index; ++i ) {
1676 for( ; element!=
end; ++element )
1677 maximum =
max( maximum, element->value() );
#define BLAZE_CONSTRAINT_MUST_BE_TRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a lower or upper triangular matrix t...
Definition: Triangular.h:61
Header file for the isnan shim.
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1073
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1328
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1245
Header file for the IsUniUpper type trait.
Compile time check for triangular matrix types.This type trait tests whether or not the given templat...
Definition: IsTriangular.h:87
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper triangular matrix type...
Definition: Triangular.h:81
constexpr bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:76
Header file for the FalseType type/value trait base class.
Header file for the IsDiagonal type trait.
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:198
bool isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1158
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1762
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:88
Header file for the IsIdentity type trait.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3085
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1584
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:394
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:88
Header file for the IsUniLower type trait.
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:343
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1809
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:129
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1686
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.
Header file for the IsSquare type trait.
Header file for the matrix storage order types.
Constraint on the data type.
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:86
Headerfile for the generic max algorithm.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3087
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
typename T::ElementType ElementType_
Alias declaration for nested ElementType type definitions.The ElementType_ alias declaration provides...
Definition: Aliases.h:163
Header file for the IsLower type trait.
Compile time check for diagonal matrices.This type trait tests whether or not the given template para...
Definition: IsDiagonal.h:90
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:340
Header file for the equal shim.
Header file for the IsUniTriangular type trait.
Header file for the IsTriangular type trait.
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
bool isnan(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is not a number.
Definition: DiagonalProxy.h:682
Compile time check for strictly upper triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyUpper.h:86
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:1010
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:264
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Constraint on the data type.
Header file for the IsStrictlyLower type trait.
Header file for the isOne shim.
Compile time check for lower unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniLower.h:86
Header file for the conjugate shim.
Header file for the IsNumeric type trait.
Compile time check for identity matrices.This type trait tests whether or not the given template para...
Definition: IsIdentity.h:90
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1500
Header file for run time assertion macros.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:778
Header file for the isDefault shim.
Compile time check for Hermitian matrices.This type trait tests whether or not the given template par...
Definition: IsHermitian.h:85
Compile time check for built-in data types.This type trait tests whether or not the given template pa...
Definition: IsBuiltin.h:75
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:700
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the RemoveReference type trait.
typename T::OppositeType OppositeType_
Alias declaration for nested OppositeType type definitions.The OppositeType_ alias declaration provid...
Definition: Aliases.h:263
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
typename T::ConstReference ConstReference_
Alias declaration for nested ConstReference type definitions.The ConstReference_ alias declaration pr...
Definition: Aliases.h:143
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:324
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
Header file for the IsBuiltin type trait.
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1413
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
Header file for the IsUpper type trait.
decltype(auto) conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatMapExpr.h:1321
Header file for the IsHermitian type trait.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix) noexcept
Checks if the given matrix is a square matrix.
Definition: Matrix.h:742
Header file for the isReal shim.
#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
Header file for the TrueType type/value trait base class.
Compile time check for unitriangular matrix types.This type trait tests whether or not the given temp...
Definition: IsUniTriangular.h:87
Header file for the IsExpression type trait class.