35 #ifndef _BLAZE_MATH_VIEWS_SPARSEROW_H_
36 #define _BLAZE_MATH_VIEWS_SPARSEROW_H_
368 template<
typename MT
369 ,
bool SO = IsRowMajorMatrix<MT>::value
370 ,
bool SF = IsSymmetric<MT>::value >
371 class SparseRow :
public SparseVector< SparseRow<MT,SO,SF>, true >
415 enum { smpAssignable = 0 };
421 explicit inline SparseRow( MT& matrix,
size_t index );
434 inline ConstReference
operator[](
size_t index )
const;
435 inline Iterator
begin ();
436 inline ConstIterator
begin ()
const;
437 inline ConstIterator
cbegin()
const;
438 inline Iterator
end ();
439 inline ConstIterator
end ()
const;
440 inline ConstIterator
cend ()
const;
457 template<
typename Other >
459 operator*=( Other rhs );
461 template<
typename Other >
463 operator/=( Other rhs );
470 inline size_t size()
const;
474 inline Iterator
set (
size_t index,
const ElementType& value );
475 inline Iterator
insert (
size_t index,
const ElementType& value );
476 inline void erase (
size_t index );
477 inline Iterator
erase ( Iterator pos );
478 inline Iterator
erase ( Iterator first, Iterator last );
479 inline void reserve(
size_t n );
480 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
487 inline Iterator
find (
size_t index );
488 inline ConstIterator
find (
size_t index )
const;
490 inline ConstIterator
lowerBound(
size_t index )
const;
492 inline ConstIterator
upperBound(
size_t index )
const;
499 inline void append(
size_t index,
const ElementType& value,
bool check=
false );
506 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
507 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
524 template<
typename MT2,
bool SO2,
typename VT >
528 template<
typename MT2,
bool SO2,
typename VT >
532 template<
typename MT2,
bool SO2,
typename VT >
533 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
536 template<
typename MT2,
bool SO2,
typename VT >
540 template<
typename MT2,
bool SO2,
typename VT >
541 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
544 template<
typename MT2,
bool SO2,
typename VT >
548 template<
typename MT2,
bool SO2,
typename VT >
549 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
564 template<
typename MT2,
bool SO2,
bool SF2 >
567 template<
typename MT2,
bool SO2,
bool SF2 >
603 template<
typename MT
611 throw std::invalid_argument(
"Invalid row access index" );
630 template<
typename MT
636 return matrix_(row_,index);
647 template<
typename MT
654 return const_cast<const MT&
>( matrix_ )(row_,index);
666 template<
typename MT
671 return matrix_.begin( row_ );
683 template<
typename MT
688 return matrix_.cbegin( row_ );
700 template<
typename MT
705 return matrix_.cbegin( row_ );
717 template<
typename MT
722 return matrix_.end( row_ );
734 template<
typename MT
739 return matrix_.cend( row_ );
751 template<
typename MT
756 return matrix_.cend( row_ );
782 template<
typename MT
793 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
796 if(
size() != rhs.size() )
797 throw std::invalid_argument(
"Row sizes do not match" );
799 if( !preservesInvariant( matrix_, rhs ) )
800 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
804 if( rhs.canAlias( &matrix_ ) ) {
807 left.reserve( tmp.nonZeros() );
812 left.reserve( rhs.nonZeros() );
837 template<
typename MT
840 template<
typename VT >
850 throw std::invalid_argument(
"Vector sizes do not match" );
855 if( !preservesInvariant( matrix_, right ) )
856 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
891 template<
typename MT
894 template<
typename VT >
904 throw std::invalid_argument(
"Vector sizes do not match" );
909 if( !preservesInvariant( matrix_, right ) )
910 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
917 left.reserve( tmp.nonZeros() );
922 left.reserve( right.nonZeros() );
947 template<
typename MT
950 template<
typename VT >
969 throw std::invalid_argument(
"Vector sizes do not match" );
971 const AddType tmp( *
this + (~rhs) );
973 if( !preservesInvariant( matrix_, tmp ) )
974 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
1002 template<
typename MT
1005 template<
typename VT >
1024 throw std::invalid_argument(
"Vector sizes do not match" );
1026 const AddType tmp( *
this + (~rhs) );
1028 if( !preservesInvariant( matrix_, tmp ) )
1029 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
1034 left.reserve( tmp.nonZeros() );
1059 template<
typename MT
1062 template<
typename VT >
1081 throw std::invalid_argument(
"Vector sizes do not match" );
1083 const SubType tmp( *
this - (~rhs) );
1085 if( !preservesInvariant( matrix_, tmp ) )
1086 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
1115 template<
typename MT
1118 template<
typename VT >
1137 throw std::invalid_argument(
"Vector sizes do not match" );
1139 const SubType tmp( *
this - (~rhs) );
1141 if( !preservesInvariant( matrix_, tmp ) )
1142 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
1147 left.reserve( tmp.nonZeros() );
1169 template<
typename MT
1172 template<
typename VT >
1189 throw std::invalid_argument(
"Vector sizes do not match" );
1193 const MultType tmp( *
this * (~rhs) );
1219 template<
typename MT
1222 template<
typename Other >
1229 element->value() *= rhs;
1252 template<
typename MT
1255 template<
typename Other >
1269 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1271 element->value() *= tmp;
1275 element->value() /= rhs;
1296 template<
typename MT
1301 return matrix_.columns();
1311 template<
typename MT
1316 return matrix_.capacity( row_ );
1329 template<
typename MT
1334 return matrix_.nonZeros( row_ );
1344 template<
typename MT
1349 matrix_.reset( row_ );
1365 template<
typename MT
1371 return matrix_.set( row_, index, value );
1388 template<
typename MT
1394 return matrix_.insert( row_, index, value );
1407 template<
typename MT
1412 matrix_.erase( row_, index );
1425 template<
typename MT
1430 return matrix_.erase( row_, pos );
1444 template<
typename MT
1450 return matrix_.erase( row_, first, last );
1464 template<
typename MT
1469 matrix_.reserve( row_, n );
1484 template<
typename MT
1487 template<
typename Other >
1493 element->value() *= scalar;
1507 template<
typename MT
1515 size_t nonzeros( 2UL*
capacity()+1UL );
1516 nonzeros =
max( nonzeros, 7UL );
1517 nonzeros =
min( nonzeros,
size() );
1537 template<
typename MT
1540 template<
typename MT2
1564 template<
typename MT
1567 template<
typename MT2
1582 for(
size_t i=ibegin; i<
size(); ++i ) {
1603 template<
typename MT
1606 template<
typename MT2
1609 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
1619 const RhsIterator last( (~rhs).
end() );
1620 RhsIterator element( (~rhs).lowerBound( ( checkDiagonal )?( row_ ):( row_+1UL ) ) );
1623 if( element == last || element->index() != row_ || !
isOne( element->value() ) )
1628 for( ; element!=last; ++element ) {
1649 template<
typename MT
1652 template<
typename MT2
1664 for(
size_t i=0UL; i<iend; ++i ) {
1688 template<
typename MT
1691 template<
typename MT2
1694 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
1708 for( RhsIterator element=(~rhs).begin(); element!=last; ++element ) {
1729 template<
typename MT
1732 template<
typename MT2
1742 for(
size_t i=0UL; i<row_; ++i ) {
1747 for(
size_t i=row_+1UL; i<
size(); ++i ) {
1768 template<
typename MT
1771 template<
typename MT2
1774 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
1783 for( RhsIterator element=(~rhs).
begin(); element!=(~rhs).
end(); ++element ) {
1784 if( element->index() != row_ && !
isDefault( element->value() ) )
1814 template<
typename MT
1819 return matrix_.find( row_, index );
1837 template<
typename MT
1842 return matrix_.find( row_, index );
1859 template<
typename MT
1864 return matrix_.lowerBound( row_, index );
1881 template<
typename MT
1886 return matrix_.lowerBound( row_, index );
1903 template<
typename MT
1908 return matrix_.upperBound( row_, index );
1925 template<
typename MT
1930 return matrix_.upperBound( row_, index );
1967 template<
typename MT
1972 matrix_.append( row_, index, value, check );
1995 template<
typename MT
1998 template<
typename Other >
2001 return matrix_.isAliased( alias );
2016 template<
typename MT
2019 template<
typename Other >
2022 return matrix_.isAliased( alias );
2038 template<
typename MT
2041 template<
typename VT >
2049 for(
size_t j=0UL; j<
size(); ++j )
2051 if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
2052 matrix_.reserve( row_, extendCapacity() );
2054 matrix_.append( row_, j, (~rhs)[j],
true );
2071 template<
typename MT
2074 template<
typename VT >
2083 matrix_.append( row_, element->index(), element->value(), true );
2100 template<
typename MT
2103 template<
typename VT >
2116 const AddType tmp(
serial( *
this + (~rhs) ) );
2117 matrix_.reset( row_ );
2134 template<
typename MT
2137 template<
typename VT >
2150 const AddType tmp(
serial( *
this + (~rhs) ) );
2151 matrix_.reset( row_ );
2152 matrix_.reserve( row_, tmp.nonZeros() );
2169 template<
typename MT
2172 template<
typename VT >
2185 const SubType tmp(
serial( *
this - (~rhs) ) );
2186 matrix_.reset( row_ );
2203 template<
typename MT
2206 template<
typename VT >
2219 const SubType tmp(
serial( *
this - (~rhs) ) );
2220 matrix_.reset( row_ );
2221 matrix_.reserve( row_, tmp.nonZeros() );
2247 template<
typename MT >
2270 typedef SparseRow<MT,false,false>
This;
2271 typedef typename RowTrait<MT>::Type
ResultType;
2281 typedef typename IfTrue< useConst, ConstReference, typename MT::Reference >::Type
Reference;
2287 template<
typename MatrixType
2288 ,
typename IteratorType >
2289 class RowElement :
private SparseElement
2299 enum { returnConst = IsConst<MatrixType>::value };
2304 typedef typename std::iterator_traits<IteratorType>::value_type SET;
2312 typedef typename SET::ValueType ValueType;
2313 typedef size_t IndexType;
2314 typedef typename IfTrue<returnConst,CRT,RT>::Type
Reference;
2324 inline RowElement( IteratorType pos,
size_t column )
2336 template<
typename T >
inline RowElement&
operator=(
const T& v ) {
2348 template<
typename T >
inline RowElement& operator+=(
const T& v ) {
2360 template<
typename T >
inline RowElement& operator-=(
const T& v ) {
2372 template<
typename T >
inline RowElement& operator*=(
const T& v ) {
2384 template<
typename T >
inline RowElement& operator/=(
const T& v ) {
2395 inline const RowElement* operator->()
const {
2405 inline Reference value()
const {
2406 return pos_->value();
2415 inline IndexType index()
const {
2431 template<
typename MatrixType
2432 ,
typename IteratorType >
2437 typedef std::forward_iterator_tag IteratorCategory;
2438 typedef RowElement<MatrixType,IteratorType> ValueType;
2439 typedef ValueType PointerType;
2440 typedef ValueType ReferenceType;
2441 typedef ptrdiff_t DifferenceType;
2444 typedef IteratorCategory iterator_category;
2445 typedef ValueType value_type;
2446 typedef PointerType pointer;
2447 typedef ReferenceType reference;
2448 typedef DifferenceType difference_type;
2454 inline RowIterator()
2469 inline RowIterator( MatrixType& matrix,
size_t row,
size_t column )
2475 for( ; column_<
matrix_->columns(); ++column_ ) {
2477 if( pos_ !=
matrix_->end( column_ ) )
break;
2490 inline RowIterator( MatrixType& matrix,
size_t row,
size_t column, IteratorType pos )
2505 template<
typename MatrixType2,
typename IteratorType2 >
2506 inline RowIterator(
const RowIterator<MatrixType2,IteratorType2>& it )
2509 , column_( it.column_ )
2519 inline RowIterator& operator++() {
2521 for( ; column_<
matrix_->columns(); ++column_ ) {
2523 if( pos_ !=
matrix_->end( column_ ) )
break;
2535 inline const RowIterator operator++(
int ) {
2536 const RowIterator tmp( *
this );
2547 inline ReferenceType
operator*()
const {
2548 return ReferenceType( pos_, column_ );
2557 inline PointerType operator->()
const {
2558 return PointerType( pos_, column_ );
2568 template<
typename MatrixType2,
typename IteratorType2 >
2569 inline bool operator==(
const RowIterator<MatrixType2,IteratorType2>& rhs )
const {
2570 return (
matrix_ == rhs.matrix_ ) && (
row_ == rhs.row_ ) && ( column_ == rhs.column_ );
2580 template<
typename MatrixType2,
typename IteratorType2 >
2581 inline bool operator!=(
const RowIterator<MatrixType2,IteratorType2>& rhs )
const {
2582 return !( *
this == rhs );
2592 inline DifferenceType
operator-(
const RowIterator& rhs )
const {
2593 size_t counter( 0UL );
2594 for(
size_t j=rhs.column_; j<column_; ++j ) {
2611 template<
typename MatrixType2,
typename IteratorType2 >
friend class RowIterator;
2612 template<
typename MT2,
bool SO2,
bool SF2 >
friend class SparseRow;
2619 typedef RowIterator<const MT,typename MT::ConstIterator>
ConstIterator;
2622 typedef typename IfTrue< useConst, ConstIterator, RowIterator<MT,typename MT::Iterator> >::Type
Iterator;
2627 enum { smpAssignable = 0 };
2633 explicit inline SparseRow( MT& matrix,
size_t index );
2646 inline ConstReference
operator[](
size_t index )
const;
2647 inline Iterator
begin ();
2648 inline ConstIterator
begin ()
const;
2649 inline ConstIterator
cbegin()
const;
2650 inline Iterator
end ();
2651 inline ConstIterator
end ()
const;
2652 inline ConstIterator
cend ()
const;
2661 template<
typename VT >
inline SparseRow& operator+=(
const Vector<VT,true>& rhs );
2662 template<
typename VT >
inline SparseRow& operator-=(
const Vector<VT,true>& rhs );
2663 template<
typename VT >
inline SparseRow& operator*=(
const Vector<VT,true>& rhs );
2665 template<
typename Other >
2666 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
2667 operator*=( Other rhs );
2669 template<
typename Other >
2670 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
2671 operator/=( Other rhs );
2678 inline size_t size()
const;
2681 inline void reset();
2682 inline Iterator
set (
size_t index,
const ElementType& value );
2683 inline Iterator
insert (
size_t index,
const ElementType& value );
2684 inline void erase (
size_t index );
2685 inline Iterator
erase ( Iterator pos );
2686 inline Iterator
erase ( Iterator first, Iterator last );
2687 inline void reserve(
size_t n );
2688 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
2695 inline Iterator
find (
size_t index );
2696 inline ConstIterator
find (
size_t index )
const;
2698 inline ConstIterator
lowerBound(
size_t index )
const;
2700 inline ConstIterator
upperBound(
size_t index )
const;
2707 inline void append(
size_t index,
const ElementType& value,
bool check=
false );
2714 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
2715 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
2717 template<
typename VT >
inline void assign (
const DenseVector <VT,true>& rhs );
2718 template<
typename VT >
inline void assign (
const SparseVector<VT,true>& rhs );
2719 template<
typename VT >
inline void addAssign(
const Vector<VT,true>& rhs );
2720 template<
typename VT >
inline void subAssign(
const Vector<VT,true>& rhs );
2728 template<
typename MT2,
bool SO2,
typename VT >
2729 inline typename EnableIf< Not< IsRestricted<MT2> >,
bool >::Type
2730 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Vector<VT,true>& rhs );
2732 template<
typename MT2,
bool SO2,
typename VT >
2733 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2734 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
2736 template<
typename MT2,
bool SO2,
typename VT >
2737 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2738 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
2740 template<
typename MT2,
bool SO2,
typename VT >
2741 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2742 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
2744 template<
typename MT2,
bool SO2,
typename VT >
2745 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
2746 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
2748 template<
typename MT2,
bool SO2,
typename VT >
2749 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
2750 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
2752 template<
typename MT2,
bool SO2,
typename VT >
2753 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
2754 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
2767 template<
typename MT2,
bool SO2,
bool SF2 >
2768 friend bool isSame(
const SparseRow<MT2,SO2,SF2>& a,
const SparseRow<MT2,SO2,SF2>& b );
2770 template<
typename MT2,
bool SO2,
bool SF2 >
2771 friend typename DerestrictTrait< SparseRow<MT2,SO2,SF2> >::Type
2772 derestrict( SparseRow<MT2,SO2,SF2>& dm );
2783 BLAZE_STATIC_ASSERT( !IsRestricted<MT>::value || IsLower<MT>::value || IsUpper<MT>::value );
2806 template<
typename MT >
2812 throw std::invalid_argument(
"Invalid row access index" );
2833 template<
typename MT >
2838 return matrix_(row_,index);
2851 template<
typename MT >
2856 return const_cast<const MT&
>( matrix_ )(row_,index);
2870 template<
typename MT >
2873 return Iterator( matrix_, row_, 0UL );
2887 template<
typename MT >
2904 template<
typename MT >
2921 template<
typename MT >
2938 template<
typename MT >
2955 template<
typename MT >
2986 template<
typename MT >
2995 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
2998 if(
size() != rhs.size() )
2999 throw std::invalid_argument(
"Row sizes do not match" );
3001 if( !preservesInvariant( matrix_, rhs ) )
3002 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
3004 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
3006 if( rhs.canAlias( &matrix_ ) ) {
3007 const ResultType tmp( rhs );
3037 template<
typename MT >
3038 template<
typename VT >
3044 throw std::invalid_argument(
"Vector sizes do not match" );
3048 if( !preservesInvariant( matrix_, tmp ) )
3049 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
3051 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
3078 template<
typename MT >
3079 template<
typename VT >
3080 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator+=(
const Vector<VT,true>& rhs )
3090 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3096 throw std::invalid_argument(
"Vector sizes do not match" );
3098 const AddType tmp( *
this + (~rhs) );
3100 if( !preservesInvariant( matrix_, tmp ) )
3101 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
3103 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
3130 template<
typename MT >
3131 template<
typename VT >
3132 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator-=(
const Vector<VT,true>& rhs )
3142 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3148 throw std::invalid_argument(
"Vector sizes do not match" );
3150 const SubType tmp( *
this - (~rhs) );
3152 if( !preservesInvariant( matrix_, tmp ) )
3153 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
3155 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
3180 template<
typename MT >
3181 template<
typename VT >
3182 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator*=(
const Vector<VT,true>& rhs )
3192 typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
3198 throw std::invalid_argument(
"Vector sizes do not match" );
3200 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
3202 const MultType tmp( *
this * (~rhs) );
3229 template<
typename MT >
3230 template<
typename Other >
3231 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
3232 SparseRow<MT,false,false>::operator*=( Other rhs )
3237 element->value() *= rhs;
3262 template<
typename MT >
3263 template<
typename Other >
3264 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
3265 SparseRow<MT,false,false>::operator/=( Other rhs )
3271 typedef typename DivTrait<ElementType,Other>::Type DT;
3272 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3276 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3277 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3279 element->value() *= tmp;
3283 element->value() /= rhs;
3306 template<
typename MT >
3309 return matrix_.columns();
3321 template<
typename MT >
3324 return matrix_.columns();
3339 template<
typename MT >
3342 size_t counter( 0UL );
3358 template<
typename MT >
3361 const size_t jbegin( ( IsUpper<MT>::value )
3362 ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
3366 const size_t jend ( ( IsLower<MT>::value )
3367 ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
3372 for(
size_t j=jbegin; j<jend; ++j ) {
3373 matrix_.erase( row_, j );
3393 template<
typename MT >
3397 return Iterator( matrix_, row_, index, matrix_.insert( row_, index, value ) );
3415 template<
typename MT >
3419 return Iterator( matrix_, row_, index, matrix_.set( row_, index, value ) );
3434 template<
typename MT >
3437 matrix_.erase( row_, index );
3452 template<
typename MT >
3455 const size_t column( pos.column_ );
3457 if( column ==
size() )
3460 matrix_.erase( column, pos.pos_ );
3461 return Iterator( matrix_, row_, column+1UL );
3477 template<
typename MT >
3481 for( ; first!=last; ++first ) {
3482 matrix_.erase( first.column_, first.pos_ );
3500 template<
typename MT >
3522 template<
typename MT >
3523 template<
typename Other >
3524 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::scale(
const Other& scalar )
3529 element->value() *= scalar;
3548 template<
typename MT >
3549 template<
typename MT2
3552 inline typename EnableIf< Not< IsRestricted<MT2> >,
bool >::Type
3553 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Vector<VT,true>& rhs )
3575 template<
typename MT >
3576 template<
typename MT2
3579 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3580 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
3586 if( IsUniLower<MT2>::value && !
isOne( (~rhs)[row_] ) )
3589 const size_t ibegin( ( IsStrictlyLower<MT2>::value )?( row_ ):( row_+1UL ) );
3591 for(
size_t i=ibegin; i<
size(); ++i ) {
3614 template<
typename MT >
3615 template<
typename MT2
3618 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3619 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
3627 const bool checkDiagonal( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value );
3628 const RhsIterator last( (~rhs).
end() );
3629 RhsIterator element( (~rhs).lowerBound( ( checkDiagonal )?( row_ ):( row_+1UL ) ) );
3631 if( IsUniLower<MT2>::value ) {
3632 if( element == last || element->index() != row_ || !
isOne( element->value() ) )
3637 for( ; element!=last; ++element ) {
3660 template<
typename MT >
3661 template<
typename MT2
3664 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3665 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
3671 const size_t iend( ( IsStrictlyUpper<MT2>::value )?( row_+1UL ):( row_ ) );
3673 for(
size_t i=0UL; i<iend; ++i ) {
3678 if( IsUniUpper<MT2>::value && !
isOne( (~rhs)[row_] ) )
3699 template<
typename MT >
3700 template<
typename MT2
3703 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
3704 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
3712 const RhsIterator last( (~rhs).lowerBound( ( IsStrictlyUpper<MT2>::value )?( row_+1UL ):( row_ ) ) );
3714 if( IsUniUpper<MT2>::value && ( last == (~rhs).
end() || last->index() != row_ || !
isOne( last->value() ) ) )
3717 for( RhsIterator element=(~rhs).begin(); element!=last; ++element ) {
3740 template<
typename MT >
3741 template<
typename MT2
3744 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
3745 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
3751 for(
size_t i=0UL; i<row_; ++i ) {
3756 for(
size_t i=row_+1UL; i<
size(); ++i ) {
3779 template<
typename MT >
3780 template<
typename MT2
3783 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
3784 SparseRow<MT,false,false>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
3792 for( RhsIterator element=(~rhs).
begin(); element!=(~rhs).
end(); ++element ) {
3793 if( element->index() != row_ && !
isDefault( element->value() ) )
3825 template<
typename MT >
3828 const typename MT::Iterator pos( matrix_.find( row_, index ) );
3830 if( pos != matrix_.end( index ) )
3831 return Iterator( matrix_, row_, index, pos );
3853 template<
typename MT >
3859 if( pos != matrix_.end( index ) )
3881 template<
typename MT >
3885 for(
size_t i=index; i<
size(); ++i )
3887 const typename MT::Iterator pos( matrix_.find( row_, i ) );
3889 if( pos != matrix_.end( i ) )
3890 return Iterator( matrix_, row_, i, pos );
3912 template<
typename MT >
3916 for(
size_t i=index; i<
size(); ++i )
3920 if( pos != matrix_.end( i ) )
3943 template<
typename MT >
3947 for(
size_t i=index+1UL; i<
size(); ++i )
3949 const typename MT::Iterator pos( matrix_.find( row_, i ) );
3951 if( pos != matrix_.end( i ) )
3952 return Iterator( matrix_, row_, i, pos );
3974 template<
typename MT >
3978 for(
size_t i=index+1UL; i<
size(); ++i )
3982 if( pos != matrix_.end( i ) )
4025 template<
typename MT >
4029 matrix_.insert( row_, index, value );
4054 template<
typename MT >
4055 template<
typename Other >
4058 return matrix_.isAliased( alias );
4071 template<
typename MT >
4072 template<
typename Other >
4075 return matrix_.isAliased( alias );
4093 template<
typename MT >
4094 template<
typename VT >
4101 for(
size_t j=0UL; j<(~rhs).
size(); ++j ) {
4102 matrix_(row_,j) = (~rhs)[j];
4121 template<
typename MT >
4122 template<
typename VT >
4132 for( ; j<element->index(); ++j )
4133 matrix_.erase( row_, j );
4134 matrix_(row_,j++) = element->value();
4136 for( ; j<
size(); ++j ) {
4137 matrix_.erase( row_, j );
4156 template<
typename MT >
4157 template<
typename VT >
4162 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4169 const AddType tmp(
serial( *
this + (~rhs) ) );
4188 template<
typename MT >
4189 template<
typename VT >
4194 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4201 const SubType tmp(
serial( *
this - (~rhs) ) );
4228 template<
typename MT >
4229 class SparseRow<MT,false,true> :
public SparseVector< SparseRow<MT,false,true>, true >
4235 typedef typename If< IsExpression<MT>, MT, MT& >::Type
Operand;
4246 enum { useConst = IsConst<MT>::value };
4251 typedef SparseRow<MT,false,true>
This;
4252 typedef typename RowTrait<MT>::Type
ResultType;
4262 typedef typename IfTrue< useConst, ConstReference, typename MT::Reference >::Type
Reference;
4268 typedef typename IfTrue< useConst, ConstIterator, typename MT::Iterator >::Type
Iterator;
4273 enum { smpAssignable = 0 };
4279 explicit inline SparseRow( MT& matrix,
size_t index );
4292 inline ConstReference
operator[](
size_t index )
const;
4293 inline Iterator
begin ();
4294 inline ConstIterator
begin ()
const;
4295 inline ConstIterator
cbegin()
const;
4296 inline Iterator
end ();
4297 inline ConstIterator
end ()
const;
4298 inline ConstIterator
cend ()
const;
4307 template<
typename VT >
inline SparseRow&
operator= (
const DenseVector<VT,true>& rhs );
4308 template<
typename VT >
inline SparseRow&
operator= (
const SparseVector<VT,true>& rhs );
4309 template<
typename VT >
inline SparseRow& operator+=(
const DenseVector<VT,true>& rhs );
4310 template<
typename VT >
inline SparseRow& operator+=(
const SparseVector<VT,true>& rhs );
4311 template<
typename VT >
inline SparseRow& operator-=(
const DenseVector<VT,true>& rhs );
4312 template<
typename VT >
inline SparseRow& operator-=(
const SparseVector<VT,true>& rhs );
4313 template<
typename VT >
inline SparseRow& operator*=(
const Vector<VT,true>& rhs );
4315 template<
typename Other >
4316 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
4317 operator*=( Other rhs );
4319 template<
typename Other >
4320 inline typename EnableIf< IsNumeric<Other>,
SparseRow >::Type&
4321 operator/=( Other rhs );
4328 inline size_t size()
const;
4331 inline void reset();
4332 inline Iterator
set (
size_t index,
const ElementType& value );
4333 inline Iterator
insert (
size_t index,
const ElementType& value );
4334 inline void erase (
size_t index );
4335 inline Iterator
erase ( Iterator pos );
4336 inline Iterator
erase ( Iterator first, Iterator last );
4337 inline void reserve(
size_t n );
4338 template<
typename Other >
inline SparseRow& scale (
const Other& scalar );
4345 inline Iterator
find (
size_t index );
4346 inline ConstIterator
find (
size_t index )
const;
4348 inline ConstIterator
lowerBound(
size_t index )
const;
4350 inline ConstIterator
upperBound(
size_t index )
const;
4357 inline void append(
size_t index,
const ElementType& value,
bool check=
false );
4364 template<
typename Other >
inline bool canAlias (
const Other* alias )
const;
4365 template<
typename Other >
inline bool isAliased(
const Other* alias )
const;
4367 template<
typename VT >
inline void assign (
const DenseVector <VT,true>& rhs );
4368 template<
typename VT >
inline void assign (
const SparseVector<VT,true>& rhs );
4369 template<
typename VT >
inline void addAssign(
const DenseVector <VT,true>& rhs );
4370 template<
typename VT >
inline void addAssign(
const SparseVector<VT,true>& rhs );
4371 template<
typename VT >
inline void subAssign(
const DenseVector <VT,true>& rhs );
4372 template<
typename VT >
inline void subAssign(
const SparseVector<VT,true>& rhs );
4382 template<
typename MT2,
bool SO2,
typename VT >
4383 inline typename EnableIf< Not< IsRestricted<MT2> >,
bool >::Type
4384 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Vector<VT,true>& rhs );
4386 template<
typename MT2,
bool SO2,
typename VT >
4387 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
4388 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
4390 template<
typename MT2,
bool SO2,
typename VT >
4391 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
4392 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
4394 template<
typename MT2,
bool SO2,
typename VT >
4395 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
4396 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
4398 template<
typename MT2,
bool SO2,
typename VT >
4399 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
4400 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
4402 template<
typename MT2,
bool SO2,
typename VT >
4403 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
4404 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs );
4406 template<
typename MT2,
bool SO2,
typename VT >
4407 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
4408 preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs );
4421 template<
typename MT2,
bool SO2,
bool SF2 >
4422 friend bool isSame(
const SparseRow<MT2,SO2,SF2>& a,
const SparseRow<MT2,SO2,SF2>& b );
4424 template<
typename MT2,
bool SO2,
bool SF2 >
4425 friend typename DerestrictTrait< SparseRow<MT2,SO2,SF2> >::Type
4426 derestrict( SparseRow<MT2,SO2,SF2>& dm );
4437 BLAZE_STATIC_ASSERT( !IsRestricted<MT>::value || IsLower<MT>::value || IsUpper<MT>::value );
4460 template<
typename MT >
4466 throw std::invalid_argument(
"Invalid row access index" );
4487 template<
typename MT >
4492 return matrix_(index,row_);
4505 template<
typename MT >
4510 return const_cast<const MT&
>( matrix_ )(index,row_);
4524 template<
typename MT >
4527 return matrix_.begin( row_ );
4541 template<
typename MT >
4544 return matrix_.cbegin( row_ );
4558 template<
typename MT >
4561 return matrix_.cbegin( row_ );
4575 template<
typename MT >
4578 return matrix_.end( row_ );
4592 template<
typename MT >
4595 return matrix_.cend( row_ );
4609 template<
typename MT >
4612 return matrix_.cend( row_ );
4640 template<
typename MT >
4649 if(
this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
4652 if(
size() != rhs.size() )
4653 throw std::invalid_argument(
"Row sizes do not match" );
4655 if( !preservesInvariant( matrix_, rhs ) )
4656 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4658 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4660 if( rhs.canAlias( &matrix_ ) ) {
4661 const ResultType tmp( rhs );
4663 left.reserve( tmp.nonZeros() );
4668 left.reserve( rhs.nonZeros() );
4695 template<
typename MT >
4696 template<
typename VT >
4697 inline SparseRow<MT,false,true>&
4707 throw std::invalid_argument(
"Vector sizes do not match" );
4709 typedef typename If< IsRestricted<MT>,
typename VT::CompositeType,
const VT& >::Type Right;
4710 Right right( ~rhs );
4712 if( !preservesInvariant( matrix_, right ) )
4713 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4715 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4717 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4750 template<
typename MT >
4751 template<
typename VT >
4752 inline SparseRow<MT,false,true>&
4762 throw std::invalid_argument(
"Vector sizes do not match" );
4764 typedef typename If< IsRestricted<MT>,
typename VT::CompositeType,
const VT& >::Type Right;
4765 Right right( ~rhs );
4767 if( !preservesInvariant( matrix_, right ) )
4768 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4770 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4772 if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4775 left.reserve( tmp.nonZeros() );
4780 left.reserve( right.nonZeros() );
4807 template<
typename MT >
4808 template<
typename VT >
4809 inline SparseRow<MT,false,true>&
4810 SparseRow<MT,false,true>::operator+=(
const DenseVector<VT,true>& rhs )
4821 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4828 throw std::invalid_argument(
"Vector sizes do not match" );
4830 const AddType tmp( *
this + (~rhs) );
4832 if( !preservesInvariant( matrix_, tmp ) )
4833 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4835 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4863 template<
typename MT >
4864 template<
typename VT >
4865 inline SparseRow<MT,false,true>&
4866 SparseRow<MT,false,true>::operator+=(
const SparseVector<VT,true>& rhs )
4877 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4884 throw std::invalid_argument(
"Vector sizes do not match" );
4886 const AddType tmp( *
this + (~rhs) );
4888 if( !preservesInvariant( matrix_, tmp ) )
4889 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4891 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4894 left.reserve( tmp.nonZeros() );
4921 template<
typename MT >
4922 template<
typename VT >
4923 inline SparseRow<MT,false,true>&
4924 SparseRow<MT,false,true>::operator-=(
const DenseVector<VT,true>& rhs )
4935 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4942 throw std::invalid_argument(
"Vector sizes do not match" );
4944 const SubType tmp( *
this - (~rhs) );
4946 if( !preservesInvariant( matrix_, tmp ) )
4947 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
4949 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
4978 template<
typename MT >
4979 template<
typename VT >
4980 inline SparseRow<MT,false,true>&
4981 SparseRow<MT,false,true>::operator-=(
const SparseVector<VT,true>& rhs )
4992 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4999 throw std::invalid_argument(
"Vector sizes do not match" );
5001 const SubType tmp( *
this - (~rhs) );
5003 if( !preservesInvariant( matrix_, tmp ) )
5004 throw std::invalid_argument(
"Invalid assignment to restricted matrix" );
5006 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
5009 left.reserve( tmp.nonZeros() );
5033 template<
typename MT >
5034 template<
typename VT >
5035 inline SparseRow<MT,false,true>&
5036 SparseRow<MT,false,true>::operator*=(
const Vector<VT,true>& rhs )
5046 typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
5052 throw std::invalid_argument(
"Vector sizes do not match" );
5054 typename DerestrictTrait<This>::Type left( derestrict( *
this ) );
5056 const MultType tmp( *
this * (~rhs) );
5084 template<
typename MT >
5085 template<
typename Other >
5086 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
5087 SparseRow<MT,false,true>::operator*=( Other rhs )
5092 element->value() *= rhs;
5117 template<
typename MT >
5118 template<
typename Other >
5119 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
5120 SparseRow<MT,false,true>::operator/=( Other rhs )
5126 typedef typename DivTrait<ElementType,Other>::Type DT;
5127 typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
5131 if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
5132 const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
5134 element->value() *= tmp;
5138 element->value() /= rhs;
5161 template<
typename MT >
5164 return matrix_.columns();
5176 template<
typename MT >
5179 return matrix_.capacity( row_ );
5194 template<
typename MT >
5197 return matrix_.nonZeros( row_ );
5209 template<
typename MT >
5212 matrix_.reset( row_ );
5230 template<
typename MT >
5234 return matrix_.set( index, row_, value );
5253 template<
typename MT >
5257 return matrix_.insert( index, row_, value );
5272 template<
typename MT >
5275 matrix_.erase( index, row_ );
5290 template<
typename MT >
5294 return matrix_.erase( row_, pos );
5310 template<
typename MT >
5314 return matrix_.erase( row_, first, last );
5330 template<
typename MT >
5333 matrix_.reserve( row_, n );
5350 template<
typename MT >
5351 template<
typename Other >
5352 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::scale(
const Other& scalar )
5357 element->value() *= scalar;
5373 template<
typename MT >
5379 size_t nonzeros( 2UL*
capacity()+1UL );
5380 nonzeros =
max( nonzeros, 7UL );
5381 nonzeros =
min( nonzeros,
size() );
5403 template<
typename MT >
5404 template<
typename MT2
5407 inline typename EnableIf< Not< IsRestricted<MT2> >,
bool >::Type
5408 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const Vector<VT,true>& rhs )
5430 template<
typename MT >
5431 template<
typename MT2
5434 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5435 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
5441 if( IsUniLower<MT2>::value && !
isOne( (~rhs)[row_] ) )
5444 const size_t ibegin( ( IsStrictlyLower<MT2>::value )?( row_ ):( row_+1UL ) );
5446 for(
size_t i=ibegin; i<
size(); ++i ) {
5469 template<
typename MT >
5470 template<
typename MT2
5473 inline typename EnableIf< And< IsLower<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5474 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
5482 const bool checkDiagonal( IsUniLower<MT2>::value || IsStrictlyLower<MT2>::value );
5483 const RhsIterator last( (~rhs).
end() );
5484 RhsIterator element( (~rhs).lowerBound( ( checkDiagonal )?( row_ ):( row_+1UL ) ) );
5486 if( IsUniLower<MT2>::value ) {
5487 if( element == last || element->index() != row_ || !
isOne( element->value() ) )
5492 for( ; element!=last; ++element ) {
5515 template<
typename MT >
5516 template<
typename MT2
5519 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5520 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
5526 const size_t iend( ( IsStrictlyUpper<MT2>::value )?( row_+1UL ):( row_ ) );
5528 for(
size_t i=0UL; i<iend; ++i ) {
5533 if( IsUniUpper<MT2>::value && !
isOne( (~rhs)[row_] ) )
5554 template<
typename MT >
5555 template<
typename MT2
5558 inline typename EnableIf< And< IsUpper<MT2>, Not< IsDiagonal<MT2> > >,
bool >::Type
5559 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
5567 const RhsIterator last( (~rhs).lowerBound( ( IsStrictlyUpper<MT2>::value )?( row_+1UL ):( row_ ) ) );
5569 if( IsUniUpper<MT2>::value && ( last == (~rhs).
end() || last->index() != row_ || !
isOne( last->value() ) ) )
5572 for( RhsIterator element=(~rhs).begin(); element!=last; ++element ) {
5595 template<
typename MT >
5596 template<
typename MT2
5599 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5600 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const DenseVector<VT,true>& rhs )
5606 for(
size_t i=0UL; i<row_; ++i ) {
5611 for(
size_t i=row_+1UL; i<
size(); ++i ) {
5634 template<
typename MT >
5635 template<
typename MT2
5638 inline typename EnableIf< IsDiagonal<MT2>,
bool >::Type
5639 SparseRow<MT,false,true>::preservesInvariant(
const SparseMatrix<MT2,SO2>& lhs,
const SparseVector<VT,true>& rhs )
5647 for( RhsIterator element=(~rhs).
begin(); element!=(~rhs).
end(); ++element ) {
5648 if( element->index() != row_ && !
isDefault( element->value() ) )
5680 template<
typename MT >
5684 return matrix_.find( index, row_ );
5704 template<
typename MT >
5708 return matrix_.find( index, row_ );
5727 template<
typename MT >
5731 return matrix_.lowerBound( index, row_ );
5750 template<
typename MT >
5754 return matrix_.lowerBound( index, row_ );
5773 template<
typename MT >
5777 return matrix_.upperBound( index, row_ );
5796 template<
typename MT >
5800 return matrix_.upperBound( index, row_ );
5839 template<
typename MT >
5842 matrix_.append( index, row_, value, check );
5867 template<
typename MT >
5868 template<
typename Other >
5871 return matrix_.isAliased( alias );
5888 template<
typename MT >
5889 template<
typename Other >
5892 return matrix_.isAliased( alias );
5910 template<
typename MT >
5911 template<
typename VT >
5919 for(
size_t i=0UL; i<
size(); ++i )
5921 if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
5922 matrix_.reserve( row_, extendCapacity() );
5924 matrix_.append( i, row_, (~rhs)[i],
true );
5943 template<
typename MT >
5944 template<
typename VT >
5953 matrix_.append( element->index(), row_, element->value(), true );
5972 template<
typename MT >
5973 template<
typename VT >
5978 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
5986 const AddType tmp(
serial( *
this + (~rhs) ) );
5987 matrix_.reset( row_ );
6006 template<
typename MT >
6007 template<
typename VT >
6012 typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
6020 const AddType tmp(
serial( *
this + (~rhs) ) );
6021 matrix_.reset( row_ );
6022 matrix_.reserve( row_, tmp.nonZeros() );
6041 template<
typename MT >
6042 template<
typename VT >
6047 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
6055 const SubType tmp(
serial( *
this - (~rhs) ) );
6056 matrix_.reset( row_ );
6075 template<
typename MT >
6076 template<
typename VT >
6081 typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
6089 const SubType tmp(
serial( *
this - (~rhs) ) );
6090 matrix_.reset( row_ );
6091 matrix_.reserve( row_, tmp.nonZeros() );
6113 template<
typename MT,
bool SO,
bool SF >
6114 inline void reset( SparseRow<MT,SO,SF>& row );
6116 template<
typename MT,
bool SO,
bool SF >
6117 inline void clear( SparseRow<MT,SO,SF>& row );
6119 template<
typename MT,
bool SO,
bool SF >
6120 inline bool isDefault(
const SparseRow<MT,SO,SF>& row );
6122 template<
typename MT,
bool SO,
bool SF >
6123 inline bool isSame(
const SparseRow<MT,SO,SF>& a,
const SparseRow<MT,SO,SF>& b );
6135 template<
typename MT
6154 template<
typename MT
6182 template<
typename MT
6189 const ConstIterator
end( row.end() );
6190 for( ConstIterator element=row.begin(); element!=
end; ++element )
6191 if( !
isDefault( element->value() ) )
return false;
6209 template<
typename MT
6214 return (
isSame( a.matrix_, b.matrix_ ) && ( a.row_ == b.row_ ) );
6234 template<
typename MT
6237 inline typename DerestrictTrait< SparseRow<MT,SO,SF> >::Type
6238 derestrict( SparseRow<MT,SO,SF>& row )
6240 typedef typename DerestrictTrait< SparseRow<MT,SO,SF> >::Type
ReturnType;
6241 return ReturnType( derestrict( row.matrix_ ), row.row_ );
6257 template<
typename MT,
bool SO,
bool SF >
6258 struct IsRestricted< SparseRow<MT,SO,SF> > :
public If< IsRestricted<MT>, TrueType, FalseType >::Type
6260 enum { value = IsRestricted<MT>::value };
6277 template<
typename MT,
bool SO,
bool SF >
6278 struct DerestrictTrait< SparseRow<MT,SO,SF> >
6280 typedef SparseRow< typename RemoveReference< typename DerestrictTrait<MT>::Type >::Type > Type;
6296 template<
typename MT,
bool SO,
bool SF >
6297 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:1649
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.
#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.
Header file for the IsUniUpper type trait.
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:8247
Header file for the subtraction trait.
SparseRow< MT, SO, SF > This
Type of this SparseRow instance.
Definition: SparseRow.h:393
Header file for basic type definitions.
Header file for the SparseVector base class.
SparseRow & operator=(const SparseRow &rhs)
Copy assignment operator for SparseRow.
Definition: SparseRow.h:785
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
Header file for the row trait.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse row.
Definition: SparseRow.h:1970
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
Header file for the row base class.
Header file for the IsDiagonal type trait.
#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:1299
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
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2507
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
Header file for the And class template.
bool canAlias(const Other *alias) const
Returns whether the sparse row can alias with the given address alias.
Definition: SparseRow.h:1999
Compile time check for lower triangular matrices.This type trait tests whether or not the given templ...
Definition: IsLower.h:90
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:118
size_t nonZeros() const
Returns the number of non-zero elements in the row.
Definition: SparseRow.h:1332
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
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
#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
Compile time check for upper triangular matrices.This type trait tests whether or not the given templ...
Definition: IsUpper.h:90
#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
Header file for the RequiresEvaluation type trait.
Header file for the IsUniLower type trait.
size_t extendCapacity() const
Calculating a new sparse row capacity.
Definition: SparseRow.h:1510
bool isLower(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a lower triangular matrix.
Definition: DenseMatrix.h:964
Base class for sparse matrices.The SparseMatrix class is a base class for all sparse matrix classes...
Definition: Forward.h:107
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
void subAssign(const DenseVector< VT, true > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseRow.h:2173
Compile time check for data types with restricted data access.This type trait tests whether the given...
Definition: IsRestricted.h:82
Constraint on the data type.
Base template for the RowTrait class.
Definition: RowTrait.h:115
Compile time check for upper unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniUpper.h:85
IfTrue< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant row value.
Definition: SparseRow.h:404
ConstIterator cbegin() const
Returns an iterator to the first element of the row.
Definition: SparseRow.h:703
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Constraint on the data type.
Header file for the IsFloatingPoint type trait.
void erase(size_t index)
Erasing an element from the sparse row.
Definition: SparseRow.h:1410
#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 SparseRow & CompositeType
Data type for composite expression templates.
Definition: SparseRow.h:398
Operand matrix_
The sparse matrix containing the row.
Definition: SparseRow.h:557
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Header file for the Or class template.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseRow.h:397
void reset()
Reset to the default initial values.
Definition: SparseRow.h:1347
void reserve(size_t n)
Setting the minimum capacity of the sparse row.
Definition: SparseRow.h:1467
size_t capacity() const
Returns the maximum capacity of the sparse row.
Definition: SparseRow.h:1314
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1602
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
Header file for the subvector trait.
RowTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseRow.h:394
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseRow.h:407
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Header file for the IsLower type trait.
#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.
MT::ConstReference ConstReference
Reference to a constant row value.
Definition: SparseRow.h:401
Header file for the SparseElement base class.
Constraint on the data type.
MT::ElementType ElementType
Type of the row elements.
Definition: SparseRow.h:396
void addAssign(const DenseVector< VT, true > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseRow.h:2104
bool isUpper(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is an upper triangular matrix.
Definition: DenseMatrix.h:1197
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:633
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 strictly upper triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyUpper.h:86
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
SparseRow(MT &matrix, size_t index)
The constructor for SparseRow.
Definition: SparseRow.h:606
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
Constraint on the data type.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse row.
Definition: SparseRow.h:1392
If< IsExpression< MT >, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseRow.h:377
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse row.
Definition: SparseRow.h:1369
Header file for the serial shim.
Header file for the isOne shim.
Compile time check for lower unitriangular matrices.This type trait tests whether or not the given te...
Definition: IsUniLower.h:85
Header file for the DerestrictTrait class template.
Constraint on the data type.
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:2506
Header file for the IsConst type trait.
Iterator end()
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:720
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:150
Base template for the MultTrait class.
Definition: MultTrait.h:150
Header file for the addition trait.
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.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_RESTRICTED(T)
Constraint on the data type.In case the given data type T does have a restricted data access...
Definition: Restricted.h:118
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.
Compile time type negation.The Not class template negates the given compile time condition. In case the given condition would evaluate to true, the nested member enumeration is set to false and vice versa:
Definition: Not.h:70
#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:2510
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
#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
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
Header file for the IsReference type trait.
Header file for the RemoveReference type trait.
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:150
Iterator find(size_t index)
Searches for a specific row element.
Definition: SparseRow.h:1817
bool isAliased(const Other *alias) const
Returns whether the sparse row is aliased with the given address alias.
Definition: SparseRow.h:2020
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseRow.h:1862
Compile time check for strictly lower triangular matrices.This type trait tests whether or not the gi...
Definition: IsStrictlyLower.h:86
#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
IfTrue< useConst, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseRow.h:410
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
boost::false_type FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:260
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:2502
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Compile time type check.This class tests whether the given template parameter T is a reference type (...
Definition: IsReference.h:94
#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
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseRow.h:395
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
Base template for the SubTrait class.
Definition: SubTrait.h:150
Header file for the IsUpper type trait.
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
ConstIterator cend() const
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:754
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
EnableIf< IsNumeric< Type >, bool >::Type isOne(const Type &v)
Returns whether the given value/object represents the numeric value 1.
Definition: IsOne.h:80
Header file for the IsRestricted type trait.
Iterator begin()
Returns an iterator to the first element of the row.
Definition: SparseRow.h:669
#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:1906
#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
const size_t row_
The index of the row in the matrix.
Definition: SparseRow.h:558
Compile time type selection.The IfTrue class template selects one of the two given types T1 and T2 de...
Definition: If.h:59
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
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:2042