35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
197 template<
typename Type
214 template<
typename Other >
215 inline Element&
operator=(
const Other& rhs )
217 ElementBase::operator=( rhs );
230 struct FindIndex :
public std::binary_function<Element,size_t,bool>
232 inline bool operator()(
const Element& element,
size_t index )
const {
233 return element.index() < index;
235 inline bool operator()(
size_t index,
const Element& element )
const {
236 return index < element.index();
238 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
239 return element1.index() < element2.index();
274 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
312 template<
typename Other >
314 operator*=( Other rhs );
316 template<
typename Other >
318 operator/=( Other rhs );
325 inline size_t rows()
const;
328 inline size_t capacity(
size_t i )
const;
330 inline size_t nonZeros(
size_t i )
const;
332 inline void reset(
size_t i );
335 inline void erase (
size_t i,
size_t j );
338 void resize (
size_t m,
size_t n,
bool preserve=
true );
339 inline void reserve(
size_t nonzeros );
340 void reserve(
size_t i,
size_t nonzeros );
342 inline void trim (
size_t i );
345 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
365 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
373 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
374 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
431 template<
typename Type,
bool SO >
446 template<
typename Type
468 template<
typename Type
477 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
492 template<
typename Type
501 begin_[0UL] = allocate<Element>( nonzeros );
502 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
518 template<
typename Type
527 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
529 size_t newCapacity( 0UL );
530 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
533 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
534 for(
size_t i=0UL; i<
m_; ++i ) {
546 template<
typename Type
555 const size_t nonzeros( sm.
nonZeros() );
557 begin_[0UL] = allocate<Element>( nonzeros );
558 for(
size_t i=0UL; i<
m_; ++i )
559 begin_[i+1UL] =
end_[i] = std::copy( sm.
begin(i), sm.
end(i), begin_[i] );
560 end_[
m_] = begin_[0UL]+nonzeros;
570 template<
typename Type
572 template<
typename MT
583 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
596 template<
typename Type
598 template<
typename MT
609 const size_t nonzeros( (~sm).
nonZeros() );
611 begin_[0UL] = allocate<Element>( nonzeros );
612 for(
size_t i=0UL; i<
m_; ++i )
632 template<
typename Type
657 template<
typename Type
677 template<
typename Type
687 if( pos ==
end_[i] || pos->index_ != j )
706 template<
typename Type
728 template<
typename Type
750 template<
typename Type
772 template<
typename Type
794 template<
typename Type
816 template<
typename Type
844 template<
typename Type
849 if( &rhs ==
this )
return *
this;
851 const size_t nonzeros( rhs.
nonZeros() );
858 newBegin[0UL] = allocate<Element>( nonzeros );
859 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
860 newBegin[i+1UL] = newEnd[i] = std::copy( rhs.
begin_[i], rhs.
end_[i], newBegin[i] );
862 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
871 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
893 template<
typename Type
895 template<
typename MT
902 if( (~rhs).canAlias(
this ) ) {
925 template<
typename Type
927 template<
typename MT
934 if( (~rhs).canAlias(
this ) ||
961 template<
typename Type
963 template<
typename MT
971 throw std::invalid_argument(
"Matrix sizes do not match" );
989 template<
typename Type
991 template<
typename MT
998 throw std::invalid_argument(
"Matrix sizes do not match" );
1016 template<
typename Type
1018 template<
typename MT
1023 if( (~rhs).
rows() !=
n_ )
1024 throw std::invalid_argument(
"Matrix sizes do not match" );
1041 template<
typename Type
1043 template<
typename Other >
1047 for(
size_t i=0UL; i<
m_; ++i ) {
1049 for(
Iterator element=begin(i); element!=last; ++element )
1050 element->value_ *= rhs;
1064 template<
typename Type
1066 template<
typename Other >
1078 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1079 for(
size_t i=0UL; i<
m_; ++i ) {
1081 for(
Iterator element=begin(i); element!=last; ++element )
1082 element->value_ *= tmp;
1086 for(
size_t i=0UL; i<
m_; ++i ) {
1088 for(
Iterator element=begin(i); element!=last; ++element )
1089 element->value_ /= rhs;
1111 template<
typename Type
1125 template<
typename Type
1139 template<
typename Type
1159 template<
typename Type
1174 template<
typename Type
1178 size_t nonzeros( 0UL );
1180 for(
size_t i=0UL; i<
m_; ++i )
1199 template<
typename Type
1214 template<
typename Type
1218 for(
size_t i=0UL; i<
m_; ++i )
1235 template<
typename Type
1252 template<
typename Type
1276 template<
typename Type
1284 const Iterator pos( lowerBound( i, j ) );
1286 if( pos !=
end_[i] && pos->index_ == j )
1287 throw std::invalid_argument(
"Bad access index" );
1290 std::copy_backward( pos,
end_[i],
end_[i]+1 );
1291 pos->value_ = value;
1298 std::copy_backward( pos,
end_[
m_-1UL],
end_[
m_-1UL]+1 );
1300 pos->value_ = value;
1303 for(
size_t k=i+1UL; k<
m_+1UL; ++k ) {
1311 size_t newCapacity( extendCapacity() );
1316 newBegin[0UL] = allocate<Element>( newCapacity );
1318 for(
size_t k=0UL; k<i; ++k ) {
1319 const size_t nonzeros(
end_[k] -
begin_[k] );
1321 newEnd [k] = newBegin[k] + nonzeros;
1322 newBegin[k+1UL] = newBegin[k] + total;
1324 newEnd [i] = newBegin[i] + (
end_[i] -
begin_[i] ) + 1;
1325 newBegin[i+1UL] = newBegin[i] + (
begin_[i+1] -
begin_[i] ) + 1;
1326 for(
size_t k=i+1UL; k<
m_; ++k ) {
1327 const size_t nonzeros(
end_[k] -
begin_[k] );
1329 newEnd [k] = newBegin[k] + nonzeros;
1330 newBegin[k+1UL] = newBegin[k] + total;
1333 newEnd[
m_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
1336 tmp->value_ = value;
1338 std::copy( pos,
end_[m_-1UL], tmp+1UL );
1360 template<
typename Type
1367 const Iterator pos( find( i, j ) );
1368 if( pos !=
end_[i] )
1369 end_[i] = std::copy( pos+1,
end_[i], pos );
1385 template<
typename Type
1393 if( pos !=
end_[i] )
1394 end_[i] = std::copy( pos+1,
end_[i], pos );
1413 template<
typename Type
1424 end_[i] = std::copy( last,
end_[i], first );
1446 template<
typename Type
1453 if( m ==
m_ && n ==
n_ )
return;
1458 Iterator* newEnd ( newBegin+m+1UL );
1460 newBegin[0UL] =
begin_[0UL];
1463 for(
size_t i=0UL; i<
m_; ++i ) {
1464 newEnd [i] =
end_ [i];
1465 newBegin[i+1UL] =
begin_[i+1UL];
1467 for(
size_t i=m_; i<m; ++i ) {
1468 newBegin[i+1UL] = newEnd[i] =
begin_[
m_];
1472 for(
size_t i=0UL; i<m; ++i ) {
1473 newBegin[i+1UL] = newEnd[i] =
begin_[0UL];
1490 for(
size_t i=0UL; i<
m_; ++i )
1494 for(
size_t i=
m_; i<m; ++i )
1500 for(
size_t i=0UL; i<m; ++i )
1501 end_[i] = lowerBound( i, n );
1504 for(
size_t i=0UL; i<m; ++i )
1527 template<
typename Type
1532 reserveElements( nonzeros );
1551 template<
typename Type
1557 const size_t current(
capacity(i) );
1559 if( current >= nonzeros )
return;
1561 const ptrdiff_t additional( nonzeros - current );
1565 const size_t newCapacity(
begin_[
m_] -
begin_[0UL] + additional );
1571 newBegin[0UL] = allocate<Element>( newCapacity );
1572 newEnd [
m_ ] = newBegin[0UL]+newCapacity;
1574 for(
size_t k=0UL; k<i; ++k ) {
1575 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1576 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1578 newEnd [i ] = std::copy(
begin_[i],
end_[i], newBegin[i] );
1579 newBegin[i+1UL] = newBegin[i] + nonzeros;
1580 for(
size_t k=i+1UL; k<
m_; ++k ) {
1581 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1582 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1595 for(
size_t j=
m_-1UL; j>i; --j ) {
1597 end_ [j] += additional;
1614 template<
typename Type
1618 for(
size_t i=0UL; i<
m_; ++i )
1635 template<
typename Type
1641 if( i < (
m_ - 1UL ) )
1653 template<
typename Type
1670 template<
typename Type
1672 template<
typename Other >
1675 for(
size_t i=0UL; i<
m_; ++i )
1677 element->value_ *= scalar;
1690 template<
typename Type
1692 template<
typename Other >
1697 for(
size_t i=0UL; i<size; ++i ) {
1699 if( pos !=
end_[i] && pos->index_ == i )
1700 pos->value_ *= scalar;
1715 template<
typename Type
1736 template<
typename Type
1740 size_t nonzeros( 2UL*
capacity()+1UL );
1756 template<
typename Type
1763 newBegin[0UL] = allocate<Element>( nonzeros );
1765 for(
size_t k=0UL; k<
m_; ++k ) {
1767 newEnd [k] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1768 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
1771 newEnd[
m_] = newBegin[0UL]+nonzeros;
1804 template<
typename Type
1809 return const_cast<Iterator>(
const_cast<const This&
>( *this ).
find( i, j ) );
1829 template<
typename Type
1835 if( pos !=
end_[i] && pos->index_ == j )
1837 else return end_[i];
1857 template<
typename Type
1882 template<
typename Type
1888 return std::lower_bound(
begin_[i],
end_[i], j, FindIndex() );
1908 template<
typename Type
1933 template<
typename Type
1939 return std::upper_bound(
begin_[i],
end_[i], j, FindIndex() );
1995 template<
typename Type
2004 end_[i]->value_ = value;
2007 end_[i]->index_ = j;
2027 template<
typename Type
2058 template<
typename Type
2060 template<
typename Other >
2063 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2078 template<
typename Type
2080 template<
typename Other >
2083 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2098 template<
typename Type
2118 template<
typename Type
2120 template<
typename MT
2127 size_t nonzeros( 0UL );
2129 for(
size_t i=1UL; i<=
m_; ++i )
2132 for(
size_t i=0UL; i<
m_; ++i )
2136 for(
size_t j=0UL; j<
n_; ++j )
2139 reserveElements( extendCapacity() );
2140 for(
size_t k=i+1UL; k<=
m_; ++k )
2144 end_[i]->value_ = (~rhs)(i,j);
2147 end_[i]->index_ = j;
2170 template<
typename Type
2172 template<
typename MT >
2179 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2180 begin_[i+1UL] =
end_[i] = std::copy( (~rhs).begin(i), (~rhs).end(i),
begin_[i] );
2197 template<
typename Type
2199 template<
typename MT >
2209 std::vector<size_t> rowLengths(
m_, 0UL );
2210 for(
size_t j=0UL; j<
n_; ++j ) {
2211 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2212 ++rowLengths[element->index()];
2216 for(
size_t i=0UL; i<
m_; ++i ) {
2221 for(
size_t j=0UL; j<
n_; ++j ) {
2222 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2223 append( element->index(), j, element->value() );
2240 template<
typename Type
2242 template<
typename MT
2266 template<
typename Type
2268 template<
typename MT
2292 template<
typename Type
2294 template<
typename MT
2318 template<
typename Type
2320 template<
typename MT
2353 template<
typename Type >
2369 template<
typename Other >
2370 inline Element&
operator=(
const Other& rhs )
2372 ElementBase::operator=( rhs );
2385 struct FindIndex :
public std::binary_function<Element,size_t,bool>
2387 inline bool operator()(
const Element& element,
size_t index )
const {
2388 return element.index() < index;
2390 inline bool operator()(
size_t index,
const Element& element )
const {
2391 return index < element.index();
2393 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
2394 return element1.index() < element2.index();
2429 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
2431 template<
typename MT,
bool SO >
inline CompressedMatrix(
const DenseMatrix<MT,SO>& dm );
2432 template<
typename MT,
bool SO >
inline CompressedMatrix(
const SparseMatrix<MT,SO>& sm );
2463 template<
typename MT,
bool SO >
inline CompressedMatrix& operator+=(
const Matrix<MT,SO>& rhs );
2464 template<
typename MT,
bool SO >
inline CompressedMatrix& operator-=(
const Matrix<MT,SO>& rhs );
2465 template<
typename MT,
bool SO >
inline CompressedMatrix& operator*=(
const Matrix<MT,SO>& rhs );
2467 template<
typename Other >
2469 operator*=( Other rhs );
2471 template<
typename Other >
2473 operator/=( Other rhs );
2480 inline size_t rows()
const;
2481 inline size_t columns()
const;
2483 inline size_t capacity(
size_t j )
const;
2485 inline size_t nonZeros(
size_t j )
const;
2486 inline void reset();
2487 inline void reset(
size_t j );
2488 inline void clear();
2490 inline void erase (
size_t i,
size_t j );
2493 void resize (
size_t m,
size_t n,
bool preserve=
true );
2494 inline void reserve(
size_t nonzeros );
2495 void reserve(
size_t j,
size_t nonzeros );
2496 inline void trim ();
2497 inline void trim (
size_t j );
2500 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
2520 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
2528 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2529 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2533 template<
typename MT,
bool SO >
inline void assign (
const DenseMatrix<MT,SO>& rhs );
2534 template<
typename MT >
inline void assign (
const SparseMatrix<MT,true>& rhs );
2535 template<
typename MT >
inline void assign (
const SparseMatrix<MT,false>& rhs );
2536 template<
typename MT,
bool SO >
inline void addAssign(
const DenseMatrix<MT,SO>& rhs );
2537 template<
typename MT,
bool SO >
inline void addAssign(
const SparseMatrix<MT,SO>& rhs );
2538 template<
typename MT,
bool SO >
inline void subAssign(
const DenseMatrix<MT,SO>& rhs );
2539 template<
typename MT,
bool SO >
inline void subAssign(
const SparseMatrix<MT,SO>& rhs );
2587 template<
typename Type >
2603 template<
typename Type >
2626 template<
typename Type >
2627 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n )
2634 for(
size_t j=0UL; j<2UL*
n_+2UL; ++j )
2651 template<
typename Type >
2652 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
size_t nonzeros )
2659 begin_[0UL] = allocate<Element>( nonzeros );
2660 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
2678 template<
typename Type >
2679 CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros )
2686 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
2688 size_t newCapacity( 0UL );
2689 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
2692 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
2693 for(
size_t j=0UL; j<
n_; ++j ) {
2707 template<
typename Type >
2708 inline CompressedMatrix<Type,true>::CompressedMatrix(
const CompressedMatrix& sm )
2715 const size_t nonzeros( sm.nonZeros() );
2717 begin_[0UL] = allocate<Element>( nonzeros );
2718 for(
size_t j=0UL; j<
n_; ++j )
2719 begin_[j+1UL] =
end_[j] = std::copy( sm.begin(j), sm.end(j), begin_[j] );
2720 end_[
n_] = begin_[0UL]+nonzeros;
2732 template<
typename Type >
2733 template<
typename MT
2735 inline CompressedMatrix<Type,true>::CompressedMatrix(
const DenseMatrix<MT,SO>& dm )
2739 , begin_ ( new
Iterator[2UL*n_+2UL] )
2740 ,
end_ ( begin_+(n_+1UL) )
2744 for(
size_t j=0UL; j<2UL*n_+2UL; ++j )
2759 template<
typename Type >
2760 template<
typename MT
2762 inline CompressedMatrix<Type,true>::CompressedMatrix(
const SparseMatrix<MT,SO>& sm )
2766 , begin_ ( new
Iterator[2UL*n_+2UL] )
2767 ,
end_ ( begin_+(n_+1UL) )
2771 const size_t nonzeros( (~sm).
nonZeros() );
2773 begin_[0UL] = allocate<Element>( nonzeros );
2774 for(
size_t j=0UL; j<
n_; ++j )
2775 begin_[j+1UL] =
end_[j] = begin_[0UL];
2776 end_[
n_] = begin_[0UL]+nonzeros;
2796 template<
typename Type >
2797 inline CompressedMatrix<Type,true>::~CompressedMatrix()
2822 template<
typename Type >
2824 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
2843 template<
typename Type >
2845 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
const
2852 if( pos ==
end_[j] || pos->index_ != i )
2868 template<
typename Type >
2870 CompressedMatrix<Type,true>::begin(
size_t j )
2886 template<
typename Type >
2888 CompressedMatrix<Type,true>::begin(
size_t j )
const
2904 template<
typename Type >
2906 CompressedMatrix<Type,true>::cbegin(
size_t j )
const
2922 template<
typename Type >
2924 CompressedMatrix<Type,true>::end(
size_t j )
2940 template<
typename Type >
2942 CompressedMatrix<Type,true>::end(
size_t j )
const
2958 template<
typename Type >
2960 CompressedMatrix<Type,true>::cend(
size_t j )
const
2987 template<
typename Type >
2988 inline CompressedMatrix<Type,true>&
2989 CompressedMatrix<Type,true>::operator=(
const CompressedMatrix& rhs )
2991 if( &rhs ==
this )
return *
this;
2993 const size_t nonzeros( rhs.nonZeros() );
2998 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
3000 newBegin[0UL] = allocate<Element>( nonzeros );
3001 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3002 newBegin[j+1UL] = newEnd[j] = std::copy( rhs.begin_[j], rhs.end_[j], newBegin[j] );
3004 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
3013 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3014 begin_[j+1UL] =
end_[j] = std::copy( rhs.begin_[j], rhs.end_[j], begin_[j] );
3037 template<
typename Type >
3038 template<
typename MT
3040 inline CompressedMatrix<Type,true>&
3041 CompressedMatrix<Type,true>::operator=(
const DenseMatrix<MT,SO>& rhs )
3045 if( (~rhs).canAlias(
this ) ) {
3046 CompressedMatrix tmp( rhs );
3070 template<
typename Type >
3071 template<
typename MT
3073 inline CompressedMatrix<Type,true>&
3074 CompressedMatrix<Type,true>::operator=(
const SparseMatrix<MT,SO>& rhs )
3078 if( (~rhs).canAlias(
this ) ||
3081 CompressedMatrix tmp( rhs );
3107 template<
typename Type >
3108 template<
typename MT
3110 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
3115 throw std::invalid_argument(
"Matrix sizes do not match" );
3135 template<
typename Type >
3136 template<
typename MT
3138 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
3143 throw std::invalid_argument(
"Matrix sizes do not match" );
3163 template<
typename Type >
3164 template<
typename MT
3166 inline CompressedMatrix<Type,true>&
3167 CompressedMatrix<Type,true>::operator*=(
const Matrix<MT,SO>& rhs )
3169 if( (~rhs).
rows() != n_ )
3170 throw std::invalid_argument(
"Matrix sizes do not match" );
3172 CompressedMatrix tmp( *
this * (~rhs) );
3189 template<
typename Type >
3190 template<
typename Other >
3191 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3192 CompressedMatrix<Type,true>::operator*=( Other rhs )
3194 for(
size_t j=0UL; j<
n_; ++j ) {
3196 for(
Iterator element=begin(j); element!=last; ++element )
3197 element->value_ *= rhs;
3213 template<
typename Type >
3214 template<
typename Other >
3215 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3216 CompressedMatrix<Type,true>::operator/=( Other rhs )
3220 typedef typename DivTrait<Type,Other>::Type DT;
3221 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3225 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3226 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3227 for(
size_t j=0UL; j<
n_; ++j ) {
3229 for(
Iterator element=begin(j); element!=last; ++element )
3230 element->value_ *= tmp;
3234 for(
size_t j=0UL; j<
n_; ++j ) {
3236 for(
Iterator element=begin(j); element!=last; ++element )
3237 element->value_ /= rhs;
3261 template<
typename Type >
3262 inline size_t CompressedMatrix<Type,true>::rows()
const
3276 template<
typename Type >
3277 inline size_t CompressedMatrix<Type,true>::columns()
const
3291 template<
typename Type >
3292 inline size_t CompressedMatrix<Type,true>::capacity()
const
3294 return end_[
n_] - begin_[0UL];
3307 template<
typename Type >
3308 inline size_t CompressedMatrix<Type,true>::capacity(
size_t j )
const
3311 return begin_[j+1UL] - begin_[j];
3323 template<
typename Type >
3324 inline size_t CompressedMatrix<Type,true>::nonZeros()
const
3326 size_t nonzeros( 0UL );
3328 for(
size_t j=0UL; j<
n_; ++j )
3344 template<
typename Type >
3345 inline size_t CompressedMatrix<Type,true>::nonZeros(
size_t j )
const
3348 return end_[j] - begin_[j];
3360 template<
typename Type >
3363 for(
size_t j=0UL; j<
n_; ++j )
3364 end_[j] = begin_[j];
3380 template<
typename Type >
3384 end_[j] = begin_[j];
3398 template<
typename Type >
3423 template<
typename Type >
3425 CompressedMatrix<Type,true>::insert(
size_t i,
size_t j,
const Type& value )
3430 const Iterator pos( lowerBound( i, j ) );
3432 if( pos !=
end_[j] && pos->index_ == i )
3433 throw std::invalid_argument(
"Bad access index" );
3435 if( begin_[j+1UL] -
end_[j] != 0 ) {
3436 std::copy_backward( pos,
end_[j],
end_[j]+1 );
3437 pos->value_ = value;
3443 else if(
end_[n_] - begin_[n_] != 0 ) {
3444 std::copy_backward( pos,
end_[n_-1UL],
end_[n_-1]+1 );
3446 pos->value_ = value;
3449 for(
size_t k=j+1UL; k<n_+1UL; ++k ) {
3457 size_t newCapacity( extendCapacity() );
3462 newBegin[0UL] = allocate<Element>( newCapacity );
3464 for(
size_t k=0UL; k<j; ++k ) {
3465 const size_t nonzeros(
end_[k] - begin_[k] );
3466 const size_t total( begin_[k+1UL] - begin_[k] );
3467 newEnd [k] = newBegin[k] + nonzeros;
3468 newBegin[k+1UL] = newBegin[k] + total;
3470 newEnd [j] = newBegin[j] + (
end_[j] - begin_[j] ) + 1;
3471 newBegin[j+1UL] = newBegin[j] + ( begin_[j+1UL] - begin_[j] ) + 1;
3472 for(
size_t k=j+1UL; k<
n_; ++k ) {
3473 const size_t nonzeros(
end_[k] - begin_[k] );
3474 const size_t total( begin_[k+1UL] - begin_[k] );
3475 newEnd [k] = newBegin[k] + nonzeros;
3476 newBegin[k+1UL] = newBegin[k] + total;
3479 newEnd[
n_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
3481 Iterator tmp = std::copy( begin_[0UL], pos, newBegin[0UL] );
3482 tmp->value_ = value;
3484 std::copy( pos,
end_[n_-1UL], tmp+1UL );
3508 template<
typename Type >
3509 inline void CompressedMatrix<Type,true>::erase(
size_t i,
size_t j )
3514 const Iterator pos( find( i, j ) );
3515 if( pos !=
end_[j] )
3516 end_[j] = std::copy( pos+1,
end_[j], pos );
3532 template<
typename Type >
3534 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator pos )
3539 if( pos !=
end_[j] )
3540 end_[j] = std::copy( pos+1,
end_[j], pos );
3559 template<
typename Type >
3561 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last )
3569 end_[j] = std::copy( last,
end_[j], first );
3593 template<
typename Type >
3594 void CompressedMatrix<Type,true>::resize(
size_t m,
size_t n,
bool preserve )
3599 if( m ==
m_ && n == n_ )
return;
3604 Iterator* newEnd ( newBegin+n+1UL );
3606 newBegin[0UL] = begin_[0UL];
3609 for(
size_t j=0UL; j<
n_; ++j ) {
3610 newEnd [j] =
end_ [j];
3611 newBegin[j+1UL] = begin_[j+1UL];
3613 for(
size_t j=n_; j<n; ++j ) {
3614 newBegin[j+1UL] = newEnd[j] = begin_[
n_];
3618 for(
size_t j=0UL; j<n; ++j ) {
3619 newBegin[j+1UL] = newEnd[j] = begin_[0UL];
3636 for(
size_t j=0UL; j<
n_; ++j )
3637 end_[j] = begin_[j];
3640 for(
size_t j=n_; j<n; ++j )
3641 begin_[j+1UL] =
end_[j] = begin_[n_];
3646 for(
size_t j=0UL; j<n; ++j )
3647 end_[j] = lowerBound( m, j );
3650 for(
size_t j=0UL; j<n; ++j )
3651 end_[j] = begin_[j];
3675 template<
typename Type >
3676 inline void CompressedMatrix<Type,true>::reserve(
size_t nonzeros )
3679 reserveElements( nonzeros );
3697 template<
typename Type >
3698 void CompressedMatrix<Type,true>::reserve(
size_t j,
size_t nonzeros )
3702 const size_t current(
capacity(j) );
3704 if( current >= nonzeros )
return;
3706 const ptrdiff_t additional( nonzeros - current );
3708 if(
end_[n_] - begin_[n_] < additional )
3710 const size_t newCapacity( begin_[n_] - begin_[0UL] + additional );
3714 Iterator* newEnd ( newBegin+n_+1UL );
3716 newBegin[0UL] = allocate<Element>( newCapacity );
3717 newEnd [
n_ ] = newBegin[0UL]+newCapacity;
3719 for(
size_t k=0UL; k<j; ++k ) {
3720 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3721 newBegin[k+1UL] = newBegin[k] +
capacity(k);
3723 newEnd [j ] = std::copy( begin_[j],
end_[j], newBegin[j] );
3724 newBegin[j+1UL] = newBegin[j] + nonzeros;
3725 for(
size_t k=j+1UL; k<
n_; ++k ) {
3726 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3727 newBegin[k+1UL] = newBegin[k] +
capacity(k);
3739 begin_[
n_] += additional;
3740 for(
size_t k=n_-1UL; k>j; --k ) {
3741 begin_[k] = std::copy_backward( begin_[k],
end_[k],
end_[k]+additional );
3742 end_ [k] += additional;
3760 template<
typename Type >
3761 void CompressedMatrix<Type,true>::trim()
3763 for(
size_t j=0UL; j<
n_; ++j )
3781 template<
typename Type >
3782 void CompressedMatrix<Type,true>::trim(
size_t j )
3786 if( j < ( n_ - 1UL ) )
3787 end_[j+1] = std::copy( begin_[j+1],
end_[j+1],
end_[j] );
3788 begin_[j+1] =
end_[j];
3800 template<
typename Type >
3801 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::transpose()
3803 CompressedMatrix tmp(
trans( *
this ) );
3818 template<
typename Type >
3819 template<
typename Other >
3820 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale( Other scalar )
3822 for(
size_t j=0UL; j<
n_; ++j )
3823 for(
Iterator element=begin_[j]; element!=
end_[j]; ++element )
3824 element->value_ *= scalar;
3839 template<
typename Type >
3840 template<
typename Other >
3841 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scaleDiagonal( Other scalar )
3843 const size_t size( blaze::min(
m_, n_ ) );
3845 for(
size_t j=0UL; j<size; ++j ) {
3847 if( pos !=
end_[j] && pos->index_ == j )
3848 pos->value_ *= scalar;
3865 template<
typename Type >
3887 template<
typename Type >
3888 inline size_t CompressedMatrix<Type,true>::extendCapacity()
const
3890 size_t nonzeros( 2UL*
capacity()+1UL );
3908 template<
typename Type >
3909 void CompressedMatrix<Type,true>::reserveElements(
size_t nonzeros )
3914 newBegin[0UL] = allocate<Element>( nonzeros );
3916 for(
size_t k=0UL; k<
n_; ++k ) {
3918 newEnd [k] = std::copy( begin_[k],
end_[k], newBegin[k] );
3919 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
3922 newEnd[
n_] = newBegin[0UL]+nonzeros;
3956 template<
typename Type >
3958 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
3960 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( i, j ) );
3981 template<
typename Type >
3983 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
const
3986 if( pos !=
end_[j] && pos->index_ == i )
3988 else return end_[j];
4008 template<
typename Type >
4010 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
4012 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( i, j ) );
4032 template<
typename Type >
4034 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
const
4037 return std::lower_bound( begin_[j],
end_[j], i, FindIndex() );
4057 template<
typename Type >
4059 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
4061 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( i, j ) );
4081 template<
typename Type >
4083 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
const
4086 return std::upper_bound( begin_[j],
end_[j], i, FindIndex() );
4141 template<
typename Type >
4142 inline void CompressedMatrix<Type,true>::append(
size_t i,
size_t j,
const Type& value,
bool check )
4149 end_[j]->value_ = value;
4152 end_[j]->index_ = i;
4174 template<
typename Type >
4175 inline void CompressedMatrix<Type,true>::finalize(
size_t j )
4179 begin_[j+1UL] =
end_[j];
4206 template<
typename Type >
4207 template<
typename Other >
4208 inline bool CompressedMatrix<Type,true>::canAlias(
const Other* alias )
const
4210 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4227 template<
typename Type >
4228 template<
typename Other >
4229 inline bool CompressedMatrix<Type,true>::isAliased(
const Other* alias )
const
4231 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4248 template<
typename Type >
4249 inline bool CompressedMatrix<Type,true>::canSMPAssign()
const
4269 template<
typename Type >
4270 template<
typename MT
4272 inline void CompressedMatrix<Type,true>::assign(
const DenseMatrix<MT,SO>& rhs )
4277 size_t nonzeros( 0UL );
4279 for(
size_t j=1UL; j<=
n_; ++j )
4282 for(
size_t j=0UL; j<
n_; ++j )
4284 begin_[j] =
end_[j] = begin_[0UL]+nonzeros;
4286 for(
size_t i=0UL; i<
m_; ++i )
4289 reserveElements( extendCapacity() );
4290 for(
size_t k=j+1UL; k<=
n_; ++k )
4294 end_[j]->value_ = (~rhs)(i,j);
4297 end_[j]->index_ = i;
4304 begin_[
n_] = begin_[0UL]+nonzeros;
4322 template<
typename Type >
4323 template<
typename MT >
4324 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,true>& rhs )
4330 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4331 begin_[j+1UL] =
end_[j] = std::copy( (~rhs).begin(j), (~rhs).end(j), begin_[j] );
4350 template<
typename Type >
4351 template<
typename MT >
4352 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,false>& rhs )
4361 std::vector<size_t> columnLengths( n_, 0UL );
4362 for(
size_t i=0UL; i<
m_; ++i ) {
4363 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4364 ++columnLengths[element->index()];
4368 for(
size_t j=0UL; j<
n_; ++j ) {
4369 begin_[j+1UL] =
end_[j+1UL] = begin_[j] + columnLengths[j];
4373 for(
size_t i=0UL; i<
m_; ++i ) {
4374 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4375 append( i, element->index(), element->value() );
4394 template<
typename Type >
4395 template<
typename MT
4397 inline void CompressedMatrix<Type,true>::addAssign(
const DenseMatrix<MT,SO>& rhs )
4402 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
4421 template<
typename Type >
4422 template<
typename MT
4424 inline void CompressedMatrix<Type,true>::addAssign(
const SparseMatrix<MT,SO>& rhs )
4429 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
4448 template<
typename Type >
4449 template<
typename MT
4451 inline void CompressedMatrix<Type,true>::subAssign(
const DenseMatrix<MT,SO>& rhs )
4456 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
4475 template<
typename Type >
4476 template<
typename MT
4478 inline void CompressedMatrix<Type,true>::subAssign(
const SparseMatrix<MT,SO>& rhs )
4483 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
4505 template<
typename Type,
bool SO >
4506 inline void reset( CompressedMatrix<Type,SO>& m );
4508 template<
typename Type,
bool SO >
4509 inline void clear( CompressedMatrix<Type,SO>& m );
4511 template<
typename Type,
bool SO >
4512 inline bool isDefault(
const CompressedMatrix<Type,SO>& m );
4514 template<
typename Type,
bool SO >
4515 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) ;
4527 template<
typename Type
4529 inline void reset( CompressedMatrix<Type,SO>& m )
4543 template<
typename Type
4545 inline void clear( CompressedMatrix<Type,SO>& m )
4570 template<
typename Type
4577 for(
size_t i=0UL; i<m.rows(); ++i ) {
4578 for( ConstIterator element=m.begin(i); element!=m.end(i); ++element )
4579 if( !
isDefault( element->value() ) )
return false;
4583 for(
size_t j=0UL; j<m.columns(); ++j ) {
4584 for( ConstIterator element=m.begin(j); element!=m.end(j); ++element )
4585 if( !
isDefault( element->value() ) )
return false;
4603 template<
typename Type
4605 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b )
4622 template<
typename T,
bool SO >
4623 struct IsResizable< CompressedMatrix<T,SO> > :
public TrueType
4629 template<
typename T,
bool SO >
4630 struct IsResizable< const CompressedMatrix<T,SO> > :
public TrueType
4636 template<
typename T,
bool SO >
4637 struct IsResizable< volatile CompressedMatrix<T,SO> > :
public TrueType
4643 template<
typename T,
bool SO >
4644 struct IsResizable< const volatile CompressedMatrix<T,SO> > :
public TrueType
4663 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4664 struct AddTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4666 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4669 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4670 struct AddTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4672 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4675 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4676 struct AddTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4678 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4681 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4682 struct AddTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4684 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4687 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4688 struct AddTrait< CompressedMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4690 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4693 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4694 struct AddTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4696 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4699 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4700 struct AddTrait< HybridMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4702 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4705 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4706 struct AddTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4708 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4711 template<
typename T1,
bool SO,
typename T2 >
4712 struct AddTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4714 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4717 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4718 struct AddTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4720 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4723 template<
typename T1,
bool SO,
typename T2 >
4724 struct AddTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4726 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4729 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4730 struct AddTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4732 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4735 template<
typename T1,
bool SO,
typename T2 >
4736 struct AddTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4738 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4741 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4742 struct AddTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4744 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4760 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4761 struct SubTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4763 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4766 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4767 struct SubTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4769 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4772 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4773 struct SubTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4775 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4778 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4779 struct SubTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4781 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4784 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4785 struct SubTrait< CompressedMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4787 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4790 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4791 struct SubTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4793 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4796 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4797 struct SubTrait< HybridMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4799 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4802 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4803 struct SubTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4805 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4808 template<
typename T1,
bool SO,
typename T2 >
4809 struct SubTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4811 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4814 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4815 struct SubTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4817 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4820 template<
typename T1,
bool SO,
typename T2 >
4821 struct SubTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4823 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4826 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4827 struct SubTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4829 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4832 template<
typename T1,
bool SO,
typename T2 >
4833 struct SubTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4835 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4838 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4839 struct SubTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4841 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4857 template<
typename T1,
bool SO,
typename T2 >
4858 struct MultTrait< CompressedMatrix<T1,SO>, T2 >
4860 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4864 template<
typename T1,
typename T2,
bool SO >
4865 struct MultTrait< T1, CompressedMatrix<T2,SO> >
4867 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4871 template<
typename T1,
bool SO,
typename T2,
size_t N >
4872 struct MultTrait< CompressedMatrix<T1,SO>, StaticVector<T2,N,false> >
4874 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4877 template<
typename T1,
size_t N,
typename T2,
bool SO >
4878 struct MultTrait< StaticVector<T1,N,true>, CompressedMatrix<T2,SO> >
4880 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4883 template<
typename T1,
bool SO,
typename T2,
size_t N >
4884 struct MultTrait< CompressedMatrix<T1,SO>, HybridVector<T2,N,false> >
4886 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4889 template<
typename T1,
size_t N,
typename T2,
bool SO >
4890 struct MultTrait< HybridVector<T1,N,true>, CompressedMatrix<T2,SO> >
4892 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4895 template<
typename T1,
bool SO,
typename T2 >
4896 struct MultTrait< CompressedMatrix<T1,SO>, DynamicVector<T2,false> >
4898 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4901 template<
typename T1,
typename T2,
bool SO >
4902 struct MultTrait< DynamicVector<T1,true>, CompressedMatrix<T2,SO> >
4904 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4907 template<
typename T1,
bool SO,
typename T2 >
4908 struct MultTrait< CompressedMatrix<T1,SO>, CompressedVector<T2,false> >
4910 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
false > Type;
4913 template<
typename T1,
typename T2,
bool SO >
4914 struct MultTrait< CompressedVector<T1,true>, CompressedMatrix<T2,SO> >
4916 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
true > Type;
4919 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4920 struct MultTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4922 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4925 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4926 struct MultTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4928 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4931 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4932 struct MultTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4934 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4937 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4938 struct MultTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4940 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4943 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4944 struct MultTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4946 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4949 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4950 struct MultTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4952 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4955 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4956 struct MultTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4958 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4974 template<
typename T1,
bool SO,
typename T2 >
4975 struct DivTrait< CompressedMatrix<T1,SO>, T2 >
4977 typedef CompressedMatrix< typename DivTrait<T1,T2>::Type, SO > Type;
4994 template<
typename T1,
bool SO,
typename T2 >
4995 struct MathTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4997 typedef CompressedMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
4998 typedef CompressedMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
5014 template<
typename T1,
bool SO >
5015 struct SubmatrixTrait< CompressedMatrix<T1,SO> >
5017 typedef CompressedMatrix<T1,SO> Type;
5033 template<
typename T1,
bool SO >
5034 struct RowTrait< CompressedMatrix<T1,SO> >
5036 typedef CompressedVector<T1,true> Type;
5052 template<
typename T1,
bool SO >
5053 struct ColumnTrait< CompressedMatrix<T1,SO> >
5055 typedef CompressedVector<T1,false> Type;
#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:116
Pointer difference type of the Blaze library.
size_t rows() const
Returns the current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:1113
void reserveElements(size_t nonzeros)
Reserving the specified number of sparse matrix elements.
Definition: CompressedMatrix.h:1758
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Constraint on the data type.
Iterator * end_
Pointers one past the last non-zero element of each row.
Definition: CompressedMatrix.h:404
Header file for mathematical functions.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#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
MatrixAccessProxy< This > Reference
Reference to a sparse matrix value.
Definition: CompressedMatrix.h:254
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Header file for the subtraction trait.
const Type & ConstReference
Reference to a constant sparse matrix value.
Definition: CompressedMatrix.h:255
const bool defaultStorageOrder
The default storage order for all matrices of the Blaze library.This value specifies the default stor...
Definition: StorageOrder.h:56
Header file for the row trait.
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:448
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:199
size_t extendCapacity() const
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1738
const blaze::Null NULL
Global NULL pointer.This instance of the Null class replaces the NULL macro to ensure a type-safe NUL...
Definition: Null.h:300
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2555
void clear()
Clearing the sparse matrix.
Definition: CompressedMatrix.h:1254
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:251
Header file for a safe C++ NULL pointer implementation.
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given sparse matrix.
Definition: CompressedMatrix.h:4545
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2402
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:249
#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:116
~CompressedMatrix()
The destructor for CompressedMatrix.
Definition: CompressedMatrix.h:634
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
void reset(CompressedMatrix< Type, SO > &m)
Resetting the given sparse matrix.
Definition: CompressedMatrix.h:4529
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
Header file for memory allocation and deallocation functionality.
bool isAliased(const Other *alias) const
Returns whether the matrix is aliased with the given address alias.
Definition: CompressedMatrix.h:2081
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:406
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:252
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes...
Definition: DenseMatrix.h:70
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
Constraint on the data type.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: CompressedMatrix.h:1176
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2557
Header file for the SparseMatrix base class.
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:402
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1529
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1216
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:253
Header file for the ValueIndexPair class.
bool isDefault(const CompressedMatrix< Type, SO > &m)
Returns whether the given sparse matrix is in default state.
Definition: CompressedMatrix.h:4572
Header file for the multiplication trait.
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4605
Header file for the MatrixAccessProxy class.
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
#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:116
Header file for the IsSMPAssignable type trait.
void erase(size_t i, size_t j)
Erasing an element from the sparse matrix.
Definition: CompressedMatrix.h:1362
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2559
size_t nonZeros(const Matrix< MT, SO > &m)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:224
#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:78
ValueIndexPair< Type > ElementBase
Base class for the sparse matrix element.
Definition: CompressedMatrix.h:203
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:271
Constraint on the data type.
Header file for the default storage order for all vectors of the Blaze library.
Iterator insert(size_t i, size_t j, const Type &value)
Inserting an element into the sparse matrix.
Definition: CompressedMatrix.h:1279
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
void subAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: CompressedMatrix.h:2296
Header file for the EnableIf class template.
Header file for the serial shim.
void swap(CompressedMatrix &sm)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:1717
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:257
bool canSMPAssign() const
Returns whether the matrix can be used in SMP assignments.
Definition: CompressedMatrix.h:2100
Header file for the equal shim.
size_t capacity() const
Returns the maximum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1141
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the sparse matrix.
Definition: CompressedMatrix.h:1448
Header file for the IsNumeric type trait.
CompressedMatrix & operator=(const CompressedMatrix &rhs)
Copy assignment operator for CompressedMatrix.
Definition: CompressedMatrix.h:847
Reference operator()(size_t i, size_t j)
2D-access to the sparse matrix elements.
Definition: CompressedMatrix.h:660
Header file for run time assertion macros.
Header file for the addition trait.
Iterator end(size_t i)
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:775
CompressedMatrix & transpose()
Transposing the matrix.
Definition: CompressedMatrix.h:1655
Header file for the division trait.
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4671
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:301
void trim()
Removing all excessive capacity from all rows/columns.
Definition: CompressedMatrix.h:1616
Header file for the submatrix trait.
Constraint on the data type.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:331
const VT::ElementType max(const SparseVector< VT, TF > &sv)
Returns the largest element of the sparse vector.
Definition: SparseVector.h:408
#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:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2411
Header file for the column trait.
Header file for the isDefault shim.
Base class for matrices.The Matrix class is a base class for all dense and sparse matrix classes with...
Definition: Forward.h:87
size_t columns() const
Returns the current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:1127
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:248
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2558
void assign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the assignment of a row-major dense matrix.
Definition: CompressedMatrix.h:2122
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:256
void append(size_t i, size_t j, const Type &value, bool check=false)
Appending an element to the specified row/column of the sparse matrix.
Definition: CompressedMatrix.h:1997
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2029
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: CompressedMatrix.h:2061
Base template for the DivTrait class.
Definition: DivTrait.h:141
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:247
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:1807
Header file for the mathematical trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:403
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2556
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:69
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:2244
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:907
const bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:250
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less then the given index.
Definition: CompressedMatrix.h:1860
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2561
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: CompressedMatrix.h:1911
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:170
Header file for basic type definitions.
ConstIterator cbegin(size_t i) const
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:753
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2409
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:351
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:401
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:819
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:400
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:154
#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
size_t capacity(const Matrix< MT, SO > &m)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:186
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:709