Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SUBVECTOR_SPARSE_H_
36 #define _BLAZE_MATH_VIEWS_SUBVECTOR_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <blaze/math/Aliases.h>
54 #include <blaze/math/Exception.h>
70 #include <blaze/math/views/Check.h>
73 #include <blaze/util/Assert.h>
74 #include <blaze/util/DisableIf.h>
75 #include <blaze/util/mpl/If.h>
76 #include <blaze/util/TypeList.h>
77 #include <blaze/util/Types.h>
82 
83 
84 namespace blaze {
85 
86 //=================================================================================================
87 //
88 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE SUBVECTORS
89 //
90 //=================================================================================================
91 
92 //*************************************************************************************************
100 template< typename VT // Type of the sparse vector
101  , AlignmentFlag AF // Alignment flag
102  , bool TF // Transpose flag
103  , size_t... CSAs > // Compile time subvector arguments
104 class Subvector<VT,AF,TF,false,CSAs...>
105  : public View< SparseVector< Subvector<VT,AF,TF,false,CSAs...>, TF > >
106  , private SubvectorData<CSAs...>
107 {
108  private:
109  //**Type definitions****************************************************************************
110  using DataType = SubvectorData<CSAs...>;
111  using Operand = If_< IsExpression<VT>, VT, VT& >;
112  //**********************************************************************************************
113 
114  public:
115  //**Type definitions****************************************************************************
117  using This = Subvector<VT,AF,TF,false,CSAs...>;
118 
119  using BaseType = SparseVector<This,TF>;
120  using ViewedType = VT;
121  using ResultType = SubvectorTrait_<VT,CSAs...>;
122  using TransposeType = TransposeType_<ResultType>;
123  using ElementType = ElementType_<VT>;
124  using ReturnType = ReturnType_<VT>;
125  using CompositeType = const Subvector&;
126 
128  using ConstReference = ConstReference_<VT>;
129 
131  using Reference = If_< IsConst<VT>, ConstReference, Reference_<VT> >;
132  //**********************************************************************************************
133 
134  //**SubvectorElement class definition***********************************************************
137  template< typename VectorType // Type of the sparse vector
138  , typename IteratorType > // Type of the sparse vector iterator
139  class SubvectorElement
140  : private SparseElement
141  {
142  public:
143  //**Constructor******************************************************************************
149  inline SubvectorElement( IteratorType pos, size_t offset )
150  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
151  , offset_( offset ) // Offset within the according sparse vector
152  {}
153  //*******************************************************************************************
154 
155  //**Assignment operator**********************************************************************
161  template< typename T > inline SubvectorElement& operator=( const T& v ) {
162  *pos_ = v;
163  return *this;
164  }
165  //*******************************************************************************************
166 
167  //**Addition assignment operator*************************************************************
173  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
174  *pos_ += v;
175  return *this;
176  }
177  //*******************************************************************************************
178 
179  //**Subtraction assignment operator**********************************************************
185  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
186  *pos_ -= v;
187  return *this;
188  }
189  //*******************************************************************************************
190 
191  //**Multiplication assignment operator*******************************************************
197  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
198  *pos_ *= v;
199  return *this;
200  }
201  //*******************************************************************************************
202 
203  //**Division assignment operator*************************************************************
209  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
210  *pos_ /= v;
211  return *this;
212  }
213  //*******************************************************************************************
214 
215  //**Element access operator******************************************************************
220  inline const SubvectorElement* operator->() const {
221  return this;
222  }
223  //*******************************************************************************************
224 
225  //**Value function***************************************************************************
230  inline decltype(auto) value() const {
231  return pos_->value();
232  }
233  //*******************************************************************************************
234 
235  //**Index function***************************************************************************
240  inline size_t index() const {
241  return pos_->index() - offset_;
242  }
243  //*******************************************************************************************
244 
245  private:
246  //**Member variables*************************************************************************
247  IteratorType pos_;
248  size_t offset_;
249  //*******************************************************************************************
250  };
251  //**********************************************************************************************
252 
253  //**SubvectorIterator class definition**********************************************************
256  template< typename VectorType // Type of the sparse vector
257  , typename IteratorType > // Type of the sparse vector iterator
258  class SubvectorIterator
259  {
260  public:
261  //**Type definitions*************************************************************************
262  using IteratorCategory = std::forward_iterator_tag;
263  using ValueType = SubvectorElement<VectorType,IteratorType>;
264  using PointerType = ValueType;
265  using ReferenceType = ValueType;
266  using DifferenceType = ptrdiff_t;
267 
268  // STL iterator requirements
269  using iterator_category = IteratorCategory;
270  using value_type = ValueType;
271  using pointer = PointerType;
272  using reference = ReferenceType;
273  using difference_type = DifferenceType;
274  //*******************************************************************************************
275 
276  //**Default constructor**********************************************************************
279  inline SubvectorIterator()
280  : pos_ () // Iterator to the current sparse element
281  , offset_() // The offset of the subvector within the sparse vector
282  {}
283  //*******************************************************************************************
284 
285  //**Constructor******************************************************************************
291  inline SubvectorIterator( IteratorType iterator, size_t index )
292  : pos_ ( iterator ) // Iterator to the current sparse element
293  , offset_( index ) // The offset of the subvector within the sparse vector
294  {}
295  //*******************************************************************************************
296 
297  //**Constructor******************************************************************************
302  template< typename VectorType2, typename IteratorType2 >
303  inline SubvectorIterator( const SubvectorIterator<VectorType2,IteratorType2>& it )
304  : pos_ ( it.base() ) // Iterator to the current sparse element.
305  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
306  {}
307  //*******************************************************************************************
308 
309  //**Prefix increment operator****************************************************************
314  inline SubvectorIterator& operator++() {
315  ++pos_;
316  return *this;
317  }
318  //*******************************************************************************************
319 
320  //**Postfix increment operator***************************************************************
325  inline const SubvectorIterator operator++( int ) {
326  const SubvectorIterator tmp( *this );
327  ++(*this);
328  return tmp;
329  }
330  //*******************************************************************************************
331 
332  //**Element access operator******************************************************************
337  inline ReferenceType operator*() const {
338  return ReferenceType( pos_, offset_ );
339  }
340  //*******************************************************************************************
341 
342  //**Element access operator******************************************************************
347  inline PointerType operator->() const {
348  return PointerType( pos_, offset_ );
349  }
350  //*******************************************************************************************
351 
352  //**Equality operator************************************************************************
358  template< typename VectorType2, typename IteratorType2 >
359  inline bool operator==( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
360  return base() == rhs.base();
361  }
362  //*******************************************************************************************
363 
364  //**Inequality operator**********************************************************************
370  template< typename VectorType2, typename IteratorType2 >
371  inline bool operator!=( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
372  return !( *this == rhs );
373  }
374  //*******************************************************************************************
375 
376  //**Subtraction operator*********************************************************************
382  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
383  return pos_ - rhs.pos_;
384  }
385  //*******************************************************************************************
386 
387  //**Base function****************************************************************************
392  inline IteratorType base() const {
393  return pos_;
394  }
395  //*******************************************************************************************
396 
397  //**Offset function**************************************************************************
402  inline size_t offset() const noexcept {
403  return offset_;
404  }
405  //*******************************************************************************************
406 
407  private:
408  //**Member variables*************************************************************************
409  IteratorType pos_;
410  size_t offset_;
411  //*******************************************************************************************
412  };
413  //**********************************************************************************************
414 
415  //**Type definitions****************************************************************************
417  using ConstIterator = SubvectorIterator< const VT, ConstIterator_<VT> >;
418 
420  using Iterator = If_< IsConst<VT>, ConstIterator, SubvectorIterator< VT, Iterator_<VT> > >;
421  //**********************************************************************************************
422 
423  //**Compilation flags***************************************************************************
425  enum : bool { smpAssignable = VT::smpAssignable };
426  //**********************************************************************************************
427 
428  //**Constructors********************************************************************************
431  template< typename... RSAs >
432  explicit inline Subvector( VT& vector, RSAs... args );
433  // No explicitly declared copy constructor.
435  //**********************************************************************************************
436 
437  //**Destructor**********************************************************************************
438  // No explicitly declared destructor.
439  //**********************************************************************************************
440 
441  //**Data access functions***********************************************************************
444  inline Reference operator[]( size_t index );
445  inline ConstReference operator[]( size_t index ) const;
446  inline Reference at( size_t index );
447  inline ConstReference at( size_t index ) const;
448  inline Iterator begin ();
449  inline ConstIterator begin () const;
450  inline ConstIterator cbegin() const;
451  inline Iterator end ();
452  inline ConstIterator end () const;
453  inline ConstIterator cend () const;
455  //**********************************************************************************************
456 
457  //**Assignment operators************************************************************************
460  inline Subvector& operator= ( initializer_list<ElementType> list );
461  inline Subvector& operator= ( const Subvector& rhs );
462  template< typename VT2 > inline Subvector& operator= ( const Vector<VT2,TF>& rhs );
463  template< typename VT2 > inline Subvector& operator+=( const Vector<VT2,TF>& rhs );
464  template< typename VT2 > inline Subvector& operator-=( const Vector<VT2,TF>& rhs );
465  template< typename VT2 > inline Subvector& operator*=( const Vector<VT2,TF>& rhs );
466  template< typename VT2 > inline Subvector& operator/=( const DenseVector<VT2,TF>& rhs );
467  template< typename VT2 > inline Subvector& operator%=( const Vector<VT2,TF>& rhs );
469  //**********************************************************************************************
470 
471  //**Utility functions***************************************************************************
474  using DataType::offset;
475  using DataType::size;
476 
477  inline VT& operand() noexcept;
478  inline const VT& operand() const noexcept;
479 
480  inline size_t capacity() const noexcept;
481  inline size_t nonZeros() const;
482  inline void reset();
483  inline void reserve( size_t n );
485  //**********************************************************************************************
486 
487  //**Insertion functions*************************************************************************
490  inline Iterator set ( size_t index, const ElementType& value );
491  inline Iterator insert( size_t index, const ElementType& value );
492  inline void append( size_t index, const ElementType& value, bool check=false );
494  //**********************************************************************************************
495 
496  //**Erase functions*****************************************************************************
499  inline void erase( size_t index );
500  inline Iterator erase( Iterator pos );
501  inline Iterator erase( Iterator first, Iterator last );
502 
503  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
504  inline void erase( Pred predicate );
505 
506  template< typename Pred >
507  inline void erase( Iterator first, Iterator last, Pred predicate );
509  //**********************************************************************************************
510 
511  //**Lookup functions****************************************************************************
514  inline Iterator find ( size_t index );
515  inline ConstIterator find ( size_t index ) const;
516  inline Iterator lowerBound( size_t index );
517  inline ConstIterator lowerBound( size_t index ) const;
518  inline Iterator upperBound( size_t index );
519  inline ConstIterator upperBound( size_t index ) const;
521  //**********************************************************************************************
522 
523  //**Numeric functions***************************************************************************
526  template< typename Other > inline Subvector& scale( const Other& scalar );
528  //**********************************************************************************************
529 
530  //**Expression template evaluation functions****************************************************
533  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
534  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
535 
536  inline bool canSMPAssign() const noexcept;
537 
538  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
539  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
540  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
541  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
542  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
543  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
545  //**********************************************************************************************
546 
547  private:
548  //**Member variables****************************************************************************
551  Operand vector_;
552 
553  //**********************************************************************************************
554 
555  //**Compile time checks*************************************************************************
561  //**********************************************************************************************
562 };
564 //*************************************************************************************************
565 
566 
567 
568 
569 //=================================================================================================
570 //
571 // CONSTRUCTORS
572 //
573 //=================================================================================================
574 
575 //*************************************************************************************************
589 template< typename VT // Type of the sparse vector
590  , AlignmentFlag AF // Alignment flag
591  , bool TF // Transpose flag
592  , size_t... CSAs > // Compile time subvector arguments
593 template< typename... RSAs > // Runtime subvector arguments
594 inline Subvector<VT,AF,TF,false,CSAs...>::Subvector( VT& vector, RSAs... args )
595  : DataType( args... ) // Base class initialization
596  , vector_ ( vector ) // The vector containing the subvector
597 {
598  if( !Contains< TypeList<RSAs...>, Unchecked >::value ) {
599  if( offset() + size() > vector.size() ) {
600  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
601  }
602  }
603  else {
604  BLAZE_USER_ASSERT( offset() + size() <= vector.size(), "Invalid subvector specification" );
605  }
606 }
608 //*************************************************************************************************
609 
610 
611 
612 
613 //=================================================================================================
614 //
615 // DATA ACCESS FUNCTIONS
616 //
617 //=================================================================================================
618 
619 //*************************************************************************************************
629 template< typename VT // Type of the sparse vector
630  , AlignmentFlag AF // Alignment flag
631  , bool TF // Transpose flag
632  , size_t... CSAs > // Compile time subvector arguments
633 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
634  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index )
635 {
636  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
637  return vector_[offset()+index];
638 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
653 template< typename VT // Type of the sparse vector
654  , AlignmentFlag AF // Alignment flag
655  , bool TF // Transpose flag
656  , size_t... CSAs > // Compile time subvector arguments
657 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
658  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index ) const
659 {
660  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
661  return const_cast<const VT&>( vector_ )[offset()+index];
662 }
664 //*************************************************************************************************
665 
666 
667 //*************************************************************************************************
678 template< typename VT // Type of the sparse vector
679  , AlignmentFlag AF // Alignment flag
680  , bool TF // Transpose flag
681  , size_t... CSAs > // Compile time subvector arguments
682 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
683  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index )
684 {
685  if( index >= size() ) {
686  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
687  }
688  return (*this)[index];
689 }
691 //*************************************************************************************************
692 
693 
694 //*************************************************************************************************
705 template< typename VT // Type of the sparse vector
706  , AlignmentFlag AF // Alignment flag
707  , bool TF // Transpose flag
708  , size_t... CSAs > // Compile time subvector arguments
709 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
710  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index ) const
711 {
712  if( index >= size() ) {
713  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
714  }
715  return (*this)[index];
716 }
718 //*************************************************************************************************
719 
720 
721 //*************************************************************************************************
729 template< typename VT // Type of the sparse vector
730  , AlignmentFlag AF // Alignment flag
731  , bool TF // Transpose flag
732  , size_t... CSAs > // Compile time subvector arguments
733 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
735 {
736  if( offset() == 0UL )
737  return Iterator( vector_.begin(), offset() );
738  else
739  return Iterator( vector_.lowerBound( offset() ), offset() );
740 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
753 template< typename VT // Type of the sparse vector
754  , AlignmentFlag AF // Alignment flag
755  , bool TF // Transpose flag
756  , size_t... CSAs > // Compile time subvector arguments
757 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
759 {
760  if( offset() == 0UL )
761  return ConstIterator( vector_.cbegin(), offset() );
762  else
763  return ConstIterator( vector_.lowerBound( offset() ), offset() );
764 }
766 //*************************************************************************************************
767 
768 
769 //*************************************************************************************************
777 template< typename VT // Type of the sparse vector
778  , AlignmentFlag AF // Alignment flag
779  , bool TF // Transpose flag
780  , size_t... CSAs > // Compile time subvector arguments
781 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
783 {
784  if( offset() == 0UL )
785  return ConstIterator( vector_.cbegin(), offset() );
786  else
787  return ConstIterator( vector_.lowerBound( offset() ), offset() );
788 }
790 //*************************************************************************************************
791 
792 
793 //*************************************************************************************************
801 template< typename VT // Type of the sparse vector
802  , AlignmentFlag AF // Alignment flag
803  , bool TF // Transpose flag
804  , size_t... CSAs > // Compile time subvector arguments
805 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
807 {
808  if( offset() + size() == vector_.size() )
809  return Iterator( vector_.end(), offset() );
810  else
811  return Iterator( vector_.lowerBound( offset() + size() ), offset() );
812 }
814 //*************************************************************************************************
815 
816 
817 //*************************************************************************************************
825 template< typename VT // Type of the sparse vector
826  , AlignmentFlag AF // Alignment flag
827  , bool TF // Transpose flag
828  , size_t... CSAs > // Compile time subvector arguments
829 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
831 {
832  if( offset() + size() == vector_.size() )
833  return ConstIterator( vector_.cend(), offset() );
834  else
835  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
836 }
838 //*************************************************************************************************
839 
840 
841 //*************************************************************************************************
849 template< typename VT // Type of the sparse vector
850  , AlignmentFlag AF // Alignment flag
851  , bool TF // Transpose flag
852  , size_t... CSAs > // Compile time subvector arguments
853 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
855 {
856  if( offset() + size() == vector_.size() )
857  return ConstIterator( vector_.cend(), offset() );
858  else
859  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
860 }
862 //*************************************************************************************************
863 
864 
865 
866 
867 //=================================================================================================
868 //
869 // ASSIGNMENT OPERATORS
870 //
871 //=================================================================================================
872 
873 //*************************************************************************************************
888 template< typename VT // Type of the sparse vector
889  , AlignmentFlag AF // Alignment flag
890  , bool TF // Transpose flag
891  , size_t... CSAs > // Compile time subvector arguments
892 inline Subvector<VT,AF,TF,false,CSAs...>&
893  Subvector<VT,AF,TF,false,CSAs...>::operator=( initializer_list<ElementType> list )
894 {
895  using blaze::assign;
896 
897  if( list.size() > size() ) {
898  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to subvector" );
899  }
900 
901  const InitializerVector<ElementType,TF> tmp( list, size() );
902 
903  if( !tryAssign( vector_, tmp, offset() ) ) {
904  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
905  }
906 
907  decltype(auto) left( derestrict( *this ) );
908 
909  reset();
910  assign( left, tmp );
911 
912  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
913 
914  return *this;
915 }
917 //*************************************************************************************************
918 
919 
920 //*************************************************************************************************
932 template< typename VT // Type of the sparse vector
933  , AlignmentFlag AF // Alignment flag
934  , bool TF // Transpose flag
935  , size_t... CSAs > // Compile time subvector arguments
936 inline Subvector<VT,AF,TF,false,CSAs...>&
937  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Subvector& rhs )
938 {
939  using blaze::assign;
940 
943 
944  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset() == rhs.offset() ) )
945  return *this;
946 
947  if( size() != rhs.size() ) {
948  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
949  }
950 
951  if( !tryAssign( vector_, rhs, offset() ) ) {
952  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
953  }
954 
955  decltype(auto) left( derestrict( *this ) );
956 
957  if( rhs.canAlias( &vector_ ) ) {
958  const ResultType tmp( rhs );
959  reset();
960  assign( left, tmp );
961  }
962  else {
963  reset();
964  assign( left, rhs );
965  }
966 
967  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
968 
969  return *this;
970 }
972 //*************************************************************************************************
973 
974 
975 //*************************************************************************************************
987 template< typename VT // Type of the sparse vector
988  , AlignmentFlag AF // Alignment flag
989  , bool TF // Transpose flag
990  , size_t... CSAs > // Compile time subvector arguments
991 template< typename VT2 > // Type of the right-hand side vector
992 inline Subvector<VT,AF,TF,false,CSAs...>&
993  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Vector<VT2,TF>& rhs )
994 {
995  using blaze::assign;
996 
999 
1000  if( size() != (~rhs).size() ) {
1001  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1002  }
1003 
1004  using Right = If_< IsRestricted<VT>, CompositeType_<VT2>, const VT2& >;
1005  Right right( ~rhs );
1006 
1007  if( !tryAssign( vector_, right, offset() ) ) {
1008  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1009  }
1010 
1011  decltype(auto) left( derestrict( *this ) );
1012 
1013  if( IsReference<Right>::value || right.canAlias( &vector_ ) ) {
1014  const ResultType_<VT2> tmp( right );
1015  reset();
1016  assign( left, tmp );
1017  }
1018  else {
1019  reset();
1020  assign( left, right );
1021  }
1022 
1023  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1024 
1025  return *this;
1026 }
1028 //*************************************************************************************************
1029 
1030 
1031 //*************************************************************************************************
1043 template< typename VT // Type of the sparse vector
1044  , AlignmentFlag AF // Alignment flag
1045  , bool TF // Transpose flag
1046  , size_t... CSAs > // Compile time subvector arguments
1047 template< typename VT2 > // Type of the right-hand side vector
1048 inline Subvector<VT,AF,TF,false,CSAs...>&
1049  Subvector<VT,AF,TF,false,CSAs...>::operator+=( const Vector<VT2,TF>& rhs )
1050 {
1051  using blaze::assign;
1052 
1056 
1057  using AddType = AddTrait_< ResultType, ResultType_<VT2> >;
1058 
1061 
1062  if( size() != (~rhs).size() ) {
1063  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1064  }
1065 
1066  const AddType tmp( *this + (~rhs) );
1067 
1068  if( !tryAssign( vector_, tmp, offset() ) ) {
1069  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1070  }
1071 
1072  decltype(auto) left( derestrict( *this ) );
1073 
1074  left.reset();
1075  assign( left, tmp );
1076 
1077  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1078 
1079  return *this;
1080 }
1082 //*************************************************************************************************
1083 
1084 
1085 //*************************************************************************************************
1097 template< typename VT // Type of the sparse vector
1098  , AlignmentFlag AF // Alignment flag
1099  , bool TF // Transpose flag
1100  , size_t... CSAs > // Compile time subvector arguments
1101 template< typename VT2 > // Type of the right-hand side vector
1102 inline Subvector<VT,AF,TF,false,CSAs...>&
1103  Subvector<VT,AF,TF,false,CSAs...>::operator-=( const Vector<VT2,TF>& rhs )
1104 {
1105  using blaze::assign;
1106 
1110 
1111  using SubType = SubTrait_< ResultType, ResultType_<VT2> >;
1112 
1115 
1116  if( size() != (~rhs).size() ) {
1117  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1118  }
1119 
1120  const SubType tmp( *this - (~rhs) );
1121 
1122  if( !tryAssign( vector_, tmp, offset() ) ) {
1123  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1124  }
1125 
1126  decltype(auto) left( derestrict( *this ) );
1127 
1128  left.reset();
1129  assign( left, tmp );
1130 
1131  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1132 
1133  return *this;
1134 }
1136 //*************************************************************************************************
1137 
1138 
1139 //*************************************************************************************************
1152 template< typename VT // Type of the sparse vector
1153  , AlignmentFlag AF // Alignment flag
1154  , bool TF // Transpose flag
1155  , size_t... CSAs > // Compile time subvector arguments
1156 template< typename VT2 > // Type of the right-hand side vector
1157 inline Subvector<VT,AF,TF,false,CSAs...>&
1158  Subvector<VT,AF,TF,false,CSAs...>::operator*=( const Vector<VT2,TF>& rhs )
1159 {
1160  using blaze::assign;
1161 
1165 
1166  using MultType = MultTrait_< ResultType, ResultType_<VT2> >;
1167 
1170 
1171  if( size() != (~rhs).size() ) {
1172  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1173  }
1174 
1175  const MultType tmp( *this * (~rhs) );
1176 
1177  if( !tryAssign( vector_, tmp, offset() ) ) {
1178  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1179  }
1180 
1181  decltype(auto) left( derestrict( *this ) );
1182 
1183  left.reset();
1184  assign( left, tmp );
1185 
1186  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1187 
1188  return *this;
1189 }
1191 //*************************************************************************************************
1192 
1193 
1194 //*************************************************************************************************
1206 template< typename VT // Type of the sparse vector
1207  , AlignmentFlag AF // Alignment flag
1208  , bool TF // Transpose flag
1209  , size_t... CSAs > // Compile time subvector arguments
1210 template< typename VT2 > // Type of the right-hand side dense vector
1211 inline Subvector<VT,AF,TF,false,CSAs...>&
1212  Subvector<VT,AF,TF,false,CSAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1213 {
1214  using blaze::assign;
1215 
1218  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_<VT2> );
1220 
1221  using DivType = DivTrait_< ResultType, ResultType_<VT2> >;
1222 
1226 
1227  if( size() != (~rhs).size() ) {
1228  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1229  }
1230 
1231  const DivType tmp( *this / (~rhs) );
1232 
1233  if( !tryAssign( vector_, tmp, offset() ) ) {
1234  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1235  }
1236 
1237  decltype(auto) left( derestrict( *this ) );
1238 
1239  left.reset();
1240  assign( left, tmp );
1241 
1242  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1243 
1244  return *this;
1245 }
1247 //*************************************************************************************************
1248 
1249 
1250 //*************************************************************************************************
1263 template< typename VT // Type of the sparse vector
1264  , AlignmentFlag AF // Alignment flag
1265  , bool TF // Transpose flag
1266  , size_t... CSAs > // Compile time subvector arguments
1267 template< typename VT2 > // Type of the right-hand side vector
1268 inline Subvector<VT,AF,TF,false,CSAs...>&
1269  Subvector<VT,AF,TF,false,CSAs...>::operator%=( const Vector<VT2,TF>& rhs )
1270 {
1271  using blaze::assign;
1272 
1275 
1276  using CrossType = CrossTrait_< ResultType, ResultType_<VT2> >;
1277 
1281 
1282  if( size() != 3UL || (~rhs).size() != 3UL ) {
1283  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1284  }
1285 
1286  const CrossType tmp( *this % (~rhs) );
1287 
1288  if( !tryAssign( vector_, tmp, offset() ) ) {
1289  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1290  }
1291 
1292  decltype(auto) left( derestrict( *this ) );
1293 
1294  left.reset();
1295  assign( left, tmp );
1296 
1297  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1298 
1299  return *this;
1300 }
1302 //*************************************************************************************************
1303 
1304 
1305 
1306 
1307 //=================================================================================================
1308 //
1309 // UTILITY FUNCTIONS
1310 //
1311 //=================================================================================================
1312 
1313 //*************************************************************************************************
1319 template< typename VT // Type of the sparse vector
1320  , AlignmentFlag AF // Alignment flag
1321  , bool TF // Transpose flag
1322  , size_t... CSAs > // Compile time subvector arguments
1323 inline VT& Subvector<VT,AF,TF,false,CSAs...>::operand() noexcept
1324 {
1325  return vector_;
1326 }
1328 //*************************************************************************************************
1329 
1330 
1331 //*************************************************************************************************
1337 template< typename VT // Type of the sparse vector
1338  , AlignmentFlag AF // Alignment flag
1339  , bool TF // Transpose flag
1340  , size_t... CSAs > // Compile time subvector arguments
1341 inline const VT& Subvector<VT,AF,TF,false,CSAs...>::operand() const noexcept
1342 {
1343  return vector_;
1344 }
1346 //*************************************************************************************************
1347 
1348 
1349 //*************************************************************************************************
1355 template< typename VT // Type of the sparse vector
1356  , AlignmentFlag AF // Alignment flag
1357  , bool TF // Transpose flag
1358  , size_t... CSAs > // Compile time subvector arguments
1359 inline size_t Subvector<VT,AF,TF,false,CSAs...>::capacity() const noexcept
1360 {
1361  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1362 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1375 template< typename VT // Type of the sparse vector
1376  , AlignmentFlag AF // Alignment flag
1377  , bool TF // Transpose flag
1378  , size_t... CSAs > // Compile time subvector arguments
1379 inline size_t Subvector<VT,AF,TF,false,CSAs...>::nonZeros() const
1380 {
1381  return end() - begin();
1382 }
1384 //*************************************************************************************************
1385 
1386 
1387 //*************************************************************************************************
1393 template< typename VT // Type of the sparse vector
1394  , AlignmentFlag AF // Alignment flag
1395  , bool TF // Transpose flag
1396  , size_t... CSAs > // Compile time subvector arguments
1398 {
1399  vector_.erase( vector_.lowerBound( offset() ), vector_.lowerBound( offset() + size() ) );
1400 }
1402 //*************************************************************************************************
1403 
1404 
1405 //*************************************************************************************************
1415 template< typename VT // Type of the sparse vector
1416  , AlignmentFlag AF // Alignment flag
1417  , bool TF // Transpose flag
1418  , size_t... CSAs > // Compile time subvector arguments
1419 void Subvector<VT,AF,TF,false,CSAs...>::reserve( size_t n )
1420 {
1421  const size_t current( capacity() );
1422 
1423  if( n > current ) {
1424  vector_.reserve( vector_.capacity() + n - current );
1425  }
1426 }
1428 //*************************************************************************************************
1429 
1430 
1431 
1432 
1433 //=================================================================================================
1434 //
1435 // INSERTION FUNCTIONS
1436 //
1437 //=================================================================================================
1438 
1439 //*************************************************************************************************
1451 template< typename VT // Type of the sparse vector
1452  , AlignmentFlag AF // Alignment flag
1453  , bool TF // Transpose flag
1454  , size_t... CSAs > // Compile time subvector arguments
1455 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1456  Subvector<VT,AF,TF,false,CSAs...>::set( size_t index, const ElementType& value )
1457 {
1458  return Iterator( vector_.set( offset() + index, value ), offset() );
1459 }
1461 //*************************************************************************************************
1462 
1463 
1464 //*************************************************************************************************
1477 template< typename VT // Type of the sparse vector
1478  , AlignmentFlag AF // Alignment flag
1479  , bool TF // Transpose flag
1480  , size_t... CSAs > // Compile time subvector arguments
1481 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1482  Subvector<VT,AF,TF,false,CSAs...>::insert( size_t index, const ElementType& value )
1483 {
1484  return Iterator( vector_.insert( offset() + index, value ), offset() );
1485 }
1487 //*************************************************************************************************
1488 
1489 
1490 //*************************************************************************************************
1515 template< typename VT // Type of the sparse vector
1516  , AlignmentFlag AF // Alignment flag
1517  , bool TF // Transpose flag
1518  , size_t... CSAs > // Compile time subvector arguments
1519 inline void Subvector<VT,AF,TF,false,CSAs...>::append( size_t index, const ElementType& value, bool check )
1520 {
1521  if( offset() + size() == vector_.size() )
1522  vector_.append( offset() + index, value, check );
1523  else if( !check || !isDefault<strict>( value ) )
1524  vector_.insert( offset() + index, value );
1525 }
1527 //*************************************************************************************************
1528 
1529 
1530 
1531 
1532 //=================================================================================================
1533 //
1534 // ERASE FUNCTIONS
1535 //
1536 //=================================================================================================
1537 
1538 //*************************************************************************************************
1547 template< typename VT // Type of the sparse vector
1548  , AlignmentFlag AF // Alignment flag
1549  , bool TF // Transpose flag
1550  , size_t... CSAs > // Compile time subvector arguments
1551 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( size_t index )
1552 {
1553  vector_.erase( offset() + index );
1554 }
1556 //*************************************************************************************************
1557 
1558 
1559 //*************************************************************************************************
1568 template< typename VT // Type of the sparse vector
1569  , AlignmentFlag AF // Alignment flag
1570  , bool TF // Transpose flag
1571  , size_t... CSAs > // Compile time subvector arguments
1572 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1573  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator pos )
1574 {
1575  return Iterator( vector_.erase( pos.base() ), offset() );
1576 }
1578 //*************************************************************************************************
1579 
1580 
1581 //*************************************************************************************************
1591 template< typename VT // Type of the sparse vector
1592  , AlignmentFlag AF // Alignment flag
1593  , bool TF // Transpose flag
1594  , size_t... CSAs > // Compile time subvector arguments
1595 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1596  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last )
1597 {
1598  return Iterator( vector_.erase( first.base(), last.base() ), offset() );
1599 }
1601 //*************************************************************************************************
1602 
1603 
1604 //*************************************************************************************************
1627 template< typename VT // Type of the sparse vector
1628  , AlignmentFlag AF // Alignment flag
1629  , bool TF // Transpose flag
1630  , size_t... CSAs > // Compile time subvector arguments
1631 template< typename Pred // Type of the unary predicate
1632  , typename > // Type restriction on the unary predicate
1633 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Pred predicate )
1634 {
1635  vector_.erase( begin().base(), end().base(), predicate );
1636 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1667 template< typename VT // Type of the sparse vector
1668  , AlignmentFlag AF // Alignment flag
1669  , bool TF // Transpose flag
1670  , size_t... CSAs > // Compile time subvector arguments
1671 template< typename Pred > // Type of the unary predicate
1672 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last, Pred predicate )
1673 {
1674  vector_.erase( first.base(), last.base(), predicate );
1675 }
1677 //*************************************************************************************************
1678 
1679 
1680 
1681 
1682 //=================================================================================================
1683 //
1684 // LOOKUP FUNCTIONS
1685 //
1686 //=================================================================================================
1687 
1688 //*************************************************************************************************
1702 template< typename VT // Type of the sparse vector
1703  , AlignmentFlag AF // Alignment flag
1704  , bool TF // Transpose flag
1705  , size_t... CSAs > // Compile time subvector arguments
1706 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1707  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index )
1708 {
1709  const Iterator_<VT> pos( vector_.find( offset() + index ) );
1710 
1711  if( pos != vector_.end() )
1712  return Iterator( pos, offset() );
1713  else
1714  return end();
1715 }
1717 //*************************************************************************************************
1718 
1719 
1720 //*************************************************************************************************
1734 template< typename VT // Type of the sparse vector
1735  , AlignmentFlag AF // Alignment flag
1736  , bool TF // Transpose flag
1737  , size_t... CSAs > // Compile time subvector arguments
1738 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1739  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index ) const
1740 {
1741  const ConstIterator_<VT> pos( vector_.find( offset() + index ) );
1742 
1743  if( pos != vector_.end() )
1744  return Iterator( pos, offset() );
1745  else
1746  return end();
1747 }
1749 //*************************************************************************************************
1750 
1751 
1752 //*************************************************************************************************
1765 template< typename VT // Type of the sparse vector
1766  , AlignmentFlag AF // Alignment flag
1767  , bool TF // Transpose flag
1768  , size_t... CSAs > // Compile time subvector arguments
1769 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1770  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index )
1771 {
1772  return Iterator( vector_.lowerBound( offset() + index ), offset() );
1773 }
1775 //*************************************************************************************************
1776 
1777 
1778 //*************************************************************************************************
1791 template< typename VT // Type of the sparse vector
1792  , AlignmentFlag AF // Alignment flag
1793  , bool TF // Transpose flag
1794  , size_t... CSAs > // Compile time subvector arguments
1795 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1796  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index ) const
1797 {
1798  return ConstIterator( vector_.lowerBound( offset() + index ), offset() );
1799 }
1801 //*************************************************************************************************
1802 
1803 
1804 //*************************************************************************************************
1817 template< typename VT // Type of the sparse vector
1818  , AlignmentFlag AF // Alignment flag
1819  , bool TF // Transpose flag
1820  , size_t... CSAs > // Compile time subvector arguments
1821 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1822  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index )
1823 {
1824  return Iterator( vector_.upperBound( offset() + index ), offset() );
1825 }
1827 //*************************************************************************************************
1828 
1829 
1830 //*************************************************************************************************
1843 template< typename VT // Type of the sparse vector
1844  , AlignmentFlag AF // Alignment flag
1845  , bool TF // Transpose flag
1846  , size_t... CSAs > // Compile time subvector arguments
1847 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1848  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index ) const
1849 {
1850  return ConstIterator( vector_.upperBound( offset() + index ), offset() );
1851 }
1853 //*************************************************************************************************
1854 
1855 
1856 
1857 
1858 //=================================================================================================
1859 //
1860 // NUMERIC FUNCTIONS
1861 //
1862 //=================================================================================================
1863 
1864 //*************************************************************************************************
1875 template< typename VT // Type of the sparse vector
1876  , AlignmentFlag AF // Alignment flag
1877  , bool TF // Transpose flag
1878  , size_t... CSAs > // Compile time subvector arguments
1879 template< typename Other > // Data type of the scalar value
1880 inline Subvector<VT,AF,TF,false,CSAs...>&
1881  Subvector<VT,AF,TF,false,CSAs...>::scale( const Other& scalar )
1882 {
1883  for( Iterator element=begin(); element!=end(); ++element )
1884  element->value() *= scalar;
1885  return *this;
1886 }
1888 //*************************************************************************************************
1889 
1890 
1891 
1892 
1893 //=================================================================================================
1894 //
1895 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1896 //
1897 //=================================================================================================
1898 
1899 //*************************************************************************************************
1910 template< typename VT // Type of the sparse vector
1911  , AlignmentFlag AF // Alignment flag
1912  , bool TF // Transpose flag
1913  , size_t... CSAs > // Compile time subvector arguments
1914 template< typename Other > // Data type of the foreign expression
1915 inline bool Subvector<VT,AF,TF,false,CSAs...>::canAlias( const Other* alias ) const noexcept
1916 {
1917  return vector_.isAliased( alias );
1918 }
1920 //*************************************************************************************************
1921 
1922 
1923 //*************************************************************************************************
1934 template< typename VT // Type of the sparse vector
1935  , AlignmentFlag AF // Alignment flag
1936  , bool TF // Transpose flag
1937  , size_t... CSAs > // Compile time subvector arguments
1938 template< typename Other > // Data type of the foreign expression
1939 inline bool Subvector<VT,AF,TF,false,CSAs...>::isAliased( const Other* alias ) const noexcept
1940 {
1941  return vector_.isAliased( alias );
1942 }
1944 //*************************************************************************************************
1945 
1946 
1947 //*************************************************************************************************
1958 template< typename VT // Type of the sparse vector
1959  , AlignmentFlag AF // Alignment flag
1960  , bool TF // Transpose flag
1961  , size_t... CSAs > // Compile time subvector arguments
1962 inline bool Subvector<VT,AF,TF,false,CSAs...>::canSMPAssign() const noexcept
1963 {
1964  return false;
1965 }
1967 //*************************************************************************************************
1968 
1969 
1970 //*************************************************************************************************
1982 template< typename VT // Type of the sparse vector
1983  , AlignmentFlag AF // Alignment flag
1984  , bool TF // Transpose flag
1985  , size_t... CSAs > // Compile time subvector arguments
1986 template< typename VT2 > // Type of the right-hand side dense vector
1987 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const DenseVector<VT2,TF>& rhs )
1988 {
1989  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1990  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1991 
1992  reserve( (~rhs).size() );
1993 
1994  for( size_t i=0UL; i<size(); ++i ) {
1995  append( i, (~rhs)[i], true );
1996  }
1997 }
1999 //*************************************************************************************************
2000 
2001 
2002 //*************************************************************************************************
2014 template< typename VT // Type of the sparse vector
2015  , AlignmentFlag AF // Alignment flag
2016  , bool TF // Transpose flag
2017  , size_t... CSAs > // Compile time subvector arguments
2018 template< typename VT2 > // Type of the right-hand side sparse vector
2019 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const SparseVector<VT2,TF>& rhs )
2020 {
2021  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2022  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2023 
2024  reserve( (~rhs).nonZeros() );
2025 
2026  for( ConstIterator_<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2027  append( element->index(), element->value(), true );
2028  }
2029 }
2031 //*************************************************************************************************
2032 
2033 
2034 //*************************************************************************************************
2046 template< typename VT // Type of the sparse vector
2047  , AlignmentFlag AF // Alignment flag
2048  , bool TF // Transpose flag
2049  , size_t... CSAs > // Compile time subvector arguments
2050 template< typename VT2 > // Type of the right-hand side dense vector
2051 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const DenseVector<VT2,TF>& rhs )
2052 {
2053  using AddType = AddTrait_< ResultType, ResultType_<VT2> >;
2054 
2058 
2059  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2060 
2061  const AddType tmp( serial( *this + (~rhs) ) );
2062  reset();
2063  assign( tmp );
2064 }
2066 //*************************************************************************************************
2067 
2068 
2069 //*************************************************************************************************
2081 template< typename VT // Type of the sparse vector
2082  , AlignmentFlag AF // Alignment flag
2083  , bool TF // Transpose flag
2084  , size_t... CSAs > // Compile time subvector arguments
2085 template< typename VT2 > // Type of the right-hand side sparse vector
2086 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const SparseVector<VT2,TF>& rhs )
2087 {
2088  using AddType = AddTrait_< ResultType, ResultType_<VT2> >;
2089 
2093 
2094  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2095 
2096  const AddType tmp( serial( *this + (~rhs) ) );
2097  reset();
2098  assign( tmp );
2099 }
2101 //*************************************************************************************************
2102 
2103 
2104 //*************************************************************************************************
2116 template< typename VT // Type of the sparse vector
2117  , AlignmentFlag AF // Alignment flag
2118  , bool TF // Transpose flag
2119  , size_t... CSAs > // Compile time subvector arguments
2120 template< typename VT2 > // Type of the right-hand side dense vector
2121 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const DenseVector<VT2,TF>& rhs )
2122 {
2123  using SubType = SubTrait_< ResultType, ResultType_<VT2> >;
2124 
2128 
2129  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2130 
2131  const SubType tmp( serial( *this - (~rhs) ) );
2132  reset();
2133  assign( tmp );
2134 }
2136 //*************************************************************************************************
2137 
2138 
2139 //*************************************************************************************************
2151 template< typename VT // Type of the sparse vector
2152  , AlignmentFlag AF // Alignment flag
2153  , bool TF // Transpose flag
2154  , size_t... CSAs > // Compile time subvector arguments
2155 template< typename VT2 > // Type of the right-hand side sparse vector
2156 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const SparseVector<VT2,TF>& rhs )
2157 {
2158  using SubType = SubTrait_< ResultType, ResultType_<VT2> >;
2159 
2163 
2164  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2165 
2166  const SubType tmp( serial( *this - (~rhs) ) );
2167  reset();
2168  assign( tmp );
2169 }
2171 //*************************************************************************************************
2172 
2173 } // namespace blaze
2174 
2175 #endif
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.Via these flags it is possible to specify subvec...
Definition: AlignmentFlag.h:62
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Constraint on the data type.
Header file for auxiliary alias declarations.
Header file for the blaze::checked and blaze::unchecked instances.
#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 alignment flag values.
Header file for the subtraction trait.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:522
Header file for basic type definitions.
Header file for the SparseVector base class.
Header file for the View base class.
Header file for the serial shim.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
#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:81
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3076
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:364
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3074
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:588
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:224
Header file for the IsIntegral type trait.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:3078
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3083
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:560
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:733
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3084
#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:81
Header file for the extended initializer_list functionality.
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:474
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:408
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the multiplication trait.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:3082
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the implementation of a vector representation of an initializer list.
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3075
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3079
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Header file for the implementation of the Subvector base template.
Header file for the implementation of the SubvectorData class template.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:3085
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
Header file for the subvector 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:61
Constraint on the data type.
Header file for the SparseElement base class.
Constraint on the data type.
Constraint on the data type.
Header file for the exception macros of the math module.
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:430
decltype(auto) operator*(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:8893
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Constraint on the data type.
Constraint on the data type.
typename SubvectorTrait< VT, CSAs... >::Type SubvectorTrait_
Auxiliary alias declaration for the SubvectorTrait type trait.The SubvectorTrait_ alias declaration p...
Definition: SubvectorTrait.h:145
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
Header file for the IsConst type trait.
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Header file for the Unique class template.
Check< false > Unchecked
Type of the blaze::unchecked instance.blaze::Unchecked is the type of the blaze::unchecked instance...
Definition: Check.h:96
Header file for the isDefault shim.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:816
#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:81
Header file for the IsReference type trait.
Header file for the RemoveReference type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3080
#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:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBVECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is a subvector type (i.e. a dense or sparse subvector), a compilation error is created.
Definition: Subvector.h:81
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:3081
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
Header file for the IsRestricted type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#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
Header file for the IsExpression type trait class.