Blaze  3.6
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>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE SUBVECTORS
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
99 template< typename VT // Type of the sparse vector
100  , AlignmentFlag AF // Alignment flag
101  , bool TF // Transpose flag
102  , size_t... CSAs > // Compile time subvector arguments
103 class Subvector<VT,AF,TF,false,CSAs...>
104  : public View< SparseVector< Subvector<VT,AF,TF,false,CSAs...>, TF > >
105  , private SubvectorData<CSAs...>
106 {
107  private:
108  //**Type definitions****************************************************************************
109  using DataType = SubvectorData<CSAs...>;
110  using Operand = If_t< IsExpression_v<VT>, VT, VT& >;
111  //**********************************************************************************************
112 
113  public:
114  //**Type definitions****************************************************************************
116  using This = Subvector<VT,AF,TF,false,CSAs...>;
117 
118  using BaseType = SparseVector<This,TF>;
119  using ViewedType = VT;
120  using ResultType = SubvectorTrait_t<VT,CSAs...>;
121  using TransposeType = TransposeType_t<ResultType>;
122  using ElementType = ElementType_t<VT>;
123  using ReturnType = ReturnType_t<VT>;
124  using CompositeType = const Subvector&;
125 
127  using ConstReference = ConstReference_t<VT>;
128 
130  using Reference = If_t< IsConst_v<VT>, ConstReference, Reference_t<VT> >;
131  //**********************************************************************************************
132 
133  //**SubvectorElement class definition***********************************************************
136  template< typename VectorType // Type of the sparse vector
137  , typename IteratorType > // Type of the sparse vector iterator
138  class SubvectorElement
139  : private SparseElement
140  {
141  public:
142  //**Constructor******************************************************************************
148  inline SubvectorElement( IteratorType pos, size_t offset )
149  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
150  , offset_( offset ) // Offset within the according sparse vector
151  {}
152  //*******************************************************************************************
153 
154  //**Assignment operator**********************************************************************
160  template< typename T > inline SubvectorElement& operator=( const T& v ) {
161  *pos_ = v;
162  return *this;
163  }
164  //*******************************************************************************************
165 
166  //**Addition assignment operator*************************************************************
172  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
173  *pos_ += v;
174  return *this;
175  }
176  //*******************************************************************************************
177 
178  //**Subtraction assignment operator**********************************************************
184  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
185  *pos_ -= v;
186  return *this;
187  }
188  //*******************************************************************************************
189 
190  //**Multiplication assignment operator*******************************************************
196  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
197  *pos_ *= v;
198  return *this;
199  }
200  //*******************************************************************************************
201 
202  //**Division assignment operator*************************************************************
208  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
209  *pos_ /= v;
210  return *this;
211  }
212  //*******************************************************************************************
213 
214  //**Element access operator******************************************************************
219  inline const SubvectorElement* operator->() const {
220  return this;
221  }
222  //*******************************************************************************************
223 
224  //**Value function***************************************************************************
229  inline decltype(auto) value() const {
230  return pos_->value();
231  }
232  //*******************************************************************************************
233 
234  //**Index function***************************************************************************
239  inline size_t index() const {
240  return pos_->index() - offset_;
241  }
242  //*******************************************************************************************
243 
244  private:
245  //**Member variables*************************************************************************
246  IteratorType pos_;
247  size_t offset_;
248  //*******************************************************************************************
249  };
250  //**********************************************************************************************
251 
252  //**SubvectorIterator class definition**********************************************************
255  template< typename VectorType // Type of the sparse vector
256  , typename IteratorType > // Type of the sparse vector iterator
257  class SubvectorIterator
258  {
259  public:
260  //**Type definitions*************************************************************************
261  using IteratorCategory = std::forward_iterator_tag;
262  using ValueType = SubvectorElement<VectorType,IteratorType>;
263  using PointerType = ValueType;
264  using ReferenceType = ValueType;
265  using DifferenceType = ptrdiff_t;
266 
267  // STL iterator requirements
268  using iterator_category = IteratorCategory;
269  using value_type = ValueType;
270  using pointer = PointerType;
271  using reference = ReferenceType;
272  using difference_type = DifferenceType;
273  //*******************************************************************************************
274 
275  //**Default constructor**********************************************************************
278  inline SubvectorIterator()
279  : pos_ () // Iterator to the current sparse element
280  , offset_() // The offset of the subvector within the sparse vector
281  {}
282  //*******************************************************************************************
283 
284  //**Constructor******************************************************************************
290  inline SubvectorIterator( IteratorType iterator, size_t index )
291  : pos_ ( iterator ) // Iterator to the current sparse element
292  , offset_( index ) // The offset of the subvector within the sparse vector
293  {}
294  //*******************************************************************************************
295 
296  //**Constructor******************************************************************************
301  template< typename VectorType2, typename IteratorType2 >
302  inline SubvectorIterator( const SubvectorIterator<VectorType2,IteratorType2>& it )
303  : pos_ ( it.base() ) // Iterator to the current sparse element.
304  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
305  {}
306  //*******************************************************************************************
307 
308  //**Prefix increment operator****************************************************************
313  inline SubvectorIterator& operator++() {
314  ++pos_;
315  return *this;
316  }
317  //*******************************************************************************************
318 
319  //**Postfix increment operator***************************************************************
324  inline const SubvectorIterator operator++( int ) {
325  const SubvectorIterator tmp( *this );
326  ++(*this);
327  return tmp;
328  }
329  //*******************************************************************************************
330 
331  //**Element access operator******************************************************************
336  inline ReferenceType operator*() const {
337  return ReferenceType( pos_, offset_ );
338  }
339  //*******************************************************************************************
340 
341  //**Element access operator******************************************************************
346  inline PointerType operator->() const {
347  return PointerType( pos_, offset_ );
348  }
349  //*******************************************************************************************
350 
351  //**Equality operator************************************************************************
357  template< typename VectorType2, typename IteratorType2 >
358  inline bool operator==( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
359  return base() == rhs.base();
360  }
361  //*******************************************************************************************
362 
363  //**Inequality operator**********************************************************************
369  template< typename VectorType2, typename IteratorType2 >
370  inline bool operator!=( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
371  return !( *this == rhs );
372  }
373  //*******************************************************************************************
374 
375  //**Subtraction operator*********************************************************************
381  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
382  return pos_ - rhs.pos_;
383  }
384  //*******************************************************************************************
385 
386  //**Base function****************************************************************************
391  inline IteratorType base() const {
392  return pos_;
393  }
394  //*******************************************************************************************
395 
396  //**Offset function**************************************************************************
401  inline size_t offset() const noexcept {
402  return offset_;
403  }
404  //*******************************************************************************************
405 
406  private:
407  //**Member variables*************************************************************************
408  IteratorType pos_;
409  size_t offset_;
410  //*******************************************************************************************
411  };
412  //**********************************************************************************************
413 
414  //**Type definitions****************************************************************************
416  using ConstIterator = SubvectorIterator< const VT, ConstIterator_t<VT> >;
417 
419  using Iterator = If_t< IsConst_v<VT>, ConstIterator, SubvectorIterator< VT, Iterator_t<VT> > >;
420  //**********************************************************************************************
421 
422  //**Compilation flags***************************************************************************
424  static constexpr bool smpAssignable = VT::smpAssignable;
425 
427  static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
428  //**********************************************************************************************
429 
430  //**Constructors********************************************************************************
433  template< typename... RSAs >
434  explicit inline Subvector( VT& vector, RSAs... args );
435 
436  Subvector( const Subvector& ) = default;
438  //**********************************************************************************************
439 
440  //**Destructor**********************************************************************************
443  ~Subvector() = default;
445  //**********************************************************************************************
446 
447  //**Data access functions***********************************************************************
450  inline Reference operator[]( size_t index );
451  inline ConstReference operator[]( size_t index ) const;
452  inline Reference at( size_t index );
453  inline ConstReference at( size_t index ) const;
454  inline Iterator begin ();
455  inline ConstIterator begin () const;
456  inline ConstIterator cbegin() const;
457  inline Iterator end ();
458  inline ConstIterator end () const;
459  inline ConstIterator cend () const;
461  //**********************************************************************************************
462 
463  //**Assignment operators************************************************************************
466  inline Subvector& operator= ( initializer_list<ElementType> list );
467  inline Subvector& operator= ( const Subvector& rhs );
468  template< typename VT2 > inline Subvector& operator= ( const Vector<VT2,TF>& rhs );
469  template< typename VT2 > inline Subvector& operator+=( const Vector<VT2,TF>& rhs );
470  template< typename VT2 > inline Subvector& operator-=( const Vector<VT2,TF>& rhs );
471  template< typename VT2 > inline Subvector& operator*=( const Vector<VT2,TF>& rhs );
472  template< typename VT2 > inline Subvector& operator/=( const DenseVector<VT2,TF>& rhs );
473  template< typename VT2 > inline Subvector& operator%=( const Vector<VT2,TF>& rhs );
475  //**********************************************************************************************
476 
477  //**Utility functions***************************************************************************
480  using DataType::offset;
481  using DataType::size;
482 
483  inline VT& operand() noexcept;
484  inline const VT& operand() const noexcept;
485 
486  inline size_t capacity() const noexcept;
487  inline size_t nonZeros() const;
488  inline void reset();
489  inline void reserve( size_t n );
491  //**********************************************************************************************
492 
493  //**Insertion functions*************************************************************************
496  inline Iterator set ( size_t index, const ElementType& value );
497  inline Iterator insert( size_t index, const ElementType& value );
498  inline void append( size_t index, const ElementType& value, bool check=false );
500  //**********************************************************************************************
501 
502  //**Erase functions*****************************************************************************
505  inline void erase( size_t index );
506  inline Iterator erase( Iterator pos );
507  inline Iterator erase( Iterator first, Iterator last );
508 
509  template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
510  inline void erase( Pred predicate );
511 
512  template< typename Pred >
513  inline void erase( Iterator first, Iterator last, Pred predicate );
515  //**********************************************************************************************
516 
517  //**Lookup functions****************************************************************************
520  inline Iterator find ( size_t index );
521  inline ConstIterator find ( size_t index ) const;
522  inline Iterator lowerBound( size_t index );
523  inline ConstIterator lowerBound( size_t index ) const;
524  inline Iterator upperBound( size_t index );
525  inline ConstIterator upperBound( size_t index ) const;
527  //**********************************************************************************************
528 
529  //**Numeric functions***************************************************************************
532  template< typename Other > inline Subvector& scale( const Other& scalar );
534  //**********************************************************************************************
535 
536  //**Expression template evaluation functions****************************************************
539  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
540  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
541 
542  inline bool canSMPAssign() const noexcept;
543 
544  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
545  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
546  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
547  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
548  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
549  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
551  //**********************************************************************************************
552 
553  private:
554  //**Member variables****************************************************************************
557  Operand vector_;
558 
559  //**********************************************************************************************
560 
561  //**Compile time checks*************************************************************************
567  //**********************************************************************************************
568 };
570 //*************************************************************************************************
571 
572 
573 
574 
575 //=================================================================================================
576 //
577 // CONSTRUCTORS
578 //
579 //=================================================================================================
580 
581 //*************************************************************************************************
595 template< typename VT // Type of the sparse vector
596  , AlignmentFlag AF // Alignment flag
597  , bool TF // Transpose flag
598  , size_t... CSAs > // Compile time subvector arguments
599 template< typename... RSAs > // Runtime subvector arguments
600 inline Subvector<VT,AF,TF,false,CSAs...>::Subvector( VT& vector, RSAs... args )
601  : DataType( args... ) // Base class initialization
602  , vector_ ( vector ) // The vector containing the subvector
603 {
604  if( !Contains_v< TypeList<RSAs...>, Unchecked > ) {
605  if( offset() + size() > vector.size() ) {
606  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
607  }
608  }
609  else {
610  BLAZE_USER_ASSERT( offset() + size() <= vector.size(), "Invalid subvector specification" );
611  }
612 }
614 //*************************************************************************************************
615 
616 
617 
618 
619 //=================================================================================================
620 //
621 // DATA ACCESS FUNCTIONS
622 //
623 //=================================================================================================
624 
625 //*************************************************************************************************
635 template< typename VT // Type of the sparse vector
636  , AlignmentFlag AF // Alignment flag
637  , bool TF // Transpose flag
638  , size_t... CSAs > // Compile time subvector arguments
639 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
640  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index )
641 {
642  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
643  return vector_[offset()+index];
644 }
646 //*************************************************************************************************
647 
648 
649 //*************************************************************************************************
659 template< typename VT // Type of the sparse vector
660  , AlignmentFlag AF // Alignment flag
661  , bool TF // Transpose flag
662  , size_t... CSAs > // Compile time subvector arguments
663 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
664  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index ) const
665 {
666  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
667  return const_cast<const VT&>( vector_ )[offset()+index];
668 }
670 //*************************************************************************************************
671 
672 
673 //*************************************************************************************************
684 template< typename VT // Type of the sparse vector
685  , AlignmentFlag AF // Alignment flag
686  , bool TF // Transpose flag
687  , size_t... CSAs > // Compile time subvector arguments
688 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
689  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index )
690 {
691  if( index >= size() ) {
692  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
693  }
694  return (*this)[index];
695 }
697 //*************************************************************************************************
698 
699 
700 //*************************************************************************************************
711 template< typename VT // Type of the sparse vector
712  , AlignmentFlag AF // Alignment flag
713  , bool TF // Transpose flag
714  , size_t... CSAs > // Compile time subvector arguments
715 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
716  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index ) const
717 {
718  if( index >= size() ) {
719  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
720  }
721  return (*this)[index];
722 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
735 template< typename VT // Type of the sparse vector
736  , AlignmentFlag AF // Alignment flag
737  , bool TF // Transpose flag
738  , size_t... CSAs > // Compile time subvector arguments
739 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
741 {
742  if( offset() == 0UL )
743  return Iterator( vector_.begin(), offset() );
744  else
745  return Iterator( vector_.lowerBound( offset() ), offset() );
746 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
759 template< typename VT // Type of the sparse vector
760  , AlignmentFlag AF // Alignment flag
761  , bool TF // Transpose flag
762  , size_t... CSAs > // Compile time subvector arguments
763 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
765 {
766  if( offset() == 0UL )
767  return ConstIterator( vector_.cbegin(), offset() );
768  else
769  return ConstIterator( vector_.lowerBound( offset() ), offset() );
770 }
772 //*************************************************************************************************
773 
774 
775 //*************************************************************************************************
783 template< typename VT // Type of the sparse vector
784  , AlignmentFlag AF // Alignment flag
785  , bool TF // Transpose flag
786  , size_t... CSAs > // Compile time subvector arguments
787 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
789 {
790  if( offset() == 0UL )
791  return ConstIterator( vector_.cbegin(), offset() );
792  else
793  return ConstIterator( vector_.lowerBound( offset() ), offset() );
794 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
807 template< typename VT // Type of the sparse vector
808  , AlignmentFlag AF // Alignment flag
809  , bool TF // Transpose flag
810  , size_t... CSAs > // Compile time subvector arguments
811 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
813 {
814  if( offset() + size() == vector_.size() )
815  return Iterator( vector_.end(), offset() );
816  else
817  return Iterator( vector_.lowerBound( offset() + size() ), offset() );
818 }
820 //*************************************************************************************************
821 
822 
823 //*************************************************************************************************
831 template< typename VT // Type of the sparse vector
832  , AlignmentFlag AF // Alignment flag
833  , bool TF // Transpose flag
834  , size_t... CSAs > // Compile time subvector arguments
835 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
837 {
838  if( offset() + size() == vector_.size() )
839  return ConstIterator( vector_.cend(), offset() );
840  else
841  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
842 }
844 //*************************************************************************************************
845 
846 
847 //*************************************************************************************************
855 template< typename VT // Type of the sparse vector
856  , AlignmentFlag AF // Alignment flag
857  , bool TF // Transpose flag
858  , size_t... CSAs > // Compile time subvector arguments
859 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
861 {
862  if( offset() + size() == vector_.size() )
863  return ConstIterator( vector_.cend(), offset() );
864  else
865  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
866 }
868 //*************************************************************************************************
869 
870 
871 
872 
873 //=================================================================================================
874 //
875 // ASSIGNMENT OPERATORS
876 //
877 //=================================================================================================
878 
879 //*************************************************************************************************
894 template< typename VT // Type of the sparse vector
895  , AlignmentFlag AF // Alignment flag
896  , bool TF // Transpose flag
897  , size_t... CSAs > // Compile time subvector arguments
898 inline Subvector<VT,AF,TF,false,CSAs...>&
899  Subvector<VT,AF,TF,false,CSAs...>::operator=( initializer_list<ElementType> list )
900 {
901  using blaze::assign;
902 
903  if( list.size() > size() ) {
904  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to subvector" );
905  }
906 
907  const InitializerVector<ElementType,TF> tmp( list, size() );
908 
909  if( !tryAssign( vector_, tmp, offset() ) ) {
910  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
911  }
912 
913  decltype(auto) left( derestrict( *this ) );
914 
915  reset();
916  assign( left, tmp );
917 
918  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
919 
920  return *this;
921 }
923 //*************************************************************************************************
924 
925 
926 //*************************************************************************************************
938 template< typename VT // Type of the sparse vector
939  , AlignmentFlag AF // Alignment flag
940  , bool TF // Transpose flag
941  , size_t... CSAs > // Compile time subvector arguments
942 inline Subvector<VT,AF,TF,false,CSAs...>&
943  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Subvector& rhs )
944 {
945  using blaze::assign;
946 
949 
950  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset() == rhs.offset() ) )
951  return *this;
952 
953  if( size() != rhs.size() ) {
954  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
955  }
956 
957  if( !tryAssign( vector_, rhs, offset() ) ) {
958  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
959  }
960 
961  decltype(auto) left( derestrict( *this ) );
962 
963  if( rhs.canAlias( &vector_ ) ) {
964  const ResultType tmp( rhs );
965  reset();
966  assign( left, tmp );
967  }
968  else {
969  reset();
970  assign( left, rhs );
971  }
972 
973  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
974 
975  return *this;
976 }
978 //*************************************************************************************************
979 
980 
981 //*************************************************************************************************
993 template< typename VT // Type of the sparse vector
994  , AlignmentFlag AF // Alignment flag
995  , bool TF // Transpose flag
996  , size_t... CSAs > // Compile time subvector arguments
997 template< typename VT2 > // Type of the right-hand side vector
998 inline Subvector<VT,AF,TF,false,CSAs...>&
999  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Vector<VT2,TF>& rhs )
1000 {
1001  using blaze::assign;
1002 
1003  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1004  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1005 
1006  if( size() != (~rhs).size() ) {
1007  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1008  }
1009 
1010  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1011  Right right( ~rhs );
1012 
1013  if( !tryAssign( vector_, right, offset() ) ) {
1014  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1015  }
1016 
1017  decltype(auto) left( derestrict( *this ) );
1018 
1019  if( IsReference_v<Right> || right.canAlias( &vector_ ) ) {
1020  const ResultType_t<VT2> tmp( right );
1021  reset();
1022  assign( left, tmp );
1023  }
1024  else {
1025  reset();
1026  assign( left, right );
1027  }
1028 
1029  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1030 
1031  return *this;
1032 }
1034 //*************************************************************************************************
1035 
1036 
1037 //*************************************************************************************************
1049 template< typename VT // Type of the sparse vector
1050  , AlignmentFlag AF // Alignment flag
1051  , bool TF // Transpose flag
1052  , size_t... CSAs > // Compile time subvector arguments
1053 template< typename VT2 > // Type of the right-hand side vector
1054 inline Subvector<VT,AF,TF,false,CSAs...>&
1055  Subvector<VT,AF,TF,false,CSAs...>::operator+=( const Vector<VT2,TF>& rhs )
1056 {
1057  using blaze::assign;
1058 
1061  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1062 
1063  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
1064 
1067 
1068  if( size() != (~rhs).size() ) {
1069  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1070  }
1071 
1072  const AddType tmp( *this + (~rhs) );
1073 
1074  if( !tryAssign( vector_, tmp, offset() ) ) {
1075  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1076  }
1077 
1078  decltype(auto) left( derestrict( *this ) );
1079 
1080  left.reset();
1081  assign( left, tmp );
1082 
1083  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1084 
1085  return *this;
1086 }
1088 //*************************************************************************************************
1089 
1090 
1091 //*************************************************************************************************
1103 template< typename VT // Type of the sparse vector
1104  , AlignmentFlag AF // Alignment flag
1105  , bool TF // Transpose flag
1106  , size_t... CSAs > // Compile time subvector arguments
1107 template< typename VT2 > // Type of the right-hand side vector
1108 inline Subvector<VT,AF,TF,false,CSAs...>&
1109  Subvector<VT,AF,TF,false,CSAs...>::operator-=( const Vector<VT2,TF>& rhs )
1110 {
1111  using blaze::assign;
1112 
1115  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1116 
1117  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
1118 
1121 
1122  if( size() != (~rhs).size() ) {
1123  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1124  }
1125 
1126  const SubType tmp( *this - (~rhs) );
1127 
1128  if( !tryAssign( vector_, tmp, offset() ) ) {
1129  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1130  }
1131 
1132  decltype(auto) left( derestrict( *this ) );
1133 
1134  left.reset();
1135  assign( left, tmp );
1136 
1137  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1138 
1139  return *this;
1140 }
1142 //*************************************************************************************************
1143 
1144 
1145 //*************************************************************************************************
1158 template< typename VT // Type of the sparse vector
1159  , AlignmentFlag AF // Alignment flag
1160  , bool TF // Transpose flag
1161  , size_t... CSAs > // Compile time subvector arguments
1162 template< typename VT2 > // Type of the right-hand side vector
1163 inline Subvector<VT,AF,TF,false,CSAs...>&
1164  Subvector<VT,AF,TF,false,CSAs...>::operator*=( const Vector<VT2,TF>& rhs )
1165 {
1166  using blaze::assign;
1167 
1170  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1171 
1172  using MultType = MultTrait_t< ResultType, ResultType_t<VT2> >;
1173 
1176 
1177  if( size() != (~rhs).size() ) {
1178  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1179  }
1180 
1181  const MultType tmp( *this * (~rhs) );
1182 
1183  if( !tryAssign( vector_, tmp, offset() ) ) {
1184  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1185  }
1186 
1187  decltype(auto) left( derestrict( *this ) );
1188 
1189  left.reset();
1190  assign( left, tmp );
1191 
1192  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1193 
1194  return *this;
1195 }
1197 //*************************************************************************************************
1198 
1199 
1200 //*************************************************************************************************
1212 template< typename VT // Type of the sparse vector
1213  , AlignmentFlag AF // Alignment flag
1214  , bool TF // Transpose flag
1215  , size_t... CSAs > // Compile time subvector arguments
1216 template< typename VT2 > // Type of the right-hand side dense vector
1217 inline Subvector<VT,AF,TF,false,CSAs...>&
1218  Subvector<VT,AF,TF,false,CSAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1219 {
1220  using blaze::assign;
1221 
1224  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT2> );
1225  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1226 
1227  using DivType = DivTrait_t< ResultType, ResultType_t<VT2> >;
1228 
1232 
1233  if( size() != (~rhs).size() ) {
1234  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1235  }
1236 
1237  const DivType tmp( *this / (~rhs) );
1238 
1239  if( !tryAssign( vector_, tmp, offset() ) ) {
1240  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1241  }
1242 
1243  decltype(auto) left( derestrict( *this ) );
1244 
1245  left.reset();
1246  assign( left, tmp );
1247 
1248  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1249 
1250  return *this;
1251 }
1253 //*************************************************************************************************
1254 
1255 
1256 //*************************************************************************************************
1269 template< typename VT // Type of the sparse vector
1270  , AlignmentFlag AF // Alignment flag
1271  , bool TF // Transpose flag
1272  , size_t... CSAs > // Compile time subvector arguments
1273 template< typename VT2 > // Type of the right-hand side vector
1274 inline Subvector<VT,AF,TF,false,CSAs...>&
1275  Subvector<VT,AF,TF,false,CSAs...>::operator%=( const Vector<VT2,TF>& rhs )
1276 {
1277  using blaze::assign;
1278 
1279  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1280  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1281 
1282  using CrossType = CrossTrait_t< ResultType, ResultType_t<VT2> >;
1283 
1287 
1288  if( size() != 3UL || (~rhs).size() != 3UL ) {
1289  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1290  }
1291 
1292  const CrossType tmp( *this % (~rhs) );
1293 
1294  if( !tryAssign( vector_, tmp, offset() ) ) {
1295  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1296  }
1297 
1298  decltype(auto) left( derestrict( *this ) );
1299 
1300  left.reset();
1301  assign( left, tmp );
1302 
1303  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1304 
1305  return *this;
1306 }
1308 //*************************************************************************************************
1309 
1310 
1311 
1312 
1313 //=================================================================================================
1314 //
1315 // UTILITY FUNCTIONS
1316 //
1317 //=================================================================================================
1318 
1319 //*************************************************************************************************
1325 template< typename VT // Type of the sparse vector
1326  , AlignmentFlag AF // Alignment flag
1327  , bool TF // Transpose flag
1328  , size_t... CSAs > // Compile time subvector arguments
1329 inline VT& Subvector<VT,AF,TF,false,CSAs...>::operand() noexcept
1330 {
1331  return vector_;
1332 }
1334 //*************************************************************************************************
1335 
1336 
1337 //*************************************************************************************************
1343 template< typename VT // Type of the sparse vector
1344  , AlignmentFlag AF // Alignment flag
1345  , bool TF // Transpose flag
1346  , size_t... CSAs > // Compile time subvector arguments
1347 inline const VT& Subvector<VT,AF,TF,false,CSAs...>::operand() const noexcept
1348 {
1349  return vector_;
1350 }
1352 //*************************************************************************************************
1353 
1354 
1355 //*************************************************************************************************
1361 template< typename VT // Type of the sparse vector
1362  , AlignmentFlag AF // Alignment flag
1363  , bool TF // Transpose flag
1364  , size_t... CSAs > // Compile time subvector arguments
1365 inline size_t Subvector<VT,AF,TF,false,CSAs...>::capacity() const noexcept
1366 {
1367  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1368 }
1370 //*************************************************************************************************
1371 
1372 
1373 //*************************************************************************************************
1381 template< typename VT // Type of the sparse vector
1382  , AlignmentFlag AF // Alignment flag
1383  , bool TF // Transpose flag
1384  , size_t... CSAs > // Compile time subvector arguments
1385 inline size_t Subvector<VT,AF,TF,false,CSAs...>::nonZeros() const
1386 {
1387  return end() - begin();
1388 }
1390 //*************************************************************************************************
1391 
1392 
1393 //*************************************************************************************************
1399 template< typename VT // Type of the sparse vector
1400  , AlignmentFlag AF // Alignment flag
1401  , bool TF // Transpose flag
1402  , size_t... CSAs > // Compile time subvector arguments
1404 {
1405  vector_.erase( vector_.lowerBound( offset() ), vector_.lowerBound( offset() + size() ) );
1406 }
1408 //*************************************************************************************************
1409 
1410 
1411 //*************************************************************************************************
1421 template< typename VT // Type of the sparse vector
1422  , AlignmentFlag AF // Alignment flag
1423  , bool TF // Transpose flag
1424  , size_t... CSAs > // Compile time subvector arguments
1425 void Subvector<VT,AF,TF,false,CSAs...>::reserve( size_t n )
1426 {
1427  const size_t current( capacity() );
1428 
1429  if( n > current ) {
1430  vector_.reserve( vector_.capacity() + n - current );
1431  }
1432 }
1434 //*************************************************************************************************
1435 
1436 
1437 
1438 
1439 //=================================================================================================
1440 //
1441 // INSERTION FUNCTIONS
1442 //
1443 //=================================================================================================
1444 
1445 //*************************************************************************************************
1457 template< typename VT // Type of the sparse vector
1458  , AlignmentFlag AF // Alignment flag
1459  , bool TF // Transpose flag
1460  , size_t... CSAs > // Compile time subvector arguments
1461 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1462  Subvector<VT,AF,TF,false,CSAs...>::set( size_t index, const ElementType& value )
1463 {
1464  return Iterator( vector_.set( offset() + index, value ), offset() );
1465 }
1467 //*************************************************************************************************
1468 
1469 
1470 //*************************************************************************************************
1483 template< typename VT // Type of the sparse vector
1484  , AlignmentFlag AF // Alignment flag
1485  , bool TF // Transpose flag
1486  , size_t... CSAs > // Compile time subvector arguments
1487 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1488  Subvector<VT,AF,TF,false,CSAs...>::insert( size_t index, const ElementType& value )
1489 {
1490  return Iterator( vector_.insert( offset() + index, value ), offset() );
1491 }
1493 //*************************************************************************************************
1494 
1495 
1496 //*************************************************************************************************
1521 template< typename VT // Type of the sparse vector
1522  , AlignmentFlag AF // Alignment flag
1523  , bool TF // Transpose flag
1524  , size_t... CSAs > // Compile time subvector arguments
1525 inline void Subvector<VT,AF,TF,false,CSAs...>::append( size_t index, const ElementType& value, bool check )
1526 {
1527  if( offset() + size() == vector_.size() )
1528  vector_.append( offset() + index, value, check );
1529  else if( !check || !isDefault<strict>( value ) )
1530  vector_.insert( offset() + index, value );
1531 }
1533 //*************************************************************************************************
1534 
1535 
1536 
1537 
1538 //=================================================================================================
1539 //
1540 // ERASE FUNCTIONS
1541 //
1542 //=================================================================================================
1543 
1544 //*************************************************************************************************
1553 template< typename VT // Type of the sparse vector
1554  , AlignmentFlag AF // Alignment flag
1555  , bool TF // Transpose flag
1556  , size_t... CSAs > // Compile time subvector arguments
1557 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( size_t index )
1558 {
1559  vector_.erase( offset() + index );
1560 }
1562 //*************************************************************************************************
1563 
1564 
1565 //*************************************************************************************************
1574 template< typename VT // Type of the sparse vector
1575  , AlignmentFlag AF // Alignment flag
1576  , bool TF // Transpose flag
1577  , size_t... CSAs > // Compile time subvector arguments
1578 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1579  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator pos )
1580 {
1581  return Iterator( vector_.erase( pos.base() ), offset() );
1582 }
1584 //*************************************************************************************************
1585 
1586 
1587 //*************************************************************************************************
1597 template< typename VT // Type of the sparse vector
1598  , AlignmentFlag AF // Alignment flag
1599  , bool TF // Transpose flag
1600  , size_t... CSAs > // Compile time subvector arguments
1601 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1602  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last )
1603 {
1604  return Iterator( vector_.erase( first.base(), last.base() ), offset() );
1605 }
1607 //*************************************************************************************************
1608 
1609 
1610 //*************************************************************************************************
1633 template< typename VT // Type of the sparse vector
1634  , AlignmentFlag AF // Alignment flag
1635  , bool TF // Transpose flag
1636  , size_t... CSAs > // Compile time subvector arguments
1637 template< typename Pred // Type of the unary predicate
1638  , typename > // Type restriction on the unary predicate
1639 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Pred predicate )
1640 {
1641  vector_.erase( begin().base(), end().base(), predicate );
1642 }
1644 //*************************************************************************************************
1645 
1646 
1647 //*************************************************************************************************
1673 template< typename VT // Type of the sparse vector
1674  , AlignmentFlag AF // Alignment flag
1675  , bool TF // Transpose flag
1676  , size_t... CSAs > // Compile time subvector arguments
1677 template< typename Pred > // Type of the unary predicate
1678 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last, Pred predicate )
1679 {
1680  vector_.erase( first.base(), last.base(), predicate );
1681 }
1683 //*************************************************************************************************
1684 
1685 
1686 
1687 
1688 //=================================================================================================
1689 //
1690 // LOOKUP FUNCTIONS
1691 //
1692 //=================================================================================================
1693 
1694 //*************************************************************************************************
1708 template< typename VT // Type of the sparse vector
1709  , AlignmentFlag AF // Alignment flag
1710  , bool TF // Transpose flag
1711  , size_t... CSAs > // Compile time subvector arguments
1712 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1713  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index )
1714 {
1715  const Iterator_t<VT> pos( vector_.find( offset() + index ) );
1716 
1717  if( pos != vector_.end() )
1718  return Iterator( pos, offset() );
1719  else
1720  return end();
1721 }
1723 //*************************************************************************************************
1724 
1725 
1726 //*************************************************************************************************
1740 template< typename VT // Type of the sparse vector
1741  , AlignmentFlag AF // Alignment flag
1742  , bool TF // Transpose flag
1743  , size_t... CSAs > // Compile time subvector arguments
1744 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1745  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index ) const
1746 {
1747  const ConstIterator_t<VT> pos( vector_.find( offset() + index ) );
1748 
1749  if( pos != vector_.end() )
1750  return Iterator( pos, offset() );
1751  else
1752  return end();
1753 }
1755 //*************************************************************************************************
1756 
1757 
1758 //*************************************************************************************************
1771 template< typename VT // Type of the sparse vector
1772  , AlignmentFlag AF // Alignment flag
1773  , bool TF // Transpose flag
1774  , size_t... CSAs > // Compile time subvector arguments
1775 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1776  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index )
1777 {
1778  return Iterator( vector_.lowerBound( offset() + index ), offset() );
1779 }
1781 //*************************************************************************************************
1782 
1783 
1784 //*************************************************************************************************
1797 template< typename VT // Type of the sparse vector
1798  , AlignmentFlag AF // Alignment flag
1799  , bool TF // Transpose flag
1800  , size_t... CSAs > // Compile time subvector arguments
1801 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1802  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index ) const
1803 {
1804  return ConstIterator( vector_.lowerBound( offset() + index ), offset() );
1805 }
1807 //*************************************************************************************************
1808 
1809 
1810 //*************************************************************************************************
1823 template< typename VT // Type of the sparse vector
1824  , AlignmentFlag AF // Alignment flag
1825  , bool TF // Transpose flag
1826  , size_t... CSAs > // Compile time subvector arguments
1827 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1828  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index )
1829 {
1830  return Iterator( vector_.upperBound( offset() + index ), offset() );
1831 }
1833 //*************************************************************************************************
1834 
1835 
1836 //*************************************************************************************************
1849 template< typename VT // Type of the sparse vector
1850  , AlignmentFlag AF // Alignment flag
1851  , bool TF // Transpose flag
1852  , size_t... CSAs > // Compile time subvector arguments
1853 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1854  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index ) const
1855 {
1856  return ConstIterator( vector_.upperBound( offset() + index ), offset() );
1857 }
1859 //*************************************************************************************************
1860 
1861 
1862 
1863 
1864 //=================================================================================================
1865 //
1866 // NUMERIC FUNCTIONS
1867 //
1868 //=================================================================================================
1869 
1870 //*************************************************************************************************
1881 template< typename VT // Type of the sparse vector
1882  , AlignmentFlag AF // Alignment flag
1883  , bool TF // Transpose flag
1884  , size_t... CSAs > // Compile time subvector arguments
1885 template< typename Other > // Data type of the scalar value
1886 inline Subvector<VT,AF,TF,false,CSAs...>&
1887  Subvector<VT,AF,TF,false,CSAs...>::scale( const Other& scalar )
1888 {
1889  for( Iterator element=begin(); element!=end(); ++element )
1890  element->value() *= scalar;
1891  return *this;
1892 }
1894 //*************************************************************************************************
1895 
1896 
1897 
1898 
1899 //=================================================================================================
1900 //
1901 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1902 //
1903 //=================================================================================================
1904 
1905 //*************************************************************************************************
1916 template< typename VT // Type of the sparse vector
1917  , AlignmentFlag AF // Alignment flag
1918  , bool TF // Transpose flag
1919  , size_t... CSAs > // Compile time subvector arguments
1920 template< typename Other > // Data type of the foreign expression
1921 inline bool Subvector<VT,AF,TF,false,CSAs...>::canAlias( const Other* alias ) const noexcept
1922 {
1923  return vector_.isAliased( alias );
1924 }
1926 //*************************************************************************************************
1927 
1928 
1929 //*************************************************************************************************
1940 template< typename VT // Type of the sparse vector
1941  , AlignmentFlag AF // Alignment flag
1942  , bool TF // Transpose flag
1943  , size_t... CSAs > // Compile time subvector arguments
1944 template< typename Other > // Data type of the foreign expression
1945 inline bool Subvector<VT,AF,TF,false,CSAs...>::isAliased( const Other* alias ) const noexcept
1946 {
1947  return vector_.isAliased( alias );
1948 }
1950 //*************************************************************************************************
1951 
1952 
1953 //*************************************************************************************************
1964 template< typename VT // Type of the sparse vector
1965  , AlignmentFlag AF // Alignment flag
1966  , bool TF // Transpose flag
1967  , size_t... CSAs > // Compile time subvector arguments
1968 inline bool Subvector<VT,AF,TF,false,CSAs...>::canSMPAssign() const noexcept
1969 {
1970  return false;
1971 }
1973 //*************************************************************************************************
1974 
1975 
1976 //*************************************************************************************************
1988 template< typename VT // Type of the sparse vector
1989  , AlignmentFlag AF // Alignment flag
1990  , bool TF // Transpose flag
1991  , size_t... CSAs > // Compile time subvector arguments
1992 template< typename VT2 > // Type of the right-hand side dense vector
1993 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const DenseVector<VT2,TF>& rhs )
1994 {
1995  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1996  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1997 
1998  reserve( (~rhs).size() );
1999 
2000  for( size_t i=0UL; i<size(); ++i ) {
2001  append( i, (~rhs)[i], true );
2002  }
2003 }
2005 //*************************************************************************************************
2006 
2007 
2008 //*************************************************************************************************
2020 template< typename VT // Type of the sparse vector
2021  , AlignmentFlag AF // Alignment flag
2022  , bool TF // Transpose flag
2023  , size_t... CSAs > // Compile time subvector arguments
2024 template< typename VT2 > // Type of the right-hand side sparse vector
2025 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const SparseVector<VT2,TF>& rhs )
2026 {
2027  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2028  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2029 
2030  reserve( (~rhs).nonZeros() );
2031 
2032  for( ConstIterator_t<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2033  append( element->index(), element->value(), true );
2034  }
2035 }
2037 //*************************************************************************************************
2038 
2039 
2040 //*************************************************************************************************
2052 template< typename VT // Type of the sparse vector
2053  , AlignmentFlag AF // Alignment flag
2054  , bool TF // Transpose flag
2055  , size_t... CSAs > // Compile time subvector arguments
2056 template< typename VT2 > // Type of the right-hand side dense vector
2057 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const DenseVector<VT2,TF>& rhs )
2058 {
2059  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2060 
2064 
2065  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2066 
2067  const AddType tmp( serial( *this + (~rhs) ) );
2068  reset();
2069  assign( tmp );
2070 }
2072 //*************************************************************************************************
2073 
2074 
2075 //*************************************************************************************************
2087 template< typename VT // Type of the sparse vector
2088  , AlignmentFlag AF // Alignment flag
2089  , bool TF // Transpose flag
2090  , size_t... CSAs > // Compile time subvector arguments
2091 template< typename VT2 > // Type of the right-hand side sparse vector
2092 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const SparseVector<VT2,TF>& rhs )
2093 {
2094  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2095 
2099 
2100  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2101 
2102  const AddType tmp( serial( *this + (~rhs) ) );
2103  reset();
2104  assign( tmp );
2105 }
2107 //*************************************************************************************************
2108 
2109 
2110 //*************************************************************************************************
2122 template< typename VT // Type of the sparse vector
2123  , AlignmentFlag AF // Alignment flag
2124  , bool TF // Transpose flag
2125  , size_t... CSAs > // Compile time subvector arguments
2126 template< typename VT2 > // Type of the right-hand side dense vector
2127 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const DenseVector<VT2,TF>& rhs )
2128 {
2129  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2130 
2134 
2135  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2136 
2137  const SubType tmp( serial( *this - (~rhs) ) );
2138  reset();
2139  assign( tmp );
2140 }
2142 //*************************************************************************************************
2143 
2144 
2145 //*************************************************************************************************
2157 template< typename VT // Type of the sparse vector
2158  , AlignmentFlag AF // Alignment flag
2159  , bool TF // Transpose flag
2160  , size_t... CSAs > // Compile time subvector arguments
2161 template< typename VT2 > // Type of the right-hand side sparse vector
2162 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const SparseVector<VT2,TF>& rhs )
2163 {
2164  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2165 
2169 
2170  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2171 
2172  const SubType tmp( serial( *this - (~rhs) ) );
2173  reset();
2174  assign( tmp );
2175 }
2177 //*************************************************************************************************
2178 
2179 } // namespace blaze
2180 
2181 #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.
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:432
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for the alignment flag values.
Header file for the subtraction trait.
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
Header file for basic type definitions.
constexpr 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:750
Header file for the SparseVector base class.
Header file for the View base class.
Header file for the serial shim.
#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
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the IsIntegral type trait.
constexpr bool IsReference_v
Auxiliary variable template for the IsReference type trait.The IsReference_v variable template provid...
Definition: IsReference.h:95
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
#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.
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:482
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:416
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the multiplication trait.
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.
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:9091
#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.
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:370
Header file for the implementation of the SubvectorData class template.
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
Header file for the subvector trait.
constexpr bool Contains_v
Auxiliary variable template for the Contains type trait.The Contains_v variable template provides a c...
Definition: Contains.h:138
#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.
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:438
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
Constraint on the data type.
Constraint on the data type.
typename SubvectorTrait< VT, CSAs... >::Type SubvectorTrait_t
Auxiliary alias declaration for the SubvectorTrait type trait.The SubvectorTrait_t alias declaration ...
Definition: SubvectorTrait.h:171
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:558
Header file for the IsConst type trait.
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.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#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.
#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....
Definition: Subvector.h:81
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
auto operator *=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:494
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.The IsIntegral_v variable template provides...
Definition: IsIntegral.h:95
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
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,...
Definition: Assert.h:101
Header file for the IsExpression type trait class.