35 #ifndef _BLAZE_MATH_VIEWS_SPARSESUBMATRIX_H_
36 #define _BLAZE_MATH_VIEWS_SPARSESUBMATRIX_H_
472 template<
typename MT
474 ,
bool SO = IsColumnMajorMatrix<MT>::value >
475 class SparseSubmatrix :
public SparseMatrix< SparseSubmatrix<MT,AF,SO>, SO >
516 ,
typename IteratorType >
532 typedef typename std::iterator_traits<IteratorType>::value_type
SET;
634 return pos_->value();
660 ,
typename IteratorType >
705 template<
typename MatrixType2,
typename IteratorType2 >
761 template<
typename MatrixType2,
typename IteratorType2 >
773 template<
typename MatrixType2,
typename IteratorType2 >
775 return !( *
this == rhs );
795 inline IteratorType
base()
const {
828 enum { smpAssignable = MT::smpAssignable };
846 inline Reference
operator()(
size_t i,
size_t j );
847 inline ConstReference
operator()(
size_t i,
size_t j )
const;
848 inline Iterator
begin (
size_t i );
849 inline ConstIterator
begin (
size_t i )
const;
850 inline ConstIterator
cbegin(
size_t i )
const;
851 inline Iterator
end (
size_t i );
852 inline ConstIterator
end (
size_t i )
const;
853 inline ConstIterator
cend (
size_t i )
const;
867 template<
typename Other >
869 operator*=( Other rhs );
871 template<
typename Other >
873 operator/=( Other rhs );
880 inline size_t rows()
const;
883 inline size_t capacity(
size_t i )
const;
885 inline size_t nonZeros(
size_t i )
const;
887 inline void reset(
size_t i );
888 inline Iterator
set(
size_t i,
size_t j,
const ElementType& value );
889 inline Iterator
insert(
size_t i,
size_t j,
const ElementType& value );
890 inline void erase(
size_t i,
size_t j );
891 inline Iterator
erase(
size_t i, Iterator pos );
892 inline Iterator
erase(
size_t i, Iterator first, Iterator last );
893 inline void reserve(
size_t nonzeros );
894 void reserve(
size_t i,
size_t nonzeros );
896 inline void trim(
size_t i );
898 template<
typename Other >
inline SparseSubmatrix& scale(
const Other& scalar );
905 inline Iterator
find (
size_t i,
size_t j );
906 inline ConstIterator
find (
size_t i,
size_t j )
const;
907 inline Iterator
lowerBound(
size_t i,
size_t j );
908 inline ConstIterator
lowerBound(
size_t i,
size_t j )
const;
909 inline Iterator
upperBound(
size_t i,
size_t j );
910 inline ConstIterator
upperBound(
size_t i,
size_t j )
const;
917 inline void append (
size_t i,
size_t j,
const ElementType& value,
bool check=
false );
925 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
926 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
946 template<
typename MT2,
bool SO2,
typename MT3,
bool SO3 >
950 template<
typename MT2,
bool SO2,
typename MT3,
bool SO3 >
954 template<
typename MT2,
bool SO2,
typename MT3 >
958 template<
typename MT2,
bool SO2,
typename MT3 >
959 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
962 template<
typename MT2,
bool SO2,
typename MT3 >
963 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
966 template<
typename MT2,
bool SO2,
typename MT3 >
967 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
970 template<
typename MT2,
bool SO2,
typename MT3 >
974 template<
typename MT2,
bool SO2,
typename MT3 >
975 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
978 template<
typename MT2,
bool SO2,
typename MT3 >
979 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
982 template<
typename MT2,
bool SO2,
typename MT3 >
983 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
986 template<
typename MT2,
bool SO2,
typename MT3 >
990 template<
typename MT2,
bool SO2,
typename MT3 >
991 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
994 template<
typename MT2,
bool SO2,
typename MT3 >
995 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
998 template<
typename MT2,
bool SO2,
typename MT3 >
999 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
1017 template<
bool AF1,
typename MT2,
bool AF2,
bool SO2 >
1021 template<
typename MT2,
bool AF2,
bool SO2 >
1024 template<
typename MT2,
bool AF2,
bool SO2 >
1027 template<
typename MT2,
bool AF2,
bool SO2 >
1030 template<
typename MT2,
bool AF2,
bool SO2 >
1033 template<
typename MT2,
bool AF2,
bool SO2 >
1036 template<
typename MT2,
bool AF2,
bool SO2 >
1039 template<
typename MT2,
bool AF2,
bool SO2 >
1082 template<
typename MT
1092 if( ( row + m > matrix.rows() ) || ( column + n > matrix.columns() ) )
1093 throw std::invalid_argument(
"Invalid submatrix specification" );
1113 template<
typename MT
1122 return matrix_(row_+i,column_+j);
1134 template<
typename MT
1143 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
1159 template<
typename MT
1167 if( column_ == 0UL )
1168 return Iterator( matrix_.begin( i + row_ ), column_ );
1170 return Iterator( matrix_.lowerBound( i + row_, column_ ), column_ );
1186 template<
typename MT
1194 if( column_ == 0UL )
1195 return ConstIterator( matrix_.cbegin( i + row_ ), column_ );
1197 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
1213 template<
typename MT
1221 if( column_ == 0UL )
1222 return ConstIterator( matrix_.cbegin( i + row_ ), column_ );
1224 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
1240 template<
typename MT
1248 if( matrix_.columns() == column_ +
n_ )
1249 return Iterator( matrix_.end( i + row_ ), column_ );
1251 return Iterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1267 template<
typename MT
1275 if( matrix_.columns() == column_ +
n_ )
1278 return ConstIterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1294 template<
typename MT
1302 if( matrix_.columns() == column_ +
n_ )
1305 return ConstIterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1332 template<
typename MT
1343 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
1346 if(
rows() != rhs.rows() ||
columns() != rhs.columns() )
1347 throw std::invalid_argument(
"Submatrix sizes do not match" );
1349 if( !preservesInvariant( matrix_, rhs ) )
1350 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
1354 if( rhs.canAlias( &matrix_ ) ) {
1387 template<
typename MT
1390 template<
typename MT2
1400 throw std::invalid_argument(
"Matrix sizes do not match" );
1403 Right right( ~rhs );
1405 if( !preservesInvariant( matrix_, right ) )
1406 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
1442 template<
typename MT
1445 template<
typename MT2
1461 throw std::invalid_argument(
"Matrix sizes do not match" );
1463 const AddType tmp( *
this + (~rhs) );
1465 if( !preservesInvariant( matrix_, tmp ) )
1466 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
1495 template<
typename MT
1498 template<
typename MT2
1514 throw std::invalid_argument(
"Matrix sizes do not match" );
1516 const SubType tmp( *
this - (~rhs) );
1518 if( !preservesInvariant( matrix_, tmp ) )
1519 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
1548 template<
typename MT
1551 template<
typename MT2
1568 throw std::invalid_argument(
"Matrix sizes do not match" );
1570 const MultType tmp( *
this * (~rhs) );
1572 if( !preservesInvariant( matrix_, tmp ) )
1573 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
1603 template<
typename MT
1606 template<
typename Other >
1612 for(
size_t i=0UL; i<
rows(); ++i ) {
1615 element->value() *= rhs;
1640 template<
typename MT
1643 template<
typename Other >
1657 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1658 for(
size_t i=0UL; i<
rows(); ++i ) {
1661 element->value() *= tmp;
1665 for(
size_t i=0UL; i<
rows(); ++i ) {
1668 element->value() /= rhs;
1690 template<
typename MT
1705 template<
typename MT
1720 template<
typename MT
1725 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1741 template<
typename MT
1747 return nonZeros( i ) + matrix_.capacity( row_+i ) - matrix_.nonZeros( row_+i );
1757 template<
typename MT
1762 size_t nonzeros( 0UL );
1764 for(
size_t i=0UL; i<
rows(); ++i )
1783 template<
typename MT
1799 template<
typename MT
1804 for(
size_t i=row_; i<row_+
m_; ++i )
1808 ?(
max( i+1UL, column_ ) )
1809 :(
max( i, column_ ) ) )
1813 ?(
min( i, column_+
n_ ) )
1814 :(
min( i+1UL, column_+
n_ ) ) )
1817 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1834 template<
typename MT
1841 const size_t index( row_ + i );
1845 ?(
max( i+1UL, column_ ) )
1846 :(
max( i, column_ ) ) )
1850 ?(
min( i, column_+
n_ ) )
1851 :(
min( i+1UL, column_+
n_ ) ) )
1854 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1871 template<
typename MT
1877 return Iterator( matrix_.set( row_+i, column_+j, value ), column_ );
1895 template<
typename MT
1901 return Iterator( matrix_.insert( row_+i, column_+j, value ), column_ );
1915 template<
typename MT
1923 matrix_.erase( row_ + i, column_ + j );
1939 template<
typename MT
1946 return Iterator( matrix_.erase( row_+i, pos.base() ), column_ );
1964 template<
typename MT
1971 return Iterator( matrix_.erase( row_+i, first.base(), last.base() ), column_ );
1986 template<
typename MT
1991 const size_t current(
capacity() );
1993 if( nonzeros > current ) {
1994 matrix_.reserve( matrix_.capacity() + nonzeros - current );
2015 template<
typename MT
2020 const size_t current(
capacity( i ) );
2021 const size_t index ( row_ + i );
2023 if( nonzeros > current ) {
2024 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
2040 template<
typename MT
2045 for(
size_t i=0UL; i<
rows(); ++i )
2062 template<
typename MT
2068 matrix_.trim( row_ + i );
2084 template<
typename MT
2092 throw std::runtime_error(
"Invalid transpose of a non-quadratic submatrix" );
2095 throw std::runtime_error(
"Invalid transpose of a lower matrix" );
2098 throw std::runtime_error(
"Invalid transpose of an upper matrix" );
2120 template<
typename MT
2123 template<
typename Other >
2128 for(
size_t i=0UL; i<
rows(); ++i ) {
2131 element->value() *= scalar;
2148 template<
typename MT
2155 if( ( row_ +
m_ <= column_ ) || ( column_ +
n_ <= row_ ) )
2173 template<
typename MT
2176 template<
typename MT2
2201 template<
typename MT
2204 template<
typename MT2
2218 const bool lower( row_ > column_ );
2219 const size_t size (
min( row_ +
m_, column_ +
n_ ) - ( lower ? row_ : column_ ) );
2224 const size_t row ( lower ? 0UL : column_ - row_ );
2225 const size_t column( lower ? row_ - column_ : 0UL );
2244 template<
typename MT
2247 template<
typename MT2
2257 if( row_ + 1UL >= column_ +
n_ )
2261 ?( column_ +
n_ - row_ )
2262 :( column_ +
n_ - row_ - 1UL ) );
2263 const size_t iend(
min( ipos,
m_ ) );
2265 for(
size_t i=0UL; i<iend; ++i )
2267 const bool containsDiagonal( row_+i >= column_ );
2272 const size_t jbegin( ( containsDiagonal )
2274 ?( row_ + i - column_ )
2275 :( row_ + i - column_ + 1UL ) )
2278 for(
size_t j=jbegin; j<
n_; ++j ) {
2301 template<
typename MT
2304 template<
typename MT2
2307 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2314 if( row_ + 1UL >= column_ +
n_ )
2319 :( row_ - column_ + 1UL ) );
2320 const size_t jbegin( ( row_ < column_ )?( 0UL ):( jpos ) );
2322 for(
size_t j=jbegin; j<
n_; ++j )
2324 const bool containsDiagonal( column_+j < row_+
m_ );
2327 ?( column_ + j - row_ + 1UL )
2328 :( column_ + j - row_ ) );
2329 const size_t iend(
min( ipos,
m_ ) );
2331 for(
size_t i=0UL; i<iend; ++i ) {
2357 template<
typename MT
2360 template<
typename MT2
2363 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2372 if( row_ + 1UL >= column_ +
n_ )
2376 ?( column_ +
n_ - row_ )
2377 :( column_ +
n_ - row_ - 1UL ) );
2378 const size_t iend(
min( ipos,
m_ ) );
2380 for(
size_t i=0UL; i<iend; ++i )
2382 const bool containsDiagonal( row_+i >= column_ );
2384 const size_t index( ( containsDiagonal )
2386 ?( row_ + i - column_ )
2387 :( row_ + i - column_ + 1UL ) )
2390 const RhsIterator last( (~rhs).
end(i) );
2391 RhsIterator element( (~rhs).lowerBound( i, index ) );
2394 if( element == last || ( element->index() != row_+i-column_ ) || !
isOne( element->value() ) )
2399 for( ; element!=last; ++element ) {
2422 template<
typename MT
2425 template<
typename MT2
2428 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2437 if( row_ + 1UL >= column_ +
n_ )
2442 :( row_ - column_ + 1UL ) );
2443 const size_t jbegin( ( row_ < column_ )?( 0UL ):( jpos ) );
2445 for(
size_t j=jbegin; j<
n_; ++j )
2447 const bool containsDiagonal( column_+j < row_+
m_ );
2450 ?( column_ + j - row_ + 1UL )
2451 :( column_ + j - row_ ) );
2452 const RhsIterator last( (~rhs).lowerBound(
min( index,
m_ ), j ) );
2455 ( last == (~rhs).
end(j) || ( last->index() != column_+j-row_ ) || !
isOne( last->value() ) ) ) {
2459 for( RhsIterator element=(~rhs).begin(j); element!=last; ++element ) {
2482 template<
typename MT
2485 template<
typename MT2
2495 if( column_ + 1UL >= row_ +
m_ )
2500 :( column_ - row_ + 1UL ) );
2501 const size_t ibegin( ( column_ < row_ )?( 0UL ):( ipos ) );
2503 for(
size_t i=ibegin; i<
m_; ++i )
2505 const bool containsDiagonal( row_+i < column_+
n_ );
2508 ?( row_ + i - column_ + 1UL )
2509 :( row_ + i - column_ ) );
2510 const size_t jend(
min( jpos,
n_ ) );
2512 for(
size_t j=0UL; j<jend; ++j ) {
2538 template<
typename MT
2541 template<
typename MT2
2544 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2551 if( column_ + 1UL >= row_ +
m_ )
2555 ?( row_ +
m_ - column_ )
2556 :( row_ +
m_ - column_ - 1UL ) );
2557 const size_t jend(
min( jpos,
n_ ) );
2559 for(
size_t j=0UL; j<jend; ++j )
2561 const bool containsDiagonal( column_+j >= row_ );
2566 const size_t ibegin( ( containsDiagonal )
2568 ?( column_ + j - row_ )
2569 :( column_ + j - row_ + 1UL ) )
2572 for(
size_t i=ibegin; i<
m_; ++i ) {
2595 template<
typename MT
2598 template<
typename MT2
2601 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2610 if( column_ + 1UL >= row_ +
m_ )
2615 :( column_ - row_ + 1UL ) );
2616 const size_t ibegin( ( column_ < row_ )?( 0UL ):( ipos ) );
2618 for(
size_t i=ibegin; i<
m_; ++i )
2620 const bool containsDiagonal( row_+i < column_+
n_ );
2623 ?( row_ + i - column_ + 1UL )
2624 :( row_ + i - column_ ) );
2625 const RhsIterator last( (~rhs).lowerBound( i,
min( index,
n_ ) ) );
2628 ( last == (~rhs).
end(i) || ( last->index() != row_+i-column_ ) || !
isOne( last->value() ) ) ) {
2632 for( RhsIterator element=(~rhs).begin(i); element!=last; ++element ) {
2655 template<
typename MT
2658 template<
typename MT2
2661 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2670 if( column_ + 1UL >= row_ +
m_ )
2674 ?( row_ +
m_ - column_ )
2675 :( row_ +
m_ - column_ - 1UL ) );
2676 const size_t jend(
min( jpos,
n_ ) );
2678 for(
size_t j=0UL; j<jend; ++j )
2680 const bool containsDiagonal( column_+j >= row_ );
2682 const size_t index( ( containsDiagonal )
2684 ?( column_ + j - row_ )
2685 :( column_ + j - row_ + 1UL ) )
2688 const RhsIterator last( (~rhs).
end(j) );
2689 RhsIterator element( (~rhs).lowerBound( index, j ) );
2692 if( element == last || ( element->index() != column_+j-row_ ) || !
isOne( element->value() ) )
2697 for( ; element!=last; ++element ) {
2719 template<
typename MT
2722 template<
typename MT2
2732 for(
size_t i=0UL; i<
m_; ++i ) {
2733 for(
size_t j=0UL; j<
n_; ++j ) {
2734 if( ( row_ + i != column_ + j ) && !
isDefault( (~rhs)(i,j) ) )
2755 template<
typename MT
2758 template<
typename MT2
2761 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
2768 for(
size_t j=0UL; j<
n_; ++j ) {
2769 for(
size_t i=0UL; i<
m_; ++i ) {
2770 if( ( column_ + j != row_ + i ) && !
isDefault( (~rhs)(i,j) ) )
2791 template<
typename MT
2794 template<
typename MT2
2797 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
2806 for(
size_t i=0UL; i<
m_; ++i ) {
2807 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element ) {
2808 if( ( row_ + i != column_ + element->index() ) && !
isDefault( element->value() ) )
2829 template<
typename MT
2832 template<
typename MT2
2835 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
2844 for(
size_t j=0UL; j<
n_; ++j ) {
2845 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element ) {
2846 if( ( column_ + j != row_ + element->index() ) && !
isDefault( element->value() ) )
2879 template<
typename MT
2885 const typename MT::Iterator pos( matrix_.find( row_ + i, column_ + j ) );
2887 if( pos != matrix_.end( row_ + i ) )
2910 template<
typename MT
2918 if( pos != matrix_.end( row_ + i ) )
2941 template<
typename MT
2947 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2967 template<
typename MT
2973 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2993 template<
typename MT
2999 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
3019 template<
typename MT
3025 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
3086 template<
typename MT
3091 if( column_ +
n_ == matrix_.columns() ) {
3092 matrix_.append( row_ + i, column_ + j, value, check );
3094 else if( !check || !
isDefault( value ) ) {
3095 matrix_.insert( row_ + i, column_ + j, value );
3114 template<
typename MT
3119 matrix_.trim( row_ + i );
3142 template<
typename MT
3145 template<
typename Other >
3148 return matrix_.isAliased( alias );
3163 template<
typename MT
3166 template<
typename Other >
3169 return matrix_.isAliased( alias );
3184 template<
typename MT
3205 template<
typename MT
3208 template<
typename MT2
3219 for(
size_t i=0UL; i<
rows(); ++i ) {
3220 for(
size_t j=0UL; j<
columns(); ++j ) {
3222 set( i, j, (~rhs)(i,j) );
3224 append( i, j, (~rhs)(i,j),
true );
3243 template<
typename MT
3246 template<
typename MT2 >
3256 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
3259 set( i, element->index(), element->value() );
3261 append( i, element->index(), element->value(), true );
3280 template<
typename MT
3283 template<
typename MT2 >
3295 std::vector<size_t> rowLengths(
m_, 0UL );
3296 for(
size_t j=0UL; j<
n_; ++j ) {
3297 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
3298 ++rowLengths[element->index()];
3302 for(
size_t i=0UL; i<
m_; ++i ) {
3303 reserve( i, rowLengths[i] );
3307 for(
size_t j=0UL; j<
n_; ++j ) {
3308 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
3310 set( element->index(), j, element->value() );
3312 append( element->index(), j, element->value(), true );
3329 template<
typename MT
3332 template<
typename MT2
3346 const AddType tmp(
serial( *
this + (~rhs) ) );
3364 template<
typename MT
3367 template<
typename MT2
3381 const AddType tmp(
serial( *
this + (~rhs) ) );
3399 template<
typename MT
3402 template<
typename MT2
3416 const SubType tmp(
serial( *
this - (~rhs) ) );
3434 template<
typename MT
3437 template<
typename MT2
3451 const SubType tmp(
serial( *
this - (~rhs) ) );
3478 template<
typename MT
3502 typedef SparseSubmatrix<MT,AF,true>
This;
3503 typedef typename SubmatrixTrait<MT>::Type
ResultType;
3514 typedef typename IfTrue< useConst, ConstReference, typename MT::Reference >::Type
Reference;
3521 ,
typename IteratorType >
3522 class SubmatrixElement :
private SparseElement
3532 enum { returnConst = IsConst<MatrixType>::value };
3537 typedef typename std::iterator_traits<IteratorType>::value_type
SET;
3545 typedef typename SET::ValueType
ValueType;
3547 typedef typename IfTrue<returnConst,CRT,RT>::Type
Reference;
3638 inline Reference
value()
const {
3639 return pos_->value();
3648 inline IndexType
index()
const {
3665 ,
typename IteratorType >
3666 class SubmatrixIterator
3671 typedef SubmatrixElement<MatrixType,IteratorType>
ValueType;
3710 template<
typename MatrixType2,
typename IteratorType2 >
3711 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
3745 inline ReferenceType
operator*()
const {
3766 template<
typename MatrixType2,
typename IteratorType2 >
3767 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
3768 return base() == rhs.base();
3778 template<
typename MatrixType2,
typename IteratorType2 >
3779 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
3780 return !( *
this == rhs );
3791 return pos_ - rhs.pos_;
3800 inline IteratorType
base()
const {
3810 inline size_t offset()
const {
3825 typedef SubmatrixIterator<const MT,typename MT::ConstIterator>
ConstIterator;
3828 typedef typename IfTrue< useConst, ConstIterator, SubmatrixIterator<MT,typename MT::Iterator> >::Type
Iterator;
3833 enum { smpAssignable = MT::smpAssignable };
3851 inline Reference
operator()(
size_t i,
size_t j );
3852 inline ConstReference
operator()(
size_t i,
size_t j )
const;
3853 inline Iterator
begin (
size_t i );
3854 inline ConstIterator
begin (
size_t i )
const;
3855 inline ConstIterator
cbegin(
size_t i )
const;
3856 inline Iterator
end (
size_t i );
3857 inline ConstIterator
end (
size_t i )
const;
3858 inline ConstIterator
cend (
size_t i )
const;
3868 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator+=(
const Matrix<MT2,SO>& rhs );
3869 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator-=(
const Matrix<MT2,SO>& rhs );
3870 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator*=(
const Matrix<MT2,SO>& rhs );
3872 template<
typename Other >
3874 operator*=( Other rhs );
3876 template<
typename Other >
3878 operator/=( Other rhs );
3885 inline size_t rows()
const;
3886 inline size_t columns()
const;
3888 inline size_t capacity(
size_t i )
const;
3890 inline size_t nonZeros(
size_t i )
const;
3891 inline void reset();
3892 inline void reset(
size_t i );
3893 inline Iterator
set(
size_t i,
size_t j,
const ElementType& value );
3894 inline Iterator
insert(
size_t i,
size_t j,
const ElementType& value );
3895 inline void erase(
size_t i,
size_t j );
3896 inline Iterator
erase(
size_t i, Iterator pos );
3897 inline Iterator
erase(
size_t i, Iterator first, Iterator last );
3898 inline void reserve(
size_t nonzeros );
3899 void reserve(
size_t i,
size_t nonzeros );
3901 inline void trim(
size_t j );
3903 template<
typename Other >
inline SparseSubmatrix& scale(
const Other& scalar );
3910 inline Iterator
find (
size_t i,
size_t j );
3911 inline ConstIterator
find (
size_t i,
size_t j )
const;
3912 inline Iterator
lowerBound(
size_t i,
size_t j );
3913 inline ConstIterator
lowerBound(
size_t i,
size_t j )
const;
3914 inline Iterator
upperBound(
size_t i,
size_t j );
3915 inline ConstIterator
upperBound(
size_t i,
size_t j )
const;
3922 inline void append (
size_t i,
size_t j,
const ElementType& value,
bool check=
false );
3930 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
3931 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
3935 template<
typename MT2,
bool SO >
inline void assign (
const DenseMatrix<MT2,SO>& rhs );
3936 template<
typename MT2 >
inline void assign (
const SparseMatrix<MT2,true>& rhs );
3937 template<
typename MT2 >
inline void assign (
const SparseMatrix<MT2,false>& rhs );
3938 template<
typename MT2,
bool SO >
inline void addAssign(
const DenseMatrix<MT2,SO>& rhs );
3939 template<
typename MT2,
bool SO >
inline void addAssign(
const SparseMatrix<MT2,SO>& rhs );
3940 template<
typename MT2,
bool SO >
inline void subAssign(
const DenseMatrix<MT2,SO>& rhs );
3941 template<
typename MT2,
bool SO >
inline void subAssign(
const SparseMatrix<MT2,SO>& rhs );
3951 template<
typename MT2,
bool SO2,
typename MT3,
bool SO3 >
3952 inline typename EnableIf< Not< IsAdaptor<MT2> >,
bool >::Type
3953 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Matrix<MT3,SO3>& rhs );
3955 template<
typename MT2,
bool SO2,
typename MT3,
bool SO3 >
3956 inline typename EnableIf< And< IsSymmetric<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3957 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Matrix<MT3,SO3>& rhs );
3959 template<
typename MT2,
bool SO2,
typename MT3 >
3960 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3961 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs );
3963 template<
typename MT2,
bool SO2,
typename MT3 >
3964 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3965 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs );
3967 template<
typename MT2,
bool SO2,
typename MT3 >
3968 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3969 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs );
3971 template<
typename MT2,
bool SO2,
typename MT3 >
3972 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3973 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs );
3975 template<
typename MT2,
bool SO2,
typename MT3 >
3976 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3977 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs );
3979 template<
typename MT2,
bool SO2,
typename MT3 >
3980 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3981 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs );
3983 template<
typename MT2,
bool SO2,
typename MT3 >
3984 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3985 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs );
3987 template<
typename MT2,
bool SO2,
typename MT3 >
3988 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3989 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs );
3991 template<
typename MT2,
bool SO2,
typename MT3 >
3992 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
3993 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs );
3995 template<
typename MT2,
bool SO2,
typename MT3 >
3996 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
3997 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs );
3999 template<
typename MT2,
bool SO2,
typename MT3 >
4000 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
4001 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs );
4003 template<
typename MT2,
bool SO2,
typename MT3 >
4004 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
4005 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs );
4021 template<
bool AF1,
typename MT2,
bool AF2,
bool SO2 >
4022 friend const SparseSubmatrix<MT2,AF1,SO2>
4023 submatrix(
const SparseSubmatrix<MT2,AF2,SO2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
4025 template<
typename MT2,
bool AF2,
bool SO2 >
4026 friend bool isSymmetric(
const SparseSubmatrix<MT2,AF2,SO2>& sm );
4028 template<
typename MT2,
bool AF2,
bool SO2 >
4029 friend bool isLower(
const SparseSubmatrix<MT2,AF2,SO2>& sm );
4031 template<
typename MT2,
bool AF2,
bool SO2 >
4032 friend bool isUpper(
const SparseSubmatrix<MT2,AF2,SO2>& sm );
4034 template<
typename MT2,
bool AF2,
bool SO2 >
4035 friend bool isSame(
const SparseSubmatrix<MT2,AF2,SO2>& a,
const SparseMatrix<MT2,SO2>& b );
4037 template<
typename MT2,
bool AF2,
bool SO2 >
4038 friend bool isSame(
const SparseMatrix<MT2,SO2>& a,
const SparseSubmatrix<MT2,AF2,SO2>& b );
4040 template<
typename MT2,
bool AF2,
bool SO2 >
4041 friend bool isSame(
const SparseSubmatrix<MT2,AF2,SO2>& a,
const SparseSubmatrix<MT2,AF2,SO2>& b );
4043 template<
typename MT2,
bool AF2,
bool SO2 >
4044 friend typename DerestrictTrait< SparseSubmatrix<MT2,AF2,SO2> >::Type
4045 derestrict( SparseSubmatrix<MT2,AF2,SO2>& sm );
4056 BLAZE_STATIC_ASSERT( !IsRestricted<MT>::value || IsLower<MT>::value || IsUpper<MT>::value );
4085 template<
typename MT
4094 if( ( row + m > matrix.rows() ) || ( column + n > matrix.columns() ) )
4095 throw std::invalid_argument(
"Invalid submatrix specification" );
4117 template<
typename MT
4125 return matrix_(row_+i,column_+j);
4139 template<
typename MT
4147 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
4160 template<
typename MT
4168 return Iterator( matrix_.begin( j + column_ ), row_ );
4170 return Iterator( matrix_.lowerBound( row_, j + column_ ), row_ );
4183 template<
typename MT
4191 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
4193 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
4206 template<
typename MT
4214 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
4216 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
4229 template<
typename MT
4236 if( matrix_.rows() == row_ +
m_ )
4237 return Iterator( matrix_.end( j + column_ ), row_ );
4239 return Iterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
4252 template<
typename MT
4259 if( matrix_.rows() == row_ +
m_ )
4262 return ConstIterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
4275 template<
typename MT
4282 if( matrix_.rows() == row_ +
m_ )
4285 return ConstIterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
4314 template<
typename MT
4316 inline SparseSubmatrix<MT,AF,true>&
4324 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
4327 if(
rows() != rhs.rows() ||
columns() != rhs.columns() )
4328 throw std::invalid_argument(
"Submatrix sizes do not match" );
4330 if( !preservesInvariant( matrix_, rhs ) )
4331 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
4333 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4335 if( rhs.canAlias( &matrix_ ) ) {
4336 const ResultType tmp( rhs );
4370 template<
typename MT
4372 template<
typename MT2
4374 inline SparseSubmatrix<MT,AF,true>&
4382 throw std::invalid_argument(
"Matrix sizes do not match" );
4385 Right right( ~rhs );
4387 if( !preservesInvariant( matrix_, right ) )
4388 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
4390 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4392 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4426 template<
typename MT
4428 template<
typename MT2
4430 inline SparseSubmatrix<MT,AF,true>&
4431 SparseSubmatrix<MT,AF,true>::operator+=(
const Matrix<MT2,SO>& rhs )
4439 typedef typename AddTrait<ResultType,typename MT2::ResultType>::Type AddType;
4444 throw std::invalid_argument(
"Matrix sizes do not match" );
4446 const AddType tmp( *
this + (~rhs) );
4448 if( !preservesInvariant( matrix_, tmp ) )
4449 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
4451 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4480 template<
typename MT
4482 template<
typename MT2
4484 inline SparseSubmatrix<MT,AF,true>&
4485 SparseSubmatrix<MT,AF,true>::operator-=(
const Matrix<MT2,SO>& rhs )
4493 typedef typename SubTrait<ResultType,typename MT2::ResultType>::Type SubType;
4498 throw std::invalid_argument(
"Matrix sizes do not match" );
4500 const SubType tmp( *
this - (~rhs) );
4502 if( !preservesInvariant( matrix_, tmp ) )
4503 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
4505 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4534 template<
typename MT
4536 template<
typename MT2
4538 inline SparseSubmatrix<MT,AF,true>&
4539 SparseSubmatrix<MT,AF,true>::operator*=(
const Matrix<MT2,SO>& rhs )
4547 typedef typename MultTrait<ResultType,typename MT2::ResultType>::Type MultType;
4553 throw std::invalid_argument(
"Matrix sizes do not match" );
4555 const MultType tmp( *
this * (~rhs) );
4557 if( !preservesInvariant( matrix_, tmp ) )
4558 throw std::invalid_argument(
"Invalid assignment to matrix adaptor" );
4560 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4590 template<
typename MT
4592 template<
typename Other >
4593 inline typename EnableIf< IsNumeric<Other>, SparseSubmatrix<MT,AF,true> >::Type&
4594 SparseSubmatrix<MT,AF,true>::operator*=( Other rhs )
4598 for(
size_t i=0UL; i<
columns(); ++i ) {
4601 element->value() *= rhs;
4628 template<
typename MT
4630 template<
typename Other >
4631 inline typename EnableIf< IsNumeric<Other>, SparseSubmatrix<MT,AF,true> >::Type&
4632 SparseSubmatrix<MT,AF,true>::operator/=( Other rhs )
4638 typedef typename DivTrait<ElementType,Other>::Type DT;
4639 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
4643 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
4644 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
4645 for(
size_t i=0UL; i<
columns(); ++i ) {
4648 element->value() *= tmp;
4652 for(
size_t i=0UL; i<
columns(); ++i ) {
4655 element->value() /= rhs;
4679 template<
typename MT
4695 template<
typename MT
4711 template<
typename MT
4715 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
4728 template<
typename MT
4733 return nonZeros( j ) + matrix_.capacity( column_+j ) - matrix_.nonZeros( column_+j );
4745 template<
typename MT
4749 size_t nonzeros( 0UL );
4751 for(
size_t i=0UL; i<
columns(); ++i )
4767 template<
typename MT
4784 template<
typename MT
4788 for(
size_t j=column_; j<column_+
n_; ++j )
4790 const size_t ibegin( ( IsLower<MT>::value )
4791 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
4792 ?(
max( j+1UL, row_ ) )
4793 :(
max( j, row_ ) ) )
4795 const size_t iend ( ( IsUpper<MT>::value )
4796 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
4797 ?(
min( j, row_+
m_ ) )
4798 :(
min( j+1UL, row_+
m_ ) ) )
4801 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
4815 template<
typename MT
4821 const size_t index( column_ + j );
4823 const size_t ibegin( ( IsLower<MT>::value )
4824 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
4825 ?(
max( j+1UL, row_ ) )
4826 :(
max( j, row_ ) ) )
4828 const size_t iend ( ( IsUpper<MT>::value )
4829 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
4830 ?(
min( j, row_+
m_ ) )
4831 :(
min( j+1UL, row_+
m_ ) ) )
4834 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
4853 template<
typename MT
4858 return Iterator( matrix_.set( row_+i, column_+j, value ), row_ );
4878 template<
typename MT
4883 return Iterator( matrix_.insert( row_+i, column_+j, value ), row_ );
4899 template<
typename MT
4906 matrix_.erase( row_ + i, column_ + j );
4922 template<
typename MT
4928 return Iterator( matrix_.erase( column_+j, pos.base() ), row_ );
4945 template<
typename MT
4951 return Iterator( matrix_.erase( column_+j, first.base(), last.base() ), row_ );
4968 template<
typename MT
4972 const size_t current(
capacity() );
4974 if( nonzeros > current ) {
4975 matrix_.reserve( matrix_.capacity() + nonzeros - current );
4994 template<
typename MT
4998 const size_t current(
capacity( j ) );
4999 const size_t index ( column_ + j );
5001 if( nonzeros > current ) {
5002 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
5019 template<
typename MT
5023 for(
size_t j=0UL; j<
columns(); ++j )
5041 template<
typename MT
5046 matrix_.trim( column_ + j );
5064 template<
typename MT
5071 throw std::runtime_error(
"Invalid transpose of a non-quadratic submatrix" );
5073 if( IsLower<MT>::value && ( row_ + 1UL < column_ + n_ ) )
5074 throw std::runtime_error(
"Invalid transpose of a lower matrix" );
5076 if( IsUpper<MT>::value && ( column_ + 1UL < row_ +
m_ ) )
5077 throw std::runtime_error(
"Invalid transpose of an upper matrix" );
5079 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
5080 const ResultType tmp(
trans(*
this) );
5101 template<
typename MT
5103 template<
typename Other >
5104 inline SparseSubmatrix<MT,AF,true>& SparseSubmatrix<MT,AF,true>::scale(
const Other& scalar )
5108 for(
size_t i=0UL; i<
columns(); ++i ) {
5111 element->value() *= scalar;
5130 template<
typename MT
5136 if( ( row_ +
m_ <= column_ ) || ( column_ + n_ <= row_ ) )
5156 template<
typename MT
5158 template<
typename MT2
5162 inline typename EnableIf< Not< IsAdaptor<MT2> >,
bool >::Type
5163 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Matrix<MT3,SO3>& rhs )
5185 template<
typename MT
5187 template<
typename MT2
5191 inline typename EnableIf< And< IsSymmetric<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5192 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Matrix<MT3,SO3>& rhs )
5201 const bool lower( row_ > column_ );
5202 const size_t size (
min( row_ +
m_, column_ + n_ ) - ( lower ? row_ : column_ ) );
5207 const size_t row ( lower ? 0UL : column_ - row_ );
5208 const size_t column( lower ? row_ - column_ : 0UL );
5229 template<
typename MT
5231 template<
typename MT2
5234 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5235 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs )
5241 if( row_ + 1UL >= column_ + n_ )
5244 const size_t ipos( ( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value )
5245 ?( column_ + n_ - row_ )
5246 :( column_ + n_ - row_ - 1UL ) );
5247 const size_t iend(
min( ipos,
m_ ) );
5249 for(
size_t i=0UL; i<iend; ++i )
5251 const bool containsDiagonal( row_+i >= column_ );
5253 if( IsUniLower<MT2>::value && containsDiagonal && !
isOne( (~rhs)(i,row_+i-column_) ) )
5256 const size_t jbegin( ( containsDiagonal )
5257 ?( ( IsStrictlyLower<MT2>::value )
5258 ?( row_ + i - column_ )
5259 :( row_ + i - column_ + 1UL ) )
5262 for(
size_t j=jbegin; j<
n_; ++j ) {
5287 template<
typename MT
5289 template<
typename MT2
5292 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5293 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs )
5299 if( row_ + 1UL >= column_ + n_ )
5302 const size_t jpos( ( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value )
5304 :( row_ - column_ + 1UL ) );
5305 const size_t jbegin( ( row_ < column_ )?( 0UL ):( jpos ) );
5307 for(
size_t j=jbegin; j<
n_; ++j )
5309 const bool containsDiagonal( column_+j < row_+
m_ );
5311 const size_t ipos( ( IsStrictlyLower<MT2>::value && containsDiagonal )
5312 ?( column_ + j - row_ + 1UL )
5313 :( column_ + j - row_ ) );
5314 const size_t iend(
min( ipos,
m_ ) );
5316 for(
size_t i=0UL; i<iend; ++i ) {
5321 if( IsUniLower<MT2>::value && containsDiagonal && !
isOne( (~rhs)(column_+j-row_,j) ) )
5344 template<
typename MT
5346 template<
typename MT2
5349 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5350 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs )
5358 if( row_ + 1UL >= column_ + n_ )
5361 const size_t ipos( ( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value )
5362 ?( column_ + n_ - row_ )
5363 :( column_ + n_ - row_ - 1UL ) );
5364 const size_t iend(
min( ipos,
m_ ) );
5366 for(
size_t i=0UL; i<iend; ++i )
5368 const bool containsDiagonal( row_+i >= column_ );
5370 const size_t index( ( containsDiagonal )
5371 ?( ( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value )
5372 ?( row_ + i - column_ )
5373 :( row_ + i - column_ + 1UL ) )
5376 const RhsIterator last( (~rhs).
end(i) );
5377 RhsIterator element( (~rhs).lowerBound( i, index ) );
5379 if( IsUniLower<MT2>::value && containsDiagonal ) {
5380 if( element == last || ( element->index() != row_+i-column_ ) || !
isOne( element->value() ) )
5385 for( ; element!=last; ++element ) {
5410 template<
typename MT
5412 template<
typename MT2
5415 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5416 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs )
5424 if( row_ + 1UL >= column_ + n_ )
5427 const size_t jpos( ( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value )
5429 :( row_ - column_ + 1UL ) );
5430 const size_t jbegin( ( row_ < column_ )?( 0UL ):( jpos ) );
5432 for(
size_t j=jbegin; j<
n_; ++j )
5434 const bool containsDiagonal( column_+j < row_+
m_ );
5436 const size_t index( ( IsStrictlyLower<MT2>::value && containsDiagonal )
5437 ?( column_ + j - row_ + 1UL )
5438 :( column_ + j - row_ ) );
5439 const RhsIterator last( (~rhs).lowerBound(
min( index,
m_ ), j ) );
5441 if( IsUniLower<MT2>::value && containsDiagonal &&
5442 ( last == (~rhs).
end(j) || ( last->index() != column_+j-row_ ) || !
isOne( last->value() ) ) ) {
5446 for( RhsIterator element=(~rhs).begin(j); element!=last; ++element ) {
5471 template<
typename MT
5473 template<
typename MT2
5476 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5477 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs )
5483 if( column_ + 1UL >= row_ +
m_ )
5486 const size_t ipos( ( IsUniUpper<MT2>::value || IsStrictlyUpper<MT2>::value )
5488 :( column_ - row_ + 1UL ) );
5489 const size_t ibegin( ( column_ < row_ )?( 0UL ):( ipos ) );
5491 for(
size_t i=ibegin; i<
m_; ++i )
5493 const bool containsDiagonal( row_+i < column_+n_ );
5495 const size_t jpos( ( IsStrictlyUpper<MT2>::value && containsDiagonal )
5496 ?( row_ + i - column_ + 1UL )
5497 :( row_ + i - column_ ) );
5498 const size_t jend(
min( jpos, n_ ) );
5500 for(
size_t j=0UL; j<jend; ++j ) {
5505 if( IsUniUpper<MT2>::value && containsDiagonal && !
isOne( (~rhs)(i,row_+i-column_) ) )
5528 template<
typename MT
5530 template<
typename MT2
5533 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5534 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs )
5540 if( column_ + 1UL >= row_ + m_ )
5543 const size_t jpos( ( IsUniUpper<MT2>::value || IsStrictlyUpper<MT2>::value )
5544 ?( row_ + m_ - column_ )
5545 :( row_ + m_ - column_ - 1UL ) );
5546 const size_t jend(
min( jpos, n_ ) );
5548 for(
size_t j=0UL; j<jend; ++j )
5550 const bool containsDiagonal( column_+j >= row_ );
5552 if( IsUniUpper<MT2>::value && containsDiagonal && !
isOne( (~rhs)(column_+j-row_,j) ) )
5555 const size_t ibegin( ( containsDiagonal )
5556 ?( ( IsStrictlyUpper<MT2>::value )
5557 ?( column_ + j - row_ )
5558 :( column_ + j - row_ + 1UL ) )
5561 for(
size_t i=ibegin; i<
m_; ++i ) {
5586 template<
typename MT
5588 template<
typename MT2
5591 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5592 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs )
5600 if( column_ + 1UL >= row_ + m_ )
5603 const size_t ipos( ( IsUniUpper<MT2>::value || IsStrictlyUpper<MT2>::value )
5605 :( column_ - row_ + 1UL ) );
5606 const size_t ibegin( ( column_ < row_ )?( 0UL ):( ipos ) );
5608 for(
size_t i=ibegin; i<
m_; ++i )
5610 const bool containsDiagonal( row_+i < column_+n_ );
5612 const size_t index( ( IsStrictlyUpper<MT2>::value && containsDiagonal )
5613 ?( row_ + i - column_ + 1UL )
5614 :( row_ + i - column_ ) );
5615 const RhsIterator last( (~rhs).lowerBound( i,
min( index, n_ ) ) );
5617 if( IsUniUpper<MT2>::value && containsDiagonal &&
5618 ( last == (~rhs).
end(i) || ( last->index() != row_+i-column_ ) || !
isOne( last->value() ) ) ) {
5622 for( RhsIterator element=(~rhs).begin(i); element!=last; ++element ) {
5647 template<
typename MT
5649 template<
typename MT2
5652 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5653 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs )
5661 if( column_ + 1UL >= row_ + m_ )
5664 const size_t jpos( ( IsUniUpper<MT2>::value || IsStrictlyUpper<MT2>::value )
5665 ?( row_ + m_ - column_ )
5666 :( row_ + m_ - column_ - 1UL ) );
5667 const size_t jend(
min( jpos, n_ ) );
5669 for(
size_t j=0UL; j<jend; ++j )
5671 const bool containsDiagonal( column_+j >= row_ );
5673 const size_t index( ( containsDiagonal )
5674 ?( ( IsUniUpper<MT2>::value || IsStrictlyUpper<MT2>::value )
5675 ?( column_ + j - row_ )
5676 :( column_ + j - row_ + 1UL ) )
5679 const RhsIterator last( (~rhs).
end(j) );
5680 RhsIterator element( (~rhs).lowerBound( index, j ) );
5682 if( IsUniUpper<MT2>::value && containsDiagonal ) {
5683 if( element == last || ( element->index() != column_+j-row_ ) || !
isOne( element->value() ) )
5688 for( ; element!=last; ++element ) {
5713 template<
typename MT
5715 template<
typename MT2
5718 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5719 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,false>& rhs )
5725 for(
size_t i=0UL; i<
m_; ++i ) {
5726 for(
size_t j=0UL; j<
n_; ++j ) {
5727 if( ( row_ + i != column_ + j ) && !
isDefault( (~rhs)(i,j) ) )
5751 template<
typename MT
5753 template<
typename MT2
5756 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5757 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseMatrix<MT3,true>& rhs )
5763 for(
size_t j=0UL; j<
n_; ++j ) {
5764 for(
size_t i=0UL; i<
m_; ++i ) {
5765 if( ( column_ + j != row_ + i ) && !
isDefault( (~rhs)(i,j) ) )
5789 template<
typename MT
5791 template<
typename MT2
5794 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5795 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,false>& rhs )
5803 for(
size_t i=0UL; i<
m_; ++i ) {
5804 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element ) {
5805 if( ( row_ + i != column_ + element->index() ) && !
isDefault( element->value() ) )
5829 template<
typename MT
5831 template<
typename MT2
5834 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5835 SparseSubmatrix<MT,AF,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseMatrix<MT3,true>& rhs )
5843 for(
size_t j=0UL; j<
n_; ++j ) {
5844 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element ) {
5845 if( ( column_ + j != row_ + element->index() ) && !
isDefault( element->value() ) )
5880 template<
typename MT
5885 const typename MT::Iterator pos( matrix_.find( row_ + i, column_ + j ) );
5887 if( pos != matrix_.end( column_ + j ) )
5912 template<
typename MT
5919 if( pos != matrix_.end( column_ + j ) )
5944 template<
typename MT
5949 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
5971 template<
typename MT
5976 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
5998 template<
typename MT
6003 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
6025 template<
typename MT
6030 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
6093 template<
typename MT
6097 if( row_ + m_ == matrix_.rows() ) {
6098 matrix_.append( row_ + i, column_ + j, value, check );
6100 else if( !check || !
isDefault( value ) ) {
6101 matrix_.insert( row_ + i, column_ + j, value );
6122 template<
typename MT
6126 matrix_.trim( column_ + j );
6151 template<
typename MT
6153 template<
typename Other >
6156 return matrix_.isAliased( alias );
6173 template<
typename MT
6175 template<
typename Other >
6178 return matrix_.isAliased( alias );
6195 template<
typename MT
6217 template<
typename MT
6219 template<
typename MT2
6230 for(
size_t j=0UL; j<
columns(); ++j ) {
6231 for(
size_t i=0UL; i<
rows(); ++i ) {
6232 if( IsSymmetric<MT>::value )
6233 set( i, j, (~rhs)(i,j) );
6235 append( i, j, (~rhs)(i,j),
true );
6256 template<
typename MT
6258 template<
typename MT2 >
6268 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
6270 if( IsSymmetric<MT>::value )
6271 set( element->index(), j, element->value() );
6273 append( element->index(), j, element->value(), true );
6294 template<
typename MT
6296 template<
typename MT2 >
6308 std::vector<size_t> columnLengths( n_, 0UL );
6309 for(
size_t i=0UL; i<
m_; ++i ) {
6310 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
6311 ++columnLengths[element->index()];
6315 for(
size_t j=0UL; j<
n_; ++j ) {
6316 reserve( j, columnLengths[j] );
6320 for(
size_t i=0UL; i<
m_; ++i ) {
6321 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
6322 if( IsSymmetric<MT>::value )
6323 set( i, element->index(), element->value() );
6325 append( i, element->index(), element->value(), true );
6344 template<
typename MT
6346 template<
typename MT2
6352 typedef typename AddTrait<ResultType,typename MT2::ResultType>::Type AddType;
6360 const AddType tmp(
serial( *
this + (~rhs) ) );
6380 template<
typename MT
6382 template<
typename MT2
6388 typedef typename AddTrait<ResultType,typename MT2::ResultType>::Type AddType;
6396 const AddType tmp(
serial( *
this + (~rhs) ) );
6416 template<
typename MT
6418 template<
typename MT2
6424 typedef typename SubTrait<ResultType,typename MT2::ResultType>::Type SubType;
6432 const SubType tmp(
serial( *
this - (~rhs) ) );
6452 template<
typename MT
6454 template<
typename MT2
6460 typedef typename SubTrait<ResultType,typename MT2::ResultType>::Type SubType;
6468 const SubType tmp(
serial( *
this - (~rhs) ) );
6491 template<
typename MT,
bool AF,
bool SO >
6492 inline void reset( SparseSubmatrix<MT,AF,SO>& sm );
6494 template<
typename MT,
bool AF,
bool SO >
6495 inline void reset( SparseSubmatrix<MT,AF,SO>& sm,
size_t i );
6497 template<
typename MT,
bool AF,
bool SO >
6498 inline void clear( SparseSubmatrix<MT,AF,SO>& sm );
6500 template<
typename MT,
bool AF,
bool SO >
6501 inline bool isDefault(
const SparseSubmatrix<MT,AF,SO>& sm );
6503 template<
typename MT,
bool AF,
bool SO >
6504 inline bool isSymmetric(
const SparseSubmatrix<MT,AF,SO>& sm );
6506 template<
typename MT,
bool AF,
bool SO >
6507 inline bool isLower(
const SparseSubmatrix<MT,AF,SO>& sm );
6509 template<
typename MT,
bool AF,
bool SO >
6510 inline bool isUpper(
const SparseSubmatrix<MT,AF,SO>& sm );
6512 template<
typename MT,
bool AF,
bool SO >
6513 inline bool isSame(
const SparseSubmatrix<MT,AF,SO>& a,
const SparseMatrix<MT,SO>& b );
6515 template<
typename MT,
bool AF,
bool SO >
6516 inline bool isSame(
const SparseMatrix<MT,SO>& a,
const SparseSubmatrix<MT,AF,SO>& b );
6518 template<
typename MT,
bool AF,
bool SO >
6519 inline bool isSame(
const SparseSubmatrix<MT,AF,SO>& a,
const SparseSubmatrix<MT,AF,SO>& b );
6531 template<
typename MT
6554 template<
typename MT
6573 template<
typename MT
6601 template<
typename MT
6610 const size_t iend( ( SO ==
rowMajor)?( sm.rows() ):( sm.columns() ) );
6612 for(
size_t i=0UL; i<iend; ++i ) {
6613 for( ConstIterator element=sm.begin(i); element!=sm.end(i); ++element )
6614 if( !
isDefault( element->value() ) )
return false;
6644 template<
typename MT
6653 else return isSymmetric( static_cast<const BaseType&>( sm ) );
6690 template<
typename MT
6699 else return isLower( static_cast<const BaseType&>( sm ) );
6736 template<
typename MT
6745 else return isUpper( static_cast<const BaseType&>( sm ) );
6762 template<
typename MT
6767 return (
isSame( a.matrix_, ~b ) && ( a.rows() == (~b).
rows() ) && ( a.columns() == (~b).
columns() ) );
6784 template<
typename MT
6789 return (
isSame( ~a, b.matrix_ ) && ( (~a).rows() == b.rows() ) && ( (~a).columns() == b.columns() ) );
6806 template<
typename MT
6811 return (
isSame( a.matrix_, b.matrix_ ) &&
6812 ( a.row_ == b.row_ ) && ( a.column_ == b.column_ ) &&
6813 ( a.m_ == b.m_ ) && ( a.n_ == b.n_ ) );
6833 template<
typename MT
6836 inline typename DerestrictTrait< SparseSubmatrix<MT,AF,SO> >::Type
6837 derestrict( SparseSubmatrix<MT,AF,SO>& sm )
6839 typedef typename DerestrictTrait< SparseSubmatrix<MT,AF,SO> >::Type
ReturnType;
6840 return ReturnType( derestrict( sm.matrix_ ), sm.row_, sm.column_, sm.m_, sm.n_ );
6873 inline const SparseSubmatrix<MT,AF1,SO>
6874 submatrix(
const SparseSubmatrix<MT,AF2,SO>& sm,
size_t row,
size_t column,
size_t m,
size_t n )
6878 if( ( row + m > sm.rows() ) || ( column + n > sm.columns() ) )
6879 throw std::invalid_argument(
"Invalid submatrix specification" );
6881 return SparseSubmatrix<MT,AF1,SO>( sm.matrix_, sm.row_ +
row, sm.column_ +
column, m, n );
6897 template<
typename MT,
bool AF,
bool SO >
6898 struct IsRestricted< SparseSubmatrix<MT,AF,SO> > :
public If< IsRestricted<MT>, TrueType, FalseType >::Type
6900 enum { value = IsRestricted<MT>::value };
6917 template<
typename MT,
bool AF,
bool SO >
6918 struct DerestrictTrait< SparseSubmatrix<MT,AF,SO> >
6920 typedef SparseSubmatrix< typename RemoveReference< typename DerestrictTrait<MT>::Type >::Type, AF > Type;
6936 template<
typename MT,
bool AF,
bool SO >
6937 struct SubmatrixTrait< SparseSubmatrix<MT,AF,SO> >
6955 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
6956 struct SubmatrixExprTrait< SparseSubmatrix<MT,AF1,SO>, AF2 >
6958 typedef SparseSubmatrix<MT,AF2,SO> Type;
6966 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
6967 struct SubmatrixExprTrait< const SparseSubmatrix<MT,AF1,SO>, AF2 >
6969 typedef SparseSubmatrix<MT,AF2,SO> Type;
6977 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
6978 struct SubmatrixExprTrait< volatile SparseSubmatrix<MT,AF1,SO>, AF2 >
6980 typedef SparseSubmatrix<MT,AF2,SO> Type;
6988 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
6989 struct SubmatrixExprTrait< const volatile SparseSubmatrix<MT,AF1,SO>, AF2 >
6991 typedef SparseSubmatrix<MT,AF2,SO> Type;
7007 template<
typename MT,
bool AF,
bool SO >
7008 struct RowTrait< SparseSubmatrix<MT,AF,SO> >
7026 template<
typename MT,
bool AF,
bool SO >
7027 struct ColumnTrait< SparseSubmatrix<MT,AF,SO> >
Constraint on the data type.
Pointer difference type of the Blaze library.
SubmatrixElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:600
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
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.
ValueType value_type
Type of the underlying elements.
Definition: SparseSubmatrix.h:673
size_t columns() const
Returns the number of columns of the sparse submatrix.
Definition: SparseSubmatrix.h:1708
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less then the given index.
Definition: SparseSubmatrix.h:2945
Header file for the subvector/submatrix alignment flag values.
Header file for the UNUSED_PARAMETER function template.
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
Header file for the subtraction trait.
ConstIterator cbegin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: SparseSubmatrix.h:1217
MT::ElementType ElementType
Type of the submatrix elements.
Definition: SparseSubmatrix.h:501
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
SubmatrixIterator()
Default constructor for the SubmatrixIterator class.
Definition: SparseSubmatrix.h:682
Header file for the row trait.
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse submatrix.
Definition: SparseSubmatrix.h:1989
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
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubmatrix.h:665
PointerType pointer
Pointer return type.
Definition: SparseSubmatrix.h:674
Base template for the SubmatrixTrait class.
Definition: SubmatrixTrait.h:118
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubmatrix.h:676
const size_t m_
The number of rows of the submatrix.
Definition: SparseSubmatrix.h:1010
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
Header file for the IsDiagonal type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
SparseSubmatrix< MT, AF, SO > MatrixType
Type of the matrix.
Definition: Matrix.h:84
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional matrix type...
Definition: DenseMatrix.h:79
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SparseSubmatrix.h:499
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:946
SparseSubmatrix< MT, AF, SO > This
Type of this SparseSubmatrix instance.
Definition: SparseSubmatrix.h:497
SubmatrixElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:588
bool isSymmetric(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is symmetric.
Definition: DenseMatrix.h:692
Reference operator()(size_t i, size_t j)
2D-access to the sparse submatrix elements.
Definition: SparseSubmatrix.h:1117
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
SubmatrixIterator(const SubmatrixIterator< MatrixType2, IteratorType2 > &it)
Conversion constructor from different SubmatrixIterator instances.
Definition: SparseSubmatrix.h:706
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2665
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
void addAssign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a dense matrix.
Definition: SparseSubmatrix.h:3334
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
void reset()
Reset to the default initial values.
Definition: SparseSubmatrix.h:1802
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:103
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBMATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a submatrix type (i.e. a dense or sparse submatrix), a compilation error is created.
Definition: Submatrix.h:118
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:90
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:118
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:259
CRT ConstReference
Reference-to-const return type.
Definition: SparseSubmatrix.h:543
SubmatrixElement & operator+=(const T &v)
Addition assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:576
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
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
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:90
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i...
Definition: TransExpr.h:118
Header file for the RequiresEvaluation type trait.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubmatrix.h:502
const size_t column_
The first column of the submatrix.
Definition: SparseSubmatrix.h:1009
Iterator find(size_t i, size_t j)
Searches for a specific submatrix element.
Definition: SparseSubmatrix.h:2883
bool operator==(const SubmatrixIterator< MatrixType2, IteratorType2 > &rhs) const
Equality comparison between two SubmatrixIterator objects.
Definition: SparseSubmatrix.h:762
Header file for the IsUniLower type trait.
Base class for all submatrices.The Submatrix class serves as a tag for all submatrices (i...
Definition: Submatrix.h:64
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 dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: SparseSubmatrix.h:1244
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubmatrix.h:672
std::iterator_traits< IteratorType >::value_type SET
Type of the underlying sparse elements.
Definition: SparseSubmatrix.h:532
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
size_t capacity() const
Returns the maximum capacity of the sparse submatrix.
Definition: SparseSubmatrix.h:1723
Compile time check for data types with restricted data access.This type trait tests whether the given...
Definition: IsRestricted.h:82
Header file for the SparseMatrix base class.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse submatrix.
Definition: SparseSubmatrix.h:1760
const size_t n_
The number of columns of the submatrix.
Definition: SparseSubmatrix.h:1011
size_t offset_
Offset within the according row/column of the sparse matrix.
Definition: SparseSubmatrix.h:651
Constraint on the data type.
Header file for the matrix storage order types.
Constraint on the data type.
MT::ConstReference ConstReference
Reference to a constant submatrix value.
Definition: SparseSubmatrix.h:506
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:85
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SparseSubmatrix.h:1298
size_t rows() const
Returns the number of rows of the sparse submatrix.
Definition: SparseSubmatrix.h:1693
bool hasOverlap() const
Checking whether there exists an overlap in the context of a symmetric matrix.
Definition: SparseSubmatrix.h:2151
Header file for the DisableIf class template.
IteratorType base() const
Access to the current position of the submatrix iterator.
Definition: SparseSubmatrix.h:795
IfTrue< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant submatrix value.
Definition: SparseSubmatrix.h:509
Reference value() const
Access to the current value of the sparse submatrix element.
Definition: SparseSubmatrix.h:633
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Operand matrix_
The sparse matrix containing the submatrix.
Definition: SparseSubmatrix.h:1007
const size_t row_
The first row of the submatrix.
Definition: SparseSubmatrix.h:1008
Header file for the IsSymmetric type trait.
size_t offset_
The offset of the according row/column of the sparse matrix.
Definition: SparseSubmatrix.h:813
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
IfTrue< useConst, ConstIterator, SubmatrixIterator< MT, typename MT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: SparseSubmatrix.h:823
Header file for the If class template.
Constraint on the data type.
Header file for the IsFloatingPoint type trait.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: StorageOrder.h:161
SparseSubmatrix & operator=(const SparseSubmatrix &rhs)
Copy assignment operator for SparseSubmatrix.
Definition: SparseSubmatrix.h:1336
IteratorType pos_
Iterator to the current position within the sparse submatrix.
Definition: SparseSubmatrix.h:650
void append(size_t i, size_t j, const ElementType &value, bool check=false)
Appending an element to the specified row/column of the sparse submatrix.
Definition: SparseSubmatrix.h:3089
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Header file for the Or class template.
SubmatrixElement< MatrixType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubmatrix.h:666
Constraint on the data type.
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
SubmatrixTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubmatrix.h:498
Access proxy for a specific element of the sparse submatrix.
Definition: SparseSubmatrix.h:517
IndexType index() const
Access to the current index of the sparse element.
Definition: SparseSubmatrix.h:643
bool isAliased(const Other *alias) const
Returns whether the submatrix is aliased with the given address alias.
Definition: SparseSubmatrix.h:3167
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: SparseSubmatrix.h:1163
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubmatrix.h:2997
Header file for the IsLower type trait.
Iterator set(size_t i, size_t j, const ElementType &value)
Setting an element of the sparse submatrix.
Definition: SparseSubmatrix.h:1875
Header file for the SparseElement base class.
void erase(size_t i, size_t j)
Erasing an element from the sparse submatrix.
Definition: SparseSubmatrix.h:1918
Constraint on the data type.
DifferenceType operator-(const SubmatrixIterator &rhs) const
Calculating the number of elements between two submatrix iterators.
Definition: SparseSubmatrix.h:785
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1197
Constraints on the storage order of matrix types.
ValueType PointerType
Pointer return type.
Definition: SparseSubmatrix.h:667
Iterator insert(size_t i, size_t j, const ElementType &value)
Inserting an element into the sparse submatrix.
Definition: SparseSubmatrix.h:1899
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
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
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 EnableIf class template.
Header file for the IsStrictlyLower type trait.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
ReferenceType operator*() const
Direct access to the current sparse submatrix element.
Definition: SparseSubmatrix.h:740
Header file for the IsAdaptor type trait.
Header file for the serial shim.
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 DerestrictTrait class template.
bool canSMPAssign() const
Returns whether the submatrix can be used in SMP assignments.
Definition: SparseSubmatrix.h:3187
const bool unaligned
Alignment flag for unaligned subvectors and submatrices.
Definition: AlignmentFlag.h:63
Constraint on the data type.
Header file for the IsNumeric type trait.
SET::ConstReference CRT
Reference-to-const type of the underlying sparse element.
Definition: SparseSubmatrix.h:535
PointerType operator->() const
Direct access to the current sparse submatrix element.
Definition: SparseSubmatrix.h:750
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:103
const SubmatrixElement * operator->() const
Direct access to the sparse submatrix element at the current iterator position.
Definition: SparseSubmatrix.h:623
const SubmatrixIterator operator++(int)
Post-increment operator.
Definition: SparseSubmatrix.h:728
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
Header file for the SubmatrixExprTrait class template.
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Header file for the IsConst type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:150
SubmatrixIterator & operator++()
Pre-increment operator.
Definition: SparseSubmatrix.h:717
Base template for the MultTrait class.
Definition: MultTrait.h:150
Header file for the addition trait.
Header file for the division trait.
Header file for the submatrix trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESTRICTED(T)
Constraint on the data type.In case the given data type T does have a restricted data access...
Definition: Restricted.h:118
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
SubmatrixElement & operator/=(const T &v)
Division assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:612
View on a specific submatrix of a sparse matrix.The SparseSubmatrix template represents a view on a s...
Definition: Forward.h:53
Compile time type negation.The Not class template negates the given compile time condition. In case the given condition would evaluate to true, the nested member enumeration is set to false and vice versa:
Definition: Not.h:70
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
void assign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a dense matrix.
Definition: SparseSubmatrix.h:3210
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
Header file for the column trait.
Header file for the isDefault shim.
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:87
Constraint on the data type.
Constraint on the data type.
SparseSubmatrix & transpose()
Transposing the submatrix.
Definition: SparseSubmatrix.h:2087
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
#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
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
Header file for the IsReference type trait.
Iterator over the elements of the sparse submatrix.
Definition: SparseSubmatrix.h:661
Header file for the RemoveReference type trait.
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type set(T value)
Sets all values in the vector to the given 2-byte integral value.
Definition: Set.h:73
SubmatrixIterator< const MT, typename MT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubmatrix.h:820
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubmatrix.h:669
Base template for the DivTrait class.
Definition: DivTrait.h:150
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2666
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubmatrix.h:500
SubmatrixExprTrait< MT, unaligned >::Type submatrix(Matrix< MT, SO > &matrix, size_t row, size_t column, size_t m, size_t n)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:143
SubmatrixElement & operator=(const T &v)
Assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:564
void subAssign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: SparseSubmatrix.h:3404
SET::ValueType ValueType
The value type of the row element.
Definition: SparseSubmatrix.h:540
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:937
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
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:260
size_t IndexType
The index type of the row element.
Definition: SparseSubmatrix.h:541
ValueType ReferenceType
Reference return type.
Definition: SparseSubmatrix.h:668
const SparseSubmatrix & CompositeType
Data type for composite expression templates.
Definition: SparseSubmatrix.h:503
ReferenceType reference
Reference return type.
Definition: SparseSubmatrix.h:675
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
SubmatrixIterator(IteratorType iterator, size_t index)
Constructor for the SubmatrixIterator class.
Definition: SparseSubmatrix.h:694
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: SparseSubmatrix.h:3117
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
SET::Reference RT
Reference type of the underlying sparse element.
Definition: SparseSubmatrix.h:534
Compile time type check.This class tests whether the given template parameter T is a reference type (...
Definition: IsReference.h:94
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
Base template for the SubTrait class.
Definition: SubTrait.h:150
Header file for the Submatrix base class.
#define BLAZE_CONSTRAINT_MUST_BE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a N-dimensional matrix type...
Definition: Matrix.h:79
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
IfTrue< returnConst, CRT, RT >::Type Reference
Reference return type.
Definition: SparseSubmatrix.h:542
If< IsExpression< MT >, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseSubmatrix.h:481
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubmatrix.h:812
EnableIf< IsNumeric< Type >, bool >::Type isOne(const Type &v)
Returns whether the given value/object represents the numeric value 1.
Definition: IsOne.h:80
Header file for the IsRestricted type trait.
#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
size_t offset() const
Access to the offset of the submatrix iterator.
Definition: SparseSubmatrix.h:805
SubmatrixElement(IteratorType pos, size_t offset)
Constructor for the SubmatrixElement class.
Definition: SparseSubmatrix.h:552
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
SparseSubmatrix(Operand matrix, size_t row, size_t column, size_t m, size_t n)
The constructor for SparseSubmatrix.
Definition: SparseSubmatrix.h:1085
Compile time type selection.The IfTrue class template selects one of the two given types T1 and T2 de...
Definition: If.h:59
Header file for the IsExpression type trait class.
Constraint on the data type.
Header file for the FunctionTrace class.
bool canAlias(const Other *alias) const
Returns whether the submatrix can alias with the given address alias.
Definition: SparseSubmatrix.h:3146
void trim()
Removing all excessive capacity from all rows/columns.
Definition: SparseSubmatrix.h:2043
bool operator!=(const SubmatrixIterator< MatrixType2, IteratorType2 > &rhs) const
Inequality comparison between two SubmatrixIterator objects.
Definition: SparseSubmatrix.h:774