35 #ifndef _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_ 36 #define _BLAZE_MATH_VIEWS_SUBMATRIX_SPARSE_H_ 113 template<
typename MT
116 class Submatrix<MT,AF,false,false,CSAs...>
117 :
public View< SparseMatrix< Submatrix<MT,AF,false,false,CSAs...>, false > >
118 ,
private SubmatrixData<CSAs...>
122 using DataType = SubmatrixData<CSAs...>;
123 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
129 using This = Submatrix<MT,AF,
false,
false,CSAs...>;
131 using BaseType = 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;
279 using DifferenceType = ptrdiff_t;
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;
480 inline Submatrix& operator=( initializer_list< initializer_list<ElementType> > list );
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 );
582 inline
bool hasOverlap() const noexcept;
628 template< typename MT
631 template< typename... RSAs >
632 inline Submatrix<MT,AF,false,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
633 : DataType( args... )
669 template<
typename MT
672 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Reference
673 Submatrix<MT,AF,false,false,CSAs...>::operator()(
size_t i,
size_t j )
695 template<
typename MT
698 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstReference
699 Submatrix<MT,AF,false,false,CSAs...>::operator()(
size_t i,
size_t j )
const 704 return const_cast<const MT&>( matrix_ )(
row()+i,
column()+j);
722 template<
typename MT
725 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Reference
726 Submatrix<MT,AF,false,false,CSAs...>::at(
size_t i,
size_t j )
752 template<
typename MT
755 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstReference
756 Submatrix<MT,AF,false,false,CSAs...>::at(
size_t i,
size_t j )
const 782 template<
typename MT
785 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
791 return Iterator( matrix_.begin( i +
row() ),
column() );
793 return Iterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
811 template<
typename MT
814 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
820 return ConstIterator( matrix_.cbegin( i +
row() ),
column() );
822 return ConstIterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
840 template<
typename MT
843 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
849 return ConstIterator( matrix_.cbegin( i +
row() ),
column() );
851 return ConstIterator( matrix_.lowerBound( i +
row(),
column() ),
column() );
869 template<
typename MT
872 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
878 return Iterator( matrix_.end( i +
row() ),
column() );
898 template<
typename MT
901 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
907 return ConstIterator( matrix_.cend( i +
row() ),
column() );
927 template<
typename MT
930 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
936 return ConstIterator( matrix_.cend( i +
row() ),
column() );
968 template<
typename MT
971 inline Submatrix<MT,AF,
false,
false,CSAs...>&
972 Submatrix<MT,AF,false,false,CSAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
976 if( list.size() !=
rows() ) {
980 const InitializerMatrix<ElementType> tmp( list,
columns() );
982 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
986 decltype(
auto) left( derestrict( *this ) );
1012 template< typename MT
1015 inline Submatrix<MT,AF,false,false,CSAs...>&
1016 Submatrix<MT,AF,false,false,CSAs...>::operator=( const Submatrix& rhs )
1018 using blaze::assign;
1023 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ &&
row() == rhs.row() &&
column() == rhs.column() ) )
1026 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
1030 if( !tryAssign( matrix_, rhs,
row(),
column() ) ) {
1034 decltype(
auto) left( derestrict( *this ) );
1036 if( rhs.canAlias( &matrix_ ) ) {
1037 const ResultType tmp( rhs );
1039 assign( left, tmp );
1043 assign( left, rhs );
1069 template<
typename MT
1072 template<
typename MT2
1074 inline Submatrix<MT,AF,
false,
false,CSAs...>&
1075 Submatrix<MT,AF,false,false,CSAs...>::operator=(
const Matrix<MT2,SO>& rhs )
1077 using blaze::assign;
1085 using Right = CompositeType_t<MT2>;
1086 Right right( ~rhs );
1088 if( !tryAssign( matrix_, right,
row(),
column() ) ) {
1092 decltype(
auto) left( derestrict( *this ) );
1095 const ResultType_t<MT2> tmp( right );
1097 assign( left, tmp );
1101 assign( left, right );
1126 template<
typename MT
1129 template<
typename MT2
1131 inline Submatrix<MT,AF,
false,
false,CSAs...>&
1134 using blaze::assign;
1140 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
1148 const AddType tmp( *
this + (~rhs) );
1150 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1154 decltype(
auto) left( derestrict( *this ) );
1157 assign( left, tmp );
1181 template< typename MT
1184 template< typename MT2
1186 inline Submatrix<MT,AF,false,false,CSAs...>&
1187 Submatrix<MT,AF,false,false,CSAs...>::operator-=( const Matrix<MT2,SO>& rhs )
1189 using blaze::assign;
1195 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
1203 const SubType tmp( *
this - (~rhs) );
1205 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1209 decltype(
auto) left( derestrict( *this ) );
1212 assign( left, tmp );
1236 template< typename MT
1239 template< typename MT2
1241 inline Submatrix<MT,AF,false,false,CSAs...>&
1242 Submatrix<MT,AF,false,false,CSAs...>::operator%=( const Matrix<MT2,SO>& rhs )
1244 using blaze::assign;
1250 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
1258 const SchurType tmp( *
this % (~rhs) );
1260 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
1264 decltype(
auto) left( derestrict( *this ) );
1267 assign( left, tmp );
1291 template< typename MT
1294 inline MT& Submatrix<MT,AF,false,false,CSAs...>::operand() noexcept
1308 template<
typename MT
1311 inline const MT& Submatrix<MT,AF,false,false,CSAs...>::operand() const noexcept
1325 template<
typename MT
1330 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
1348 template<
typename MT
1354 return nonZeros( i ) + matrix_.capacity(
row()+i ) - matrix_.nonZeros(
row()+i );
1366 template<
typename MT
1371 size_t nonzeros( 0UL );
1373 for(
size_t i=0UL; i<
rows(); ++i )
1394 template<
typename MT
1412 template<
typename MT
1419 const size_t jbegin( ( IsUpper_v<MT> )
1420 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1424 const size_t jend ( ( IsLower_v<MT> )
1425 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1430 matrix_.erase( i, matrix_.lowerBound( i, jbegin ), matrix_.lowerBound( i, jend ) );
1449 template<
typename MT
1456 const size_t index(
row() + i );
1458 const size_t jbegin( ( IsUpper_v<MT> )
1459 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
1463 const size_t jend ( ( IsLower_v<MT> )
1464 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
1469 matrix_.erase( index, matrix_.lowerBound( index, jbegin ), matrix_.lowerBound( index, jend ) );
1486 template<
typename MT
1489 inline void Submatrix<MT,AF,false,false,CSAs...>::reserve(
size_t nonzeros )
1491 const size_t current(
capacity() );
1493 if( nonzeros > current ) {
1494 matrix_.reserve( matrix_.capacity() + nonzeros - current );
1517 template<
typename MT
1520 void Submatrix<MT,AF,false,false,CSAs...>::reserve(
size_t i,
size_t nonzeros )
1522 const size_t current(
capacity( i ) );
1523 const size_t index (
row() + i );
1525 if( nonzeros > current ) {
1526 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
1544 template<
typename MT
1547 void Submatrix<MT,AF,false,false,CSAs...>::trim()
1549 for(
size_t i=0UL; i<
rows(); ++i )
1568 template<
typename MT
1571 void Submatrix<MT,AF,false,false,CSAs...>::trim(
size_t i )
1574 matrix_.trim(
row() + i );
1590 template<
typename MT
1593 inline bool Submatrix<MT,AF,false,false,CSAs...>::hasOverlap() const noexcept
1626 template<
typename MT
1629 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1632 return Iterator( matrix_.set(
row()+i,
column()+j, value ),
column() );
1652 template<
typename MT
1655 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1656 Submatrix<MT,AF,false,false,CSAs...>::insert(
size_t i,
size_t j,
const ElementType& value )
1658 return Iterator( matrix_.insert(
row()+i,
column()+j, value ),
column() );
1708 template<
typename MT
1711 inline void Submatrix<MT,AF,false,false,CSAs...>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
1714 matrix_.append(
row() + i,
column() + j, value, check );
1716 else if( !check || !isDefault<strict>( value ) ) {
1717 matrix_.insert(
row() + i,
column() + j, value );
1738 template<
typename MT
1741 inline void Submatrix<MT,AF,false,false,CSAs...>::finalize(
size_t i )
1743 matrix_.trim(
row() + i );
1767 template<
typename MT
1770 inline void Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i,
size_t j )
1775 matrix_.erase(
row() + i,
column() + j );
1793 template<
typename MT
1796 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1797 Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator pos )
1800 return Iterator( matrix_.erase(
row()+i, pos.base() ),
column() );
1820 template<
typename MT
1823 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1824 Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator first, Iterator last )
1827 return Iterator( matrix_.erase(
row()+i, first.base(), last.base() ),
column() );
1856 template<
typename MT
1859 template<
typename Pred >
1860 inline void Submatrix<MT,AF,false,false,CSAs...>::erase( Pred predicate )
1862 for(
size_t i=0UL; i<
rows(); ++i ) {
1863 matrix_.erase(
row()+i,
begin(i).base(),
end(i).base(), predicate );
1899 template<
typename MT
1902 template<
typename Pred >
1903 inline void Submatrix<MT,AF,false,false,CSAs...>::erase(
size_t i, Iterator first, Iterator last, Pred predicate )
1906 matrix_.erase(
row()+i, first.base(), last.base(), predicate );
1936 template<
typename MT
1939 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
1940 Submatrix<MT,AF,false,false,CSAs...>::find(
size_t i,
size_t j )
1942 const Iterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
1944 if( pos != matrix_.end(
row() + i ) )
1945 return Iterator( pos,
column() );
1969 template<
typename MT
1972 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
1973 Submatrix<MT,AF,false,false,CSAs...>::find(
size_t i,
size_t j )
const 1975 const ConstIterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
1977 if( pos != matrix_.end(
row() + i ) )
1978 return ConstIterator( pos,
column() );
2002 template<
typename MT
2005 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
2006 Submatrix<MT,AF,false,false,CSAs...>::lowerBound(
size_t i,
size_t j )
2008 return Iterator( matrix_.lowerBound(
row() + i,
column() + j ),
column() );
2030 template<
typename MT
2033 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
2034 Submatrix<MT,AF,false,false,CSAs...>::lowerBound(
size_t i,
size_t j )
const 2036 return ConstIterator( matrix_.lowerBound(
row() + i,
column() + j ),
column() );
2058 template<
typename MT
2061 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::Iterator
2062 Submatrix<MT,AF,false,false,CSAs...>::upperBound(
size_t i,
size_t j )
2064 return Iterator( matrix_.upperBound(
row() + i,
column() + j ),
column() );
2086 template<
typename MT
2089 inline typename Submatrix<MT,AF,
false,
false,CSAs...>::ConstIterator
2090 Submatrix<MT,AF,false,false,CSAs...>::upperBound(
size_t i,
size_t j )
const 2092 return ConstIterator( matrix_.upperBound(
row() + i,
column() + j ),
column() );
2124 template<
typename MT
2127 inline Submatrix<MT,AF,
false,
false,CSAs...>&
2130 using blaze::assign;
2140 decltype(
auto) left( derestrict( *this ) );
2141 const ResultType tmp(
trans( *this ) );
2144 assign( left, tmp );
2170 template< typename MT
2173 inline Submatrix<MT,AF,false,false,CSAs...>&
2174 Submatrix<MT,AF,false,false,CSAs...>::
ctranspose()
2176 using blaze::assign;
2186 decltype(
auto) left( derestrict( *this ) );
2187 const ResultType tmp(
ctrans( *this ) );
2190 assign( left, tmp );
2211 template< typename MT
2214 template< typename Other >
2215 inline Submatrix<MT,AF,false,false,CSAs...>&
2216 Submatrix<MT,AF,false,false,CSAs...>::scale( const Other& scalar )
2220 for(
size_t i=0UL; i<
rows(); ++i ) {
2221 const Iterator last(
end(i) );
2222 for( Iterator element=
begin(i); element!=last; ++element )
2223 element->value() *= scalar;
2251 template<
typename MT
2254 template<
typename Other >
2255 inline bool Submatrix<MT,AF,false,false,CSAs...>::canAlias(
const Other* alias )
const noexcept
2257 return matrix_.isAliased( alias );
2274 template<
typename MT
2277 template<
typename Other >
2278 inline bool Submatrix<MT,AF,false,false,CSAs...>::isAliased(
const Other* alias )
const noexcept
2280 return matrix_.isAliased( alias );
2297 template<
typename MT
2300 inline bool Submatrix<MT,AF,false,false,CSAs...>::canSMPAssign() const noexcept
2320 template<
typename MT
2323 template<
typename MT2
2325 inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const DenseMatrix<MT2,SO>& rhs )
2332 for(
size_t i=0UL; i<
rows(); ++i ) {
2333 for(
size_t j=0UL; j<
columns(); ++j ) {
2334 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2335 const ElementType& value( (~rhs)(i,j) );
2336 if( !isDefault<strict>( value ) )
2340 append( i, j, (~rhs)(i,j),
true );
2362 template<
typename MT
2365 template<
typename MT2 >
2366 inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const SparseMatrix<MT2,false>& rhs )
2373 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2374 for( ConstIterator_t<MT2> element=(~rhs).begin(i); element!=(~rhs).
end(i); ++element ) {
2375 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2376 const ElementType& value( element->value() );
2377 if( !isDefault<strict>( value ) )
2378 set( i, element->index(), value );
2381 append( i, element->index(), element->value(), true );
2403 template<
typename MT
2406 template<
typename MT2 >
2407 inline void Submatrix<MT,AF,false,false,CSAs...>::assign(
const SparseMatrix<MT2,true>& rhs )
2415 std::vector<size_t> rowLengths(
rows(), 0UL );
2416 for(
size_t j=0UL; j<
columns(); ++j ) {
2417 for(
auto element=(~rhs).begin(j); element!=(~rhs).
end(j); ++element )
2418 ++rowLengths[element->index()];
2422 for(
size_t i=0UL; i<
rows(); ++i ) {
2423 reserve( i, rowLengths[i] );
2427 for(
size_t j=0UL; j<
columns(); ++j ) {
2428 for(
auto element=(~rhs).begin(j); element!=(~rhs).
end(j); ++element )
2429 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
2430 const ElementType& value( element->value() );
2431 if( !isDefault<strict>( value ) )
2432 set( element->index(), j, value );
2435 append( element->index(), j, element->value(), true );
2455 template<
typename MT
2458 template<
typename MT2
2460 inline void Submatrix<MT,AF,false,false,CSAs...>::addAssign(
const Matrix<MT2,SO>& rhs )
2462 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
2469 const AddType tmp(
serial( *
this + (~rhs) ) );
2489 template<
typename MT
2492 template<
typename MT2
2494 inline void Submatrix<MT,AF,false,false,CSAs...>::subAssign(
const Matrix<MT2,SO>& rhs )
2496 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
2503 const SubType tmp(
serial( *
this - (~rhs) ) );
2523 template<
typename MT
2526 template<
typename MT2
2528 inline void Submatrix<MT,AF,false,false,CSAs...>::schurAssign(
const Matrix<MT2,SO>& rhs )
2530 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
2538 const SchurType tmp(
serial( *
this % (~rhs) ) );
2566 template<
typename MT
2569 class Submatrix<MT,AF,true,false,CSAs...>
2570 :
public View< SparseMatrix< Submatrix<MT,AF,true,false,CSAs...>, true > >
2571 ,
private SubmatrixData<CSAs...>
2575 using DataType = SubmatrixData<CSAs...>;
2576 using Operand = If_t< IsExpression_v<MT>, MT, MT& >;
2582 using This = Submatrix<MT,AF,
true,
false,CSAs...>;
2584 using BaseType = SparseMatrix<This,true>;
2585 using ViewedType = MT;
2587 using OppositeType = OppositeType_t<ResultType>;
2588 using TransposeType = TransposeType_t<ResultType>;
2589 using ElementType = ElementType_t<MT>;
2590 using ReturnType = ReturnType_t<MT>;
2591 using CompositeType =
const Submatrix&;
2594 using ConstReference = ConstReference_t<MT>;
2597 using Reference = If_t< IsConst_v<MT>, ConstReference, Reference_t<MT> >;
2603 template<
typename MatrixType
2604 ,
typename IteratorType >
2605 class SubmatrixElement
2606 :
private SparseElement
2615 inline SubmatrixElement( IteratorType pos,
size_t offset )
2627 template<
typename T >
inline SubmatrixElement& operator=(
const T& v ) {
2639 template<
typename T >
inline SubmatrixElement&
operator+=(
const T& v ) {
2651 template<
typename T >
inline SubmatrixElement&
operator-=(
const T& v ) {
2663 template<
typename T >
inline SubmatrixElement&
operator*=(
const T& v ) {
2675 template<
typename T >
inline SubmatrixElement&
operator/=(
const T& v ) {
2686 inline const SubmatrixElement* operator->()
const {
2696 inline decltype(
auto) value()
const {
2697 return pos_->value();
2706 inline size_t index()
const {
2707 return pos_->index() - offset_;
2722 template<
typename MatrixType
2723 ,
typename IteratorType >
2724 class SubmatrixIterator
2728 using IteratorCategory = std::forward_iterator_tag;
2729 using ValueType = SubmatrixElement<MatrixType,IteratorType>;
2730 using PointerType = ValueType;
2731 using ReferenceType = ValueType;
2732 using DifferenceType = ptrdiff_t;
2735 using iterator_category = IteratorCategory;
2736 using value_type = ValueType;
2737 using pointer = PointerType;
2738 using reference = ReferenceType;
2739 using difference_type = DifferenceType;
2745 inline SubmatrixIterator()
2757 inline SubmatrixIterator( IteratorType iterator,
size_t index )
2768 template<
typename MatrixType2,
typename IteratorType2 >
2769 inline SubmatrixIterator(
const SubmatrixIterator<MatrixType2,IteratorType2>& it )
2770 : pos_ ( it.base() )
2771 , offset_( it.offset() )
2780 inline SubmatrixIterator& operator++() {
2791 inline const SubmatrixIterator operator++(
int ) {
2792 const SubmatrixIterator tmp( *
this );
2803 inline ReferenceType
operator*()
const {
2804 return ReferenceType( pos_, offset_ );
2813 inline PointerType operator->()
const {
2814 return PointerType( pos_, offset_ );
2824 template<
typename MatrixType2,
typename IteratorType2 >
2825 inline bool operator==(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2826 return base() == rhs.base();
2836 template<
typename MatrixType2,
typename IteratorType2 >
2837 inline bool operator!=(
const SubmatrixIterator<MatrixType2,IteratorType2>& rhs )
const {
2838 return !( *
this == rhs );
2848 inline DifferenceType
operator-(
const SubmatrixIterator& rhs )
const {
2849 return pos_ - rhs.pos_;
2858 inline IteratorType base()
const {
2868 inline size_t offset() const noexcept {
2883 using ConstIterator = SubmatrixIterator< const MT, ConstIterator_t<MT> >;
2886 using Iterator = If_t< IsConst_v<MT>, ConstIterator, SubmatrixIterator< MT, Iterator_t<MT> > >;
2891 static constexpr
bool smpAssignable = MT::smpAssignable;
2894 static constexpr
bool compileTimeArgs = DataType::compileTimeArgs;
2900 template<
typename... RSAs >
2901 explicit inline Submatrix( MT& matrix, RSAs... args );
2903 Submatrix(
const Submatrix& ) =
default;
2910 ~Submatrix() =
default;
2917 inline Reference operator()(
size_t i,
size_t j );
2918 inline ConstReference operator()(
size_t i,
size_t j )
const;
2919 inline Reference at(
size_t i,
size_t j );
2920 inline ConstReference at(
size_t i,
size_t j )
const;
2921 inline Iterator
begin (
size_t i );
2922 inline ConstIterator
begin (
size_t i )
const;
2923 inline ConstIterator
cbegin(
size_t i )
const;
2924 inline Iterator
end (
size_t i );
2925 inline ConstIterator
end (
size_t i )
const;
2926 inline ConstIterator
cend (
size_t i )
const;
2933 inline Submatrix& operator=( initializer_list< initializer_list<ElementType> > list );
2934 inline Submatrix& operator=(
const Submatrix& rhs );
2936 template<
typename MT2,
bool SO >
inline Submatrix& operator= (
const Matrix<MT2,SO>& rhs );
2937 template<
typename MT2,
bool SO >
inline Submatrix&
operator+=(
const Matrix<MT2,SO>& rhs );
2938 template<
typename MT2,
bool SO >
inline Submatrix&
operator-=(
const Matrix<MT2,SO>& rhs );
2939 template<
typename MT2,
bool SO >
inline Submatrix& operator%=(
const Matrix<MT2,SO>& rhs );
2951 inline MT& operand() noexcept;
2952 inline const MT& operand() const noexcept;
2954 inline
size_t capacity() const noexcept;
2955 inline
size_t capacity(
size_t i ) const noexcept;
2957 inline
size_t nonZeros(
size_t i ) const;
2958 inline
void reset();
2959 inline
void reset(
size_t i );
2960 inline
void reserve(
size_t nonzeros );
2961 void reserve(
size_t i,
size_t nonzeros );
2963 inline
void trim(
size_t j );
2970 inline Iterator
set (
size_t i,
size_t j, const ElementType& value );
2971 inline Iterator insert (
size_t i,
size_t j, const ElementType& value );
2972 inline
void append (
size_t i,
size_t j, const ElementType& value,
bool check=false );
2973 inline
void finalize(
size_t i );
2980 inline
void erase(
size_t i,
size_t j );
2981 inline Iterator erase(
size_t i, Iterator pos );
2982 inline Iterator erase(
size_t i, Iterator first, Iterator last );
2984 template< typename Pred >
2985 inline
void erase( Pred predicate );
2987 template< typename Pred >
2988 inline
void erase(
size_t i, Iterator first, Iterator last, Pred predicate );
2995 inline Iterator find (
size_t i,
size_t j );
2996 inline ConstIterator find (
size_t i,
size_t j ) const;
2997 inline Iterator lowerBound(
size_t i,
size_t j );
2998 inline ConstIterator lowerBound(
size_t i,
size_t j ) const;
2999 inline Iterator upperBound(
size_t i,
size_t j );
3000 inline ConstIterator upperBound(
size_t i,
size_t j ) const;
3010 template< typename Other > inline Submatrix& scale( const Other& scalar );
3017 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
3018 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
3020 inline
bool canSMPAssign() const noexcept;
3022 template< typename MT2,
bool SO > inline
void assign ( const DenseMatrix<MT2,SO>& rhs );
3023 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,true>& rhs );
3024 template< typename MT2 > inline
void assign ( const SparseMatrix<MT2,false>& rhs );
3025 template< typename MT2,
bool SO > inline
void addAssign ( const Matrix<MT2,SO>& rhs );
3026 template< typename MT2,
bool SO > inline
void subAssign ( const Matrix<MT2,SO>& rhs );
3027 template< typename MT2,
bool SO > inline
void schurAssign( const Matrix<MT2,SO>& rhs );
3035 inline
bool hasOverlap() const noexcept;
3081 template< typename MT
3084 template< typename... RSAs >
3085 inline Submatrix<MT,AF,true,false,CSAs...>::Submatrix( MT& matrix, RSAs... args )
3086 : DataType( args... )
3087 , matrix_ ( matrix )
3122 template<
typename MT
3125 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Reference
3126 Submatrix<MT,AF,true,false,CSAs...>::operator()(
size_t i,
size_t j )
3148 template<
typename MT
3151 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstReference
3152 Submatrix<MT,AF,true,false,CSAs...>::operator()(
size_t i,
size_t j )
const 3157 return const_cast<const MT&>( matrix_ )(
row()+i,
column()+j);
3175 template<
typename MT
3178 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Reference
3179 Submatrix<MT,AF,true,false,CSAs...>::at(
size_t i,
size_t j )
3187 return (*
this)(i,j);
3205 template<
typename MT
3208 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstReference
3209 Submatrix<MT,AF,true,false,CSAs...>::at(
size_t i,
size_t j )
const 3217 return (*
this)(i,j);
3230 template<
typename MT
3233 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3239 return Iterator( matrix_.begin( j +
column() ),
row() );
3241 return Iterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3254 template<
typename MT
3257 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3263 return ConstIterator( matrix_.cbegin( j +
column() ),
row() );
3265 return ConstIterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3278 template<
typename MT
3281 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3287 return ConstIterator( matrix_.cbegin( j +
column() ),
row() );
3289 return ConstIterator( matrix_.lowerBound(
row(), j +
column() ),
row() );
3302 template<
typename MT
3305 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
3310 if( matrix_.rows() ==
row() +
rows() )
3311 return Iterator( matrix_.end( j +
column() ),
row() );
3313 return Iterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3326 template<
typename MT
3329 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3334 if( matrix_.rows() ==
row() +
rows() )
3335 return ConstIterator( matrix_.cend( j +
column() ),
row() );
3337 return ConstIterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3350 template<
typename MT
3353 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
3358 if( matrix_.rows() ==
row() +
rows() )
3359 return ConstIterator( matrix_.cend( j +
column() ),
row() );
3361 return ConstIterator( matrix_.lowerBound(
row() +
rows(), j +
column() ),
row() );
3391 template<
typename MT
3394 inline Submatrix<MT,AF,
true,
false,CSAs...>&
3395 Submatrix<MT,AF,true,false,CSAs...>::operator=( initializer_list< initializer_list<ElementType> > list )
3397 using blaze::assign;
3399 if( list.size() !=
rows() ) {
3403 const InitializerMatrix<ElementType> tmp( list,
columns() );
3405 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3409 decltype(
auto) left( derestrict( *this ) );
3412 assign( left, tmp );
3435 template< typename MT
3438 inline Submatrix<MT,AF,true,false,CSAs...>&
3439 Submatrix<MT,AF,true,false,CSAs...>::operator=( const Submatrix& rhs )
3441 using blaze::assign;
3446 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ &&
row() == rhs.row() &&
column() == rhs.column() ) )
3449 if(
rows() != rhs.rows() ||
columns() != rhs.columns() ) {
3453 if( !tryAssign( matrix_, rhs,
row(),
column() ) ) {
3457 decltype(
auto) left( derestrict( *this ) );
3459 if( rhs.canAlias( &matrix_ ) ) {
3460 const ResultType tmp( rhs );
3462 assign( left, tmp );
3466 assign( left, rhs );
3492 template<
typename MT
3495 template<
typename MT2
3497 inline Submatrix<MT,AF,
true,
false,CSAs...>&
3498 Submatrix<MT,AF,true,false,CSAs...>::operator=(
const Matrix<MT2,SO>& rhs )
3500 using blaze::assign;
3508 using Right = CompositeType_t<MT2>;
3509 Right right( ~rhs );
3511 if( !tryAssign( matrix_, right,
row(),
column() ) ) {
3515 decltype(
auto) left( derestrict( *this ) );
3518 const ResultType_t<MT2> tmp( right );
3520 assign( left, tmp );
3524 assign( left, right );
3549 template<
typename MT
3552 template<
typename MT2
3554 inline Submatrix<MT,AF,
true,
false,CSAs...>&
3557 using blaze::assign;
3563 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
3571 const AddType tmp( *
this + (~rhs) );
3573 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3577 decltype(
auto) left( derestrict( *this ) );
3580 assign( left, tmp );
3604 template< typename MT
3607 template< typename MT2
3609 inline Submatrix<MT,AF,true,false,CSAs...>&
3610 Submatrix<MT,AF,true,false,CSAs...>::operator-=( const Matrix<MT2,SO>& rhs )
3612 using blaze::assign;
3618 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
3626 const SubType tmp( *
this - (~rhs) );
3628 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3632 decltype(
auto) left( derestrict( *this ) );
3635 assign( left, tmp );
3659 template< typename MT
3662 template< typename MT2
3664 inline Submatrix<MT,AF,true,false,CSAs...>&
3665 Submatrix<MT,AF,true,false,CSAs...>::operator%=( const Matrix<MT2,SO>& rhs )
3667 using blaze::assign;
3673 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
3681 const SchurType tmp( *
this % (~rhs) );
3683 if( !tryAssign( matrix_, tmp,
row(),
column() ) ) {
3687 decltype(
auto) left( derestrict( *this ) );
3690 assign( left, tmp );
3714 template< typename MT
3717 inline MT& Submatrix<MT,AF,true,false,CSAs...>::operand() noexcept
3731 template<
typename MT
3734 inline const MT& Submatrix<MT,AF,true,false,CSAs...>::operand() const noexcept
3748 template<
typename MT
3753 return nonZeros() + matrix_.capacity() - matrix_.nonZeros();
3766 template<
typename MT
3784 template<
typename MT
3789 size_t nonzeros( 0UL );
3791 for(
size_t i=0UL; i<
columns(); ++i )
3807 template<
typename MT
3825 template<
typename MT
3832 const size_t ibegin( ( IsLower_v<MT> )
3833 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3837 const size_t iend ( ( IsUpper_v<MT> )
3838 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3843 matrix_.erase( j, matrix_.lowerBound( ibegin, j ), matrix_.lowerBound( iend, j ) );
3857 template<
typename MT
3864 const size_t index(
column() + j );
3866 const size_t ibegin( ( IsLower_v<MT> )
3867 ?( ( IsUniLower_v<MT> || IsStrictlyLower_v<MT> )
3871 const size_t iend ( ( IsUpper_v<MT> )
3872 ?( ( IsUniUpper_v<MT> || IsStrictlyUpper_v<MT> )
3877 matrix_.erase( index, matrix_.lowerBound( ibegin, index ), matrix_.lowerBound( iend, index ) );
3894 template<
typename MT
3897 inline void Submatrix<MT,AF,true,false,CSAs...>::reserve(
size_t nonzeros )
3899 const size_t current(
capacity() );
3901 if( nonzeros > current ) {
3902 matrix_.reserve( matrix_.capacity() + nonzeros - current );
3921 template<
typename MT
3924 void Submatrix<MT,AF,true,false,CSAs...>::reserve(
size_t j,
size_t nonzeros )
3926 const size_t current(
capacity( j ) );
3927 const size_t index (
column() + j );
3929 if( nonzeros > current ) {
3930 matrix_.reserve( index, matrix_.capacity( index ) + nonzeros - current );
3947 template<
typename MT
3950 void Submatrix<MT,AF,true,false,CSAs...>::trim()
3952 for(
size_t j=0UL; j<
columns(); ++j )
3970 template<
typename MT
3973 void Submatrix<MT,AF,true,false,CSAs...>::trim(
size_t j )
3976 matrix_.trim(
column() + j );
3992 template<
typename MT
3995 inline bool Submatrix<MT,AF,true,false,CSAs...>::hasOverlap() const noexcept
4028 template<
typename MT
4031 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4034 return Iterator( matrix_.set(
row()+i,
column()+j, value ),
row() );
4054 template<
typename MT
4057 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4058 Submatrix<MT,AF,true,false,CSAs...>::insert(
size_t i,
size_t j,
const ElementType& value )
4060 return Iterator( matrix_.insert(
row()+i,
column()+j, value ),
row() );
4110 template<
typename MT
4113 inline void Submatrix<MT,AF,true,false,CSAs...>::append(
size_t i,
size_t j,
const ElementType& value,
bool check )
4115 if(
row() +
rows() == matrix_.rows() ) {
4116 matrix_.append(
row() + i,
column() + j, value, check );
4118 else if( !check || !isDefault<strict>( value ) ) {
4119 matrix_.insert(
row() + i,
column() + j, value );
4140 template<
typename MT
4143 inline void Submatrix<MT,AF,true,false,CSAs...>::finalize(
size_t j )
4145 matrix_.trim(
column() + j );
4169 template<
typename MT
4172 inline void Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t i,
size_t j )
4177 matrix_.erase(
row() + i,
column() + j );
4193 template<
typename MT
4196 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4197 Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator pos )
4200 return Iterator( matrix_.erase(
column()+j, pos.base() ),
row() );
4217 template<
typename MT
4220 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4221 Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator first, Iterator last )
4224 return Iterator( matrix_.erase(
column()+j, first.base(), last.base() ),
row() );
4253 template<
typename MT
4256 template<
typename Pred >
4257 inline void Submatrix<MT,AF,true,false,CSAs...>::erase( Pred predicate )
4259 for(
size_t j=0UL; j<
columns(); ++j ) {
4260 matrix_.erase(
column()+j,
begin(j).base(),
end(j).base(), predicate );
4293 template<
typename MT
4296 template<
typename Pred >
4297 inline void Submatrix<MT,AF,true,false,CSAs...>::erase(
size_t j, Iterator first, Iterator last, Pred predicate )
4300 matrix_.erase(
column()+j, first.base(), last.base(), predicate );
4330 template<
typename MT
4333 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4334 Submatrix<MT,AF,true,false,CSAs...>::find(
size_t i,
size_t j )
4336 const Iterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
4338 if( pos != matrix_.end(
column() + j ) )
4339 return Iterator( pos,
row() );
4363 template<
typename MT
4366 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4367 Submatrix<MT,AF,true,false,CSAs...>::find(
size_t i,
size_t j )
const 4369 const ConstIterator_t<MT> pos( matrix_.find(
row() + i,
column() + j ) );
4371 if( pos != matrix_.end(
column() + j ) )
4372 return ConstIterator( pos,
row() );
4396 template<
typename MT
4399 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4400 Submatrix<MT,AF,true,false,CSAs...>::lowerBound(
size_t i,
size_t j )
4402 return Iterator( matrix_.lowerBound(
row() + i,
column() + j ),
row() );
4424 template<
typename MT
4427 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4428 Submatrix<MT,AF,true,false,CSAs...>::lowerBound(
size_t i,
size_t j )
const 4430 return ConstIterator( matrix_.lowerBound(
row() + i,
column() + j ),
row() );
4452 template<
typename MT
4455 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::Iterator
4456 Submatrix<MT,AF,true,false,CSAs...>::upperBound(
size_t i,
size_t j )
4458 return Iterator( matrix_.upperBound(
row() + i,
column() + j ),
row() );
4480 template<
typename MT
4483 inline typename Submatrix<MT,AF,
true,
false,CSAs...>::ConstIterator
4484 Submatrix<MT,AF,true,false,CSAs...>::upperBound(
size_t i,
size_t j )
const 4486 return ConstIterator( matrix_.upperBound(
row() + i,
column() + j ),
row() );
4518 template<
typename MT
4521 inline Submatrix<MT,AF,
true,
false,CSAs...>&
4524 using blaze::assign;
4534 decltype(
auto) left( derestrict( *this ) );
4535 const ResultType tmp(
trans( *this ) );
4538 assign( left, tmp );
4564 template< typename MT
4567 inline Submatrix<MT,AF,true,false,CSAs...>&
4568 Submatrix<MT,AF,true,false,CSAs...>::
ctranspose()
4570 using blaze::assign;
4580 decltype(
auto) left( derestrict( *this ) );
4581 const ResultType tmp(
ctrans(*this) );
4584 assign( left, tmp );
4605 template< typename MT
4608 template< typename Other >
4609 inline Submatrix<MT,AF,true,false,CSAs...>&
4610 Submatrix<MT,AF,true,false,CSAs...>::scale( const Other& scalar )
4614 for(
size_t i=0UL; i<
columns(); ++i ) {
4615 const Iterator last(
end(i) );
4616 for( Iterator element=
begin(i); element!=last; ++element )
4617 element->value() *= scalar;
4645 template<
typename MT
4648 template<
typename Other >
4649 inline bool Submatrix<MT,AF,true,false,CSAs...>::canAlias(
const Other* alias )
const noexcept
4651 return matrix_.isAliased( alias );
4668 template<
typename MT
4671 template<
typename Other >
4672 inline bool Submatrix<MT,AF,true,false,CSAs...>::isAliased(
const Other* alias )
const noexcept
4674 return matrix_.isAliased( alias );
4691 template<
typename MT
4694 inline bool Submatrix<MT,AF,true,false,CSAs...>::canSMPAssign() const noexcept
4714 template<
typename MT
4717 template<
typename MT2
4719 inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const DenseMatrix<MT2,SO>& rhs )
4726 for(
size_t j=0UL; j<
columns(); ++j ) {
4727 for(
size_t i=0UL; i<
rows(); ++i ) {
4728 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4729 const ElementType& value( (~rhs)(i,j) );
4730 if( !isDefault<strict>( value ) )
4734 append( i, j, (~rhs)(i,j),
true );
4756 template<
typename MT
4759 template<
typename MT2 >
4760 inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const SparseMatrix<MT2,true>& rhs )
4767 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4768 for( ConstIterator_t<MT2> element=(~rhs).begin(j); element!=(~rhs).
end(j); ++element ) {
4769 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4770 const ElementType& value( element->value() );
4771 if( !isDefault<strict>( value ) )
4772 set( element->index(), j, value );
4775 append( element->index(), j, element->value(), true );
4796 template<
typename MT
4799 template<
typename MT2 >
4800 inline void Submatrix<MT,AF,true,false,CSAs...>::assign(
const SparseMatrix<MT2,false>& rhs )
4808 std::vector<size_t> columnLengths(
columns(), 0UL );
4809 for(
size_t i=0UL; i<
rows(); ++i ) {
4810 for(
auto element=(~rhs).begin(i); element!=(~rhs).
end(i); ++element )
4811 ++columnLengths[element->index()];
4815 for(
size_t j=0UL; j<
columns(); ++j ) {
4816 reserve( j, columnLengths[j] );
4820 for(
size_t i=0UL; i<
rows(); ++i ) {
4821 for(
auto element=(~rhs).begin(i); element!=(~rhs).
end(i); ++element )
4822 if( IsSymmetric_v<MT> || IsHermitian_v<MT> ) {
4823 const ElementType& value( element->value() );
4824 if( !isDefault<strict>( value ) )
4825 set( i, element->index(), value );
4828 append( i, element->index(), element->value(), true );
4848 template<
typename MT
4851 template<
typename MT2
4853 inline void Submatrix<MT,AF,true,false,CSAs...>::addAssign(
const Matrix<MT2,SO>& rhs )
4855 using AddType = AddTrait_t< ResultType, ResultType_t<MT2> >;
4862 const AddType tmp(
serial( *
this + (~rhs) ) );
4882 template<
typename MT
4885 template<
typename MT2
4887 inline void Submatrix<MT,AF,true,false,CSAs...>::subAssign(
const Matrix<MT2,SO>& rhs )
4889 using SubType = SubTrait_t< ResultType, ResultType_t<MT2> >;
4896 const SubType tmp(
serial( *
this - (~rhs) ) );
4916 template<
typename MT
4919 template<
typename MT2
4921 inline void Submatrix<MT,AF,true,false,CSAs...>::schurAssign(
const Matrix<MT2,SO>& rhs )
4923 using SchurType = SchurTrait_t< ResultType, ResultType_t<MT2> >;
4930 const SchurType tmp(
serial( *
this % (~rhs) ) );
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.Via these flags it is possible to specify subvec...
Definition: AlignmentFlag.h:62
#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.
decltype(auto) column(Matrix< MT, SO > &matrix, RCAs... args)
Creating a view on a specific column of the given matrix.
Definition: Column.h:133
Headerfile for the generic min algorithm.
Header file for the blaze::checked and blaze::unchecked instances.
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:432
Header file for the Schur product trait.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for the alignment flag values.
Header file for the IsUniUpper type trait.
Header file for the subtraction trait.
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
Header file for basic type definitions.
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:750
Header file for the View base class.
Header file for the serial shim.
#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
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
#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....
Definition: Submatrix.h:81
void ctranspose(Matrix< MT, SO > &matrix)
In-place conjugate transpose of the given matrix.
Definition: Matrix.h:851
#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
constexpr bool IsReference_v
Auxiliary variable template for the IsReference type trait.The IsReference_v variable template provid...
Definition: IsReference.h:95
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the reset shim.
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
Header file for the extended initializer_list functionality.
Header file for the IsUniLower type trait.
typename SubmatrixTrait< MT, CSAs... >::Type SubmatrixTrait_t
Auxiliary alias declaration for the SubmatrixTrait type trait.The SubmatrixTrait_t alias declaration ...
Definition: SubmatrixTrait.h:171
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
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:482
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:416
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 implementation of a matrix representation of an initializer list.
Headerfile for the generic max algorithm.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) ctrans(const DenseMatrix< MT, SO > &dm)
Returns the conjugate transpose matrix of dm.
Definition: DMatMapExpr.h:1361
Header file for the If class template.
#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
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:9091
#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
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:1162
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.
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:370
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
constexpr bool Contains_v
Auxiliary variable template for the Contains type trait.The Contains_v variable template provides a c...
Definition: Contains.h:138
Header file for the IsLower type trait.
Header file for the SparseElement base class.
Constraint on the data type.
Header file for the exception macros of the math module.
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:1198
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:438
Header file for the implementation of the SubmatrixData class template.
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
Constraint on the data type.
Header file for the IsStrictlyLower type trait.
Constraint on the data type.
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:558
#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,...
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
Header file for the IsConst type trait.
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the addition trait.
Header file for the Unique class template.
Header file for the submatrix trait.
Check< false > Unchecked
Type of the blaze::unchecked instance.blaze::Unchecked is the type of the blaze::unchecked instance,...
Definition: Check.h:96
decltype(auto) row(Matrix< MT, SO > &, RRAs...)
Creating a view on a specific row of the given matrix.
Definition: Row.h:133
#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,...
Definition: Reference.h:79
Header file for the isDefault shim.
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
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#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.
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
auto operator *=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:494
#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
Header file for the IsUpper type trait.
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,...
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.
void transpose(Matrix< MT, SO > &matrix)
In-place transpose of the given matrix.
Definition: Matrix.h:825