35 #ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
36 #define _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
111 template<
typename MT
113 class Submatrix<MT,AF,false,false>
114 :
public SparseMatrix< Submatrix<MT,AF,false,false>, false >
120 typedef If_< IsExpression<MT>, MT, MT& > Operand;
125 typedef Submatrix<MT,AF,false,false>
This;
126 typedef SparseMatrix<This,false>
BaseType;
144 template<
typename MatrixType
145 ,
typename IteratorType >
146 class SubmatrixElement :
private SparseElement
156 enum :
bool { returnConst = IsConst<MatrixType>::value };
161 typedef typename std::iterator_traits<IteratorType>::value_type SET;
163 typedef Reference_<SET> RT;
164 typedef ConstReference_<SET> CRT;
169 typedef ValueType_<SET> ValueType;
170 typedef size_t IndexType;
171 typedef IfTrue_<returnConst,CRT,RT>
Reference;
181 inline SubmatrixElement( IteratorType pos,
size_t offset )
193 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
205 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
217 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
229 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
241 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
252 inline const SubmatrixElement* operator->()
const {
262 inline Reference value()
const {
263 return pos_->value();
272 inline IndexType index()
const {
273 return pos_->index() - offset_;
288 template<
typename MatrixType
289 ,
typename IteratorType >
290 class SubmatrixIterator
294 typedef std::forward_iterator_tag IteratorCategory;
295 typedef SubmatrixElement<MatrixType,IteratorType> ValueType;
296 typedef ValueType PointerType;
297 typedef ValueType ReferenceType;
298 typedef ptrdiff_t DifferenceType;
301 typedef IteratorCategory iterator_category;
302 typedef ValueType value_type;
303 typedef PointerType pointer;
304 typedef ReferenceType reference;
305 typedef DifferenceType difference_type;
311 inline SubmatrixIterator()
323 inline SubmatrixIterator( IteratorType iterator,
size_t index )
334 template<
typename MatrixType2,
typename IteratorType2 >
335 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
337 , offset_( it.offset() )
346 inline SubmatrixIterator& operator++() {
357 inline const SubmatrixIterator operator++(
int ) {
358 const SubmatrixIterator tmp( *
this );
370 return ReferenceType( pos_, offset_ );
379 inline PointerType operator->()
const {
380 return PointerType( pos_, offset_ );
390 template<
typename MatrixType2,
typename IteratorType2 >
391 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
392 return base() == rhs.base();
402 template<
typename MatrixType2,
typename IteratorType2 >
403 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
404 return !( *
this == rhs );
414 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
415 return pos_ - rhs.pos_;
424 inline IteratorType base()
const {
434 inline size_t offset() const noexcept {
449 typedef SubmatrixIterator< const MT, ConstIterator_<MT> >
ConstIterator;
457 enum :
bool { smpAssignable = MT::smpAssignable };
463 explicit inline Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n );
475 inline Reference operator()(
size_t i,
size_t j );
476 inline ConstReference operator()(
size_t i,
size_t j )
const;
477 inline Reference at(
size_t i,
size_t j );
478 inline ConstReference at(
size_t i,
size_t j )
const;
479 inline Iterator
begin (
size_t i );
480 inline ConstIterator
begin (
size_t i )
const;
481 inline ConstIterator
cbegin(
size_t i )
const;
482 inline Iterator
end (
size_t i );
483 inline ConstIterator
end (
size_t i )
const;
484 inline ConstIterator
cend (
size_t i )
const;
491 inline Submatrix& operator=(
const Submatrix& rhs );
493 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& 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 );
498 template<
typename Other >
499 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator*=( Other rhs );
501 template<
typename Other >
502 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator/=( Other rhs );
509 inline size_t row() const noexcept;
510 inline
size_t rows() const noexcept;
511 inline
size_t column() const noexcept;
512 inline
size_t columns() const noexcept;
513 inline
size_t capacity() const noexcept;
514 inline
size_t capacity(
size_t i ) const noexcept;
516 inline
size_t nonZeros(
size_t i ) const;
518 inline
void reset(
size_t i );
519 inline Iterator
set(
size_t i,
size_t j, const ElementType& value );
520 inline Iterator insert(
size_t i,
size_t j, const ElementType& value );
521 inline
void erase(
size_t i,
size_t j );
522 inline Iterator erase(
size_t i, Iterator pos );
523 inline Iterator erase(
size_t i, Iterator first, Iterator last );
524 inline
void reserve(
size_t nonzeros );
525 void reserve(
size_t i,
size_t nonzeros );
527 inline
void trim(
size_t i );
530 template< typename Other > inline Submatrix& scale( const Other& scalar );
537 inline Iterator find (
size_t i,
size_t j );
538 inline ConstIterator find (
size_t i,
size_t j ) const;
539 inline Iterator lowerBound(
size_t i,
size_t j );
540 inline ConstIterator lowerBound(
size_t i,
size_t j ) const;
541 inline Iterator upperBound(
size_t i,
size_t j );
542 inline ConstIterator upperBound(
size_t i,
size_t j ) const;
549 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
550 inline
void finalize(
size_t i );
557 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
558 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
560 inline
bool canSMPAssign() const noexcept;
562 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
563 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
564 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
565 template< typename MT2,
bool SO > inline
void addAssign( const DenseMatrix<MT2,SO>& rhs );
566 template< typename MT2,
bool SO > inline
void addAssign( const SparseMatrix<MT2,SO>& rhs );
567 template< typename MT2,
bool SO > inline
void subAssign( const DenseMatrix<MT2,SO>& rhs );
568 template< typename MT2,
bool SO > inline
void subAssign( const SparseMatrix<MT2,SO>& rhs );
576 inline
bool hasOverlap() const noexcept;
585 const
size_t column_;
592 template<
bool AF1, typename MT2,
bool AF2,
bool SO2,
bool DF2 >
593 friend const Submatrix<MT2,AF1,SO2,DF2>
594 submatrix( const Submatrix<MT2,AF2,SO2,DF2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
596 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
597 friend
bool isIntact( const Submatrix<MT2,AF2,SO2,DF2>& sm ) noexcept;
599 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
600 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Matrix<MT2,SO2>& b ) noexcept;
602 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
603 friend
bool isSame( const Matrix<MT2,SO2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
605 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
606 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
608 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
609 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
610 size_t row,
size_t column );
612 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
613 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
614 size_t row,
size_t column );
616 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
617 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
618 size_t row,
size_t column );
620 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
621 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
622 size_t row,
size_t column );
624 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
625 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
626 size_t row,
size_t column );
628 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
629 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
630 size_t row,
size_t column );
632 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
633 friend
bool tryMultAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
634 size_t row,
size_t column );
636 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
637 friend
DerestrictTrait_< Submatrix<MT2,AF2,SO2,DF2> > derestrict( Submatrix<MT2,AF2,SO2,DF2>& sm );
676 template< typename MT
678 inline Submatrix<MT,AF,false,false>::Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n )
685 if( ( row_ + m_ > matrix_.rows() ) || ( column_ + n_ > matrix_.columns() ) ) {
712 template<
typename MT
715 Submatrix<MT,AF,false,false>::operator()(
size_t i,
size_t j )
720 return matrix_(row_+i,column_+j);
737 template<
typename MT
740 Submatrix<MT,AF,false,false>::operator()(
size_t i,
size_t j )
const
745 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
763 template<
typename MT
766 Submatrix<MT,AF,false,false>::at(
size_t i,
size_t j )
792 template<
typename MT
795 Submatrix<MT,AF,false,false>::at(
size_t i,
size_t j )
const
821 template<
typename MT
829 return Iterator( matrix_.begin( i + row_ ), column_ );
831 return Iterator( matrix_.lowerBound( i + row_, column_ ), column_ );
849 template<
typename MT
859 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
877 template<
typename MT
887 return ConstIterator( matrix_.lowerBound( i + row_, column_ ), column_ );
905 template<
typename MT
912 if( matrix_.columns() == column_ +
n_ )
913 return Iterator( matrix_.end( i + row_ ), column_ );
915 return Iterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
933 template<
typename MT
940 if( matrix_.columns() == column_ +
n_ )
943 return ConstIterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
961 template<
typename MT
968 if( matrix_.columns() == column_ +
n_ )
971 return ConstIterator( matrix_.lowerBound( i + row_, column_ + n_ ), column_ );
1000 template<
typename MT
1002 inline Submatrix<MT,AF,false,false>&
1003 Submatrix<MT,AF,false,false>::operator=(
const Submatrix& rhs )
1005 using blaze::assign;
1010 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
1013 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
1017 if( !tryAssign( matrix_, rhs, row_, column_ ) ) {
1021 DerestrictTrait_<This> left( derestrict( *
this ) );
1023 if( rhs.canAlias( &matrix_ ) ) {
1024 const ResultType tmp( rhs );
1026 assign( left, tmp );
1030 assign( left, rhs );
1056 template<
typename MT
1058 template<
typename MT2
1060 inline Submatrix<MT,AF,false,false>&
1061 Submatrix<MT,AF,false,false>::operator=(
const Matrix<MT2,SO>& rhs )
1063 using blaze::assign;
1071 typedef CompositeType_<MT2> Right;
1072 Right right( ~rhs );
1074 if( !tryAssign( matrix_, right, row_, column_ ) ) {
1078 DerestrictTrait_<This> left( derestrict( *
this ) );
1080 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
1081 const ResultType_<MT2> tmp( right );
1083 assign( left, tmp );
1087 assign( left, right );
1112 template<
typename MT
1114 template<
typename MT2
1116 inline Submatrix<MT,AF,false,false>&
1119 using blaze::assign;
1125 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
1133 const AddType tmp( *
this + (~rhs) );
1135 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1139 DerestrictTrait_<This> left( derestrict( *
this ) );
1142 assign( left, tmp );
1166 template<
typename MT
1168 template<
typename MT2
1170 inline Submatrix<MT,AF,false,false>&
1173 using blaze::assign;
1179 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
1187 const SubType tmp( *
this - (~rhs) );
1189 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1193 DerestrictTrait_<This> left( derestrict( *
this ) );
1196 assign( left, tmp );
1220 template<
typename MT
1222 template<
typename MT2
1224 inline Submatrix<MT,AF,false,false>&
1227 using blaze::assign;
1233 typedef MultTrait_< ResultType, ResultType_<MT2> > MultType;
1242 const MultType tmp( *
this * (~rhs) );
1244 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
1248 DerestrictTrait_<This> left( derestrict( *
this ) );
1251 assign( left, tmp );
1276 template<
typename MT
1278 template<
typename Other >
1279 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,false,false> >&
1284 for(
size_t i=0UL; i<
rows(); ++i ) {
1285 const Iterator last(
end(i) );
1286 for( Iterator element=
begin(i); element!=last; ++element )
1287 element->value() *= rhs;
1314 template<
typename MT
1316 template<
typename Other >
1317 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,false,false> >&
1324 typedef DivTrait_<ElementType,Other> DT;
1325 typedef If_< IsNumeric<DT>, DT, Other > Tmp;
1329 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
1330 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1331 for(
size_t i=0UL; i<
rows(); ++i ) {
1332 const Iterator last(
end(i) );
1333 for( Iterator element=
begin(i); element!=last; ++element )
1334 element->value() *= tmp;
1338 for(
size_t i=0UL; i<
rows(); ++i ) {
1339 const Iterator last(
end(i) );
1340 for( Iterator element=
begin(i); element!=last; ++element )
1341 element->value() /= rhs;
1365 template<
typename MT
1381 template<
typename MT
1397 template<
typename MT
1413 template<
typename MT
1429 template<
typename MT
1433 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1451 template<
typename MT
1456 return nonZeros( i ) + matrix_.capacity( row_+i ) - matrix_.nonZeros( row_+i );
1468 template<
typename MT
1472 size_t nonzeros( 0UL );
1474 for(
size_t i=0UL; i<
rows(); ++i )
1495 template<
typename MT
1512 template<
typename MT
1516 for(
size_t i=row_; i<row_+
m_; ++i )
1518 const size_t jbegin( ( IsUpper<MT>::value )
1519 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
1520 ?(
max( i+1UL, column_ ) )
1521 :(
max( i, column_ ) ) )
1523 const size_t jend ( ( IsLower<MT>::value )
1524 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
1525 ?(
min( i, column_+n_ ) )
1526 :(
min( i+1UL, column_+n_ ) ) )
1529 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1548 template<
typename MT
1554 const size_t index( row_ + i );
1556 const size_t jbegin( ( IsUpper<MT>::value )
1557 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
1558 ?(
max( i+1UL, column_ ) )
1559 :(
max( i, column_ ) ) )
1561 const size_t jend ( ( IsLower<MT>::value )
1562 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
1563 ?(
min( i, column_+n_ ) )
1564 :(
min( i+1UL, column_+n_ ) ) )
1567 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1586 template<
typename MT
1591 return Iterator( matrix_.set( row_+i, column_+j, value ), column_ );
1611 template<
typename MT
1614 Submatrix<MT,AF,false,false>::insert(
size_t i,
size_t j,
const ElementType& value )
1616 return Iterator( matrix_.insert( row_+i, column_+j, value ), column_ );
1632 template<
typename MT
1634 inline void Submatrix<MT,AF,false,false>::erase(
size_t i,
size_t j )
1639 matrix_.erase( row_ + i, column_ + j );
1657 template<
typename MT
1660 Submatrix<MT,AF,false,false>::erase(
size_t i, Iterator pos )
1663 return Iterator( matrix_.erase( row_+i, pos.base() ), column_ );
1683 template<
typename MT
1686 Submatrix<MT,AF,false,false>::erase(
size_t i, Iterator first, Iterator last )
1689 return Iterator( matrix_.erase( row_+i, first.base(), last.base() ), column_ );
1706 template<
typename MT
1708 inline void Submatrix<MT,AF,false,false>::reserve(
size_t nonzeros )
1710 const size_t current(
capacity() );
1712 if( nonzeros > current ) {
1713 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1736 template<
typename MT
1738 void Submatrix<MT,AF,false,false>::reserve(
size_t i,
size_t nonzeros )
1740 const size_t current(
capacity( i ) );
1741 const size_t index ( row_ + i );
1743 if( nonzeros > current ) {
1744 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1762 template<
typename MT
1764 void Submatrix<MT,AF,false,false>::trim()
1766 for(
size_t i=0UL; i<
rows(); ++i )
1785 template<
typename MT
1787 void Submatrix<MT,AF,false,false>::trim(
size_t i )
1790 matrix_.trim( row_ + i );
1814 template<
typename MT
1818 using blaze::assign;
1824 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
1828 DerestrictTrait_<This> left( derestrict( *
this ) );
1829 const ResultType tmp(
trans( *
this ) );
1831 assign( left, tmp );
1857 template<
typename MT
1861 using blaze::assign;
1867 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
1871 DerestrictTrait_<This> left( derestrict( *
this ) );
1872 const ResultType tmp(
ctrans( *
this ) );
1874 assign( left, tmp );
1893 template<
typename MT
1895 template<
typename Other >
1896 inline Submatrix<MT,AF,false,false>& Submatrix<MT,AF,false,false>::scale(
const Other& scalar )
1900 for(
size_t i=0UL; i<
rows(); ++i ) {
1901 const Iterator last(
end(i) );
1902 for( Iterator element=
begin(i); element!=last; ++element )
1903 element->value() *= scalar;
1922 template<
typename MT
1924 inline bool Submatrix<MT,AF,false,false>::hasOverlap() const noexcept
1926 BLAZE_INTERNAL_ASSERT( IsSymmetric<MT>::value || IsHermitian<MT>::value,
"Invalid matrix detected" );
1928 if( ( row_ + m_ <= column_ ) || ( column_ + n_ <= row_ ) )
1960 template<
typename MT
1963 Submatrix<MT,AF,false,false>::find(
size_t i,
size_t j )
1965 const Iterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
1967 if( pos != matrix_.end( row_ + i ) )
1992 template<
typename MT
1995 Submatrix<MT,AF,false,false>::find(
size_t i,
size_t j )
const
1997 const ConstIterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
1999 if( pos != matrix_.end( row_ + i ) )
2024 template<
typename MT
2027 Submatrix<MT,AF,false,false>::lowerBound(
size_t i,
size_t j )
2029 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2051 template<
typename MT
2054 Submatrix<MT,AF,false,false>::lowerBound(
size_t i,
size_t j )
const
2056 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), column_ );
2078 template<
typename MT
2081 Submatrix<MT,AF,false,false>::upperBound(
size_t i,
size_t j )
2083 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
2105 template<
typename MT
2108 Submatrix<MT,AF,false,false>::upperBound(
size_t i,
size_t j )
const
2110 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), column_ );
2173 template<
typename MT
2175 inline void Submatrix<MT,AF,false,false>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
2177 if( column_ + n_ == matrix_.columns() ) {
2178 matrix_.append( row_ + i, column_ + j, value, check );
2180 else if( !check || !
isDefault( value ) ) {
2181 matrix_.insert( row_ + i, column_ + j, value );
2202 template<
typename MT
2204 inline void Submatrix<MT,AF,false,false>::finalize(
size_t i )
2206 matrix_.trim( row_ + i );
2231 template<
typename MT
2233 template<
typename Other >
2234 inline bool Submatrix<MT,AF,false,false>::canAlias(
const Other* alias )
const noexcept
2236 return matrix_.isAliased( alias );
2253 template<
typename MT
2255 template<
typename Other >
2256 inline bool Submatrix<MT,AF,false,false>::isAliased(
const Other* alias )
const noexcept
2258 return matrix_.isAliased( alias );
2275 template<
typename MT
2277 inline bool Submatrix<MT,AF,false,false>::canSMPAssign() const noexcept
2297 template<
typename MT
2299 template<
typename MT2
2301 inline void Submatrix<MT,AF,false,false>::assign(
const DenseMatrix<MT2,SO>& rhs )
2308 for(
size_t i=0UL; i<
rows(); ++i ) {
2309 for(
size_t j=0UL; j<
columns(); ++j ) {
2310 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
2311 set( i, j, (~rhs)(i,j) );
2313 append( i, j, (~rhs)(i,j),
true );
2334 template<
typename MT
2336 template<
typename MT2 >
2337 inline void Submatrix<MT,AF,false,false>::assign(
const SparseMatrix<MT2,false>& rhs )
2344 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2345 for( ConstIterator_<MT2> element=(~rhs).begin(i); element!=(~rhs).
end(i); ++element ) {
2346 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
2347 set( i, element->index(), element->value() );
2349 append( i, element->index(), element->value(), true );
2370 template<
typename MT
2372 template<
typename MT2 >
2373 inline void Submatrix<MT,AF,false,false>::assign(
const SparseMatrix<MT2,true>& rhs )
2380 typedef ConstIterator_<MT2> RhsIterator;
2383 std::vector<size_t> rowLengths( m_, 0UL );
2384 for(
size_t j=0UL; j<
n_; ++j ) {
2385 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2386 ++rowLengths[element->index()];
2390 for(
size_t i=0UL; i<
m_; ++i ) {
2391 reserve( i, rowLengths[i] );
2395 for(
size_t j=0UL; j<
n_; ++j ) {
2396 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2397 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
2398 set( element->index(), j, element->value() );
2400 append( element->index(), j, element->value(), true );
2419 template<
typename MT
2421 template<
typename MT2
2423 inline void Submatrix<MT,AF,false,false>::addAssign(
const DenseMatrix<MT2,SO>& rhs )
2425 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
2433 const AddType tmp(
serial( *
this + (~rhs) ) );
2453 template<
typename MT
2455 template<
typename MT2
2457 inline void Submatrix<MT,AF,false,false>::addAssign(
const SparseMatrix<MT2,SO>& rhs )
2459 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
2467 const AddType tmp(
serial( *
this + (~rhs) ) );
2487 template<
typename MT
2489 template<
typename MT2
2491 inline void Submatrix<MT,AF,false,false>::subAssign(
const DenseMatrix<MT2,SO>& rhs )
2493 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
2501 const SubType tmp(
serial( *
this - (~rhs) ) );
2521 template<
typename MT
2523 template<
typename MT2
2525 inline void Submatrix<MT,AF,false,false>::subAssign(
const SparseMatrix<MT2,SO>& rhs )
2527 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
2535 const SubType tmp(
serial( *
this - (~rhs) ) );
2563 template<
typename MT
2565 class Submatrix<MT,AF,true,false>
2566 :
public SparseMatrix< Submatrix<MT,AF,true,false>, true >
2572 typedef If_< IsExpression<MT>, MT, MT& > Operand;
2577 typedef Submatrix<MT,AF,true,false>
This;
2578 typedef SparseMatrix<This,true>
BaseType;
2596 template<
typename MatrixType
2597 ,
typename IteratorType >
2598 class SubmatrixElement :
private SparseElement
2608 enum :
bool { returnConst = IsConst<MatrixType>::value };
2613 typedef typename std::iterator_traits<IteratorType>::value_type SET;
2615 typedef Reference_<SET> RT;
2616 typedef ConstReference_<SET> CRT;
2621 typedef ValueType_<SET> ValueType;
2622 typedef size_t IndexType;
2623 typedef IfTrue_<returnConst,CRT,RT>
Reference;
2633 inline SubmatrixElement( IteratorType pos,
size_t offset )
2645 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
2657 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
2669 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
2681 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
2693 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
2704 inline const SubmatrixElement* operator->()
const {
2714 inline Reference value()
const {
2715 return pos_->value();
2724 inline IndexType index()
const {
2725 return pos_->index() - offset_;
2740 template<
typename MatrixType
2741 ,
typename IteratorType >
2742 class SubmatrixIterator
2746 typedef std::forward_iterator_tag IteratorCategory;
2747 typedef SubmatrixElement<MatrixType,IteratorType> ValueType;
2748 typedef ValueType PointerType;
2749 typedef ValueType ReferenceType;
2750 typedef ptrdiff_t DifferenceType;
2753 typedef IteratorCategory iterator_category;
2754 typedef ValueType value_type;
2755 typedef PointerType pointer;
2756 typedef ReferenceType reference;
2757 typedef DifferenceType difference_type;
2763 inline SubmatrixIterator()
2775 inline SubmatrixIterator( IteratorType iterator,
size_t index )
2786 template<
typename MatrixType2,
typename IteratorType2 >
2787 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2788 : pos_ ( it.base() )
2789 , offset_( it.offset() )
2798 inline SubmatrixIterator& operator++() {
2809 inline const SubmatrixIterator operator++(
int ) {
2810 const SubmatrixIterator tmp( *
this );
2821 inline ReferenceType
operator*()
const {
2822 return ReferenceType( pos_, offset_ );
2831 inline PointerType operator->()
const {
2832 return PointerType( pos_, offset_ );
2842 template<
typename MatrixType2,
typename IteratorType2 >
2843 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2844 return base() == rhs.base();
2854 template<
typename MatrixType2,
typename IteratorType2 >
2855 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2856 return !( *
this == rhs );
2866 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
2867 return pos_ - rhs.pos_;
2876 inline IteratorType base()
const {
2886 inline size_t offset() const noexcept {
2901 typedef SubmatrixIterator< const MT, ConstIterator_<MT> >
ConstIterator;
2909 enum :
bool { smpAssignable = MT::smpAssignable };
2915 explicit inline Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n );
2927 inline Reference operator()(
size_t i,
size_t j );
2928 inline ConstReference operator()(
size_t i,
size_t j )
const;
2929 inline Reference at(
size_t i,
size_t j );
2930 inline ConstReference at(
size_t i,
size_t j )
const;
2931 inline Iterator
begin (
size_t i );
2932 inline ConstIterator
begin (
size_t i )
const;
2933 inline ConstIterator
cbegin(
size_t i )
const;
2934 inline Iterator
end (
size_t i );
2935 inline ConstIterator
end (
size_t i )
const;
2936 inline ConstIterator
cend (
size_t i )
const;
2943 inline Submatrix& operator=(
const Submatrix& rhs );
2945 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
2946 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
2947 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
2948 template<
typename MT2,
bool SO >
inline Submatrix&
operator*=(
const Matrix<MT2,SO>& rhs );
2950 template<
typename Other >
2951 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator*=( Other rhs );
2953 template<
typename Other >
2954 inline EnableIf_<IsNumeric<Other>, Submatrix >&
operator/=( Other rhs );
2961 inline size_t row() const noexcept;
2962 inline
size_t rows() const noexcept;
2963 inline
size_t column() const noexcept;
2964 inline
size_t columns() const noexcept;
2965 inline
size_t capacity() const noexcept;
2966 inline
size_t capacity(
size_t i ) const noexcept;
2968 inline
size_t nonZeros(
size_t i ) const;
2969 inline
void reset();
2970 inline
void reset(
size_t i );
2971 inline Iterator
set(
size_t i,
size_t j, const ElementType& value );
2972 inline Iterator insert(
size_t i,
size_t j, const ElementType& value );
2973 inline
void erase(
size_t i,
size_t j );
2974 inline Iterator erase(
size_t i, Iterator pos );
2975 inline Iterator erase(
size_t i, Iterator first, Iterator last );
2976 inline
void reserve(
size_t nonzeros );
2977 void reserve(
size_t i,
size_t nonzeros );
2979 inline
void trim(
size_t j );
2980 inline Submatrix& transpose();
2981 inline Submatrix& ctranspose();
2982 template< typename Other > inline Submatrix& scale( const Other& scalar );
2989 inline Iterator find (
size_t i,
size_t j );
2990 inline ConstIterator find (
size_t i,
size_t j ) const;
2991 inline Iterator lowerBound(
size_t i,
size_t j );
2992 inline ConstIterator lowerBound(
size_t i,
size_t j ) const;
2993 inline Iterator upperBound(
size_t i,
size_t j );
2994 inline ConstIterator upperBound(
size_t i,
size_t j ) const;
3001 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
3002 inline
void finalize(
size_t i );
3009 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
3010 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
3012 inline
bool canSMPAssign() const noexcept;
3014 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
3015 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
3016 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
3017 template< typename MT2,
bool SO > inline
void addAssign( const DenseMatrix<MT2,SO>& rhs );
3018 template< typename MT2,
bool SO > inline
void addAssign( const SparseMatrix<MT2,SO>& rhs );
3019 template< typename MT2,
bool SO > inline
void subAssign( const DenseMatrix<MT2,SO>& rhs );
3020 template< typename MT2,
bool SO > inline
void subAssign( const SparseMatrix<MT2,SO>& rhs );
3028 inline
bool hasOverlap() const noexcept;
3037 const
size_t column_;
3044 template<
bool AF1, typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3045 friend const Submatrix<MT2,AF1,SO2,DF2>
3046 submatrix( const Submatrix<MT2,AF2,SO2,DF2>& sm,
size_t row,
size_t column,
size_t m,
size_t n );
3048 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3049 friend
bool isIntact( const Submatrix<MT2,AF2,SO2,DF2>& sm ) noexcept;
3051 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3052 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Matrix<MT2,SO2>& b ) noexcept;
3054 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3055 friend
bool isSame( const Matrix<MT2,SO2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
3057 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3058 friend
bool isSame( const Submatrix<MT2,AF2,SO2,DF2>& a, const Submatrix<MT2,AF2,SO2,DF2>& b ) noexcept;
3060 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3061 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2>& lhs, const Vector<VT,TF>& rhs,
3062 size_t row,
size_t column );
3064 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3065 friend
bool tryAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3066 size_t row,
size_t column );
3068 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3069 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3070 size_t row,
size_t column );
3072 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3073 friend
bool tryAddAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3074 size_t row,
size_t column );
3076 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3077 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3078 size_t row,
size_t column );
3080 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename MT3,
bool SO3 >
3081 friend
bool trySubAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Matrix<MT3,SO3>& rhs,
3082 size_t row,
size_t column );
3084 template< typename MT2,
bool AF2,
bool SO2,
bool DF2, typename VT,
bool TF >
3085 friend
bool tryMultAssign( const Submatrix<MT2,AF2,SO2,DF2>& lhs, const Vector<VT,TF>& rhs,
3086 size_t row,
size_t column );
3088 template< typename MT2,
bool AF2,
bool SO2,
bool DF2 >
3089 friend
DerestrictTrait_< Submatrix<MT2,AF2,SO2,DF2> > derestrict( Submatrix<MT2,AF2,SO2,DF2>& sm );
3128 template< typename MT
3130 inline Submatrix<MT,AF,true,false>::Submatrix( Operand matrix,
size_t rindex,
size_t cindex,
size_t m,
size_t n )
3137 if( ( row_ + m_ > matrix_.rows() ) || ( column_ + n_ > matrix_.columns() ) ) {
3164 template<
typename MT
3167 Submatrix<MT,AF,true,false>::operator()(
size_t i,
size_t j )
3172 return matrix_(row_+i,column_+j);
3189 template<
typename MT
3192 Submatrix<MT,AF,true,false>::operator()(
size_t i,
size_t j )
const
3197 return const_cast<const MT&
>( matrix_ )(row_+i,column_+j);
3215 template<
typename MT
3218 Submatrix<MT,AF,true,false>::at(
size_t i,
size_t j )
3226 return (*
this)(i,j);
3244 template<
typename MT
3247 Submatrix<MT,AF,true,false>::at(
size_t i,
size_t j )
const
3255 return (*
this)(i,j);
3268 template<
typename MT
3276 return Iterator( matrix_.begin( j + column_ ), row_ );
3278 return Iterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3291 template<
typename MT
3299 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
3301 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3314 template<
typename MT
3322 return ConstIterator( matrix_.cbegin( j + column_ ), row_ );
3324 return ConstIterator( matrix_.lowerBound( row_, j + column_ ), row_ );
3337 template<
typename MT
3344 if( matrix_.rows() == row_ +
m_ )
3345 return Iterator( matrix_.end( j + column_ ), row_ );
3347 return Iterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3360 template<
typename MT
3367 if( matrix_.rows() == row_ +
m_ )
3370 return ConstIterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3383 template<
typename MT
3390 if( matrix_.rows() == row_ +
m_ )
3393 return ConstIterator( matrix_.lowerBound( row_ + m_, j + column_ ), row_ );
3422 template<
typename MT
3424 inline Submatrix<MT,AF,true,false>&
3425 Submatrix<MT,AF,true,false>::operator=(
const Submatrix& rhs )
3427 using blaze::assign;
3432 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ && column_ == rhs.column_ ) )
3435 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
3439 if( !tryAssign( matrix_, rhs, row_, column_ ) ) {
3443 DerestrictTrait_<This> left( derestrict( *
this ) );
3445 if( rhs.canAlias( &matrix_ ) ) {
3446 const ResultType tmp( rhs );
3448 assign( left, tmp );
3452 assign( left, rhs );
3478 template<
typename MT
3480 template<
typename MT2
3482 inline Submatrix<MT,AF,true,false>&
3483 Submatrix<MT,AF,true,false>::operator=(
const Matrix<MT2,SO>& rhs )
3485 using blaze::assign;
3493 typedef CompositeType_<MT2> Right;
3494 Right right( ~rhs );
3496 if( !tryAssign( matrix_, right, row_, column_ ) ) {
3500 DerestrictTrait_<This> left( derestrict( *
this ) );
3502 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
3503 const ResultType_<MT2> tmp( right );
3505 assign( left, tmp );
3509 assign( left, right );
3534 template<
typename MT
3536 template<
typename MT2
3538 inline Submatrix<MT,AF,true,false>&
3541 using blaze::assign;
3547 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
3555 const AddType tmp( *
this + (~rhs) );
3557 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3561 DerestrictTrait_<This> left( derestrict( *
this ) );
3564 assign( left, tmp );
3588 template<
typename MT
3590 template<
typename MT2
3592 inline Submatrix<MT,AF,true,false>&
3595 using blaze::assign;
3601 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
3609 const SubType tmp( *
this - (~rhs) );
3611 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3615 DerestrictTrait_<This> left( derestrict( *
this ) );
3618 assign( left, tmp );
3642 template<
typename MT
3644 template<
typename MT2
3646 inline Submatrix<MT,AF,true,false>&
3649 using blaze::assign;
3655 typedef MultTrait_< ResultType, ResultType_<MT2> > MultType;
3664 const MultType tmp( *
this * (~rhs) );
3666 if( !tryAssign( matrix_, tmp, row_, column_ ) ) {
3670 DerestrictTrait_<This> left( derestrict( *
this ) );
3673 assign( left, tmp );
3698 template<
typename MT
3700 template<
typename Other >
3701 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,true,false> >&
3706 for(
size_t i=0UL; i<
columns(); ++i ) {
3707 const Iterator last(
end(i) );
3708 for( Iterator element=
begin(i); element!=last; ++element )
3709 element->value() *= rhs;
3736 template<
typename MT
3738 template<
typename Other >
3739 inline EnableIf_<IsNumeric<Other>, Submatrix<MT,AF,true,false> >&
3746 typedef DivTrait_<ElementType,Other> DT;
3747 typedef If_< IsNumeric<DT>, DT, Other > Tmp;
3751 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3752 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3753 for(
size_t i=0UL; i<
columns(); ++i ) {
3754 const Iterator last(
end(i) );
3755 for( Iterator element=
begin(i); element!=last; ++element )
3756 element->value() *= tmp;
3760 for(
size_t i=0UL; i<
columns(); ++i ) {
3761 const Iterator last(
end(i) );
3762 for( Iterator element=
begin(i); element!=last; ++element )
3763 element->value() /= rhs;
3787 template<
typename MT
3803 template<
typename MT
3819 template<
typename MT
3835 template<
typename MT
3851 template<
typename MT
3855 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
3868 template<
typename MT
3873 return nonZeros( j ) + matrix_.capacity( column_+j ) - matrix_.nonZeros( column_+j );
3885 template<
typename MT
3889 size_t nonzeros( 0UL );
3891 for(
size_t i=0UL; i<
columns(); ++i )
3907 template<
typename MT
3924 template<
typename MT
3928 for(
size_t j=column_; j<column_+
n_; ++j )
3930 const size_t ibegin( ( IsLower<MT>::value )
3931 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
3932 ?(
max( j+1UL, row_ ) )
3933 :(
max( j, row_ ) ) )
3935 const size_t iend ( ( IsUpper<MT>::value )
3936 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
3937 ?(
min( j, row_+m_ ) )
3938 :(
min( j+1UL, row_+m_ ) ) )
3941 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
3955 template<
typename MT
3961 const size_t index( column_ + j );
3963 const size_t ibegin( ( IsLower<MT>::value )
3964 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
3965 ?(
max( j+1UL, row_ ) )
3966 :(
max( j, row_ ) ) )
3968 const size_t iend ( ( IsUpper<MT>::value )
3969 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
3970 ?(
min( j, row_+m_ ) )
3971 :(
min( j+1UL, row_+m_ ) ) )
3974 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
3993 template<
typename MT
3998 return Iterator( matrix_.set( row_+i, column_+j, value ), row_ );
4018 template<
typename MT
4021 Submatrix<MT,AF,true,false>::insert(
size_t i,
size_t j,
const ElementType& value )
4023 return Iterator( matrix_.insert( row_+i, column_+j, value ), row_ );
4039 template<
typename MT
4041 inline void Submatrix<MT,AF,true,false>::erase(
size_t i,
size_t j )
4046 matrix_.erase( row_ + i, column_ + j );
4062 template<
typename MT
4065 Submatrix<MT,AF,true,false>::erase(
size_t j, Iterator pos )
4068 return Iterator( matrix_.erase( column_+j, pos.base() ), row_ );
4085 template<
typename MT
4088 Submatrix<MT,AF,true,false>::erase(
size_t j, Iterator first, Iterator last )
4091 return Iterator( matrix_.erase( column_+j, first.base(), last.base() ), row_ );
4108 template<
typename MT
4110 inline void Submatrix<MT,AF,true,false>::reserve(
size_t nonzeros )
4112 const size_t current(
capacity() );
4114 if( nonzeros > current ) {
4115 matrix_.reserve( matrix_.capacity() + nonzeros - current );
4134 template<
typename MT
4136 void Submatrix<MT,AF,true,false>::reserve(
size_t j,
size_t nonzeros )
4138 const size_t current(
capacity( j ) );
4139 const size_t index ( column_ + j );
4141 if( nonzeros > current ) {
4142 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
4159 template<
typename MT
4161 void Submatrix<MT,AF,true,false>::trim()
4163 for(
size_t j=0UL; j<
columns(); ++j )
4181 template<
typename MT
4183 void Submatrix<MT,AF,true,false>::trim(
size_t j )
4186 matrix_.trim( column_ + j );
4210 template<
typename MT
4214 using blaze::assign;
4220 if( !tryAssign( matrix_,
trans( *
this ), row_, column_ ) ) {
4224 DerestrictTrait_<This> left( derestrict( *
this ) );
4225 const ResultType tmp(
trans( *
this ) );
4227 assign( left, tmp );
4253 template<
typename MT
4257 using blaze::assign;
4263 if( !tryAssign( matrix_,
ctrans( *
this ), row_, column_ ) ) {
4267 DerestrictTrait_<This> left( derestrict( *
this ) );
4268 const ResultType tmp(
ctrans(*
this) );
4270 assign( left, tmp );
4289 template<
typename MT
4291 template<
typename Other >
4292 inline Submatrix<MT,AF,true,false>& Submatrix<MT,AF,true,false>::scale(
const Other& scalar )
4296 for(
size_t i=0UL; i<
columns(); ++i ) {
4297 const Iterator last(
end(i) );
4298 for( Iterator element=
begin(i); element!=last; ++element )
4299 element->value() *= scalar;
4318 template<
typename MT
4320 inline bool Submatrix<MT,AF,true,false>::hasOverlap() const noexcept
4322 BLAZE_INTERNAL_ASSERT( IsSymmetric<MT>::value || IsHermitian<MT>::value,
"Invalid matrix detected" );
4324 if( ( row_ + m_ <= column_ ) || ( column_ + n_ <= row_ ) )
4356 template<
typename MT
4359 Submatrix<MT,AF,true,false>::find(
size_t i,
size_t j )
4361 const Iterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
4363 if( pos != matrix_.end( column_ + j ) )
4388 template<
typename MT
4391 Submatrix<MT,AF,true,false>::find(
size_t i,
size_t j )
const
4393 const ConstIterator_<MT> pos( matrix_.find( row_ + i, column_ + j ) );
4395 if( pos != matrix_.end( column_ + j ) )
4420 template<
typename MT
4423 Submatrix<MT,AF,true,false>::lowerBound(
size_t i,
size_t j )
4425 return Iterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
4447 template<
typename MT
4450 Submatrix<MT,AF,true,false>::lowerBound(
size_t i,
size_t j )
const
4452 return ConstIterator( matrix_.lowerBound( row_ + i, column_ + j ), row_ );
4474 template<
typename MT
4477 Submatrix<MT,AF,true,false>::upperBound(
size_t i,
size_t j )
4479 return Iterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
4501 template<
typename MT
4504 Submatrix<MT,AF,true,false>::upperBound(
size_t i,
size_t j )
const
4506 return ConstIterator( matrix_.upperBound( row_ + i, column_ + j ), row_ );
4569 template<
typename MT
4571 inline void Submatrix<MT,AF,true,false>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
4573 if( row_ + m_ == matrix_.rows() ) {
4574 matrix_.append( row_ + i, column_ + j, value, check );
4576 else if( !check || !
isDefault( value ) ) {
4577 matrix_.insert( row_ + i, column_ + j, value );
4598 template<
typename MT
4600 inline void Submatrix<MT,AF,true,false>::finalize(
size_t j )
4602 matrix_.trim( column_ + j );
4627 template<
typename MT
4629 template<
typename Other >
4630 inline bool Submatrix<MT,AF,true,false>::canAlias(
const Other* alias )
const noexcept
4632 return matrix_.isAliased( alias );
4649 template<
typename MT
4651 template<
typename Other >
4652 inline bool Submatrix<MT,AF,true,false>::isAliased(
const Other* alias )
const noexcept
4654 return matrix_.isAliased( alias );
4671 template<
typename MT
4673 inline bool Submatrix<MT,AF,true,false>::canSMPAssign() const noexcept
4693 template<
typename MT
4695 template<
typename MT2
4697 inline void Submatrix<MT,AF,true,false>::assign(
const DenseMatrix<MT2,SO>& rhs )
4704 for(
size_t j=0UL; j<
columns(); ++j ) {
4705 for(
size_t i=0UL; i<
rows(); ++i ) {
4706 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
4707 set( i, j, (~rhs)(i,j) );
4709 append( i, j, (~rhs)(i,j),
true );
4730 template<
typename MT
4732 template<
typename MT2 >
4733 inline void Submatrix<MT,AF,true,false>::assign(
const SparseMatrix<MT2,true>& rhs )
4740 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4741 for( ConstIterator_<MT2> element=(~rhs).begin(j); element!=(~rhs).
end(j); ++element ) {
4742 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
4743 set( element->index(), j, element->value() );
4745 append( element->index(), j, element->value(), true );
4766 template<
typename MT
4768 template<
typename MT2 >
4769 inline void Submatrix<MT,AF,true,false>::assign(
const SparseMatrix<MT2,false>& rhs )
4776 typedef ConstIterator_<MT2> RhsIterator;
4779 std::vector<size_t> columnLengths( n_, 0UL );
4780 for(
size_t i=0UL; i<
m_; ++i ) {
4781 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
4782 ++columnLengths[element->index()];
4786 for(
size_t j=0UL; j<
n_; ++j ) {
4787 reserve( j, columnLengths[j] );
4791 for(
size_t i=0UL; i<
m_; ++i ) {
4792 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
4793 if( IsSymmetric<MT>::value || IsHermitian<MT>::value )
4794 set( i, element->index(), element->value() );
4796 append( i, element->index(), element->value(), true );
4815 template<
typename MT
4817 template<
typename MT2
4819 inline void Submatrix<MT,AF,true,false>::addAssign(
const DenseMatrix<MT2,SO>& rhs )
4821 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
4829 const AddType tmp(
serial( *
this + (~rhs) ) );
4849 template<
typename MT
4851 template<
typename MT2
4853 inline void Submatrix<MT,AF,true,false>::addAssign(
const SparseMatrix<MT2,SO>& rhs )
4855 typedef AddTrait_< ResultType, ResultType_<MT2> > AddType;
4863 const AddType tmp(
serial( *
this + (~rhs) ) );
4883 template<
typename MT
4885 template<
typename MT2
4887 inline void Submatrix<MT,AF,true,false>::subAssign(
const DenseMatrix<MT2,SO>& rhs )
4889 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
4897 const SubType tmp(
serial( *
this - (~rhs) ) );
4917 template<
typename MT
4919 template<
typename MT2
4921 inline void Submatrix<MT,AF,true,false>::subAssign(
const SparseMatrix<MT2,SO>& rhs )
4923 typedef SubTrait_< ResultType, ResultType_<MT2> > SubType;
4931 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.
const DMatDMatMultExpr< T1, T2 > 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:7800
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:346
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:653
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:1195
#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:188
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 sparse matrix.
Definition: CompressedMatrix.h:2805
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2643
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1669
#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:590
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2636
#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:723
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:384
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:1716
CompressedMatrix< Type, false > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:2639
DisableIf_< Or< IsComputation< MT >, IsTransExpr< 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:126
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:298
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:232
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
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:2647
#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.
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:330
Header file for the SparseElement base class.
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2640
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:254
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2641
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2645
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
DisableIf_< Or< IsComputation< MT >, IsTransExpr< 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:126
#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:2642
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 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:2646
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:314
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2637
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2806
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:950
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2638
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:240
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2644
#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:167
Header file for the IsHermitian type trait.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
#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:564