35 #ifndef _BLAZE_MATH_VIEWS_SPARSEROW_H_
36 #define _BLAZE_MATH_VIEWS_SPARSEROW_H_
350 template<
typename MT
351 ,
bool SO = IsRowMajorMatrix<MT>::value
352 ,
bool SF = IsSymmetric<MT>::value >
353 class SparseRow :
public SparseVector< SparseRow<MT,SO,SF>, true >
397 enum { smpAssignable = 0 };
403 explicit inline SparseRow( MT& matrix,
size_t index );
436 template<
typename Other >
438 operator*=( Other rhs );
440 template<
typename Other >
442 operator/=( Other rhs );
449 inline size_t size()
const;
455 inline void erase (
size_t index );
458 inline void reserve(
size_t n );
459 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
485 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
486 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
515 template<
typename MT2,
bool SO2,
bool SF2 >
547 template<
typename MT
555 throw std::invalid_argument(
"Invalid row access index" );
574 template<
typename MT
580 return matrix_(row_,index);
591 template<
typename MT
598 return const_cast<const MT&
>( matrix_ )(row_,index);
610 template<
typename MT
615 return matrix_.begin( row_ );
627 template<
typename MT
632 return matrix_.cbegin( row_ );
644 template<
typename MT
649 return matrix_.cbegin( row_ );
661 template<
typename MT
666 return matrix_.end( row_ );
678 template<
typename MT
683 return matrix_.cend( row_ );
695 template<
typename MT
700 return matrix_.cend( row_ );
723 template<
typename MT
734 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
737 if(
size() != rhs.size() )
738 throw std::invalid_argument(
"Row sizes do not match" );
740 if( rhs.canAlias( &matrix_ ) ) {
742 matrix_.reset ( row_ );
743 matrix_.reserve( row_, tmp.nonZeros() );
747 matrix_.reset ( row_ );
748 matrix_.reserve( row_, rhs.nonZeros() );
767 template<
typename MT
770 template<
typename VT >
780 throw std::invalid_argument(
"Vector sizes do not match" );
782 if( (~rhs).canAlias( &matrix_ ) ) {
784 matrix_.reset( row_ );
788 matrix_.reset( row_ );
807 template<
typename MT
810 template<
typename VT >
820 throw std::invalid_argument(
"Vector sizes do not match" );
822 if( (~rhs).canAlias( &matrix_ ) ) {
824 matrix_.reset ( row_ );
825 matrix_.reserve( row_, tmp.nonZeros() );
829 matrix_.reset ( row_ );
830 matrix_.reserve( row_, (~rhs).
nonZeros() );
849 template<
typename MT
852 template<
typename VT >
858 throw std::invalid_argument(
"Vector sizes do not match" );
877 template<
typename MT
880 template<
typename VT >
886 throw std::invalid_argument(
"Vector sizes do not match" );
906 template<
typename MT
909 template<
typename VT >
913 throw std::invalid_argument(
"Vector sizes do not match" );
920 const MultType tmp( *
this * (~rhs) );
921 matrix_.reset( row_ );
940 template<
typename MT
943 template<
typename Other >
948 element->value() *= rhs;
966 template<
typename MT
969 template<
typename Other >
981 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
983 element->value() *= tmp;
987 element->value() /= rhs;
1008 template<
typename MT
1013 return matrix_.columns();
1023 template<
typename MT
1028 return matrix_.capacity( row_ );
1041 template<
typename MT
1046 return matrix_.nonZeros( row_ );
1056 template<
typename MT
1061 matrix_.reset( row_ );
1077 template<
typename MT
1083 return matrix_.set( row_, index, value );
1100 template<
typename MT
1106 return matrix_.insert( row_, index, value );
1119 template<
typename MT
1124 matrix_.erase( row_, index );
1137 template<
typename MT
1142 return matrix_.erase( row_, pos );
1156 template<
typename MT
1162 return matrix_.erase( row_, first, last );
1176 template<
typename MT
1181 matrix_.reserve( row_, n );
1192 template<
typename MT
1195 template<
typename Other >
1199 element->value() *= scalar;
1213 template<
typename MT
1221 size_t nonzeros( 2UL*
capacity()+1UL );
1222 nonzeros =
max( nonzeros, 7UL );
1223 nonzeros =
min( nonzeros,
size() );
1253 template<
typename MT
1258 return matrix_.find( row_, index );
1276 template<
typename MT
1281 return matrix_.find( row_, index );
1298 template<
typename MT
1303 return matrix_.lowerBound( row_, index );
1320 template<
typename MT
1325 return matrix_.lowerBound( row_, index );
1342 template<
typename MT
1347 return matrix_.upperBound( row_, index );
1364 template<
typename MT
1369 return matrix_.upperBound( row_, index );
1406 template<
typename MT
1411 matrix_.append( row_, index, value, check );
1434 template<
typename MT
1437 template<
typename Other >
1440 return matrix_.isAliased( alias );
1455 template<
typename MT
1458 template<
typename Other >
1461 return matrix_.isAliased( alias );
1477 template<
typename MT
1480 template<
typename VT >
1486 for(
size_t j=0UL; j<
size(); ++j )
1488 if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
1489 matrix_.reserve( row_, extendCapacity() );
1491 matrix_.append( row_, j, (~rhs)[j],
true );
1508 template<
typename MT
1511 template<
typename VT >
1518 matrix_.append( row_, element->index(), element->value() );
1535 template<
typename MT
1538 template<
typename VT >
1549 const AddType tmp(
serial( *
this + (~rhs) ) );
1550 matrix_.reset( row_ );
1567 template<
typename MT
1570 template<
typename VT >
1581 const AddType tmp(
serial( *
this + (~rhs) ) );
1582 matrix_.reset ( row_ );
1583 matrix_.reserve( row_, tmp.nonZeros() );
1600 template<
typename MT
1603 template<
typename VT >
1614 const SubType tmp(
serial( *
this - (~rhs) ) );
1615 matrix_.reset ( row_ );
1632 template<
typename MT
1635 template<
typename VT >
1646 const SubType tmp(
serial( *
this - (~rhs) ) );
1647 matrix_.reset ( row_ );
1648 matrix_.reserve( row_, tmp.nonZeros() );
1674 template<
typename MT >
1697 typedef SparseRow<MT,false,false>
This;
1698 typedef typename RowTrait<MT>::Type
ResultType;
1708 typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type
Reference;
1714 template<
typename MatrixType
1715 ,
typename IteratorType >
1716 class RowElement :
private SparseElement
1726 enum { returnConst = IsConst<MatrixType>::value };
1731 typedef typename std::iterator_traits<IteratorType>::value_type SET;
1739 typedef typename SET::ValueType ValueType;
1740 typedef size_t IndexType;
1741 typedef typename SelectType<returnConst,CRT,RT>::Type
Reference;
1751 inline RowElement( IteratorType pos,
size_t column )
1763 template<
typename T >
inline RowElement&
operator=(
const T& v ) {
1775 template<
typename T >
inline RowElement& operator+=(
const T& v ) {
1787 template<
typename T >
inline RowElement& operator-=(
const T& v ) {
1799 template<
typename T >
inline RowElement& operator*=(
const T& v ) {
1811 template<
typename T >
inline RowElement& operator/=(
const T& v ) {
1822 inline const RowElement* operator->()
const {
1833 return pos_->value();
1842 inline IndexType index()
const {
1858 template<
typename MatrixType
1859 ,
typename IteratorType >
1864 typedef std::forward_iterator_tag IteratorCategory;
1865 typedef RowElement<MatrixType,IteratorType> ValueType;
1866 typedef ValueType PointerType;
1867 typedef ValueType ReferenceType;
1868 typedef ptrdiff_t DifferenceType;
1871 typedef IteratorCategory iterator_category;
1872 typedef ValueType value_type;
1873 typedef PointerType pointer;
1874 typedef ReferenceType reference;
1875 typedef DifferenceType difference_type;
1881 inline RowIterator()
1896 inline RowIterator( MatrixType& matrix,
size_t row,
size_t column )
1902 for( ; column_<
matrix_->columns(); ++column_ ) {
1904 if( pos_ !=
matrix_->end( column_ ) )
break;
1917 inline RowIterator( MatrixType& matrix,
size_t row,
size_t column, IteratorType pos )
1932 template<
typename MatrixType2,
typename IteratorType2 >
1933 inline RowIterator(
const RowIterator<MatrixType2,IteratorType2>& it )
1936 , column_( it.column_ )
1946 inline RowIterator& operator++() {
1948 for( ; column_<
matrix_->columns(); ++column_ ) {
1950 if( pos_ !=
matrix_->end( column_ ) )
break;
1962 inline const RowIterator operator++(
int ) {
1963 const RowIterator tmp( *
this );
1974 inline ReferenceType
operator*()
const {
1975 return ReferenceType( pos_, column_ );
1984 inline PointerType operator->()
const {
1985 return PointerType( pos_, column_ );
1995 template<
typename MatrixType2,
typename IteratorType2 >
1996 inline bool operator==(
const RowIterator<MatrixType2,IteratorType2>& rhs )
const {
1997 return (
matrix_ == rhs.matrix_ ) && (
row_ == rhs.row_ ) && ( column_ == rhs.column_ );
2007 template<
typename MatrixType2,
typename IteratorType2 >
2008 inline bool operator!=(
const RowIterator<MatrixType2,IteratorType2>& rhs )
const {
2009 return !( *
this == rhs );
2019 inline DifferenceType
operator-(
const RowIterator& rhs )
const {
2020 size_t counter( 0UL );
2021 for(
size_t j=rhs.column_; j<column_; ++j ) {
2038 template<
typename MatrixType2,
typename IteratorType2 >
friend class RowIterator;
2039 template<
typename MT2,
bool SO2,
bool SF2 >
friend class SparseRow;
2046 typedef RowIterator<const MT,typename MT::ConstIterator>
ConstIterator;
2049 typedef typename SelectType< useConst, ConstIterator, RowIterator<MT,typename MT::Iterator> >::Type
Iterator;
2054 enum { smpAssignable = 0 };
2060 explicit inline SparseRow( MT& matrix,
size_t index );
2088 template<
typename VT >
inline SparseRow& operator+=(
const Vector<VT,true>& rhs );
2089 template<
typename VT >
inline SparseRow& operator-=(
const Vector<VT,true>& rhs );
2090 template<
typename VT >
inline SparseRow& operator*=(
const Vector<VT,true>& rhs );
2092 template<
typename Other >
2093 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
2094 operator*=( Other rhs );
2096 template<
typename Other >
2097 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
2098 operator/=( Other rhs );
2105 inline size_t size()
const;
2108 inline void reset();
2111 inline void erase (
size_t index );
2114 inline void reserve(
size_t n );
2115 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
2141 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2142 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2144 template<
typename VT >
inline void assign (
const DenseVector <VT,true>& rhs );
2145 template<
typename VT >
inline void assign (
const SparseVector<VT,true>& rhs );
2146 template<
typename VT >
inline void addAssign(
const Vector<VT,true>& rhs );
2147 template<
typename VT >
inline void subAssign(
const Vector<VT,true>& rhs );
2161 template<
typename MT2,
bool SO2,
bool SF2 >
2162 friend bool isSame(
const SparseRow<MT2,SO2,SF2>& a,
const SparseRow<MT2,SO2,SF2>& b );
2193 template<
typename MT >
2199 throw std::invalid_argument(
"Invalid row access index" );
2220 template<
typename MT >
2225 return matrix_(row_,index);
2238 template<
typename MT >
2243 return const_cast<const MT&
>( matrix_ )(row_,index);
2257 template<
typename MT >
2260 return Iterator( matrix_, row_, 0UL );
2274 template<
typename MT >
2291 template<
typename MT >
2308 template<
typename MT >
2325 template<
typename MT >
2342 template<
typename MT >
2370 template<
typename MT >
2379 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
2382 if(
size() != rhs.size() )
2383 throw std::invalid_argument(
"Row sizes do not match" );
2385 if( rhs.canAlias( &matrix_ ) ) {
2410 template<
typename MT >
2411 template<
typename VT >
2417 throw std::invalid_argument(
"Vector sizes do not match" );
2439 template<
typename MT >
2440 template<
typename VT >
2441 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator+=(
const Vector<VT,true>& rhs )
2446 throw std::invalid_argument(
"Vector sizes do not match" );
2467 template<
typename MT >
2468 template<
typename VT >
2469 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator-=(
const Vector<VT,true>& rhs )
2474 throw std::invalid_argument(
"Vector sizes do not match" );
2496 template<
typename MT >
2497 template<
typename VT >
2498 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator*=(
const Vector<VT,true>& rhs )
2501 throw std::invalid_argument(
"Vector sizes do not match" );
2503 typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
2508 const MultType tmp( *
this * (~rhs) );
2529 template<
typename MT >
2530 template<
typename Other >
2531 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
2532 SparseRow<MT,false,false>::operator*=( Other rhs )
2535 element->value() *= rhs;
2555 template<
typename MT >
2556 template<
typename Other >
2557 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
2558 SparseRow<MT,false,false>::operator/=( Other rhs )
2562 typedef typename DivTrait<ElementType,Other>::Type DT;
2563 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
2567 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
2568 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
2570 element->value() *= tmp;
2574 element->value() /= rhs;
2597 template<
typename MT >
2600 return matrix_.columns();
2612 template<
typename MT >
2615 return matrix_.columns();
2630 template<
typename MT >
2633 size_t counter( 0UL );
2649 template<
typename MT >
2652 for(
size_t j=0UL; j<
size(); ++j ) {
2653 matrix_.erase( row_, j );
2673 template<
typename MT >
2677 return Iterator( matrix_, row_, index, matrix_.insert( row_, index, value ) );
2695 template<
typename MT >
2699 return Iterator( matrix_, row_, index, matrix_.set( row_, index, value ) );
2714 template<
typename MT >
2717 matrix_.erase( row_, index );
2732 template<
typename MT >
2735 const size_t column( pos.column_ );
2737 if( column ==
size() )
2740 matrix_.erase( column, pos.pos_ );
2741 return Iterator( matrix_, row_, column+1UL );
2757 template<
typename MT >
2761 for( ; first!=last; ++first ) {
2762 matrix_.erase( first.column_, first.pos_ );
2780 template<
typename MT >
2797 template<
typename MT >
2798 template<
typename Other >
2799 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::scale(
const Other& scalar )
2802 element->value() *= scalar;
2831 template<
typename MT >
2834 const typename MT::Iterator pos( matrix_.find( row_, index ) );
2836 if( pos != matrix_.end( index ) )
2837 return Iterator( matrix_, row_, index, pos );
2859 template<
typename MT >
2865 if( pos != matrix_.end( index ) )
2887 template<
typename MT >
2891 for(
size_t i=index; i<
size(); ++i )
2893 const typename MT::Iterator pos( matrix_.find( row_, i ) );
2895 if( pos != matrix_.end( i ) )
2896 return Iterator( matrix_, row_, i, pos );
2918 template<
typename MT >
2922 for(
size_t i=index; i<
size(); ++i )
2926 if( pos != matrix_.end( i ) )
2949 template<
typename MT >
2953 for(
size_t i=index+1UL; i<
size(); ++i )
2955 const typename MT::Iterator pos( matrix_.find( row_, i ) );
2957 if( pos != matrix_.end( i ) )
2958 return Iterator( matrix_, row_, i, pos );
2980 template<
typename MT >
2984 for(
size_t i=index+1UL; i<
size(); ++i )
2988 if( pos != matrix_.end( i ) )
3031 template<
typename MT >
3035 matrix_.insert( row_, index, value );
3060 template<
typename MT >
3061 template<
typename Other >
3064 return matrix_.isAliased( alias );
3077 template<
typename MT >
3078 template<
typename Other >
3081 return matrix_.isAliased( alias );
3099 template<
typename MT >
3100 template<
typename VT >
3105 for(
size_t j=0UL; j<(~rhs).
size(); ++j ) {
3106 matrix_(row_,j) = (~rhs)[j];
3125 template<
typename MT >
3126 template<
typename VT >
3134 for( ; j<element->index(); ++j )
3135 matrix_.erase( row_, j );
3136 matrix_(row_,j++) = element->value();
3138 for( ; j<
size(); ++j ) {
3139 matrix_.erase( row_, j );
3158 template<
typename MT >
3159 template<
typename VT >
3162 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3169 const AddType tmp(
serial( *
this + (~rhs) ) );
3188 template<
typename MT >
3189 template<
typename VT >
3192 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3199 const SubType tmp(
serial( *
this - (~rhs) ) );
3226 template<
typename MT >
3227 class SparseRow<MT,false,true> :
public SparseVector< SparseRow<MT,false,true>, true >
3233 typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type
Operand;
3244 enum { useConst = IsConst<MT>::value };
3249 typedef SparseRow<MT,false,true>
This;
3250 typedef typename RowTrait<MT>::Type
ResultType;
3260 typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type
Reference;
3266 typedef typename SelectType< useConst, ConstIterator, typename MT::Iterator >::Type
Iterator;
3271 enum { smpAssignable = 0 };
3277 explicit inline SparseRow( MT& matrix,
size_t index );
3304 template<
typename VT >
inline SparseRow&
operator= (
const DenseVector <VT,true>& rhs );
3305 template<
typename VT >
inline SparseRow&
operator= (
const SparseVector<VT,true>& rhs );
3306 template<
typename VT >
inline SparseRow& operator+=(
const Vector<VT,true>& rhs );
3307 template<
typename VT >
inline SparseRow& operator-=(
const Vector<VT,true>& rhs );
3308 template<
typename VT >
inline SparseRow& operator*=(
const Vector<VT,true>& rhs );
3310 template<
typename Other >
3311 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
3312 operator*=( Other rhs );
3314 template<
typename Other >
3315 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
3316 operator/=( Other rhs );
3323 inline size_t size()
const;
3326 inline void reset();
3329 inline void erase (
size_t index );
3332 inline void reserve(
size_t n );
3333 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
3359 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
3360 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
3362 template<
typename VT >
inline void assign (
const DenseVector <VT,true>& rhs );
3363 template<
typename VT >
inline void assign (
const SparseVector<VT,true>& rhs );
3364 template<
typename VT >
inline void addAssign(
const DenseVector <VT,true>& rhs );
3365 template<
typename VT >
inline void addAssign(
const SparseVector<VT,true>& rhs );
3366 template<
typename VT >
inline void subAssign(
const DenseVector <VT,true>& rhs );
3367 template<
typename VT >
inline void subAssign(
const SparseVector<VT,true>& rhs );
3388 template<
typename MT2,
bool SO2,
bool SF2 >
3389 friend bool isSame(
const SparseRow<MT2,SO2,SF2>& a,
const SparseRow<MT2,SO2,SF2>& b );
3420 template<
typename MT >
3426 throw std::invalid_argument(
"Invalid row access index" );
3447 template<
typename MT >
3452 return matrix_(index,row_);
3465 template<
typename MT >
3470 return const_cast<const MT&
>( matrix_ )(index,row_);
3484 template<
typename MT >
3487 return matrix_.begin( row_ );
3501 template<
typename MT >
3504 return matrix_.cbegin( row_ );
3518 template<
typename MT >
3521 return matrix_.cbegin( row_ );
3535 template<
typename MT >
3538 return matrix_.end( row_ );
3552 template<
typename MT >
3555 return matrix_.cend( row_ );
3569 template<
typename MT >
3572 return matrix_.cend( row_ );
3597 template<
typename MT >
3606 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
3609 if(
size() != rhs.size() )
3610 throw std::invalid_argument(
"Row sizes do not match" );
3612 if( rhs.canAlias( &matrix_ ) ) {
3614 matrix_.reset ( row_ );
3615 matrix_.reserve( row_, tmp.nonZeros() );
3619 matrix_.reset ( row_ );
3620 matrix_.reserve( row_, rhs.nonZeros() );
3641 template<
typename MT >
3642 template<
typename VT >
3643 inline SparseRow<MT,false,true>&
3653 throw std::invalid_argument(
"Vector sizes do not match" );
3655 if( (~rhs).canAlias( &matrix_ ) ) {
3657 matrix_.reset( row_ );
3661 matrix_.reset( row_ );
3682 template<
typename MT >
3683 template<
typename VT >
3684 inline SparseRow<MT,false,true>&
3694 throw std::invalid_argument(
"Vector sizes do not match" );
3696 if( (~rhs).canAlias( &matrix_ ) ) {
3698 matrix_.reset ( row_ );
3699 matrix_.reserve( row_, tmp.nonZeros() );
3703 matrix_.reset ( row_ );
3704 matrix_.reserve( row_, (~rhs).
nonZeros() );
3725 template<
typename MT >
3726 template<
typename VT >
3727 inline SparseRow<MT,false,true>&
3728 SparseRow<MT,false,true>::operator+=(
const Vector<VT,true>& rhs )
3733 throw std::invalid_argument(
"Vector sizes do not match" );
3754 template<
typename MT >
3755 template<
typename VT >
3756 inline SparseRow<MT,false,true>&
3757 SparseRow<MT,false,true>::operator-=(
const Vector<VT,true>& rhs )
3762 throw std::invalid_argument(
"Vector sizes do not match" );
3784 template<
typename MT >
3785 template<
typename VT >
3786 inline SparseRow<MT,false,true>&
3787 SparseRow<MT,false,true>::operator*=(
const Vector<VT,true>& rhs )
3790 throw std::invalid_argument(
"Vector sizes do not match" );
3792 typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
3797 const MultType tmp( *
this * (~rhs) );
3798 matrix_.reset( row_ );
3819 template<
typename MT >
3820 template<
typename Other >
3821 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
3822 SparseRow<MT,false,true>::operator*=( Other rhs )
3825 element->value() *= rhs;
3845 template<
typename MT >
3846 template<
typename Other >
3847 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
3848 SparseRow<MT,false,true>::operator/=( Other rhs )
3852 typedef typename DivTrait<ElementType,Other>::Type DT;
3853 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3857 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3858 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3860 element->value() *= tmp;
3864 element->value() /= rhs;
3887 template<
typename MT >
3890 return matrix_.columns();
3902 template<
typename MT >
3905 return matrix_.capacity( row_ );
3920 template<
typename MT >
3923 return matrix_.nonZeros( row_ );
3935 template<
typename MT >
3938 matrix_.reset( row_ );
3956 template<
typename MT >
3960 return matrix_.set( index, row_, value );
3979 template<
typename MT >
3983 return matrix_.insert( index, row_, value );
3998 template<
typename MT >
4001 matrix_.erase( index, row_ );
4016 template<
typename MT >
4020 return matrix_.erase( row_, pos );
4036 template<
typename MT >
4040 return matrix_.erase( row_, first, last );
4056 template<
typename MT >
4059 matrix_.reserve( row_, n );
4072 template<
typename MT >
4073 template<
typename Other >
4074 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::scale(
const Other& scalar )
4077 element->value() *= scalar;
4093 template<
typename MT >
4099 size_t nonzeros( 2UL*
capacity()+1UL );
4100 nonzeros =
max( nonzeros, 7UL );
4101 nonzeros =
min( nonzeros,
size() );
4133 template<
typename MT >
4137 return matrix_.find( index, row_ );
4157 template<
typename MT >
4161 return matrix_.find( index, row_ );
4180 template<
typename MT >
4184 return matrix_.lowerBound( index, row_ );
4203 template<
typename MT >
4207 return matrix_.lowerBound( index, row_ );
4226 template<
typename MT >
4230 return matrix_.upperBound( index, row_ );
4249 template<
typename MT >
4253 return matrix_.upperBound( index, row_ );
4292 template<
typename MT >
4295 matrix_.append( index, row_, value, check );
4320 template<
typename MT >
4321 template<
typename Other >
4324 return matrix_.isAliased( alias );
4341 template<
typename MT >
4342 template<
typename Other >
4345 return matrix_.isAliased( alias );
4363 template<
typename MT >
4364 template<
typename VT >
4370 for(
size_t i=0UL; i<
size(); ++i )
4372 if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
4373 matrix_.reserve( row_, extendCapacity() );
4375 matrix_.append( i, row_, (~rhs)[i],
true );
4394 template<
typename MT >
4395 template<
typename VT >
4402 matrix_.append( element->index(), row_, element->value() );
4421 template<
typename MT >
4422 template<
typename VT >
4425 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4433 const AddType tmp(
serial( *
this + (~rhs) ) );
4434 matrix_.reset( row_ );
4453 template<
typename MT >
4454 template<
typename VT >
4457 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4465 const AddType tmp(
serial( *
this + (~rhs) ) );
4466 matrix_.reset ( row_ );
4467 matrix_.reserve( row_, tmp.nonZeros() );
4486 template<
typename MT >
4487 template<
typename VT >
4490 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4498 const SubType tmp(
serial( *
this - (~rhs) ) );
4499 matrix_.reset ( row_ );
4518 template<
typename MT >
4519 template<
typename VT >
4522 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4530 const SubType tmp(
serial( *
this - (~rhs) ) );
4531 matrix_.reset ( row_ );
4532 matrix_.reserve( row_, tmp.nonZeros() );
4554 template<
typename MT,
bool SO,
bool SF >
4555 inline void reset( SparseRow<MT,SO,SF>& row );
4557 template<
typename MT,
bool SO,
bool SF >
4558 inline void clear( SparseRow<MT,SO,SF>& row );
4560 template<
typename MT,
bool SO,
bool SF >
4561 inline bool isDefault(
const SparseRow<MT,SO,SF>& row );
4563 template<
typename MT,
bool SO,
bool SF >
4564 inline bool isSame(
const SparseRow<MT,SO,SF>& a,
const SparseRow<MT,SO,SF>& b );
4576 template<
typename MT
4595 template<
typename MT
4623 template<
typename MT
4630 const ConstIterator
end( row.end() );
4631 for( ConstIterator element=row.begin(); element!=
end; ++element )
4632 if( !
isDefault( element->value() ) )
return false;
4650 template<
typename MT
4655 return (
isSame( a.matrix_, b.matrix_ ) && ( a.row_ == b.row_ ) );
4670 template<
typename MT,
bool SO,
bool SF >
4671 struct SubvectorTrait< SparseRow<MT,SO,SF> >
Constraint on the data type.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:994
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
MT::ConstReference ConstReference
Reference to a constant row value.
Definition: SparseRow.h:383
#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
Header file for the UNUSED_PARAMETER function template.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:4838
Header file for the subtraction trait.
Header file for the SparseVector base class.
SparseRow & operator=(const SparseRow &rhs)
Copy assignment operator for SparseRow.
Definition: SparseRow.h:726
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.
SparseRow< MT, SO, SF > This
Type of this SparseRow instance.
Definition: SparseRow.h:375
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
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse row.
Definition: SparseRow.h:1409
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
Header file for the row base class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
size_t size() const
Returns the current size/dimension of the sparse row.
Definition: SparseRow.h:1011
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:946
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:103
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
bool canAlias(const Other *alias) const
Returns whether the sparse row can alias with the given address alias.
Definition: SparseRow.h:1438
size_t nonZeros() const
Returns the number of non-zero elements in the row.
Definition: SparseRow.h:1044
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseRow.h:379
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
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
#define BLAZE_CONSTRAINT_MUST_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a symmetric matrix type...
Definition: Symmetric.h:78
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i...
Definition: TransExpr.h:118
size_t extendCapacity() const
Calculating a new sparse row capacity.
Definition: SparseRow.h:1216
RowTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseRow.h:376
void subAssign(const DenseVector< VT, true > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseRow.h:1604
Constraint on the data type.
const size_t row_
The index of the row in the matrix.
Definition: SparseRow.h:509
Base template for the RowTrait class.
Definition: RowTrait.h:115
SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant row value.
Definition: SparseRow.h:386
ConstIterator cbegin() const
Returns an iterator to the first element of the row.
Definition: SparseRow.h:647
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
void erase(size_t index)
Erasing an element from the sparse row.
Definition: SparseRow.h:1122
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
Header file for the Or class template.
void reset()
Reset to the default initial values.
Definition: SparseRow.h:1059
void reserve(size_t n)
Setting the minimum capacity of the sparse row.
Definition: SparseRow.h:1179
size_t capacity() const
Returns the maximum capacity of the sparse row.
Definition: SparseRow.h:1026
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
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
Header file for the subvector trait.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
Header file for the SparseElement base class.
Constraint on the data type.
void addAssign(const DenseVector< VT, true > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseRow.h:1539
Operand matrix_
The sparse matrix containing the row.
Definition: SparseRow.h:508
Constraints on the storage order of matrix types.
Constraint on the data type.
Reference operator[](size_t index)
Subscript operator for the direct access to the row elements.
Definition: SparseRow.h:577
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
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
MT::ElementType ElementType
Type of the row elements.
Definition: SparseRow.h:378
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseRow.h:389
SparseRow(MT &matrix, size_t index)
The constructor for SparseRow.
Definition: SparseRow.h:550
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Constraint on the data type.
Header file for the SelectType class template.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse row.
Definition: SparseRow.h:1104
Header file for the EnableIf class template.
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse row.
Definition: SparseRow.h:1081
Header file for the serial shim.
Header file for the IsNumeric type trait.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:103
#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
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Header file for the IsConst type trait.
Iterator end()
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:664
Base class for all rows.The Row class serves as a tag for all rows (i.e. dense and sparse rows)...
Definition: Row.h:63
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:142
Base template for the MultTrait class.
Definition: MultTrait.h:142
Header file for the addition trait.
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
Reference to a specific row of a sparse matrix.The SparseRow template represents a reference to a spe...
Definition: Forward.h:52
Header file for the division trait.
SelectType< useConst, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseRow.h:392
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the reset shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the isDefault shim.
const SparseRow & CompositeType
Data type for composite expression templates.
Definition: SparseRow.h:380
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.
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:118
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
Base template for the DivTrait class.
Definition: DivTrait.h:142
Iterator find(size_t index)
Searches for a specific row element.
Definition: SparseRow.h:1256
bool isAliased(const Other *alias) const
Returns whether the sparse row is aliased with the given address alias.
Definition: SparseRow.h:1459
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseRow.h:1301
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseRow.h:377
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
Header file for the IsRowMajorMatrix type trait.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:151
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:256
SelectType< IsExpression< MT >::value, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseRow.h:359
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2473
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: TransposeFlag.h:81
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Base template for the SubTrait class.
Definition: SubTrait.h:142
ConstIterator cend() const
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:698
Iterator begin()
Returns an iterator to the first element of the row.
Definition: SparseRow.h:613
#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 upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseRow.h:1345
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
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.
void assign(const DenseVector< VT, true > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseRow.h:1481