35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_ 225 template<
typename Type
226 ,
bool SO = defaultStorageOrder >
247 explicit Element() =
default;
248 Element(
const Element& rhs ) =
default;
249 Element( Element&& rhs ) =
default;
253 inline Element&
operator=(
const Element& rhs )
255 this->value_ = rhs.value_;
259 inline Element&
operator=( Element&& rhs )
261 this->value_ = std::move( rhs.value_ );
265 template<
typename Other >
266 inline auto operator=(
const Other& rhs )
269 this->value_ = rhs.value();
273 template<
typename Other >
276 IsRValueReference_v<Other&&>, Element& >
278 this->value_ = std::move( rhs.value() );
282 template<
typename Other >
290 template<
typename Other >
293 IsRValueReference_v<Other&&>, Element& >
295 this->value_ = std::move( v );
311 struct Uninitialized {};
334 template<
typename NewType >
343 template<
size_t NewM
364 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
417 inline size_t rows() const noexcept;
418 inline
size_t columns() const noexcept;
419 inline
size_t capacity() const noexcept;
420 inline
size_t capacity(
size_t i ) const noexcept;
422 inline
size_t nonZeros(
size_t i ) const;
424 inline
void reset(
size_t i );
426 void resize (
size_t m,
size_t n,
bool preserve=true );
427 inline
void reserve(
size_t nonzeros );
428 void reserve(
size_t i,
size_t nonzeros );
430 inline
void trim (
size_t i );
439 inline
Iterator set (
size_t i,
size_t j, const Type& value );
441 inline
void append (
size_t i,
size_t j, const Type& value,
bool check=false );
449 inline
void erase(
size_t i,
size_t j );
453 template< typename Pred >
454 inline
void erase( Pred predicate );
456 template< typename Pred >
479 template< typename Other > inline
CompressedMatrix& scale( const Other& scalar );
486 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
487 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
491 template< typename MT,
bool SO2 > inline
void assign ( const
DenseMatrix<MT,SO2>& rhs );
562 template< typename Type,
bool SO >
577 template<
typename Type
597 template<
typename Type
602 for(
size_t i=1UL; i<2UL*
m_+2UL; ++i )
617 template<
typename Type
622 begin_[0UL] = allocate<Element>( nonzeros );
623 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
641 template<
typename Type
646 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
648 size_t newCapacity( 0UL );
649 for(
auto it=nonzeros.begin(); it!=nonzeros.end(); ++it )
652 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
653 for(
size_t i=0UL; i<
m_; ++i ) {
680 template<
typename Type
687 for(
const auto& rowList : list )
691 for(
const Type& element : rowList ) {
692 if( !isDefault<strict>( element ) )
709 template<
typename Type
714 const size_t nonzeros( sm.
nonZeros() );
716 begin_[0UL] = allocate<Element>( nonzeros );
717 for(
size_t i=0UL; i<
m_; ++i ) {
731 template<
typename Type
736 , capacity_( sm.capacity_ )
737 , begin_ ( sm.begin_ )
754 template<
typename Type
756 template<
typename MT
773 template<
typename Type
775 template<
typename MT
793 template<
typename Type
800 , end_ ( begin_+(m+1UL) )
818 template<
typename Type
822 if( begin_ !=
nullptr ) {
851 template<
typename Type
874 template<
typename Type
884 if( pos == end_[i] || pos->index_ != j )
905 template<
typename Type
932 template<
typename Type
959 template<
typename Type
981 template<
typename Type
1003 template<
typename Type
1025 template<
typename Type
1047 template<
typename Type
1069 template<
typename Type
1109 template<
typename Type
1121 for(
const auto& rowList : list )
1125 for(
const Type& element : rowList ) {
1126 if( !isDefault<strict>( element ) )
1127 append( i, j, element );
1149 template<
typename Type
1156 if( &rhs ==
this )
return *
this;
1158 const size_t nonzeros( rhs.
nonZeros() );
1160 if( rhs.
m_ > capacity_ || nonzeros >
capacity() )
1165 newBegin[0UL] = allocate<Element>( nonzeros );
1166 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
1167 newEnd[i] = castDown( std::copy( rhs.
begin_[i], rhs.
end_[i], castUp( newBegin[i] ) ) );
1168 newBegin[i+1UL] = newEnd[i];
1170 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
1172 swap( begin_, newBegin );
1176 if( newBegin !=
nullptr ) {
1182 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
1183 end_[i] = castDown( std::copy( rhs.
begin_[i], rhs.
end_[i], castUp( begin_[i] ) ) );
1184 begin_[i+1UL] = end_[i];
1202 template<
typename Type
1207 if( begin_ !=
nullptr ) {
1214 capacity_ = rhs.capacity_;
1215 begin_ = rhs.begin_;
1220 rhs.capacity_ = 0UL;
1221 rhs.begin_ =
nullptr;
1238 template<
typename Type
1240 template<
typename MT
1245 using blaze::assign;
1247 if( (~rhs).canAlias(
this ) ) {
1253 assign( *
this, ~rhs );
1270 template<
typename Type
1272 template<
typename MT
1277 using blaze::assign;
1279 if( (~rhs).canAlias(
this ) ||
1280 (~rhs).
rows() > capacity_ ||
1289 if( !IsZero_v<MT> ) {
1290 assign( *
this, ~rhs );
1309 template<
typename Type
1311 template<
typename MT
1316 using blaze::addAssign;
1318 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
1322 if( !IsZero_v<MT> ) {
1323 addAssign( *
this, ~rhs );
1341 template<
typename Type
1343 template<
typename MT
1347 using blaze::subAssign;
1349 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
1353 if( !IsZero_v<MT> ) {
1354 subAssign( *
this, ~rhs );
1373 template<
typename Type
1375 template<
typename MT
1380 using blaze::schurAssign;
1382 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
1386 if( (~rhs).canAlias(
this ) ) {
1392 schurAssign( *
this, tmp );
1411 template<
typename Type
1413 template<
typename MT
1418 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
1422 if( !IsZero_v<MT> ) {
1448 template<
typename Type
1462 template<
typename Type
1476 template<
typename Type
1480 if( begin_ !=
nullptr )
1481 return end_[m_] - begin_[0UL];
1498 template<
typename Type
1503 return begin_[i+1UL] - begin_[i];
1513 template<
typename Type
1517 size_t nonzeros( 0UL );
1519 for(
size_t i=0UL; i<m_; ++i )
1538 template<
typename Type
1543 return end_[i] - begin_[i];
1553 template<
typename Type
1557 for(
size_t i=0UL; i<m_; ++i )
1558 end_[i] = begin_[i];
1574 template<
typename Type
1579 end_[i] = begin_[i];
1591 template<
typename Type
1595 if( end_ !=
nullptr )
1596 end_[0UL] = end_[m_];
1618 template<
typename Type
1625 BLAZE_INTERNAL_ASSERT( begin_ ==
nullptr ||
size_t( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
1627 if( m == m_ && n == n_ )
return;
1629 if( begin_ ==
nullptr )
1632 end_ = begin_+m+1UL;
1634 for(
size_t i=0UL; i<2UL*m+2UL; ++i ) {
1635 begin_[i] =
nullptr;
1640 else if( m > capacity_ )
1643 Iterator* newEnd ( newBegin+m+1UL );
1645 newBegin[0UL] = begin_[0UL];
1648 for(
size_t i=0UL; i<m_; ++i ) {
1649 newEnd [i] = end_ [i];
1650 newBegin[i+1UL] = begin_[i+1UL];
1652 for(
size_t i=m_; i<m; ++i ) {
1653 newBegin[i+1UL] = newEnd[i] = begin_[m_];
1657 for(
size_t i=0UL; i<m; ++i ) {
1658 newBegin[i+1UL] = newEnd[i] = begin_[0UL];
1662 newEnd[m] = end_[m_];
1664 swap( newBegin, begin_ );
1674 for(
size_t i=0UL; i<m_; ++i )
1675 end_[i] = begin_[i];
1678 for(
size_t i=m_; i<m; ++i ) {
1679 begin_[i+1UL] = end_[i] = begin_[m_];
1685 for(
size_t i=0UL; i<m; ++i )
1686 end_[i] = lowerBound( i, n );
1689 for(
size_t i=0UL; i<m; ++i )
1690 end_[i] = begin_[i];
1700 BLAZE_INTERNAL_ASSERT(
size_t( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
1715 template<
typename Type
1720 reserveElements( nonzeros );
1739 template<
typename Type
1748 BLAZE_INTERNAL_ASSERT( static_cast<size_t>( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
1750 const size_t current(
capacity(i) );
1752 if( current >= nonzeros )
return;
1754 const ptrdiff_t additional( nonzeros - current );
1756 if( end_[m_] - begin_[m_] < additional )
1758 const size_t newCapacity( begin_[m_] - begin_[0UL] + additional );
1762 Iterator* newEnd ( newBegin+m_+1UL );
1764 newBegin[0UL] = allocate<Element>( newCapacity );
1765 newEnd [m_ ] = newBegin[0UL]+newCapacity;
1767 for(
size_t k=0UL; k<i; ++k ) {
1768 newEnd [k ] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
1769 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1771 newEnd [i ] = castDown(
transfer( begin_[i], end_[i], castUp( newBegin[i] ) ) );
1772 newBegin[i+1UL] = newBegin[i] + nonzeros;
1773 for(
size_t k=i+1UL; k<m_; ++k ) {
1774 newEnd [k ] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
1775 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1780 swap( newBegin, begin_ );
1788 begin_[m_] += additional;
1789 for(
size_t j=m_-1UL; j>i; --j ) {
1790 begin_[j] = castDown( std::move_backward( begin_[j], end_[j], castUp( end_[j]+additional ) ) );
1791 end_ [j] += additional;
1796 BLAZE_INTERNAL_ASSERT( static_cast<size_t>( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
1811 template<
typename Type
1815 for(
size_t i=0UL; i<m_; ++i )
1832 template<
typename Type
1838 if( i < ( m_ - 1UL ) )
1839 end_[i+1] = castDown( std::move( begin_[i+1], end_[i+1], castUp( end_[i] ) ) );
1840 begin_[i+1] = end_[i];
1854 template<
typename Type
1871 template<
typename Type
1879 swap( capacity_, sm.capacity_ );
1880 swap( begin_, sm.begin_ );
1881 swap( end_ , sm.end_ );
1894 template<
typename Type
1898 size_t nonzeros( 2UL*
capacity()+1UL );
1914 template<
typename Type
1921 Iterator* newEnd = newBegin+capacity_+1UL;
1923 newBegin[0UL] = allocate<Element>( nonzeros );
1925 for(
size_t k=0UL; k<m_; ++k ) {
1927 newEnd [k] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
1928 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
1931 newEnd[m_] = newBegin[0UL]+nonzeros;
1933 swap( newBegin, begin_ );
1936 if( newBegin !=
nullptr ) {
1952 template<
typename Type
1957 return static_cast<Iterator>( it );
1970 template<
typename Type
1975 return static_cast<IteratorBase>( it );
2000 template<
typename Type
2008 const Iterator pos( lowerBound( i, j ) );
2010 if( pos != end_[i] && pos->index_ == j ) {
2011 pos->value() = value;
2014 else return insert( pos, i, j, value );
2032 template<
typename Type
2040 const Iterator pos( lowerBound( i, j ) );
2042 if( pos != end_[i] && pos->index_ == j ) {
2046 return insert( pos, i, j, value );
2061 template<
typename Type
2068 if( begin_[i+1UL] - end_[i] != 0 ) {
2069 std::move_backward( pos, end_[i], castUp( end_[i]+1UL ) );
2070 pos->value_ = value;
2076 else if( end_[m_] - begin_[m_] != 0 ) {
2077 std::move_backward( pos, end_[m_-1UL], castUp( end_[m_-1UL]+1UL ) );
2079 pos->value_ = value;
2082 for(
size_t k=i+1UL; k<m_+1UL; ++k ) {
2090 size_t newCapacity( extendCapacity() );
2093 Iterator* newEnd = newBegin+capacity_+1UL;
2095 newBegin[0UL] = allocate<Element>( newCapacity );
2097 for(
size_t k=0UL; k<i; ++k ) {
2098 const size_t nonzeros( end_[k] - begin_[k] );
2099 const size_t total( begin_[k+1UL] - begin_[k] );
2100 newEnd [k] = newBegin[k] + nonzeros;
2101 newBegin[k+1UL] = newBegin[k] + total;
2103 newEnd [i] = newBegin[i] + ( end_[i] - begin_[i] ) + 1;
2104 newBegin[i+1UL] = newBegin[i] + ( begin_[i+1] - begin_[i] ) + 1;
2105 for(
size_t k=i+1UL; k<m_; ++k ) {
2106 const size_t nonzeros( end_[k] - begin_[k] );
2107 const size_t total( begin_[k+1UL] - begin_[k] );
2108 newEnd [k] = newBegin[k] + nonzeros;
2109 newBegin[k+1UL] = newBegin[k] + total;
2112 newEnd[m_] = newEnd[capacity_] = newBegin[0UL]+newCapacity;
2114 Iterator tmp = castDown( std::move( begin_[0UL], pos, castUp( newBegin[0UL] ) ) );
2115 tmp->value_ = value;
2117 std::move( pos, end_[m_-1UL], castUp( tmp+1UL ) );
2119 swap( newBegin, begin_ );
2183 template<
typename Type
2190 BLAZE_USER_ASSERT( begin_[i] == end_[i] || j > ( end_[i]-1UL )->index_,
"Index is not strictly increasing" );
2192 end_[i]->value_ = value;
2194 if( !check || !isDefault<strict>( end_[i]->value_ ) ) {
2195 end_[i]->index_ = j;
2215 template<
typename Type
2221 begin_[i+1UL] = end_[i];
2223 end_[i+1UL] = end_[i];
2245 template<
typename Type
2252 const Iterator pos( find( i, j ) );
2253 if( pos != end_[i] )
2254 end_[i] = castDown( std::move( pos+1, end_[i], castUp( pos ) ) );
2270 template<
typename Type
2276 BLAZE_USER_ASSERT( pos >= begin_[i] && pos <= end_[i],
"Invalid compressed matrix iterator" );
2278 if( pos != end_[i] )
2279 end_[i] = castDown( std::move( pos+1, end_[i], castUp( pos ) ) );
2298 template<
typename Type
2305 BLAZE_USER_ASSERT( first >= begin_[i] && first <= end_[i],
"Invalid compressed matrix iterator" );
2306 BLAZE_USER_ASSERT( last >= begin_[i] && last <= end_[i],
"Invalid compressed matrix iterator" );
2309 end_[i] = castDown( std::move( last, end_[i], castUp( first ) ) );
2337 template<
typename Type
2339 template<
typename Pred >
2342 for(
size_t i=0UL; i<m_; ++i ) {
2343 end_[i] = castDown( std::remove_if( castUp( begin_[i] ), castUp( end_[i] ),
2344 [predicate=predicate](
const ElementBase& element) {
2345 return predicate( element.
value() );
2379 template<
typename Type
2381 template<
typename Pred >
2386 BLAZE_USER_ASSERT( first >= begin_[i] && first <= end_[i],
"Invalid compressed matrix iterator" );
2387 BLAZE_USER_ASSERT( last >= begin_[i] && last <= end_[i],
"Invalid compressed matrix iterator" );
2389 const auto pos = std::remove_if( castUp( first ), castUp( last ),
2390 [predicate=predicate](
const ElementBase& element ) {
2391 return predicate( element.
value() );
2394 end_[i] = castDown( std::move( last, end_[i], pos ) );
2422 template<
typename Type
2427 return const_cast<Iterator>( const_cast<const This&>( *this ).find( i, j ) );
2447 template<
typename Type
2453 if( pos != end_[i] && pos->index_ == j )
2455 else return end_[i];
2475 template<
typename Type
2480 return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( i, j ) );
2500 template<
typename Type
2506 return std::lower_bound( begin_[i], end_[i], j,
2507 [](
const Element& element,
size_t index )
2509 return element.index() < index;
2530 template<
typename Type
2535 return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( i, j ) );
2555 template<
typename Type
2561 return std::upper_bound( begin_[i], end_[i], j,
2562 [](
size_t index,
const Element& element )
2564 return index < element.index();
2583 template<
typename Type
2599 template<
typename Type
2627 template<
typename Type
2629 template<
typename Other >
2632 for(
size_t i=0UL; i<m_; ++i )
2633 for(
auto element=begin_[i]; element!=end_[i]; ++element )
2634 element->value_ *= scalar;
2659 template<
typename Type
2661 template<
typename Other >
2664 return static_cast<const void*>(
this ) == static_cast<const void*>( alias );
2679 template<
typename Type
2681 template<
typename Other >
2684 return static_cast<const void*>(
this ) == static_cast<const void*>( alias );
2699 template<
typename Type
2719 template<
typename Type
2721 template<
typename MT
2728 if( m_ == 0UL || n_ == 0UL )
2731 size_t nonzeros( 0UL );
2733 for(
size_t i=1UL; i<=m_; ++i )
2734 begin_[i] = end_[i] = end_[m_];
2736 for(
size_t i=0UL; i<m_; ++i )
2738 begin_[i] = end_[i] = begin_[0UL]+nonzeros;
2740 const size_t jbegin( ( IsUpper_v<MT> )
2741 ?( IsStrictlyUpper_v<MT> ? i+1UL : i )
2743 const size_t jend ( ( IsLower_v<MT> )
2744 ?( IsStrictlyLower_v<MT> ? i : i+1UL )
2747 for(
size_t j=jbegin; j<jend; ++j )
2750 reserveElements( extendCapacity() );
2751 for(
size_t k=i+1UL; k<=m_; ++k )
2752 begin_[k] = end_[k] = end_[m_];
2755 end_[i]->value_ = (~rhs)(i,j);
2757 if( !isDefault<strict>( end_[i]->value_ ) ) {
2758 end_[i]->index_ = j;
2765 begin_[m_] = begin_[0UL]+nonzeros;
2781 template<
typename Type
2783 template<
typename MT >
2791 if( m_ == 0UL || begin_[0] ==
nullptr )
2794 for(
size_t i=0UL; i<m_; ++i ) {
2795 end_[i] = castDown( std::copy( (~rhs).
begin(i), (~rhs).
end(i), castUp( begin_[i] ) ) );
2796 begin_[i+1UL] = end_[i];
2813 template<
typename Type
2815 template<
typename MT >
2826 std::vector<size_t> rowLengths( m_, 0UL );
2827 for(
size_t j=0UL; j<n_; ++j ) {
2828 for(
auto element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2829 ++rowLengths[element->index()];
2833 for(
size_t i=0UL; i<m_; ++i ) {
2834 begin_[i+1UL] = end_[i+1UL] = begin_[i] + rowLengths[i];
2838 for(
size_t j=0UL; j<n_; ++j ) {
2839 for(
auto element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2840 append( element->index(), j, element->value() );
2857 template<
typename Type
2859 template<
typename MT
2883 template<
typename Type
2885 template<
typename MT
2909 template<
typename Type
2911 template<
typename MT
2935 template<
typename Type
2937 template<
typename MT
2961 template<
typename Type
2963 template<
typename MT
2972 for(
size_t i=0UL; i<m_; ++i ) {
2974 for(
auto element=
begin(i); element!=last; ++element )
2975 element->value_ *= (~rhs)(i,element->index_);
3001 template<
typename Type >
3003 :
public SparseMatrix< CompressedMatrix<Type,true>, true >
3021 explicit Element() =
default;
3022 Element(
const Element& rhs ) =
default;
3023 Element( Element&& rhs ) =
default;
3027 inline Element&
operator=(
const Element& rhs )
3029 this->value_ = rhs.value_;
3033 inline Element&
operator=( Element&& rhs )
3035 this->value_ = std::move( rhs.value_ );
3039 template<
typename Other >
3040 inline auto operator=(
const Other& rhs )
3041 -> EnableIf_t< IsSparseElement_v<Other>, Element& >
3043 this->value_ = rhs.value();
3047 template<
typename Other >
3049 -> EnableIf_t< IsSparseElement_v< RemoveReference_t<Other> > &&
3050 IsRValueReference_v<Other&&>, Element& >
3052 this->value_ = std::move( rhs.value() );
3056 template<
typename Other >
3058 -> EnableIf_t< !IsSparseElement_v<Other>, Element& >
3064 template<
typename Other >
3066 -> EnableIf_t< !IsSparseElement_v< RemoveReference_t<Other> > &&
3067 IsRValueReference_v<Other&&>, Element& >
3069 this->value_ = std::move( v );
3083 struct Uninitialized {};
3088 using This = CompressedMatrix<Type,true>;
3089 using BaseType = SparseMatrix<This,true>;
3096 using Reference = MatrixAccessProxy<This>;
3105 template<
typename NewType >
3107 using Other = CompressedMatrix<NewType,true>;
3114 template<
size_t NewM
3117 using Other = CompressedMatrix<Type,true>;
3126 static constexpr
bool smpAssignable = !IsSMPAssignable_v<Type>;
3135 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
3136 inline CompressedMatrix( initializer_list< initializer_list<Type> > list );
3141 template<
typename MT,
bool SO >
inline CompressedMatrix(
const DenseMatrix<MT,SO>& dm );
3142 template<
typename MT,
bool SO >
inline CompressedMatrix(
const SparseMatrix<MT,SO>& sm );
3178 template<
typename MT,
bool SO >
inline CompressedMatrix& operator+=(
const Matrix<MT,SO>& rhs );
3179 template<
typename MT,
bool SO >
inline CompressedMatrix& operator-=(
const Matrix<MT,SO>& rhs );
3180 template<
typename MT,
bool SO >
inline CompressedMatrix& operator%=(
const DenseMatrix<MT,SO>& rhs );
3181 template<
typename MT,
bool SO >
inline CompressedMatrix& operator%=(
const SparseMatrix<MT,SO>& rhs );
3188 inline size_t rows() const noexcept;
3189 inline
size_t columns() const noexcept;
3190 inline
size_t capacity() const noexcept;
3191 inline
size_t capacity(
size_t j ) const noexcept;
3193 inline
size_t nonZeros(
size_t j ) const;
3194 inline
void reset();
3195 inline
void reset(
size_t j );
3196 inline
void clear();
3197 void resize (
size_t m,
size_t n,
bool preserve=true );
3198 inline
void reserve(
size_t nonzeros );
3199 void reserve(
size_t j,
size_t nonzeros );
3200 inline
void trim ();
3201 inline
void trim (
size_t j );
3210 inline
Iterator set (
size_t i,
size_t j, const Type& value );
3211 inline
Iterator insert (
size_t i,
size_t j, const Type& value );
3212 inline
void append (
size_t i,
size_t j, const Type& value,
bool check=false );
3220 inline
void erase(
size_t i,
size_t j );
3224 template< typename Pred >
3225 inline
void erase( Pred predicate );
3227 template< typename Pred >
3250 template< typename Other > inline
CompressedMatrix& scale( const Other& scalar );
3257 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
3258 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
3262 template< typename MT,
bool SO > inline
void assign ( const DenseMatrix<MT,SO>& rhs );
3263 template< typename MT > inline
void assign ( const SparseMatrix<MT,true>& rhs );
3264 template< typename MT > inline
void assign ( const SparseMatrix<MT,false>& rhs );
3265 template< typename MT,
bool SO > inline
void addAssign ( const DenseMatrix<MT,SO>& rhs );
3266 template< typename MT,
bool SO > inline
void addAssign ( const SparseMatrix<MT,SO>& rhs );
3267 template< typename MT,
bool SO > inline
void subAssign ( const DenseMatrix<MT,SO>& rhs );
3268 template< typename MT,
bool SO > inline
void subAssign ( const SparseMatrix<MT,SO>& rhs );
3269 template< typename MT,
bool SO > inline
void schurAssign( const DenseMatrix<MT,SO>& rhs );
3308 static const Type
zero_;
3332 template< typename Type >
3348 template<
typename Type >
3369 template<
typename Type >
3371 : CompressedMatrix( m, n, Uninitialized() )
3373 for(
size_t j=1UL; j<2UL*
n_+2UL; ++j )
3390 template<
typename Type >
3392 : CompressedMatrix( m, n, Uninitialized() )
3394 begin_[0UL] = allocate<Element>( nonzeros );
3395 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
3414 template<
typename Type >
3416 : CompressedMatrix( m, n, Uninitialized() )
3418 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
3420 size_t newCapacity( 0UL );
3421 for(
auto it=nonzeros.begin(); it!=nonzeros.end(); ++it )
3424 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
3425 for(
size_t j=0UL; j<
n_; ++j ) {
3454 template<
typename Type >
3458 for(
size_t j=0UL; j<
n_; ++j )
3462 for(
const auto& rowList : list )
3464 if( rowList.size() <= j ) {
3469 auto pos( rowList.begin() );
3470 std::advance( pos, j );
3471 if( !isDefault<strict>( *pos ) )
3489 template<
typename Type >
3491 : CompressedMatrix( sm.m_, sm.n_, Uninitialized() )
3493 const size_t nonzeros( sm.nonZeros() );
3495 begin_[0UL] = allocate<Element>( nonzeros );
3496 for(
size_t j=0UL; j<
n_; ++j ) {
3512 template<
typename Type >
3516 , capacity_( sm.capacity_ )
3517 , begin_ ( sm.begin_ )
3523 sm.begin_ =
nullptr;
3536 template<
typename Type >
3537 template<
typename MT
3540 : CompressedMatrix( (~dm).
rows(), (~dm).
columns() )
3542 using blaze::assign;
3556 template<
typename Type >
3557 template<
typename MT
3562 using blaze::assign;
3577 template<
typename Type >
3582 , begin_( new Iterator[2UL*n+2UL] )
3583 , end_ ( begin_+(n+1UL) )
3603 template<
typename Type >
3606 if( begin_ !=
nullptr ) {
3637 template<
typename Type >
3644 return Reference( *
this, i, j );
3661 template<
typename Type >
3668 const ConstIterator pos( lowerBound( i, j ) );
3670 if( pos == end_[j] || pos->index_ != i )
3693 template<
typename Type >
3703 return (*
this)(i,j);
3721 template<
typename Type >
3731 return (*
this)(i,j);
3744 template<
typename Type >
3762 template<
typename Type >
3780 template<
typename Type >
3798 template<
typename Type >
3816 template<
typename Type >
3834 template<
typename Type >
3875 template<
typename Type >
3876 inline CompressedMatrix<Type,true>&
3884 for(
size_t j=0UL; j<n_; ++j )
3888 for(
const auto& rowList : list )
3890 if( rowList.size() <= j ) {
3895 auto pos( rowList.begin() );
3896 std::advance( pos, j );
3897 if( !isDefault<strict>( *pos ) )
3898 append( i, j, *pos );
3921 template<
typename Type >
3922 inline CompressedMatrix<Type,true>&
3927 if( &rhs ==
this )
return *
this;
3929 const size_t nonzeros( rhs.nonZeros() );
3931 if( rhs.n_ > capacity_ || nonzeros >
capacity() )
3933 Iterator* newBegin(
new Iterator[2UL*rhs.n_+2UL] );
3934 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
3936 newBegin[0UL] = allocate<Element>( nonzeros );
3937 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3938 newEnd[j] = castDown( std::copy( rhs.begin_[j], rhs.end_[j], castUp( newBegin[j] ) ) );
3939 newBegin[j+1UL] = newEnd[j];
3941 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
3943 swap( begin_, newBegin );
3947 if( newBegin !=
nullptr ) {
3953 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3954 end_[j] = castDown( std::copy( rhs.begin_[j], rhs.end_[j], castUp( begin_[j] ) ) );
3955 begin_[j+1UL] = end_[j];
3975 template<
typename Type >
3976 inline CompressedMatrix<Type,true>&
3979 if( begin_ !=
nullptr ) {
3986 capacity_ = rhs.capacity_;
3987 begin_ = rhs.begin_;
3992 rhs.capacity_ = 0UL;
3993 rhs.begin_ =
nullptr;
4012 template<
typename Type >
4013 template<
typename MT
4015 inline CompressedMatrix<Type,true>&
4018 using blaze::assign;
4020 if( (~rhs).canAlias(
this ) ) {
4021 CompressedMatrix tmp( ~rhs );
4026 assign( *
this, ~rhs );
4045 template<
typename Type >
4046 template<
typename MT
4048 inline CompressedMatrix<Type,true>&
4051 using blaze::assign;
4053 if( (~rhs).canAlias(
this ) ||
4054 (~rhs).
columns() > capacity_ ||
4056 CompressedMatrix tmp( ~rhs );
4063 if( !IsZero_v<MT> ) {
4064 assign( *
this, ~rhs );
4085 template<
typename Type >
4086 template<
typename MT
4088 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
4090 using blaze::addAssign;
4092 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
4096 if( !IsZero_v<MT> ) {
4097 addAssign( *
this, ~rhs );
4117 template<
typename Type >
4118 template<
typename MT
4120 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
4122 using blaze::subAssign;
4124 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
4128 if( !IsZero_v<MT> ) {
4129 subAssign( *
this, ~rhs );
4150 template<
typename Type >
4151 template<
typename MT
4153 inline CompressedMatrix<Type,true>&
4154 CompressedMatrix<Type,true>::operator%=(
const DenseMatrix<MT,SO>& rhs )
4156 using blaze::schurAssign;
4158 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
4162 if( (~rhs).canAlias(
this ) ) {
4163 CompressedMatrix tmp( *
this % (~rhs) );
4167 CompositeType_t<MT> tmp( ~rhs );
4168 schurAssign( *
this, tmp );
4189 template<
typename Type >
4190 template<
typename MT
4192 inline CompressedMatrix<Type,true>&
4193 CompressedMatrix<Type,true>::operator%=(
const SparseMatrix<MT,SO>& rhs )
4195 if( (~rhs).
rows() != m_ || (~rhs).
columns() != n_ ) {
4199 if( !IsZero_v<MT> ) {
4200 CompressedMatrix tmp( *
this % (~rhs) );
4227 template<
typename Type >
4242 template<
typename Type >
4257 template<
typename Type >
4260 if( begin_ !=
nullptr )
4261 return end_[n_] - begin_[0UL];
4275 template<
typename Type >
4279 return begin_[j+1UL] - begin_[j];
4291 template<
typename Type >
4294 size_t nonzeros( 0UL );
4296 for(
size_t j=0UL; j<n_; ++j )
4312 template<
typename Type >
4316 return end_[j] - begin_[j];
4328 template<
typename Type >
4331 for(
size_t j=0UL; j<n_; ++j )
4332 end_[j] = begin_[j];
4348 template<
typename Type >
4352 end_[j] = begin_[j];
4366 template<
typename Type >
4369 if( end_ !=
nullptr )
4370 end_[0UL] = end_[n_];
4394 template<
typename Type >
4400 BLAZE_INTERNAL_ASSERT( begin_ ==
nullptr ||
size_t( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
4402 if( m == m_ && n == n_ )
return;
4404 if( begin_ ==
nullptr )
4406 begin_ =
new Iterator[2UL*n+2UL];
4407 end_ = begin_+n+1UL;
4409 for(
size_t j=0UL; j<2UL*n+2UL; ++j ) {
4410 begin_[j] =
nullptr;
4415 else if( n > capacity_ )
4417 Iterator* newBegin(
new Iterator[2UL*n+2UL] );
4418 Iterator* newEnd ( newBegin+n+1UL );
4420 newBegin[0UL] = begin_[0UL];
4423 for(
size_t j=0UL; j<n_; ++j ) {
4424 newEnd [j] = end_ [j];
4425 newBegin[j+1UL] = begin_[j+1UL];
4427 for(
size_t j=n_; j<n; ++j ) {
4428 newBegin[j+1UL] = newEnd[j] = begin_[n_];
4432 for(
size_t j=0UL; j<n; ++j ) {
4433 newBegin[j+1UL] = newEnd[j] = begin_[0UL];
4437 newEnd[n] = end_[n_];
4439 swap( newBegin, begin_ );
4449 for(
size_t j=0UL; j<n_; ++j )
4450 end_[j] = begin_[j];
4453 for(
size_t j=n_; j<n; ++j ) {
4454 begin_[j+1UL] = end_[j] = begin_[n_];
4460 for(
size_t j=0UL; j<n; ++j )
4461 end_[j] = lowerBound( m, j );
4464 for(
size_t j=0UL; j<n; ++j )
4465 end_[j] = begin_[j];
4475 BLAZE_INTERNAL_ASSERT(
size_t( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
4492 template<
typename Type >
4496 reserveElements( nonzeros );
4514 template<
typename Type >
4522 BLAZE_INTERNAL_ASSERT( static_cast<size_t>( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
4524 const size_t current(
capacity(j) );
4526 if( current >= nonzeros )
return;
4528 const ptrdiff_t additional( nonzeros - current );
4530 if( end_[n_] - begin_[n_] < additional )
4532 const size_t newCapacity( begin_[n_] - begin_[0UL] + additional );
4535 Iterator* newBegin(
new Iterator[2UL*n_+2UL] );
4536 Iterator* newEnd ( newBegin+n_+1UL );
4538 newBegin[0UL] = allocate<Element>( newCapacity );
4539 newEnd [n_ ] = newBegin[0UL]+newCapacity;
4541 for(
size_t k=0UL; k<j; ++k ) {
4542 newEnd [k ] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
4543 newBegin[k+1UL] = newBegin[k] +
capacity(k);
4545 newEnd [j ] = castDown(
transfer( begin_[j], end_[j], castUp( newBegin[j] ) ) );
4546 newBegin[j+1UL] = newBegin[j] + nonzeros;
4547 for(
size_t k=j+1UL; k<n_; ++k ) {
4548 newEnd [k ] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
4549 newBegin[k+1UL] = newBegin[k] +
capacity(k);
4554 swap( newBegin, begin_ );
4562 begin_[n_] += additional;
4563 for(
size_t k=n_-1UL; k>j; --k ) {
4564 begin_[k] = castDown( std::move_backward( begin_[k], end_[k], castUp( end_[k]+additional ) ) );
4565 end_ [k] += additional;
4570 BLAZE_INTERNAL_ASSERT( static_cast<size_t>( end_ - begin_ ) == capacity_ + 1UL,
"Invalid storage setting detected" );
4586 template<
typename Type >
4589 for(
size_t j=0UL; j<n_; ++j )
4607 template<
typename Type >
4612 if( j < ( n_ - 1UL ) )
4613 end_[j+1] = castDown( std::move( begin_[j+1], end_[j+1], castUp( end_[j] ) ) );
4614 begin_[j+1] = end_[j];
4630 template<
typename Type >
4634 CompressedMatrix( *this ).swap( *
this );
4648 template<
typename Type >
4655 swap( capacity_, sm.capacity_ );
4656 swap( begin_, sm.begin_ );
4657 swap( end_ , sm.end_ );
4672 template<
typename Type >
4675 size_t nonzeros( 2UL*
capacity()+1UL );
4693 template<
typename Type >
4698 Iterator* newBegin =
new Iterator[2UL*capacity_+2UL];
4699 Iterator* newEnd = newBegin+capacity_+1UL;
4701 newBegin[0UL] = allocate<Element>( nonzeros );
4703 for(
size_t k=0UL; k<n_; ++k ) {
4705 newEnd [k] = castDown(
transfer( begin_[k], end_[k], castUp( newBegin[k] ) ) );
4706 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
4709 newEnd[n_] = newBegin[0UL]+nonzeros;
4711 swap( newBegin, begin_ );
4714 if( newBegin !=
nullptr ) {
4731 template<
typename Type >
4735 return static_cast<Iterator>( it );
4748 template<
typename Type >
4752 return static_cast<IteratorBase>( it );
4778 template<
typename Type >
4785 const Iterator pos( lowerBound( i, j ) );
4787 if( pos != end_[j] && pos->index_ == i ) {
4788 pos->value() = value;
4791 else return insert( pos, i, j, value );
4811 template<
typename Type >
4818 const Iterator pos( lowerBound( i, j ) );
4820 if( pos != end_[j] && pos->index_ == i ) {
4824 return insert( pos, i, j, value );
4841 template<
typename Type >
4847 if( begin_[j+1UL] - end_[j] != 0 ) {
4848 std::move_backward( pos, end_[j], castUp( end_[j]+1UL ) );
4849 pos->value_ = value;
4855 else if( end_[n_] - begin_[n_] != 0 ) {
4856 std::move_backward( pos, end_[n_-1UL], castUp( end_[n_-1]+1UL ) );
4858 pos->value_ = value;
4861 for(
size_t k=j+1UL; k<n_+1UL; ++k ) {
4869 size_t newCapacity( extendCapacity() );
4871 Iterator* newBegin =
new Iterator[2UL*capacity_+2UL];
4872 Iterator* newEnd = newBegin+capacity_+1UL;
4874 newBegin[0UL] = allocate<Element>( newCapacity );
4876 for(
size_t k=0UL; k<j; ++k ) {
4877 const size_t nonzeros( end_[k] - begin_[k] );
4878 const size_t total( begin_[k+1UL] - begin_[k] );
4879 newEnd [k] = newBegin[k] + nonzeros;
4880 newBegin[k+1UL] = newBegin[k] + total;
4882 newEnd [j] = newBegin[j] + ( end_[j] - begin_[j] ) + 1;
4883 newBegin[j+1UL] = newBegin[j] + ( begin_[j+1UL] - begin_[j] ) + 1;
4884 for(
size_t k=j+1UL; k<n_; ++k ) {
4885 const size_t nonzeros( end_[k] - begin_[k] );
4886 const size_t total( begin_[k+1UL] - begin_[k] );
4887 newEnd [k] = newBegin[k] + nonzeros;
4888 newBegin[k+1UL] = newBegin[k] + total;
4891 newEnd[n_] = newEnd[capacity_] = newBegin[0UL]+newCapacity;
4893 Iterator tmp = castDown( std::move( begin_[0UL], pos, castUp( newBegin[0UL] ) ) );
4894 tmp->value_ = value;
4896 std::move( pos, end_[n_-1UL], castUp( tmp+1UL ) );
4898 swap( newBegin, begin_ );
4963 template<
typename Type >
4969 BLAZE_USER_ASSERT( begin_[j] == end_[j] || i > ( end_[j]-1UL )->index_,
"Index is not strictly increasing" );
4971 end_[j]->value_ = value;
4973 if( !check || !isDefault<strict>( end_[j]->value_ ) ) {
4974 end_[j]->index_ = i;
4996 template<
typename Type >
5001 begin_[j+1UL] = end_[j];
5003 end_[j+1UL] = end_[j];
5027 template<
typename Type >
5033 const Iterator pos( find( i, j ) );
5034 if( pos != end_[j] )
5035 end_[j] = castDown( std::move( pos+1, end_[j], castUp( pos ) ) );
5051 template<
typename Type >
5056 BLAZE_USER_ASSERT( pos >= begin_[j] && pos <= end_[j],
"Invalid compressed matrix iterator" );
5058 if( pos != end_[j] )
5059 end_[j] = castDown( std::move( pos+1, end_[j], castUp( pos ) ) );
5078 template<
typename Type >
5084 BLAZE_USER_ASSERT( first >= begin_[j] && first <= end_[j],
"Invalid compressed matrix iterator" );
5085 BLAZE_USER_ASSERT( last >= begin_[j] && last <= end_[j],
"Invalid compressed matrix iterator" );
5088 end_[j] = castDown( std::move( last, end_[j], castUp( first ) ) );
5118 template<
typename Type >
5119 template<
typename Pred >
5122 for(
size_t j=0UL; j<n_; ++j ) {
5123 end_[j] = castDown( std::remove_if( castUp( begin_[j] ), castUp( end_[j] ),
5124 [predicate=predicate](
const ElementBase& element ) {
5125 return predicate( element.value() );
5158 template<
typename Type >
5159 template<
typename Pred >
5164 BLAZE_USER_ASSERT( first >= begin_[j] && first <= end_[j],
"Invalid compressed matrix iterator" );
5165 BLAZE_USER_ASSERT( last >= begin_[j] && last <= end_[j],
"Invalid compressed matrix iterator" );
5167 const auto pos = std::remove_if( castUp( first ), castUp( last ),
5168 [predicate=predicate](
const ElementBase& element ) {
5169 return predicate( element.value() );
5172 end_[j] = castDown( std::move( last, end_[j], pos ) );
5201 template<
typename Type >
5205 return const_cast<Iterator>( const_cast<const This&>( *this ).find( i, j ) );
5226 template<
typename Type >
5230 const ConstIterator pos( lowerBound( i, j ) );
5231 if( pos != end_[j] && pos->index_ == i )
5233 else return end_[j];
5253 template<
typename Type >
5257 return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( i, j ) );
5277 template<
typename Type >
5282 return std::lower_bound( begin_[j], end_[j], i,
5283 [](
const Element& element,
size_t index )
5285 return element.index() < index;
5306 template<
typename Type >
5310 return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( i, j ) );
5330 template<
typename Type >
5335 return std::upper_bound( begin_[j], end_[j], i,
5336 [](
size_t index,
const Element& element )
5338 return index < element.index();
5359 template<
typename Type >
5362 CompressedMatrix tmp(
trans( *
this ) );
5376 template<
typename Type >
5379 CompressedMatrix tmp(
ctrans( *
this ) );
5405 template<
typename Type >
5406 template<
typename Other >
5407 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale(
const Other& scalar )
5409 for(
size_t j=0UL; j<n_; ++j )
5410 for(
auto element=begin_[j]; element!=end_[j]; ++element )
5411 element->value_ *= scalar;
5438 template<
typename Type >
5439 template<
typename Other >
5442 return static_cast<const void*>(
this ) == static_cast<const void*>( alias );
5459 template<
typename Type >
5460 template<
typename Other >
5463 return static_cast<const void*>(
this ) == static_cast<const void*>( alias );
5480 template<
typename Type >
5501 template<
typename Type >
5502 template<
typename MT
5509 if( m_ == 0UL || n_ == 0UL )
5512 size_t nonzeros( 0UL );
5514 for(
size_t j=1UL; j<=n_; ++j )
5515 begin_[j] = end_[j] = end_[n_];
5517 for(
size_t j=0UL; j<n_; ++j )
5519 begin_[j] = end_[j] = begin_[0UL]+nonzeros;
5521 const size_t ibegin( ( IsLower_v<MT> )
5522 ?( IsStrictlyLower_v<MT> ? j+1UL : j )
5524 const size_t iend ( ( IsUpper_v<MT> )
5525 ?( IsStrictlyUpper_v<MT> ? j : j+1UL )
5528 for(
size_t i=ibegin; i<iend; ++i )
5531 reserveElements( extendCapacity() );
5532 for(
size_t k=j+1UL; k<=n_; ++k )
5533 begin_[k] = end_[k] = end_[n_];
5536 end_[j]->value_ = (~rhs)(i,j);
5538 if( !isDefault<strict>( end_[j]->value_ ) ) {
5539 end_[j]->index_ = i;
5546 begin_[n_] = begin_[0UL]+nonzeros;
5564 template<
typename Type >
5565 template<
typename MT >
5573 if( n_ == 0UL || begin_[0] ==
nullptr )
5576 for(
size_t j=0UL; j<n_; ++j ) {
5577 end_[j] = castDown( std::copy( (~rhs).
begin(j), (~rhs).
end(j), castUp( begin_[j] ) ) );
5578 begin_[j+1UL] = end_[j];
5597 template<
typename Type >
5598 template<
typename MT >
5609 std::vector<size_t> columnLengths( n_, 0UL );
5610 for(
size_t i=0UL; i<m_; ++i ) {
5611 for(
auto element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5612 ++columnLengths[element->index()];
5616 for(
size_t j=0UL; j<n_; ++j ) {
5617 begin_[j+1UL] = end_[j+1UL] = begin_[j] + columnLengths[j];
5621 for(
size_t i=0UL; i<m_; ++i ) {
5622 for(
auto element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5623 append( i, element->index(), element->value() );
5642 template<
typename Type >
5643 template<
typename MT
5650 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
5669 template<
typename Type >
5670 template<
typename MT
5677 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
5696 template<
typename Type >
5697 template<
typename MT
5704 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
5723 template<
typename Type >
5724 template<
typename MT
5731 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
5750 template<
typename Type >
5751 template<
typename MT
5760 for(
size_t j=0UL; j<n_; ++j ) {
5761 const Iterator last(
end(j) );
5762 for(
auto element=
begin(j); element!=last; ++element )
5763 element->value_ *= (~rhs)(element->index_,j);
5785 template<
typename Type,
bool SO >
5786 void reset( CompressedMatrix<Type,SO>& m );
5788 template<
typename Type,
bool SO >
5789 void reset( CompressedMatrix<Type,SO>& m,
size_t i );
5791 template<
typename Type,
bool SO >
5792 void clear( CompressedMatrix<Type,SO>& m );
5794 template<
bool RF,
typename Type,
bool SO >
5795 bool isDefault(
const CompressedMatrix<Type,SO>& m );
5797 template<
typename Type,
bool SO >
5798 bool isIntact(
const CompressedMatrix<Type,SO>& m );
5800 template<
typename Type,
bool SO >
5801 void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) noexcept;
5813 template<
typename Type
5835 template<
typename Type
5851 template<
typename Type
5913 template<
typename Type
5930 template<
typename Type
5949 template<
typename T,
bool SO >
5950 struct IsResizable< CompressedMatrix<T,SO> >
5967 template<
typename T,
bool SO >
5968 struct IsShrinkable< CompressedMatrix<T,SO> >
5985 template<
typename T1,
typename T2 >
5986 struct AddTraitEval2< T1, T2
5989 using ET1 = ElementType_t<T1>;
5990 using ET2 = ElementType_t<T2>;
5992 static constexpr
bool SO = ( StorageOrder_v<T1> && StorageOrder_v<T2> );
5994 using Type = CompressedMatrix< AddTrait_t<ET1,ET2>, SO >;
6010 template<
typename T1,
typename T2 >
6011 struct SubTraitEval2< T1, T2
6014 using ET1 = ElementType_t<T1>;
6015 using ET2 = ElementType_t<T2>;
6017 static constexpr
bool SO = ( StorageOrder_v<T1> && StorageOrder_v<T2> );
6019 using Type = CompressedMatrix< SubTrait_t<ET1,ET2>, SO >;
6035 template<
typename T1
6037 struct SchurTraitEval2< T1, T2
6040 ( IsSparseMatrix_v<T1> || IsSparseMatrix_v<T2> ) > >
6042 using ET1 = ElementType_t<T1>;
6043 using ET2 = ElementType_t<T2>;
6045 static constexpr
bool SO = ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2>
6046 ? ( StorageOrder_v<T1> && StorageOrder_v<T2> )
6047 : ( IsSparseMatrix_v<T1>
6048 ? StorageOrder_v<T1>
6049 : StorageOrder_v<T2> ) );
6051 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, SO >;
6067 template<
typename T1,
typename T2 >
6068 struct MultTraitEval2< T1, T2
6071 using ET1 = ElementType_t<T1>;
6073 using Type = CompressedMatrix< MultTrait_t<ET1,T2>, StorageOrder_v<T1> >;
6076 template<
typename T1,
typename T2 >
6077 struct MultTraitEval2< T1, T2
6080 using ET2 = ElementType_t<T2>;
6082 using Type = CompressedMatrix< MultTrait_t<T1,ET2>, StorageOrder_v<T2> >;
6085 template<
typename T1,
typename T2 >
6086 struct MultTraitEval2< T1, T2
6089 IsColumnVector_v<T1> &&
6090 IsRowVector_v<T2> > >
6092 using ET1 = ElementType_t<T1>;
6093 using ET2 = ElementType_t<T2>;
6097 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, SO >;
6100 template<
typename T1,
typename T2 >
6101 struct MultTraitEval2< T1, T2
6103 IsSparseMatrix_v<T2> &&
6104 !( IsIdentity_v<T1> && IsIdentity_v<T2> ) > >
6106 using ET1 = ElementType_t<T1>;
6107 using ET2 = ElementType_t<T2>;
6109 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
6125 template<
typename T1
6127 struct KronTraitEval2< T1, T2
6130 ( IsSparseMatrix_v<T1> || IsSparseMatrix_v<T2> ) > >
6132 using ET1 = ElementType_t<T1>;
6133 using ET2 = ElementType_t<T2>;
6135 static constexpr
bool SO = ( IsDenseMatrix_v<T2> ? StorageOrder_v<T1> : StorageOrder_v<T2> );
6137 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, SO >;
6153 template<
typename T1,
typename T2 >
6154 struct DivTraitEval2< T1, T2
6157 using ET1 = ElementType_t<T1>;
6159 using Type = CompressedMatrix< DivTrait_t<ET1,T2>, StorageOrder_v<T1> >;
6175 template<
typename T,
typename OP >
6176 struct UnaryMapTraitEval2< T, OP
6179 using ET = ElementType_t<T>;
6181 using Type = CompressedMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
6197 template<
typename T
6199 struct ExpandTraitEval2< T, E
6204 using Type = CompressedMatrix< ElementType_t<T>, TF >;
6220 template<
typename T1,
bool SO,
typename T2 >
6221 struct HighType< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
6223 using Type = CompressedMatrix< typename HighType<T1,T2>::Type, SO >;
6239 template<
typename T1,
bool SO,
typename T2 >
6240 struct LowType< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
6242 using Type = CompressedMatrix< typename LowType<T1,T2>::Type, SO >;
6258 template<
typename MT,
size_t I,
size_t J,
size_t M,
size_t N >
6259 struct SubmatrixTraitEval2< MT, I, J, M, N
6262 using Type = CompressedMatrix< RemoveConst_t< ElementType_t<MT> >, StorageOrder_v<MT> >;
6278 template<
typename MT,
size_t M >
6279 struct RowsTraitEval2< MT, M
6282 using Type = CompressedMatrix< RemoveConst_t< ElementType_t<MT> >,
false >;
6298 template<
typename MT,
size_t N >
6299 struct ColumnsTraitEval2< MT, N
6302 using Type = CompressedMatrix< RemoveConst_t< ElementType_t<MT> >,
true >;
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
#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
Pointer difference type of the Blaze library.
void reserveElements(size_t nonzeros)
Reserving the specified number of compressed matrix elements.
Definition: CompressedMatrix.h:1916
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
Iterator * end_
Pointers one past the last non-zero element of each row.
Definition: CompressedMatrix.h:535
Header file for the Schur product trait.
void schurAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the Schur product assignment of a dense matrix.
Definition: CompressedMatrix.h:2965
constexpr bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.The IsMatrix_v variable template provides a c...
Definition: IsMatrix.h:138
#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
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: CompressedMatrix.h:1856
Header file for the subtraction trait.
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: CompressedMatrix.h:2701
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.
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: CompressedMatrix.h:2682
CompressedMatrix & ctranspose()
In-place conjugate transpose of the matrix.
Definition: CompressedMatrix.h:2601
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5932
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:324
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:579
Header file for the serial shim.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:227
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:355
Iterator end(size_t i) noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:1028
Reference operator()(size_t i, size_t j) noexcept
2D-access to the compressed matrix elements.
Definition: CompressedMatrix.h:854
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
MatrixAccessProxy< This > Reference
Reference to a compressed matrix value.
Definition: CompressedMatrix.h:325
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
void clear()
Clearing the compressed matrix.
Definition: CompressedMatrix.h:1593
Header file for the IsRowVector type trait.
Header file for the IsIdentity type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
SparseMatrix< This, SO > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:318
~CompressedMatrix()
The destructor for CompressedMatrix.
Definition: CompressedMatrix.h:820
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:101
size_t columns() const noexcept
Returns the current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:1464
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
Header file for all forward declarations of the math module.
Header file for memory allocation and deallocation functionality.
Iterator castDown(IteratorBase it) const noexcept
Performs a down-cast of the given iterator.
Definition: CompressedMatrix.h:1955
Header file for the extended initializer_list functionality.
ConstIterator cbegin(size_t i) const noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:1006
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes....
Definition: Forward.h:145
void swap(CompressedMatrix &sm) noexcept
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:1873
Constraint on the data type.
Header file for the IsMatrix type trait.
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:320
Header file for the SparseMatrix base class.
ElementBase * IteratorBase
Iterator over non-constant base elements.
Definition: CompressedMatrix.h:233
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:533
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
void reserve(size_t nonzeros)
Setting the minimum capacity of the compressed matrix.
Definition: CompressedMatrix.h:1717
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1555
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99
Headerfile for the generic max algorithm.
Header file for the ValueIndexPair class.
Header file for the LowType type trait.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper 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
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:321
Header file for the IsFloatingPoint type trait.
Header file for the IsShrinkable type trait.
Iterator set(size_t i, size_t j, const Type &value)
Setting an element of the compressed matrix.
Definition: CompressedMatrix.h:2003
Header file for the MatrixAccessProxy class.
IteratorBase castUp(Iterator it) const noexcept
Performs an up-cast of the given iterator.
Definition: CompressedMatrix.h:1973
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Header file for the expand trait.
void erase(size_t i, size_t j)
Erasing an element from the compressed matrix.
Definition: CompressedMatrix.h:2247
size_t rows() const noexcept
Returns the current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:1450
#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
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.In case the types T1 and T2 don't have the same size,...
Definition: SameSize.h:60
constexpr bool IsNumeric_v
Auxiliary variable template for the IsNumeric type trait.The IsNumeric_v variable template provides a...
Definition: IsNumeric.h:143
size_t capacity() const noexcept
Returns the maximum capacity of the compressed matrix.
Definition: CompressedMatrix.h:1478
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:537
ConstIterator cend(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:1072
Constraint on the data type.
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:317
Header file for the IsLower type trait.
Header file for the default storage order for all vectors of the Blaze library.
Header file for the Kron product trait.
Iterator insert(size_t i, size_t j, const Type &value)
Inserting an element into the compressed matrix.
Definition: CompressedMatrix.h:2035
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:323
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
void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:738
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
Constraint on the data type.
void subAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: CompressedMatrix.h:2913
size_t nonZeros() const
Returns the number of non-zero elements in the compressed matrix.
Definition: CompressedMatrix.h:1515
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:615
CompressedMatrix & operator=(initializer_list< initializer_list< Type > > list)
List assignment to all matrix elements.
Definition: CompressedMatrix.h:1112
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the compressed matrix.
Definition: CompressedMatrix.h:1620
Header file for the IsNumeric type trait.
Header file for the RemoveConst type trait.
Header file for the IsSparseVector type trait.
#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
bool canAlias(const Other *alias) const noexcept
Returns whether the matrix can alias with the given address alias.
Definition: CompressedMatrix.h:2662
CompressedMatrix< NewType, SO > Other
The type of the other CompressedMatrix.
Definition: CompressedMatrix.h:336
Header file for run time assertion macros.
Header file for the relaxation flag types.
typename T::CompositeType CompositeType_t
Alias declaration for nested CompositeType type definitions.The CompositeType_t alias declaration pro...
Definition: Aliases.h:90
Header file for the addition trait.
Resize mechanism to obtain a CompressedMatrix with different fixed dimensions.
Definition: CompressedMatrix.h:345
CompressedMatrix & transpose()
In-place transpose of the matrix.
Definition: CompressedMatrix.h:2585
Header file for the division trait.
void trim()
Removing all excessive capacity from all rows/columns.
Definition: CompressedMatrix.h:1813
Header file for the submatrix trait.
Constraint on the data type.
Header file for the columns trait.
Headerfile for the generic transfer algorithm.
Header file for the IsZero type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type,...
Definition: Reference.h:79
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:282
const Type & ConstReference
Reference to a constant compressed matrix value.
Definition: CompressedMatrix.h:326
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:114
constexpr Reference value() noexcept
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:370
Constraint on the data type.
Constraint on the data type.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:328
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
void assign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the assignment of a row-major dense matrix.
Definition: CompressedMatrix.h:2723
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
void append(size_t i, size_t j, const Type &value, bool check=false)
Appending an element to the specified row/column of the compressed matrix.
Definition: CompressedMatrix.h:2185
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2217
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:2425
Header file for the rows trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:534
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Constraint on the size of two data types.
void addAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the addition assignment of a dense matrix.
Definition: CompressedMatrix.h:2861
EnableIf_t< IsBuiltin_v< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:224
Header file for the default transpose flag for all vectors of the Blaze library.
Initializer list type of the Blaze library.
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less than the given index.
Definition: CompressedMatrix.h:2478
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: CompressedMatrix.h:2533
Header file for the StorageOrder type trait.
Header file for the IntegralConstant class template.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:327
Header file for the map trait.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
CompressedMatrix< Type, SO > Other
The type of the other CompressedMatrix.
Definition: CompressedMatrix.h:346
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
size_t extendCapacity() const noexcept
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1896
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:335
Header file for the IsUpper type trait.
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:532
constexpr bool IsSparseVector_v
Auxiliary variable template for the IsSparseVector type trait.The IsSparseVector_v variable template ...
Definition: IsSparseVector.h:138
Header file for the IsColumnVector type trait.
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition: Transfer.h:70
ValueIndexPair< Type > ElementBase
Base class for the compressed matrix element.
Definition: CompressedMatrix.h:232
Reference at(size_t i, size_t j)
Checked access to the matrix elements.
Definition: CompressedMatrix.h:908
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:319
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:531
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:322
constexpr size_t determineColumns(initializer_list< initializer_list< Type > > list) noexcept
Determines the maximum number of columns specified by the given initializer list.
Definition: InitializerList.h:108
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.The IsSparseMatrix_v variable template ...
Definition: IsSparseMatrix.h:138
Header file for the HighType type trait.
Iterator begin(size_t i) noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:962