35 #ifndef _BLAZE_MATH_VIEWS_SPARSESUBMATRIX_H_
36 #define _BLAZE_MATH_VIEWS_SPARSESUBMATRIX_H_
377 template<
typename MT
379 ,
bool SO = IsColumnMajorMatrix<MT>::value >
380 class SparseSubmatrix :
public SparseMatrix< SparseSubmatrix<MT,AF,SO>, SO >
421 ,
typename IteratorType >
529 return pos_->value();
555 ,
typename IteratorType >
600 template<
typename MatrixType2,
typename IteratorType2 >
656 template<
typename MatrixType2,
typename IteratorType2 >
668 template<
typename MatrixType2,
typename IteratorType2 >
670 return !( *
this == rhs );
690 inline IteratorType
base()
const {
723 enum { smpAssignable = 0 };
762 template<
typename Other >
764 operator*=( Other rhs );
766 template<
typename Other >
768 operator/=( Other rhs );
775 inline size_t rows()
const;
778 inline size_t capacity(
size_t i )
const;
780 inline size_t nonZeros(
size_t i )
const;
782 inline void reset(
size_t i );
784 inline void erase(
size_t i,
size_t j );
787 inline void reserve(
size_t nonzeros );
788 void reserve(
size_t i,
size_t nonzeros );
790 inline void trim(
size_t i );
791 template<
typename Other >
inline SparseSubmatrix& scale( Other scalar );
810 inline void append (
size_t i,
size_t j,
const ElementType& value,
bool check=
false );
818 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
819 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
844 template<
bool AF1,
typename MT2,
bool AF2,
bool SO2 >
884 template<
typename MT
894 if( ( row + m > matrix.rows() ) || ( column + n > matrix.columns() ) )
895 throw std::invalid_argument(
"Invalid submatrix specification" );
915 template<
typename MT
924 return matrix_(row_+i,column_+j);
936 template<
typename MT
945 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
961 template<
typename MT
970 return Iterator( matrix_.begin( i + row_ ), column_ );
972 return Iterator( matrix_.lowerBound( i + row_, column_ ), column_ );
988 template<
typename MT
999 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
1015 template<
typename MT
1023 if( column_ == 0UL )
1024 return ConstIterator( matrix_.cbegin( i + row_ ), column_ );
1026 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
1042 template<
typename MT
1050 if( matrix_.columns() == column_ +
n_ )
1051 return Iterator( matrix_.end( i + row_ ), column_ );
1053 return Iterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1069 template<
typename MT
1077 if( matrix_.columns() == column_ +
n_ )
1080 return ConstIterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1096 template<
typename MT
1104 if( matrix_.columns() == column_ +
n_ )
1107 return ConstIterator( matrix_.lowerBound( i + row_, column_ +
n_ ), column_ );
1131 template<
typename MT
1142 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
1145 if(
rows() != rhs.rows() ||
columns() != rhs.columns() )
1146 throw std::invalid_argument(
"Submatrix sizes do not match" );
1148 if( rhs.canAlias( &matrix_ ) ) {
1173 template<
typename MT
1176 template<
typename MT2
1187 throw std::invalid_argument(
"Matrix sizes do not match" );
1214 template<
typename MT
1217 template<
typename MT2
1228 throw std::invalid_argument(
"Matrix sizes do not match" );
1255 template<
typename MT
1258 template<
typename MT2
1266 throw std::invalid_argument(
"Matrix sizes do not match" );
1285 template<
typename MT
1288 template<
typename MT2
1296 throw std::invalid_argument(
"Matrix sizes do not match" );
1315 template<
typename MT
1318 template<
typename MT2
1324 throw std::invalid_argument(
"Matrix sizes do not match" );
1332 const MultType tmp( *
this * (~rhs) );
1348 template<
typename MT
1351 template<
typename Other >
1355 for(
size_t i=0UL; i<
rows(); ++i ) {
1357 for(
Iterator element=begin(i); element!=last; ++element )
1358 element->value() *= rhs;
1373 template<
typename MT
1376 template<
typename Other >
1388 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1389 for(
size_t i=0UL; i<
rows(); ++i ) {
1391 for(
Iterator element=begin(i); element!=last; ++element )
1392 element->value() *= tmp;
1396 for(
size_t i=0UL; i<
rows(); ++i ) {
1398 for(
Iterator element=begin(i); element!=last; ++element )
1399 element->value() /= rhs;
1421 template<
typename MT
1436 template<
typename MT
1451 template<
typename MT
1456 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1472 template<
typename MT
1478 return nonZeros( i ) + matrix_.capacity( row_+i ) - matrix_.nonZeros( row_+i );
1488 template<
typename MT
1493 size_t nonzeros( 0UL );
1495 for(
size_t i=0UL; i<
rows(); ++i )
1496 nonzeros += nonZeros( i );
1514 template<
typename MT
1520 return end(i) - begin(i);
1530 template<
typename MT
1535 for(
size_t i=row_; i<row_+
m_; ++i ) {
1536 matrix_.erase( i, matrix_.lowerBound( i, column_ ), matrix_.lowerBound( i, column_+
n_ ) );
1553 template<
typename MT
1559 const size_t index( row_ + i );
1560 matrix_.erase( index, matrix_.lowerBound( index, column_ ), matrix_.lowerBound( index, column_+
n_ ) );
1578 template<
typename MT
1584 return Iterator( matrix_.insert( row_+i, column_+j, value ), column_ );
1598 template<
typename MT
1606 matrix_.erase( row_ + i, column_ + j );
1622 template<
typename MT
1629 return Iterator( matrix_.erase( row_+i, pos.base() ), column_ );
1647 template<
typename MT
1654 return Iterator( matrix_.erase( row_+i, first.base(), last.base() ), column_ );
1669 template<
typename MT
1674 const size_t current( capacity() );
1676 if( nonzeros > current ) {
1677 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1698 template<
typename MT
1703 const size_t current( capacity( i ) );
1704 const size_t index ( row_ + i );
1706 if( nonzeros > current ) {
1707 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1723 template<
typename MT
1728 for(
size_t i=0UL; i<
rows(); ++i )
1745 template<
typename MT
1751 matrix_.trim( row_ + i );
1762 template<
typename MT
1765 template<
typename Other >
1768 for(
size_t i=0UL; i<
rows(); ++i ) {
1770 for(
Iterator element=begin(i); element!=last; ++element )
1771 element->value() *= scalar;
1802 template<
typename MT
1808 const typename MT::Iterator pos( matrix_.find( row_ + i, column_ + j ) );
1810 if( pos != matrix_.end( row_ + i ) )
1833 template<
typename MT
1841 if( pos != matrix_.end( row_ + i ) )
1864 template<
typename MT
1870 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
1890 template<
typename MT
1896 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
1916 template<
typename MT
1922 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
1942 template<
typename MT
1948 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
2008 template<
typename MT
2013 if( column_ +
n_ == matrix_.columns() ) {
2014 matrix_.append( row_ + i, column_ + j, value, check );
2016 else if( !check || !
isDefault( value ) ) {
2017 matrix_.insert( row_ + i, column_ + j, value );
2036 template<
typename MT
2041 matrix_.trim( row_ + i );
2064 template<
typename MT
2067 template<
typename Other >
2070 return static_cast<const void*
>( &matrix_ ) == static_cast<const void*>( alias );
2085 template<
typename MT
2088 template<
typename Other >
2091 return static_cast<const void*
>( &matrix_ ) == static_cast<const void*>( alias );
2107 template<
typename MT
2110 template<
typename MT2
2119 for(
size_t i=0UL; i<
rows(); ++i ) {
2120 for(
size_t j=0UL; j<
columns(); ++j ) {
2121 append( i, j, (~rhs)(i,j),
true );
2140 template<
typename MT
2143 template<
typename MT2 >
2149 reserve( 0UL, (~rhs).nonZeros() );
2151 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2152 for(
typename MT2::ConstIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element ) {
2153 append( i, element->index(), element->value(), true );
2172 template<
typename MT
2175 template<
typename MT2 >
2184 std::vector<size_t> rowLengths(
m_, 0UL );
2185 for(
size_t j=0UL; j<
n_; ++j ) {
2186 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2187 ++rowLengths[element->index()];
2191 for(
size_t i=0UL; i<
m_; ++i ) {
2192 reserve( i, rowLengths[i] );
2196 for(
size_t j=0UL; j<
n_; ++j ) {
2197 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2198 append( element->index(), j, element->value() );
2215 template<
typename MT
2218 template<
typename MT2
2230 const AddType tmp( *
this + (~rhs) );
2248 template<
typename MT
2251 template<
typename MT2
2263 const AddType tmp( *
this + (~rhs) );
2281 template<
typename MT
2284 template<
typename MT2
2296 const SubType tmp( *
this - (~rhs) );
2314 template<
typename MT
2317 template<
typename MT2
2329 const SubType tmp( *
this - (~rhs) );
2356 template<
typename MT
2380 typedef SparseSubmatrix<MT,AF,true>
This;
2381 typedef typename SubmatrixTrait<MT>::Type
ResultType;
2392 typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type
Reference;
2399 ,
typename IteratorType >
2400 class SubmatrixElement :
private SparseElement
2410 enum { returnConst = IsConst<MatrixType>::value };
2415 typedef typename SelectType< returnConst, const ElementType&, ElementType& >::Type
ReferenceType;
2506 return pos_->value();
2515 inline size_t index()
const {
2532 ,
typename IteratorType >
2533 class SubmatrixIterator
2538 typedef SubmatrixElement<MatrixType,IteratorType>
ValueType;
2577 template<
typename MatrixType2,
typename IteratorType2 >
2578 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2633 template<
typename MatrixType2,
typename IteratorType2 >
2634 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2635 return base() == rhs.base();
2645 template<
typename MatrixType2,
typename IteratorType2 >
2646 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2647 return !( *
this == rhs );
2658 return pos_ - rhs.pos_;
2667 inline IteratorType
base()
const {
2677 inline size_t offset()
const {
2692 typedef SubmatrixIterator<const MT,typename MT::ConstIterator>
ConstIterator;
2695 typedef typename SelectType< useConst, ConstIterator, SubmatrixIterator<MT,typename MT::Iterator> >::Type
Iterator;
2700 enum { smpAssignable = 0 };
2735 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator+=(
const Matrix<MT2,SO>& rhs );
2736 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator-=(
const Matrix<MT2,SO>& rhs );
2737 template<
typename MT2,
bool SO >
inline SparseSubmatrix& operator*=(
const Matrix<MT2,SO>& rhs );
2739 template<
typename Other >
2741 operator*=( Other rhs );
2743 template<
typename Other >
2745 operator/=( Other rhs );
2752 inline size_t rows()
const;
2753 inline size_t columns()
const;
2755 inline size_t capacity(
size_t i )
const;
2757 inline size_t nonZeros(
size_t i )
const;
2758 inline void reset();
2759 inline void reset(
size_t i );
2761 inline void erase(
size_t i,
size_t j );
2764 inline void reserve(
size_t nonzeros );
2765 void reserve(
size_t i,
size_t nonzeros );
2767 inline void trim(
size_t j );
2768 template<
typename Other >
inline SparseSubmatrix& scale( Other scalar );
2787 inline void append (
size_t i,
size_t j,
const ElementType& value,
bool check=
false );
2795 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2796 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2797 template<
typename MT2,
bool SO >
inline void assign (
const DenseMatrix<MT2,SO>& rhs );
2798 template<
typename MT2 >
inline void assign (
const SparseMatrix<MT2,false>& rhs );
2799 template<
typename MT2 >
inline void assign (
const SparseMatrix<MT2,true>& rhs );
2800 template<
typename MT2,
bool SO >
inline void addAssign(
const DenseMatrix<MT2,SO>& rhs );
2801 template<
typename MT2,
bool SO >
inline void addAssign(
const SparseMatrix<MT2,SO>& rhs );
2802 template<
typename MT2,
bool SO >
inline void subAssign(
const DenseMatrix<MT2,SO>& rhs );
2803 template<
typename MT2,
bool SO >
inline void subAssign(
const SparseMatrix<MT2,SO>& rhs );
2820 template<
bool AF1,
typename MT2,
bool AF2,
bool SO2 >
2821 friend const SparseSubmatrix<MT2,AF1,SO2>
2822 submatrix(
const SparseSubmatrix<MT2,AF2,SO2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
2859 template<
typename MT
2868 if( ( row + m > matrix.rows() ) || ( column + n > matrix.columns() ) )
2869 throw std::invalid_argument(
"Invalid submatrix specification" );
2891 template<
typename MT
2899 return matrix_(row_+i,column_+j);
2913 template<
typename MT
2921 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
2934 template<
typename MT
2942 return Iterator( matrix_.begin( j + column_ ), row_ );
2944 return Iterator( matrix_.lowerBound( row_, j + column_ ), row_ );
2957 template<
typename MT
2965 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
2967 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
2980 template<
typename MT
2988 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
2990 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3003 template<
typename MT
3010 if( matrix_.rows() == row_ +
m_ )
3011 return Iterator( matrix_.end( j + column_ ), row_ );
3013 return Iterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
3026 template<
typename MT
3033 if( matrix_.rows() == row_ +
m_ )
3036 return ConstIterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
3049 template<
typename MT
3056 if( matrix_.rows() == row_ +
m_ )
3059 return ConstIterator( matrix_.lowerBound( row_ +
m_, j + column_ ), row_ );
3085 template<
typename MT
3087 inline SparseSubmatrix<MT,AF,true>&
3095 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
3098 if(
rows() != rhs.rows() ||
columns() != rhs.columns() )
3099 throw std::invalid_argument(
"Submatrix sizes do not match" );
3101 if( rhs.canAlias( &matrix_ ) ) {
3128 template<
typename MT
3130 template<
typename MT2
3132 inline SparseSubmatrix<MT,AF,true>&
3140 throw std::invalid_argument(
"Matrix sizes do not match" );
3142 if( RequiresEvaluation<MT2>::value || (~rhs).canAlias( &matrix_ ) ) {
3169 template<
typename MT
3171 template<
typename MT2
3173 inline SparseSubmatrix<MT,AF,true>&
3182 throw std::invalid_argument(
"Matrix sizes do not match" );
3184 if( RequiresEvaluation<MT2>::value || (~rhs).canAlias( &matrix_ ) ) {
3211 template<
typename MT
3213 template<
typename MT2
3215 inline SparseSubmatrix<MT,AF,true>&
3216 SparseSubmatrix<MT,AF,true>::operator+=(
const Matrix<MT2,SO>& rhs )
3221 throw std::invalid_argument(
"Matrix sizes do not match" );
3242 template<
typename MT
3244 template<
typename MT2
3246 inline SparseSubmatrix<MT,AF,true>&
3247 SparseSubmatrix<MT,AF,true>::operator-=(
const Matrix<MT2,SO>& rhs )
3252 throw std::invalid_argument(
"Matrix sizes do not match" );
3273 template<
typename MT
3275 template<
typename MT2
3277 inline SparseSubmatrix<MT,AF,true>&
3278 SparseSubmatrix<MT,AF,true>::operator*=(
const Matrix<MT2,SO>& rhs )
3281 throw std::invalid_argument(
"Matrix sizes do not match" );
3283 typedef typename MultTrait<ResultType,typename MT2::ResultType>::Type MultType;
3289 const MultType tmp( *
this * (~rhs) );
3307 template<
typename MT
3309 template<
typename Other >
3310 inline typename EnableIf< IsNumeric<Other>, SparseSubmatrix<MT,AF,true> >::Type&
3311 SparseSubmatrix<MT,AF,true>::operator*=( Other rhs )
3313 for(
size_t i=0UL; i<
columns(); ++i ) {
3315 for(
Iterator element=begin(i); element!=last; ++element )
3316 element->value() *= rhs;
3333 template<
typename MT
3335 template<
typename Other >
3336 inline typename EnableIf< IsNumeric<Other>, SparseSubmatrix<MT,AF,true> >::Type&
3337 SparseSubmatrix<MT,AF,true>::operator/=( Other rhs )
3341 typedef typename DivTrait<ElementType,Other>::Type DT;
3342 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3346 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3347 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3348 for(
size_t i=0UL; i<
columns(); ++i ) {
3350 for(
Iterator element=begin(i); element!=last; ++element )
3351 element->value() *= tmp;
3355 for(
size_t i=0UL; i<
columns(); ++i ) {
3357 for(
Iterator element=begin(i); element!=last; ++element )
3358 element->value() /= rhs;
3382 template<
typename MT
3398 template<
typename MT
3414 template<
typename MT
3418 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
3431 template<
typename MT
3436 return nonZeros( j ) + matrix_.capacity( column_+j ) - matrix_.nonZeros( column_+j );
3448 template<
typename MT
3452 size_t nonzeros( 0UL );
3454 for(
size_t i=0UL; i<
columns(); ++i )
3455 nonzeros += nonZeros( i );
3470 template<
typename MT
3475 return end(j) - begin(j);
3487 template<
typename MT
3491 for(
size_t j=column_; j<column_+
n_; ++j ) {
3492 matrix_.erase( j, matrix_.lowerBound( row_, j ), matrix_.lowerBound( row_+
m_, j ) );
3506 template<
typename MT
3511 const size_t index( column_ + j );
3512 matrix_.erase( index, matrix_.lowerBound( row_, index ), matrix_.lowerBound( row_+
m_, index ) );
3532 template<
typename MT
3537 return Iterator( matrix_.insert( row_+i, column_+j, value ), row_ );
3553 template<
typename MT
3560 matrix_.erase( row_ + i, column_ + j );
3576 template<
typename MT
3582 return Iterator( matrix_.erase( column_+j, pos.base() ), row_ );
3599 template<
typename MT
3605 return Iterator( matrix_.erase( column_+j, first.base(), last.base() ), row_ );
3622 template<
typename MT
3626 const size_t current( capacity() );
3628 if( nonzeros > current ) {
3629 matrix_.reserve( matrix_.capacity() + nonzeros - current );
3648 template<
typename MT
3652 const size_t current( capacity( j ) );
3653 const size_t index ( column_ + j );
3655 if( nonzeros > current ) {
3656 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
3673 template<
typename MT
3677 for(
size_t j=0UL; j<
columns(); ++j )
3695 template<
typename MT
3700 matrix_.trim( column_ + j );
3713 template<
typename MT
3715 template<
typename Other >
3716 inline SparseSubmatrix<MT,AF,true>& SparseSubmatrix<MT,AF,true>::scale( Other scalar )
3718 for(
size_t i=0UL; i<
columns(); ++i ) {
3720 for(
Iterator element=begin(i); element!=last; ++element )
3721 element->value() *= scalar;
3754 template<
typename MT
3759 const typename MT::Iterator pos( matrix_.find( row_ + i, column_ + j ) );
3761 if( pos != matrix_.end( column_ + j ) )
3786 template<
typename MT
3793 if( pos != matrix_.end( column_ + j ) )
3818 template<
typename MT
3823 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
3845 template<
typename MT
3850 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
3872 template<
typename MT
3877 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
3899 template<
typename MT
3904 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
3966 template<
typename MT
3970 if( row_ +
m_ == matrix_.rows() ) {
3971 matrix_.append( row_ + i, column_ + j, value, check );
3973 else if( !check || !
isDefault( value ) ) {
3974 matrix_.insert( row_ + i, column_ + j, value );
3995 template<
typename MT
3999 matrix_.trim( column_ + j );
4024 template<
typename MT
4026 template<
typename Other >
4029 return static_cast<const void*
>( &matrix_ ) == static_cast<const void*>( alias );
4046 template<
typename MT
4048 template<
typename Other >
4051 return static_cast<const void*
>( &matrix_ ) == static_cast<const void*>( alias );
4069 template<
typename MT
4071 template<
typename MT2
4080 for(
size_t j=0UL; j<
columns(); ++j ) {
4081 for(
size_t i=0UL; i<
rows(); ++i ) {
4082 append( i, j, (~rhs)(i,j),
true );
4103 template<
typename MT
4105 template<
typename MT2 >
4114 std::vector<size_t> columnLengths( n_, 0UL );
4115 for(
size_t i=0UL; i<
m_; ++i ) {
4116 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4117 ++columnLengths[element->index()];
4121 for(
size_t j=0UL; j<
n_; ++j ) {
4122 reserve( j, columnLengths[j] );
4126 for(
size_t i=0UL; i<
m_; ++i ) {
4127 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4128 append( i, element->index(), element->value() );
4147 template<
typename MT
4149 template<
typename MT2 >
4155 reserve( 0UL, (~rhs).nonZeros() );
4157 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4158 for(
typename MT2::ConstIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element ) {
4159 append( element->index(), j, element->value(), true );
4180 template<
typename MT
4182 template<
typename MT2
4186 typedef typename AddTrait<ResultType,typename MT2::ResultType>::Type AddType;
4194 const AddType tmp( *
this + (~rhs) );
4214 template<
typename MT
4216 template<
typename MT2
4220 typedef typename AddTrait<ResultType,typename MT2::ResultType>::Type AddType;
4228 const AddType tmp( *
this + (~rhs) );
4248 template<
typename MT
4250 template<
typename MT2
4254 typedef typename SubTrait<ResultType,typename MT2::ResultType>::Type SubType;
4262 const SubType tmp( *
this - (~rhs) );
4282 template<
typename MT
4284 template<
typename MT2
4288 typedef typename SubTrait<ResultType,typename MT2::ResultType>::Type SubType;
4296 const SubType tmp( *
this - (~rhs) );
4319 template<
typename MT,
bool AF,
bool SO >
4320 inline void reset( SparseSubmatrix<MT,AF,SO>& sm );
4322 template<
typename MT,
bool AF,
bool SO >
4323 inline void clear( SparseSubmatrix<MT,AF,SO>& sm );
4325 template<
typename MT,
bool AF,
bool SO >
4326 inline bool isDefault(
const SparseSubmatrix<MT,AF,SO>& sm );
4338 template<
typename MT
4357 template<
typename MT
4385 template<
typename MT
4394 const size_t iend( ( SO ==
rowMajor)?( sm.rows() ):( sm.columns() ) );
4396 for(
size_t i=0UL; i<iend; ++i ) {
4397 for( ConstIterator element=sm.begin(i); element!=sm.end(i); ++element )
4398 if( !
isDefault( element->value() ) )
return false;
4433 inline const SparseSubmatrix<MT,AF1,SO>
4434 submatrix(
const SparseSubmatrix<MT,AF2,SO>& sm,
size_t row,
size_t column,
size_t m,
size_t n )
4438 if( ( row + m > sm.rows() ) || ( column + n > sm.columns() ) )
4439 throw std::invalid_argument(
"Invalid submatrix specification" );
4441 return SparseSubmatrix<MT,AF1,SO>( sm.matrix_, sm.row_ +
row, sm.column_ +
column, m, n );
4457 template<
typename MT,
bool AF,
bool SO >
4458 struct SubmatrixTrait< SparseSubmatrix<MT,AF,SO> >
4476 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
4477 struct SubmatrixExprTrait< SparseSubmatrix<MT,AF1,SO>, AF2 >
4479 typedef SparseSubmatrix<MT,AF2,SO> Type;
4487 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
4488 struct SubmatrixExprTrait< const SparseSubmatrix<MT,AF1,SO>, AF2 >
4490 typedef SparseSubmatrix<MT,AF2,SO> Type;
4498 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
4499 struct SubmatrixExprTrait< volatile SparseSubmatrix<MT,AF1,SO>, AF2 >
4501 typedef SparseSubmatrix<MT,AF2,SO> Type;
4509 template<
typename MT,
bool AF1,
bool SO,
bool AF2 >
4510 struct SubmatrixExprTrait< const volatile SparseSubmatrix<MT,AF1,SO>, AF2 >
4512 typedef SparseSubmatrix<MT,AF2,SO> Type;
4528 template<
typename MT,
bool AF,
bool SO >
4529 struct RowTrait< SparseSubmatrix<MT,AF,SO> >
4547 template<
typename MT,
bool AF,
bool SO >
4548 struct ColumnTrait< SparseSubmatrix<MT,AF,SO> >
MT MatrixType
Type of the matrix.
Definition: Matrix.h:71
const size_t m_
The number of rows of the submatrix.
Definition: SparseSubmatrix.h:837
Constraint on the data type.
Pointer difference type of the Blaze library.
SubmatrixIterator(const SubmatrixIterator< MatrixType2, IteratorType2 > &it)
Conversion constructor from different SubmatrixIterator instances.
Definition: SparseSubmatrix.h:601
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubmatrix.h:564
IteratorType pos_
Iterator to the current position within the sparse submatrix.
Definition: SparseSubmatrix.h:545
SparseSubmatrix< MT, AF, SO > This
Type of this SparseSubmatrix instance.
Definition: SparseSubmatrix.h:402
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
size_t columns() const
Returns the number of columns of the sparse submatrix.
Definition: SparseSubmatrix.h:1439
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#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:1868
Header file for the subvector/submatrix alignment flag values.
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:1019
Header file for the row trait.
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse submatrix.
Definition: SparseSubmatrix.h:1672
Base template for the SubmatrixTrait class.
Definition: SubmatrixTrait.h:117
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
SubmatrixTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubmatrix.h:403
ReferenceType value() const
Access to the current value of the sparse submatrix element.
Definition: SparseSubmatrix.h:528
#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
size_t offset() const
Access to the offset of the submatrix iterator.
Definition: SparseSubmatrix.h:700
#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
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubmatrix.h:707
Reference operator()(size_t i, size_t j)
2D-access to the sparse submatrix elements.
Definition: SparseSubmatrix.h:919
Header file for the IsColumnMajorMatrix type trait.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2528
SelectType< returnConst, const ElementType &, ElementType & >::Type ReferenceType
Return type of the value member function.
Definition: SparseSubmatrix.h:438
void addAssign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a dense matrix.
Definition: SparseSubmatrix.h:2220
void reset()
Reset to the default initial values.
Definition: SparseSubmatrix.h:1533
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
#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
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:247
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
#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.
Iterator find(size_t i, size_t j)
Searches for a specific submatrix element.
Definition: SparseSubmatrix.h:1806
ValueType value_type
Type of the underlying elements.
Definition: SparseSubmatrix.h:568
DifferenceType operator-(const SubmatrixIterator &rhs) const
Calculating the number of elements between two submatrix iterators.
Definition: SparseSubmatrix.h:680
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubmatrix.h:560
ReferenceType operator*() const
Direct access to the current sparse submatrix element.
Definition: SparseSubmatrix.h:635
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
size_t index() const
Access to the current index of the sparse element.
Definition: SparseSubmatrix.h:538
Base class for all submatrices.The Submatrix class serves as a tag for all submatrices (i...
Definition: Submatrix.h:64
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:104
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: SparseSubmatrix.h:1046
size_t capacity() const
Returns the maximum capacity of the sparse submatrix.
Definition: SparseSubmatrix.h:1454
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:1491
Constraint on the data type.
Header file for the matrix storage order types.
Constraint on the data type.
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
ValueType ReferenceType
Reference return type.
Definition: SparseSubmatrix.h:563
Operand matrix_
The sparse matrix containing the submatrix.
Definition: SparseSubmatrix.h:834
size_t offset_
Offset within the according row/column of the sparse matrix.
Definition: SparseSubmatrix.h:546
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: SparseSubmatrix.h:1100
size_t rows() const
Returns the number of rows of the sparse submatrix.
Definition: SparseSubmatrix.h:1424
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
SubmatrixElement< MatrixType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubmatrix.h:561
PointerType operator->() const
Direct access to the current sparse submatrix element.
Definition: SparseSubmatrix.h:645
Header file for the multiplication trait.
SubmatrixElement(IteratorType pos, size_t offset)
Constructor for the SubmatrixElement class.
Definition: SparseSubmatrix.h:447
Header file for the If class template.
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:1135
SubmatrixElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:483
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:2011
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
Header file for the Or class template.
Constraint on the data type.
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:179
Access proxy for a specific element of the sparse submatrix.
Definition: SparseSubmatrix.h:422
bool isAliased(const Other *alias) const
Returns whether the submatrix is aliased with the given address alias.
Definition: SparseSubmatrix.h:2089
SubmatrixIterator(IteratorType iterator, size_t index)
Constructor for the SubmatrixIterator class.
Definition: SparseSubmatrix.h:589
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: SparseSubmatrix.h:965
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubmatrix.h:1920
const size_t row_
The first row of the submatrix.
Definition: SparseSubmatrix.h:835
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:1601
Constraint on the data type.
Constraints on the storage order of matrix types.
MT::ConstReference ConstReference
Reference to a constant submatrix value.
Definition: SparseSubmatrix.h:411
Iterator insert(size_t i, size_t j, const ElementType &value)
Inserting an element into the sparse submatrix.
Definition: SparseSubmatrix.h:1582
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
SubmatrixElement & operator/=(const T &v)
Division assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:507
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
Constraint on the data type.
Header file for the SelectType class template.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2386
size_t offset_
The offset of the according row/column of the sparse matrix.
Definition: SparseSubmatrix.h:708
Header file for the EnableIf class template.
SubmatrixIterator & operator++()
Pre-increment operator.
Definition: SparseSubmatrix.h:612
SubmatrixIterator()
Default constructor for the SubmatrixIterator class.
Definition: SparseSubmatrix.h:577
const size_t n_
The number of columns of the submatrix.
Definition: SparseSubmatrix.h:838
SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant submatrix value.
Definition: SparseSubmatrix.h:414
const bool unaligned
Alignment flag for unaligned subvectors and submatrices.
Definition: AlignmentFlag.h:63
Header file for the IsNumeric type trait.
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
ValueType PointerType
Pointer return type.
Definition: SparseSubmatrix.h:562
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:2383
Header file for the IsConst type trait.
SelectType< IsExpression< MT >::value, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseSubmatrix.h:386
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
ResultType::OppositeType OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: SparseSubmatrix.h:404
Base template for the MultTrait class.
Definition: MultTrait.h:141
Header file for the addition trait.
Header file for the division trait.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
Header file for the submatrix trait.
const SubmatrixIterator operator++(int)
Post-increment operator.
Definition: SparseSubmatrix.h:623
bool operator==(const SubmatrixIterator< MatrixType2, IteratorType2 > &rhs) const
Equality comparison between two SubmatrixIterator objects.
Definition: SparseSubmatrix.h:657
bool operator!=(const SubmatrixIterator< MatrixType2, IteratorType2 > &rhs) const
Inequality comparison between two SubmatrixIterator objects.
Definition: SparseSubmatrix.h:669
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
View on a specific submatrix of a sparse matrix.The SparseSubmatrix template represents a view on a s...
Definition: Forward.h:53
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
void assign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a dense matrix.
Definition: SparseSubmatrix.h:2112
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2387
IteratorType base() const
Access to the current position of the submatrix iterator.
Definition: SparseSubmatrix.h:690
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:85
SelectType< useConst, ConstIterator, SubmatrixIterator< MT, typename MT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: SparseSubmatrix.h:718
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
SubmatrixElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:495
#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
Iterator over the elements of the sparse submatrix.
Definition: SparseSubmatrix.h:556
const size_t column_
The first column of the submatrix.
Definition: SparseSubmatrix.h:836
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
Base template for the DivTrait class.
Definition: DivTrait.h:141
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2529
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:134
MT::ElementType ElementType
Type of the submatrix elements.
Definition: SparseSubmatrix.h:406
ReferenceType reference
Reference return type.
Definition: SparseSubmatrix.h:570
void subAssign(const DenseMatrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: SparseSubmatrix.h:2286
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubmatrix.h:405
PointerType pointer
Pointer return type.
Definition: SparseSubmatrix.h:569
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:248
#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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2379
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: SparseSubmatrix.h:2039
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
Header file for basic type definitions.
const SubmatrixElement * operator->() const
Direct access to the sparse submatrix element at the current iterator position.
Definition: SparseSubmatrix.h:518
SubmatrixIterator< const MT, typename MT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubmatrix.h:715
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2385
Base template for the SubTrait class.
Definition: SubTrait.h:141
Header file for the Submatrix base class.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubmatrix.h:407
#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
SubmatrixElement & operator=(const T &v)
Assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:459
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
SubmatrixElement & operator+=(const T &v)
Addition assignment to the accessed sparse submatrix element.
Definition: SparseSubmatrix.h:471
#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
#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:887
const SparseSubmatrix & CompositeType
Data type for composite expression templates.
Definition: SparseSubmatrix.h:408
Header file for the IsExpression type trait class.
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubmatrix.h:567
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:2068
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubmatrix.h:571
void trim()
Removing all excessive capacity from all rows/columns.
Definition: SparseSubmatrix.h:1726