35 #ifndef _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_
84 template<
typename T1,
typename T2,
bool SO >
85 inline bool operator==(
const SparseMatrix<T1,false>& lhs,
const SparseMatrix<T2,false>& rhs );
87 template<
typename T1,
typename T2,
bool SO >
88 inline bool operator==(
const SparseMatrix<T1,true>& lhs,
const SparseMatrix<T2,true>& rhs );
90 template<
typename T1,
typename T2,
bool SO >
91 inline bool operator==(
const SparseMatrix<T1,SO>& lhs,
const SparseMatrix<T2,!SO>& rhs );
93 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
94 inline bool operator!=(
const SparseMatrix<T1,SO1>& lhs,
const SparseMatrix<T2,SO2>& rhs );
107 template<
typename T1
126 for(
size_t i=0UL; i<A.rows(); ++i )
128 const LhsConstIterator lend( A.end(i) );
129 const RhsConstIterator rend( B.end(i) );
131 LhsConstIterator lelem( A.begin(i) );
132 RhsConstIterator relem( B.begin(i) );
134 while( lelem != lend && relem != rend )
136 if( lelem->index() < relem->index() ) {
141 else if( lelem->index() > relem->index() ) {
146 else if( !
equal( lelem->value(), relem->value() ) ) {
155 while( lelem != lend ) {
161 while( relem != rend ) {
181 template<
typename T1
200 for(
size_t j=0UL; j<A.columns(); ++j )
202 const LhsConstIterator lend( A.end(j) );
203 const RhsConstIterator rend( B.end(j) );
205 LhsConstIterator lelem( A.begin(j) );
206 RhsConstIterator relem( B.begin(j) );
208 while( lelem != lend && relem != rend )
210 if( lelem->index() < relem->index() ) {
215 else if( lelem->index() > relem->index() ) {
220 else if( !
equal( lelem->value(), relem->value() ) ) {
229 while( lelem != lend ) {
235 while( relem != rend ) {
255 template<
typename T1
261 return ( ~lhs == tmp );
274 template<
typename T1
280 return !( lhs == rhs );
296 template<
typename MT,
bool SO >
297 bool isnan(
const SparseMatrix<MT,SO>& sm );
299 template<
typename MT,
bool SO >
302 template<
typename MT,
bool SO >
303 bool isUniform(
const SparseMatrix<MT,SO>& sm );
305 template<
typename MT,
bool SO >
306 bool isLower(
const SparseMatrix<MT,SO>& sm );
308 template<
typename MT,
bool SO >
309 bool isUniLower(
const SparseMatrix<MT,SO>& sm );
311 template<
typename MT,
bool SO >
314 template<
typename MT,
bool SO >
315 bool isUpper(
const SparseMatrix<MT,SO>& sm );
317 template<
typename MT,
bool SO >
318 bool isUniUpper(
const SparseMatrix<MT,SO>& sm );
320 template<
typename MT,
bool SO >
323 template<
typename MT,
bool SO >
324 bool isDiagonal(
const SparseMatrix<MT,SO>& sm );
326 template<
typename MT,
bool SO >
327 bool isIdentity(
const SparseMatrix<MT,SO>& sm );
329 template<
typename MT,
bool SO >
332 template<
typename MT,
bool SO >
358 template<
typename MT
368 for(
size_t i=0UL; i<A.rows(); ++i ) {
369 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
370 if(
isnan( element->value() ) )
return true;
374 for(
size_t j=0UL; j<A.columns(); ++j ) {
375 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
376 if(
isnan( element->value() ) )
return true;
411 template<
typename MT
427 if( (~sm).
rows() < 2UL )
433 for(
size_t i=0UL; i<A.rows(); ++i ) {
434 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
436 const size_t j( element->index() );
438 if( i == j ||
isDefault( element->value() ) )
441 const ConstIterator pos( A.find( j, i ) );
442 if( pos == A.end(j) || !
equal( pos->value(), element->value() ) )
448 for(
size_t j=0UL; j<A.columns(); ++j ) {
449 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
451 const size_t i( element->index() );
453 if( j == i ||
isDefault( element->value() ) )
456 const ConstIterator pos( A.find( j, i ) );
457 if( pos == A.end(i) || !
equal( pos->value(), element->value() ) )
476 template<
typename MT >
477 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
TrueType )
487 const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
488 const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~sm).
rows()-1UL ):( (~sm).
rows() ) );
490 for(
size_t i=ibegin; i<iend; ++i ) {
491 for( ConstIterator element=(~sm).
begin(i); element!=(~sm).
end(i); ++element ) {
511 template<
typename MT >
512 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
TrueType )
522 const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
523 const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~sm).
columns()-1UL ):( (~sm).
columns() ) );
525 for(
size_t j=jbegin; j<jend; ++j ) {
526 for( ConstIterator element=(~sm).
begin(j); element!=(~sm).
end(j); ++element ) {
546 template<
typename MT >
547 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
FalseType )
558 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
560 if( (~sm).
nonZeros() != maxElements )
562 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
563 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
573 ConstReference cmp( (~sm)(0UL,0UL) );
575 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
576 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
577 if( element->value() != cmp )
597 template<
typename MT >
598 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
FalseType )
609 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
611 if( (~sm).
nonZeros() != maxElements )
613 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
614 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
624 ConstReference cmp( (~sm)(0UL,0UL) );
626 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
627 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
628 if( element->value() != cmp )
666 template<
typename MT
673 if( (~sm).
rows() == 0UL || (~sm).
columns() == 0UL ||
674 ( (~sm).
rows() == 1UL && (~sm).
columns() == 1UL ) )
720 template<
typename MT
736 if( (~sm).
rows() < 2UL )
742 for(
size_t i=0UL; i<A.rows()-1UL; ++i ) {
743 for( ConstIterator element=A.lowerBound(i,i+1UL); element!=A.end(i); ++element )
751 for(
size_t j=1UL; j<A.columns(); ++j ) {
752 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
754 if( element->index() >= j )
803 template<
typename MT
823 for(
size_t i=0UL; i<A.rows(); ++i )
825 ConstIterator element( A.lowerBound(i,i) );
827 if( element == A.end(i) || element->index() != i || !
isOne( element->value() ) )
832 for( ; element!=A.end(i); ++element ) {
839 for(
size_t j=0UL; j<A.columns(); ++j )
841 bool hasDiagonalElement(
false );
843 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
845 if( element->index() >= j ) {
846 if( element->index() != j || !
isOne( element->value() ) )
848 hasDiagonalElement =
true;
856 if( !hasDiagonalElement ) {
903 template<
typename MT
923 for(
size_t i=0UL; i<A.rows(); ++i ) {
924 for( ConstIterator element=A.lowerBound(i,i); element!=A.end(i); ++element )
932 for(
size_t j=0UL; j<A.columns(); ++j ) {
933 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
935 if( element->index() > j )
985 template<
typename MT
1001 if( (~sm).
rows() < 2UL )
1007 for(
size_t i=1UL; i<A.rows(); ++i ) {
1008 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1010 if( element->index() >= i )
1019 for(
size_t j=0UL; j<A.columns()-1UL; ++j ) {
1020 for( ConstIterator element=A.lowerBound(j+1UL,j); element!=A.end(j); ++element )
1068 template<
typename MT
1088 for(
size_t i=0UL; i<A.rows(); ++i )
1090 bool hasDiagonalElement(
false );
1092 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1094 if( element->index() >= i ) {
1095 if( element->index() != i || !
isOne( element->value() ) )
1097 hasDiagonalElement =
true;
1100 else if( !
isDefault( element->value() ) ) {
1105 if( !hasDiagonalElement ) {
1111 for(
size_t j=0UL; j<A.columns(); ++j )
1113 ConstIterator element( A.lowerBound(j,j) );
1115 if( element == A.end(j) || element->index() != j || !
isOne( element->value() ) )
1120 for( ; element!=A.end(j); ++element ) {
1168 template<
typename MT
1188 for(
size_t i=0UL; i<A.rows(); ++i ) {
1189 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1191 if( element->index() > i )
1200 for(
size_t j=0UL; j<A.columns(); ++j ) {
1201 for( ConstIterator element=A.lowerBound(j,j); element!=A.end(j); ++element )
1250 template<
typename MT
1266 if( (~sm).
rows() < 2UL )
1272 for(
size_t i=0UL; i<A.rows(); ++i ) {
1273 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1274 if( element->index() != i && !
isDefault( element->value() ) )
1279 for(
size_t j=0UL; j<A.columns(); ++j ) {
1280 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1281 if( element->index() != j && !
isDefault( element->value() ) )
1327 template<
typename MT
1347 for(
size_t i=0UL; i<A.rows(); ++i )
1349 bool hasDiagonalElement(
false );
1351 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1353 if( element->index() == i ) {
1354 if( !
isOne( element->value() ) )
1356 hasDiagonalElement =
true;
1358 else if( !
isDefault( element->value() ) ) {
1363 if( !hasDiagonalElement ) {
1369 for(
size_t j=0UL; j<A.columns(); ++j )
1371 bool hasDiagonalElement(
false );
1373 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1375 if( element->index() == j ) {
1376 if( !
isOne( element->value() ) )
1378 hasDiagonalElement =
true;
1380 else if( !
isDefault( element->value() ) ) {
1385 if( !hasDiagonalElement ) {
1408 template<
typename MT
1420 const size_t nonzeros( A.nonZeros() );
1422 if( nonzeros == 0UL ) {
1427 if( nonzeros == A.rows() * A.columns() ) {
1428 minimum = A.begin( 0UL )->value();
1431 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1433 for(
size_t i=0UL; i<index; ++i ) {
1434 const ConstIterator
end( A.end( i ) );
1435 ConstIterator element( A.begin( i ) );
1436 for( ; element!=
end; ++element )
1437 minimum =
min( minimum, element->value() );
1457 template<
typename MT
1469 const size_t nonzeros( A.nonZeros() );
1471 if( nonzeros == 0UL ) {
1476 if( nonzeros == A.rows() * A.columns() ) {
1477 maximum = A.begin( 0UL )->value();
1480 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1482 for(
size_t i=0UL; i<index; ++i ) {
1483 const ConstIterator
end( A.end( i ) );
1484 ConstIterator element( A.begin( i ) );
1485 for( ; element!=
end; ++element )
1486 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:79
Header file for the isnan shim.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
Header file for mathematical functions.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1431
Header file for the IsUniUpper type trait.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Compile time check for triangular matrix types.This type trait tests whether or not the given templat...
Definition: IsTriangular.h:105
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE bool isSquare(const Matrix< MT, SO > &matrix)
Checks if the given matrix is a square matrix.
Definition: Matrix.h:902
#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:118
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:258
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1121
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1354
Header file for the FalseType type/value trait base class.
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:692
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:90
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:386
bool isnan(const DenseMatrix< MT, SO > &dm)
Checks the given dense matrix for not-a-number elements.
Definition: DenseMatrix.h:640
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:90
Header file for the IsUniLower type trait.
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2503
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:964
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
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.
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:85
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:2511
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
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:92
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:1197
Compile time check for symmetric matrices.This type trait tests whether or not the given template par...
Definition: IsSymmetric.h:85
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:195
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:1041
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
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:85
Compile time check for identity matrices.This type trait tests whether or not the given template para...
Definition: IsIdentity.h:92
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Removal of reference modifiers.The RemoveCV type trait removes any reference modifiers from the given...
Definition: RemoveReference.h:69
Header file for run time assertion macros.
bool equal(const T1 &a, const T2 &b)
Generic equality check.
Definition: Equal.h:376
Header file for the isDefault shim.
#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:118
Header file for the RemoveReference type trait.
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
bool isUniform(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a uniform matrix.
Definition: DenseMatrix.h:910
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
boost::false_type 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 operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
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:1274
Header file for the IsUpper type trait.
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
EnableIf< IsNumeric< Type >, bool >::Type isOne(const Type &v)
Returns whether the given value/object represents the numeric value 1.
Definition: IsOne.h:80
#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:105
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1525
Header file for the IsExpression type trait class.