35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_ 36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_ 222 template<
typename Type
223 ,
bool SO = defaultStorageOrder >
244 explicit Element() =
default;
245 Element(
const Element& rhs ) =
default;
246 Element( Element&& rhs ) =
default;
250 inline Element&
operator=(
const Element& rhs )
252 this->value_ = rhs.value_;
256 inline Element&
operator=( Element&& rhs )
258 this->value_ = std::move( rhs.value_ );
262 template<
typename Other >
263 inline auto operator=(
const Other& rhs )
266 this->value_ = rhs.value();
270 template<
typename Other >
273 IsRValueReference_v<Other&&>, Element& >
275 this->value_ = std::move( rhs.value() );
279 template<
typename Other >
287 template<
typename Other >
290 IsRValueReference_v<Other&&>, Element& >
292 this->value_ = std::move( v );
308 struct Uninitialized {};
331 template<
typename NewType >
340 template<
size_t NewM
361 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
414 inline size_t rows() const noexcept;
415 inline
size_t columns() const noexcept;
416 inline
size_t capacity() const noexcept;
417 inline
size_t capacity(
size_t i ) const noexcept;
419 inline
size_t nonZeros(
size_t i ) const;
421 inline
void reset(
size_t i );
423 void resize (
size_t m,
size_t n,
bool preserve=true );
424 inline
void reserve(
size_t nonzeros );
425 void reserve(
size_t i,
size_t nonzeros );
427 inline
void trim (
size_t i );
436 inline
Iterator set (
size_t i,
size_t j, const Type& value );
438 inline
void append (
size_t i,
size_t j, const Type& value,
bool check=false );
446 inline
void erase(
size_t i,
size_t j );
450 template< typename Pred >
451 inline
void erase( Pred predicate );
453 template< typename Pred >
476 template< typename Other > inline
CompressedMatrix& scale( const Other& scalar );
483 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
484 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
488 template< typename MT,
bool SO2 > inline
void assign ( const
DenseMatrix<MT,SO2>& rhs );
559 template< typename Type,
bool SO >
574 template<
typename Type
594 template<
typename Type
599 for(
size_t i=1UL; i<2UL*
m_+2UL; ++i )
614 template<
typename Type
619 begin_[0UL] = allocate<Element>( nonzeros );
620 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
638 template<
typename Type
643 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
645 size_t newCapacity( 0UL );
646 for(
auto it=nonzeros.begin(); it!=nonzeros.end(); ++it )
649 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
650 for(
size_t i=0UL; i<
m_; ++i ) {
677 template<
typename Type
684 for(
const auto& rowList : list )
688 for(
const Type& element : rowList ) {
689 if( !isDefault<strict>( element ) )
706 template<
typename Type
711 const size_t nonzeros( sm.
nonZeros() );
713 begin_[0UL] = allocate<Element>( nonzeros );
714 for(
size_t i=0UL; i<
m_; ++i ) {
728 template<
typename Type
751 template<
typename Type
753 template<
typename MT
770 template<
typename Type
772 template<
typename MT
790 template<
typename Type
815 template<
typename Type
848 template<
typename Type
871 template<
typename Type
881 if( pos ==
end_[i] || pos->index_ != j )
902 template<
typename Type
929 template<
typename Type
956 template<
typename Type
978 template<
typename Type
1000 template<
typename Type
1022 template<
typename Type
1044 template<
typename Type
1066 template<
typename Type
1106 template<
typename Type
1118 for(
const auto& rowList : list )
1122 for(
const Type& element : rowList ) {
1123 if( !isDefault<strict>( element ) )
1124 append( i, j, element );
1146 template<
typename Type
1153 if( &rhs ==
this )
return *
this;
1155 const size_t nonzeros( rhs.
nonZeros() );
1162 newBegin[0UL] = allocate<Element>( nonzeros );
1163 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
1164 newEnd[i] = castDown( std::copy( rhs.
begin_[i], rhs.
end_[i], castUp( newBegin[i] ) ) );
1165 newBegin[i+1UL] = newEnd[i];
1167 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
1173 if( newBegin !=
nullptr ) {
1179 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
1199 template<
typename Type
1204 if(
begin_ !=
nullptr ) {
1217 rhs.capacity_ = 0UL;
1218 rhs.begin_ =
nullptr;
1235 template<
typename Type
1237 template<
typename MT
1242 using blaze::assign;
1244 if( (~rhs).canAlias(
this ) ) {
1250 assign( *
this, ~rhs );
1267 template<
typename Type
1269 template<
typename MT
1274 using blaze::assign;
1276 if( (~rhs).canAlias(
this ) ||
1285 assign( *
this, ~rhs );
1303 template<
typename Type
1305 template<
typename MT
1310 using blaze::addAssign;
1316 addAssign( *
this, ~rhs );
1332 template<
typename Type
1334 template<
typename MT
1338 using blaze::subAssign;
1344 subAssign( *
this, ~rhs );
1361 template<
typename Type
1363 template<
typename MT
1368 using blaze::schurAssign;
1374 if( (~rhs).canAlias(
this ) ) {
1380 schurAssign( *
this, tmp );
1399 template<
typename Type
1401 template<
typename MT
1431 template<
typename Type
1445 template<
typename Type
1459 template<
typename Type
1481 template<
typename Type
1496 template<
typename Type
1500 size_t nonzeros( 0UL );
1502 for(
size_t i=0UL; i<
m_; ++i )
1521 template<
typename Type
1536 template<
typename Type
1540 for(
size_t i=0UL; i<
m_; ++i )
1557 template<
typename Type
1574 template<
typename Type
1578 if(
end_ !=
nullptr )
1601 template<
typename Type
1610 if( m ==
m_ && n ==
n_ )
return;
1617 for(
size_t i=0UL; i<2UL*m+2UL; ++i ) {
1626 Iterator* newEnd ( newBegin+m+1UL );
1628 newBegin[0UL] =
begin_[0UL];
1631 for(
size_t i=0UL; i<
m_; ++i ) {
1632 newEnd [i] =
end_ [i];
1633 newBegin[i+1UL] =
begin_[i+1UL];
1635 for(
size_t i=
m_; i<m; ++i ) {
1636 newBegin[i+1UL] = newEnd[i] =
begin_[
m_];
1640 for(
size_t i=0UL; i<m; ++i ) {
1641 newBegin[i+1UL] = newEnd[i] =
begin_[0UL];
1657 for(
size_t i=0UL; i<
m_; ++i )
1661 for(
size_t i=
m_; i<m; ++i ) {
1668 for(
size_t i=0UL; i<m; ++i )
1669 end_[i] = lowerBound( i, n );
1672 for(
size_t i=0UL; i<m; ++i )
1698 template<
typename Type
1703 reserveElements( nonzeros );
1722 template<
typename Type
1733 const size_t current(
capacity(i) );
1735 if( current >= nonzeros )
return;
1737 const ptrdiff_t additional( nonzeros - current );
1741 const size_t newCapacity(
begin_[
m_] -
begin_[0UL] + additional );
1747 newBegin[0UL] = allocate<Element>( newCapacity );
1748 newEnd [
m_ ] = newBegin[0UL]+newCapacity;
1750 for(
size_t k=0UL; k<i; ++k ) {
1752 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1755 newBegin[i+1UL] = newBegin[i] + nonzeros;
1756 for(
size_t k=i+1UL; k<
m_; ++k ) {
1758 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1772 for(
size_t j=
m_-1UL; j>i; --j ) {
1773 begin_[j] = castDown( std::move_backward(
begin_[j],
end_[j], castUp(
end_[j]+additional ) ) );
1774 end_ [j] += additional;
1794 template<
typename Type
1798 for(
size_t i=0UL; i<
m_; ++i )
1815 template<
typename Type
1821 if( i < (
m_ - 1UL ) )
1837 template<
typename Type
1854 template<
typename Type
1877 template<
typename Type
1881 size_t nonzeros( 2UL*
capacity()+1UL );
1897 template<
typename Type
1906 newBegin[0UL] = allocate<Element>( nonzeros );
1908 for(
size_t k=0UL; k<
m_; ++k ) {
1911 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
1914 newEnd[
m_] = newBegin[0UL]+nonzeros;
1919 if( newBegin !=
nullptr ) {
1935 template<
typename Type
1940 return static_cast<Iterator>( it );
1953 template<
typename Type
1983 template<
typename Type
1991 const Iterator pos( lowerBound( i, j ) );
1993 if( pos !=
end_[i] && pos->index_ == j ) {
1994 pos->value() = value;
1997 else return insert( pos, i, j, value );
2015 template<
typename Type
2023 const Iterator pos( lowerBound( i, j ) );
2025 if( pos !=
end_[i] && pos->index_ == j ) {
2029 return insert( pos, i, j, value );
2044 template<
typename Type
2052 std::move_backward( pos,
end_[i], castUp(
end_[i]+1UL ) );
2053 pos->value_ = value;
2060 std::move_backward( pos,
end_[
m_-1UL], castUp(
end_[
m_-1UL]+1UL ) );
2062 pos->value_ = value;
2065 for(
size_t k=i+1UL; k<
m_+1UL; ++k ) {
2073 size_t newCapacity( extendCapacity() );
2078 newBegin[0UL] = allocate<Element>( newCapacity );
2080 for(
size_t k=0UL; k<i; ++k ) {
2081 const size_t nonzeros(
end_[k] -
begin_[k] );
2083 newEnd [k] = newBegin[k] + nonzeros;
2084 newBegin[k+1UL] = newBegin[k] + total;
2086 newEnd [i] = newBegin[i] + (
end_[i] -
begin_[i] ) + 1;
2087 newBegin[i+1UL] = newBegin[i] + (
begin_[i+1] -
begin_[i] ) + 1;
2088 for(
size_t k=i+1UL; k<
m_; ++k ) {
2089 const size_t nonzeros(
end_[k] -
begin_[k] );
2091 newEnd [k] = newBegin[k] + nonzeros;
2092 newBegin[k+1UL] = newBegin[k] + total;
2095 newEnd[
m_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
2097 Iterator tmp = castDown( std::move(
begin_[0UL], pos, castUp( newBegin[0UL] ) ) );
2098 tmp->value_ = value;
2100 std::move( pos,
end_[
m_-1UL], castUp( tmp+1UL ) );
2166 template<
typename Type
2175 end_[i]->value_ = value;
2177 if( !check || !isDefault<strict>(
end_[i]->value_ ) ) {
2178 end_[i]->index_ = j;
2198 template<
typename Type
2228 template<
typename Type
2235 const Iterator pos( find( i, j ) );
2236 if( pos !=
end_[i] )
2237 end_[i] = castDown( std::move( pos+1,
end_[i], castUp( pos ) ) );
2253 template<
typename Type
2261 if( pos !=
end_[i] )
2262 end_[i] = castDown( std::move( pos+1,
end_[i], castUp( pos ) ) );
2281 template<
typename Type
2292 end_[i] = castDown( std::move( last,
end_[i], castUp( first ) ) );
2320 template<
typename Type
2322 template<
typename Pred >
2325 for(
size_t i=0UL; i<
m_; ++i ) {
2326 end_[i] = castDown( std::remove_if( castUp(
begin_[i] ), castUp(
end_[i] ),
2327 [predicate=predicate](
const ElementBase& element) {
2328 return predicate( element.
value() );
2362 template<
typename Type
2364 template<
typename Pred >
2372 const auto pos = std::remove_if( castUp( first ), castUp( last ),
2373 [predicate=predicate](
const ElementBase& element ) {
2374 return predicate( element.
value() );
2377 end_[i] = castDown( std::move( last,
end_[i], pos ) );
2405 template<
typename Type
2410 return const_cast<Iterator>(
const_cast<const This&
>( *this ).
find( i, j ) );
2430 template<
typename Type
2436 if( pos !=
end_[i] && pos->index_ == j )
2438 else return end_[i];
2458 template<
typename Type
2483 template<
typename Type
2489 return std::lower_bound(
begin_[i],
end_[i], j,
2490 [](
const Element& element,
size_t index )
2492 return element.index() < index;
2513 template<
typename Type
2538 template<
typename Type
2544 return std::upper_bound(
begin_[i],
end_[i], j,
2545 [](
size_t index,
const Element& element )
2547 return index < element.index();
2566 template<
typename Type
2582 template<
typename Type
2610 template<
typename Type
2612 template<
typename Other >
2615 for(
size_t i=0UL; i<
m_; ++i )
2616 for(
auto element=
begin_[i]; element!=
end_[i]; ++element )
2617 element->value_ *= scalar;
2642 template<
typename Type
2644 template<
typename Other >
2647 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2662 template<
typename Type
2664 template<
typename Other >
2667 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2682 template<
typename Type
2702 template<
typename Type
2704 template<
typename MT
2711 if(
m_ == 0UL ||
n_ == 0UL )
2714 size_t nonzeros( 0UL );
2716 for(
size_t i=1UL; i<=
m_; ++i )
2719 for(
size_t i=0UL; i<
m_; ++i )
2723 const size_t jbegin( ( IsUpper_v<MT> )
2724 ?( IsStrictlyUpper_v<MT> ? i+1UL : i )
2726 const size_t jend ( ( IsLower_v<MT> )
2727 ?( IsStrictlyLower_v<MT> ? i : i+1UL )
2730 for(
size_t j=jbegin; j<jend; ++j )
2733 reserveElements( extendCapacity() );
2734 for(
size_t k=i+1UL; k<=
m_; ++k )
2738 end_[i]->value_ = (~rhs)(i,j);
2740 if( !isDefault<strict>(
end_[i]->value_ ) ) {
2741 end_[i]->index_ = j;
2764 template<
typename Type
2766 template<
typename MT >
2774 if(
m_ == 0UL ||
begin_[0] ==
nullptr )
2777 for(
size_t i=0UL; i<
m_; ++i ) {
2778 end_[i] = castDown( std::copy( (~rhs).
begin(i), (~rhs).
end(i), castUp(
begin_[i] ) ) );
2796 template<
typename Type
2798 template<
typename MT >
2809 std::vector<size_t> rowLengths(
m_, 0UL );
2810 for(
size_t j=0UL; j<
n_; ++j ) {
2811 for(
auto element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2812 ++rowLengths[element->index()];
2816 for(
size_t i=0UL; i<
m_; ++i ) {
2821 for(
size_t j=0UL; j<
n_; ++j ) {
2822 for(
auto element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2823 append( element->index(), j, element->value() );
2840 template<
typename Type
2842 template<
typename MT
2866 template<
typename Type
2868 template<
typename MT
2892 template<
typename Type
2894 template<
typename MT
2918 template<
typename Type
2920 template<
typename MT
2944 template<
typename Type
2946 template<
typename MT
2955 for(
size_t i=0UL; i<
m_; ++i ) {
2957 for(
auto element=
begin(i); element!=last; ++element )
2958 element->value_ *= (~rhs)(i,element->index_);
2984 template<
typename Type >
2986 :
public SparseMatrix< CompressedMatrix<Type,true>, true >
3005 explicit Element() =
default;
3006 Element(
const Element& rhs ) =
default;
3007 Element( Element&& rhs ) =
default;
3011 inline Element&
operator=(
const Element& rhs )
3013 this->value_ = rhs.value_;
3017 inline Element&
operator=( Element&& rhs )
3019 this->value_ = std::move( rhs.value_ );
3023 template<
typename Other >
3024 inline auto operator=(
const Other& rhs )
3025 -> EnableIf_t< IsSparseElement_v<Other>, Element& >
3027 this->value_ = rhs.value();
3031 template<
typename Other >
3033 -> EnableIf_t< IsSparseElement_v< RemoveReference_t<Other> > &&
3034 IsRValueReference_v<Other&&>, Element& >
3036 this->value_ = std::move( rhs.value() );
3040 template<
typename Other >
3042 -> EnableIf_t< !IsSparseElement_v<Other>, Element& >
3048 template<
typename Other >
3050 -> EnableIf_t< !IsSparseElement_v< RemoveReference_t<Other> > &&
3051 IsRValueReference_v<Other&&>, Element& >
3053 this->value_ = std::move( v );
3069 struct Uninitialized {};
3092 template<
typename NewType >
3101 template<
size_t NewM
3122 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
3175 inline size_t rows() const noexcept;
3176 inline
size_t columns() const noexcept;
3177 inline
size_t capacity() const noexcept;
3178 inline
size_t capacity(
size_t j ) const noexcept;
3180 inline
size_t nonZeros(
size_t j ) const;
3181 inline
void reset();
3182 inline
void reset(
size_t j );
3183 inline
void clear();
3184 void resize (
size_t m,
size_t n,
bool preserve=true );
3185 inline
void reserve(
size_t nonzeros );
3186 void reserve(
size_t j,
size_t nonzeros );
3187 inline
void trim ();
3188 inline
void trim (
size_t j );
3197 inline
Iterator set (
size_t i,
size_t j, const Type& value );
3198 inline
Iterator insert (
size_t i,
size_t j, const Type& value );
3199 inline
void append (
size_t i,
size_t j, const Type& value,
bool check=false );
3207 inline
void erase(
size_t i,
size_t j );
3211 template< typename Pred >
3212 inline
void erase( Pred predicate );
3214 template< typename Pred >
3237 template< typename Other > inline
CompressedMatrix& scale( const Other& scalar );
3244 template< typename Other > inline
bool canAlias ( const Other* alias ) const noexcept;
3245 template< typename Other > inline
bool isAliased( const Other* alias ) const noexcept;
3249 template< typename MT,
bool SO > inline
void assign ( const
DenseMatrix<MT,SO>& rhs );
3321 template< typename Type >
3337 template<
typename Type >
3358 template<
typename Type >
3359 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n )
3360 : CompressedMatrix( m, n, Uninitialized() )
3362 for(
size_t j=1UL; j<2UL*
n_+2UL; ++j )
3379 template<
typename Type >
3380 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
size_t nonzeros )
3381 : CompressedMatrix( m, n, Uninitialized() )
3383 begin_[0UL] = allocate<Element>( nonzeros );
3384 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
3403 template<
typename Type >
3404 CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros )
3405 : CompressedMatrix( m, n, Uninitialized() )
3407 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
3409 size_t newCapacity( 0UL );
3410 for(
auto it=nonzeros.begin(); it!=nonzeros.end(); ++it )
3413 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
3414 for(
size_t j=0UL; j<
n_; ++j ) {
3443 template<
typename Type >
3444 inline CompressedMatrix<Type,true>::CompressedMatrix( initializer_list< initializer_list<Type> > list )
3447 for(
size_t j=0UL; j<
n_; ++j )
3451 for(
const auto& rowList : list )
3453 if( rowList.size() <= j ) {
3458 auto pos( rowList.begin() );
3459 std::advance( pos, j );
3460 if( !isDefault<strict>( *pos ) )
3461 append( i, j, *pos );
3478 template<
typename Type >
3479 inline CompressedMatrix<Type,true>::CompressedMatrix(
const CompressedMatrix& sm )
3480 : CompressedMatrix( sm.
m_, sm.
n_, Uninitialized() )
3482 const size_t nonzeros( sm.nonZeros() );
3484 begin_[0UL] = allocate<Element>( nonzeros );
3485 for(
size_t j=0UL; j<
n_; ++j ) {
3486 end_[j] = castDown( std::copy( sm.begin(j), sm.end(j), castUp(
begin_[j] ) ) );
3501 template<
typename Type >
3502 inline CompressedMatrix<Type,true>::CompressedMatrix( CompressedMatrix&& sm ) noexcept
3512 sm.begin_ =
nullptr;
3525 template<
typename Type >
3526 template<
typename MT
3528 inline CompressedMatrix<Type,true>::CompressedMatrix(
const DenseMatrix<MT,SO>& dm )
3529 : CompressedMatrix( (~dm).
rows(), (~dm).
columns() )
3531 using blaze::assign;
3533 assign( *
this, ~dm );
3545 template<
typename Type >
3546 template<
typename MT
3548 inline CompressedMatrix<Type,true>::CompressedMatrix(
const SparseMatrix<MT,SO>& sm )
3551 using blaze::assign;
3553 assign( *
this, ~sm );
3566 template<
typename Type >
3567 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n, Uninitialized )
3592 template<
typename Type >
3593 inline CompressedMatrix<Type,true>::~CompressedMatrix()
3595 if(
begin_ !=
nullptr ) {
3626 template<
typename Type >
3628 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j ) noexcept
3650 template<
typename Type >
3652 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
const noexcept
3659 if( pos ==
end_[j] || pos->index_ != i )
3682 template<
typename Type >
3684 CompressedMatrix<Type,true>::at(
size_t i,
size_t j )
3692 return (*
this)(i,j);
3710 template<
typename Type >
3712 CompressedMatrix<Type,true>::at(
size_t i,
size_t j )
const 3720 return (*
this)(i,j);
3733 template<
typename Type >
3735 CompressedMatrix<Type,true>::begin(
size_t j ) noexcept
3751 template<
typename Type >
3753 CompressedMatrix<Type,true>::begin(
size_t j )
const noexcept
3769 template<
typename Type >
3771 CompressedMatrix<Type,true>::cbegin(
size_t j )
const noexcept
3787 template<
typename Type >
3789 CompressedMatrix<Type,true>::end(
size_t j ) noexcept
3805 template<
typename Type >
3807 CompressedMatrix<Type,true>::end(
size_t j )
const noexcept
3823 template<
typename Type >
3825 CompressedMatrix<Type,true>::cend(
size_t j )
const noexcept
3864 template<
typename Type >
3865 inline CompressedMatrix<Type,true>&
3866 CompressedMatrix<Type,true>::operator=( initializer_list< initializer_list<Type> > list )
3873 for(
size_t j=0UL; j<
n_; ++j )
3877 for(
const auto& rowList : list )
3879 if( rowList.size() <= j ) {
3884 auto pos( rowList.begin() );
3885 std::advance( pos, j );
3886 if( !isDefault<strict>( *pos ) )
3887 append( i, j, *pos );
3910 template<
typename Type >
3911 inline CompressedMatrix<Type,true>&
3912 CompressedMatrix<Type,true>::operator=(
const CompressedMatrix& rhs )
3916 if( &rhs ==
this )
return *
this;
3918 const size_t nonzeros( rhs.nonZeros() );
3923 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
3925 newBegin[0UL] = allocate<Element>( nonzeros );
3926 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3927 newEnd[j] = castDown( std::copy( rhs.begin_[j], rhs.end_[j], castUp( newBegin[j] ) ) );
3928 newBegin[j+1UL] = newEnd[j];
3930 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
3936 if( newBegin !=
nullptr ) {
3942 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3943 end_[j] = castDown( std::copy( rhs.begin_[j], rhs.end_[j], castUp(
begin_[j] ) ) );
3964 template<
typename Type >
3965 inline CompressedMatrix<Type,true>&
3966 CompressedMatrix<Type,true>::operator=( CompressedMatrix&& rhs ) noexcept
3968 if(
begin_ !=
nullptr ) {
3981 rhs.capacity_ = 0UL;
3982 rhs.begin_ =
nullptr;
4001 template<
typename Type >
4002 template<
typename MT
4004 inline CompressedMatrix<Type,true>&
4005 CompressedMatrix<Type,true>::operator=(
const DenseMatrix<MT,SO>& rhs )
4007 using blaze::assign;
4009 if( (~rhs).canAlias(
this ) ) {
4010 CompressedMatrix tmp( ~rhs );
4015 assign( *
this, ~rhs );
4034 template<
typename Type >
4035 template<
typename MT
4037 inline CompressedMatrix<Type,true>&
4038 CompressedMatrix<Type,true>::operator=(
const SparseMatrix<MT,SO>& rhs )
4040 using blaze::assign;
4042 if( (~rhs).canAlias(
this ) ||
4045 CompressedMatrix tmp( ~rhs );
4051 assign( *
this, ~rhs );
4071 template<
typename Type >
4072 template<
typename MT
4074 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
4076 using blaze::addAssign;
4082 addAssign( *
this, ~rhs );
4100 template<
typename Type >
4101 template<
typename MT
4103 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
4105 using blaze::subAssign;
4111 subAssign( *
this, ~rhs );
4130 template<
typename Type >
4131 template<
typename MT
4133 inline CompressedMatrix<Type,true>&
4134 CompressedMatrix<Type,true>::operator%=(
const DenseMatrix<MT,SO>& rhs )
4136 using blaze::schurAssign;
4142 if( (~rhs).canAlias(
this ) ) {
4143 CompressedMatrix tmp( *
this % (~rhs) );
4147 CompositeType_t<MT> tmp( ~rhs );
4148 schurAssign( *
this, tmp );
4169 template<
typename Type >
4170 template<
typename MT
4172 inline CompressedMatrix<Type,true>&
4173 CompressedMatrix<Type,true>::operator%=(
const SparseMatrix<MT,SO>& rhs )
4179 CompressedMatrix tmp( *
this % (~rhs) );
4202 template<
typename Type >
4203 inline size_t CompressedMatrix<Type,true>::rows() const noexcept
4217 template<
typename Type >
4218 inline size_t CompressedMatrix<Type,true>::columns() const noexcept
4232 template<
typename Type >
4233 inline size_t CompressedMatrix<Type,true>::capacity() const noexcept
4250 template<
typename Type >
4251 inline size_t CompressedMatrix<Type,true>::capacity(
size_t j )
const noexcept
4266 template<
typename Type >
4267 inline size_t CompressedMatrix<Type,true>::nonZeros()
const 4269 size_t nonzeros( 0UL );
4271 for(
size_t j=0UL; j<
n_; ++j )
4287 template<
typename Type >
4288 inline size_t CompressedMatrix<Type,true>::nonZeros(
size_t j )
const 4303 template<
typename Type >
4306 for(
size_t j=0UL; j<
n_; ++j )
4323 template<
typename Type >
4341 template<
typename Type >
4344 if(
end_ !=
nullptr )
4369 template<
typename Type >
4370 void CompressedMatrix<Type,true>::resize(
size_t m,
size_t n,
bool preserve )
4377 if( m ==
m_ && n ==
n_ )
return;
4384 for(
size_t j=0UL; j<2UL*n+2UL; ++j ) {
4393 Iterator* newEnd ( newBegin+n+1UL );
4395 newBegin[0UL] =
begin_[0UL];
4398 for(
size_t j=0UL; j<
n_; ++j ) {
4399 newEnd [j] =
end_ [j];
4400 newBegin[j+1UL] =
begin_[j+1UL];
4402 for(
size_t j=
n_; j<n; ++j ) {
4403 newBegin[j+1UL] = newEnd[j] =
begin_[
n_];
4407 for(
size_t j=0UL; j<n; ++j ) {
4408 newBegin[j+1UL] = newEnd[j] =
begin_[0UL];
4424 for(
size_t j=0UL; j<
n_; ++j )
4428 for(
size_t j=
n_; j<n; ++j ) {
4435 for(
size_t j=0UL; j<n; ++j )
4436 end_[j] = lowerBound( m, j );
4439 for(
size_t j=0UL; j<n; ++j )
4467 template<
typename Type >
4468 inline void CompressedMatrix<Type,true>::reserve(
size_t nonzeros )
4471 reserveElements( nonzeros );
4489 template<
typename Type >
4490 void CompressedMatrix<Type,true>::reserve(
size_t j,
size_t nonzeros )
4499 const size_t current(
capacity(j) );
4501 if( current >= nonzeros )
return;
4503 const ptrdiff_t additional( nonzeros - current );
4507 const size_t newCapacity(
begin_[
n_] -
begin_[0UL] + additional );
4513 newBegin[0UL] = allocate<Element>( newCapacity );
4514 newEnd [
n_ ] = newBegin[0UL]+newCapacity;
4516 for(
size_t k=0UL; k<j; ++k ) {
4518 newBegin[k+1UL] = newBegin[k] +
capacity(k);
4521 newBegin[j+1UL] = newBegin[j] + nonzeros;
4522 for(
size_t k=j+1UL; k<
n_; ++k ) {
4524 newBegin[k+1UL] = newBegin[k] +
capacity(k);
4538 for(
size_t k=
n_-1UL; k>j; --k ) {
4539 begin_[k] = castDown( std::move_backward(
begin_[k],
end_[k], castUp(
end_[k]+additional ) ) );
4540 end_ [k] += additional;
4561 template<
typename Type >
4562 void CompressedMatrix<Type,true>::trim()
4564 for(
size_t j=0UL; j<
n_; ++j )
4582 template<
typename Type >
4583 void CompressedMatrix<Type,true>::trim(
size_t j )
4587 if( j < (
n_ - 1UL ) )
4605 template<
typename Type >
4606 inline void CompressedMatrix<Type,true>::shrinkToFit()
4609 CompressedMatrix( *this ).swap( *
this );
4623 template<
typename Type >
4647 template<
typename Type >
4648 inline size_t CompressedMatrix<Type,true>::extendCapacity() const noexcept
4650 size_t nonzeros( 2UL*
capacity()+1UL );
4668 template<
typename Type >
4669 void CompressedMatrix<Type,true>::reserveElements(
size_t nonzeros )
4676 newBegin[0UL] = allocate<Element>( nonzeros );
4678 for(
size_t k=0UL; k<
n_; ++k ) {
4681 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
4684 newEnd[
n_] = newBegin[0UL]+nonzeros;
4689 if( newBegin !=
nullptr ) {
4706 template<
typename Type >
4708 CompressedMatrix<Type,true>::castDown( IteratorBase it )
const noexcept
4710 return static_cast<Iterator>( it );
4723 template<
typename Type >
4724 inline typename CompressedMatrix<Type,true>::IteratorBase
4725 CompressedMatrix<Type,true>::castUp(
Iterator it )
const noexcept
4727 return static_cast<IteratorBase
>( it );
4753 template<
typename Type >
4755 CompressedMatrix<Type,true>::set(
size_t i,
size_t j,
const Type& value )
4760 const Iterator pos( lowerBound( i, j ) );
4762 if( pos !=
end_[j] && pos->index_ == i ) {
4763 pos->value() = value;
4766 else return insert( pos, i, j, value );
4786 template<
typename Type >
4788 CompressedMatrix<Type,true>::insert(
size_t i,
size_t j,
const Type& value )
4793 const Iterator pos( lowerBound( i, j ) );
4795 if( pos !=
end_[j] && pos->index_ == i ) {
4799 return insert( pos, i, j, value );
4816 template<
typename Type >
4818 CompressedMatrix<Type,true>::insert(
Iterator pos,
size_t i,
size_t j,
const Type& value )
4823 std::move_backward( pos,
end_[j], castUp(
end_[j]+1UL ) );
4824 pos->value_ = value;
4831 std::move_backward( pos,
end_[
n_-1UL], castUp(
end_[
n_-1]+1UL ) );
4833 pos->value_ = value;
4836 for(
size_t k=j+1UL; k<
n_+1UL; ++k ) {
4844 size_t newCapacity( extendCapacity() );
4849 newBegin[0UL] = allocate<Element>( newCapacity );
4851 for(
size_t k=0UL; k<j; ++k ) {
4852 const size_t nonzeros(
end_[k] -
begin_[k] );
4854 newEnd [k] = newBegin[k] + nonzeros;
4855 newBegin[k+1UL] = newBegin[k] + total;
4857 newEnd [j] = newBegin[j] + (
end_[j] -
begin_[j] ) + 1;
4858 newBegin[j+1UL] = newBegin[j] + (
begin_[j+1UL] -
begin_[j] ) + 1;
4859 for(
size_t k=j+1UL; k<
n_; ++k ) {
4860 const size_t nonzeros(
end_[k] -
begin_[k] );
4862 newEnd [k] = newBegin[k] + nonzeros;
4863 newBegin[k+1UL] = newBegin[k] + total;
4866 newEnd[
n_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
4868 Iterator tmp = castDown( std::move(
begin_[0UL], pos, castUp( newBegin[0UL] ) ) );
4869 tmp->value_ = value;
4871 std::move( pos,
end_[
n_-1UL], castUp( tmp+1UL ) );
4938 template<
typename Type >
4939 inline void CompressedMatrix<Type,true>::append(
size_t i,
size_t j,
const Type& value,
bool check )
4946 end_[j]->value_ = value;
4948 if( !check || !isDefault<strict>(
end_[j]->value_ ) ) {
4949 end_[j]->index_ = i;
4971 template<
typename Type >
4972 inline void CompressedMatrix<Type,true>::finalize(
size_t j )
5002 template<
typename Type >
5003 inline void CompressedMatrix<Type,true>::erase(
size_t i,
size_t j )
5008 const Iterator pos( find( i, j ) );
5009 if( pos !=
end_[j] )
5010 end_[j] = castDown( std::move( pos+1,
end_[j], castUp( pos ) ) );
5026 template<
typename Type >
5028 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator pos )
5033 if( pos !=
end_[j] )
5034 end_[j] = castDown( std::move( pos+1,
end_[j], castUp( pos ) ) );
5053 template<
typename Type >
5055 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last )
5063 end_[j] = castDown( std::move( last,
end_[j], castUp( first ) ) );
5093 template<
typename Type >
5094 template<
typename Pred >
5095 inline void CompressedMatrix<Type,true>::erase( Pred predicate )
5097 for(
size_t j=0UL; j<
n_; ++j ) {
5098 end_[j] = castDown( std::remove_if( castUp(
begin_[j] ), castUp(
end_[j] ),
5099 [predicate=predicate](
const ElementBase& element ) {
5100 return predicate( element.value() );
5133 template<
typename Type >
5134 template<
typename Pred >
5135 inline void CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last, Pred predicate )
5142 const auto pos = std::remove_if( castUp( first ), castUp( last ),
5143 [predicate=predicate](
const ElementBase& element ) {
5144 return predicate( element.value() );
5147 end_[j] = castDown( std::move( last,
end_[j], pos ) );
5176 template<
typename Type >
5178 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
5180 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( i, j ) );
5201 template<
typename Type >
5203 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
const 5206 if( pos !=
end_[j] && pos->index_ == i )
5208 else return end_[j];
5228 template<
typename Type >
5230 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
5232 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( i, j ) );
5252 template<
typename Type >
5254 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
const 5257 return std::lower_bound(
begin_[j],
end_[j], i,
5258 [](
const Element& element,
size_t index )
5260 return element.index() < index;
5281 template<
typename Type >
5283 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
5285 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( i, j ) );
5305 template<
typename Type >
5307 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
const 5310 return std::upper_bound(
begin_[j],
end_[j], i,
5311 [](
size_t index,
const Element& element )
5313 return index < element.index();
5334 template<
typename Type >
5335 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::transpose()
5337 CompressedMatrix tmp(
trans( *
this ) );
5351 template<
typename Type >
5352 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::ctranspose()
5354 CompressedMatrix tmp(
ctrans( *
this ) );
5380 template<
typename Type >
5381 template<
typename Other >
5382 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale(
const Other& scalar )
5384 for(
size_t j=0UL; j<
n_; ++j )
5385 for(
auto element=
begin_[j]; element!=
end_[j]; ++element )
5386 element->value_ *= scalar;
5413 template<
typename Type >
5414 template<
typename Other >
5415 inline bool CompressedMatrix<Type,true>::canAlias(
const Other* alias )
const noexcept
5417 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
5434 template<
typename Type >
5435 template<
typename Other >
5436 inline bool CompressedMatrix<Type,true>::isAliased(
const Other* alias )
const noexcept
5438 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
5455 template<
typename Type >
5456 inline bool CompressedMatrix<Type,true>::canSMPAssign() const noexcept
5476 template<
typename Type >
5477 template<
typename MT
5479 inline void CompressedMatrix<Type,true>::assign(
const DenseMatrix<MT,SO>& rhs )
5484 if(
m_ == 0UL ||
n_ == 0UL )
5487 size_t nonzeros( 0UL );
5489 for(
size_t j=1UL; j<=
n_; ++j )
5492 for(
size_t j=0UL; j<
n_; ++j )
5496 const size_t ibegin( ( IsLower_v<MT> )
5497 ?( IsStrictlyLower_v<MT> ? j+1UL : j )
5499 const size_t iend ( ( IsUpper_v<MT> )
5500 ?( IsStrictlyUpper_v<MT> ? j : j+1UL )
5503 for(
size_t i=ibegin; i<iend; ++i )
5506 reserveElements( extendCapacity() );
5507 for(
size_t k=j+1UL; k<=
n_; ++k )
5511 end_[j]->value_ = (~rhs)(i,j);
5513 if( !isDefault<strict>(
end_[j]->value_ ) ) {
5514 end_[j]->index_ = i;
5539 template<
typename Type >
5540 template<
typename MT >
5541 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,true>& rhs )
5548 if(
n_ == 0UL ||
begin_[0] ==
nullptr )
5551 for(
size_t j=0UL; j<
n_; ++j ) {
5552 end_[j] = castDown( std::copy( (~rhs).
begin(j), (~rhs).
end(j), castUp(
begin_[j] ) ) );
5572 template<
typename Type >
5573 template<
typename MT >
5574 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,false>& rhs )
5584 std::vector<size_t> columnLengths(
n_, 0UL );
5585 for(
size_t i=0UL; i<
m_; ++i ) {
5586 for(
auto element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5587 ++columnLengths[element->index()];
5591 for(
size_t j=0UL; j<
n_; ++j ) {
5596 for(
size_t i=0UL; i<
m_; ++i ) {
5597 for(
auto element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
5598 append( i, element->index(), element->value() );
5617 template<
typename Type >
5618 template<
typename MT
5620 inline void CompressedMatrix<Type,true>::addAssign(
const DenseMatrix<MT,SO>& rhs )
5625 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
5644 template<
typename Type >
5645 template<
typename MT
5647 inline void CompressedMatrix<Type,true>::addAssign(
const SparseMatrix<MT,SO>& rhs )
5652 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
5671 template<
typename Type >
5672 template<
typename MT
5674 inline void CompressedMatrix<Type,true>::subAssign(
const DenseMatrix<MT,SO>& rhs )
5679 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
5698 template<
typename Type >
5699 template<
typename MT
5701 inline void CompressedMatrix<Type,true>::subAssign(
const SparseMatrix<MT,SO>& rhs )
5706 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
5725 template<
typename Type >
5726 template<
typename MT
5728 inline void CompressedMatrix<Type,true>::schurAssign(
const DenseMatrix<MT,SO>& rhs )
5735 for(
size_t j=0UL; j<
n_; ++j ) {
5737 for(
auto element=
begin(j); element!=last; ++element )
5738 element->value_ *= (~rhs)(element->index_,j);
5760 template<
typename Type,
bool SO >
5761 void reset( CompressedMatrix<Type,SO>& m );
5763 template<
typename Type,
bool SO >
5764 void reset( CompressedMatrix<Type,SO>& m,
size_t i );
5766 template<
typename Type,
bool SO >
5767 void clear( CompressedMatrix<Type,SO>& m );
5769 template<
bool RF,
typename Type,
bool SO >
5770 bool isDefault(
const CompressedMatrix<Type,SO>& m );
5772 template<
typename Type,
bool SO >
5773 bool isIntact(
const CompressedMatrix<Type,SO>& m );
5775 template<
typename Type,
bool SO >
5776 void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) noexcept;
5788 template<
typename Type
5790 inline void reset( CompressedMatrix<Type,SO>& m )
5810 template<
typename Type
5812 inline void reset( CompressedMatrix<Type,SO>& m,
size_t i )
5826 template<
typename Type
5828 inline void clear( CompressedMatrix<Type,SO>& m )
5865 return ( m.rows() == 0UL && m.columns() == 0UL );
5888 template<
typename Type
5890 inline bool isIntact(
const CompressedMatrix<Type,SO>& m )
5892 return ( m.nonZeros() <= m.capacity() );
5905 template<
typename Type
5907 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) noexcept
5924 template<
typename T,
bool SO >
5925 struct IsResizable< CompressedMatrix<T,SO> >
5942 template<
typename T,
bool SO >
5943 struct IsShrinkable< CompressedMatrix<T,SO> >
5960 template<
typename T1,
typename T2 >
5961 struct AddTraitEval2< T1, T2
5964 using ET1 = ElementType_t<T1>;
5965 using ET2 = ElementType_t<T2>;
5967 static constexpr
bool SO = ( StorageOrder_v<T1> && StorageOrder_v<T2> );
5969 using Type = CompressedMatrix< AddTrait_t<ET1,ET2>, SO >;
5985 template<
typename T1,
typename T2 >
5986 struct SubTraitEval2< 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< SubTrait_t<ET1,ET2>, SO >;
6010 template<
typename T1
6012 struct SchurTraitEval2< T1, T2
6015 ( IsSparseMatrix_v<T1> || IsSparseMatrix_v<T2> ) > >
6017 using ET1 = ElementType_t<T1>;
6018 using ET2 = ElementType_t<T2>;
6020 static constexpr
bool SO = ( IsSparseMatrix_v<T1> && IsSparseMatrix_v<T2>
6021 ? ( StorageOrder_v<T1> && StorageOrder_v<T2> )
6022 : ( IsSparseMatrix_v<T1>
6023 ? StorageOrder_v<T1>
6024 : StorageOrder_v<T2> ) );
6026 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, SO >;
6042 template<
typename T1,
typename T2 >
6043 struct MultTraitEval2< T1, T2
6046 using ET1 = ElementType_t<T1>;
6048 using Type = CompressedMatrix< MultTrait_t<ET1,T2>, StorageOrder_v<T1> >;
6051 template<
typename T1,
typename T2 >
6052 struct MultTraitEval2< T1, T2
6055 using ET2 = ElementType_t<T2>;
6057 using Type = CompressedMatrix< MultTrait_t<T1,ET2>, StorageOrder_v<T2> >;
6060 template<
typename T1,
typename T2 >
6061 struct MultTraitEval2< T1, T2
6064 IsColumnVector_v<T1> &&
6065 IsRowVector_v<T2> > >
6067 using ET1 = ElementType_t<T1>;
6068 using ET2 = ElementType_t<T2>;
6072 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, SO >;
6075 template<
typename T1,
typename T2 >
6076 struct MultTraitEval2< T1, T2
6078 IsSparseMatrix_v<T2> &&
6079 !( IsIdentity_v<T1> && IsIdentity_v<T2> ) > >
6081 using ET1 = ElementType_t<T1>;
6082 using ET2 = ElementType_t<T2>;
6084 using Type = CompressedMatrix< MultTrait_t<ET1,ET2>, StorageOrder_v<T1> >;
6100 template<
typename T1,
typename T2 >
6101 struct DivTraitEval2< T1, T2
6104 using ET1 = ElementType_t<T1>;
6106 using Type = CompressedMatrix< DivTrait_t<ET1,T2>, StorageOrder_v<T1> >;
6122 template<
typename T,
typename OP >
6123 struct UnaryMapTraitEval2< T, OP
6126 using ET = ElementType_t<T>;
6128 using Type = CompressedMatrix< MapTrait_t<ET,OP>, StorageOrder_v<T> >;
6144 template<
typename T
6146 struct ExpandTraitEval2< T, E
6151 using Type = CompressedMatrix< ElementType_t<T>, TF >;
6167 template<
typename T1,
bool SO,
typename T2 >
6168 struct HighType< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
6170 using Type = CompressedMatrix< typename HighType<T1,T2>::Type, SO >;
6186 template<
typename T1,
bool SO,
typename T2 >
6187 struct LowType< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
6189 using Type = CompressedMatrix< typename LowType<T1,T2>::Type, SO >;
6205 template<
typename MT,
size_t I,
size_t J,
size_t M,
size_t N >
6206 struct SubmatrixTraitEval2< MT, I, J, M, N
6209 using Type = CompressedMatrix< RemoveConst_t< ElementType_t<MT> >, StorageOrder_v<MT> >;
6225 template<
typename MT,
size_t M >
6226 struct RowsTraitEval2< MT, M
6229 using Type = CompressedMatrix< RemoveConst_t< ElementType_t<MT> >,
false >;
6245 template<
typename MT,
size_t N >
6246 struct ColumnsTraitEval2< MT, N
6249 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, a compilation error is created.
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:1899
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:532
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:2948
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
constexpr bool IsSparseMatrix_v
Auxiliary variable template for the IsSparseMatrix type trait.The IsSparseMatrix_v variable template ...
Definition: IsSparseMatrix.h:139
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: CompressedMatrix.h:1839
Header file for the subtraction trait.
bool canSMPAssign() const noexcept
Returns whether the matrix can be used in SMP assignments.
Definition: CompressedMatrix.h:2684
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 bool IsMatrix_v
Auxiliary variable template for the IsMatrix type trait.The IsMatrix_v variable template provides a c...
Definition: IsMatrix.h:139
bool isAliased(const Other *alias) const noexcept
Returns whether the matrix is aliased with the given address alias.
Definition: CompressedMatrix.h:2665
CompressedMatrix & ctranspose()
In-place conjugate transpose of the matrix.
Definition: CompressedMatrix.h:2584
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:576
Header file for the serial shim.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:224
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:352
Iterator end(size_t i) noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:1025
Reference operator()(size_t i, size_t j) noexcept
2D-access to the compressed matrix elements.
Definition: CompressedMatrix.h:851
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
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3075
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
size_t m_
The current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:3289
void clear()
Clearing the compressed matrix.
Definition: CompressedMatrix.h:1576
Header file for the IsRowVector type trait.
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:5828
Header file for the IsIdentity type trait.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3084
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
~CompressedMatrix()
The destructor for CompressedMatrix.
Definition: CompressedMatrix.h:817
void reset(CompressedMatrix< Type, SO > &m)
Resetting the given compressed matrix.
Definition: CompressedMatrix.h:5790
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:1447
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3085
Header file for memory allocation and deallocation functionality.
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:1003
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:534
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
Resize mechanism to obtain a CompressedMatrix with different fixed dimensions.
Definition: CompressedMatrix.h:3103
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:80
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:137
void swap(CompressedMatrix &sm) noexcept
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:1856
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:3291
Header file for the IsMatrix type trait.
Header file for the SparseMatrix base class.
ElementBase * IteratorBase
Iterator over non-constant base elements.
Definition: CompressedMatrix.h:230
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:530
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:1700
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1538
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.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:3083
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:1364
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5907
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:1986
bool isIntact(const CompressedMatrix< Type, SO > &m)
Returns whether the invariants of the given compressed matrix are intact.
Definition: CompressedMatrix.h:5890
Header file for the MatrixAccessProxy class.
Header file for all forward declarations of the math module.
#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.
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
Header file for the expand trait.
void erase(size_t i, size_t j)
Erasing an element from the compressed matrix.
Definition: CompressedMatrix.h:2230
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:3293
size_t rows() const noexcept
Returns the current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:1433
#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
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3086
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:1461
ConstIterator cend(size_t i) const noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:1069
Constraint on the data type.
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:314
Header file for the IsLower type trait.
constexpr bool IsSparseVector_v
Auxiliary variable template for the IsSparseVector type trait.The IsSparseVector_v variable template ...
Definition: IsSparseVector.h:139
Header file for the default storage order for all vectors of the Blaze library.
IteratorBase castUp(Iterator it) const noexcept
Performs an up-cast of the given iterator.
Definition: CompressedMatrix.h:1956
Iterator insert(size_t i, size_t j, const Type &value)
Inserting an element into the compressed matrix.
Definition: CompressedMatrix.h:2018
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:320
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:1179
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:2896
size_t nonZeros() const
Returns the number of non-zero elements in the compressed matrix.
Definition: CompressedMatrix.h:1498
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
CompressedMatrix & operator=(initializer_list< initializer_list< Type > > list)
List assignment to all matrix elements.
Definition: CompressedMatrix.h:1109
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the compressed matrix.
Definition: CompressedMatrix.h:1603
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, a compilation error is created.
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:2645
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:342
CompressedMatrix & transpose()
In-place transpose of the matrix.
Definition: CompressedMatrix.h:2568
Header file for the division trait.
void trim()
Removing all excessive capacity from all rows/columns.
Definition: CompressedMatrix.h:1796
Header file for the submatrix trait.
Constraint on the data type.
Header file for the columns trait.
Headerfile for the generic transfer algorithm.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
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:281
const Type & ConstReference
Reference to a constant compressed matrix value.
Definition: CompressedMatrix.h:323
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:109
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:325
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:3292
#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:2706
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:2168
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2200
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:2408
Header file for the rows trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:531
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
decltype(auto) trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:765
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:3290
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.
Iterator castDown(IteratorBase it) const noexcept
Performs a down-cast of the given iterator.
Definition: CompressedMatrix.h:1938
void addAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the addition assignment of a dense matrix.
Definition: CompressedMatrix.h:2844
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:2461
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:3295
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater than the given index.
Definition: CompressedMatrix.h:2516
Header file for the StorageOrder type trait.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:324
Header file for the map trait.
size_t extendCapacity() const noexcept
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1879
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:332
bool isDefault(const CompressedMatrix< Type, SO > &m)
Returns whether the given compressed matrix is in default state.
Definition: CompressedMatrix.h:5863
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:3093
Header file for the IsUpper type trait.
size_t n_
The current number of columns of the compressed matrix.
Definition: CompressedMatrix.h:529
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:229
Reference at(size_t i, size_t j)
Checked access to the matrix elements.
Definition: CompressedMatrix.h:905
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the compressed matrix.
Definition: CompressedMatrix.h:528
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, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:319
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
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:959