35 #ifndef _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_ 88 template<
typename T1,
typename T2,
bool SO >
89 inline bool operator==(
const SparseMatrix<T1,false>& lhs,
const SparseMatrix<T2,false>& rhs );
91 template<
typename T1,
typename T2,
bool SO >
92 inline bool operator==(
const SparseMatrix<T1,true>& lhs,
const SparseMatrix<T2,true>& rhs );
94 template<
typename T1,
typename T2,
bool SO >
95 inline bool operator==(
const SparseMatrix<T1,SO>& lhs,
const SparseMatrix<T2,!SO>& rhs );
97 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
98 inline bool operator!=(
const SparseMatrix<T1,SO1>& lhs,
const SparseMatrix<T2,SO2>& rhs );
111 template<
typename T1
130 for(
size_t i=0UL; i<A.rows(); ++i )
132 const LhsConstIterator lend( A.end(i) );
133 const RhsConstIterator rend( B.end(i) );
135 LhsConstIterator lelem( A.begin(i) );
136 RhsConstIterator relem( B.begin(i) );
138 while( lelem != lend && relem != rend )
140 if( lelem->index() < relem->index() ) {
145 else if( lelem->index() > relem->index() ) {
150 else if( !
equal( lelem->value(), relem->value() ) ) {
159 while( lelem != lend ) {
165 while( relem != rend ) {
185 template<
typename T1
204 for(
size_t j=0UL; j<A.columns(); ++j )
206 const LhsConstIterator lend( A.end(j) );
207 const RhsConstIterator rend( B.end(j) );
209 LhsConstIterator lelem( A.begin(j) );
210 RhsConstIterator relem( B.begin(j) );
212 while( lelem != lend && relem != rend )
214 if( lelem->index() < relem->index() ) {
219 else if( lelem->index() > relem->index() ) {
224 else if( !
equal( lelem->value(), relem->value() ) ) {
233 while( lelem != lend ) {
239 while( relem != rend ) {
259 template<
typename T1
265 return ( ~lhs == tmp );
278 template<
typename T1
284 return !( lhs == rhs );
300 template<
typename MT,
bool SO >
303 template<
bool RF,
typename MT,
bool SO >
306 template<
bool RF,
typename MT,
bool SO >
309 template<
bool RF,
typename MT,
bool SO >
312 template<
bool RF,
typename MT,
bool SO >
315 template<
bool RF,
typename MT,
bool SO >
318 template<
bool RF,
typename MT,
bool SO >
321 template<
bool RF,
typename MT,
bool SO >
324 template<
bool RF,
typename MT,
bool SO >
327 template<
bool RF,
typename MT,
bool SO >
330 template<
bool RF,
typename MT,
bool SO >
333 template<
bool RF,
typename MT,
bool SO >
336 template<
typename MT,
bool SO >
339 template<
typename MT,
bool SO >
365 template<
typename MT
375 for(
size_t i=0UL; i<A.rows(); ++i ) {
376 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
377 if(
isnan( element->value() ) )
return true;
381 for(
size_t j=0UL; j<A.columns(); ++j ) {
382 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
383 if(
isnan( element->value() ) )
return true;
442 if( (~sm).
rows() < 2UL )
448 for(
size_t i=0UL; i<A.rows(); ++i ) {
449 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
451 const size_t j( element->index() );
453 if( i == j || isDefault<RF>( element->value() ) )
456 const ConstIterator pos( A.find( j, i ) );
457 if( pos == A.end(j) || !equal<RF>( pos->value(), element->value() ) )
463 for(
size_t j=0UL; j<A.columns(); ++j ) {
464 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
466 const size_t i( element->index() );
468 if( j == i || isDefault<RF>( element->value() ) )
471 const ConstIterator pos( A.find( j, i ) );
472 if( pos == A.end(i) || !equal<RF>( pos->value(), element->value() ) )
539 for(
size_t i=0UL; i<A.rows(); ++i ) {
540 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
542 const size_t j( element->index() );
544 if( isDefault<RF>( element->value() ) )
547 if( i == j && !isReal<RF>( element->value() ) )
550 const ConstIterator pos( A.find( j, i ) );
551 if( pos == A.end(j) || !equal<RF>( pos->value(),
conj( element->value() ) ) )
557 for(
size_t j=0UL; j<A.columns(); ++j ) {
558 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
560 const size_t i( element->index() );
562 if( isDefault<RF>( element->value() ) )
565 if( j == i && !isReal<RF>( element->value() ) )
568 const ConstIterator pos( A.find( j, i ) );
569 if( pos == A.end(i) || !equal<RF>( pos->value(),
conj( element->value() ) ) )
603 for(
size_t i=ibegin; i<iend; ++i ) {
604 for( ConstIterator element=(~sm).
begin(i); element!=(~sm).
end(i); ++element ) {
605 if( !isDefault<RF>( element->value() ) )
639 for(
size_t j=jbegin; j<jend; ++j ) {
640 for( ConstIterator element=(~sm).
begin(j); element!=(~sm).
end(j); ++element ) {
641 if( !isDefault<RF>( element->value() ) )
673 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
675 if( (~sm).
nonZeros() != maxElements )
677 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
678 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
679 if( !isDefault<RF>( element->value() ) )
688 ConstReference cmp( (~sm)(0UL,0UL) );
690 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
691 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
692 if( element->value() != cmp )
725 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
727 if( (~sm).
nonZeros() != maxElements )
729 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
730 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
731 if( !isDefault<RF>( element->value() ) )
740 ConstReference cmp( (~sm)(0UL,0UL) );
742 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
743 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
744 if( element->value() != cmp )
797 if( (~sm).
rows() == 0UL || (~sm).
columns() == 0UL ||
798 ( (~sm).
rows() == 1UL && (~sm).
columns() == 1UL ) )
868 if( (~sm).
rows() < 2UL )
874 for(
size_t i=0UL; i<A.rows()-1UL; ++i ) {
875 for( ConstIterator element=A.lowerBound(i,i+1UL); element!=A.end(i); ++element )
877 if( !isDefault<RF>( element->value() ) )
883 for(
size_t j=1UL; j<A.columns(); ++j ) {
884 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
886 if( element->index() >= j )
889 if( !isDefault<RF>( element->value() ) )
962 for(
size_t i=0UL; i<A.rows(); ++i )
964 ConstIterator element( A.lowerBound(i,i) );
966 if( element == A.end(i) || element->index() != i || !isOne<RF>( element->value() ) )
971 for( ; element!=A.end(i); ++element ) {
972 if( !isZero<RF>( element->value() ) )
978 for(
size_t j=0UL; j<A.columns(); ++j )
980 bool hasDiagonalElement(
false );
982 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
984 if( element->index() >= j ) {
985 if( element->index() != j || !isOne<RF>( element->value() ) )
987 hasDiagonalElement =
true;
991 if( !isZero<RF>( element->value() ) )
995 if( !hasDiagonalElement ) {
1069 for(
size_t i=0UL; i<A.rows(); ++i ) {
1070 for( ConstIterator element=A.lowerBound(i,i); element!=A.end(i); ++element )
1072 if( !isDefault<RF>( element->value() ) )
1078 for(
size_t j=0UL; j<A.columns(); ++j ) {
1079 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1081 if( element->index() > j )
1084 if( !isDefault<RF>( element->value() ) )
1155 if( (~sm).
rows() < 2UL )
1161 for(
size_t i=1UL; i<A.rows(); ++i ) {
1162 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1164 if( element->index() >= i )
1167 if( !isDefault<RF>( element->value() ) )
1173 for(
size_t j=0UL; j<A.columns()-1UL; ++j ) {
1174 for( ConstIterator element=A.lowerBound(j+1UL,j); element!=A.end(j); ++element )
1176 if( !isDefault<RF>( element->value() ) )
1249 for(
size_t i=0UL; i<A.rows(); ++i )
1251 bool hasDiagonalElement(
false );
1253 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1255 if( element->index() >= i ) {
1256 if( element->index() != i || !isOne<RF>( element->value() ) )
1258 hasDiagonalElement =
true;
1261 else if( !isZero<RF>( element->value() ) ) {
1266 if( !hasDiagonalElement ) {
1272 for(
size_t j=0UL; j<A.columns(); ++j )
1274 ConstIterator element( A.lowerBound(j,j) );
1276 if( element == A.end(j) || element->index() != j || !isOne<RF>( element->value() ) )
1281 for( ; element!=A.end(j); ++element ) {
1282 if( !isZero<RF>( element->value() ) )
1356 for(
size_t i=0UL; i<A.rows(); ++i ) {
1357 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1359 if( element->index() > i )
1362 if( !isDefault<RF>( element->value() ) )
1368 for(
size_t j=0UL; j<A.columns(); ++j ) {
1369 for( ConstIterator element=A.lowerBound(j,j); element!=A.end(j); ++element )
1371 if( !isDefault<RF>( element->value() ) )
1442 if( (~sm).
rows() < 2UL )
1448 for(
size_t i=0UL; i<A.rows(); ++i ) {
1449 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1450 if( element->index() != i && !isDefault<RF>( element->value() ) )
1455 for(
size_t j=0UL; j<A.columns(); ++j ) {
1456 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1457 if( element->index() != j && !isDefault<RF>( element->value() ) )
1530 for(
size_t i=0UL; i<A.rows(); ++i )
1532 bool hasDiagonalElement(
false );
1534 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1536 if( element->index() == i ) {
1537 if( !isOne<RF>( element->value() ) )
1539 hasDiagonalElement =
true;
1541 else if( !isZero<RF>( element->value() ) ) {
1546 if( !hasDiagonalElement ) {
1552 for(
size_t j=0UL; j<A.columns(); ++j )
1554 bool hasDiagonalElement(
false );
1556 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1558 if( element->index() == j ) {
1559 if( !isOne<RF>( element->value() ) )
1561 hasDiagonalElement =
true;
1563 else if( !isZero<RF>( element->value() ) ) {
1568 if( !hasDiagonalElement ) {
1591 template<
typename MT
1603 const size_t nonzeros( A.nonZeros() );
1605 if( nonzeros == 0UL ) {
1610 if( nonzeros == A.rows() * A.columns() ) {
1611 minimum = A.begin( 0UL )->value();
1614 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1616 for(
size_t i=0UL; i<index; ++i ) {
1617 const ConstIterator
end( A.end( i ) );
1618 ConstIterator element( A.begin( i ) );
1619 for( ; element!=
end; ++element )
1620 minimum =
min( minimum, element->value() );
1640 template<
typename MT
1652 const size_t nonzeros( A.nonZeros() );
1654 if( nonzeros == 0UL ) {
1659 if( nonzeros == A.rows() * A.columns() ) {
1660 maximum = A.begin( 0UL )->value();
1663 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1665 for(
size_t i=0UL; i<index; ++i ) {
1666 const ConstIterator
end( A.end( i ) );
1667 ConstIterator element( A.begin( i ) );
1668 for( ; element!=
end; ++element )
1669 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.
const DMatForEachExpr< MT, Conj, SO > conj(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the complex conjugate of each single element of dm.
Definition: DMatForEachExpr.h:1214
Header file for auxiliary alias declarations.
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
Header file for mathematical functions.
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1066
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1321
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1238
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:194
bool isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1151
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1755
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.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1577
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:390
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:323
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1802
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:119
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1679
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.
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
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:2939
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:336
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:655
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:1004
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:260
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.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2937
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.
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:1493
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:160
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:775
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
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:697
#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:243
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:320
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
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1406
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Header file for the IsUpper type trait.
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:677
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.