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_t< IsExpression_v<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_t<VT,CSAs...>;
122  using TransposeType = TransposeType_t<ResultType>;
123  using ElementType = ElementType_t<VT>;
124  using ReturnType = ReturnType_t<VT>;
125  using CompositeType = const Subvector&;
126 
128  using ConstReference = ConstReference_t<VT>;
129 
131  using Reference = If_t< IsConst_v<VT>, ConstReference, Reference_t<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_t<VT> >;
418 
420  using Iterator = If_t< IsConst_v<VT>, ConstIterator, SubvectorIterator< VT, Iterator_t<VT> > >;
421  //**********************************************************************************************
422 
423  //**Compilation flags***************************************************************************
425  static constexpr bool smpAssignable = VT::smpAssignable;
426  //**********************************************************************************************
427 
428  //**Constructors********************************************************************************
431  template< typename... RSAs >
432  explicit inline Subvector( VT& vector, RSAs... args );
433 
434  Subvector( const Subvector& ) = default;
436  //**********************************************************************************************
437 
438  //**Destructor**********************************************************************************
441  ~Subvector() = default;
443  //**********************************************************************************************
444 
445  //**Data access functions***********************************************************************
448  inline Reference operator[]( size_t index );
449  inline ConstReference operator[]( size_t index ) const;
450  inline Reference at( size_t index );
451  inline ConstReference at( size_t index ) const;
452  inline Iterator begin ();
453  inline ConstIterator begin () const;
454  inline ConstIterator cbegin() const;
455  inline Iterator end ();
456  inline ConstIterator end () const;
457  inline ConstIterator cend () const;
459  //**********************************************************************************************
460 
461  //**Assignment operators************************************************************************
464  inline Subvector& operator= ( initializer_list<ElementType> list );
465  inline Subvector& operator= ( const Subvector& rhs );
466  template< typename VT2 > inline Subvector& operator= ( const Vector<VT2,TF>& rhs );
467  template< typename VT2 > inline Subvector& operator+=( const Vector<VT2,TF>& 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 DenseVector<VT2,TF>& rhs );
471  template< typename VT2 > inline Subvector& operator%=( const Vector<VT2,TF>& rhs );
473  //**********************************************************************************************
474 
475  //**Utility functions***************************************************************************
478  using DataType::offset;
479  using DataType::size;
480 
481  inline VT& operand() noexcept;
482  inline const VT& operand() const noexcept;
483 
484  inline size_t capacity() const noexcept;
485  inline size_t nonZeros() const;
486  inline void reset();
487  inline void reserve( size_t n );
489  //**********************************************************************************************
490 
491  //**Insertion functions*************************************************************************
494  inline Iterator set ( size_t index, const ElementType& value );
495  inline Iterator insert( size_t index, const ElementType& value );
496  inline void append( size_t index, const ElementType& value, bool check=false );
498  //**********************************************************************************************
499 
500  //**Erase functions*****************************************************************************
503  inline void erase( size_t index );
504  inline Iterator erase( Iterator pos );
505  inline Iterator erase( Iterator first, Iterator last );
506 
507  template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
508  inline void erase( Pred predicate );
509 
510  template< typename Pred >
511  inline void erase( Iterator first, Iterator last, Pred predicate );
513  //**********************************************************************************************
514 
515  //**Lookup functions****************************************************************************
518  inline Iterator find ( size_t index );
519  inline ConstIterator find ( size_t index ) const;
520  inline Iterator lowerBound( size_t index );
521  inline ConstIterator lowerBound( size_t index ) const;
522  inline Iterator upperBound( size_t index );
523  inline ConstIterator upperBound( size_t index ) const;
525  //**********************************************************************************************
526 
527  //**Numeric functions***************************************************************************
530  template< typename Other > inline Subvector& scale( const Other& scalar );
532  //**********************************************************************************************
533 
534  //**Expression template evaluation functions****************************************************
537  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
538  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
539 
540  inline bool canSMPAssign() const noexcept;
541 
542  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
543  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
544  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
545  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
546  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
547  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
549  //**********************************************************************************************
550 
551  private:
552  //**Member variables****************************************************************************
555  Operand vector_;
556 
557  //**********************************************************************************************
558 
559  //**Compile time checks*************************************************************************
565  //**********************************************************************************************
566 };
568 //*************************************************************************************************
569 
570 
571 
572 
573 //=================================================================================================
574 //
575 // CONSTRUCTORS
576 //
577 //=================================================================================================
578 
579 //*************************************************************************************************
593 template< typename VT // Type of the sparse vector
594  , AlignmentFlag AF // Alignment flag
595  , bool TF // Transpose flag
596  , size_t... CSAs > // Compile time subvector arguments
597 template< typename... RSAs > // Runtime subvector arguments
598 inline Subvector<VT,AF,TF,false,CSAs...>::Subvector( VT& vector, RSAs... args )
599  : DataType( args... ) // Base class initialization
600  , vector_ ( vector ) // The vector containing the subvector
601 {
602  if( !Contains_v< TypeList<RSAs...>, Unchecked > ) {
603  if( offset() + size() > vector.size() ) {
604  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
605  }
606  }
607  else {
608  BLAZE_USER_ASSERT( offset() + size() <= vector.size(), "Invalid subvector specification" );
609  }
610 }
612 //*************************************************************************************************
613 
614 
615 
616 
617 //=================================================================================================
618 //
619 // DATA ACCESS FUNCTIONS
620 //
621 //=================================================================================================
622 
623 //*************************************************************************************************
633 template< typename VT // Type of the sparse vector
634  , AlignmentFlag AF // Alignment flag
635  , bool TF // Transpose flag
636  , size_t... CSAs > // Compile time subvector arguments
637 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
638  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index )
639 {
640  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
641  return vector_[offset()+index];
642 }
644 //*************************************************************************************************
645 
646 
647 //*************************************************************************************************
657 template< typename VT // Type of the sparse vector
658  , AlignmentFlag AF // Alignment flag
659  , bool TF // Transpose flag
660  , size_t... CSAs > // Compile time subvector arguments
661 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
662  Subvector<VT,AF,TF,false,CSAs...>::operator[]( size_t index ) const
663 {
664  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
665  return const_cast<const VT&>( vector_ )[offset()+index];
666 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
682 template< typename VT // Type of the sparse vector
683  , AlignmentFlag AF // Alignment flag
684  , bool TF // Transpose flag
685  , size_t... CSAs > // Compile time subvector arguments
686 inline typename Subvector<VT,AF,TF,false,CSAs...>::Reference
687  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index )
688 {
689  if( index >= size() ) {
690  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
691  }
692  return (*this)[index];
693 }
695 //*************************************************************************************************
696 
697 
698 //*************************************************************************************************
709 template< typename VT // Type of the sparse vector
710  , AlignmentFlag AF // Alignment flag
711  , bool TF // Transpose flag
712  , size_t... CSAs > // Compile time subvector arguments
713 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstReference
714  Subvector<VT,AF,TF,false,CSAs...>::at( size_t index ) const
715 {
716  if( index >= size() ) {
717  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
718  }
719  return (*this)[index];
720 }
722 //*************************************************************************************************
723 
724 
725 //*************************************************************************************************
733 template< typename VT // Type of the sparse vector
734  , AlignmentFlag AF // Alignment flag
735  , bool TF // Transpose flag
736  , size_t... CSAs > // Compile time subvector arguments
737 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
739 {
740  if( offset() == 0UL )
741  return Iterator( vector_.begin(), offset() );
742  else
743  return Iterator( vector_.lowerBound( offset() ), offset() );
744 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
757 template< typename VT // Type of the sparse vector
758  , AlignmentFlag AF // Alignment flag
759  , bool TF // Transpose flag
760  , size_t... CSAs > // Compile time subvector arguments
761 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
763 {
764  if( offset() == 0UL )
765  return ConstIterator( vector_.cbegin(), offset() );
766  else
767  return ConstIterator( vector_.lowerBound( offset() ), offset() );
768 }
770 //*************************************************************************************************
771 
772 
773 //*************************************************************************************************
781 template< typename VT // Type of the sparse vector
782  , AlignmentFlag AF // Alignment flag
783  , bool TF // Transpose flag
784  , size_t... CSAs > // Compile time subvector arguments
785 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
787 {
788  if( offset() == 0UL )
789  return ConstIterator( vector_.cbegin(), offset() );
790  else
791  return ConstIterator( vector_.lowerBound( offset() ), offset() );
792 }
794 //*************************************************************************************************
795 
796 
797 //*************************************************************************************************
805 template< typename VT // Type of the sparse vector
806  , AlignmentFlag AF // Alignment flag
807  , bool TF // Transpose flag
808  , size_t... CSAs > // Compile time subvector arguments
809 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
811 {
812  if( offset() + size() == vector_.size() )
813  return Iterator( vector_.end(), offset() );
814  else
815  return Iterator( vector_.lowerBound( offset() + size() ), offset() );
816 }
818 //*************************************************************************************************
819 
820 
821 //*************************************************************************************************
829 template< typename VT // Type of the sparse vector
830  , AlignmentFlag AF // Alignment flag
831  , bool TF // Transpose flag
832  , size_t... CSAs > // Compile time subvector arguments
833 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
835 {
836  if( offset() + size() == vector_.size() )
837  return ConstIterator( vector_.cend(), offset() );
838  else
839  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
840 }
842 //*************************************************************************************************
843 
844 
845 //*************************************************************************************************
853 template< typename VT // Type of the sparse vector
854  , AlignmentFlag AF // Alignment flag
855  , bool TF // Transpose flag
856  , size_t... CSAs > // Compile time subvector arguments
857 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
859 {
860  if( offset() + size() == vector_.size() )
861  return ConstIterator( vector_.cend(), offset() );
862  else
863  return ConstIterator( vector_.lowerBound( offset() + size() ), offset() );
864 }
866 //*************************************************************************************************
867 
868 
869 
870 
871 //=================================================================================================
872 //
873 // ASSIGNMENT OPERATORS
874 //
875 //=================================================================================================
876 
877 //*************************************************************************************************
892 template< typename VT // Type of the sparse vector
893  , AlignmentFlag AF // Alignment flag
894  , bool TF // Transpose flag
895  , size_t... CSAs > // Compile time subvector arguments
896 inline Subvector<VT,AF,TF,false,CSAs...>&
897  Subvector<VT,AF,TF,false,CSAs...>::operator=( initializer_list<ElementType> list )
898 {
899  using blaze::assign;
900 
901  if( list.size() > size() ) {
902  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to subvector" );
903  }
904 
905  const InitializerVector<ElementType,TF> tmp( list, size() );
906 
907  if( !tryAssign( vector_, tmp, offset() ) ) {
908  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
909  }
910 
911  decltype(auto) left( derestrict( *this ) );
912 
913  reset();
914  assign( left, tmp );
915 
916  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
917 
918  return *this;
919 }
921 //*************************************************************************************************
922 
923 
924 //*************************************************************************************************
936 template< typename VT // Type of the sparse vector
937  , AlignmentFlag AF // Alignment flag
938  , bool TF // Transpose flag
939  , size_t... CSAs > // Compile time subvector arguments
940 inline Subvector<VT,AF,TF,false,CSAs...>&
941  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Subvector& rhs )
942 {
943  using blaze::assign;
944 
947 
948  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset() == rhs.offset() ) )
949  return *this;
950 
951  if( size() != rhs.size() ) {
952  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
953  }
954 
955  if( !tryAssign( vector_, rhs, offset() ) ) {
956  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
957  }
958 
959  decltype(auto) left( derestrict( *this ) );
960 
961  if( rhs.canAlias( &vector_ ) ) {
962  const ResultType tmp( rhs );
963  reset();
964  assign( left, tmp );
965  }
966  else {
967  reset();
968  assign( left, rhs );
969  }
970 
971  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
972 
973  return *this;
974 }
976 //*************************************************************************************************
977 
978 
979 //*************************************************************************************************
991 template< typename VT // Type of the sparse vector
992  , AlignmentFlag AF // Alignment flag
993  , bool TF // Transpose flag
994  , size_t... CSAs > // Compile time subvector arguments
995 template< typename VT2 > // Type of the right-hand side vector
996 inline Subvector<VT,AF,TF,false,CSAs...>&
997  Subvector<VT,AF,TF,false,CSAs...>::operator=( const Vector<VT2,TF>& rhs )
998 {
999  using blaze::assign;
1000 
1001  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1002  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1003 
1004  if( size() != (~rhs).size() ) {
1005  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1006  }
1007 
1008  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1009  Right right( ~rhs );
1010 
1011  if( !tryAssign( vector_, right, offset() ) ) {
1012  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1013  }
1014 
1015  decltype(auto) left( derestrict( *this ) );
1016 
1017  if( IsReference_v<Right> || right.canAlias( &vector_ ) ) {
1018  const ResultType_t<VT2> tmp( right );
1019  reset();
1020  assign( left, tmp );
1021  }
1022  else {
1023  reset();
1024  assign( left, right );
1025  }
1026 
1027  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1028 
1029  return *this;
1030 }
1032 //*************************************************************************************************
1033 
1034 
1035 //*************************************************************************************************
1047 template< typename VT // Type of the sparse vector
1048  , AlignmentFlag AF // Alignment flag
1049  , bool TF // Transpose flag
1050  , size_t... CSAs > // Compile time subvector arguments
1051 template< typename VT2 > // Type of the right-hand side vector
1052 inline Subvector<VT,AF,TF,false,CSAs...>&
1053  Subvector<VT,AF,TF,false,CSAs...>::operator+=( const Vector<VT2,TF>& rhs )
1054 {
1055  using blaze::assign;
1056 
1059  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1060 
1061  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
1062 
1065 
1066  if( size() != (~rhs).size() ) {
1067  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1068  }
1069 
1070  const AddType tmp( *this + (~rhs) );
1071 
1072  if( !tryAssign( vector_, tmp, offset() ) ) {
1073  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1074  }
1075 
1076  decltype(auto) left( derestrict( *this ) );
1077 
1078  left.reset();
1079  assign( left, tmp );
1080 
1081  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1082 
1083  return *this;
1084 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1101 template< typename VT // Type of the sparse vector
1102  , AlignmentFlag AF // Alignment flag
1103  , bool TF // Transpose flag
1104  , size_t... CSAs > // Compile time subvector arguments
1105 template< typename VT2 > // Type of the right-hand side vector
1106 inline Subvector<VT,AF,TF,false,CSAs...>&
1107  Subvector<VT,AF,TF,false,CSAs...>::operator-=( const Vector<VT2,TF>& rhs )
1108 {
1109  using blaze::assign;
1110 
1113  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1114 
1115  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
1116 
1119 
1120  if( size() != (~rhs).size() ) {
1121  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1122  }
1123 
1124  const SubType tmp( *this - (~rhs) );
1125 
1126  if( !tryAssign( vector_, tmp, offset() ) ) {
1127  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1128  }
1129 
1130  decltype(auto) left( derestrict( *this ) );
1131 
1132  left.reset();
1133  assign( left, tmp );
1134 
1135  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1136 
1137  return *this;
1138 }
1140 //*************************************************************************************************
1141 
1142 
1143 //*************************************************************************************************
1156 template< typename VT // Type of the sparse vector
1157  , AlignmentFlag AF // Alignment flag
1158  , bool TF // Transpose flag
1159  , size_t... CSAs > // Compile time subvector arguments
1160 template< typename VT2 > // Type of the right-hand side vector
1161 inline Subvector<VT,AF,TF,false,CSAs...>&
1162  Subvector<VT,AF,TF,false,CSAs...>::operator*=( const Vector<VT2,TF>& rhs )
1163 {
1164  using blaze::assign;
1165 
1168  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1169 
1170  using MultType = MultTrait_t< ResultType, ResultType_t<VT2> >;
1171 
1174 
1175  if( size() != (~rhs).size() ) {
1176  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1177  }
1178 
1179  const MultType tmp( *this * (~rhs) );
1180 
1181  if( !tryAssign( vector_, tmp, offset() ) ) {
1182  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1183  }
1184 
1185  decltype(auto) left( derestrict( *this ) );
1186 
1187  left.reset();
1188  assign( left, tmp );
1189 
1190  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1191 
1192  return *this;
1193 }
1195 //*************************************************************************************************
1196 
1197 
1198 //*************************************************************************************************
1210 template< typename VT // Type of the sparse vector
1211  , AlignmentFlag AF // Alignment flag
1212  , bool TF // Transpose flag
1213  , size_t... CSAs > // Compile time subvector arguments
1214 template< typename VT2 > // Type of the right-hand side dense vector
1215 inline Subvector<VT,AF,TF,false,CSAs...>&
1216  Subvector<VT,AF,TF,false,CSAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1217 {
1218  using blaze::assign;
1219 
1222  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT2> );
1223  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1224 
1225  using DivType = DivTrait_t< ResultType, ResultType_t<VT2> >;
1226 
1230 
1231  if( size() != (~rhs).size() ) {
1232  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1233  }
1234 
1235  const DivType tmp( *this / (~rhs) );
1236 
1237  if( !tryAssign( vector_, tmp, offset() ) ) {
1238  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1239  }
1240 
1241  decltype(auto) left( derestrict( *this ) );
1242 
1243  left.reset();
1244  assign( left, tmp );
1245 
1246  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1247 
1248  return *this;
1249 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1267 template< typename VT // Type of the sparse vector
1268  , AlignmentFlag AF // Alignment flag
1269  , bool TF // Transpose flag
1270  , size_t... CSAs > // Compile time subvector arguments
1271 template< typename VT2 > // Type of the right-hand side vector
1272 inline Subvector<VT,AF,TF,false,CSAs...>&
1273  Subvector<VT,AF,TF,false,CSAs...>::operator%=( const Vector<VT2,TF>& rhs )
1274 {
1275  using blaze::assign;
1276 
1277  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1278  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1279 
1280  using CrossType = CrossTrait_t< ResultType, ResultType_t<VT2> >;
1281 
1285 
1286  if( size() != 3UL || (~rhs).size() != 3UL ) {
1287  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1288  }
1289 
1290  const CrossType tmp( *this % (~rhs) );
1291 
1292  if( !tryAssign( vector_, tmp, offset() ) ) {
1293  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1294  }
1295 
1296  decltype(auto) left( derestrict( *this ) );
1297 
1298  left.reset();
1299  assign( left, tmp );
1300 
1301  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1302 
1303  return *this;
1304 }
1306 //*************************************************************************************************
1307 
1308 
1309 
1310 
1311 //=================================================================================================
1312 //
1313 // UTILITY FUNCTIONS
1314 //
1315 //=================================================================================================
1316 
1317 //*************************************************************************************************
1323 template< typename VT // Type of the sparse vector
1324  , AlignmentFlag AF // Alignment flag
1325  , bool TF // Transpose flag
1326  , size_t... CSAs > // Compile time subvector arguments
1327 inline VT& Subvector<VT,AF,TF,false,CSAs...>::operand() noexcept
1328 {
1329  return vector_;
1330 }
1332 //*************************************************************************************************
1333 
1334 
1335 //*************************************************************************************************
1341 template< typename VT // Type of the sparse vector
1342  , AlignmentFlag AF // Alignment flag
1343  , bool TF // Transpose flag
1344  , size_t... CSAs > // Compile time subvector arguments
1345 inline const VT& Subvector<VT,AF,TF,false,CSAs...>::operand() const noexcept
1346 {
1347  return vector_;
1348 }
1350 //*************************************************************************************************
1351 
1352 
1353 //*************************************************************************************************
1359 template< typename VT // Type of the sparse vector
1360  , AlignmentFlag AF // Alignment flag
1361  , bool TF // Transpose flag
1362  , size_t... CSAs > // Compile time subvector arguments
1363 inline size_t Subvector<VT,AF,TF,false,CSAs...>::capacity() const noexcept
1364 {
1365  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1366 }
1368 //*************************************************************************************************
1369 
1370 
1371 //*************************************************************************************************
1379 template< typename VT // Type of the sparse vector
1380  , AlignmentFlag AF // Alignment flag
1381  , bool TF // Transpose flag
1382  , size_t... CSAs > // Compile time subvector arguments
1383 inline size_t Subvector<VT,AF,TF,false,CSAs...>::nonZeros() const
1384 {
1385  return end() - begin();
1386 }
1388 //*************************************************************************************************
1389 
1390 
1391 //*************************************************************************************************
1397 template< typename VT // Type of the sparse vector
1398  , AlignmentFlag AF // Alignment flag
1399  , bool TF // Transpose flag
1400  , size_t... CSAs > // Compile time subvector arguments
1402 {
1403  vector_.erase( vector_.lowerBound( offset() ), vector_.lowerBound( offset() + size() ) );
1404 }
1406 //*************************************************************************************************
1407 
1408 
1409 //*************************************************************************************************
1419 template< typename VT // Type of the sparse vector
1420  , AlignmentFlag AF // Alignment flag
1421  , bool TF // Transpose flag
1422  , size_t... CSAs > // Compile time subvector arguments
1423 void Subvector<VT,AF,TF,false,CSAs...>::reserve( size_t n )
1424 {
1425  const size_t current( capacity() );
1426 
1427  if( n > current ) {
1428  vector_.reserve( vector_.capacity() + n - current );
1429  }
1430 }
1432 //*************************************************************************************************
1433 
1434 
1435 
1436 
1437 //=================================================================================================
1438 //
1439 // INSERTION FUNCTIONS
1440 //
1441 //=================================================================================================
1442 
1443 //*************************************************************************************************
1455 template< typename VT // Type of the sparse vector
1456  , AlignmentFlag AF // Alignment flag
1457  , bool TF // Transpose flag
1458  , size_t... CSAs > // Compile time subvector arguments
1459 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1460  Subvector<VT,AF,TF,false,CSAs...>::set( size_t index, const ElementType& value )
1461 {
1462  return Iterator( vector_.set( offset() + index, value ), offset() );
1463 }
1465 //*************************************************************************************************
1466 
1467 
1468 //*************************************************************************************************
1481 template< typename VT // Type of the sparse vector
1482  , AlignmentFlag AF // Alignment flag
1483  , bool TF // Transpose flag
1484  , size_t... CSAs > // Compile time subvector arguments
1485 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1486  Subvector<VT,AF,TF,false,CSAs...>::insert( size_t index, const ElementType& value )
1487 {
1488  return Iterator( vector_.insert( offset() + index, value ), offset() );
1489 }
1491 //*************************************************************************************************
1492 
1493 
1494 //*************************************************************************************************
1519 template< typename VT // Type of the sparse vector
1520  , AlignmentFlag AF // Alignment flag
1521  , bool TF // Transpose flag
1522  , size_t... CSAs > // Compile time subvector arguments
1523 inline void Subvector<VT,AF,TF,false,CSAs...>::append( size_t index, const ElementType& value, bool check )
1524 {
1525  if( offset() + size() == vector_.size() )
1526  vector_.append( offset() + index, value, check );
1527  else if( !check || !isDefault<strict>( value ) )
1528  vector_.insert( offset() + index, value );
1529 }
1531 //*************************************************************************************************
1532 
1533 
1534 
1535 
1536 //=================================================================================================
1537 //
1538 // ERASE FUNCTIONS
1539 //
1540 //=================================================================================================
1541 
1542 //*************************************************************************************************
1551 template< typename VT // Type of the sparse vector
1552  , AlignmentFlag AF // Alignment flag
1553  , bool TF // Transpose flag
1554  , size_t... CSAs > // Compile time subvector arguments
1555 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( size_t index )
1556 {
1557  vector_.erase( offset() + index );
1558 }
1560 //*************************************************************************************************
1561 
1562 
1563 //*************************************************************************************************
1572 template< typename VT // Type of the sparse vector
1573  , AlignmentFlag AF // Alignment flag
1574  , bool TF // Transpose flag
1575  , size_t... CSAs > // Compile time subvector arguments
1576 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1577  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator pos )
1578 {
1579  return Iterator( vector_.erase( pos.base() ), offset() );
1580 }
1582 //*************************************************************************************************
1583 
1584 
1585 //*************************************************************************************************
1595 template< typename VT // Type of the sparse vector
1596  , AlignmentFlag AF // Alignment flag
1597  , bool TF // Transpose flag
1598  , size_t... CSAs > // Compile time subvector arguments
1599 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1600  Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last )
1601 {
1602  return Iterator( vector_.erase( first.base(), last.base() ), offset() );
1603 }
1605 //*************************************************************************************************
1606 
1607 
1608 //*************************************************************************************************
1631 template< typename VT // Type of the sparse vector
1632  , AlignmentFlag AF // Alignment flag
1633  , bool TF // Transpose flag
1634  , size_t... CSAs > // Compile time subvector arguments
1635 template< typename Pred // Type of the unary predicate
1636  , typename > // Type restriction on the unary predicate
1637 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Pred predicate )
1638 {
1639  vector_.erase( begin().base(), end().base(), predicate );
1640 }
1642 //*************************************************************************************************
1643 
1644 
1645 //*************************************************************************************************
1671 template< typename VT // Type of the sparse vector
1672  , AlignmentFlag AF // Alignment flag
1673  , bool TF // Transpose flag
1674  , size_t... CSAs > // Compile time subvector arguments
1675 template< typename Pred > // Type of the unary predicate
1676 inline void Subvector<VT,AF,TF,false,CSAs...>::erase( Iterator first, Iterator last, Pred predicate )
1677 {
1678  vector_.erase( first.base(), last.base(), predicate );
1679 }
1681 //*************************************************************************************************
1682 
1683 
1684 
1685 
1686 //=================================================================================================
1687 //
1688 // LOOKUP FUNCTIONS
1689 //
1690 //=================================================================================================
1691 
1692 //*************************************************************************************************
1706 template< typename VT // Type of the sparse vector
1707  , AlignmentFlag AF // Alignment flag
1708  , bool TF // Transpose flag
1709  , size_t... CSAs > // Compile time subvector arguments
1710 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1711  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index )
1712 {
1713  const Iterator_t<VT> pos( vector_.find( offset() + index ) );
1714 
1715  if( pos != vector_.end() )
1716  return Iterator( pos, offset() );
1717  else
1718  return end();
1719 }
1721 //*************************************************************************************************
1722 
1723 
1724 //*************************************************************************************************
1738 template< typename VT // Type of the sparse vector
1739  , AlignmentFlag AF // Alignment flag
1740  , bool TF // Transpose flag
1741  , size_t... CSAs > // Compile time subvector arguments
1742 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1743  Subvector<VT,AF,TF,false,CSAs...>::find( size_t index ) const
1744 {
1745  const ConstIterator_t<VT> pos( vector_.find( offset() + index ) );
1746 
1747  if( pos != vector_.end() )
1748  return Iterator( pos, offset() );
1749  else
1750  return end();
1751 }
1753 //*************************************************************************************************
1754 
1755 
1756 //*************************************************************************************************
1769 template< typename VT // Type of the sparse vector
1770  , AlignmentFlag AF // Alignment flag
1771  , bool TF // Transpose flag
1772  , size_t... CSAs > // Compile time subvector arguments
1773 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1774  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index )
1775 {
1776  return Iterator( vector_.lowerBound( offset() + index ), offset() );
1777 }
1779 //*************************************************************************************************
1780 
1781 
1782 //*************************************************************************************************
1795 template< typename VT // Type of the sparse vector
1796  , AlignmentFlag AF // Alignment flag
1797  , bool TF // Transpose flag
1798  , size_t... CSAs > // Compile time subvector arguments
1799 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1800  Subvector<VT,AF,TF,false,CSAs...>::lowerBound( size_t index ) const
1801 {
1802  return ConstIterator( vector_.lowerBound( offset() + index ), offset() );
1803 }
1805 //*************************************************************************************************
1806 
1807 
1808 //*************************************************************************************************
1821 template< typename VT // Type of the sparse vector
1822  , AlignmentFlag AF // Alignment flag
1823  , bool TF // Transpose flag
1824  , size_t... CSAs > // Compile time subvector arguments
1825 inline typename Subvector<VT,AF,TF,false,CSAs...>::Iterator
1826  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index )
1827 {
1828  return Iterator( vector_.upperBound( offset() + index ), offset() );
1829 }
1831 //*************************************************************************************************
1832 
1833 
1834 //*************************************************************************************************
1847 template< typename VT // Type of the sparse vector
1848  , AlignmentFlag AF // Alignment flag
1849  , bool TF // Transpose flag
1850  , size_t... CSAs > // Compile time subvector arguments
1851 inline typename Subvector<VT,AF,TF,false,CSAs...>::ConstIterator
1852  Subvector<VT,AF,TF,false,CSAs...>::upperBound( size_t index ) const
1853 {
1854  return ConstIterator( vector_.upperBound( offset() + index ), offset() );
1855 }
1857 //*************************************************************************************************
1858 
1859 
1860 
1861 
1862 //=================================================================================================
1863 //
1864 // NUMERIC FUNCTIONS
1865 //
1866 //=================================================================================================
1867 
1868 //*************************************************************************************************
1879 template< typename VT // Type of the sparse vector
1880  , AlignmentFlag AF // Alignment flag
1881  , bool TF // Transpose flag
1882  , size_t... CSAs > // Compile time subvector arguments
1883 template< typename Other > // Data type of the scalar value
1884 inline Subvector<VT,AF,TF,false,CSAs...>&
1885  Subvector<VT,AF,TF,false,CSAs...>::scale( const Other& scalar )
1886 {
1887  for( Iterator element=begin(); element!=end(); ++element )
1888  element->value() *= scalar;
1889  return *this;
1890 }
1892 //*************************************************************************************************
1893 
1894 
1895 
1896 
1897 //=================================================================================================
1898 //
1899 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1900 //
1901 //=================================================================================================
1902 
1903 //*************************************************************************************************
1914 template< typename VT // Type of the sparse vector
1915  , AlignmentFlag AF // Alignment flag
1916  , bool TF // Transpose flag
1917  , size_t... CSAs > // Compile time subvector arguments
1918 template< typename Other > // Data type of the foreign expression
1919 inline bool Subvector<VT,AF,TF,false,CSAs...>::canAlias( const Other* alias ) const noexcept
1920 {
1921  return vector_.isAliased( alias );
1922 }
1924 //*************************************************************************************************
1925 
1926 
1927 //*************************************************************************************************
1938 template< typename VT // Type of the sparse vector
1939  , AlignmentFlag AF // Alignment flag
1940  , bool TF // Transpose flag
1941  , size_t... CSAs > // Compile time subvector arguments
1942 template< typename Other > // Data type of the foreign expression
1943 inline bool Subvector<VT,AF,TF,false,CSAs...>::isAliased( const Other* alias ) const noexcept
1944 {
1945  return vector_.isAliased( alias );
1946 }
1948 //*************************************************************************************************
1949 
1950 
1951 //*************************************************************************************************
1962 template< typename VT // Type of the sparse vector
1963  , AlignmentFlag AF // Alignment flag
1964  , bool TF // Transpose flag
1965  , size_t... CSAs > // Compile time subvector arguments
1966 inline bool Subvector<VT,AF,TF,false,CSAs...>::canSMPAssign() const noexcept
1967 {
1968  return false;
1969 }
1971 //*************************************************************************************************
1972 
1973 
1974 //*************************************************************************************************
1986 template< typename VT // Type of the sparse vector
1987  , AlignmentFlag AF // Alignment flag
1988  , bool TF // Transpose flag
1989  , size_t... CSAs > // Compile time subvector arguments
1990 template< typename VT2 > // Type of the right-hand side dense vector
1991 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const DenseVector<VT2,TF>& rhs )
1992 {
1993  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1994  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1995 
1996  reserve( (~rhs).size() );
1997 
1998  for( size_t i=0UL; i<size(); ++i ) {
1999  append( i, (~rhs)[i], true );
2000  }
2001 }
2003 //*************************************************************************************************
2004 
2005 
2006 //*************************************************************************************************
2018 template< typename VT // Type of the sparse vector
2019  , AlignmentFlag AF // Alignment flag
2020  , bool TF // Transpose flag
2021  , size_t... CSAs > // Compile time subvector arguments
2022 template< typename VT2 > // Type of the right-hand side sparse vector
2023 inline void Subvector<VT,AF,TF,false,CSAs...>::assign( const SparseVector<VT2,TF>& rhs )
2024 {
2025  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2026  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2027 
2028  reserve( (~rhs).nonZeros() );
2029 
2030  for( ConstIterator_t<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2031  append( element->index(), element->value(), true );
2032  }
2033 }
2035 //*************************************************************************************************
2036 
2037 
2038 //*************************************************************************************************
2050 template< typename VT // Type of the sparse vector
2051  , AlignmentFlag AF // Alignment flag
2052  , bool TF // Transpose flag
2053  , size_t... CSAs > // Compile time subvector arguments
2054 template< typename VT2 > // Type of the right-hand side dense vector
2055 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const DenseVector<VT2,TF>& rhs )
2056 {
2057  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2058 
2062 
2063  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2064 
2065  const AddType tmp( serial( *this + (~rhs) ) );
2066  reset();
2067  assign( tmp );
2068 }
2070 //*************************************************************************************************
2071 
2072 
2073 //*************************************************************************************************
2085 template< typename VT // Type of the sparse vector
2086  , AlignmentFlag AF // Alignment flag
2087  , bool TF // Transpose flag
2088  , size_t... CSAs > // Compile time subvector arguments
2089 template< typename VT2 > // Type of the right-hand side sparse vector
2090 inline void Subvector<VT,AF,TF,false,CSAs...>::addAssign( const SparseVector<VT2,TF>& rhs )
2091 {
2092  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2093 
2097 
2098  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2099 
2100  const AddType tmp( serial( *this + (~rhs) ) );
2101  reset();
2102  assign( tmp );
2103 }
2105 //*************************************************************************************************
2106 
2107 
2108 //*************************************************************************************************
2120 template< typename VT // Type of the sparse vector
2121  , AlignmentFlag AF // Alignment flag
2122  , bool TF // Transpose flag
2123  , size_t... CSAs > // Compile time subvector arguments
2124 template< typename VT2 > // Type of the right-hand side dense vector
2125 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const DenseVector<VT2,TF>& rhs )
2126 {
2127  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2128 
2132 
2133  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2134 
2135  const SubType tmp( serial( *this - (~rhs) ) );
2136  reset();
2137  assign( tmp );
2138 }
2140 //*************************************************************************************************
2141 
2142 
2143 //*************************************************************************************************
2155 template< typename VT // Type of the sparse vector
2156  , AlignmentFlag AF // Alignment flag
2157  , bool TF // Transpose flag
2158  , size_t... CSAs > // Compile time subvector arguments
2159 template< typename VT2 > // Type of the right-hand side sparse vector
2160 inline void Subvector<VT,AF,TF,false,CSAs...>::subAssign( const SparseVector<VT2,TF>& rhs )
2161 {
2162  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2163 
2167 
2168  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2169 
2170  const SubType tmp( serial( *this - (~rhs) ) );
2171  reset();
2172  assign( tmp );
2173 }
2175 //*************************************************************************************************
2176 
2177 } // namespace blaze
2178 
2179 #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
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:354
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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:3077
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
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3075
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:591
static constexpr bool smpAssignable
Compilation flag for SMP assignments.
Definition: CompressedMatrix.h:3113
Header file for the IsIntegral type trait.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:3079
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3084
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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3085
#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.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:3083
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:3076
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3080
#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:3086
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:139
#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
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:8908
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
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.
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.
Header file for the RemoveReference type trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:3081
#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
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:3082
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:290
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:263
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.The IsIntegral_v variable template provides...
Definition: IsIntegral.h:95
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
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, 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.