35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
203 template<
typename Type
220 template<
typename Other >
221 inline Element&
operator=(
const Other& rhs )
223 ElementBase::operator=( rhs );
236 struct FindIndex :
public std::binary_function<Element,size_t,bool>
238 inline bool operator()(
const Element& element,
size_t index )
const {
239 return element.index() < index;
241 inline bool operator()(
size_t index,
const Element& element )
const {
242 return index < element.index();
244 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
245 return element1.index() < element2.index();
269 template<
typename ET >
289 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
327 template<
typename Other >
329 operator*=( Other rhs );
331 template<
typename Other >
333 operator/=( Other rhs );
340 inline size_t rows()
const;
343 inline size_t capacity(
size_t i )
const;
345 inline size_t nonZeros(
size_t i )
const;
347 inline void reset(
size_t i );
349 inline Iterator set (
size_t i,
size_t j,
const Type& value );
351 inline void erase (
size_t i,
size_t j );
354 void resize (
size_t m,
size_t n,
bool preserve=
true );
355 inline void reserve(
size_t nonzeros );
356 void reserve(
size_t i,
size_t nonzeros );
358 inline void trim (
size_t i );
360 template<
typename Other >
inline CompressedMatrix& scale(
const Other& scalar );
361 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
381 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
389 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
390 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
448 template<
typename Type,
bool SO >
463 template<
typename Type
485 template<
typename Type
494 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
509 template<
typename Type
518 begin_[0UL] = allocate<Element>( nonzeros );
519 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
535 template<
typename Type
544 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
546 size_t newCapacity( 0UL );
547 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
550 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
551 for(
size_t i=0UL; i<
m_; ++i ) {
563 template<
typename Type
572 const size_t nonzeros( sm.
nonZeros() );
574 begin_[0UL] = allocate<Element>( nonzeros );
575 for(
size_t i=0UL; i<
m_; ++i )
576 begin_[i+1UL] =
end_[i] = std::copy( sm.
begin(i), sm.
end(i), begin_[i] );
577 end_[
m_] = begin_[0UL]+nonzeros;
587 template<
typename Type
589 template<
typename MT
600 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
613 template<
typename Type
615 template<
typename MT
626 const size_t nonzeros( (~sm).
nonZeros() );
628 begin_[0UL] = allocate<Element>( nonzeros );
629 for(
size_t i=0UL; i<
m_; ++i )
649 template<
typename Type
674 template<
typename Type
694 template<
typename Type
704 if( pos ==
end_[i] || pos->index_ != j )
723 template<
typename Type
745 template<
typename Type
767 template<
typename Type
789 template<
typename Type
811 template<
typename Type
833 template<
typename Type
861 template<
typename Type
866 if( &rhs ==
this )
return *
this;
868 const size_t nonzeros( rhs.
nonZeros() );
875 newBegin[0UL] = allocate<Element>( nonzeros );
876 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
877 newBegin[i+1UL] = newEnd[i] = std::copy( rhs.
begin_[i], rhs.
end_[i], newBegin[i] );
879 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
888 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
910 template<
typename Type
912 template<
typename MT
919 if( (~rhs).canAlias(
this ) ) {
942 template<
typename Type
944 template<
typename MT
951 if( (~rhs).canAlias(
this ) ||
978 template<
typename Type
980 template<
typename MT
988 throw std::invalid_argument(
"Matrix sizes do not match" );
1006 template<
typename Type
1008 template<
typename MT
1015 throw std::invalid_argument(
"Matrix sizes do not match" );
1033 template<
typename Type
1035 template<
typename MT
1040 if( (~rhs).
rows() !=
n_ )
1041 throw std::invalid_argument(
"Matrix sizes do not match" );
1058 template<
typename Type
1060 template<
typename Other >
1064 for(
size_t i=0UL; i<
m_; ++i ) {
1067 element->value_ *= rhs;
1081 template<
typename Type
1083 template<
typename Other >
1095 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1096 for(
size_t i=0UL; i<
m_; ++i ) {
1099 element->value_ *= tmp;
1103 for(
size_t i=0UL; i<
m_; ++i ) {
1106 element->value_ /= rhs;
1128 template<
typename Type
1142 template<
typename Type
1156 template<
typename Type
1176 template<
typename Type
1191 template<
typename Type
1195 size_t nonzeros( 0UL );
1197 for(
size_t i=0UL; i<
m_; ++i )
1216 template<
typename Type
1231 template<
typename Type
1235 for(
size_t i=0UL; i<
m_; ++i )
1252 template<
typename Type
1269 template<
typename Type
1292 template<
typename Type
1300 const Iterator pos( lowerBound( i, j ) );
1302 if( pos !=
end_[i] && pos->index_ == j ) {
1303 pos->value() = value;
1306 else return insert( pos, i, j, value );
1324 template<
typename Type
1332 const Iterator pos( lowerBound( i, j ) );
1334 if( pos !=
end_[i] && pos->index_ == j )
1335 throw std::invalid_argument(
"Bad access index" );
1337 return insert( pos, i, j, value );
1352 template<
typename Type
1358 std::copy_backward( pos,
end_[i],
end_[i]+1 );
1359 pos->value_ = value;
1366 std::copy_backward( pos,
end_[
m_-1UL],
end_[
m_-1UL]+1 );
1368 pos->value_ = value;
1371 for(
size_t k=i+1UL; k<
m_+1UL; ++k ) {
1379 size_t newCapacity( extendCapacity() );
1384 newBegin[0UL] = allocate<Element>( newCapacity );
1386 for(
size_t k=0UL; k<i; ++k ) {
1387 const size_t nonzeros(
end_[k] -
begin_[k] );
1389 newEnd [k] = newBegin[k] + nonzeros;
1390 newBegin[k+1UL] = newBegin[k] + total;
1392 newEnd [i] = newBegin[i] + (
end_[i] -
begin_[i] ) + 1;
1393 newBegin[i+1UL] = newBegin[i] + (
begin_[i+1] -
begin_[i] ) + 1;
1394 for(
size_t k=i+1UL; k<
m_; ++k ) {
1395 const size_t nonzeros(
end_[k] -
begin_[k] );
1397 newEnd [k] = newBegin[k] + nonzeros;
1398 newBegin[k+1UL] = newBegin[k] + total;
1401 newEnd[
m_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
1404 tmp->value_ = value;
1406 std::copy( pos,
end_[m_-1UL], tmp+1UL );
1428 template<
typename Type
1435 const Iterator pos( find( i, j ) );
1436 if( pos !=
end_[i] )
1437 end_[i] = std::copy( pos+1,
end_[i], pos );
1453 template<
typename Type
1461 if( pos !=
end_[i] )
1462 end_[i] = std::copy( pos+1,
end_[i], pos );
1481 template<
typename Type
1492 end_[i] = std::copy( last,
end_[i], first );
1514 template<
typename Type
1521 if( m ==
m_ && n ==
n_ )
return;
1526 Iterator* newEnd ( newBegin+m+1UL );
1528 newBegin[0UL] =
begin_[0UL];
1531 for(
size_t i=0UL; i<
m_; ++i ) {
1532 newEnd [i] =
end_ [i];
1533 newBegin[i+1UL] =
begin_[i+1UL];
1535 for(
size_t i=m_; i<m; ++i ) {
1536 newBegin[i+1UL] = newEnd[i] =
begin_[
m_];
1540 for(
size_t i=0UL; i<m; ++i ) {
1541 newBegin[i+1UL] = newEnd[i] =
begin_[0UL];
1558 for(
size_t i=0UL; i<
m_; ++i )
1562 for(
size_t i=
m_; i<m; ++i )
1568 for(
size_t i=0UL; i<m; ++i )
1569 end_[i] = lowerBound( i, n );
1572 for(
size_t i=0UL; i<m; ++i )
1595 template<
typename Type
1600 reserveElements( nonzeros );
1619 template<
typename Type
1625 const size_t current(
capacity(i) );
1627 if( current >= nonzeros )
return;
1629 const ptrdiff_t additional( nonzeros - current );
1633 const size_t newCapacity(
begin_[
m_] -
begin_[0UL] + additional );
1639 newBegin[0UL] = allocate<Element>( newCapacity );
1640 newEnd [
m_ ] = newBegin[0UL]+newCapacity;
1642 for(
size_t k=0UL; k<i; ++k ) {
1643 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1644 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1646 newEnd [i ] = std::copy(
begin_[i],
end_[i], newBegin[i] );
1647 newBegin[i+1UL] = newBegin[i] + nonzeros;
1648 for(
size_t k=i+1UL; k<
m_; ++k ) {
1649 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1650 newBegin[k+1UL] = newBegin[k] +
capacity(k);
1663 for(
size_t j=
m_-1UL; j>i; --j ) {
1665 end_ [j] += additional;
1682 template<
typename Type
1686 for(
size_t i=0UL; i<
m_; ++i )
1703 template<
typename Type
1709 if( i < (
m_ - 1UL ) )
1721 template<
typename Type
1738 template<
typename Type
1740 template<
typename Other >
1743 for(
size_t i=0UL; i<
m_; ++i )
1745 element->value_ *= scalar;
1758 template<
typename Type
1760 template<
typename Other >
1765 for(
size_t i=0UL; i<
size; ++i ) {
1767 if( pos !=
end_[i] && pos->index_ == i )
1768 pos->value_ *= scalar;
1783 template<
typename Type
1804 template<
typename Type
1808 size_t nonzeros( 2UL*
capacity()+1UL );
1824 template<
typename Type
1831 newBegin[0UL] = allocate<Element>( nonzeros );
1833 for(
size_t k=0UL; k<
m_; ++k ) {
1835 newEnd [k] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1836 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
1839 newEnd[
m_] = newBegin[0UL]+nonzeros;
1872 template<
typename Type
1877 return const_cast<Iterator>(
const_cast<const This&
>( *this ).
find( i, j ) );
1897 template<
typename Type
1903 if( pos !=
end_[i] && pos->index_ == j )
1905 else return end_[i];
1925 template<
typename Type
1950 template<
typename Type
1956 return std::lower_bound(
begin_[i],
end_[i], j, FindIndex() );
1976 template<
typename Type
2001 template<
typename Type
2007 return std::upper_bound(
begin_[i],
end_[i], j, FindIndex() );
2063 template<
typename Type
2072 end_[i]->value_ = value;
2075 end_[i]->index_ = j;
2095 template<
typename Type
2126 template<
typename Type
2128 template<
typename Other >
2131 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2146 template<
typename Type
2148 template<
typename Other >
2151 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2166 template<
typename Type
2186 template<
typename Type
2188 template<
typename MT
2195 size_t nonzeros( 0UL );
2197 for(
size_t i=1UL; i<=
m_; ++i )
2200 for(
size_t i=0UL; i<
m_; ++i )
2204 for(
size_t j=0UL; j<
n_; ++j )
2207 reserveElements( extendCapacity() );
2208 for(
size_t k=i+1UL; k<=
m_; ++k )
2212 end_[i]->value_ = (~rhs)(i,j);
2215 end_[i]->index_ = j;
2238 template<
typename Type
2240 template<
typename MT >
2247 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2265 template<
typename Type
2267 template<
typename MT >
2279 std::vector<size_t> rowLengths(
m_, 0UL );
2280 for(
size_t j=0UL; j<
n_; ++j ) {
2281 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2282 ++rowLengths[element->index()];
2286 for(
size_t i=0UL; i<
m_; ++i ) {
2291 for(
size_t j=0UL; j<
n_; ++j ) {
2292 for( RhsIterator element=(~rhs).
begin(j); element!=(~rhs).
end(j); ++element )
2293 append( element->index(), j, element->value() );
2310 template<
typename Type
2312 template<
typename MT
2336 template<
typename Type
2338 template<
typename MT
2362 template<
typename Type
2364 template<
typename MT
2388 template<
typename Type
2390 template<
typename MT
2423 template<
typename Type >
2439 template<
typename Other >
2440 inline Element&
operator=(
const Other& rhs )
2442 ElementBase::operator=( rhs );
2455 struct FindIndex :
public std::binary_function<Element,size_t,bool>
2457 inline bool operator()(
const Element& element,
size_t index )
const {
2458 return element.index() < index;
2460 inline bool operator()(
size_t index,
const Element& element )
const {
2461 return index < element.index();
2463 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
2464 return element1.index() < element2.index();
2488 template<
typename ET >
2508 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
2510 template<
typename MT,
bool SO >
inline CompressedMatrix(
const DenseMatrix<MT,SO>& dm );
2511 template<
typename MT,
bool SO >
inline CompressedMatrix(
const SparseMatrix<MT,SO>& sm );
2542 template<
typename MT,
bool SO >
inline CompressedMatrix& operator+=(
const Matrix<MT,SO>& rhs );
2543 template<
typename MT,
bool SO >
inline CompressedMatrix& operator-=(
const Matrix<MT,SO>& rhs );
2544 template<
typename MT,
bool SO >
inline CompressedMatrix& operator*=(
const Matrix<MT,SO>& rhs );
2546 template<
typename Other >
2548 operator*=( Other rhs );
2550 template<
typename Other >
2552 operator/=( Other rhs );
2559 inline size_t rows()
const;
2560 inline size_t columns()
const;
2562 inline size_t capacity(
size_t j )
const;
2564 inline size_t nonZeros(
size_t j )
const;
2565 inline void reset();
2566 inline void reset(
size_t j );
2567 inline void clear();
2568 inline Iterator set (
size_t i,
size_t j,
const Type& value );
2569 inline Iterator insert (
size_t i,
size_t j,
const Type& value );
2570 inline void erase (
size_t i,
size_t j );
2573 void resize (
size_t m,
size_t n,
bool preserve=
true );
2574 inline void reserve(
size_t nonzeros );
2575 void reserve(
size_t j,
size_t nonzeros );
2576 inline void trim ();
2577 inline void trim (
size_t j );
2579 template<
typename Other >
inline CompressedMatrix& scale(
const Other& scalar );
2580 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
2600 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
2608 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2609 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2613 template<
typename MT,
bool SO >
inline void assign (
const DenseMatrix<MT,SO>& rhs );
2614 template<
typename MT >
inline void assign (
const SparseMatrix<MT,true>& rhs );
2615 template<
typename MT >
inline void assign (
const SparseMatrix<MT,false>& rhs );
2616 template<
typename MT,
bool SO >
inline void addAssign(
const DenseMatrix<MT,SO>& rhs );
2617 template<
typename MT,
bool SO >
inline void addAssign(
const SparseMatrix<MT,SO>& rhs );
2618 template<
typename MT,
bool SO >
inline void subAssign(
const DenseMatrix<MT,SO>& rhs );
2619 template<
typename MT,
bool SO >
inline void subAssign(
const SparseMatrix<MT,SO>& rhs );
2668 template<
typename Type >
2684 template<
typename Type >
2707 template<
typename Type >
2708 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n )
2715 for(
size_t j=0UL; j<2UL*
n_+2UL; ++j )
2732 template<
typename Type >
2733 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
size_t nonzeros )
2740 begin_[0UL] = allocate<Element>( nonzeros );
2741 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
2759 template<
typename Type >
2760 CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros )
2767 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
2769 size_t newCapacity( 0UL );
2770 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
2773 begin_[0UL] =
end_[0UL] = allocate<Element>( newCapacity );
2774 for(
size_t j=0UL; j<
n_; ++j ) {
2788 template<
typename Type >
2789 inline CompressedMatrix<Type,true>::CompressedMatrix(
const CompressedMatrix& sm )
2796 const size_t nonzeros( sm.nonZeros() );
2798 begin_[0UL] = allocate<Element>( nonzeros );
2799 for(
size_t j=0UL; j<
n_; ++j )
2800 begin_[j+1UL] =
end_[j] = std::copy( sm.begin(j), sm.end(j), begin_[j] );
2801 end_[
n_] = begin_[0UL]+nonzeros;
2813 template<
typename Type >
2814 template<
typename MT
2816 inline CompressedMatrix<Type,true>::CompressedMatrix(
const DenseMatrix<MT,SO>& dm )
2820 , begin_ ( new
Iterator[2UL*n_+2UL] )
2821 ,
end_ ( begin_+(n_+1UL) )
2825 for(
size_t j=0UL; j<2UL*n_+2UL; ++j )
2840 template<
typename Type >
2841 template<
typename MT
2843 inline CompressedMatrix<Type,true>::CompressedMatrix(
const SparseMatrix<MT,SO>& sm )
2847 , begin_ ( new
Iterator[2UL*n_+2UL] )
2848 ,
end_ ( begin_+(n_+1UL) )
2852 const size_t nonzeros( (~sm).
nonZeros() );
2854 begin_[0UL] = allocate<Element>( nonzeros );
2855 for(
size_t j=0UL; j<
n_; ++j )
2856 begin_[j+1UL] =
end_[j] = begin_[0UL];
2857 end_[
n_] = begin_[0UL]+nonzeros;
2877 template<
typename Type >
2878 inline CompressedMatrix<Type,true>::~CompressedMatrix()
2903 template<
typename Type >
2905 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
2924 template<
typename Type >
2926 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
const
2933 if( pos ==
end_[j] || pos->index_ != i )
2949 template<
typename Type >
2951 CompressedMatrix<Type,true>::begin(
size_t j )
2967 template<
typename Type >
2969 CompressedMatrix<Type,true>::begin(
size_t j )
const
2985 template<
typename Type >
2987 CompressedMatrix<Type,true>::cbegin(
size_t j )
const
3003 template<
typename Type >
3005 CompressedMatrix<Type,true>::end(
size_t j )
3021 template<
typename Type >
3023 CompressedMatrix<Type,true>::end(
size_t j )
const
3039 template<
typename Type >
3041 CompressedMatrix<Type,true>::cend(
size_t j )
const
3068 template<
typename Type >
3069 inline CompressedMatrix<Type,true>&
3070 CompressedMatrix<Type,true>::operator=(
const CompressedMatrix& rhs )
3072 if( &rhs ==
this )
return *
this;
3074 const size_t nonzeros( rhs.nonZeros() );
3079 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
3081 newBegin[0UL] = allocate<Element>( nonzeros );
3082 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3083 newBegin[j+1UL] = newEnd[j] = std::copy( rhs.begin_[j], rhs.end_[j], newBegin[j] );
3085 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
3094 for(
size_t j=0UL; j<rhs.n_; ++j ) {
3095 begin_[j+1UL] =
end_[j] = std::copy( rhs.begin_[j], rhs.end_[j], begin_[j] );
3118 template<
typename Type >
3119 template<
typename MT
3121 inline CompressedMatrix<Type,true>&
3122 CompressedMatrix<Type,true>::operator=(
const DenseMatrix<MT,SO>& rhs )
3126 if( (~rhs).canAlias(
this ) ) {
3127 CompressedMatrix tmp( ~rhs );
3151 template<
typename Type >
3152 template<
typename MT
3154 inline CompressedMatrix<Type,true>&
3155 CompressedMatrix<Type,true>::operator=(
const SparseMatrix<MT,SO>& rhs )
3159 if( (~rhs).canAlias(
this ) ||
3162 CompressedMatrix tmp( ~rhs );
3188 template<
typename Type >
3189 template<
typename MT
3191 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
3196 throw std::invalid_argument(
"Matrix sizes do not match" );
3216 template<
typename Type >
3217 template<
typename MT
3219 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
3224 throw std::invalid_argument(
"Matrix sizes do not match" );
3244 template<
typename Type >
3245 template<
typename MT
3247 inline CompressedMatrix<Type,true>&
3248 CompressedMatrix<Type,true>::operator*=(
const Matrix<MT,SO>& rhs )
3250 if( (~rhs).
rows() != n_ )
3251 throw std::invalid_argument(
"Matrix sizes do not match" );
3253 CompressedMatrix tmp( *
this * (~rhs) );
3270 template<
typename Type >
3271 template<
typename Other >
3272 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3273 CompressedMatrix<Type,true>::operator*=( Other rhs )
3275 for(
size_t j=0UL; j<
n_; ++j ) {
3278 element->value_ *= rhs;
3294 template<
typename Type >
3295 template<
typename Other >
3296 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3297 CompressedMatrix<Type,true>::operator/=( Other rhs )
3301 typedef typename DivTrait<Type,Other>::Type DT;
3302 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3306 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3307 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3308 for(
size_t j=0UL; j<
n_; ++j ) {
3311 element->value_ *= tmp;
3315 for(
size_t j=0UL; j<
n_; ++j ) {
3318 element->value_ /= rhs;
3342 template<
typename Type >
3343 inline size_t CompressedMatrix<Type,true>::rows()
const
3357 template<
typename Type >
3358 inline size_t CompressedMatrix<Type,true>::columns()
const
3372 template<
typename Type >
3373 inline size_t CompressedMatrix<Type,true>::capacity()
const
3375 return end_[
n_] - begin_[0UL];
3388 template<
typename Type >
3389 inline size_t CompressedMatrix<Type,true>::capacity(
size_t j )
const
3392 return begin_[j+1UL] - begin_[j];
3404 template<
typename Type >
3405 inline size_t CompressedMatrix<Type,true>::nonZeros()
const
3407 size_t nonzeros( 0UL );
3409 for(
size_t j=0UL; j<
n_; ++j )
3425 template<
typename Type >
3426 inline size_t CompressedMatrix<Type,true>::nonZeros(
size_t j )
const
3429 return end_[j] - begin_[j];
3441 template<
typename Type >
3444 for(
size_t j=0UL; j<
n_; ++j )
3445 end_[j] = begin_[j];
3461 template<
typename Type >
3465 end_[j] = begin_[j];
3479 template<
typename Type >
3503 template<
typename Type >
3505 CompressedMatrix<Type,true>::set(
size_t i,
size_t j,
const Type& value )
3510 const Iterator pos( lowerBound( i, j ) );
3512 if( pos !=
end_[j] && pos->index_ == i ) {
3513 pos->value() = value;
3516 else return insert( pos, i, j, value );
3536 template<
typename Type >
3538 CompressedMatrix<Type,true>::insert(
size_t i,
size_t j,
const Type& value )
3543 const Iterator pos( lowerBound( i, j ) );
3545 if( pos !=
end_[j] && pos->index_ == i )
3546 throw std::invalid_argument(
"Bad access index" );
3548 return insert( pos, i, j, value );
3565 template<
typename Type >
3567 CompressedMatrix<Type,true>::insert(
Iterator pos,
size_t i,
size_t j,
const Type& value )
3569 if( begin_[j+1UL] -
end_[j] != 0 ) {
3570 std::copy_backward( pos,
end_[j],
end_[j]+1 );
3571 pos->value_ = value;
3577 else if(
end_[n_] - begin_[n_] != 0 ) {
3578 std::copy_backward( pos,
end_[n_-1UL],
end_[n_-1]+1 );
3580 pos->value_ = value;
3583 for(
size_t k=j+1UL; k<n_+1UL; ++k ) {
3591 size_t newCapacity( extendCapacity() );
3596 newBegin[0UL] = allocate<Element>( newCapacity );
3598 for(
size_t k=0UL; k<j; ++k ) {
3599 const size_t nonzeros(
end_[k] - begin_[k] );
3600 const size_t total( begin_[k+1UL] - begin_[k] );
3601 newEnd [k] = newBegin[k] + nonzeros;
3602 newBegin[k+1UL] = newBegin[k] + total;
3604 newEnd [j] = newBegin[j] + (
end_[j] - begin_[j] ) + 1;
3605 newBegin[j+1UL] = newBegin[j] + ( begin_[j+1UL] - begin_[j] ) + 1;
3606 for(
size_t k=j+1UL; k<
n_; ++k ) {
3607 const size_t nonzeros(
end_[k] - begin_[k] );
3608 const size_t total( begin_[k+1UL] - begin_[k] );
3609 newEnd [k] = newBegin[k] + nonzeros;
3610 newBegin[k+1UL] = newBegin[k] + total;
3613 newEnd[
n_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
3615 Iterator tmp = std::copy( begin_[0UL], pos, newBegin[0UL] );
3616 tmp->value_ = value;
3618 std::copy( pos,
end_[n_-1UL], tmp+1UL );
3642 template<
typename Type >
3643 inline void CompressedMatrix<Type,true>::erase(
size_t i,
size_t j )
3648 const Iterator pos( find( i, j ) );
3649 if( pos !=
end_[j] )
3650 end_[j] = std::copy( pos+1,
end_[j], pos );
3666 template<
typename Type >
3668 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator pos )
3673 if( pos !=
end_[j] )
3674 end_[j] = std::copy( pos+1,
end_[j], pos );
3693 template<
typename Type >
3695 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last )
3703 end_[j] = std::copy( last,
end_[j], first );
3727 template<
typename Type >
3728 void CompressedMatrix<Type,true>::resize(
size_t m,
size_t n,
bool preserve )
3733 if( m ==
m_ && n == n_ )
return;
3738 Iterator* newEnd ( newBegin+n+1UL );
3740 newBegin[0UL] = begin_[0UL];
3743 for(
size_t j=0UL; j<
n_; ++j ) {
3744 newEnd [j] =
end_ [j];
3745 newBegin[j+1UL] = begin_[j+1UL];
3747 for(
size_t j=n_; j<n; ++j ) {
3748 newBegin[j+1UL] = newEnd[j] = begin_[
n_];
3752 for(
size_t j=0UL; j<n; ++j ) {
3753 newBegin[j+1UL] = newEnd[j] = begin_[0UL];
3770 for(
size_t j=0UL; j<
n_; ++j )
3771 end_[j] = begin_[j];
3774 for(
size_t j=n_; j<n; ++j )
3775 begin_[j+1UL] =
end_[j] = begin_[n_];
3780 for(
size_t j=0UL; j<n; ++j )
3781 end_[j] = lowerBound( m, j );
3784 for(
size_t j=0UL; j<n; ++j )
3785 end_[j] = begin_[j];
3809 template<
typename Type >
3810 inline void CompressedMatrix<Type,true>::reserve(
size_t nonzeros )
3813 reserveElements( nonzeros );
3831 template<
typename Type >
3832 void CompressedMatrix<Type,true>::reserve(
size_t j,
size_t nonzeros )
3836 const size_t current(
capacity(j) );
3838 if( current >= nonzeros )
return;
3840 const ptrdiff_t additional( nonzeros - current );
3842 if(
end_[n_] - begin_[n_] < additional )
3844 const size_t newCapacity( begin_[n_] - begin_[0UL] + additional );
3848 Iterator* newEnd ( newBegin+n_+1UL );
3850 newBegin[0UL] = allocate<Element>( newCapacity );
3851 newEnd [
n_ ] = newBegin[0UL]+newCapacity;
3853 for(
size_t k=0UL; k<j; ++k ) {
3854 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3855 newBegin[k+1UL] = newBegin[k] +
capacity(k);
3857 newEnd [j ] = std::copy( begin_[j],
end_[j], newBegin[j] );
3858 newBegin[j+1UL] = newBegin[j] + nonzeros;
3859 for(
size_t k=j+1UL; k<
n_; ++k ) {
3860 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3861 newBegin[k+1UL] = newBegin[k] +
capacity(k);
3873 begin_[
n_] += additional;
3874 for(
size_t k=n_-1UL; k>j; --k ) {
3875 begin_[k] = std::copy_backward( begin_[k],
end_[k],
end_[k]+additional );
3876 end_ [k] += additional;
3894 template<
typename Type >
3895 void CompressedMatrix<Type,true>::trim()
3897 for(
size_t j=0UL; j<
n_; ++j )
3915 template<
typename Type >
3916 void CompressedMatrix<Type,true>::trim(
size_t j )
3920 if( j < ( n_ - 1UL ) )
3921 end_[j+1] = std::copy( begin_[j+1],
end_[j+1],
end_[j] );
3922 begin_[j+1] =
end_[j];
3934 template<
typename Type >
3935 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::transpose()
3937 CompressedMatrix tmp(
trans( *
this ) );
3952 template<
typename Type >
3953 template<
typename Other >
3954 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale(
const Other& scalar )
3956 for(
size_t j=0UL; j<
n_; ++j )
3957 for(
Iterator element=begin_[j]; element!=
end_[j]; ++element )
3958 element->value_ *= scalar;
3973 template<
typename Type >
3974 template<
typename Other >
3975 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scaleDiagonal( Other scalar )
3979 for(
size_t j=0UL; j<
size; ++j ) {
3981 if( pos !=
end_[j] && pos->index_ == j )
3982 pos->value_ *= scalar;
3999 template<
typename Type >
4021 template<
typename Type >
4022 inline size_t CompressedMatrix<Type,true>::extendCapacity()
const
4024 size_t nonzeros( 2UL*
capacity()+1UL );
4042 template<
typename Type >
4043 void CompressedMatrix<Type,true>::reserveElements(
size_t nonzeros )
4048 newBegin[0UL] = allocate<Element>( nonzeros );
4050 for(
size_t k=0UL; k<
n_; ++k ) {
4052 newEnd [k] = std::copy( begin_[k],
end_[k], newBegin[k] );
4053 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
4056 newEnd[
n_] = newBegin[0UL]+nonzeros;
4090 template<
typename Type >
4092 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
4094 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( i, j ) );
4115 template<
typename Type >
4117 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
const
4120 if( pos !=
end_[j] && pos->index_ == i )
4122 else return end_[j];
4142 template<
typename Type >
4144 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
4146 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( i, j ) );
4166 template<
typename Type >
4168 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
const
4171 return std::lower_bound( begin_[j],
end_[j], i, FindIndex() );
4191 template<
typename Type >
4193 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
4195 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( i, j ) );
4215 template<
typename Type >
4217 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
const
4220 return std::upper_bound( begin_[j],
end_[j], i, FindIndex() );
4275 template<
typename Type >
4276 inline void CompressedMatrix<Type,true>::append(
size_t i,
size_t j,
const Type& value,
bool check )
4283 end_[j]->value_ = value;
4286 end_[j]->index_ = i;
4308 template<
typename Type >
4309 inline void CompressedMatrix<Type,true>::finalize(
size_t j )
4313 begin_[j+1UL] =
end_[j];
4340 template<
typename Type >
4341 template<
typename Other >
4342 inline bool CompressedMatrix<Type,true>::canAlias(
const Other* alias )
const
4344 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4361 template<
typename Type >
4362 template<
typename Other >
4363 inline bool CompressedMatrix<Type,true>::isAliased(
const Other* alias )
const
4365 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4382 template<
typename Type >
4383 inline bool CompressedMatrix<Type,true>::canSMPAssign()
const
4403 template<
typename Type >
4404 template<
typename MT
4406 inline void CompressedMatrix<Type,true>::assign(
const DenseMatrix<MT,SO>& rhs )
4411 size_t nonzeros( 0UL );
4413 for(
size_t j=1UL; j<=
n_; ++j )
4416 for(
size_t j=0UL; j<
n_; ++j )
4418 begin_[j] =
end_[j] = begin_[0UL]+nonzeros;
4420 for(
size_t i=0UL; i<
m_; ++i )
4423 reserveElements( extendCapacity() );
4424 for(
size_t k=j+1UL; k<=
n_; ++k )
4428 end_[j]->value_ = (~rhs)(i,j);
4431 end_[j]->index_ = i;
4438 begin_[
n_] = begin_[0UL]+nonzeros;
4456 template<
typename Type >
4457 template<
typename MT >
4458 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,true>& rhs )
4464 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4465 begin_[j+1UL] =
end_[j] = std::copy( (~rhs).
begin(j), (~rhs).
end(j), begin_[j] );
4484 template<
typename Type >
4485 template<
typename MT >
4486 inline void CompressedMatrix<Type,true>::assign(
const SparseMatrix<MT,false>& rhs )
4497 std::vector<size_t> columnLengths( n_, 0UL );
4498 for(
size_t i=0UL; i<
m_; ++i ) {
4499 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
4500 ++columnLengths[element->index()];
4504 for(
size_t j=0UL; j<
n_; ++j ) {
4505 begin_[j+1UL] =
end_[j+1UL] = begin_[j] + columnLengths[j];
4509 for(
size_t i=0UL; i<
m_; ++i ) {
4510 for( RhsIterator element=(~rhs).
begin(i); element!=(~rhs).
end(i); ++element )
4511 append( i, element->index(), element->value() );
4530 template<
typename Type >
4531 template<
typename MT
4533 inline void CompressedMatrix<Type,true>::addAssign(
const DenseMatrix<MT,SO>& rhs )
4538 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
4557 template<
typename Type >
4558 template<
typename MT
4560 inline void CompressedMatrix<Type,true>::addAssign(
const SparseMatrix<MT,SO>& rhs )
4565 CompressedMatrix tmp(
serial( *
this + (~rhs) ) );
4584 template<
typename Type >
4585 template<
typename MT
4587 inline void CompressedMatrix<Type,true>::subAssign(
const DenseMatrix<MT,SO>& rhs )
4592 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
4611 template<
typename Type >
4612 template<
typename MT
4614 inline void CompressedMatrix<Type,true>::subAssign(
const SparseMatrix<MT,SO>& rhs )
4619 CompressedMatrix tmp(
serial( *
this - (~rhs) ) );
4641 template<
typename Type,
bool SO >
4642 inline void reset( CompressedMatrix<Type,SO>& m );
4644 template<
typename Type,
bool SO >
4645 inline void reset( CompressedMatrix<Type,SO>& m,
size_t i );
4647 template<
typename Type,
bool SO >
4648 inline void clear( CompressedMatrix<Type,SO>& m );
4650 template<
typename Type,
bool SO >
4651 inline bool isDefault(
const CompressedMatrix<Type,SO>& m );
4653 template<
typename Type,
bool SO >
4654 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) ;
4656 template<
typename Type,
bool SO >
4657 inline void move( CompressedMatrix<Type,SO>& dst, CompressedMatrix<Type,SO>& src ) ;
4669 template<
typename Type
4671 inline void reset( CompressedMatrix<Type,SO>& m )
4691 template<
typename Type
4693 inline void reset( CompressedMatrix<Type,SO>& m,
size_t i )
4707 template<
typename Type
4709 inline void clear( CompressedMatrix<Type,SO>& m )
4734 template<
typename Type
4738 return ( m.rows() == 0UL && m.columns() == 0UL );
4752 template<
typename Type
4754 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b )
4770 template<
typename Type
4772 inline void move( CompressedMatrix<Type,SO>& dst, CompressedMatrix<Type,SO>& src )
4789 template<
typename T,
bool SO >
4790 struct IsResizable< CompressedMatrix<T,SO> > :
public TrueType
4809 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4810 struct AddTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4812 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4815 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4816 struct AddTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4818 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO2 > Type;
4821 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4822 struct AddTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4824 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4827 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4828 struct AddTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4830 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO1 > Type;
4833 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4834 struct AddTrait< CompressedMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4836 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4839 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4840 struct AddTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4842 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO2 > Type;
4845 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4846 struct AddTrait< HybridMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4848 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4851 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4852 struct AddTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4854 typedef HybridMatrix< typename AddTrait<T1,T2>::Type, M, N, SO1 > Type;
4857 template<
typename T1,
bool SO,
typename T2 >
4858 struct AddTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4860 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4863 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4864 struct AddTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4866 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO2 > Type;
4869 template<
typename T1,
bool SO,
typename T2 >
4870 struct AddTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4872 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4875 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4876 struct AddTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4878 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO1 > Type;
4881 template<
typename T1,
bool SO,
typename T2 >
4882 struct AddTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4884 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4887 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4888 struct AddTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4890 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4906 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4907 struct SubTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4909 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4912 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4913 struct SubTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4915 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO2 > Type;
4918 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4919 struct SubTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4921 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4924 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4925 struct SubTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4927 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO1 > Type;
4930 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4931 struct SubTrait< CompressedMatrix<T1,SO>, HybridMatrix<T2,M,N,SO> >
4933 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4936 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4937 struct SubTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
4939 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO2 > Type;
4942 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4943 struct SubTrait< HybridMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4945 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4948 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4949 struct SubTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4951 typedef HybridMatrix< typename SubTrait<T1,T2>::Type, M, N, SO1 > Type;
4954 template<
typename T1,
bool SO,
typename T2 >
4955 struct SubTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4957 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4960 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4961 struct SubTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4963 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO2 > Type;
4966 template<
typename T1,
bool SO,
typename T2 >
4967 struct SubTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4969 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4972 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4973 struct SubTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4975 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO1 > Type;
4978 template<
typename T1,
bool SO,
typename T2 >
4979 struct SubTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4981 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4984 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4985 struct SubTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4987 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
5003 template<
typename T1,
bool SO,
typename T2 >
5004 struct MultTrait< CompressedMatrix<T1,SO>, T2 >
5006 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
5010 template<
typename T1,
typename T2,
bool SO >
5011 struct MultTrait< T1, CompressedMatrix<T2,SO> >
5013 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
5017 template<
typename T1,
bool SO,
typename T2,
size_t N >
5018 struct MultTrait< CompressedMatrix<T1,SO>, StaticVector<T2,N,false> >
5020 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
5023 template<
typename T1,
size_t N,
typename T2,
bool SO >
5024 struct MultTrait< StaticVector<T1,N,true>, CompressedMatrix<T2,SO> >
5026 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
5029 template<
typename T1,
bool SO,
typename T2,
size_t N >
5030 struct MultTrait< CompressedMatrix<T1,SO>, HybridVector<T2,N,false> >
5032 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
5035 template<
typename T1,
size_t N,
typename T2,
bool SO >
5036 struct MultTrait< HybridVector<T1,N,true>, CompressedMatrix<T2,SO> >
5038 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
5041 template<
typename T1,
bool SO,
typename T2 >
5042 struct MultTrait< CompressedMatrix<T1,SO>, DynamicVector<T2,false> >
5044 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
5047 template<
typename T1,
typename T2,
bool SO >
5048 struct MultTrait< DynamicVector<T1,true>, CompressedMatrix<T2,SO> >
5050 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
5053 template<
typename T1,
bool SO,
typename T2 >
5054 struct MultTrait< CompressedMatrix<T1,SO>, CompressedVector<T2,false> >
5056 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
false > Type;
5059 template<
typename T1,
typename T2,
bool SO >
5060 struct MultTrait< CompressedVector<T1,true>, CompressedMatrix<T2,SO> >
5062 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
true > Type;
5065 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
5066 struct MultTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
5068 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5071 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5072 struct MultTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
5074 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5077 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
5078 struct MultTrait< CompressedMatrix<T1,SO1>, HybridMatrix<T2,M,N,SO2> >
5080 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5083 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
5084 struct MultTrait< HybridMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
5086 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5089 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
5090 struct MultTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
5092 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5095 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
5096 struct MultTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
5098 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5101 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
5102 struct MultTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
5104 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
5120 template<
typename T1,
bool SO,
typename T2 >
5121 struct DivTrait< CompressedMatrix<T1,SO>, T2 >
5123 typedef CompressedMatrix< typename DivTrait<T1,T2>::Type, SO > Type;
5140 template<
typename T1,
bool SO,
typename T2 >
5141 struct MathTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
5143 typedef CompressedMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
5144 typedef CompressedMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
5160 template<
typename T1,
bool SO >
5161 struct SubmatrixTrait< CompressedMatrix<T1,SO> >
5163 typedef CompressedMatrix<T1,SO> Type;
5179 template<
typename T1,
bool SO >
5180 struct RowTrait< CompressedMatrix<T1,SO> >
5182 typedef CompressedVector<T1,true> Type;
5198 template<
typename T1,
bool SO >
5199 struct ColumnTrait< CompressedMatrix<T1,SO> >
5201 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.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:994
size_t rows() const
Returns the current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:1130
void reserveElements(size_t nonzeros)
Reserving the specified number of sparse matrix elements.
Definition: CompressedMatrix.h:1826
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:421
Header file for mathematical functions.
void swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
#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:260
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:261
const bool defaultStorageOrder
The default storage order for all matrices of the Blaze library.This value specifies the default stor...
Definition: StorageOrder.h:56
void move(CompressedMatrix< Type, SO > &dst, CompressedMatrix< Type, SO > &src)
Moving the contents of one compressed matrix to another.
Definition: CompressedMatrix.h:4772
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
Header file for the row trait.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:465
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
size_t extendCapacity() const
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1806
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2636
void clear()
Clearing the sparse matrix.
Definition: CompressedMatrix.h:1271
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:257
BLAZE_ALWAYS_INLINE size_t rows(const Matrix< MT, SO > &matrix)
Returns the current number of rows of the matrix.
Definition: Matrix.h:316
void clear(CompressedMatrix< Type, SO > &m)
Clearing the given compressed matrix.
Definition: CompressedMatrix.h:4709
CompressedMatrix< ET, SO > Other
The type of the other CompressedMatrix.
Definition: CompressedMatrix.h:271
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2472
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:255
#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:651
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
void reset(CompressedMatrix< Type, SO > &m)
Resetting the given compressed matrix.
Definition: CompressedMatrix.h:4671
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:95
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:2149
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:423
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:258
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:1193
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2638
Header file for the SparseMatrix base class.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:419
void reserve(size_t nonzeros)
Setting the minimum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1597
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1233
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:259
Header file for the ValueIndexPair class.
bool isDefault(const CompressedMatrix< Type, SO > &m)
Returns whether the given compressed matrix is in default state.
Definition: CompressedMatrix.h:4736
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 compressed matrices.
Definition: CompressedMatrix.h:4754
Iterator set(size_t i, size_t j, const Type &value)
Setting an element of the compressed matrix.
Definition: CompressedMatrix.h:1295
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:2482
#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:1430
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2640
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:947
BLAZE_ALWAYS_INLINE 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:635
EnableIf< IsBuiltin< T > >::Type deallocate(T *address)
Deallocation of memory for built-in data types.
Definition: Memory.h:226
#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:209
Constraint on the data type.
Header file for the equal shim.
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 compressed matrix.
Definition: CompressedMatrix.h:1327
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
CompressedMatrix< ET, true > Other
The type of the other CompressedMatrix.
Definition: CompressedMatrix.h:2490
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
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:535
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
void subAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: CompressedMatrix.h:2366
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:1785
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:263
bool canSMPAssign() const
Returns whether the matrix can be used in SMP assignments.
Definition: CompressedMatrix.h:2168
size_t capacity() const
Returns the maximum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1158
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the sparse matrix.
Definition: CompressedMatrix.h:1516
Header file for the IsNumeric type trait.
CompressedMatrix & operator=(const CompressedMatrix &rhs)
Copy assignment operator for CompressedMatrix.
Definition: CompressedMatrix.h:864
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
Reference operator()(size_t i, size_t j)
2D-access to the sparse matrix elements.
Definition: CompressedMatrix.h:677
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:792
CompressedMatrix & transpose()
Transposing the matrix.
Definition: CompressedMatrix.h:1723
BLAZE_ALWAYS_INLINE 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:742
Header file for the division trait.
void trim()
Removing all excessive capacity from all rows/columns.
Definition: CompressedMatrix.h:1684
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
#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:2481
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
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
size_t columns() const
Returns the current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:1144
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:254
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2639
void assign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the assignment of a row-major dense matrix.
Definition: CompressedMatrix.h:2190
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:262
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:2065
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2097
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: CompressedMatrix.h:2129
Base template for the DivTrait class.
Definition: DivTrait.h:142
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:253
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:1875
Header file for the mathematical trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:420
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2637
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
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:2314
const DMatTransExpr< MT,!SO > trans(const DenseMatrix< MT, SO > &dm)
Calculation of the transpose of the given dense matrix.
Definition: DMatTransExpr.h:932
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:256
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less then the given index.
Definition: CompressedMatrix.h:1928
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2642
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: CompressedMatrix.h:1979
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix)
Returns the current number of columns of the matrix.
Definition: Matrix.h:332
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:770
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:270
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:2489
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:418
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:836
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:417
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Iterator begin(size_t i)
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:726
BLAZE_ALWAYS_INLINE 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:849
Header file for a safe C++ NULL pointer implementation.