35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDMATRIX_H_
194 template<
typename Type
211 template<
typename Other >
212 inline Element&
operator=(
const Other& rhs )
214 ElementBase::operator=( rhs );
227 struct FindIndex :
public std::binary_function<Element,size_t,bool>
229 inline bool operator()(
const Element& element,
size_t index )
const {
230 return element.index() < index;
232 inline bool operator()(
size_t index,
const Element& element )
const {
233 return index < element.index();
235 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
236 return element1.index() < element2.index();
263 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
301 template<
typename Other >
303 operator*=( Other rhs );
305 template<
typename Other >
307 operator/=( Other rhs );
314 inline size_t rows()
const;
317 inline size_t capacity(
size_t i )
const;
319 inline size_t nonZeros(
size_t i )
const;
321 inline void reset(
size_t i );
324 inline void erase (
size_t i,
size_t j );
327 void resize (
size_t m,
size_t n,
bool preserve=
true );
328 inline void reserve(
size_t nonzeros );
329 void reserve(
size_t i,
size_t nonzeros );
331 inline void trim (
size_t i );
334 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
354 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
362 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
363 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
417 template<
typename Type,
bool SO >
432 template<
typename Type
454 template<
typename Type
463 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
478 template<
typename Type
487 begin_[0UL] =
new Element[nonzeros];
488 for(
size_t i=1UL; i<(2UL*
m_+1UL); ++i )
504 template<
typename Type
513 BLAZE_USER_ASSERT( nonzeros.size() == m,
"Size of capacity vector and number of rows don't match" );
515 size_t newCapacity( 0UL );
516 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
519 begin_[0UL] =
end_[0UL] =
new Element[newCapacity];
520 for(
size_t i=0UL; i<
m_; ++i ) {
532 template<
typename Type
541 const size_t nonzeros( sm.
nonZeros() );
543 begin_[0UL] =
new Element[nonzeros];
544 for(
size_t i=0UL; i<
m_; ++i )
545 begin_[i+1UL] =
end_[i] = std::copy( sm.
begin(i), sm.
end(i), begin_[i] );
546 end_[
m_] = begin_[0UL]+nonzeros;
556 template<
typename Type
558 template<
typename MT
569 for(
size_t i=0UL; i<2UL*
m_+2UL; ++i )
582 template<
typename Type
584 template<
typename MT
595 const size_t nonzeros( (~sm).
nonZeros() );
597 begin_[0UL] =
new Element[nonzeros];
598 for(
size_t i=0UL; i<
m_; ++i )
618 template<
typename Type
643 template<
typename Type
663 template<
typename Type
673 if( pos ==
end_[i] || pos->index_ != j )
692 template<
typename Type
714 template<
typename Type
736 template<
typename Type
758 template<
typename Type
780 template<
typename Type
802 template<
typename Type
830 template<
typename Type
835 if( &rhs ==
this )
return *
this;
837 const size_t nonzeros( rhs.
nonZeros() );
844 newBegin[0UL] =
new Element[nonzeros];
845 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
846 newBegin[i+1UL] = newEnd[i] = std::copy( rhs.
begin_[i], rhs.
end_[i], newBegin[i] );
848 newEnd[rhs.
m_] = newBegin[0UL]+nonzeros;
852 delete [] newBegin[0UL];
857 for(
size_t i=0UL; i<rhs.
m_; ++i ) {
879 template<
typename Type
881 template<
typename MT
888 if( (~rhs).canAlias(
this ) ) {
911 template<
typename Type
913 template<
typename MT
920 if( (~rhs).canAlias(
this ) ||
922 (~rhs).nonZeros() > capacity() ) {
947 template<
typename Type
949 template<
typename MT
957 throw std::invalid_argument(
"Matrix sizes do not match" );
975 template<
typename Type
977 template<
typename MT
984 throw std::invalid_argument(
"Matrix sizes do not match" );
1002 template<
typename Type
1004 template<
typename MT
1009 if( (~rhs).
rows() !=
n_ )
1010 throw std::invalid_argument(
"Matrix sizes do not match" );
1027 template<
typename Type
1029 template<
typename Other >
1033 for(
size_t i=0UL; i<
m_; ++i ) {
1035 for(
Iterator element=begin(i); element!=last; ++element )
1036 element->value_ *= rhs;
1051 template<
typename Type
1053 template<
typename Other >
1065 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1066 for(
size_t i=0UL; i<
m_; ++i ) {
1068 for(
Iterator element=begin(i); element!=last; ++element )
1069 element->value_ *= tmp;
1073 for(
size_t i=0UL; i<
m_; ++i ) {
1075 for(
Iterator element=begin(i); element!=last; ++element )
1076 element->value_ /= rhs;
1098 template<
typename Type
1112 template<
typename Type
1126 template<
typename Type
1146 template<
typename Type
1161 template<
typename Type
1165 size_t nonzeros( 0UL );
1167 for(
size_t i=0UL; i<
m_; ++i )
1168 nonzeros += nonZeros( i );
1186 template<
typename Type
1201 template<
typename Type
1205 for(
size_t i=0UL; i<
m_; ++i )
1222 template<
typename Type
1239 template<
typename Type
1263 template<
typename Type
1271 const Iterator pos( lowerBound( i, j ) );
1273 if( pos !=
end_[i] && pos->index_ == j )
1274 throw std::invalid_argument(
"Bad access index" );
1277 std::copy_backward( pos,
end_[i],
end_[i]+1 );
1278 pos->value_ = value;
1285 std::copy_backward( pos,
end_[
m_-1UL],
end_[
m_-1UL]+1 );
1287 pos->value_ = value;
1290 for(
size_t k=i+1UL; k<
m_+1UL; ++k ) {
1298 size_t newCapacity( extendCapacity() );
1303 newBegin[0UL] =
new Element[newCapacity];
1305 for(
size_t k=0UL; k<i; ++k ) {
1306 const size_t nonzeros(
end_[k] -
begin_[k] );
1308 newEnd [k] = newBegin[k] + nonzeros;
1309 newBegin[k+1UL] = newBegin[k] + total;
1311 newEnd [i] = newBegin[i] + (
end_[i] -
begin_[i] ) + 1;
1312 newBegin[i+1UL] = newBegin[i] + (
begin_[i+1] -
begin_[i] ) + 1;
1313 for(
size_t k=i+1UL; k<
m_; ++k ) {
1314 const size_t nonzeros(
end_[k] -
begin_[k] );
1316 newEnd [k] = newBegin[k] + nonzeros;
1317 newBegin[k+1UL] = newBegin[k] + total;
1320 newEnd[
m_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
1323 tmp->value_ = value;
1325 std::copy( pos,
end_[m_-1UL], tmp+1UL );
1329 delete [] newBegin[0UL];
1347 template<
typename Type
1354 const Iterator pos( find( i, j ) );
1355 if( pos !=
end_[i] )
1356 end_[i] = std::copy( pos+1,
end_[i], pos );
1372 template<
typename Type
1380 if( pos !=
end_[i] )
1381 end_[i] = std::copy( pos+1,
end_[i], pos );
1400 template<
typename Type
1411 end_[i] = std::copy( last,
end_[i], first );
1432 template<
typename Type
1439 if( m ==
m_ && n ==
n_ )
return;
1444 Iterator* newEnd ( newBegin+m+1UL );
1446 newBegin[0UL] =
begin_[0UL];
1449 for(
size_t i=0UL; i<
m_; ++i ) {
1450 newEnd [i] =
end_ [i];
1451 newBegin[i+1UL] =
begin_[i+1UL];
1453 for(
size_t i=m_; i<m; ++i ) {
1454 newBegin[i+1UL] = newEnd[i] =
begin_[
m_];
1458 for(
size_t i=0UL; i<m; ++i ) {
1459 newBegin[i+1UL] = newEnd[i] =
begin_[0UL];
1476 for(
size_t i=0UL; i<
m_; ++i )
1480 for(
size_t i=
m_; i<m; ++i )
1486 for(
size_t i=0UL; i<m; ++i )
1487 end_[i] = lowerBound( i, n );
1490 for(
size_t i=0UL; i<m; ++i )
1513 template<
typename Type
1517 if( nonzeros > capacity() )
1518 reserveElements( nonzeros );
1537 template<
typename Type
1543 const size_t current( capacity(i) );
1545 if( current >= nonzeros )
return;
1547 const ptrdiff_t additional( nonzeros - current );
1551 const size_t newCapacity(
begin_[
m_] -
begin_[0UL] + additional );
1557 newBegin[0UL] =
new Element[newCapacity];
1558 newEnd [
m_ ] = newBegin[0UL]+newCapacity;
1560 for(
size_t k=0UL; k<i; ++k ) {
1561 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1562 newBegin[k+1UL] = newBegin[k] + capacity(k);
1564 newEnd [i ] = std::copy(
begin_[i],
end_[i], newBegin[i] );
1565 newBegin[i+1UL] = newBegin[i] + nonzeros;
1566 for(
size_t k=i+1UL; k<
m_; ++k ) {
1567 newEnd [k ] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1568 newBegin[k+1UL] = newBegin[k] + capacity(k);
1574 delete [] newBegin[0UL];
1581 for(
size_t j=
m_-1UL; j>i; --j ) {
1583 end_ [j] += additional;
1600 template<
typename Type
1604 for(
size_t i=0UL; i<
m_; ++i )
1621 template<
typename Type
1627 if( i < (
m_ - 1UL ) )
1639 template<
typename Type
1656 template<
typename Type
1658 template<
typename Other >
1661 for(
size_t i=0UL; i<
m_; ++i )
1663 element->value_ *= scalar;
1676 template<
typename Type
1678 template<
typename Other >
1683 for(
size_t i=0UL; i<size; ++i ) {
1685 if( pos !=
end_[i] && pos->index_ == i )
1686 pos->value_ *= scalar;
1701 template<
typename Type
1722 template<
typename Type
1726 size_t nonzeros( 2UL*capacity()+1UL );
1742 template<
typename Type
1749 newBegin[0UL] =
new Element[nonzeros];
1751 for(
size_t k=0UL; k<
m_; ++k ) {
1753 newEnd [k] = std::copy(
begin_[k],
end_[k], newBegin[k] );
1754 newBegin[k+1UL] = newBegin[k] + (
begin_[k+1UL] -
begin_[k] );
1757 newEnd[
m_] = newBegin[0UL]+nonzeros;
1760 delete [] newBegin[0UL];
1790 template<
typename Type
1795 return const_cast<Iterator>(
const_cast<const This&
>( *this ).
find( i, j ) );
1815 template<
typename Type
1821 if( pos !=
end_[i] && pos->index_ == j )
1823 else return end_[i];
1843 template<
typename Type
1868 template<
typename Type
1874 return std::lower_bound(
begin_[i],
end_[i], j, FindIndex() );
1894 template<
typename Type
1919 template<
typename Type
1925 return std::upper_bound(
begin_[i],
end_[i], j, FindIndex() );
1981 template<
typename Type
1990 end_[i]->value_ = value;
1993 end_[i]->index_ = j;
2013 template<
typename Type
2044 template<
typename Type
2046 template<
typename Other >
2049 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2064 template<
typename Type
2066 template<
typename Other >
2069 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
2085 template<
typename Type
2087 template<
typename MT
2094 size_t nonzeros( 0UL );
2096 for(
size_t i=1UL; i<=
m_; ++i )
2099 for(
size_t i=0UL; i<
m_; ++i )
2103 for(
size_t j=0UL; j<
n_; ++j )
2105 if( nonzeros == capacity() ) {
2106 reserveElements( extendCapacity() );
2107 for(
size_t k=i+1UL; k<=
m_; ++k )
2111 end_[i]->value_ = (~rhs)(i,j);
2114 end_[i]->index_ = j;
2137 template<
typename Type
2139 template<
typename MT >
2146 for(
size_t i=0UL; i<(~rhs).
rows(); ++i ) {
2147 begin_[i+1UL] =
end_[i] = std::copy( (~rhs).begin(i), (~rhs).end(i),
begin_[i] );
2164 template<
typename Type
2166 template<
typename MT >
2176 std::vector<size_t> rowLengths(
m_, 0UL );
2177 for(
size_t j=0UL; j<
n_; ++j ) {
2178 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2179 ++rowLengths[element->index()];
2183 for(
size_t i=0UL; i<
m_; ++i ) {
2188 for(
size_t j=0UL; j<
n_; ++j ) {
2189 for( RhsIterator element=(~rhs).begin(j); element!=(~rhs).end(j); ++element )
2190 append( element->index(), j, element->value() );
2207 template<
typename Type
2209 template<
typename MT
2233 template<
typename Type
2235 template<
typename MT
2259 template<
typename Type
2261 template<
typename MT
2285 template<
typename Type
2287 template<
typename MT
2320 template<
typename Type >
2336 template<
typename Other >
2337 inline Element&
operator=(
const Other& rhs )
2339 ElementBase::operator=( rhs );
2352 struct FindIndex :
public std::binary_function<Element,size_t,bool>
2354 inline bool operator()(
const Element& element,
size_t index )
const {
2355 return element.index() < index;
2357 inline bool operator()(
size_t index,
const Element& element )
const {
2358 return index < element.index();
2360 inline bool operator()(
const Element& element1,
const Element& element2 )
const {
2361 return element1.index() < element2.index();
2388 explicit CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros );
2426 template<
typename Other >
2428 operator*=( Other rhs );
2430 template<
typename Other >
2432 operator/=( Other rhs );
2439 inline size_t rows()
const;
2440 inline size_t columns()
const;
2442 inline size_t capacity(
size_t j )
const;
2444 inline size_t nonZeros(
size_t j )
const;
2445 inline void reset();
2446 inline void reset(
size_t j );
2447 inline void clear();
2449 inline void erase (
size_t i,
size_t j );
2452 void resize (
size_t m,
size_t n,
bool preserve=
true );
2453 inline void reserve(
size_t nonzeros );
2454 void reserve(
size_t j,
size_t nonzeros );
2455 inline void trim ();
2456 inline void trim (
size_t j );
2459 template<
typename Other >
inline CompressedMatrix& scaleDiagonal( Other scalar );
2479 inline void append (
size_t i,
size_t j,
const Type& value,
bool check=
false );
2487 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2488 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2543 template<
typename Type >
2559 template<
typename Type >
2582 template<
typename Type >
2583 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n )
2590 for(
size_t j=0UL; j<2UL*
n_+2UL; ++j )
2607 template<
typename Type >
2608 inline CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
size_t nonzeros )
2615 begin_[0UL] =
new Element[nonzeros];
2616 for(
size_t j=1UL; j<(2UL*
n_+1UL); ++j )
2634 template<
typename Type >
2635 CompressedMatrix<Type,true>::CompressedMatrix(
size_t m,
size_t n,
const std::vector<size_t>& nonzeros )
2642 BLAZE_USER_ASSERT( nonzeros.size() == n,
"Size of capacity vector and number of columns don't match" );
2644 size_t newCapacity( 0UL );
2645 for( std::vector<size_t>::const_iterator it=nonzeros.begin(); it!=nonzeros.end(); ++it )
2648 begin_[0UL] =
end_[0UL] =
new Element[newCapacity];
2649 for(
size_t j=0UL; j<
n_; ++j ) {
2663 template<
typename Type >
2664 inline CompressedMatrix<Type,true>::CompressedMatrix(
const CompressedMatrix& sm )
2671 const size_t nonzeros( sm.nonZeros() );
2673 begin_[0UL] =
new Element[nonzeros];
2674 for(
size_t j=0UL; j<
n_; ++j )
2675 begin_[j+1UL] =
end_[j] = std::copy( sm.begin(j), sm.end(j), begin_[j] );
2676 end_[
n_] = begin_[0UL]+nonzeros;
2688 template<
typename Type >
2689 template<
typename MT
2691 inline CompressedMatrix<Type,true>::CompressedMatrix(
const DenseMatrix<MT,SO>& dm )
2695 , begin_ ( new
Iterator[2UL*n_+2UL] )
2696 ,
end_ ( begin_+(n_+1UL) )
2700 for(
size_t j=0UL; j<2UL*n_+2UL; ++j )
2715 template<
typename Type >
2716 template<
typename MT
2718 inline CompressedMatrix<Type,true>::CompressedMatrix(
const SparseMatrix<MT,SO>& sm )
2722 , begin_ ( new
Iterator[2UL*n_+2UL] )
2723 ,
end_ ( begin_+(n_+1UL) )
2727 const size_t nonzeros( (~sm).nonZeros() );
2729 begin_[0UL] =
new Element[nonzeros];
2730 for(
size_t j=0UL; j<
n_; ++j )
2731 begin_[j+1UL] =
end_[j] = begin_[0UL];
2732 end_[
n_] = begin_[0UL]+nonzeros;
2752 template<
typename Type >
2753 inline CompressedMatrix<Type,true>::~CompressedMatrix()
2755 delete [] begin_[0UL];
2778 template<
typename Type >
2780 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
2799 template<
typename Type >
2801 CompressedMatrix<Type,true>::operator()(
size_t i,
size_t j )
const
2808 if( pos ==
end_[j] || pos->index_ != i )
2824 template<
typename Type >
2826 CompressedMatrix<Type,true>::begin(
size_t j )
2842 template<
typename Type >
2844 CompressedMatrix<Type,true>::begin(
size_t j )
const
2860 template<
typename Type >
2862 CompressedMatrix<Type,true>::cbegin(
size_t j )
const
2878 template<
typename Type >
2880 CompressedMatrix<Type,true>::end(
size_t j )
2896 template<
typename Type >
2898 CompressedMatrix<Type,true>::end(
size_t j )
const
2914 template<
typename Type >
2916 CompressedMatrix<Type,true>::cend(
size_t j )
const
2943 template<
typename Type >
2944 inline CompressedMatrix<Type,true>&
2945 CompressedMatrix<Type,true>::operator=(
const CompressedMatrix& rhs )
2947 if( &rhs ==
this )
return *
this;
2949 const size_t nonzeros( rhs.nonZeros() );
2951 if( rhs.n_ >
capacity_ || nonzeros > capacity() )
2954 Iterator* newEnd ( newBegin+(rhs.n_+1UL) );
2956 newBegin[0UL] =
new Element[nonzeros];
2957 for(
size_t j=0UL; j<rhs.n_; ++j ) {
2958 newBegin[j+1UL] = newEnd[j] = std::copy( rhs.begin_[j], rhs.end_[j], newBegin[j] );
2960 newEnd[rhs.n_] = newBegin[0UL]+nonzeros;
2964 delete [] newBegin[0UL];
2969 for(
size_t j=0UL; j<rhs.n_; ++j ) {
2970 begin_[j+1UL] =
end_[j] = std::copy( rhs.begin_[j], rhs.end_[j], begin_[j] );
2993 template<
typename Type >
2994 template<
typename MT
2996 inline CompressedMatrix<Type,true>&
2997 CompressedMatrix<Type,true>::operator=(
const DenseMatrix<MT,SO>& rhs )
3001 if( (~rhs).canAlias(
this ) ) {
3002 CompressedMatrix tmp( rhs );
3026 template<
typename Type >
3027 template<
typename MT
3029 inline CompressedMatrix<Type,true>&
3030 CompressedMatrix<Type,true>::operator=(
const SparseMatrix<MT,SO>& rhs )
3034 if( (~rhs).canAlias(
this ) ||
3036 (~rhs).nonZeros() > capacity() ) {
3037 CompressedMatrix tmp( rhs );
3063 template<
typename Type >
3064 template<
typename MT
3066 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator+=(
const Matrix<MT,SO>& rhs )
3071 throw std::invalid_argument(
"Matrix sizes do not match" );
3091 template<
typename Type >
3092 template<
typename MT
3094 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::operator-=(
const Matrix<MT,SO>& rhs )
3099 throw std::invalid_argument(
"Matrix sizes do not match" );
3119 template<
typename Type >
3120 template<
typename MT
3122 inline CompressedMatrix<Type,true>&
3123 CompressedMatrix<Type,true>::operator*=(
const Matrix<MT,SO>& rhs )
3125 if( (~rhs).
rows() != n_ )
3126 throw std::invalid_argument(
"Matrix sizes do not match" );
3128 CompressedMatrix tmp( *
this * (~rhs) );
3145 template<
typename Type >
3146 template<
typename Other >
3147 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3148 CompressedMatrix<Type,true>::operator*=( Other rhs )
3150 for(
size_t j=0UL; j<
n_; ++j ) {
3152 for(
Iterator element=begin(j); element!=last; ++element )
3153 element->value_ *= rhs;
3170 template<
typename Type >
3171 template<
typename Other >
3172 inline typename EnableIf< IsNumeric<Other>, CompressedMatrix<Type,true> >::Type&
3173 CompressedMatrix<Type,true>::operator/=( Other rhs )
3177 typedef typename DivTrait<Type,Other>::Type DT;
3178 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3182 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3183 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3184 for(
size_t j=0UL; j<
n_; ++j ) {
3186 for(
Iterator element=begin(j); element!=last; ++element )
3187 element->value_ *= tmp;
3191 for(
size_t j=0UL; j<
n_; ++j ) {
3193 for(
Iterator element=begin(j); element!=last; ++element )
3194 element->value_ /= rhs;
3218 template<
typename Type >
3233 template<
typename Type >
3248 template<
typename Type >
3249 inline size_t CompressedMatrix<Type,true>::capacity()
const
3251 return end_[
n_] - begin_[0UL];
3264 template<
typename Type >
3265 inline size_t CompressedMatrix<Type,true>::capacity(
size_t j )
const
3268 return begin_[j+1UL] - begin_[j];
3280 template<
typename Type >
3281 inline size_t CompressedMatrix<Type,true>::nonZeros()
const
3283 size_t nonzeros( 0UL );
3285 for(
size_t j=0UL; j<
n_; ++j )
3286 nonzeros += nonZeros( j );
3301 template<
typename Type >
3302 inline size_t CompressedMatrix<Type,true>::nonZeros(
size_t j )
const
3305 return end_[j] - begin_[j];
3317 template<
typename Type >
3320 for(
size_t j=0UL; j<
n_; ++j )
3321 end_[j] = begin_[j];
3337 template<
typename Type >
3341 end_[j] = begin_[j];
3355 template<
typename Type >
3380 template<
typename Type >
3382 CompressedMatrix<Type,true>::insert(
size_t i,
size_t j,
const Type& value )
3387 const Iterator pos( lowerBound( i, j ) );
3389 if( pos !=
end_[j] && pos->index_ == i )
3390 throw std::invalid_argument(
"Bad access index" );
3392 if( begin_[j+1UL] -
end_[j] != 0 ) {
3393 std::copy_backward( pos,
end_[j],
end_[j]+1 );
3394 pos->value_ = value;
3400 else if(
end_[n_] - begin_[n_] != 0 ) {
3401 std::copy_backward( pos,
end_[n_-1UL],
end_[n_-1]+1 );
3403 pos->value_ = value;
3406 for(
size_t k=j+1UL; k<n_+1UL; ++k ) {
3414 size_t newCapacity( extendCapacity() );
3419 newBegin[0UL] =
new Element[newCapacity];
3421 for(
size_t k=0UL; k<j; ++k ) {
3422 const size_t nonzeros(
end_[k] - begin_[k] );
3423 const size_t total( begin_[k+1UL] - begin_[k] );
3424 newEnd [k] = newBegin[k] + nonzeros;
3425 newBegin[k+1UL] = newBegin[k] + total;
3427 newEnd [j] = newBegin[j] + (
end_[j] - begin_[j] ) + 1;
3428 newBegin[j+1UL] = newBegin[j] + ( begin_[j+1UL] - begin_[j] ) + 1;
3429 for(
size_t k=j+1UL; k<
n_; ++k ) {
3430 const size_t nonzeros(
end_[k] - begin_[k] );
3431 const size_t total( begin_[k+1UL] - begin_[k] );
3432 newEnd [k] = newBegin[k] + nonzeros;
3433 newBegin[k+1UL] = newBegin[k] + total;
3436 newEnd[
n_] = newEnd[
capacity_] = newBegin[0UL]+newCapacity;
3438 Iterator tmp = std::copy( begin_[0UL], pos, newBegin[0UL] );
3439 tmp->value_ = value;
3441 std::copy( pos,
end_[n_-1UL], tmp+1UL );
3445 delete [] newBegin[0UL];
3465 template<
typename Type >
3466 inline void CompressedMatrix<Type,true>::erase(
size_t i,
size_t j )
3471 const Iterator pos( find( i, j ) );
3472 if( pos !=
end_[j] )
3473 end_[j] = std::copy( pos+1,
end_[j], pos );
3489 template<
typename Type >
3491 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator pos )
3496 if( pos !=
end_[j] )
3497 end_[j] = std::copy( pos+1,
end_[j], pos );
3516 template<
typename Type >
3518 CompressedMatrix<Type,true>::erase(
size_t j,
Iterator first,
Iterator last )
3526 end_[j] = std::copy( last,
end_[j], first );
3549 template<
typename Type >
3550 void CompressedMatrix<Type,true>::resize(
size_t m,
size_t n,
bool preserve )
3555 if( m ==
m_ && n == n_ )
return;
3560 Iterator* newEnd ( newBegin+n+1UL );
3562 newBegin[0UL] = begin_[0UL];
3565 for(
size_t j=0UL; j<
n_; ++j ) {
3566 newEnd [j] =
end_ [j];
3567 newBegin[j+1UL] = begin_[j+1UL];
3569 for(
size_t j=n_; j<n; ++j ) {
3570 newBegin[j+1UL] = newEnd[j] = begin_[
n_];
3574 for(
size_t j=0UL; j<n; ++j ) {
3575 newBegin[j+1UL] = newEnd[j] = begin_[0UL];
3592 for(
size_t j=0UL; j<
n_; ++j )
3593 end_[j] = begin_[j];
3596 for(
size_t j=n_; j<n; ++j )
3597 begin_[j+1UL] =
end_[j] = begin_[n_];
3602 for(
size_t j=0UL; j<n; ++j )
3603 end_[j] = lowerBound( m, j );
3606 for(
size_t j=0UL; j<n; ++j )
3607 end_[j] = begin_[j];
3631 template<
typename Type >
3632 inline void CompressedMatrix<Type,true>::reserve(
size_t nonzeros )
3634 if( nonzeros > capacity() )
3635 reserveElements( nonzeros );
3653 template<
typename Type >
3654 void CompressedMatrix<Type,true>::reserve(
size_t j,
size_t nonzeros )
3658 const size_t current( capacity(j) );
3660 if( current >= nonzeros )
return;
3662 const ptrdiff_t additional( nonzeros - current );
3664 if(
end_[n_] - begin_[n_] < additional )
3666 const size_t newCapacity( begin_[n_] - begin_[0UL] + additional );
3670 Iterator* newEnd ( newBegin+n_+1UL );
3672 newBegin[0UL] =
new Element[newCapacity];
3673 newEnd [
n_ ] = newBegin[0UL]+newCapacity;
3675 for(
size_t k=0UL; k<j; ++k ) {
3676 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3677 newBegin[k+1UL] = newBegin[k] + capacity(k);
3679 newEnd [j ] = std::copy( begin_[j],
end_[j], newBegin[j] );
3680 newBegin[j+1UL] = newBegin[j] + nonzeros;
3681 for(
size_t k=j+1UL; k<
n_; ++k ) {
3682 newEnd [k ] = std::copy( begin_[k],
end_[k], newBegin[k] );
3683 newBegin[k+1UL] = newBegin[k] + capacity(k);
3689 delete [] newBegin[0UL];
3695 begin_[
n_] += additional;
3696 for(
size_t k=n_-1UL; k>j; --k ) {
3697 begin_[k] = std::copy_backward( begin_[k],
end_[k],
end_[k]+additional );
3698 end_ [k] += additional;
3716 template<
typename Type >
3717 void CompressedMatrix<Type,true>::trim()
3719 for(
size_t j=0UL; j<
n_; ++j )
3737 template<
typename Type >
3738 void CompressedMatrix<Type,true>::trim(
size_t j )
3742 if( j < ( n_ - 1UL ) )
3743 end_[j+1] = std::copy( begin_[j+1],
end_[j+1],
end_[j] );
3744 begin_[j+1] =
end_[j];
3756 template<
typename Type >
3757 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::transpose()
3759 CompressedMatrix tmp(
trans( *
this ) );
3774 template<
typename Type >
3775 template<
typename Other >
3776 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scale( Other scalar )
3778 for(
size_t j=0UL; j<
n_; ++j )
3779 for(
Iterator element=begin_[j]; element!=
end_[j]; ++element )
3780 element->value_ *= scalar;
3795 template<
typename Type >
3796 template<
typename Other >
3797 inline CompressedMatrix<Type,true>& CompressedMatrix<Type,true>::scaleDiagonal( Other scalar )
3799 const size_t size( blaze::min(
m_, n_ ) );
3801 for(
size_t j=0UL; j<size; ++j ) {
3803 if( pos !=
end_[j] && pos->index_ == j )
3804 pos->value_ *= scalar;
3821 template<
typename Type >
3843 template<
typename Type >
3844 inline size_t CompressedMatrix<Type,true>::extendCapacity()
const
3846 size_t nonzeros( 2UL*capacity()+1UL );
3864 template<
typename Type >
3865 void CompressedMatrix<Type,true>::reserveElements(
size_t nonzeros )
3870 newBegin[0UL] =
new Element[nonzeros];
3872 for(
size_t k=0UL; k<
n_; ++k ) {
3874 newEnd [k] = std::copy( begin_[k],
end_[k], newBegin[k] );
3875 newBegin[k+1UL] = newBegin[k] + ( begin_[k+1UL] - begin_[k] );
3878 newEnd[
n_] = newBegin[0UL]+nonzeros;
3881 delete [] newBegin[0UL];
3912 template<
typename Type >
3914 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
3916 return const_cast<Iterator>(
const_cast<const This&
>( *this ).find( i, j ) );
3937 template<
typename Type >
3939 CompressedMatrix<Type,true>::find(
size_t i,
size_t j )
const
3942 if( pos !=
end_[j] && pos->index_ == i )
3944 else return end_[j];
3964 template<
typename Type >
3966 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
3968 return const_cast<Iterator>(
const_cast<const This&
>( *this ).lowerBound( i, j ) );
3988 template<
typename Type >
3990 CompressedMatrix<Type,true>::lowerBound(
size_t i,
size_t j )
const
3993 return std::lower_bound( begin_[j],
end_[j], i, FindIndex() );
4013 template<
typename Type >
4015 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
4017 return const_cast<Iterator>(
const_cast<const This&
>( *this ).upperBound( i, j ) );
4037 template<
typename Type >
4039 CompressedMatrix<Type,true>::upperBound(
size_t i,
size_t j )
const
4042 return std::upper_bound( begin_[j],
end_[j], i, FindIndex() );
4097 template<
typename Type >
4098 inline void CompressedMatrix<Type,true>::append(
size_t i,
size_t j,
const Type& value,
bool check )
4105 end_[j]->value_ = value;
4108 end_[j]->index_ = i;
4130 template<
typename Type >
4131 inline void CompressedMatrix<Type,true>::finalize(
size_t j )
4135 begin_[j+1UL] =
end_[j];
4162 template<
typename Type >
4163 template<
typename Other >
4164 inline bool CompressedMatrix<Type,true>::canAlias(
const Other* alias )
const
4166 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4183 template<
typename Type >
4184 template<
typename Other >
4185 inline bool CompressedMatrix<Type,true>::isAliased(
const Other* alias )
const
4187 return static_cast<const void*
>( this ) == static_cast<const void*>( alias );
4205 template<
typename Type >
4206 template<
typename MT
4213 size_t nonzeros( 0UL );
4215 for(
size_t j=1UL; j<=
n_; ++j )
4218 for(
size_t j=0UL; j<
n_; ++j )
4220 begin_[j] =
end_[j] = begin_[0UL]+nonzeros;
4222 for(
size_t i=0UL; i<
m_; ++i )
4224 if( nonzeros == capacity() ) {
4225 reserveElements( extendCapacity() );
4226 for(
size_t k=j+1UL; k<=
n_; ++k )
4230 end_[j]->value_ = (~rhs)(i,j);
4233 end_[j]->index_ = i;
4240 begin_[
n_] = begin_[0UL]+nonzeros;
4258 template<
typename Type >
4259 template<
typename MT >
4266 for(
size_t j=0UL; j<(~rhs).
columns(); ++j ) {
4267 begin_[j+1UL] =
end_[j] = std::copy( (~rhs).begin(j), (~rhs).end(j), begin_[j] );
4286 template<
typename Type >
4287 template<
typename MT >
4297 std::vector<size_t> columnLengths( n_, 0UL );
4298 for(
size_t i=0UL; i<
m_; ++i ) {
4299 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4300 ++columnLengths[element->index()];
4304 for(
size_t j=0UL; j<
n_; ++j ) {
4305 begin_[j+1UL] =
end_[j+1UL] = begin_[j] + columnLengths[j];
4309 for(
size_t i=0UL; i<
m_; ++i ) {
4310 for( RhsIterator element=(~rhs).begin(i); element!=(~rhs).end(i); ++element )
4311 append( i, element->index(), element->value() );
4330 template<
typename Type >
4331 template<
typename MT
4338 CompressedMatrix tmp( *
this + (~rhs) );
4357 template<
typename Type >
4358 template<
typename MT
4365 CompressedMatrix tmp( *
this + (~rhs) );
4384 template<
typename Type >
4385 template<
typename MT
4392 CompressedMatrix tmp( *
this - (~rhs) );
4411 template<
typename Type >
4412 template<
typename MT
4419 CompressedMatrix tmp( *
this - (~rhs) );
4441 template<
typename Type,
bool SO >
4442 inline void reset( CompressedMatrix<Type,SO>& m );
4444 template<
typename Type,
bool SO >
4445 inline void clear( CompressedMatrix<Type,SO>& m );
4447 template<
typename Type,
bool SO >
4448 inline bool isDefault(
const CompressedMatrix<Type,SO>& m );
4450 template<
typename Type,
bool SO >
4451 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b ) ;
4463 template<
typename Type
4465 inline void reset( CompressedMatrix<Type,SO>& m )
4479 template<
typename Type
4481 inline void clear( CompressedMatrix<Type,SO>& m )
4506 template<
typename Type
4513 for(
size_t i=0UL; i<m.rows(); ++i ) {
4514 for( ConstIterator element=m.begin(i); element!=m.end(i); ++element )
4515 if( !
isDefault( element->value() ) )
return false;
4519 for(
size_t j=0UL; j<m.columns(); ++j ) {
4520 for( ConstIterator element=m.begin(j); element!=m.end(j); ++element )
4521 if( !
isDefault( element->value() ) )
return false;
4539 template<
typename Type
4541 inline void swap( CompressedMatrix<Type,SO>& a, CompressedMatrix<Type,SO>& b )
4558 template<
typename T,
bool SO >
4559 struct IsResizable< CompressedMatrix<T,SO> > :
public TrueType
4565 template<
typename T,
bool SO >
4566 struct IsResizable< const CompressedMatrix<T,SO> > :
public TrueType
4572 template<
typename T,
bool SO >
4573 struct IsResizable< volatile CompressedMatrix<T,SO> > :
public TrueType
4579 template<
typename T,
bool SO >
4580 struct IsResizable< const volatile CompressedMatrix<T,SO> > :
public TrueType
4599 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4600 struct AddTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4602 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4605 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4606 struct AddTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4608 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4611 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4612 struct AddTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4614 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N, SO > Type;
4617 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4618 struct AddTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4620 typedef StaticMatrix< typename AddTrait<T1,T2>::Type, M, N,
false > Type;
4623 template<
typename T1,
bool SO,
typename T2 >
4624 struct AddTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4626 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4629 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4630 struct AddTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4632 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4635 template<
typename T1,
bool SO,
typename T2 >
4636 struct AddTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4638 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4641 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4642 struct AddTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4644 typedef DynamicMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4647 template<
typename T1,
bool SO,
typename T2 >
4648 struct AddTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4650 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type , SO > Type;
4653 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4654 struct AddTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4656 typedef CompressedMatrix< typename AddTrait<T1,T2>::Type ,
false > Type;
4672 template<
typename T1,
bool SO,
typename T2,
size_t M,
size_t N >
4673 struct SubTrait< CompressedMatrix<T1,SO>, StaticMatrix<T2,M,N,SO> >
4675 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4678 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4679 struct SubTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4681 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4684 template<
typename T1,
size_t M,
size_t N,
bool SO,
typename T2 >
4685 struct SubTrait< StaticMatrix<T1,M,N,SO>, CompressedMatrix<T2,SO> >
4687 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N, SO > Type;
4690 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4691 struct SubTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4693 typedef StaticMatrix< typename SubTrait<T1,T2>::Type, M, N,
false > Type;
4696 template<
typename T1,
bool SO,
typename T2 >
4697 struct SubTrait< CompressedMatrix<T1,SO>, DynamicMatrix<T2,SO> >
4699 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4702 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4703 struct SubTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4705 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4708 template<
typename T1,
bool SO,
typename T2 >
4709 struct SubTrait< DynamicMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4711 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4714 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4715 struct SubTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4717 typedef DynamicMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4720 template<
typename T1,
bool SO,
typename T2 >
4721 struct SubTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4723 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type , SO > Type;
4726 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4727 struct SubTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4729 typedef CompressedMatrix< typename SubTrait<T1,T2>::Type ,
false > Type;
4745 template<
typename T1,
bool SO,
typename T2 >
4746 struct MultTrait< CompressedMatrix<T1,SO>, T2 >
4748 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4752 template<
typename T1,
typename T2,
bool SO >
4753 struct MultTrait< T1, CompressedMatrix<T2,SO> >
4755 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO > Type;
4759 template<
typename T1,
bool SO,
typename T2,
size_t N >
4760 struct MultTrait< CompressedMatrix<T1,SO>, StaticVector<T2,N,false> >
4762 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4765 template<
typename T1,
size_t N,
typename T2,
bool SO >
4766 struct MultTrait< StaticVector<T1,N,true>, CompressedMatrix<T2,SO> >
4768 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4771 template<
typename T1,
bool SO,
typename T2,
size_t N >
4772 struct MultTrait< CompressedMatrix<T1,SO>, HybridVector<T2,N,false> >
4774 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4777 template<
typename T1,
size_t N,
typename T2,
bool SO >
4778 struct MultTrait< HybridVector<T1,N,true>, CompressedMatrix<T2,SO> >
4780 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4783 template<
typename T1,
bool SO,
typename T2 >
4784 struct MultTrait< CompressedMatrix<T1,SO>, DynamicVector<T2,false> >
4786 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
false > Type;
4789 template<
typename T1,
typename T2,
bool SO >
4790 struct MultTrait< DynamicVector<T1,true>, CompressedMatrix<T2,SO> >
4792 typedef DynamicVector< typename MultTrait<T1,T2>::Type,
true > Type;
4795 template<
typename T1,
bool SO,
typename T2 >
4796 struct MultTrait< CompressedMatrix<T1,SO>, CompressedVector<T2,false> >
4798 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
false > Type;
4801 template<
typename T1,
typename T2,
bool SO >
4802 struct MultTrait< CompressedVector<T1,true>, CompressedMatrix<T2,SO> >
4804 typedef CompressedVector< typename MultTrait<T1,T2>::Type,
true > Type;
4807 template<
typename T1,
bool SO1,
typename T2,
size_t M,
size_t N,
bool SO2 >
4808 struct MultTrait< CompressedMatrix<T1,SO1>, StaticMatrix<T2,M,N,SO2> >
4810 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4813 template<
typename T1,
size_t M,
size_t N,
bool SO1,
typename T2,
bool SO2 >
4814 struct MultTrait< StaticMatrix<T1,M,N,SO1>, CompressedMatrix<T2,SO2> >
4816 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4819 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4820 struct MultTrait< CompressedMatrix<T1,SO1>, DynamicMatrix<T2,SO2> >
4822 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4825 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4826 struct MultTrait< DynamicMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4828 typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4831 template<
typename T1,
bool SO1,
typename T2,
bool SO2 >
4832 struct MultTrait< CompressedMatrix<T1,SO1>, CompressedMatrix<T2,SO2> >
4834 typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, SO1 > Type;
4850 template<
typename T1,
bool SO,
typename T2 >
4851 struct DivTrait< CompressedMatrix<T1,SO>, T2 >
4853 typedef CompressedMatrix< typename DivTrait<T1,T2>::Type, SO > Type;
4870 template<
typename T1,
bool SO,
typename T2 >
4871 struct MathTrait< CompressedMatrix<T1,SO>, CompressedMatrix<T2,SO> >
4873 typedef CompressedMatrix< typename MathTrait<T1,T2>::HighType, SO > HighType;
4874 typedef CompressedMatrix< typename MathTrait<T1,T2>::LowType , SO > LowType;
4890 template<
typename T1,
bool SO >
4891 struct SubmatrixTrait< CompressedMatrix<T1,SO> >
4893 typedef CompressedMatrix<T1,SO> Type;
4909 template<
typename T1,
bool SO >
4910 struct RowTrait< CompressedMatrix<T1,SO> >
4912 typedef CompressedVector<T1,true> Type;
4928 template<
typename T1,
bool SO >
4929 struct ColumnTrait< CompressedMatrix<T1,SO> >
4931 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:1100
void reserveElements(size_t nonzeros)
Reserving the specified number of sparse matrix elements.
Definition: CompressedMatrix.h:1744
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:390
Header file for mathematical functions.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#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:251
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:252
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:446
Header file for the IsSparseMatrix type trait.
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:434
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4555
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:196
size_t extendCapacity() const
Calculating a new matrix capacity.
Definition: CompressedMatrix.h:1724
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
void clear()
Clearing the sparse matrix.
Definition: CompressedMatrix.h:1241
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:248
Header file for a safe C++ NULL pointer implementation.
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2369
CompressedMatrix< Type,!SO > OppositeType
Result type with opposite storage order for expression template evaluations.
Definition: CompressedMatrix.h:246
#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:620
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
bool isAliased(const Other *alias) const
Returns whether the matrix is aliased with the given address alias.
Definition: CompressedMatrix.h:2067
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:392
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:249
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4528
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:1163
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2513
Header file for the SparseMatrix base class.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:388
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:1515
void reset()
Reset to the default initial values.
Definition: CompressedMatrix.h:1203
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:250
Header file for the ValueIndexPair class.
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:4541
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:2379
#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:1349
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2515
#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:200
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.
size_t n_
The current number of columns of the sparse matrix.
Definition: CompressedMatrix.h:2512
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:1266
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:2377
void subAssign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the subtraction assignment of a dense matrix.
Definition: CompressedMatrix.h:2263
const size_t m_
The number of rows of the submatrix.
Definition: SparseSubmatrix.h:2655
Header file for the EnableIf class template.
void swap(CompressedMatrix &sm)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:1703
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:254
Header file for the equal shim.
ColumnIterator< const MT > ConstIterator
Iterator over constant elements.
Definition: DenseColumn.h:1972
size_t capacity() const
Returns the maximum capacity of the sparse matrix.
Definition: CompressedMatrix.h:1128
void resize(size_t m, size_t n, bool preserve=true)
Changing the size of the sparse matrix.
Definition: CompressedMatrix.h:1434
Header file for the IsNumeric type trait.
CompressedMatrix & operator=(const CompressedMatrix &rhs)
Copy assignment operator for CompressedMatrix.
Definition: CompressedMatrix.h:833
Reference operator()(size_t i, size_t j)
2D-access to the sparse matrix elements.
Definition: CompressedMatrix.h:646
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:761
CompressedMatrix & transpose()
Transposing the matrix.
Definition: CompressedMatrix.h:1641
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:4584
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:1602
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:2378
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:1114
Constraint on the data type.
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:245
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2514
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:2511
void assign(const DenseMatrix< MT, SO2 > &rhs)
Default implementation of the assignment of a row-major dense matrix.
Definition: CompressedMatrix.h:2089
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:253
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:1983
void finalize(size_t i)
Finalizing the element insertion of a row/column.
Definition: CompressedMatrix.h:2015
bool canAlias(const Other *alias) const
Returns whether the matrix can alias with the given address alias.
Definition: CompressedMatrix.h:2047
Base template for the DivTrait class.
Definition: DivTrait.h:141
CompressedMatrix< Type, SO > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:244
Iterator find(size_t i, size_t j)
Searches for a specific matrix element.
Definition: CompressedMatrix.h:1793
Header file for the mathematical trait.
Iterator * begin_
Pointers to the first non-zero element of each row.
Definition: CompressedMatrix.h:389
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:2211
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:247
Iterator lowerBound(size_t i, size_t j)
Returns an iterator to the first index not less then the given index.
Definition: CompressedMatrix.h:1846
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2517
Iterator upperBound(size_t i, size_t j)
Returns an iterator to the first index greater then the given index.
Definition: CompressedMatrix.h:1897
const size_t n_
The number of columns of the submatrix.
Definition: SparseSubmatrix.h:2656
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:739
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2376
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:348
SelectType< useConst, ConstIterator, ColumnIterator< MT > >::Type Iterator
Iterator over non-constant elements.
Definition: DenseColumn.h:1980
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:387
ConstIterator cend(size_t i) const
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:805
Header file for the IsResizable type trait.
size_t m_
The current number of rows of the sparse matrix.
Definition: CompressedMatrix.h:386
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:695