35#ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
36#define _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_
114class Submatrix<MT,AF,false,false,CSAs...>
115 :
public View< SparseMatrix< Submatrix<MT,AF,false,false,CSAs...>, false > >
116 ,
private SubmatrixData<CSAs...>
120 using DataType = SubmatrixData<CSAs...>;
121 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
127 using This = Submatrix<MT,AF,
false,
false,CSAs...>;
130 using BaseType = View< SparseMatrix<This,false> >;
132 using ViewedType = MT;
134 using OppositeType = OppositeType_t<ResultType>;
135 using TransposeType = TransposeType_t<ResultType>;
136 using ElementType = ElementType_t<MT>;
137 using ReturnType = ReturnType_t<MT>;
138 using CompositeType =
const Submatrix&;
141 using ConstReference = ConstReference_t<MT>;
144 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
150 template<
typename MatrixType
151 ,
typename IteratorType >
152 class SubmatrixElement
153 :
private SparseElement
162 inline SubmatrixElement( IteratorType pos,
size_t offset )
174 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
186 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
198 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
210 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
222 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
233 inline const SubmatrixElement* operator->()
const {
243 inline decltype(
auto) value()
const {
244 return pos_->value();
253 inline size_t index()
const {
254 return pos_->index() - offset_;
269 template<
typename MatrixType
270 ,
typename IteratorType >
271 class SubmatrixIterator
275 using IteratorCategory = std::forward_iterator_tag;
276 using ValueType = SubmatrixElement<MatrixType,IteratorType>;
277 using PointerType = ValueType;
278 using ReferenceType = ValueType;
282 using iterator_category = IteratorCategory;
283 using value_type = ValueType;
284 using pointer = PointerType;
285 using reference = ReferenceType;
286 using difference_type = DifferenceType;
292 inline SubmatrixIterator()
304 inline SubmatrixIterator( IteratorType iterator,
size_t index )
315 template<
typename MatrixType2,
typename IteratorType2 >
316 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
318 , offset_( it.offset() )
327 inline SubmatrixIterator& operator++() {
338 inline const SubmatrixIterator operator++(
int ) {
339 const SubmatrixIterator tmp( *
this );
351 return ReferenceType( pos_, offset_ );
360 inline PointerType operator->()
const {
361 return PointerType( pos_, offset_ );
371 template<
typename MatrixType2,
typename IteratorType2 >
372 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
373 return base() == rhs.base();
383 template<
typename MatrixType2,
typename IteratorType2 >
384 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
385 return !( *
this == rhs );
395 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
396 return pos_ - rhs.pos_;
405 inline IteratorType base()
const {
415 inline size_t offset() const noexcept {
430 using ConstIterator = SubmatrixIterator< const MT, ConstIterator_t<MT> >;
433 using Iterator = If_t< IsConst_v<MT>, ConstIterator, SubmatrixIterator< MT, Iterator_t<MT> > >;
438 static constexpr bool smpAssignable = MT::smpAssignable;
441 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
447 template<
typename... RSAs >
448 explicit inline Submatrix( MT& matrix, RSAs... args );
450 Submatrix(
const Submatrix& ) =
default;
457 ~Submatrix() =
default;
464 inline Reference operator()(
size_t i,
size_t j );
465 inline ConstReference operator()(
size_t i,
size_t j )
const;
466 inline Reference at(
size_t i,
size_t j );
467 inline ConstReference at(
size_t i,
size_t j )
const;
468 inline Iterator
begin (
size_t i );
469 inline ConstIterator
begin (
size_t i )
const;
470 inline ConstIterator
cbegin(
size_t i )
const;
471 inline Iterator
end (
size_t i );
472 inline ConstIterator
end (
size_t i )
const;
473 inline ConstIterator
cend (
size_t i )
const;
481 inline Submatrix& operator=(
const Submatrix& rhs );
483 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
484 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
485 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
486 template<
typename MT2,
bool SO >
inline Submatrix& operator%=(
const Matrix<MT2,SO>& rhs );
498 inline MT& operand() noexcept;
499 inline const MT& operand() const noexcept;
501 inline
size_t capacity() const noexcept;
502 inline
size_t capacity(
size_t i ) const noexcept;
504 inline
size_t nonZeros(
size_t i ) const;
506 inline
void reset(
size_t i );
507 inline
void reserve(
size_t nonzeros );
508 void reserve(
size_t i,
size_t nonzeros );
510 inline
void trim(
size_t i );
517 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
518 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
519 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
520 inline
void finalize(
size_t i );
527 inline
void erase(
size_t i,
size_t j );
528 inline Iterator erase(
size_t i, Iterator pos );
529 inline Iterator erase(
size_t i, Iterator first, Iterator last );
531 template< typename Pred >
532 inline
void erase( Pred predicate );
534 template< typename Pred >
535 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
542 inline Iterator
find (
size_t i,
size_t j );
543 inline ConstIterator
find (
size_t i,
size_t j ) const;
544 inline Iterator
lowerBound(
size_t i,
size_t j );
545 inline ConstIterator
lowerBound(
size_t i,
size_t j ) const;
546 inline Iterator
upperBound(
size_t i,
size_t j );
547 inline ConstIterator
upperBound(
size_t i,
size_t j ) const;
557 template< typename Other > inline Submatrix& scale( const Other& scalar );
564 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
565 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
567 inline
bool canSMPAssign() const noexcept;
569 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
570 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
571 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
572 template< typename MT2,
bool SO > inline
void addAssign ( const Matrix<MT2,SO>& rhs );
573 template< typename MT2,
bool SO > inline
void subAssign ( const Matrix<MT2,SO>& rhs );
574 template< typename MT2,
bool SO > inline
void schurAssign( const Matrix<MT2,SO>& rhs );
624template< typename... RSAs >
625inline Submatrix<MT,AF,false,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
626 : DataType( args... )
665inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Reference
666 Submatrix<MT,AF,false,false,CSAs...>::operator()(
size_t i,
size_t j )
691inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstReference
692 Submatrix<MT,AF,false,false,CSAs...>::operator()(
size_t i,
size_t j )
const
697 return const_cast<const MT&
>( matrix_ )(
row()+i,
column()+j);
718inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Reference
719 Submatrix<MT,AF,false,false,CSAs...>::at(
size_t i,
size_t j )
748inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstReference
749 Submatrix<MT,AF,false,false,CSAs...>::at(
size_t i,
size_t j )
const
778inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
784 return Iterator( matrix_.begin( i +
row() ),
column() );
786 return Iterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
807inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
813 return ConstIterator( matrix_.cbegin( i +
row() ),
column() );
815 return ConstIterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
836inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
842 return ConstIterator( matrix_.cbegin( i +
row() ),
column() );
844 return ConstIterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
865inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
871 return Iterator( matrix_.end( i +
row() ),
column() );
894inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
900 return ConstIterator( matrix_.cend( i +
row() ),
column() );
923inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
929 return ConstIterator( matrix_.cend( i +
row() ),
column() );
964inline Submatrix<MT,AF,
false,
false,CSAs...>&
969 if( list.size() !=
rows() ) {
973 const InitializerMatrix<ElementType> tmp( list,
columns() );
975 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
979 decltype(
auto) left( derestrict( *
this ) );
1005template<
typename MT
1008inline Submatrix<MT,AF,
false,
false,CSAs...>&
1009 Submatrix<MT,AF,false,false,CSAs...>::operator=(
const Submatrix& rhs )
1011 using blaze::assign;
1016 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ &&
row() == rhs.row() &&
column() == rhs.column() ) )
1019 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
1023 if( !tryAssign( matrix_, rhs,
row(),
column() ) ) {
1027 decltype(
auto) left( derestrict( *
this ) );
1029 if( rhs.canAlias(
this ) ) {
1030 const ResultType tmp( rhs );
1032 assign( left, tmp );
1036 assign( left, rhs );
1062template<
typename MT
1065template<
typename MT2
1067inline Submatrix<MT,AF,
false,
false,CSAs...>&
1068 Submatrix<MT,AF,false,false,CSAs...>::operator=(
const Matrix<MT2,SO>& rhs )
1070 using blaze::assign;
1074 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
1078 using Right = CompositeType_t<MT2>;
1079 Right right( *rhs );
1081 if( !tryAssign( matrix_, right,
row(),
column() ) ) {
1085 decltype(
auto) left( derestrict( *
this ) );
1087 if( IsReference_v<Right> && right.canAlias(
this ) ) {
1088 const ResultType_t<MT2> tmp( right );
1090 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
1094 assign( left,
transIf< IsSymmetric_v<This> >( right ) );
1119template<
typename MT
1122template<
typename MT2
1124inline Submatrix<MT,AF,
false,
false,CSAs...>&
1127 using blaze::assign;
1133 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
1137 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
1141 const AddType tmp( *
this + (*rhs) );
1143 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1147 decltype(
auto) left( derestrict( *
this ) );
1150 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
1174template<
typename MT
1177template<
typename MT2
1179inline Submatrix<MT,AF,
false,
false,CSAs...>&
1182 using blaze::assign;
1188 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
1192 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
1196 const SubType tmp( *
this - (*rhs) );
1198 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1202 decltype(
auto) left( derestrict( *
this ) );
1205 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
1229template<
typename MT
1232template<
typename MT2
1234inline Submatrix<MT,AF,
false,
false,CSAs...>&
1235 Submatrix<MT,AF,false,false,CSAs...>::operator%=(
const Matrix<MT2,SO>& rhs )
1237 using blaze::assign;
1243 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
1247 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
1251 const SchurType tmp( *
this % (*rhs) );
1253 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1257 decltype(
auto) left( derestrict( *
this ) );
1260 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
1284template<
typename MT
1287inline MT& Submatrix<MT,AF,false,false,CSAs...>::operand() noexcept
1301template<
typename MT
1304inline const MT& Submatrix<MT,AF,false,false,CSAs...>::operand() const noexcept
1318template<
typename MT
1323 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1341template<
typename MT
1347 return nonZeros( i ) + matrix_.capacity(
row()+i ) - matrix_.nonZeros(
row()+i );
1359template<
typename MT
1364 size_t nonzeros( 0UL );
1366 for(
size_t i=0UL; i<
rows(); ++i )
1387template<
typename MT
1405template<
typename MT
1412 const size_t jbegin( ( IsUpper_v<MT> )
1413 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1417 const size_t jend ( ( IsLower_v<MT> )
1418 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1423 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1442template<
typename MT
1449 const size_t index(
row() + i );
1451 const size_t jbegin( ( IsUpper_v<MT> )
1452 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1456 const size_t jend ( ( IsLower_v<MT> )
1457 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1462 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1479template<
typename MT
1482inline void Submatrix<MT,AF,false,false,CSAs...>::reserve(
size_t nonzeros )
1484 const size_t current(
capacity() );
1486 if( nonzeros > current ) {
1487 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1510template<
typename MT
1513void Submatrix<MT,AF,false,false,CSAs...>::reserve(
size_t i,
size_t nonzeros )
1515 const size_t current(
capacity( i ) );
1516 const size_t index (
row() + i );
1518 if( nonzeros > current ) {
1519 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1537template<
typename MT
1540void Submatrix<MT,AF,false,false,CSAs...>::trim()
1542 for(
size_t i=0UL; i<
rows(); ++i )
1561template<
typename MT
1564void Submatrix<MT,AF,false,false,CSAs...>::trim(
size_t i )
1567 matrix_.trim(
row() + i );
1594template<
typename MT
1597inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1600 return Iterator( matrix_.set(
row()+i,
column()+j, value ),
column() );
1620template<
typename MT
1623inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1624 Submatrix<MT,AF,false,false,CSAs...>::insert(
size_t i,
size_t j,
const ElementType& value )
1626 return Iterator( matrix_.insert(
row()+i,
column()+j, value ),
column() );
1676template<
typename MT
1679inline void Submatrix<MT,AF,false,false,CSAs...>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
1682 matrix_.append(
row() + i,
column() + j, value, check );
1684 else if( !check || !isDefault<strict>( value ) ) {
1685 matrix_.insert(
row() + i,
column() + j, value );
1706template<
typename MT
1709inline void Submatrix<MT,AF,false,false,CSAs...>::finalize(
size_t i )
1711 matrix_.trim(
row() + i );
1735template<
typename MT
1738inline void Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i,
size_t j )
1743 matrix_.erase(
row() + i,
column() + j );
1761template<
typename MT
1764inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1765 Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator pos )
1768 return Iterator( matrix_.erase(
row()+i, pos.base() ),
column() );
1788template<
typename MT
1791inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1792 Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator first, Iterator last )
1795 return Iterator( matrix_.erase(
row()+i, first.base(), last.base() ),
column() );
1824template<
typename MT
1827template<
typename Pred >
1828inline void Submatrix<MT,AF,false,false,CSAs...>::erase( Pred predicate )
1830 for(
size_t i=0UL; i<
rows(); ++i ) {
1831 matrix_.erase(
row()+i,
begin(i).base(),
end(i).base(), predicate );
1867template<
typename MT
1870template<
typename Pred >
1871inline void Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator first, Iterator last, Pred predicate )
1874 matrix_.erase(
row()+i, first.base(), last.base(), predicate );
1904template<
typename MT
1907inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1910 const Iterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
1912 if( pos != matrix_.end(
row() + i ) )
1913 return Iterator( pos,
column() );
1937template<
typename MT
1940inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
1943 const ConstIterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
1945 if( pos != matrix_.end(
row() + i ) )
1946 return ConstIterator( pos,
column() );
1970template<
typename MT
1973inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1976 return Iterator( matrix_.lowerBound(
row() + i,
column() + j ),
column() );
1998template<
typename MT
2001inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
2004 return ConstIterator( matrix_.lowerBound(
row() + i,
column() + j ),
column() );
2026template<
typename MT
2029inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
2032 return Iterator( matrix_.upperBound(
row() + i,
column() + j ),
column() );
2054template<
typename MT
2057inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
2060 return ConstIterator( matrix_.upperBound(
row() + i,
column() + j ),
column() );
2092template<
typename MT
2095inline Submatrix<MT,AF,
false,
false,CSAs...>&
2098 using blaze::assign;
2108 decltype(
auto) left( derestrict( *
this ) );
2109 const ResultType tmp(
trans( *
this ) );
2112 assign( left, tmp );
2138template<
typename MT
2141inline Submatrix<MT,AF,
false,
false,CSAs...>&
2144 using blaze::assign;
2154 decltype(
auto) left( derestrict( *
this ) );
2155 const ResultType tmp(
ctrans( *
this ) );
2158 assign( left, tmp );
2179template<
typename MT
2182template<
typename Other >
2183inline Submatrix<MT,AF,
false,
false,CSAs...>&
2184 Submatrix<MT,AF,false,false,CSAs...>::scale(
const Other& scalar )
2188 for(
size_t i=0UL; i<
rows(); ++i ) {
2189 const Iterator last(
end(i) );
2190 for( Iterator element=
begin(i); element!=last; ++element )
2191 element->value() *= scalar;
2219template<
typename MT
2222template<
typename Other >
2223inline bool Submatrix<MT,AF,false,false,CSAs...>::canAlias(
const Other* alias )
const noexcept
2225 return matrix_.isAliased( &unview( *alias ) );
2242template<
typename MT
2245template<
typename Other >
2246inline bool Submatrix<MT,AF,false,false,CSAs...>::isAliased(
const Other* alias )
const noexcept
2248 return matrix_.isAliased( &unview( *alias ) );
2265template<
typename MT
2268inline bool Submatrix<MT,AF,false,false,CSAs...>::canSMPAssign() const noexcept
2288template<
typename MT
2291template<
typename MT2
2293inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const DenseMatrix<MT2,SO>& rhs )
2300 for(
size_t i=0UL; i<
rows(); ++i ) {
2301 for(
size_t j=0UL; j<
columns(); ++j ) {
2302 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2303 const ElementType& value( (*rhs)(i,j) );
2304 if( !isDefault<strict>( value ) )
2308 append( i, j, (*rhs)(i,j),
true );
2330template<
typename MT
2333template<
typename MT2 >
2334inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const SparseMatrix<MT2,false>& rhs )
2339 reserve( 0UL, (*rhs).nonZeros() );
2341 for(
size_t i=0UL; i<(*rhs).rows(); ++i ) {
2342 for( ConstIterator_t<MT2> element=(*rhs).begin(i); element!=(*rhs).end(i); ++element ) {
2343 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2344 const ElementType& value( element->value() );
2345 if( !isDefault<strict>( value ) )
2346 set( i, element->index(), value );
2349 append( i, element->index(), element->value(),
true );
2371template<
typename MT
2374template<
typename MT2 >
2375inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const SparseMatrix<MT2,true>& rhs )
2383 std::vector<size_t> rowLengths(
rows(), 0UL );
2384 for(
size_t j=0UL; j<
columns(); ++j ) {
2385 for(
auto element=(*rhs).begin(j); element!=(*rhs).end(j); ++element )
2386 ++rowLengths[element->index()];
2390 for(
size_t i=0UL; i<
rows(); ++i ) {
2391 reserve( i, rowLengths[i] );
2395 for(
size_t j=0UL; j<
columns(); ++j ) {
2396 for(
auto element=(*rhs).begin(j); element!=(*rhs).end(j); ++element )
2397 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2398 const ElementType& value( element->value() );
2399 if( !isDefault<strict>( value ) )
2400 set( element->index(), j, value );
2403 append( element->index(), j, element->value(),
true );
2423template<
typename MT
2426template<
typename MT2
2428inline void Submatrix<MT,AF,false,false,CSAs...>::addAssign(
const Matrix<MT2,SO>& rhs )
2430 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
2437 const AddType tmp(
serial( *
this + (*rhs) ) );
2457template<
typename MT
2460template<
typename MT2
2462inline void Submatrix<MT,AF,false,false,CSAs...>::subAssign(
const Matrix<MT2,SO>& rhs )
2464 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
2471 const SubType tmp(
serial( *
this - (*rhs) ) );
2491template<
typename MT
2494template<
typename MT2
2496inline void Submatrix<MT,AF,false,false,CSAs...>::schurAssign(
const Matrix<MT2,SO>& rhs )
2498 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
2506 const SchurType tmp(
serial( *
this % (*rhs) ) );
2534template<
typename MT
2537class Submatrix<MT,AF,true,false,CSAs...>
2538 :
public View< SparseMatrix< Submatrix<MT,AF,true,false,CSAs...>, true > >
2539 ,
private SubmatrixData<CSAs...>
2543 using DataType = SubmatrixData<CSAs...>;
2544 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2550 using This = Submatrix<MT,AF,
true,
false,CSAs...>;
2553 using BaseType = View< SparseMatrix<This,true> >;
2555 using ViewedType = MT;
2557 using OppositeType = OppositeType_t<ResultType>;
2558 using TransposeType = TransposeType_t<ResultType>;
2559 using ElementType = ElementType_t<MT>;
2560 using ReturnType = ReturnType_t<MT>;
2561 using CompositeType =
const Submatrix&;
2564 using ConstReference = ConstReference_t<MT>;
2567 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2573 template<
typename MatrixType
2574 ,
typename IteratorType >
2575 class SubmatrixElement
2576 :
private SparseElement
2585 inline SubmatrixElement( IteratorType pos,
size_t offset )
2597 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
2609 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
2621 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
2633 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
2645 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
2656 inline const SubmatrixElement* operator->()
const {
2666 inline decltype(
auto) value()
const {
2667 return pos_->value();
2676 inline size_t index()
const {
2677 return pos_->index() - offset_;
2692 template<
typename MatrixType
2693 ,
typename IteratorType >
2694 class SubmatrixIterator
2698 using IteratorCategory = std::forward_iterator_tag;
2699 using ValueType = SubmatrixElement<MatrixType,IteratorType>;
2700 using PointerType = ValueType;
2701 using ReferenceType = ValueType;
2705 using iterator_category = IteratorCategory;
2706 using value_type = ValueType;
2707 using pointer = PointerType;
2708 using reference = ReferenceType;
2709 using difference_type = DifferenceType;
2715 inline SubmatrixIterator()
2727 inline SubmatrixIterator( IteratorType iterator,
size_t index )
2738 template<
typename MatrixType2,
typename IteratorType2 >
2739 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2740 : pos_ ( it.base() )
2741 , offset_( it.offset() )
2750 inline SubmatrixIterator& operator++() {
2761 inline const SubmatrixIterator operator++(
int ) {
2762 const SubmatrixIterator tmp( *
this );
2773 inline ReferenceType
operator*()
const {
2774 return ReferenceType( pos_, offset_ );
2783 inline PointerType operator->()
const {
2784 return PointerType( pos_, offset_ );
2794 template<
typename MatrixType2,
typename IteratorType2 >
2795 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2796 return base() == rhs.base();
2806 template<
typename MatrixType2,
typename IteratorType2 >
2807 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2808 return !( *
this == rhs );
2818 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
2819 return pos_ - rhs.pos_;
2828 inline IteratorType base()
const {
2838 inline size_t offset() const noexcept {
2853 using ConstIterator = SubmatrixIterator< const MT, ConstIterator_t<MT> >;
2856 using Iterator = If_t< IsConst_v<MT>, ConstIterator, SubmatrixIterator< MT, Iterator_t<MT> > >;
2861 static constexpr bool smpAssignable = MT::smpAssignable;
2864 static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
2870 template<
typename... RSAs >
2871 explicit inline Submatrix( MT& matrix, RSAs... args );
2873 Submatrix(
const Submatrix& ) =
default;
2880 ~Submatrix() =
default;
2887 inline Reference operator()(
size_t i,
size_t j );
2888 inline ConstReference operator()(
size_t i,
size_t j )
const;
2889 inline Reference at(
size_t i,
size_t j );
2890 inline ConstReference at(
size_t i,
size_t j )
const;
2891 inline Iterator
begin (
size_t i );
2892 inline ConstIterator
begin (
size_t i )
const;
2893 inline ConstIterator
cbegin(
size_t i )
const;
2894 inline Iterator
end (
size_t i );
2895 inline ConstIterator
end (
size_t i )
const;
2896 inline ConstIterator
cend (
size_t i )
const;
2904 inline Submatrix& operator=(
const Submatrix& rhs );
2906 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
2907 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
2908 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
2909 template<
typename MT2,
bool SO >
inline Submatrix& operator%=(
const Matrix<MT2,SO>& rhs );
2921 inline MT& operand() noexcept;
2922 inline const MT& operand() const noexcept;
2924 inline
size_t capacity() const noexcept;
2925 inline
size_t capacity(
size_t i ) const noexcept;
2927 inline
size_t nonZeros(
size_t i ) const;
2928 inline
void reset();
2929 inline
void reset(
size_t i );
2930 inline
void reserve(
size_t nonzeros );
2931 void reserve(
size_t i,
size_t nonzeros );
2933 inline
void trim(
size_t j );
2940 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
2941 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
2942 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
2943 inline
void finalize(
size_t i );
2950 inline
void erase(
size_t i,
size_t j );
2951 inline Iterator erase(
size_t i, Iterator pos );
2952 inline Iterator erase(
size_t i, Iterator first, Iterator last );
2954 template< typename Pred >
2955 inline
void erase( Pred predicate );
2957 template< typename Pred >
2958 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
2965 inline Iterator
find (
size_t i,
size_t j );
2966 inline ConstIterator
find (
size_t i,
size_t j ) const;
2967 inline Iterator
lowerBound(
size_t i,
size_t j );
2968 inline ConstIterator
lowerBound(
size_t i,
size_t j ) const;
2969 inline Iterator
upperBound(
size_t i,
size_t j );
2970 inline ConstIterator
upperBound(
size_t i,
size_t j ) const;
2980 template< typename Other > inline Submatrix& scale( const Other& scalar );
2987 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
2988 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
2990 inline
bool canSMPAssign() const noexcept;
2992 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
2993 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
2994 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
2995 template< typename MT2,
bool SO > inline
void addAssign ( const Matrix<MT2,SO>& rhs );
2996 template< typename MT2,
bool SO > inline
void subAssign ( const Matrix<MT2,SO>& rhs );
2997 template< typename MT2,
bool SO > inline
void schurAssign( const Matrix<MT2,SO>& rhs );
3044template< typename MT
3047template< typename... RSAs >
3048inline Submatrix<MT,AF,true,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
3049 : DataType( args... )
3050 , matrix_ ( matrix )
3085template<
typename MT
3088inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Reference
3089 Submatrix<MT,AF,true,false,CSAs...>::operator()(
size_t i,
size_t j )
3111template<
typename MT
3114inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstReference
3115 Submatrix<MT,AF,true,false,CSAs...>::operator()(
size_t i,
size_t j )
const
3120 return const_cast<const MT&
>( matrix_ )(
row()+i,
column()+j);
3138template<
typename MT
3141inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Reference
3142 Submatrix<MT,AF,true,false,CSAs...>::at(
size_t i,
size_t j )
3150 return (*
this)(i,j);
3168template<
typename MT
3171inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstReference
3172 Submatrix<MT,AF,true,false,CSAs...>::at(
size_t i,
size_t j )
const
3180 return (*
this)(i,j);
3193template<
typename MT
3196inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3202 return Iterator( matrix_.begin( j +
column() ),
row() );
3204 return Iterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3217template<
typename MT
3220inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3226 return ConstIterator( matrix_.cbegin( j +
column() ),
row() );
3228 return ConstIterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3241template<
typename MT
3244inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3250 return ConstIterator( matrix_.cbegin( j +
column() ),
row() );
3252 return ConstIterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3265template<
typename MT
3268inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3273 if( matrix_.rows() ==
row() +
rows() )
3274 return Iterator( matrix_.end( j +
column() ),
row() );
3276 return Iterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3289template<
typename MT
3292inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3297 if( matrix_.rows() ==
row() +
rows() )
3298 return ConstIterator( matrix_.cend( j +
column() ),
row() );
3300 return ConstIterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3313template<
typename MT
3316inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3321 if( matrix_.rows() ==
row() +
rows() )
3322 return ConstIterator( matrix_.cend( j +
column() ),
row() );
3324 return ConstIterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3354template<
typename MT
3357inline Submatrix<MT,AF,
true,
false,CSAs...>&
3360 using blaze::assign;
3362 if( list.size() !=
rows() ) {
3366 const InitializerMatrix<ElementType> tmp( list,
columns() );
3368 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3372 decltype(
auto) left( derestrict( *
this ) );
3375 assign( left, tmp );
3398template<
typename MT
3401inline Submatrix<MT,AF,
true,
false,CSAs...>&
3402 Submatrix<MT,AF,true,false,CSAs...>::operator=(
const Submatrix& rhs )
3404 using blaze::assign;
3409 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ &&
row() == rhs.row() &&
column() == rhs.column() ) )
3412 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
3416 if( !tryAssign( matrix_, rhs,
row(),
column() ) ) {
3420 decltype(
auto) left( derestrict( *
this ) );
3422 if( rhs.canAlias(
this ) ) {
3423 const ResultType tmp( rhs );
3425 assign( left, tmp );
3429 assign( left, rhs );
3455template<
typename MT
3458template<
typename MT2
3460inline Submatrix<MT,AF,
true,
false,CSAs...>&
3461 Submatrix<MT,AF,true,false,CSAs...>::operator=(
const Matrix<MT2,SO>& rhs )
3463 using blaze::assign;
3467 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
3471 using Right = CompositeType_t<MT2>;
3472 Right right( *rhs );
3474 if( !tryAssign( matrix_, right,
row(),
column() ) ) {
3478 decltype(
auto) left( derestrict( *
this ) );
3480 if( IsReference_v<Right> && right.canAlias(
this ) ) {
3481 const ResultType_t<MT2> tmp( right );
3483 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
3487 assign( left,
transIf< IsSymmetric_v<This> >( right ) );
3512template<
typename MT
3515template<
typename MT2
3517inline Submatrix<MT,AF,
true,
false,CSAs...>&
3520 using blaze::assign;
3526 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
3530 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
3534 const AddType tmp( *
this + (*rhs) );
3536 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3540 decltype(
auto) left( derestrict( *
this ) );
3543 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
3567template<
typename MT
3570template<
typename MT2
3572inline Submatrix<MT,AF,
true,
false,CSAs...>&
3575 using blaze::assign;
3581 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
3585 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
3589 const SubType tmp( *
this - (*rhs) );
3591 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3595 decltype(
auto) left( derestrict( *
this ) );
3598 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
3622template<
typename MT
3625template<
typename MT2
3627inline Submatrix<MT,AF,
true,
false,CSAs...>&
3628 Submatrix<MT,AF,true,false,CSAs...>::operator%=(
const Matrix<MT2,SO>& rhs )
3630 using blaze::assign;
3636 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
3640 if(
rows() != (*rhs).rows() ||
columns() != (*rhs).columns() ) {
3644 const SchurType tmp( *
this % (*rhs) );
3646 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3650 decltype(
auto) left( derestrict( *
this ) );
3653 assign( left,
transIf< IsSymmetric_v<This> >( tmp ) );
3677template<
typename MT
3680inline MT& Submatrix<MT,AF,true,false,CSAs...>::operand() noexcept
3694template<
typename MT
3697inline const MT& Submatrix<MT,AF,true,false,CSAs...>::operand() const noexcept
3711template<
typename MT
3716 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
3729template<
typename MT
3747template<
typename MT
3752 size_t nonzeros( 0UL );
3754 for(
size_t i=0UL; i<
columns(); ++i )
3770template<
typename MT
3788template<
typename MT
3795 const size_t ibegin( ( IsLower_v<MT> )
3796 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3800 const size_t iend ( ( IsUpper_v<MT> )
3801 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3806 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
3820template<
typename MT
3827 const size_t index(
column() + j );
3829 const size_t ibegin( ( IsLower_v<MT> )
3830 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3834 const size_t iend ( ( IsUpper_v<MT> )
3835 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3840 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
3857template<
typename MT
3860inline void Submatrix<MT,AF,true,false,CSAs...>::reserve(
size_t nonzeros )
3862 const size_t current(
capacity() );
3864 if( nonzeros > current ) {
3865 matrix_.reserve( matrix_.capacity() + nonzeros - current );
3884template<
typename MT
3887void Submatrix<MT,AF,true,false,CSAs...>::reserve(
size_t j,
size_t nonzeros )
3889 const size_t current(
capacity( j ) );
3890 const size_t index (
column() + j );
3892 if( nonzeros > current ) {
3893 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
3910template<
typename MT
3913void Submatrix<MT,AF,true,false,CSAs...>::trim()
3915 for(
size_t j=0UL; j<
columns(); ++j )
3933template<
typename MT
3936void Submatrix<MT,AF,true,false,CSAs...>::trim(
size_t j )
3939 matrix_.trim(
column() + j );
3966template<
typename MT
3969inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3972 return Iterator( matrix_.set(
row()+i,
column()+j, value ),
row() );
3992template<
typename MT
3995inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3996 Submatrix<MT,AF,true,false,CSAs...>::insert(
size_t i,
size_t j,
const ElementType& value )
3998 return Iterator( matrix_.insert(
row()+i,
column()+j, value ),
row() );
4048template<
typename MT
4051inline void Submatrix<MT,AF,true,false,CSAs...>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
4053 if(
row() +
rows() == matrix_.rows() ) {
4054 matrix_.append(
row() + i,
column() + j, value, check );
4056 else if( !check || !isDefault<strict>( value ) ) {
4057 matrix_.insert(
row() + i,
column() + j, value );
4078template<
typename MT
4081inline void Submatrix<MT,AF,true,false,CSAs...>::finalize(
size_t j )
4083 matrix_.trim(
column() + j );
4107template<
typename MT
4110inline void Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t i,
size_t j )
4115 matrix_.erase(
row() + i,
column() + j );
4131template<
typename MT
4134inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4135 Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator pos )
4138 return Iterator( matrix_.erase(
column()+j, pos.base() ),
row() );
4155template<
typename MT
4158inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4159 Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator first, Iterator last )
4162 return Iterator( matrix_.erase(
column()+j, first.base(), last.base() ),
row() );
4191template<
typename MT
4194template<
typename Pred >
4195inline void Submatrix<MT,AF,true,false,CSAs...>::erase( Pred predicate )
4197 for(
size_t j=0UL; j<
columns(); ++j ) {
4198 matrix_.erase(
column()+j,
begin(j).base(),
end(j).base(), predicate );
4231template<
typename MT
4234template<
typename Pred >
4235inline void Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator first, Iterator last, Pred predicate )
4238 matrix_.erase(
column()+j, first.base(), last.base(), predicate );
4268template<
typename MT
4271inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4274 const Iterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
4276 if( pos != matrix_.end(
column() + j ) )
4277 return Iterator( pos,
row() );
4301template<
typename MT
4304inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4307 const ConstIterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
4309 if( pos != matrix_.end(
column() + j ) )
4310 return ConstIterator( pos,
row() );
4334template<
typename MT
4337inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4340 return Iterator( matrix_.lowerBound(
row() + i,
column() + j ),
row() );
4362template<
typename MT
4365inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4368 return ConstIterator( matrix_.lowerBound(
row() + i,
column() + j ),
row() );
4390template<
typename MT
4393inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4396 return Iterator( matrix_.upperBound(
row() + i,
column() + j ),
row() );
4418template<
typename MT
4421inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4424 return ConstIterator( matrix_.upperBound(
row() + i,
column() + j ),
row() );
4456template<
typename MT
4459inline Submatrix<MT,AF,
true,
false,CSAs...>&
4462 using blaze::assign;
4472 decltype(
auto) left( derestrict( *
this ) );
4473 const ResultType tmp(
trans( *
this ) );
4476 assign( left, tmp );
4502template<
typename MT
4505inline Submatrix<MT,AF,
true,
false,CSAs...>&
4508 using blaze::assign;
4518 decltype(
auto) left( derestrict( *
this ) );
4519 const ResultType tmp(
ctrans(*
this) );
4522 assign( left, tmp );
4543template<
typename MT
4546template<
typename Other >
4547inline Submatrix<MT,AF,
true,
false,CSAs...>&
4548 Submatrix<MT,AF,true,false,CSAs...>::scale(
const Other& scalar )
4552 for(
size_t i=0UL; i<
columns(); ++i ) {
4553 const Iterator last(
end(i) );
4554 for( Iterator element=
begin(i); element!=last; ++element )
4555 element->value() *= scalar;
4583template<
typename MT
4586template<
typename Other >
4587inline bool Submatrix<MT,AF,true,false,CSAs...>::canAlias(
const Other* alias )
const noexcept
4589 return matrix_.isAliased( &unview( *alias ) );
4606template<
typename MT
4609template<
typename Other >
4610inline bool Submatrix<MT,AF,true,false,CSAs...>::isAliased(
const Other* alias )
const noexcept
4612 return matrix_.isAliased( &unview( *alias ) );
4629template<
typename MT
4632inline bool Submatrix<MT,AF,true,false,CSAs...>::canSMPAssign() const noexcept
4652template<
typename MT
4655template<
typename MT2
4657inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const DenseMatrix<MT2,SO>& rhs )
4664 for(
size_t j=0UL; j<
columns(); ++j ) {
4665 for(
size_t i=0UL; i<
rows(); ++i ) {
4666 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4667 const ElementType& value( (*rhs)(i,j) );
4668 if( !isDefault<strict>( value ) )
4672 append( i, j, (*rhs)(i,j),
true );
4694template<
typename MT
4697template<
typename MT2 >
4698inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const SparseMatrix<MT2,true>& rhs )
4703 reserve( 0UL, (*rhs).nonZeros() );
4705 for(
size_t j=0UL; j<(*rhs).columns(); ++j ) {
4706 for( ConstIterator_t<MT2> element=(*rhs).begin(j); element!=(*rhs).end(j); ++element ) {
4707 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4708 const ElementType& value( element->value() );
4709 if( !isDefault<strict>( value ) )
4710 set( element->index(), j, value );
4713 append( element->index(), j, element->value(),
true );
4734template<
typename MT
4737template<
typename MT2 >
4738inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const SparseMatrix<MT2,false>& rhs )
4746 std::vector<size_t> columnLengths(
columns(), 0UL );
4747 for(
size_t i=0UL; i<
rows(); ++i ) {
4748 for(
auto element=(*rhs).begin(i); element!=(*rhs).end(i); ++element )
4749 ++columnLengths[element->index()];
4753 for(
size_t j=0UL; j<
columns(); ++j ) {
4754 reserve( j, columnLengths[j] );
4758 for(
size_t i=0UL; i<
rows(); ++i ) {
4759 for(
auto element=(*rhs).begin(i); element!=(*rhs).end(i); ++element )
4760 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4761 const ElementType& value( element->value() );
4762 if( !isDefault<strict>( value ) )
4763 set( i, element->index(), value );
4766 append( i, element->index(), element->value(),
true );
4786template<
typename MT
4789template<
typename MT2
4791inline void Submatrix<MT,AF,true,false,CSAs...>::addAssign(
const Matrix<MT2,SO>& rhs )
4793 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
4800 const AddType tmp(
serial( *
this + (*rhs) ) );
4820template<
typename MT
4823template<
typename MT2
4825inline void Submatrix<MT,AF,true,false,CSAs...>::subAssign(
const Matrix<MT2,SO>& rhs )
4827 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
4834 const SubType tmp(
serial( *
this - (*rhs) ) );
4854template<
typename MT
4857template<
typename MT2
4859inline void Submatrix<MT,AF,true,false,CSAs...>::schurAssign(
const Matrix<MT2,SO>& rhs )
4861 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
4868 const SchurType tmp(
serial( *
this % (*rhs) ) );
Header file for the addition trait.
Header file for auxiliary alias declarations.
Header file for the alignment flag enumeration.
Header file for run time assertion macros.
Header file for the blaze::checked and blaze::unchecked instances.
Constraints on the storage order of matrix types.
constexpr 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:751
Header file for the If class template.
Header file for the IsConst type trait.
Header file for the isDefault shim.
Header file for the IsExpression type trait class.
Header file for the IsHermitian type trait.
Header file for the IsLower type trait.
Header file for the IsReference type trait.
Header file for the IsStrictlyLower type trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Header file for the IsUniLower type trait.
Header file for the IsUniUpper type trait.
Header file for the IsUpper type trait.
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
Header file for the Schur product trait.
Header file for the subtraction trait.
Header file for the implementation of the SubmatrixData class template.
Header file for the submatrix trait.
Constraint on the data type.
Constraint on the data type.
Initializer list type of the Blaze library.
Pointer difference type of the Blaze library.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the implementation of a matrix representation of an initializer list.
Header file for the SparseMatrix base class.
Header file for the View base class.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:574
decltype(auto) transIf(const DenseMatrix< MT, SO > &dm)
Conditional calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:832
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1339
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1501
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:766
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:386
auto operator*=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:510
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:812
decltype(auto) operator*(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9640
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsScalar_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:448
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.
Definition: Symmetric.h:79
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: RowMajorMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.
Definition: RequiresEvaluation.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.
Definition: TransExpr.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBMATRIX_TYPE(T)
Constraint on the data type.
Definition: Submatrix.h:81
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.
Definition: Computation.h:81
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.
Definition: SparseMatrix.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: UniTriangular.h:81
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.
Definition: ColumnMajorMatrix.h:61
typename SubmatrixTrait< MT, CSAs... >::Type SubmatrixTrait_t
Auxiliary alias declaration for the SubmatrixTrait type trait.
Definition: SubmatrixTrait.h:145
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.
Definition: AlignmentFlag.h:63
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
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:628
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:730
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:562
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:692
constexpr void reset(Matrix< MT, SO > &matrix)
Resetting the given matrix.
Definition: Matrix.h:806
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
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:584
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:1221
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:518
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:1195
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:137
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
MT::Iterator upperBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: SparseMatrix.h:244
MT::Iterator lowerBound(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: SparseMatrix.h:194
MT::Iterator find(SparseMatrix< MT, SO > &sm, size_t i, size_t j)
Searches for a specific matrix element.
Definition: SparseMatrix.h:144
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.
Definition: Exception.h:331
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_THROW_LOGIC_ERROR(MESSAGE)
Macro for the emission of a std::logic_error exception.
Definition: Exception.h:187
constexpr bool isChecked(const Ts &... args)
Extracting blaze::Check arguments from a given list of arguments.
Definition: Check.h:225
Header file for the exception macros of the math module.
Header file for the extended initializer_list functionality.
Header file for the matrix storage order types.
Header file for the reset shim.
Header file for the serial shim.
Header file for the SparseElement base class.
Header file for basic type definitions.
Header file for the generic max algorithm.
Header file for the generic min algorithm.
Header file for the implementation of the Submatrix base template.