35 #ifndef _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_SPARSEMATRIX_H_
87 template<
typename T1,
typename T2,
bool SO >
88 inline bool operator==(
const SparseMatrix<T1,false>& lhs,
const SparseMatrix<T2,false>& rhs );
90 template<
typename T1,
typename T2,
bool SO >
91 inline bool operator==(
const SparseMatrix<T1,true>& lhs,
const SparseMatrix<T2,true>& rhs );
93 template<
typename T1,
typename T2,
bool SO >
94 inline bool operator==(
const SparseMatrix<T1,SO>& lhs,
const SparseMatrix<T2,!SO>& rhs );
96 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
97 inline bool operator!=(
const SparseMatrix<T1,SO1>& lhs,
const SparseMatrix<T2,SO2>& rhs );
110 template<
typename T1
129 for(
size_t i=0UL; i<A.rows(); ++i )
131 const LhsConstIterator lend( A.end(i) );
132 const RhsConstIterator rend( B.end(i) );
134 LhsConstIterator lelem( A.begin(i) );
135 RhsConstIterator relem( B.begin(i) );
137 while( lelem != lend && relem != rend )
139 if( lelem->index() < relem->index() ) {
144 else if( lelem->index() > relem->index() ) {
149 else if( !
equal( lelem->value(), relem->value() ) ) {
158 while( lelem != lend ) {
164 while( relem != rend ) {
184 template<
typename T1
203 for(
size_t j=0UL; j<A.columns(); ++j )
205 const LhsConstIterator lend( A.end(j) );
206 const RhsConstIterator rend( B.end(j) );
208 LhsConstIterator lelem( A.begin(j) );
209 RhsConstIterator relem( B.begin(j) );
211 while( lelem != lend && relem != rend )
213 if( lelem->index() < relem->index() ) {
218 else if( lelem->index() > relem->index() ) {
223 else if( !
equal( lelem->value(), relem->value() ) ) {
232 while( lelem != lend ) {
238 while( relem != rend ) {
258 template<
typename T1
264 return ( ~lhs == tmp );
277 template<
typename T1
283 return !( lhs == rhs );
299 template<
typename MT,
bool SO >
300 bool isnan(
const SparseMatrix<MT,SO>& sm );
302 template<
typename MT,
bool SO >
305 template<
typename MT,
bool SO >
308 template<
typename MT,
bool SO >
309 bool isUniform(
const SparseMatrix<MT,SO>& sm );
311 template<
typename MT,
bool SO >
312 bool isLower(
const SparseMatrix<MT,SO>& sm );
314 template<
typename MT,
bool SO >
315 bool isUniLower(
const SparseMatrix<MT,SO>& sm );
317 template<
typename MT,
bool SO >
320 template<
typename MT,
bool SO >
321 bool isUpper(
const SparseMatrix<MT,SO>& sm );
323 template<
typename MT,
bool SO >
324 bool isUniUpper(
const SparseMatrix<MT,SO>& sm );
326 template<
typename MT,
bool SO >
329 template<
typename MT,
bool SO >
330 bool isDiagonal(
const SparseMatrix<MT,SO>& sm );
332 template<
typename MT,
bool SO >
333 bool isIdentity(
const SparseMatrix<MT,SO>& sm );
335 template<
typename MT,
bool SO >
338 template<
typename MT,
bool SO >
364 template<
typename MT
374 for(
size_t i=0UL; i<A.rows(); ++i ) {
375 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
376 if(
isnan( element->value() ) )
return true;
380 for(
size_t j=0UL; j<A.columns(); ++j ) {
381 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
382 if(
isnan( element->value() ) )
return true;
417 template<
typename MT
433 if( (~sm).
rows() < 2UL )
439 for(
size_t i=0UL; i<A.rows(); ++i ) {
440 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
442 const size_t j( element->index() );
444 if( i == j ||
isDefault( element->value() ) )
447 const ConstIterator pos( A.find( j, i ) );
448 if( pos == A.end(j) || !
equal( pos->value(), element->value() ) )
454 for(
size_t j=0UL; j<A.columns(); ++j ) {
455 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
457 const size_t i( element->index() );
459 if( j == i ||
isDefault( element->value() ) )
462 const ConstIterator pos( A.find( j, i ) );
463 if( pos == A.end(i) || !
equal( pos->value(), element->value() ) )
502 template<
typename MT
519 if( (~sm).
rows() < 2UL )
525 for(
size_t i=0UL; i<A.rows(); ++i ) {
526 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
528 const size_t j( element->index() );
533 if( i == j && !
isReal( element->value() ) )
536 const ConstIterator pos( A.find( j, i ) );
537 if( pos == A.end(j) || !
equal( pos->value(),
conj( element->value() ) ) )
543 for(
size_t j=0UL; j<A.columns(); ++j ) {
544 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
546 const size_t i( element->index() );
551 if( j == i && !
isReal( element->value() ) )
554 const ConstIterator pos( A.find( j, i ) );
555 if( pos == A.end(i) || !
equal( pos->value(),
conj( element->value() ) ) )
574 template<
typename MT >
575 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
TrueType )
585 const size_t ibegin( ( IsStrictlyLower<MT>::value )?( 1UL ):( 0UL ) );
586 const size_t iend ( ( IsStrictlyUpper<MT>::value )?( (~sm).
rows()-1UL ):( (~sm).
rows() ) );
588 for(
size_t i=ibegin; i<iend; ++i ) {
589 for( ConstIterator element=(~sm).
begin(i); element!=(~sm).
end(i); ++element ) {
609 template<
typename MT >
610 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
TrueType )
620 const size_t jbegin( ( IsStrictlyUpper<MT>::value )?( 1UL ):( 0UL ) );
621 const size_t jend ( ( IsStrictlyLower<MT>::value )?( (~sm).
columns()-1UL ):( (~sm).
columns() ) );
623 for(
size_t j=jbegin; j<jend; ++j ) {
624 for( ConstIterator element=(~sm).
begin(j); element!=(~sm).
end(j); ++element ) {
644 template<
typename MT >
645 bool isUniform_backend(
const SparseMatrix<MT,false>& sm,
FalseType )
656 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
658 if( (~sm).
nonZeros() != maxElements )
660 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
661 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
671 ConstReference cmp( (~sm)(0UL,0UL) );
673 for(
size_t i=0UL; i<(~sm).
rows(); ++i ) {
674 for( ConstIterator element=(~sm).begin(i); element!=(~sm).
end(i); ++element ) {
675 if( element->value() != cmp )
695 template<
typename MT >
696 bool isUniform_backend(
const SparseMatrix<MT,true>& sm,
FalseType )
707 const size_t maxElements( (~sm).
rows() * (~sm).
columns() );
709 if( (~sm).
nonZeros() != maxElements )
711 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
712 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
722 ConstReference cmp( (~sm)(0UL,0UL) );
724 for(
size_t j=0UL; j<(~sm).
columns(); ++j ) {
725 for( ConstIterator element=(~sm).begin(j); element!=(~sm).
end(j); ++element ) {
726 if( element->value() != cmp )
764 template<
typename MT
771 if( (~sm).
rows() == 0UL || (~sm).
columns() == 0UL ||
772 ( (~sm).
rows() == 1UL && (~sm).
columns() == 1UL ) )
818 template<
typename MT
834 if( (~sm).
rows() < 2UL )
840 for(
size_t i=0UL; i<A.rows()-1UL; ++i ) {
841 for( ConstIterator element=A.lowerBound(i,i+1UL); element!=A.end(i); ++element )
849 for(
size_t j=1UL; j<A.columns(); ++j ) {
850 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
852 if( element->index() >= j )
901 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 ) {
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;
954 if( !hasDiagonalElement ) {
1001 template<
typename MT
1021 for(
size_t i=0UL; i<A.rows(); ++i ) {
1022 for( ConstIterator element=A.lowerBound(i,i); element!=A.end(i); ++element )
1030 for(
size_t j=0UL; j<A.columns(); ++j ) {
1031 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1033 if( element->index() > j )
1083 template<
typename MT
1099 if( (~sm).
rows() < 2UL )
1105 for(
size_t i=1UL; i<A.rows(); ++i ) {
1106 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1108 if( element->index() >= i )
1117 for(
size_t j=0UL; j<A.columns()-1UL; ++j ) {
1118 for( ConstIterator element=A.lowerBound(j+1UL,j); element!=A.end(j); ++element )
1166 template<
typename MT
1186 for(
size_t i=0UL; i<A.rows(); ++i )
1188 bool hasDiagonalElement(
false );
1190 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1192 if( element->index() >= i ) {
1193 if( element->index() != i || !
isOne( element->value() ) )
1195 hasDiagonalElement =
true;
1198 else if( !
isDefault( element->value() ) ) {
1203 if( !hasDiagonalElement ) {
1209 for(
size_t j=0UL; j<A.columns(); ++j )
1211 ConstIterator element( A.lowerBound(j,j) );
1213 if( element == A.end(j) || element->index() != j || !
isOne( element->value() ) )
1218 for( ; element!=A.end(j); ++element ) {
1266 template<
typename MT
1286 for(
size_t i=0UL; i<A.rows(); ++i ) {
1287 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1289 if( element->index() > i )
1298 for(
size_t j=0UL; j<A.columns(); ++j ) {
1299 for( ConstIterator element=A.lowerBound(j,j); element!=A.end(j); ++element )
1348 template<
typename MT
1364 if( (~sm).
rows() < 2UL )
1370 for(
size_t i=0UL; i<A.rows(); ++i ) {
1371 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1372 if( element->index() != i && !
isDefault( element->value() ) )
1377 for(
size_t j=0UL; j<A.columns(); ++j ) {
1378 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1379 if( element->index() != j && !
isDefault( element->value() ) )
1425 template<
typename MT
1445 for(
size_t i=0UL; i<A.rows(); ++i )
1447 bool hasDiagonalElement(
false );
1449 for( ConstIterator element=A.begin(i); element!=A.end(i); ++element )
1451 if( element->index() == i ) {
1452 if( !
isOne( element->value() ) )
1454 hasDiagonalElement =
true;
1456 else if( !
isDefault( element->value() ) ) {
1461 if( !hasDiagonalElement ) {
1467 for(
size_t j=0UL; j<A.columns(); ++j )
1469 bool hasDiagonalElement(
false );
1471 for( ConstIterator element=A.begin(j); element!=A.end(j); ++element )
1473 if( element->index() == j ) {
1474 if( !
isOne( element->value() ) )
1476 hasDiagonalElement =
true;
1478 else if( !
isDefault( element->value() ) ) {
1483 if( !hasDiagonalElement ) {
1506 template<
typename MT
1518 const size_t nonzeros( A.nonZeros() );
1520 if( nonzeros == 0UL ) {
1525 if( nonzeros == A.rows() * A.columns() ) {
1526 minimum = A.begin( 0UL )->value();
1529 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1531 for(
size_t i=0UL; i<index; ++i ) {
1532 const ConstIterator
end( A.end( i ) );
1533 ConstIterator element( A.begin( i ) );
1534 for( ; element!=
end; ++element )
1535 minimum =
min( minimum, element->value() );
1555 template<
typename MT
1567 const size_t nonzeros( A.nonZeros() );
1569 if( nonzeros == 0UL ) {
1574 if( nonzeros == A.rows() * A.columns() ) {
1575 maximum = A.begin( 0UL )->value();
1578 const size_t index( ( SO ==
rowMajor )?( A.rows() ):( A.columns() ) );
1580 for(
size_t i=0UL; i<index; ++i ) {
1581 const ConstIterator
end( A.end( i ) );
1582 ConstIterator element( A.begin( i ) );
1583 for( ; element!=
end; ++element )
1584 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.
bool isOne(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 1.
Definition: DiagonalProxy.h:609
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
bool isDiagonal(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is diagonal.
Definition: DenseMatrix.h:1511
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:603
#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:250
bool isStrictlyLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly lower triangular matrix.
Definition: DenseMatrix.h:1201
bool isStrictlyUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a strictly upper triangular matrix.
Definition: DenseMatrix.h:1434
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:569
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:697
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:308
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:378
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:2584
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:1044
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:117
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Header file for the SparseMatrix base class.
ConjExprTrait< typename DiagonalProxy< MT >::RepresentedType >::Type conj(const DiagonalProxy< MT > &proxy)
Computing the complex conjugate of the represented element.
Definition: DiagonalProxy.h:487
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:2592
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
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:1277
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:629
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:187
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:1121
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
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
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:92
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
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:73
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: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:990
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 isHermitian(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is Hermitian.
Definition: DenseMatrix.h:767
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:2583
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:324
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:1354
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
Header file for the IsHermitian type trait.
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:105
bool isIdentity(const DenseMatrix< MT, SO > &dm)
Checks if the give dense matrix is an identity matrix.
Definition: DenseMatrix.h:1605
Header file for the IsExpression type trait class.