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 >
301 bool isnan(
const SparseMatrix<MT,SO>& sm );
303 template<
typename MT,
bool SO >
306 template<
typename MT,
bool SO >
309 template<
typename MT,
bool SO >
310 bool isUniform(
const SparseMatrix<MT,SO>& sm );
312 template<
typename MT,
bool SO >
313 bool isLower(
const SparseMatrix<MT,SO>& sm );
315 template<
typename MT,
bool SO >
316 bool isUniLower(
const SparseMatrix<MT,SO>& sm );
318 template<
typename MT,
bool SO >
321 template<
typename MT,
bool SO >
322 bool isUpper(
const SparseMatrix<MT,SO>& sm );
324 template<
typename MT,
bool SO >
325 bool isUniUpper(
const SparseMatrix<MT,SO>& sm );
327 template<
typename MT,
bool SO >
330 template<
typename MT,
bool SO >
331 bool isDiagonal(
const SparseMatrix<MT,SO>& sm );
333 template<
typename MT,
bool SO >
334 bool isIdentity(
const SparseMatrix<MT,SO>& sm );
336 template<
typename MT,
bool SO >
337 const ElementType_<MT>
min(
const SparseMatrix<MT,SO>& sm );
339 template<
typename MT,
bool SO >
340 const ElementType_<MT>
max(
const SparseMatrix<MT,SO>& sm );
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;
418 template<
typename MT
434 if( (~sm).
rows() < 2UL )
440 for(
size_t i=0UL; i<A.rows(); ++i ) {
441 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
443 const size_t j( element->index() );
445 if( i == j ||
isDefault( element->value() ) )
448 const ConstIterator pos( A.find( j, i ) );
449 if( pos == A.end(j) || !
equal( pos->value(), element->value() ) )
455 for(
size_t j=0UL; j<A.columns(); ++j ) {
456 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
458 const size_t i( element->index() );
460 if( j == i ||
isDefault( element->value() ) )
463 const ConstIterator pos( A.find( j, i ) );
464 if( pos == A.end(i) || !
equal( pos->value(), element->value() ) )
503 template<
typename MT
520 if( (~sm).
rows() < 2UL )
526 for(
size_t i=0UL; i<A.rows(); ++i ) {
527 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
529 const size_t j( element->index() );
534 if( i == j && !
isReal( element->value() ) )
537 const ConstIterator pos( A.find( j, i ) );
538 if( pos == A.end(j) || !
equal( pos->value(),
conj( element->value() ) ) )
544 for(
size_t j=0UL; j<A.columns(); ++j ) {
545 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
547 const size_t i( element->index() );
552 if( j == i && !
isReal( element->value() ) )
555 const ConstIterator pos( A.find( j, i ) );
556 if( pos == A.end(i) || !
equal( pos->value(),
conj( element->value() ) ) )
575 template<
typename MT >
576 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
TrueType )
586 const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
587 const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~sm).
rows()-1UL ):( (~sm).
rows() ) );
589 for(
size_t i=ibegin; i<iend; ++i ) {
590 for( ConstIterator element=(~sm).
begin(i); element!=(~sm).
end(i); ++element ) {
610 template<
typename MT >
611 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
TrueType )
621 const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
622 const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~sm).
columns()-1UL ):( (~sm).
columns() ) );
624 for(
size_t j=jbegin; j<jend; ++j ) {
625 for( ConstIterator element=(~sm).
begin(j); element!=(~sm).
end(j); ++element ) {
645 template<
typename MT >
646 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
FalseType )
657 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
659 if( (~sm).
nonZeros() != maxElements )
661 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
662 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
672 ConstReference cmp( (~sm)(0UL,0UL) );
674 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
675 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
676 if( element->value() != cmp )
696 template<
typename MT >
697 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
FalseType )
708 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
710 if( (~sm).
nonZeros() != maxElements )
712 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
713 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
723 ConstReference cmp( (~sm)(0UL,0UL) );
725 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
726 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
727 if( element->value() != cmp )
765 template<
typename MT
772 if( (~sm).
rows() == 0UL || (~sm).
columns() == 0UL ||
773 ( (~sm).
rows() == 1UL && (~sm).
columns() == 1UL ) )
819 template<
typename MT
835 if( (~sm).
rows() < 2UL )
841 for(
size_t i=0UL; i<A.rows()-1UL; ++i ) {
842 for( ConstIterator element=A.lowerBound(i,i+1UL); element!=A.end(i); ++element )
850 for(
size_t j=1UL; j<A.columns(); ++j ) {
851 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
853 if( element->index() >= j )
902 template<
typename MT
921 for(
size_t i=0UL; i<A.rows(); ++i )
923 ConstIterator element( A.lowerBound(i,i) );
925 if( element == A.end(i) || element->index() != i || !
isOne( element->value() ) )
930 for( ; element!=A.end(i); ++element ) {
931 if( !
isZero( element->value() ) )
937 for(
size_t j=0UL; j<A.columns(); ++j )
939 bool hasDiagonalElement(
false );
941 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
943 if( element->index() >= j ) {
944 if( element->index() != j || !
isOne( element->value() ) )
946 hasDiagonalElement =
true;
950 if( !
isZero( element->value() ) )
954 if( !hasDiagonalElement ) {
1001 template<
typename MT
1020 for(
size_t i=0UL; i<A.rows(); ++i ) {
1021 for( ConstIterator element=A.lowerBound(i,i); element!=A.end(i); ++element )
1029 for(
size_t j=0UL; j<A.columns(); ++j ) {
1030 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1032 if( element->index() > j )
1082 template<
typename MT
1098 if( (~sm).
rows() < 2UL )
1104 for(
size_t i=1UL; i<A.rows(); ++i ) {
1105 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1107 if( element->index() >= i )
1116 for(
size_t j=0UL; j<A.columns()-1UL; ++j ) {
1117 for( ConstIterator element=A.lowerBound(j+1UL,j); element!=A.end(j); ++element )
1165 template<
typename MT
1184 for(
size_t i=0UL; i<A.rows(); ++i )
1186 bool hasDiagonalElement(
false );
1188 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1190 if( element->index() >= i ) {
1191 if( element->index() != i || !
isOne( element->value() ) )
1193 hasDiagonalElement =
true;
1196 else if( !
isZero( element->value() ) ) {
1201 if( !hasDiagonalElement ) {
1207 for(
size_t j=0UL; j<A.columns(); ++j )
1209 ConstIterator element( A.lowerBound(j,j) );
1211 if( element == A.end(j) || element->index() != j || !
isOne( element->value() ) )
1216 for( ; element!=A.end(j); ++element ) {
1217 if( !
isZero( element->value() ) )
1264 template<
typename MT
1283 for(
size_t i=0UL; i<A.rows(); ++i ) {
1284 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1286 if( element->index() > i )
1295 for(
size_t j=0UL; j<A.columns(); ++j ) {
1296 for( ConstIterator element=A.lowerBound(j,j); element!=A.end(j); ++element )
1345 template<
typename MT
1361 if( (~sm).
rows() < 2UL )
1367 for(
size_t i=0UL; i<A.rows(); ++i ) {
1368 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1369 if( element->index() != i && !
isDefault( element->value() ) )
1374 for(
size_t j=0UL; j<A.columns(); ++j ) {
1375 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1376 if( element->index() != j && !
isDefault( element->value() ) )
1422 template<
typename MT
1441 for(
size_t i=0UL; i<A.rows(); ++i )
1443 bool hasDiagonalElement(
false );
1445 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1447 if( element->index() == i ) {
1448 if( !
isOne( element->value() ) )
1450 hasDiagonalElement =
true;
1452 else if( !
isZero( element->value() ) ) {
1457 if( !hasDiagonalElement ) {
1463 for(
size_t j=0UL; j<A.columns(); ++j )
1465 bool hasDiagonalElement(
false );
1467 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1469 if( element->index() == j ) {
1470 if( !
isOne( element->value() ) )
1472 hasDiagonalElement =
true;
1474 else if( !
isZero( element->value() ) ) {
1479 if( !hasDiagonalElement ) {
1502 template<
typename MT
1514 const size_t nonzeros( A.nonZeros() );
1516 if( nonzeros == 0UL ) {
1521 if( nonzeros == A.rows() * A.columns() ) {
1522 minimum = A.begin( 0UL )->value();
1525 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1527 for(
size_t i=0UL; i<index; ++i ) {
1528 const ConstIterator
end( A.end( i ) );
1529 ConstIterator element( A.begin( i ) );
1530 for( ; element!=
end; ++element )
1531 minimum =
min( minimum, element->value() );
1551 template<
typename MT
1563 const size_t nonzeros( A.nonZeros() );
1565 if( nonzeros == 0UL ) {
1570 if( nonzeros == A.rows() * A.columns() ) {
1571 maximum = A.begin( 0UL )->value();
1574 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1576 for(
size_t i=0UL; i<index; ++i ) {
1577 const ConstIterator
end( A.end( i ) );
1578 ConstIterator element( A.begin( i ) );
1579 for( ; element!=
end; ++element )
1580 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.
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:635
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:1158
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 isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1499
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
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1192
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1423
Header file for the FalseType type/value trait base class.
bool isReal(const DiagonalProxy< MT > &proxy)
Returns whether the matrix element represents a real number.
Definition: DiagonalProxy.h:595
Header file for the IsDiagonal type trait.
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:689
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:188
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
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.
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:384
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:88
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
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:1716
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1036
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:109
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
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:2647
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:330
Header file for the equal shim.
Header file for the IsUniTriangular type trait.
Header file for the IsTriangular type trait.
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1267
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 isUniLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower unitriangular matrix.
Definition: DenseMatrix.h:1113
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:254
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2645
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
Header file for run time assertion macros.
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:73
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
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
#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
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:314
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:982
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
bool isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:759
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:615
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
bool isUniUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper unitriangular matrix.
Definition: DenseMatrix.h:1344
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:609
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
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1593
Header file for the IsExpression type trait class.