35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
195 template<
typename Type
212 template<
typename Other >
213 inline Element&
operator=(
const Other& rhs )
215 ElementBase::operator=( rhs );
228 struct FindIndex :
public std::binary_function<Element,size_t,bool>
230 inline bool operator()(
const Element& element,
size_t index )
const {
231 return element.index() < index;
233 inline bool operator()(
size_t index,
const Element& element )
const {
234 return index < element.index();
236 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
237 return element1.index() < element2.index();
263 enum { smpAssignable = 0 };
272 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
310 template<
typename Other >
312 operator*=( Other rhs );
314 template<
typename Other >
316 operator/=( Other rhs );
323 inline size_t rows()
const;
326 inline size_t capacity(
size_t i )
const;
328 inline size_t nonZeros(
size_t i )
const;
330 inline void reset(
size_t i );
333 inline void erase (
size_t i,
size_t j );
336 void resize (
size_t m,
size_t n,
bool preserve=
true );
337 inline void reserve(
size_t nonzeros );
338 void reserve(
size_t i,
size_t nonzeros );
340 inline void trim (
size_t i );
343 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
363 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
371 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
372 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
426 template<
typename Type,
bool SO >
441 template<
typename Type
463 template<
typename Type
472 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
487 template<
typename Type
496 begin_[0UL] = allocate<Element>( nonzeros );
497 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
513 template<
typename Type
522 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
524 size_t newCapacity( 0UL );
525 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
528 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
529 for(
size_t i=0UL; i<
m_; ++i ) {
541 template<
typename Type
550 const size_t nonzeros( sm.
nonZeros() );
552 begin_[0UL] = allocate<Element>( nonzeros );
553 for(
size_t i=0UL; i<
m_; ++i )
554 begin_[i+1UL] =
end_[i] = std::copy( sm.
begin(i), sm.
end(i), begin_[i] );
555 end_[
m_] = begin_[0UL]+nonzeros;
565 template<
typename Type
567 template<
typename MT
578 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
591 template<
typename Type
593 template<
typename MT
604 const size_t nonzeros( (~sm).
nonZeros() );
606 begin_[0UL] = allocate<Element>( nonzeros );
607 for(
size_t i=0UL; i<
m_; ++i )
627 template<
typename Type
652 template<
typename Type
672 template<
typename Type
682 if( pos ==
end_[i] || pos->index_ != j )
701 template<
typename Type
723 template<
typename Type
745 template<
typename Type
767 template<
typename Type
789 template<
typename Type
811 template<
typename Type
839 template<
typename Type
844 if( &rhs ==
this )
return *
this;
846 const size_t nonzeros( rhs.
nonZeros() );
853 newBegin[0UL] = allocate<Element>( nonzeros );
854 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
855 newBegin[i+1UL] = newEnd[i] = std::copy( rhs.
begin_[i], rhs.
end_[i], newBegin[i] );
857 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
866 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
888 template<
typename Type
890 template<
typename MT
897 if( (~rhs).canAlias(
this ) ) {
920 template<
typename Type
922 template<
typename MT
929 if( (~rhs).canAlias(
this ) ||
931 (~rhs).nonZeros() > capacity() ) {
956 template<
typename Type
958 template<
typename MT
966 throw std::invalid_argument(
"Matrix sizes do not match" );
984 template<
typename Type
986 template<
typename MT
993 throw std::invalid_argument(
"Matrix sizes do not match" );
1011 template<
typename Type
1013 template<
typename MT
1018 if( (~rhs).
rows() !=
n_ )
1019 throw std::invalid_argument(
"Matrix sizes do not match" );
1036 template<
typename Type
1038 template<
typename Other >
1042 for(
size_t i=0UL; i<
m_; ++i ) {
1044 for(
Iterator element=begin(i); element!=last; ++element )
1045 element->value_ *= rhs;
1060 template<
typename Type
1062 template<
typename Other >
1074 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1075 for(
size_t i=0UL; i<
m_; ++i ) {
1077 for(
Iterator element=begin(i); element!=last; ++element )
1078 element->value_ *= tmp;
1082 for(
size_t i=0UL; i<
m_; ++i ) {
1084 for(
Iterator element=begin(i); element!=last; ++element )
1085 element->value_ /= rhs;
1107 template<
typename Type
1121 template<
typename Type
1135 template<
typename Type
1155 template<
typename Type
1170 template<
typename Type
1174 size_t nonzeros( 0UL );
1176 for(
size_t i=0UL; i<
m_; ++i )
1177 nonzeros += nonZeros( i );
1195 template<
typename Type
1210 template<
typename Type
1214 for(
size_t i=0UL; i<
m_; ++i )
1231 template<
typename Type
1248 template<
typename Type
1272 template<
typename Type
1280 const Iterator pos( lowerBound( i, j ) );
1282 if( pos !=
end_[i] && pos->index_ == j )
1283 throw std::invalid_argument(
"Bad access index" );
1286 std::copy_backward( pos,
end_[i],
end_[i]+1 );
1287 pos->value_ = value;
1294 std::copy_backward( pos,
end_[
m_-1UL],
end_[
m_-1UL]+1 );
1296 pos->value_ = value;
1299 for(
size_t k=i+1UL; k<
m_+1UL; ++k ) {
1307 size_t newCapacity( extendCapacity() );
1312 newBegin[0UL] = allocate<Element>( newCapacity );
1314 for(
size_t k=0UL; k<i; ++k ) {
1315 const size_t nonzeros(
end_[k] -
begin_[k] );
1317 newEnd [k] = newBegin[k] + nonzeros;
1318 newBegin[k+1UL] = newBegin[k] + total;
1320 newEnd [i] = newBegin[i] + (
end_[i] -
begin_[i] ) + 1;
1321 newBegin[i+1UL] = newBegin[i] + (
begin_[i+1] -
begin_[i] ) + 1;
1322 for(
size_t k=i+1UL; k<
m_; ++k ) {
1323 const size_t nonzeros(
end_[k] -
begin_[k] );
1325 newEnd [k] = newBegin[k] + nonzeros;
1326 newBegin[k+1UL] = newBegin[k] + total;
1329 newEnd[
m_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
1332 tmp->value_ = value;
1334 std::copy( pos,
end_[m_-1UL], tmp+1UL );
1356 template<
typename Type
1363 const Iterator pos( find( i, j ) );
1364 if( pos !=
end_[i] )
1365 end_[i] = std::copy( pos+1,
end_[i], pos );
1381 template<
typename Type
1389 if( pos !=
end_[i] )
1390 end_[i] = std::copy( pos+1,
end_[i], pos );
1409 template<
typename Type
1420 end_[i] = std::copy( last,
end_[i], first );
1441 template<
typename Type
1448 if( m ==
m_ && n ==
n_ )
return;
1453 Iterator* newEnd ( newBegin+m+1UL );
1455 newBegin[0UL] =
begin_[0UL];
1458 for(
size_t i=0UL; i<
m_; ++i ) {
1459 newEnd [i] =
end_ [i];
1460 newBegin[i+1UL] =
begin_[i+1UL];
1462 for(
size_t i=m_; i<m; ++i ) {
1463 newBegin[i+1UL] = newEnd[i] =
begin_[
m_];
1467 for(
size_t i=0UL; i<m; ++i ) {
1468 newBegin[i+1UL] = newEnd[i] =
begin_[0UL];
1485 for(
size_t i=0UL; i<
m_; ++i )
1489 for(
size_t i=
m_; i<m; ++i )
1495 for(
size_t i=0UL; i<m; ++i )
1496 end_[i] = lowerBound( i, n );
1499 for(
size_t i=0UL; i<m; ++i )
1522 template<
typename Type
1526 if( nonzeros > capacity() )
1527 reserveElements( nonzeros );
1546 template<
typename Type
1552 const size_t current( capacity(i) );
1554 if( current >= nonzeros )
return;
1556 const ptrdiff_t additional( nonzeros - current );
1560 const size_t newCapacity(
begin_[
m_] -
begin_[0UL] + additional );
1566 newBegin[0UL] = allocate<Element>( newCapacity );
1567 newEnd [
m_ ] = newBegin[0UL]+newCapacity;
1569 for(
size_t k=0UL; k<i; ++k ) {
1570 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1571 newBegin[k+1UL] = newBegin[k] + capacity(k);
1573 newEnd [i ] = std::copy(
begin_[i],
end_[i], newBegin[i] );
1574 newBegin[i+1UL] = newBegin[i] + nonzeros;
1575 for(
size_t k=i+1UL; k<
m_; ++k ) {
1576 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1577 newBegin[k+1UL] = newBegin[k] + capacity(k);
1590 for(
size_t j=
m_-1UL; j>i; --j ) {
1592 end_ [j] += additional;
1609 template<
typename Type
1613 for(
size_t i=0UL; i<
m_; ++i )
1630 template<
typename Type
1636 if( i < (
m_ - 1UL ) )
1648 template<
typename Type
1665 template<
typename Type
1667 template<
typename Other >
1670 for(
size_t i=0UL; i<
m_; ++i )
1672 element->value_ *= scalar;
1685 template<
typename Type
1687 template<
typename Other >
1692 for(
size_t i=0UL; i<size; ++i ) {
1694 if( pos !=
end_[i] && pos->index_ == i )
1695 pos->value_ *= scalar;
1710 template<
typename Type
1731 template<
typename Type
1735 size_t nonzeros( 2UL*capacity()+1UL );
1751 template<
typename Type
1758 newBegin[0UL] = allocate<Element>( nonzeros );
1760 for(
size_t k=0UL; k<
m_; ++k ) {
1762 newEnd [k] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1763 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
1766 newEnd[
m_] = newBegin[0UL]+nonzeros;
1799 template<
typename Type
1804 return const_cast<Iterator>(
const_cast<const This&
>( *this ).
find( i, j ) );
1824 template<
typename Type
1830 if( pos !=
end_[i] && pos->index_ == j )
1832 else return end_[i];
1852 template<
typename Type
1877 template<
typename Type
1883 return std::lower_bound(
begin_[i],
end_[i], j, FindIndex() );
1903 template<
typename Type
1928 template<
typename Type
1934 return std::upper_bound(
begin_[i],
end_[i], j, FindIndex() );
1990 template<
typename Type
1999 end_[i]->value_ = value;
2002 end_[i]->index_ = j;
2022 template<
typename Type
2053 template<
typename Type
2055 template<
typename Other >
2058 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2073 template<
typename Type
2075 template<
typename Other >
2078 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2094 template<
typename Type
2096 template<
typename MT
2103 size_t nonzeros( 0UL );
2105 for(
size_t i=1UL; i<=
m_; ++i )
2108 for(
size_t i=0UL; i<
m_; ++i )
2112 for(
size_t j=0UL; j<
n_; ++j )
2114 if( nonzeros == capacity() ) {
2115 reserveElements( extendCapacity() );
2116 for(
size_t k=i+1UL; k<=
m_; ++k )
2120 end_[i]->value_ = (~rhs)(i,j);
2123 end_[i]->index_ = j;
2146 template<
typename Type
2148 template<
typename MT >
2155 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2156 begin_[i+1UL] =
end_[i] = std::copy( (~rhs).begin(i), (~rhs).end(i),
begin_[i] );
2173 template<
typename Type
2175 template<
typename MT >
2185 std::vector<size_t> rowLengths(
m_, 0UL );
2186 for(
size_t j=0UL; j<
n_; ++j ) {
2187 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2188 ++rowLengths[element->index()];
2192 for(
size_t i=0UL; i<
m_; ++i ) {
2197 for(
size_t j=0UL; j<
n_; ++j ) {
2198 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2199 append( element->index(), j, element->value() );
2216 template<
typename Type
2218 template<
typename MT
2242 template<
typename Type
2244 template<
typename MT
2268 template<
typename Type
2270 template<
typename MT
2294 template<
typename Type
2296 template<
typename MT
2329 template<
typename Type >
2345 template<
typename Other >
2346 inline Element&
operator=(
const Other& rhs )
2348 ElementBase::operator=( rhs );
2361 struct FindIndex :
public std::binary_function<Element,size_t,bool>
2363 inline bool operator()(
const Element& element,
size_t index )
const {
2364 return element.index() < index;
2366 inline bool operator()(
size_t index,
const Element& element )
const {
2367 return index < element.index();
2369 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
2370 return element1.index() < element2.index();
2396 enum { smpAssignable = 0 };
2405 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
2407 template<
typename MT,
bool SO >
inline CompressedMatrix(
const DenseMatrix<MT,SO>& dm );
2408 template<
typename MT,
bool SO >
inline CompressedMatrix(
const SparseMatrix<MT,SO>& sm );
2439 template<
typename MT,
bool SO >
inline CompressedMatrix& operator+=(
const Matrix<MT,SO>& rhs );
2440 template<
typename MT,
bool SO >
inline CompressedMatrix& operator-=(
const Matrix<MT,SO>& rhs );
2441 template<
typename MT,
bool SO >
inline CompressedMatrix& operator*=(
const Matrix<MT,SO>& rhs );
2443 template<
typename Other >
2445 operator*=( Other rhs );
2447 template<
typename Other >
2449 operator/=( Other rhs );
2456 inline size_t rows()
const;
2457 inline size_t columns()
const;
2459 inline size_t capacity(
size_t j )
const;
2461 inline size_t nonZeros(
size_t j )
const;
2462 inline void reset();
2463 inline void reset(
size_t j );
2464 inline void clear();
2466 inline void erase (
size_t i,
size_t j );
2469 void resize (
size_t m,
size_t n,
bool preserve=
true );
2470 inline void reserve(
size_t nonzeros );
2471 void reserve(
size_t j,
size_t nonzeros );
2472 inline void trim ();
2473 inline void trim (
size_t j );
2476 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
2496 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
2504 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2505 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2506 template<
typename MT,
bool SO >
inline void assign (
const DenseMatrix<MT,SO>& rhs );
2507 template<
typename MT >
inline void assign (
const SparseMatrix<MT,true>& rhs );
2508 template<
typename MT >
inline void assign (
const SparseMatrix<MT,false>& rhs );
2509 template<
typename MT,
bool SO >
inline void addAssign(
const DenseMatrix<MT,SO>& rhs );
2510 template<
typename MT,
bool SO >
inline void addAssign(
const SparseMatrix<MT,SO>& rhs );
2511 template<
typename MT,
bool SO >
inline void subAssign(
const DenseMatrix<MT,SO>& rhs );
2512 template<
typename MT,
bool SO >
inline void subAssign(
const SparseMatrix<MT,SO>& rhs );
2560 template<
typename Type >
2576 template<
typename Type >
2599 template<
typename Type >
2600 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n )
2607 for(
size_t j=0UL; j<2UL*
n_+2UL; ++j )
2624 template<
typename Type >
2625 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
size_t nonzeros )
2632 begin_[0UL] = allocate<Element>( nonzeros );
2633 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
2651 template<
typename Type >
2652 CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros )
2659 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
2661 size_t newCapacity( 0UL );
2662 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
2665 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
2666 for(
size_t j=0UL; j<
n_; ++j ) {
2680 template<
typename Type >
2681 inline CompressedMatrix<Type,true>::CompressedMatrix(
const CompressedMatrix& sm )
2688 const size_t nonzeros( sm.nonZeros() );
2690 begin_[0UL] = allocate<Element>( nonzeros );
2691 for(
size_t j=0UL; j<
n_; ++j )
2692 begin_[j+1UL] =
end_[j] = std::copy( sm.begin(j), sm.end(j), begin_[j] );
2693 end_[
n_] = begin_[0UL]+nonzeros;
2705 template<
typename Type >
2706 template<
typename MT
2708 inline CompressedMatrix<Type,true>::CompressedMatrix(
const DenseMatrix<MT,SO>& dm )
2712 , begin_ ( new
Iterator[2UL*n_+2UL] )
2713 ,
end_ ( begin_+(n_+1UL) )
2717 for(
size_t j=0UL; j<2UL*n_+2UL; ++j )
2732 template<
typename Type >
2733 template<
typename MT
2735 inline CompressedMatrix<Type,true>::CompressedMatrix(
const SparseMatrix<MT,SO>& sm )
2739 , begin_ ( new
Iterator[2UL*n_+2UL] )
2740 ,
end_ ( begin_+(n_+1UL) )
2744 const size_t nonzeros( (~sm).nonZeros() );
2746 begin_[0UL] = allocate<Element>( nonzeros );
2747 for(
size_t j=0UL; j<
n_; ++j )
2748 begin_[j+1UL] =
end_[j] = begin_[0UL];
2749 end_[
n_] = begin_[0UL]+nonzeros;
2769 template<
typename Type >
2770 inline CompressedMatrix<Type,true>::~CompressedMatrix()
2795 template<
typename Type >
2797 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
2816 template<
typename Type >
2818 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
const
2825 if( pos ==
end_[j] || pos->index_ != i )
2841 template<
typename Type >
2843 CompressedMatrix<Type,true>::begin(
size_t j )
2859 template<
typename Type >
2861 CompressedMatrix<Type,true>::begin(
size_t j )
const
2877 template<
typename Type >
2879 CompressedMatrix<Type,true>::cbegin(
size_t j )
const
2895 template<
typename Type >
2897 CompressedMatrix<Type,true>::end(
size_t j )
2913 template<
typename Type >
2915 CompressedMatrix<Type,true>::end(
size_t j )
const
2931 template<
typename Type >
2933 CompressedMatrix<Type,true>::cend(
size_t j )
const
2960 template<
typename Type >
2961 inline CompressedMatrix<Type,true>&
2962 CompressedMatrix<Type,true>::operator=(
const CompressedMatrix& rhs )
2964 if( &rhs ==
this )
return *
this;
2966 const size_t nonzeros( rhs.nonZeros() );
2968 if( rhs.n_ >
capacity_ || nonzeros > capacity() )
2971 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
2973 newBegin[0UL] = allocate<Element>( nonzeros );
2974 for(
size_t j=0UL; j<rhs.n_; ++j ) {
2975 newBegin[j+1UL] = newEnd[j] = std::copy( rhs.begin_[j], rhs.end_[j], newBegin[j] );
2977 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
2986 for(
size_t j=0UL; j<rhs.n_; ++j ) {
2987 begin_[j+1UL] =
end_[j] = std::copy( rhs.begin_[j], rhs.end_[j], begin_[j] );
3010 template<
typename Type >
3011 template<
typename MT
3013 inline CompressedMatrix<Type,true>&
3014 CompressedMatrix<Type,true>::operator=(
const DenseMatrix<MT,SO>& rhs )
3018 if( (~rhs).canAlias(
this ) ) {
3019 CompressedMatrix tmp( rhs );
3043 template<
typename Type >
3044 template<
typename MT
3046 inline CompressedMatrix<Type,true>&
3047 CompressedMatrix<Type,true>::operator=(
const SparseMatrix<MT,SO>& rhs )
3051 if( (~rhs).canAlias(
this ) ||
3053 (~rhs).nonZeros() > capacity() ) {
3054 CompressedMatrix tmp( rhs );
3080 template<
typename Type >
3081 template<
typename MT
3083 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
3088 throw std::invalid_argument(
"Matrix sizes do not match" );
3108 template<
typename Type >
3109 template<
typename MT
3111 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
3116 throw std::invalid_argument(
"Matrix sizes do not match" );
3136 template<
typename Type >
3137 template<
typename MT
3139 inline CompressedMatrix<Type,true>&
3140 CompressedMatrix<Type,true>::operator*=(
const Matrix<MT,SO>& rhs )
3142 if( (~rhs).
rows() != n_ )
3143 throw std::invalid_argument(
"Matrix sizes do not match" );
3145 CompressedMatrix tmp( *
this * (~rhs) );
3162 template<
typename Type >
3163 template<
typename Other >
3164 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3165 CompressedMatrix<Type,true>::operator*=( Other rhs )
3167 for(
size_t j=0UL; j<
n_; ++j ) {
3169 for(
Iterator element=begin(j); element!=last; ++element )
3170 element->value_ *= rhs;
3187 template<
typename Type >
3188 template<
typename Other >
3189 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3190 CompressedMatrix<Type,true>::operator/=( Other rhs )
3194 typedef typename DivTrait<Type,Other>::Type DT;
3195 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3199 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3200 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3201 for(
size_t j=0UL; j<
n_; ++j ) {
3203 for(
Iterator element=begin(j); element!=last; ++element )
3204 element->value_ *= tmp;
3208 for(
size_t j=0UL; j<
n_; ++j ) {
3210 for(
Iterator element=begin(j); element!=last; ++element )
3211 element->value_ /= rhs;
3235 template<
typename Type >
3250 template<
typename Type >
3265 template<
typename Type >
3266 inline size_t CompressedMatrix<Type,true>::capacity()
const
3268 return end_[
n_] - begin_[0UL];
3281 template<
typename Type >
3282 inline size_t CompressedMatrix<Type,true>::capacity(
size_t j )
const
3285 return begin_[j+1UL] - begin_[j];
3297 template<
typename Type >
3298 inline size_t CompressedMatrix<Type,true>::nonZeros()
const
3300 size_t nonzeros( 0UL );
3302 for(
size_t j=0UL; j<
n_; ++j )
3303 nonzeros += nonZeros( j );
3318 template<
typename Type >
3319 inline size_t CompressedMatrix<Type,true>::nonZeros(
size_t j )
const
3322 return end_[j] - begin_[j];
3334 template<
typename Type >
3337 for(
size_t j=0UL; j<
n_; ++j )
3338 end_[j] = begin_[j];
3354 template<
typename Type >
3358 end_[j] = begin_[j];
3372 template<
typename Type >
3397 template<
typename Type >
3399 CompressedMatrix<Type,true>::insert(
size_t i,
size_t j,
const Type& value )
3404 const Iterator pos( lowerBound( i, j ) );
3406 if( pos !=
end_[j] && pos->index_ == i )
3407 throw std::invalid_argument(
"Bad access index" );
3409 if( begin_[j+1UL] -
end_[j] != 0 ) {
3410 std::copy_backward( pos,
end_[j],
end_[j]+1 );
3411 pos->value_ = value;
3417 else if(
end_[n_] - begin_[n_] != 0 ) {
3418 std::copy_backward( pos,
end_[n_-1UL],
end_[n_-1]+1 );
3420 pos->value_ = value;
3423 for(
size_t k=j+1UL; k<n_+1UL; ++k ) {
3431 size_t newCapacity( extendCapacity() );
3436 newBegin[0UL] = allocate<Element>( newCapacity );
3438 for(
size_t k=0UL; k<j; ++k ) {
3439 const size_t nonzeros(
end_[k] - begin_[k] );
3440 const size_t total( begin_[k+1UL] - begin_[k] );
3441 newEnd [k] = newBegin[k] + nonzeros;
3442 newBegin[k+1UL] = newBegin[k] + total;
3444 newEnd [j] = newBegin[j] + (
end_[j] - begin_[j] ) + 1;
3445 newBegin[j+1UL] = newBegin[j] + ( begin_[j+1UL] - begin_[j] ) + 1;
3446 for(
size_t k=j+1UL; k<
n_; ++k ) {
3447 const size_t nonzeros(
end_[k] - begin_[k] );
3448 const size_t total( begin_[k+1UL] - begin_[k] );
3449 newEnd [k] = newBegin[k] + nonzeros;
3450 newBegin[k+1UL] = newBegin[k] + total;
3453 newEnd[
n_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
3455 Iterator tmp = std::copy( begin_[0UL], pos, newBegin[0UL] );
3456 tmp->value_ = value;
3458 std::copy( pos,
end_[n_-1UL], tmp+1UL );
3482 template<
typename Type >
3483 inline void CompressedMatrix<Type,true>::erase(
size_t i,
size_t j )
3488 const Iterator pos( find( i, j ) );
3489 if( pos !=
end_[j] )
3490 end_[j] = std::copy( pos+1,
end_[j], pos );
3506 template<
typename Type >
3508 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator pos )
3513 if( pos !=
end_[j] )
3514 end_[j] = std::copy( pos+1,
end_[j], pos );
3533 template<
typename Type >
3535 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last )
3543 end_[j] = std::copy( last,
end_[j], first );
3566 template<
typename Type >
3567 void CompressedMatrix<Type,true>::resize(
size_t m,
size_t n,
bool preserve )
3572 if( m ==
m_ && n == n_ )
return;
3577 Iterator* newEnd ( newBegin+n+1UL );
3579 newBegin[0UL] = begin_[0UL];
3582 for(
size_t j=0UL; j<
n_; ++j ) {
3583 newEnd [j] =
end_ [j];
3584 newBegin[j+1UL] = begin_[j+1UL];
3586 for(
size_t j=n_; j<n; ++j ) {
3587 newBegin[j+1UL] = newEnd[j] = begin_[
n_];
3591 for(
size_t j=0UL; j<n; ++j ) {
3592 newBegin[j+1UL] = newEnd[j] = begin_[0UL];
3609 for(
size_t j=0UL; j<
n_; ++j )
3610 end_[j] = begin_[j];
3613 for(
size_t j=n_; j<n; ++j )
3614 begin_[j+1UL] =
end_[j] = begin_[n_];
3619 for(
size_t j=0UL; j<n; ++j )
3620 end_[j] = lowerBound( m, j );
3623 for(
size_t j=0UL; j<n; ++j )
3624 end_[j] = begin_[j];
3648 template<
typename Type >
3649 inline void CompressedMatrix<Type,true>::reserve(
size_t nonzeros )
3651 if( nonzeros > capacity() )
3652 reserveElements( nonzeros );
3670 template<
typename Type >
3671 void CompressedMatrix<Type,true>::reserve(
size_t j,
size_t nonzeros )
3675 const size_t current( capacity(j) );
3677 if( current >= nonzeros )
return;
3679 const ptrdiff_t additional( nonzeros - current );
3681 if(
end_[n_] - begin_[n_] < additional )
3683 const size_t newCapacity( begin_[n_] - begin_[0UL] + additional );
3687 Iterator* newEnd ( newBegin+n_+1UL );
3689 newBegin[0UL] = allocate<Element>( newCapacity );
3690 newEnd [
n_ ] = newBegin[0UL]+newCapacity;
3692 for(
size_t k=0UL; k<j; ++k ) {
3693 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3694 newBegin[k+1UL] = newBegin[k] + capacity(k);
3696 newEnd [j ] = std::copy( begin_[j],
end_[j], newBegin[j] );
3697 newBegin[j+1UL] = newBegin[j] + nonzeros;
3698 for(
size_t k=j+1UL; k<
n_; ++k ) {
3699 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3700 newBegin[k+1UL] = newBegin[k] + capacity(k);
3712 begin_[
n_] += additional;
3713 for(
size_t k=n_-1UL; k>j; --k ) {
3714 begin_[k] = std::copy_backward( begin_[k],
end_[k],
end_[k]+additional );
3715 end_ [k] += additional;
3733 template<
typename Type >
3734 void CompressedMatrix<Type,true>::trim()
3736 for(
size_t j=0UL; j<
n_; ++j )
3754 template<
typename Type >
3755 void CompressedMatrix<Type,true>::trim(
size_t j )
3759 if( j < ( n_ - 1UL ) )
3760 end_[j+1] = std::copy( begin_[j+1],
end_[j+1],
end_[j] );
3761 begin_[j+1] =
end_[j];
3773 template<
typename Type >
3774 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::transpose()
3776 CompressedMatrix tmp(
trans( *
this ) );
3791 template<
typename Type >
3792 template<
typename Other >
3793 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale( Other scalar )
3795 for(
size_t j=0UL; j<
n_; ++j )
3796 for(
Iterator element=begin_[j]; element!=
end_[j]; ++element )
3797 element->value_ *= scalar;
3812 template<
typename Type >
3813 template<
typename Other >
3814 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scaleDiagonal( Other scalar )
3816 const size_t size( blaze::min(
m_, n_ ) );
3818 for(
size_t j=0UL; j<size; ++j ) {
3820 if( pos !=
end_[j] && pos->index_ == j )
3821 pos->value_ *= scalar;
3838 template<
typename Type >
3860 template<
typename Type >
3861 inline size_t CompressedMatrix<Type,true>::extendCapacity()
const
3863 size_t nonzeros( 2UL*capacity()+1UL );
3881 template<
typename Type >
3882 void CompressedMatrix<Type,true>::reserveElements(
size_t nonzeros )
3887 newBegin[0UL] = allocate<Element>( nonzeros );
3889 for(
size_t k=0UL; k<
n_; ++k ) {
3891 newEnd [k] = std::copy( begin_[k],
end_[k], newBegin[k] );
3892 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
3895 newEnd[
n_] = newBegin[0UL]+nonzeros;
3929 template<
typename Type >
3931 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
3933 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( i, j ) );
3954 template<
typename Type >
3956 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
const
3959 if( pos !=
end_[j] && pos->index_ == i )
3961 else return end_[j];
3981 template<
typename Type >
3983 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
3985 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( i, j ) );
4005 template<
typename Type >
4007 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
const
4010 return std::lower_bound( begin_[j],
end_[j], i, FindIndex() );
4030 template<
typename Type >
4032 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
4034 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( i, j ) );
4054 template<
typename Type >
4056 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
const
4059 return std::upper_bound( begin_[j],
end_[j], i, FindIndex() );
4114 template<
typename Type >
4115 inline void CompressedMatrix<Type,true>::append(
size_t i,
size_t j,
const Type& value,
bool check )
4122 end_[j]->value_ = value;
4125 end_[j]->index_ = i;
4147 template<
typename Type >
4148 inline void CompressedMatrix<Type,true>::finalize(
size_t j )
4152 begin_[j+1UL] =
end_[j];
4179 template<
typename Type >
4180 template<
typename Other >
4181 inline bool CompressedMatrix<Type,true>::canAlias(
const Other* alias )
const
4183 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4200 template<
typename Type >
4201 template<
typename Other >
4202 inline bool CompressedMatrix<Type,true>::isAliased(
const Other* alias )
const
4204 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4222 template<
typename Type >
4223 template<
typename MT
4230 size_t nonzeros( 0UL );
4232 for(
size_t j=1UL; j<=
n_; ++j )
4235 for(
size_t j=0UL; j<
n_; ++j )
4237 begin_[j] =
end_[j] = begin_[0UL]+nonzeros;
4239 for(
size_t i=0UL; i<
m_; ++i )
4241 if( nonzeros == capacity() ) {
4242 reserveElements( extendCapacity() );
4243 for(
size_t k=j+1UL; k<=
n_; ++k )
4247 end_[j]->value_ = (~rhs)(i,j);
4250 end_[j]->index_ = i;
4257 begin_[
n_] = begin_[0UL]+nonzeros;
4275 template<
typename Type >
4276 template<
typename MT >
4283 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4284 begin_[j+1UL] =
end_[j] = std::copy( (~rhs).begin(j), (~rhs).end(j), begin_[j] );
4303 template<
typename Type >
4304 template<
typename MT >
4314 std::vector<size_t> columnLengths( n_, 0UL );
4315 for(
size_t i=0UL; i<
m_; ++i ) {
4316 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4317 ++columnLengths[element->index()];
4321 for(
size_t j=0UL; j<
n_; ++j ) {
4322 begin_[j+1UL] =
end_[j+1UL] = begin_[j] + columnLengths[j];
4326 for(
size_t i=0UL; i<
m_; ++i ) {
4327 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4328 append( i, element->index(), element->value() );
4347 template<
typename Type >
4348 template<
typename MT
4355 CompressedMatrix tmp( *
this + (~rhs) );
4374 template<
typename Type >
4375 template<
typename MT
4382 CompressedMatrix tmp( *
this + (~rhs) );
4401 template<
typename Type >
4402 template<
typename MT
4409 CompressedMatrix tmp( *
this - (~rhs) );
4428 template<
typename Type >
4429 template<
typename MT
4436 CompressedMatrix tmp( *
this - (~rhs) );
4458 template<
typename Type,
bool SO >
4459 inline void reset( CompressedMatrix<Type,SO>& m );
4461 template<
typename Type,
bool SO >
4462 inline void clear( CompressedMatrix<Type,SO>& m );
4464 template<
typename Type,
bool SO >
4465 inline bool isDefault(
const CompressedMatrix<Type,SO>& m );
4467 template<
typename Type,
bool SO >
4468 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) ;
4480 template<
typename Type
4482 inline void reset( CompressedMatrix<Type,SO>& m )
4496 template<
typename Type
4498 inline void clear( CompressedMatrix<Type,SO>& m )
4523 template<
typename Type
4530 for(
size_t i=0UL; i<m.rows(); ++i ) {
4531 for( ConstIterator element=m.begin(i); element!=m.end(i); ++element )
4532 if( !
isDefault( element->value() ) )
return false;
4536 for(
size_t j=0UL; j<m.columns(); ++j ) {
4537 for( ConstIterator element=m.begin(j); element!=m.end(j); ++element )
4538 if( !
isDefault( element->value() ) )
return false;
4556 template<
typename Type
4558 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b )
4575 template<
typename T,
bool SO >
4576 struct IsResizable< CompressedMatrix<T,SO> > :
public TrueType
4582 template<
typename T,
bool SO >
4583 struct IsResizable< const CompressedMatrix<T,SO> > :
public TrueType
4589 template<
typename T,
bool SO >
4590 struct IsResizable< volatile CompressedMatrix<T,SO> > :
public TrueType
4596 template<
typename T,
bool SO >
4597 struct IsResizable< const volatile CompressedMatrix<T,SO> > :
public TrueType
4616 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4617 struct AddTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4619 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4622 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4623 struct AddTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4625 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4628 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4629 struct AddTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4631 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4634 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4635 struct AddTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4637 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4640 template<
typename T1,
bool SO,
typename T2 >
4641 struct AddTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4643 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4646 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4647 struct AddTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4649 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4652 template<
typename T1,
bool SO,
typename T2 >
4653 struct AddTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4655 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4658 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4659 struct AddTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4661 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4664 template<
typename T1,
bool SO,
typename T2 >
4665 struct AddTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4667 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4670 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4671 struct AddTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4673 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4689 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4690 struct SubTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4692 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4695 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4696 struct SubTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4698 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4701 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4702 struct SubTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4704 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4707 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4708 struct SubTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4710 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4713 template<
typename T1,
bool SO,
typename T2 >
4714 struct SubTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4716 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4719 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4720 struct SubTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4722 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4725 template<
typename T1,
bool SO,
typename T2 >
4726 struct SubTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4728 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4731 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4732 struct SubTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4734 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4737 template<
typename T1,
bool SO,
typename T2 >
4738 struct SubTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4740 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4743 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4744 struct SubTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4746 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4762 template<
typename T1,
bool SO,
typename T2 >
4763 struct MultTrait< CompressedMatrix<T1,SO>, T2 >
4765 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4769 template<
typename T1,
typename T2,
bool SO >
4770 struct MultTrait< T1, CompressedMatrix<T2,SO> >
4772 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4776 template<
typename T1,
bool SO,
typename T2,
size_t N >
4777 struct MultTrait< CompressedMatrix<T1,SO>, StaticVector<T2,N,false> >
4779 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4782 template<
typename T1,
size_t N,
typename T2,
bool SO >
4783 struct MultTrait< StaticVector<T1,N,true>, CompressedMatrix<T2,SO> >
4785 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4788 template<
typename T1,
bool SO,
typename T2,
size_t N >
4789 struct MultTrait< CompressedMatrix<T1,SO>, HybridVector<T2,N,false> >
4791 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4794 template<
typename T1,
size_t N,
typename T2,
bool SO >
4795 struct MultTrait< HybridVector<T1,N,true>, CompressedMatrix<T2,SO> >
4797 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4800 template<
typename T1,
bool SO,
typename T2 >
4801 struct MultTrait< CompressedMatrix<T1,SO>, DynamicVector<T2,false> >
4803 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4806 template<
typename T1,
typename T2,
bool SO >
4807 struct MultTrait< DynamicVector<T1,true>, CompressedMatrix<T2,SO> >
4809 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4812 template<
typename T1,
bool SO,
typename T2 >
4813 struct MultTrait< CompressedMatrix<T1,SO>, CompressedVector<T2,false> >
4815 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
false > Type;
4818 template<
typename T1,
typename T2,
bool SO >
4819 struct MultTrait< CompressedVector<T1,true>, CompressedMatrix<T2,SO> >
4821 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
true > Type;
4824 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4825 struct MultTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4827 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4830 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4831 struct MultTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4833 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4836 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4837 struct MultTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4839 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4842 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4843 struct MultTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4845 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4848 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4849 struct MultTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4851 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4867 template<
typename T1,
bool SO,
typename T2 >
4868 struct DivTrait< CompressedMatrix<T1,SO>, T2 >
4870 typedef CompressedMatrix< typename DivTrait<T1,T2>::Type, SO > Type;
4887 template<
typename T1,
bool SO,
typename T2 >
4888 struct MathTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4890 typedef CompressedMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
4891 typedef CompressedMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
4907 template<
typename T1,
bool SO >
4908 struct SubmatrixTrait< CompressedMatrix<T1,SO> >
4910 typedef CompressedMatrix<T1,SO> Type;
4926 template<
typename T1,
bool SO >
4927 struct RowTrait< CompressedMatrix<T1,SO> >
4929 typedef CompressedVector<T1,true> Type;
4945 template<
typename T1,
bool SO >
4946 struct ColumnTrait< CompressedMatrix<T1,SO> >
4948 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:1109
void reserveElements(size_t nonzeros)
Reserving the specified number of sparse matrix elements.
Definition: CompressedMatrix.h:1753
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:399
Header file for mathematical functions.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#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:252
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:253
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.
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:751
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:443
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
size_t extendCapacity() const
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1733
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:2528
void clear()
Clearing the sparse matrix.
Definition: CompressedMatrix.h:1250
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:249
Header file for a safe C++ NULL pointer implementation.
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given sparse matrix.
Definition: CompressedMatrix.h:4498
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2378
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:247
#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:629
void reset(CompressedMatrix< Type, SO > &m)
Resetting the given sparse matrix.
Definition: CompressedMatrix.h:4482
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:2076
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:401
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:250
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:104
Constraint on the data type.
size_t nonZeros() const
Returns the number of non-zero elements in the sparse matrix.
Definition: CompressedMatrix.h:1172
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2530
Header file for the SparseMatrix base class.
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:114
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:397
Header file for the floating point precision of the Blaze library.
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1524
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1212
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:251
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:4525
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:4558
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:2388
#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
void erase(size_t i, size_t j)
Erasing an element from the sparse matrix.
Definition: CompressedMatrix.h:1358
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2532
#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:201
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:179
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:1275
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2386
void subAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: CompressedMatrix.h:2272
Header file for the EnableIf class template.
void swap(CompressedMatrix &sm)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:1712
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:255
Header file for the equal shim.
size_t capacity() const
Returns the maximum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1137
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the sparse matrix.
Definition: CompressedMatrix.h:1443
Header file for the IsNumeric type trait.
CompressedMatrix & operator=(const CompressedMatrix &rhs)
Copy assignment operator for CompressedMatrix.
Definition: CompressedMatrix.h:842
Reference operator()(size_t i, size_t j)
2D-access to the sparse matrix elements.
Definition: CompressedMatrix.h:655
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:770
CompressedMatrix & transpose()
Transposing the matrix.
Definition: CompressedMatrix.h:1650
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:4651
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:209
void trim()
Removing all excessive capacity from all rows/columns.
Definition: CompressedMatrix.h:1611
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:239
const VT::ElementType max(const SparseVector< VT, TF > &sv)
Returns the largest element of the sparse vector.
Definition: SparseVector.h:405
#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:2387
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:85
size_t columns() const
Returns the current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:1123
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:246
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2531
void assign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the assignment of a row-major dense matrix.
Definition: CompressedMatrix.h:2098
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:254
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:1992
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2024
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: CompressedMatrix.h:2056
Base template for the DivTrait class.
Definition: DivTrait.h:141
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:245
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:1802
Header file for the mathematical trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:398
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2529
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:2220
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:248
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less then the given index.
Definition: CompressedMatrix.h:1855
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2534
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: CompressedMatrix.h:1906
size_t columns(const Matrix< MT, SO > &m)
Returns the current number of columns of the matrix.
Definition: Matrix.h:154
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:748
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2385
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:348
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:396
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:814
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:395
size_t rows(const Matrix< MT, SO > &m)
Returns the current number of rows of the matrix.
Definition: Matrix.h:138
#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
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:704