35 #ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_ 36 #define _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_ 112 template<
typename MT
114 class Submatrix<MT,AF,false,false>
115 :
public SparseMatrix< Submatrix<MT,AF,false,false>, false >
121 typedef If_< IsExpression<MT>, MT, MT& > Operand;
126 typedef Submatrix<MT,AF,false,false>
This;
127 typedef SparseMatrix<This,false>
BaseType;
145 template<
typename MatrixType
146 ,
typename IteratorType >
147 class SubmatrixElement :
private SparseElement
157 enum :
bool { returnConst = IsConst<MatrixType>::value };
162 typedef typename std::iterator_traits<IteratorType>::value_type SET;
164 typedef Reference_<SET> RT;
165 typedef ConstReference_<SET> CRT;
170 typedef ValueType_<SET> ValueType;
171 typedef size_t IndexType;
172 typedef IfTrue_<returnConst,CRT,RT>
Reference;
182 inline SubmatrixElement( IteratorType pos,
size_t offset )
194 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
206 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
218 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
230 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
242 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
253 inline const SubmatrixElement* operator->()
const {
263 inline Reference value()
const {
264 return pos_->value();
273 inline IndexType index()
const {
274 return pos_->index() - offset_;
289 template<
typename MatrixType
290 ,
typename IteratorType >
291 class SubmatrixIterator
295 typedef std::forward_iterator_tag IteratorCategory;
296 typedef SubmatrixElement<MatrixType,IteratorType> ValueType;
297 typedef ValueType PointerType;
298 typedef ValueType ReferenceType;
299 typedef ptrdiff_t DifferenceType;
302 typedef IteratorCategory iterator_category;
303 typedef ValueType value_type;
304 typedef PointerType pointer;
305 typedef ReferenceType reference;
306 typedef DifferenceType difference_type;
312 inline SubmatrixIterator()
324 inline SubmatrixIterator( IteratorType iterator,
size_t index )
335 template<
typename MatrixType2,
typename IteratorType2 >
336 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
338 , offset_( it.offset() )
347 inline SubmatrixIterator& operator++() {
358 inline const SubmatrixIterator operator++(
int ) {
359 const SubmatrixIterator tmp( *
this );
371 return ReferenceType( pos_, offset_ );
380 inline PointerType operator->()
const {
381 return PointerType( pos_, offset_ );
391 template<
typename MatrixType2,
typename IteratorType2 >
392 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
393 return base() == rhs.base();
403 template<
typename MatrixType2,
typename IteratorType2 >
404 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
405 return !( *
this == rhs );
415 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
416 return pos_ - rhs.pos_;
425 inline IteratorType base()
const {
435 inline size_t offset() const noexcept {
450 typedef SubmatrixIterator< const MT, ConstIterator_<MT> >
ConstIterator;
458 enum :
bool { smpAssignable = MT::smpAssignable };
464 explicit inline Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n );
476 inline Reference operator()(
size_t i,
size_t j );
477 inline ConstReference operator()(
size_t i,
size_t j )
const;
478 inline Reference at(
size_t i,
size_t j );
479 inline ConstReference at(
size_t i,
size_t j )
const;
480 inline Iterator
begin (
size_t i );
481 inline ConstIterator
begin (
size_t i )
const;
482 inline ConstIterator
cbegin(
size_t i )
const;
483 inline Iterator
end (
size_t i );
484 inline ConstIterator
end (
size_t i )
const;
485 inline ConstIterator
cend (
size_t i )
const;
492 inline Submatrix& operator=(
const Submatrix& rhs );
494 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
495 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
496 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
497 template<
typename MT2,
bool SO >
inline Submatrix&
operator*=(
const Matrix<MT2,SO>& rhs );
499 template<
typename Other >
500 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator*=( Other rhs );
502 template<
typename Other >
503 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator/=( Other rhs );
510 inline size_t row() const noexcept;
511 inline
size_t rows() const noexcept;
512 inline
size_t column() const noexcept;
513 inline
size_t columns() const noexcept;
514 inline
size_t capacity() const noexcept;
515 inline
size_t capacity(
size_t i ) const noexcept;
517 inline
size_t nonZeros(
size_t i ) const;
519 inline
void reset(
size_t i );
520 inline
void reserve(
size_t nonzeros );
521 void reserve(
size_t i,
size_t nonzeros );
523 inline
void trim(
size_t i );
530 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
531 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
532 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
533 inline
void finalize(
size_t i );
540 inline
void erase(
size_t i,
size_t j );
541 inline Iterator erase(
size_t i, Iterator pos );
542 inline Iterator erase(
size_t i, Iterator first, Iterator last );
544 template< typename Pred >
545 inline
void erase( Pred predicate );
547 template< typename Pred >
548 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
555 inline Iterator find (
size_t i,
size_t j );
556 inline ConstIterator find (
size_t i,
size_t j ) const;
557 inline Iterator lowerBound(
size_t i,
size_t j );
558 inline ConstIterator lowerBound(
size_t i,
size_t j ) const;
559 inline Iterator upperBound(
size_t i,
size_t j );
560 inline ConstIterator upperBound(
size_t i,
size_t j ) const;
570 template< typename Other > inline Submatrix& scale( const Other& scalar );
577 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
578 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
580 inline
bool canSMPAssign() const noexcept;
582 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
583 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
584 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
585 template< typename MT2,
bool SO > inline
void addAssign( const DenseMatrix<MT2,SO>& rhs );
586 template< typename MT2,
bool SO > inline
void addAssign( const SparseMatrix<MT2,SO>& rhs );
587 template< typename MT2,
bool SO > inline
void subAssign( const DenseMatrix<MT2,SO>& rhs );
588 template< typename MT2,
bool SO > inline
void subAssign( const SparseMatrix<MT2,SO>& rhs );
596 inline
bool hasOverlap() const noexcept;
605 const
size_t column_;
612 template<
bool AF1, typename MT2,
bool AF2,
bool SO2,
bool DF2 >
613 friend const Submatrix<MT2,AF1,SO2,DF2>
614 submatrix( const Submatrix<MT2,AF2,SO2,DF2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
616 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
617 friend
bool isIntact( const Submatrix<MT2,AF2,SO2,DF2>& sm ) noexcept;
619 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
620 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Matrix<MT2,SO2>& b ) noexcept;
622 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
623 friend
bool isSame( const Matrix<MT2,SO2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
625 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
626 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
628 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
629 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
630 size_t row,
size_t column );
632 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
633 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
634 size_t row,
size_t column );
636 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
637 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
638 size_t row,
size_t column );
640 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
641 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
642 size_t row,
size_t column );
644 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
645 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
646 size_t row,
size_t column );
648 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
649 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
650 size_t row,
size_t column );
652 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
653 friend
bool tryMultAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
654 size_t row,
size_t column );
656 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
657 friend
DerestrictTrait_< Submatrix<MT2,AF2,SO2,DF2> > derestrict( Submatrix<MT2,AF2,SO2,DF2>& sm );
696 template< typename MT
698 inline Submatrix<MT,AF,false,false>::Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n )
705 if( ( row_ + m_ > matrix_.rows() ) || ( column_ + n_ > matrix_.columns() ) ) {
732 template<
typename MT
735 Submatrix<MT,AF,false,false>::operator()(
size_t i,
size_t j )
740 return matrix_(row_+i,column_+j);
757 template<
typename MT
760 Submatrix<MT,AF,false,false>::operator()(
size_t i,
size_t j )
const 765 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
783 template<
typename MT
786 Submatrix<MT,AF,false,false>::at(
size_t i,
size_t j )
812 template<
typename MT
815 Submatrix<MT,AF,false,false>::at(
size_t i,
size_t j )
const 841 template<
typename MT
849 return Iterator( matrix_.begin( i + row_ ), column_ );
851 return Iterator( matrix_.lowerBound( i + row_, column_ ), column_ );
869 template<
typename MT
879 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
897 template<
typename MT
907 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
925 template<
typename MT
932 if( matrix_.columns() == column_ +
n_ )
933 return Iterator( matrix_.end( i + row_ ), column_ );
935 return Iterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
953 template<
typename MT
960 if( matrix_.columns() == column_ +
n_ )
963 return ConstIterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
981 template<
typename MT
988 if( matrix_.columns() == column_ +
n_ )
991 return ConstIterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
1020 template<
typename MT
1022 inline Submatrix<MT,AF,false,false>&
1023 Submatrix<MT,AF,false,false>::operator=(
const Submatrix& rhs )
1025 using blaze::assign;
1030 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
1033 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
1037 if( !tryAssign( matrix_, rhs, row_, column_ ) ) {
1041 DerestrictTrait_<This> left( derestrict( *
this ) );
1043 if( rhs.canAlias( &matrix_ ) ) {
1044 const ResultType tmp( rhs );
1046 assign( left, tmp );
1050 assign( left, rhs );
1076 template<
typename MT
1078 template<
typename MT2
1080 inline Submatrix<MT,AF,false,false>&
1081 Submatrix<MT,AF,false,false>::operator=(
const Matrix<MT2,SO>& rhs )
1083 using blaze::assign;
1091 typedef CompositeType_<MT2> Right;
1092 Right right( ~rhs );
1094 if( !tryAssign( matrix_, right, row_, column_ ) ) {
1098 DerestrictTrait_<This> left( derestrict( *
this ) );
1100 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
1101 const ResultType_<MT2> tmp( right );
1103 assign( left, tmp );
1107 assign( left, right );
1132 template<
typename MT
1134 template<
typename MT2
1136 inline Submatrix<MT,AF,false,false>&
1139 using blaze::assign;
1145 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
1153 const AddType tmp( *
this + (~rhs) );
1155 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1159 DerestrictTrait_<This> left( derestrict( *
this ) );
1162 assign( left, tmp );
1186 template<
typename MT
1188 template<
typename MT2
1190 inline Submatrix<MT,AF,false,false>&
1193 using blaze::assign;
1199 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
1207 const SubType tmp( *
this - (~rhs) );
1209 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1213 DerestrictTrait_<This> left( derestrict( *
this ) );
1216 assign( left, tmp );
1240 template<
typename MT
1242 template<
typename MT2
1244 inline Submatrix<MT,AF,false,false>&
1247 using blaze::assign;
1253 typedef MultTrait_< ResultType, ResultType_<MT2> > MultType;
1262 const MultType tmp( *
this * (~rhs) );
1264 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1268 DerestrictTrait_<This> left( derestrict( *
this ) );
1271 assign( left, tmp );
1296 template<
typename MT
1298 template<
typename Other >
1299 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,false,false> >&
1304 for(
size_t i=0UL; i<
rows(); ++i ) {
1305 const Iterator last(
end(i) );
1306 for( Iterator element=
begin(i); element!=last; ++element )
1307 element->value() *= rhs;
1334 template<
typename MT
1336 template<
typename Other >
1337 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,false,false> >&
1344 typedef DivTrait_<ElementType,Other> DT;
1345 typedef If_< IsNumeric<DT>, DT, Other > Tmp;
1349 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
1350 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1351 for(
size_t i=0UL; i<
rows(); ++i ) {
1352 const Iterator last(
end(i) );
1353 for( Iterator element=
begin(i); element!=last; ++element )
1354 element->value() *= tmp;
1358 for(
size_t i=0UL; i<
rows(); ++i ) {
1359 const Iterator last(
end(i) );
1360 for( Iterator element=
begin(i); element!=last; ++element )
1361 element->value() /= rhs;
1385 template<
typename MT
1401 template<
typename MT
1417 template<
typename MT
1433 template<
typename MT
1449 template<
typename MT
1453 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1471 template<
typename MT
1476 return nonZeros( i ) + matrix_.capacity( row_+i ) - matrix_.nonZeros( row_+i );
1488 template<
typename MT
1492 size_t nonzeros( 0UL );
1494 for(
size_t i=0UL; i<
rows(); ++i )
1515 template<
typename MT
1532 template<
typename MT
1536 for(
size_t i=row_; i<row_+
m_; ++i )
1538 const size_t jbegin( ( IsUpper<MT>::value )
1539 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
1540 ?(
max( i+1UL, column_ ) )
1541 :(
max( i, column_ ) ) )
1543 const size_t jend ( ( IsLower<MT>::value )
1544 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
1545 ?(
min( i, column_+n_ ) )
1546 :(
min( i+1UL, column_+n_ ) ) )
1549 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1568 template<
typename MT
1574 const size_t index( row_ + i );
1576 const size_t jbegin( ( IsUpper<MT>::value )
1577 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
1578 ?(
max( i+1UL, column_ ) )
1579 :(
max( i, column_ ) ) )
1581 const size_t jend ( ( IsLower<MT>::value )
1582 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
1583 ?(
min( i, column_+n_ ) )
1584 :(
min( i+1UL, column_+n_ ) ) )
1587 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1604 template<
typename MT
1606 inline void Submatrix<MT,AF,false,false>::reserve(
size_t nonzeros )
1608 const size_t current(
capacity() );
1610 if( nonzeros > current ) {
1611 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1634 template<
typename MT
1636 void Submatrix<MT,AF,false,false>::reserve(
size_t i,
size_t nonzeros )
1638 const size_t current(
capacity( i ) );
1639 const size_t index ( row_ + i );
1641 if( nonzeros > current ) {
1642 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1660 template<
typename MT
1662 void Submatrix<MT,AF,false,false>::trim()
1664 for(
size_t i=0UL; i<
rows(); ++i )
1683 template<
typename MT
1685 void Submatrix<MT,AF,false,false>::trim(
size_t i )
1688 matrix_.trim( row_ + i );
1704 template<
typename MT
1706 inline bool Submatrix<MT,AF,false,false>::hasOverlap() const noexcept
1708 BLAZE_INTERNAL_ASSERT( IsSymmetric<MT>::value || IsHermitian<MT>::value,
"Invalid matrix detected" );
1710 if( ( row_ + m_ <= column_ ) || ( column_ + n_ <= row_ ) )
1739 template<
typename MT
1744 return Iterator( matrix_.set( row_+i, column_+j, value ), column_ );
1764 template<
typename MT
1767 Submatrix<MT,AF,false,false>::insert(
size_t i,
size_t j,
const ElementType& value )
1769 return Iterator( matrix_.insert( row_+i, column_+j, value ), column_ );
1824 template<
typename MT
1826 inline void Submatrix<MT,AF,false,false>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
1828 if( column_ + n_ == matrix_.columns() ) {
1829 matrix_.append( row_ + i, column_ + j, value, check );
1831 else if( !check || !
isDefault( value ) ) {
1832 matrix_.insert( row_ + i, column_ + j, value );
1853 template<
typename MT
1855 inline void Submatrix<MT,AF,false,false>::finalize(
size_t i )
1857 matrix_.trim( row_ + i );
1881 template<
typename MT
1883 inline void Submatrix<MT,AF,false,false>::erase(
size_t i,
size_t j )
1888 matrix_.erase( row_ + i, column_ + j );
1906 template<
typename MT
1909 Submatrix<MT,AF,false,false>::erase(
size_t i, Iterator pos )
1912 return Iterator( matrix_.erase( row_+i, pos.base() ), column_ );
1932 template<
typename MT
1935 Submatrix<MT,AF,false,false>::erase(
size_t i, Iterator first, Iterator last )
1938 return Iterator( matrix_.erase( row_+i, first.base(), last.base() ), column_ );
1967 template<
typename MT
1969 template<
typename Pred >
1970 inline void Submatrix<MT,AF,false,false>::erase( Pred predicate )
1972 for(
size_t i=0UL; i<
rows(); ++i ) {
1973 matrix_.erase( row_+i,
begin(i).base(),
end(i).base(), predicate );
2009 template<
typename MT
2011 template<
typename Pred >
2012 inline void Submatrix<MT,AF,false,false>::erase(
size_t i, Iterator first, Iterator last, Pred predicate )
2015 matrix_.erase( row_+i, first.base(), last.base(), predicate );
2045 template<
typename MT
2048 Submatrix<MT,AF,false,false>::find(
size_t i,
size_t j )
2050 const Iterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
2052 if( pos != matrix_.end( row_ + i ) )
2077 template<
typename MT
2080 Submatrix<MT,AF,false,false>::find(
size_t i,
size_t j )
const 2082 const ConstIterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
2084 if( pos != matrix_.end( row_ + i ) )
2109 template<
typename MT
2112 Submatrix<MT,AF,false,false>::lowerBound(
size_t i,
size_t j )
2114 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2136 template<
typename MT
2139 Submatrix<MT,AF,false,false>::lowerBound(
size_t i,
size_t j )
const 2141 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2163 template<
typename MT
2166 Submatrix<MT,AF,false,false>::upperBound(
size_t i,
size_t j )
2168 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
2190 template<
typename MT
2193 Submatrix<MT,AF,false,false>::upperBound(
size_t i,
size_t j )
const 2195 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
2227 template<
typename MT
2231 using blaze::assign;
2237 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
2241 DerestrictTrait_<This> left( derestrict( *
this ) );
2242 const ResultType tmp(
trans( *
this ) );
2244 assign( left, tmp );
2270 template<
typename MT
2274 using blaze::assign;
2280 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
2284 DerestrictTrait_<This> left( derestrict( *
this ) );
2285 const ResultType tmp(
ctrans( *
this ) );
2287 assign( left, tmp );
2306 template<
typename MT
2308 template<
typename Other >
2309 inline Submatrix<MT,AF,false,false>& Submatrix<MT,AF,false,false>::scale(
const Other& scalar )
2313 for(
size_t i=0UL; i<
rows(); ++i ) {
2314 const Iterator last(
end(i) );
2315 for( Iterator element=
begin(i); element!=last; ++element )
2316 element->value() *= scalar;
2344 template<
typename MT
2346 template<
typename Other >
2347 inline bool Submatrix<MT,AF,false,false>::canAlias(
const Other* alias )
const noexcept
2349 return matrix_.isAliased( alias );
2366 template<
typename MT
2368 template<
typename Other >
2369 inline bool Submatrix<MT,AF,false,false>::isAliased(
const Other* alias )
const noexcept
2371 return matrix_.isAliased( alias );
2388 template<
typename MT
2390 inline bool Submatrix<MT,AF,false,false>::canSMPAssign() const noexcept
2410 template<
typename MT
2412 template<
typename MT2
2414 inline void Submatrix<MT,AF,false,false>::assign(
const DenseMatrix<MT2,SO>& rhs )
2421 for(
size_t i=0UL; i<
rows(); ++i ) {
2422 for(
size_t j=0UL; j<
columns(); ++j ) {
2423 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
2424 const ElementType& value( (~rhs)(i,j) );
2425 if( !isDefault<strict>( value ) )
2429 append( i, j, (~rhs)(i,j),
true );
2451 template<
typename MT
2453 template<
typename MT2 >
2454 inline void Submatrix<MT,AF,false,false>::assign(
const SparseMatrix<MT2,false>& rhs )
2461 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2462 for( ConstIterator_<MT2> element=(~rhs).begin(i); element!=(~rhs).
end(i); ++element ) {
2463 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
2464 const ElementType& value( element->value() );
2465 if( !isDefault<strict>( value ) )
2466 set( i, element->index(), value );
2469 append( i, element->index(), element->value(), true );
2491 template<
typename MT
2493 template<
typename MT2 >
2494 inline void Submatrix<MT,AF,false,false>::assign(
const SparseMatrix<MT2,true>& rhs )
2501 typedef ConstIterator_<MT2> RhsIterator;
2504 std::vector<size_t> rowLengths( m_, 0UL );
2505 for(
size_t j=0UL; j<
n_; ++j ) {
2506 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2507 ++rowLengths[element->index()];
2511 for(
size_t i=0UL; i<
m_; ++i ) {
2512 reserve( i, rowLengths[i] );
2516 for(
size_t j=0UL; j<
n_; ++j ) {
2517 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2518 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
2519 const ElementType& value( element->value() );
2520 if( !isDefault<strict>( value ) )
2521 set( element->index(), j, value );
2524 append( element->index(), j, element->value(), true );
2544 template<
typename MT
2546 template<
typename MT2
2548 inline void Submatrix<MT,AF,false,false>::addAssign(
const DenseMatrix<MT2,SO>& rhs )
2550 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
2558 const AddType tmp(
serial( *
this + (~rhs) ) );
2578 template<
typename MT
2580 template<
typename MT2
2582 inline void Submatrix<MT,AF,false,false>::addAssign(
const SparseMatrix<MT2,SO>& rhs )
2584 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
2592 const AddType tmp(
serial( *
this + (~rhs) ) );
2612 template<
typename MT
2614 template<
typename MT2
2616 inline void Submatrix<MT,AF,false,false>::subAssign(
const DenseMatrix<MT2,SO>& rhs )
2618 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
2626 const SubType tmp(
serial( *
this - (~rhs) ) );
2646 template<
typename MT
2648 template<
typename MT2
2650 inline void Submatrix<MT,AF,false,false>::subAssign(
const SparseMatrix<MT2,SO>& rhs )
2652 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
2660 const SubType tmp(
serial( *
this - (~rhs) ) );
2688 template<
typename MT
2690 class Submatrix<MT,AF,true,false>
2691 :
public SparseMatrix< Submatrix<MT,AF,true,false>, true >
2697 typedef If_< IsExpression<MT>, MT, MT& > Operand;
2702 typedef Submatrix<MT,AF,true,false>
This;
2703 typedef SparseMatrix<This,true>
BaseType;
2721 template<
typename MatrixType
2722 ,
typename IteratorType >
2723 class SubmatrixElement :
private SparseElement
2733 enum :
bool { returnConst = IsConst<MatrixType>::value };
2738 typedef typename std::iterator_traits<IteratorType>::value_type SET;
2740 typedef Reference_<SET> RT;
2741 typedef ConstReference_<SET> CRT;
2746 typedef ValueType_<SET> ValueType;
2747 typedef size_t IndexType;
2748 typedef IfTrue_<returnConst,CRT,RT>
Reference;
2758 inline SubmatrixElement( IteratorType pos,
size_t offset )
2770 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
2782 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
2794 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
2806 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
2818 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
2829 inline const SubmatrixElement* operator->()
const {
2839 inline Reference value()
const {
2840 return pos_->value();
2849 inline IndexType index()
const {
2850 return pos_->index() - offset_;
2865 template<
typename MatrixType
2866 ,
typename IteratorType >
2867 class SubmatrixIterator
2871 typedef std::forward_iterator_tag IteratorCategory;
2872 typedef SubmatrixElement<MatrixType,IteratorType> ValueType;
2873 typedef ValueType PointerType;
2874 typedef ValueType ReferenceType;
2875 typedef ptrdiff_t DifferenceType;
2878 typedef IteratorCategory iterator_category;
2879 typedef ValueType value_type;
2880 typedef PointerType pointer;
2881 typedef ReferenceType reference;
2882 typedef DifferenceType difference_type;
2888 inline SubmatrixIterator()
2900 inline SubmatrixIterator( IteratorType iterator,
size_t index )
2911 template<
typename MatrixType2,
typename IteratorType2 >
2912 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2913 : pos_ ( it.base() )
2914 , offset_( it.offset() )
2923 inline SubmatrixIterator& operator++() {
2934 inline const SubmatrixIterator operator++(
int ) {
2935 const SubmatrixIterator tmp( *
this );
2946 inline ReferenceType
operator*()
const {
2947 return ReferenceType( pos_, offset_ );
2956 inline PointerType operator->()
const {
2957 return PointerType( pos_, offset_ );
2967 template<
typename MatrixType2,
typename IteratorType2 >
2968 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2969 return base() == rhs.base();
2979 template<
typename MatrixType2,
typename IteratorType2 >
2980 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2981 return !( *
this == rhs );
2991 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
2992 return pos_ - rhs.pos_;
3001 inline IteratorType base()
const {
3011 inline size_t offset() const noexcept {
3026 typedef SubmatrixIterator< const MT, ConstIterator_<MT> >
ConstIterator;
3034 enum :
bool { smpAssignable = MT::smpAssignable };
3040 explicit inline Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n );
3052 inline Reference operator()(
size_t i,
size_t j );
3053 inline ConstReference operator()(
size_t i,
size_t j )
const;
3054 inline Reference at(
size_t i,
size_t j );
3055 inline ConstReference at(
size_t i,
size_t j )
const;
3056 inline Iterator
begin (
size_t i );
3057 inline ConstIterator
begin (
size_t i )
const;
3058 inline ConstIterator
cbegin(
size_t i )
const;
3059 inline Iterator
end (
size_t i );
3060 inline ConstIterator
end (
size_t i )
const;
3061 inline ConstIterator
cend (
size_t i )
const;
3068 inline Submatrix& operator=(
const Submatrix& rhs );
3070 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
3071 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
3072 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
3073 template<
typename MT2,
bool SO >
inline Submatrix&
operator*=(
const Matrix<MT2,SO>& rhs );
3075 template<
typename Other >
3076 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator*=( Other rhs );
3078 template<
typename Other >
3079 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator/=( Other rhs );
3086 inline size_t row() const noexcept;
3087 inline
size_t rows() const noexcept;
3088 inline
size_t column() const noexcept;
3089 inline
size_t columns() const noexcept;
3090 inline
size_t capacity() const noexcept;
3091 inline
size_t capacity(
size_t i ) const noexcept;
3093 inline
size_t nonZeros(
size_t i ) const;
3094 inline
void reset();
3095 inline
void reset(
size_t i );
3096 inline
void reserve(
size_t nonzeros );
3097 void reserve(
size_t i,
size_t nonzeros );
3099 inline
void trim(
size_t j );
3106 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
3107 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
3108 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
3109 inline
void finalize(
size_t i );
3116 inline
void erase(
size_t i,
size_t j );
3117 inline Iterator erase(
size_t i, Iterator pos );
3118 inline Iterator erase(
size_t i, Iterator first, Iterator last );
3120 template< typename Pred >
3121 inline
void erase( Pred predicate );
3123 template< typename Pred >
3124 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
3131 inline Iterator find (
size_t i,
size_t j );
3132 inline ConstIterator find (
size_t i,
size_t j ) const;
3133 inline Iterator lowerBound(
size_t i,
size_t j );
3134 inline ConstIterator lowerBound(
size_t i,
size_t j ) const;
3135 inline Iterator upperBound(
size_t i,
size_t j );
3136 inline ConstIterator upperBound(
size_t i,
size_t j ) const;
3143 inline Submatrix& transpose();
3144 inline Submatrix& ctranspose();
3146 template< typename Other > inline Submatrix& scale( const Other& scalar );
3153 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
3154 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
3156 inline
bool canSMPAssign() const noexcept;
3158 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
3159 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
3160 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
3161 template< typename MT2,
bool SO > inline
void addAssign( const DenseMatrix<MT2,SO>& rhs );
3162 template< typename MT2,
bool SO > inline
void addAssign( const SparseMatrix<MT2,SO>& rhs );
3163 template< typename MT2,
bool SO > inline
void subAssign( const DenseMatrix<MT2,SO>& rhs );
3164 template< typename MT2,
bool SO > inline
void subAssign( const SparseMatrix<MT2,SO>& rhs );
3172 inline
bool hasOverlap() const noexcept;
3181 const
size_t column_;
3188 template<
bool AF1, typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3189 friend const Submatrix<MT2,AF1,SO2,DF2>
3190 submatrix( const Submatrix<MT2,AF2,SO2,DF2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
3192 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3193 friend
bool isIntact( const Submatrix<MT2,AF2,SO2,DF2>& sm ) noexcept;
3195 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3196 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Matrix<MT2,SO2>& b ) noexcept;
3198 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3199 friend
bool isSame( const Matrix<MT2,SO2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
3201 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3202 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
3204 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3205 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2>& lhs, const Vector<VT,TF>& rhs,
3206 size_t row,
size_t column );
3208 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3209 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3210 size_t row,
size_t column );
3212 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3213 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3214 size_t row,
size_t column );
3216 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3217 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3218 size_t row,
size_t column );
3220 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3221 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3222 size_t row,
size_t column );
3224 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3225 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3226 size_t row,
size_t column );
3228 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3229 friend
bool tryMultAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3230 size_t row,
size_t column );
3232 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3233 friend
DerestrictTrait_< Submatrix<MT2,AF2,SO2,DF2> > derestrict( Submatrix<MT2,AF2,SO2,DF2>& sm );
3272 template< typename MT
3274 inline Submatrix<MT,AF,true,false>::Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n )
3281 if( ( row_ + m_ > matrix_.rows() ) || ( column_ + n_ > matrix_.columns() ) ) {
3308 template<
typename MT
3311 Submatrix<MT,AF,true,false>::operator()(
size_t i,
size_t j )
3316 return matrix_(row_+i,column_+j);
3333 template<
typename MT
3336 Submatrix<MT,AF,true,false>::operator()(
size_t i,
size_t j )
const 3341 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
3359 template<
typename MT
3362 Submatrix<MT,AF,true,false>::at(
size_t i,
size_t j )
3370 return (*
this)(i,j);
3388 template<
typename MT
3391 Submatrix<MT,AF,true,false>::at(
size_t i,
size_t j )
const 3399 return (*
this)(i,j);
3412 template<
typename MT
3420 return Iterator( matrix_.begin( j + column_ ), row_ );
3422 return Iterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3435 template<
typename MT
3443 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
3445 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3458 template<
typename MT
3466 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
3468 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3481 template<
typename MT
3488 if( matrix_.rows() == row_ +
m_ )
3489 return Iterator( matrix_.end( j + column_ ), row_ );
3491 return Iterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3504 template<
typename MT
3511 if( matrix_.rows() == row_ +
m_ )
3514 return ConstIterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3527 template<
typename MT
3534 if( matrix_.rows() == row_ +
m_ )
3537 return ConstIterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3566 template<
typename MT
3568 inline Submatrix<MT,AF,true,false>&
3569 Submatrix<MT,AF,true,false>::operator=(
const Submatrix& rhs )
3571 using blaze::assign;
3576 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
3579 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
3583 if( !tryAssign( matrix_, rhs, row_, column_ ) ) {
3587 DerestrictTrait_<This> left( derestrict( *
this ) );
3589 if( rhs.canAlias( &matrix_ ) ) {
3590 const ResultType tmp( rhs );
3592 assign( left, tmp );
3596 assign( left, rhs );
3622 template<
typename MT
3624 template<
typename MT2
3626 inline Submatrix<MT,AF,true,false>&
3627 Submatrix<MT,AF,true,false>::operator=(
const Matrix<MT2,SO>& rhs )
3629 using blaze::assign;
3637 typedef CompositeType_<MT2> Right;
3638 Right right( ~rhs );
3640 if( !tryAssign( matrix_, right, row_, column_ ) ) {
3644 DerestrictTrait_<This> left( derestrict( *
this ) );
3646 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
3647 const ResultType_<MT2> tmp( right );
3649 assign( left, tmp );
3653 assign( left, right );
3678 template<
typename MT
3680 template<
typename MT2
3682 inline Submatrix<MT,AF,true,false>&
3685 using blaze::assign;
3691 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
3699 const AddType tmp( *
this + (~rhs) );
3701 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3705 DerestrictTrait_<This> left( derestrict( *
this ) );
3708 assign( left, tmp );
3732 template<
typename MT
3734 template<
typename MT2
3736 inline Submatrix<MT,AF,true,false>&
3739 using blaze::assign;
3745 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
3753 const SubType tmp( *
this - (~rhs) );
3755 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3759 DerestrictTrait_<This> left( derestrict( *
this ) );
3762 assign( left, tmp );
3786 template<
typename MT
3788 template<
typename MT2
3790 inline Submatrix<MT,AF,true,false>&
3793 using blaze::assign;
3799 typedef MultTrait_< ResultType, ResultType_<MT2> > MultType;
3808 const MultType tmp( *
this * (~rhs) );
3810 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3814 DerestrictTrait_<This> left( derestrict( *
this ) );
3817 assign( left, tmp );
3842 template<
typename MT
3844 template<
typename Other >
3845 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,true,false> >&
3850 for(
size_t i=0UL; i<
columns(); ++i ) {
3851 const Iterator last(
end(i) );
3852 for( Iterator element=
begin(i); element!=last; ++element )
3853 element->value() *= rhs;
3880 template<
typename MT
3882 template<
typename Other >
3883 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,true,false> >&
3890 typedef DivTrait_<ElementType,Other> DT;
3891 typedef If_< IsNumeric<DT>, DT, Other > Tmp;
3895 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3896 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3897 for(
size_t i=0UL; i<
columns(); ++i ) {
3898 const Iterator last(
end(i) );
3899 for( Iterator element=
begin(i); element!=last; ++element )
3900 element->value() *= tmp;
3904 for(
size_t i=0UL; i<
columns(); ++i ) {
3905 const Iterator last(
end(i) );
3906 for( Iterator element=
begin(i); element!=last; ++element )
3907 element->value() /= rhs;
3931 template<
typename MT
3947 template<
typename MT
3963 template<
typename MT
3979 template<
typename MT
3995 template<
typename MT
3999 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
4012 template<
typename MT
4017 return nonZeros( j ) + matrix_.capacity( column_+j ) - matrix_.nonZeros( column_+j );
4029 template<
typename MT
4033 size_t nonzeros( 0UL );
4035 for(
size_t i=0UL; i<
columns(); ++i )
4051 template<
typename MT
4068 template<
typename MT
4072 for(
size_t j=column_; j<column_+
n_; ++j )
4074 const size_t ibegin( ( IsLower<MT>::value )
4075 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
4076 ?(
max( j+1UL, row_ ) )
4077 :(
max( j, row_ ) ) )
4079 const size_t iend ( ( IsUpper<MT>::value )
4080 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
4081 ?(
min( j, row_+m_ ) )
4082 :(
min( j+1UL, row_+m_ ) ) )
4085 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
4099 template<
typename MT
4105 const size_t index( column_ + j );
4107 const size_t ibegin( ( IsLower<MT>::value )
4108 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
4109 ?(
max( j+1UL, row_ ) )
4110 :(
max( j, row_ ) ) )
4112 const size_t iend ( ( IsUpper<MT>::value )
4113 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
4114 ?(
min( j, row_+m_ ) )
4115 :(
min( j+1UL, row_+m_ ) ) )
4118 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
4135 template<
typename MT
4137 inline void Submatrix<MT,AF,true,false>::reserve(
size_t nonzeros )
4139 const size_t current(
capacity() );
4141 if( nonzeros > current ) {
4142 matrix_.reserve( matrix_.capacity() + nonzeros - current );
4161 template<
typename MT
4163 void Submatrix<MT,AF,true,false>::reserve(
size_t j,
size_t nonzeros )
4165 const size_t current(
capacity( j ) );
4166 const size_t index ( column_ + j );
4168 if( nonzeros > current ) {
4169 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
4186 template<
typename MT
4188 void Submatrix<MT,AF,true,false>::trim()
4190 for(
size_t j=0UL; j<
columns(); ++j )
4208 template<
typename MT
4210 void Submatrix<MT,AF,true,false>::trim(
size_t j )
4213 matrix_.trim( column_ + j );
4229 template<
typename MT
4231 inline bool Submatrix<MT,AF,true,false>::hasOverlap() const noexcept
4233 BLAZE_INTERNAL_ASSERT( IsSymmetric<MT>::value || IsHermitian<MT>::value,
"Invalid matrix detected" );
4235 if( ( row_ + m_ <= column_ ) || ( column_ + n_ <= row_ ) )
4264 template<
typename MT
4269 return Iterator( matrix_.set( row_+i, column_+j, value ), row_ );
4289 template<
typename MT
4292 Submatrix<MT,AF,true,false>::insert(
size_t i,
size_t j,
const ElementType& value )
4294 return Iterator( matrix_.insert( row_+i, column_+j, value ), row_ );
4349 template<
typename MT
4351 inline void Submatrix<MT,AF,true,false>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
4353 if( row_ + m_ == matrix_.rows() ) {
4354 matrix_.append( row_ + i, column_ + j, value, check );
4356 else if( !check || !
isDefault( value ) ) {
4357 matrix_.insert( row_ + i, column_ + j, value );
4378 template<
typename MT
4380 inline void Submatrix<MT,AF,true,false>::finalize(
size_t j )
4382 matrix_.trim( column_ + j );
4406 template<
typename MT
4408 inline void Submatrix<MT,AF,true,false>::erase(
size_t i,
size_t j )
4413 matrix_.erase( row_ + i, column_ + j );
4429 template<
typename MT
4432 Submatrix<MT,AF,true,false>::erase(
size_t j, Iterator pos )
4435 return Iterator( matrix_.erase( column_+j, pos.base() ), row_ );
4452 template<
typename MT
4455 Submatrix<MT,AF,true,false>::erase(
size_t j, Iterator first, Iterator last )
4458 return Iterator( matrix_.erase( column_+j, first.base(), last.base() ), row_ );
4487 template<
typename MT
4489 template<
typename Pred >
4490 inline void Submatrix<MT,AF,true,false>::erase( Pred predicate )
4492 for(
size_t j=0UL; j<
columns(); ++j ) {
4493 matrix_.erase( column_+j,
begin(j).base(),
end(j).base(), predicate );
4526 template<
typename MT
4528 template<
typename Pred >
4529 inline void Submatrix<MT,AF,true,false>::erase(
size_t j, Iterator first, Iterator last, Pred predicate )
4532 matrix_.erase( column_+j, first.base(), last.base(), predicate );
4562 template<
typename MT
4565 Submatrix<MT,AF,true,false>::find(
size_t i,
size_t j )
4567 const Iterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
4569 if( pos != matrix_.end( column_ + j ) )
4594 template<
typename MT
4597 Submatrix<MT,AF,true,false>::find(
size_t i,
size_t j )
const 4599 const ConstIterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
4601 if( pos != matrix_.end( column_ + j ) )
4626 template<
typename MT
4629 Submatrix<MT,AF,true,false>::lowerBound(
size_t i,
size_t j )
4631 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
4653 template<
typename MT
4656 Submatrix<MT,AF,true,false>::lowerBound(
size_t i,
size_t j )
const 4658 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
4680 template<
typename MT
4683 Submatrix<MT,AF,true,false>::upperBound(
size_t i,
size_t j )
4685 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
4707 template<
typename MT
4710 Submatrix<MT,AF,true,false>::upperBound(
size_t i,
size_t j )
const 4712 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
4744 template<
typename MT
4748 using blaze::assign;
4754 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
4758 DerestrictTrait_<This> left( derestrict( *
this ) );
4759 const ResultType tmp(
trans( *
this ) );
4761 assign( left, tmp );
4787 template<
typename MT
4791 using blaze::assign;
4797 if( !tryAssign( matrix_,
ctrans( *
this ), row_, column_ ) ) {
4801 DerestrictTrait_<This> left( derestrict( *
this ) );
4802 const ResultType tmp(
ctrans(*
this) );
4804 assign( left, tmp );
4823 template<
typename MT
4825 template<
typename Other >
4826 inline Submatrix<MT,AF,true,false>& Submatrix<MT,AF,true,false>::scale(
const Other& scalar )
4830 for(
size_t i=0UL; i<
columns(); ++i ) {
4831 const Iterator last(
end(i) );
4832 for( Iterator element=
begin(i); element!=last; ++element )
4833 element->value() *= scalar;
4861 template<
typename MT
4863 template<
typename Other >
4864 inline bool Submatrix<MT,AF,true,false>::canAlias(
const Other* alias )
const noexcept
4866 return matrix_.isAliased( alias );
4883 template<
typename MT
4885 template<
typename Other >
4886 inline bool Submatrix<MT,AF,true,false>::isAliased(
const Other* alias )
const noexcept
4888 return matrix_.isAliased( alias );
4905 template<
typename MT
4907 inline bool Submatrix<MT,AF,true,false>::canSMPAssign() const noexcept
4927 template<
typename MT
4929 template<
typename MT2
4931 inline void Submatrix<MT,AF,true,false>::assign(
const DenseMatrix<MT2,SO>& rhs )
4938 for(
size_t j=0UL; j<
columns(); ++j ) {
4939 for(
size_t i=0UL; i<
rows(); ++i ) {
4940 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
4941 const ElementType& value( (~rhs)(i,j) );
4942 if( !isDefault<strict>( value ) )
4946 append( i, j, (~rhs)(i,j),
true );
4968 template<
typename MT
4970 template<
typename MT2 >
4971 inline void Submatrix<MT,AF,true,false>::assign(
const SparseMatrix<MT2,true>& rhs )
4978 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4979 for( ConstIterator_<MT2> element=(~rhs).begin(j); element!=(~rhs).
end(j); ++element ) {
4980 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
4981 const ElementType& value( element->value() );
4982 if( !isDefault<strict>( value ) )
4983 set( element->index(), j, value );
4986 append( element->index(), j, element->value(), true );
5007 template<
typename MT
5009 template<
typename MT2 >
5010 inline void Submatrix<MT,AF,true,false>::assign(
const SparseMatrix<MT2,false>& rhs )
5017 typedef ConstIterator_<MT2> RhsIterator;
5020 std::vector<size_t> columnLengths( n_, 0UL );
5021 for(
size_t i=0UL; i<
m_; ++i ) {
5022 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5023 ++columnLengths[element->index()];
5027 for(
size_t j=0UL; j<
n_; ++j ) {
5028 reserve( j, columnLengths[j] );
5032 for(
size_t i=0UL; i<
m_; ++i ) {
5033 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5034 if( IsSymmetric<MT>::value || IsHermitian<MT>::value ) {
5035 const ElementType& value( element->value() );
5036 if( !isDefault<strict>( value ) )
5037 set( i, element->index(), value );
5040 append( i, element->index(), element->value(), true );
5060 template<
typename MT
5062 template<
typename MT2
5064 inline void Submatrix<MT,AF,true,false>::addAssign(
const DenseMatrix<MT2,SO>& rhs )
5066 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
5074 const AddType tmp(
serial( *
this + (~rhs) ) );
5094 template<
typename MT
5096 template<
typename MT2
5098 inline void Submatrix<MT,AF,true,false>::addAssign(
const SparseMatrix<MT2,SO>& rhs )
5100 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
5108 const AddType tmp(
serial( *
this + (~rhs) ) );
5128 template<
typename MT
5130 template<
typename MT2
5132 inline void Submatrix<MT,AF,true,false>::subAssign(
const DenseMatrix<MT2,SO>& rhs )
5134 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
5142 const SubType tmp(
serial( *
this - (~rhs) ) );
5162 template<
typename MT
5164 template<
typename MT2
5166 inline void Submatrix<MT,AF,true,false>::subAssign(
const SparseMatrix<MT2,SO>& rhs )
5168 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
5176 const SubType tmp(
serial( *
this - (~rhs) ) );
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Constraint on the data type.
Header file for auxiliary alias declarations.
Header file for mathematical functions.
typename DerestrictTrait< T >::Type DerestrictTrait_
Auxiliary alias declaration for the DerestrictTrait type trait.The DerestrictTrait_ alias declaration...
Definition: DerestrictTrait.h:110
#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
Header file for the alignment flag values.
Header file for the IsUniUpper type trait.
Header file for the subtraction trait.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:352
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:721
Header file for basic type definitions.
Header file for the View base class.
Header file for the serial shim.
const CTransExprTrait_< MT > ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatForEachExpr.h:1251
#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:81
#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:61
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1339
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:194
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
size_t m_
The current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:3135
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2935
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1755
#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:81
BLAZE_ALWAYS_INLINE void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:596
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2928
#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:81
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
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:390
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:731
Constraints on the storage order of matrix types.
#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:81
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1321
Header file for the IsUniLower type trait.
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1802
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2931
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:304
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:238
Constraint on the data type.
Header file for the SparseMatrix base class.
Constraint on the data type.
Header file for the matrix storage order types.
Constraint on the data type.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
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: ColumnMajorMatrix.h:61
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2939
#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:79
Header file for the Or class template.
Constraint on the data type.
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Header file for the implementation of the Submatrix base template.
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
Header file for the IsLower type trait.
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:336
Header file for the SparseElement base class.
Constraint on the data type.
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT >, IsDeclExpr< MT > >, RowExprTrait_< MT > > row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:128
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2932
Header file for the exception macros of the math module.
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:260
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:2933
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2937
DisableIf_< Or< IsComputation< MT >, IsTransExpr< MT >, IsDeclExpr< MT > >, ColumnExprTrait_< MT > > column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:128
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
Header file for the DerestrictTrait class template.
Constraint on the data type.
Header file for the IsNumeric type trait.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
#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:79
#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: RowMajorMatrix.h:61
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2934
Header file for the IsConst type trait.
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1285
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the addition trait.
Header file for the division trait.
Header file for the submatrix trait.
#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:79
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2938
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the IsReference type trait.
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:320
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2929
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:3136
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:733
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2930
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:249
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2936
#define BLAZE_THROW_LOGIC_ERROR(MESSAGE)
Macro for the emission of a std::logic_error exception.This macro encapsulates the default way of Bla...
Definition: Exception.h:187
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1303
#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:61
Header file for the IsUpper type trait.
SubmatrixExprTrait_< MT, unaligned > 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:168
Header file for the IsHermitian type trait.
const DMatDMatMultExpr< T1, T2, false, false, false, false > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7505
#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:61
Header file for the IsExpression type trait class.
Constraint on the data type.
BLAZE_ALWAYS_INLINE void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:570