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>
53 #include <blaze/math/Exception.h>
68 #include <blaze/util/Assert.h>
69 #include <blaze/util/DisableIf.h>
70 #include <blaze/util/EnableIf.h>
71 #include <blaze/util/mpl/If.h>
72 #include <blaze/util/Types.h>
79 
80 
81 namespace blaze {
82 
83 //=================================================================================================
84 //
85 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE SUBVECTORS
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
97 template< typename VT // Type of the sparse vector
98  , bool AF // Alignment flag
99  , bool TF > // Transpose flag
100 class Subvector<VT,AF,TF,false>
101  : public SparseVector< Subvector<VT,AF,TF,false>, TF >
102  , private View
103 {
104  private:
105  //**Type definitions****************************************************************************
107  typedef If_< IsExpression<VT>, VT, VT& > Operand;
108  //**********************************************************************************************
109 
110  public:
111  //**Type definitions****************************************************************************
112  typedef Subvector<VT,AF,TF,false> This;
113  typedef SparseVector<This,TF> BaseType;
114  typedef SubvectorTrait_<VT> ResultType;
115  typedef TransposeType_<ResultType> TransposeType;
116  typedef ElementType_<VT> ElementType;
117  typedef ReturnType_<VT> ReturnType;
118  typedef const Subvector& CompositeType;
119 
121  typedef ConstReference_<VT> ConstReference;
122 
124  typedef If_< IsConst<VT>, ConstReference, Reference_<VT> > Reference;
125  //**********************************************************************************************
126 
127  //**SubvectorElement class definition***********************************************************
130  template< typename VectorType // Type of the sparse vector
131  , typename IteratorType > // Type of the sparse vector iterator
132  class SubvectorElement : private SparseElement
133  {
134  private:
135  //*******************************************************************************************
137 
142  enum : bool { returnConst = IsConst<VectorType>::value };
143  //*******************************************************************************************
144 
145  //**Type definitions*************************************************************************
147  typedef typename std::iterator_traits<IteratorType>::value_type SET;
148 
149  typedef Reference_<SET> RT;
150  typedef ConstReference_<SET> CRT;
151  //*******************************************************************************************
152 
153  public:
154  //**Type definitions*************************************************************************
155  typedef ValueType_<SET> ValueType;
156  typedef size_t IndexType;
157  typedef IfTrue_<returnConst,CRT,RT> Reference;
158  typedef CRT ConstReference;
159  //*******************************************************************************************
160 
161  //**Constructor******************************************************************************
167  inline SubvectorElement( IteratorType pos, size_t offset )
168  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
169  , offset_( offset ) // Offset within the according sparse vector
170  {}
171  //*******************************************************************************************
172 
173  //**Assignment operator**********************************************************************
179  template< typename T > inline SubvectorElement& operator=( const T& v ) {
180  *pos_ = v;
181  return *this;
182  }
183  //*******************************************************************************************
184 
185  //**Addition assignment operator*************************************************************
191  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
192  *pos_ += v;
193  return *this;
194  }
195  //*******************************************************************************************
196 
197  //**Subtraction assignment operator**********************************************************
203  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
204  *pos_ -= v;
205  return *this;
206  }
207  //*******************************************************************************************
208 
209  //**Multiplication assignment operator*******************************************************
215  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
216  *pos_ *= v;
217  return *this;
218  }
219  //*******************************************************************************************
220 
221  //**Division assignment operator*************************************************************
227  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
228  *pos_ /= v;
229  return *this;
230  }
231  //*******************************************************************************************
232 
233  //**Element access operator******************************************************************
238  inline const SubvectorElement* operator->() const {
239  return this;
240  }
241  //*******************************************************************************************
242 
243  //**Value function***************************************************************************
248  inline Reference value() const {
249  return pos_->value();
250  }
251  //*******************************************************************************************
252 
253  //**Index function***************************************************************************
258  inline IndexType index() const {
259  return pos_->index() - offset_;
260  }
261  //*******************************************************************************************
262 
263  private:
264  //**Member variables*************************************************************************
265  IteratorType pos_;
266  size_t offset_;
267  //*******************************************************************************************
268  };
269  //**********************************************************************************************
270 
271  //**SubvectorIterator class definition**********************************************************
274  template< typename VectorType // Type of the sparse vector
275  , typename IteratorType > // Type of the sparse vector iterator
276  class SubvectorIterator
277  {
278  public:
279  //**Type definitions*************************************************************************
280  typedef std::forward_iterator_tag IteratorCategory;
281  typedef SubvectorElement<VectorType,IteratorType> ValueType;
282  typedef ValueType PointerType;
283  typedef ValueType ReferenceType;
284  typedef ptrdiff_t DifferenceType;
285 
286  // STL iterator requirements
287  typedef IteratorCategory iterator_category;
288  typedef ValueType value_type;
289  typedef PointerType pointer;
290  typedef ReferenceType reference;
291  typedef DifferenceType difference_type;
292  //*******************************************************************************************
293 
294  //**Default constructor**********************************************************************
297  inline SubvectorIterator()
298  : pos_ () // Iterator to the current sparse element
299  , offset_() // The offset of the subvector within the sparse vector
300  {}
301  //*******************************************************************************************
302 
303  //**Constructor******************************************************************************
309  inline SubvectorIterator( IteratorType iterator, size_t index )
310  : pos_ ( iterator ) // Iterator to the current sparse element
311  , offset_( index ) // The offset of the subvector within the sparse vector
312  {}
313  //*******************************************************************************************
314 
315  //**Constructor******************************************************************************
320  template< typename VectorType2, typename IteratorType2 >
321  inline SubvectorIterator( const SubvectorIterator<VectorType2,IteratorType2>& it )
322  : pos_ ( it.base() ) // Iterator to the current sparse element.
323  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
324  {}
325  //*******************************************************************************************
326 
327  //**Prefix increment operator****************************************************************
332  inline SubvectorIterator& operator++() {
333  ++pos_;
334  return *this;
335  }
336  //*******************************************************************************************
337 
338  //**Postfix increment operator***************************************************************
343  inline const SubvectorIterator operator++( int ) {
344  const SubvectorIterator tmp( *this );
345  ++(*this);
346  return tmp;
347  }
348  //*******************************************************************************************
349 
350  //**Element access operator******************************************************************
355  inline ReferenceType operator*() const {
356  return ReferenceType( pos_, offset_ );
357  }
358  //*******************************************************************************************
359 
360  //**Element access operator******************************************************************
365  inline PointerType operator->() const {
366  return PointerType( pos_, offset_ );
367  }
368  //*******************************************************************************************
369 
370  //**Equality operator************************************************************************
376  template< typename VectorType2, typename IteratorType2 >
377  inline bool operator==( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
378  return base() == rhs.base();
379  }
380  //*******************************************************************************************
381 
382  //**Inequality operator**********************************************************************
388  template< typename VectorType2, typename IteratorType2 >
389  inline bool operator!=( const SubvectorIterator<VectorType2,IteratorType2>& rhs ) const {
390  return !( *this == rhs );
391  }
392  //*******************************************************************************************
393 
394  //**Subtraction operator*********************************************************************
400  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
401  return pos_ - rhs.pos_;
402  }
403  //*******************************************************************************************
404 
405  //**Base function****************************************************************************
410  inline IteratorType base() const {
411  return pos_;
412  }
413  //*******************************************************************************************
414 
415  //**Offset function**************************************************************************
420  inline size_t offset() const noexcept {
421  return offset_;
422  }
423  //*******************************************************************************************
424 
425  private:
426  //**Member variables*************************************************************************
427  IteratorType pos_;
428  size_t offset_;
429  //*******************************************************************************************
430  };
431  //**********************************************************************************************
432 
433  //**Type definitions****************************************************************************
435  typedef SubvectorIterator< const VT, ConstIterator_<VT> > ConstIterator;
436 
438  typedef If_< IsConst<VT>, ConstIterator, SubvectorIterator< VT, Iterator_<VT> > > Iterator;
439  //**********************************************************************************************
440 
441  //**Compilation flags***************************************************************************
443  enum : bool { smpAssignable = VT::smpAssignable };
444  //**********************************************************************************************
445 
446  //**Constructors********************************************************************************
449  explicit inline Subvector( Operand vector, size_t index, size_t n );
450  // No explicitly declared copy constructor.
452  //**********************************************************************************************
453 
454  //**Destructor**********************************************************************************
455  // No explicitly declared destructor.
456  //**********************************************************************************************
457 
458  //**Data access functions***********************************************************************
461  inline Reference operator[]( size_t index );
462  inline ConstReference operator[]( size_t index ) const;
463  inline Reference at( size_t index );
464  inline ConstReference at( size_t index ) const;
465  inline Iterator begin ();
466  inline ConstIterator begin () const;
467  inline ConstIterator cbegin() const;
468  inline Iterator end ();
469  inline ConstIterator end () const;
470  inline ConstIterator cend () const;
472  //**********************************************************************************************
473 
474  //**Assignment operators************************************************************************
477  inline Subvector& operator= ( const Subvector& rhs );
478  template< typename VT2 > inline Subvector& operator= ( const Vector<VT2,TF>& rhs );
479  template< typename VT2 > inline Subvector& operator+=( const Vector<VT2,TF>& rhs );
480  template< typename VT2 > inline Subvector& operator-=( const Vector<VT2,TF>& rhs );
481  template< typename VT2 > inline Subvector& operator*=( const Vector<VT2,TF>& rhs );
482  template< typename VT2 > inline Subvector& operator/=( const DenseVector<VT2,TF>& rhs );
483 
484  template< typename Other >
485  inline EnableIf_<IsNumeric<Other>, Subvector >& operator*=( Other rhs );
486 
487  template< typename Other >
488  inline EnableIf_<IsNumeric<Other>, Subvector >& operator/=( Other rhs );
490  //**********************************************************************************************
491 
492  //**Utility functions***************************************************************************
495  inline size_t size() const noexcept;
496  inline size_t capacity() const noexcept;
497  inline size_t nonZeros() const;
498  inline void reset();
499  inline void reserve( size_t n );
501  //**********************************************************************************************
502 
503  //**Insertion functions*************************************************************************
506  inline Iterator set ( size_t index, const ElementType& value );
507  inline Iterator insert( size_t index, const ElementType& value );
508  inline void append( size_t index, const ElementType& value, bool check=false );
510  //**********************************************************************************************
511 
512  //**Erase functions*****************************************************************************
515  inline void erase( size_t index );
516  inline Iterator erase( Iterator pos );
517  inline Iterator erase( Iterator first, Iterator last );
518 
519  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
520  inline void erase( Pred predicate );
521 
522  template< typename Pred >
523  inline void erase( Iterator first, Iterator last, Pred predicate );
525  //**********************************************************************************************
526 
527  //**Lookup functions****************************************************************************
530  inline Iterator find ( size_t index );
531  inline ConstIterator find ( size_t index ) const;
532  inline Iterator lowerBound( size_t index );
533  inline ConstIterator lowerBound( size_t index ) const;
534  inline Iterator upperBound( size_t index );
535  inline ConstIterator upperBound( size_t index ) const;
537  //**********************************************************************************************
538 
539  //**Numeric functions***************************************************************************
542  template< typename Other > inline Subvector& scale( const Other& scalar );
544  //**********************************************************************************************
545 
546  //**Expression template evaluation functions****************************************************
549  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
550  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
551 
552  inline bool canSMPAssign() const noexcept;
553 
554  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
555  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
556  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
557  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
558  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
559  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
561  //**********************************************************************************************
562 
563  private:
564  //**Member variables****************************************************************************
567  Operand vector_;
568  const size_t offset_;
569  const size_t size_;
570 
571  //**********************************************************************************************
572 
573  //**Friend declarations*************************************************************************
574  template< bool AF1, typename VT2, bool AF2, bool TF2, bool DF2 >
575  friend const Subvector<VT2,AF1,TF2,DF2>
576  subvector( const Subvector<VT2,AF2,TF2,DF2>& sv, size_t index, size_t size );
577 
578  template< typename VT2, bool AF2, bool TF2, bool DF2 >
579  friend bool isIntact( const Subvector<VT2,AF2,TF2,DF2>& sv ) noexcept;
580 
581  template< typename VT2, bool AF2, bool TF2, bool DF2 >
582  friend bool isSame( const Subvector<VT2,AF2,TF2,DF2>& a, const Vector<VT2,TF2>& b ) noexcept;
583 
584  template< typename VT2, bool AF2, bool TF2, bool DF2 >
585  friend bool isSame( const Vector<VT2,TF2>& a, const Subvector<VT2,AF2,TF2,DF2>& b ) noexcept;
586 
587  template< typename VT2, bool AF2, bool TF2, bool DF2 >
588  friend bool isSame( const Subvector<VT2,AF2,TF2,DF2>& a, const Subvector<VT2,AF2,TF2,DF2>& b ) noexcept;
589 
590  template< typename VT2, bool AF2, bool TF2, bool DF2, typename VT3 >
591  friend bool tryAssign( const Subvector<VT2,AF2,TF2,DF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
592 
593  template< typename VT2, bool AF2, bool TF2, bool DF2, typename VT3 >
594  friend bool tryAddAssign( const Subvector<VT2,AF2,TF2,DF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
595 
596  template< typename VT2, bool AF2, bool TF2, bool DF2, typename VT3 >
597  friend bool trySubAssign( const Subvector<VT2,AF2,TF2,DF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
598 
599  template< typename VT2, bool AF2, bool TF2, bool DF2, typename VT3 >
600  friend bool tryMultAssign( const Subvector<VT2,AF2,TF2,DF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
601 
602  template< typename VT2, bool AF2, bool TF2, bool DF2 >
603  friend DerestrictTrait_< Subvector<VT2,AF2,TF2,DF2> > derestrict( Subvector<VT2,AF2,TF2,DF2>& sv );
604  //**********************************************************************************************
605 
606  //**Compile time checks*************************************************************************
612  //**********************************************************************************************
613 };
615 //*************************************************************************************************
616 
617 
618 
619 
620 //=================================================================================================
621 //
622 // CONSTRUCTOR
623 //
624 //=================================================================================================
625 
626 //*************************************************************************************************
639 template< typename VT // Type of the sparse vector
640  , bool AF // Alignment flag
641  , bool TF > // Transpose flag
642 inline Subvector<VT,AF,TF,false>::Subvector( Operand vector, size_t index, size_t n )
643  : vector_( vector ) // The sparse vector containing the subvector
644  , offset_( index ) // The offset of the subvector within the sparse vector
645  , size_ ( n ) // The size of the subvector
646 {
647  if( index + n > vector.size() ) {
648  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
649  }
650 }
652 //*************************************************************************************************
653 
654 
655 
656 
657 //=================================================================================================
658 //
659 // DATA ACCESS FUNCTIONS
660 //
661 //=================================================================================================
662 
663 //*************************************************************************************************
673 template< typename VT // Type of the sparse vector
674  , bool AF // Alignment flag
675  , bool TF > // Transpose flag
677  Subvector<VT,AF,TF,false>::operator[]( size_t index )
678 {
679  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
680  return vector_[offset_+index];
681 }
683 //*************************************************************************************************
684 
685 
686 //*************************************************************************************************
696 template< typename VT // Type of the sparse vector
697  , bool AF // Alignment flag
698  , bool TF > // Transpose flag
700  Subvector<VT,AF,TF,false>::operator[]( size_t index ) const
701 {
702  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
703  return const_cast<const VT&>( vector_ )[offset_+index];
704 }
706 //*************************************************************************************************
707 
708 
709 //*************************************************************************************************
720 template< typename VT // Type of the sparse vector
721  , bool AF // Alignment flag
722  , bool TF > // Transpose flag
724  Subvector<VT,AF,TF,false>::at( size_t index )
725 {
726  if( index >= size() ) {
727  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
728  }
729  return (*this)[index];
730 }
732 //*************************************************************************************************
733 
734 
735 //*************************************************************************************************
746 template< typename VT // Type of the sparse vector
747  , bool AF // Alignment flag
748  , bool TF > // Transpose flag
750  Subvector<VT,AF,TF,false>::at( size_t index ) const
751 {
752  if( index >= size() ) {
753  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
754  }
755  return (*this)[index];
756 }
758 //*************************************************************************************************
759 
760 
761 //*************************************************************************************************
769 template< typename VT // Type of the sparse vector
770  , bool AF // Alignment flag
771  , bool TF > // Transpose flag
773 {
774  if( offset_ == 0UL )
775  return Iterator( vector_.begin(), offset_ );
776  else
777  return Iterator( vector_.lowerBound( offset_ ), offset_ );
778 }
780 //*************************************************************************************************
781 
782 
783 //*************************************************************************************************
791 template< typename VT // Type of the sparse vector
792  , bool AF // Alignment flag
793  , bool TF > // Transpose flag
795 {
796  if( offset_ == 0UL )
797  return ConstIterator( vector_.cbegin(), offset_ );
798  else
799  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
800 }
802 //*************************************************************************************************
803 
804 
805 //*************************************************************************************************
813 template< typename VT // Type of the sparse vector
814  , bool AF // Alignment flag
815  , bool TF > // Transpose flag
817 {
818  if( offset_ == 0UL )
819  return ConstIterator( vector_.cbegin(), offset_ );
820  else
821  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
822 }
824 //*************************************************************************************************
825 
826 
827 //*************************************************************************************************
835 template< typename VT // Type of the sparse vector
836  , bool AF // Alignment flag
837  , bool TF > // Transpose flag
839 {
840  if( offset_ + size_ == vector_.size() )
841  return Iterator( vector_.end(), offset_ );
842  else
843  return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
844 }
846 //*************************************************************************************************
847 
848 
849 //*************************************************************************************************
857 template< typename VT // Type of the sparse vector
858  , bool AF // Alignment flag
859  , bool TF > // Transpose flag
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 //*************************************************************************************************
879 template< typename VT // Type of the sparse vector
880  , bool AF // Alignment flag
881  , bool TF > // Transpose flag
883 {
884  if( offset_ + size_ == vector_.size() )
885  return ConstIterator( vector_.cend(), offset_ );
886  else
887  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
888 }
890 //*************************************************************************************************
891 
892 
893 
894 
895 //=================================================================================================
896 //
897 // ASSIGNMENT OPERATORS
898 //
899 //=================================================================================================
900 
901 //*************************************************************************************************
913 template< typename VT // Type of the sparse vector
914  , bool AF // Alignment flag
915  , bool TF > // Transpose flag
916 inline Subvector<VT,AF,TF,false>&
917  Subvector<VT,AF,TF,false>::operator=( const Subvector& rhs )
918 {
919  using blaze::assign;
920 
923 
924  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
925  return *this;
926 
927  if( size() != rhs.size() ) {
928  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
929  }
930 
931  if( !tryAssign( vector_, rhs, offset_ ) ) {
932  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
933  }
934 
935  DerestrictTrait_<This> left( derestrict( *this ) );
936 
937  if( rhs.canAlias( &vector_ ) ) {
938  const ResultType tmp( rhs );
939  reset();
940  assign( left, tmp );
941  }
942  else {
943  reset();
944  assign( left, rhs );
945  }
946 
947  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
948 
949  return *this;
950 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
967 template< typename VT // Type of the sparse vector
968  , bool AF // Alignment flag
969  , bool TF > // Transpose flag
970 template< typename VT2 > // Type of the right-hand side vector
971 inline Subvector<VT,AF,TF,false>&
972  Subvector<VT,AF,TF,false>::operator=( const Vector<VT2,TF>& rhs )
973 {
974  using blaze::assign;
975 
978 
979  if( size() != (~rhs).size() ) {
980  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
981  }
982 
983  typedef If_< IsRestricted<VT>, CompositeType_<VT2>, const VT2& > Right;
984  Right right( ~rhs );
985 
986  if( !tryAssign( vector_, right, offset_ ) ) {
987  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
988  }
989 
990  DerestrictTrait_<This> left( derestrict( *this ) );
991 
992  if( IsReference<Right>::value || right.canAlias( &vector_ ) ) {
993  const ResultType_<VT2> tmp( right );
994  reset();
995  assign( left, tmp );
996  }
997  else {
998  reset();
999  assign( left, right );
1000  }
1001 
1002  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1003 
1004  return *this;
1005 }
1007 //*************************************************************************************************
1008 
1009 
1010 //*************************************************************************************************
1022 template< typename VT // Type of the sparse vector
1023  , bool AF // Alignment flag
1024  , bool TF > // Transpose flag
1025 template< typename VT2 > // Type of the right-hand side vector
1026 inline Subvector<VT,AF,TF,false>&
1027  Subvector<VT,AF,TF,false>::operator+=( const Vector<VT2,TF>& rhs )
1028 {
1029  using blaze::assign;
1030 
1034 
1035  typedef AddTrait_< ResultType, ResultType_<VT2> > AddType;
1036 
1039 
1040  if( size() != (~rhs).size() ) {
1041  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1042  }
1043 
1044  const AddType tmp( *this + (~rhs) );
1045 
1046  if( !tryAssign( vector_, tmp, offset_ ) ) {
1047  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1048  }
1049 
1050  DerestrictTrait_<This> left( derestrict( *this ) );
1051 
1052  left.reset();
1053  assign( left, tmp );
1054 
1055  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1056 
1057  return *this;
1058 }
1060 //*************************************************************************************************
1061 
1062 
1063 //*************************************************************************************************
1075 template< typename VT // Type of the sparse vector
1076  , bool AF // Alignment flag
1077  , bool TF > // Transpose flag
1078 template< typename VT2 > // Type of the right-hand side vector
1079 inline Subvector<VT,AF,TF,false>&
1080  Subvector<VT,AF,TF,false>::operator-=( const Vector<VT2,TF>& rhs )
1081 {
1082  using blaze::assign;
1083 
1087 
1088  typedef SubTrait_< ResultType, ResultType_<VT2> > SubType;
1089 
1092 
1093  if( size() != (~rhs).size() ) {
1094  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1095  }
1096 
1097  const SubType tmp( *this - (~rhs) );
1098 
1099  if( !tryAssign( vector_, tmp, offset_ ) ) {
1100  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1101  }
1102 
1103  DerestrictTrait_<This> left( derestrict( *this ) );
1104 
1105  left.reset();
1106  assign( left, tmp );
1107 
1108  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1109 
1110  return *this;
1111 }
1113 //*************************************************************************************************
1114 
1115 
1116 //*************************************************************************************************
1129 template< typename VT // Type of the sparse vector
1130  , bool AF // Alignment flag
1131  , bool TF > // Transpose flag
1132 template< typename VT2 > // Type of the right-hand side vector
1133 inline Subvector<VT,AF,TF,false>&
1134  Subvector<VT,AF,TF,false>::operator*=( const Vector<VT2,TF>& rhs )
1135 {
1136  using blaze::assign;
1137 
1141 
1142  typedef MultTrait_< ResultType, ResultType_<VT2> > MultType;
1143 
1146 
1147  if( size() != (~rhs).size() ) {
1148  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1149  }
1150 
1151  const MultType tmp( *this * (~rhs) );
1152 
1153  if( !tryAssign( vector_, tmp, offset_ ) ) {
1154  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1155  }
1156 
1157  DerestrictTrait_<This> left( derestrict( *this ) );
1158 
1159  left.reset();
1160  assign( left, tmp );
1161 
1162  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1163 
1164  return *this;
1165 }
1167 //*************************************************************************************************
1168 
1169 
1170 //*************************************************************************************************
1182 template< typename VT // Type of the sparse vector
1183  , bool AF // Alignment flag
1184  , bool TF > // Transpose flag
1185 template< typename VT2 > // Type of the right-hand side dense vector
1186 inline Subvector<VT,AF,TF,false>&
1187  Subvector<VT,AF,TF,false>::operator/=( const DenseVector<VT2,TF>& rhs )
1188 {
1189  using blaze::assign;
1190 
1193  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_<VT2> );
1195 
1196  typedef DivTrait_< ResultType, ResultType_<VT2> > DivType;
1197 
1201 
1202  if( size() != (~rhs).size() ) {
1203  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1204  }
1205 
1206  const DivType tmp( *this / (~rhs) );
1207 
1208  if( !tryAssign( vector_, tmp, offset_ ) ) {
1209  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1210  }
1211 
1212  DerestrictTrait_<This> left( derestrict( *this ) );
1213 
1214  left.reset();
1215  assign( left, tmp );
1216 
1217  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1218 
1219  return *this;
1220 }
1222 //*************************************************************************************************
1223 
1224 
1225 //*************************************************************************************************
1237 template< typename VT // Type of the sparse vector
1238  , bool AF // Alignment flag
1239  , bool TF > // Transpose flag
1240 template< typename Other > // Data type of the right-hand side scalar
1241 inline EnableIf_<IsNumeric<Other>, Subvector<VT,AF,TF,false> >&
1243 {
1244  const Iterator last( end() );
1245  for( Iterator element=begin(); element!=last; ++element )
1246  element->value() *= rhs;
1247  return *this;
1248 }
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1266 template< typename VT // Type of the sparse vector
1267  , bool AF // Alignment flag
1268  , bool TF > // Transpose flag
1269 template< typename Other > // Data type of the right-hand side scalar
1270 inline EnableIf_<IsNumeric<Other>, Subvector<VT,AF,TF,false> >&
1272 {
1273  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1274 
1275  typedef DivTrait_<ElementType,Other> DT;
1276  typedef If_< IsNumeric<DT>, DT, Other > Tmp;
1277 
1278  const Iterator last( end() );
1279 
1280  // Depending on the two involved data types, an integer division is applied or a
1281  // floating point division is selected.
1282  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
1283  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1284  for( Iterator element=begin(); element!=last; ++element )
1285  element->value() *= tmp;
1286  }
1287  else {
1288  for( Iterator element=begin(); element!=last; ++element )
1289  element->value() /= rhs;
1290  }
1291 
1292  return *this;
1293 }
1295 //*************************************************************************************************
1296 
1297 
1298 
1299 
1300 //=================================================================================================
1301 //
1302 // UTILITY FUNCTIONS
1303 //
1304 //=================================================================================================
1305 
1306 //*************************************************************************************************
1312 template< typename VT // Type of the sparse vector
1313  , bool AF // Alignment flag
1314  , bool TF > // Transpose flag
1315 inline size_t Subvector<VT,AF,TF,false>::size() const noexcept
1316 {
1317  return size_;
1318 }
1320 //*************************************************************************************************
1321 
1322 
1323 //*************************************************************************************************
1329 template< typename VT // Type of the sparse vector
1330  , bool AF // Alignment flag
1331  , bool TF > // Transpose flag
1332 inline size_t Subvector<VT,AF,TF,false>::capacity() const noexcept
1333 {
1334  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1335 }
1337 //*************************************************************************************************
1338 
1339 
1340 //*************************************************************************************************
1348 template< typename VT // Type of the sparse vector
1349  , bool AF // Alignment flag
1350  , bool TF > // Transpose flag
1351 inline size_t Subvector<VT,AF,TF,false>::nonZeros() const
1352 {
1353  return end() - begin();
1354 }
1356 //*************************************************************************************************
1357 
1358 
1359 //*************************************************************************************************
1365 template< typename VT // Type of the sparse vector
1366  , bool AF // Alignment flag
1367  , bool TF > // Transpose flag
1369 {
1370  vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1371 }
1373 //*************************************************************************************************
1374 
1375 
1376 //*************************************************************************************************
1386 template< typename VT // Type of the sparse vector
1387  , bool AF // Alignment flag
1388  , bool TF > // Transpose flag
1389 void Subvector<VT,AF,TF,false>::reserve( size_t n )
1390 {
1391  const size_t current( capacity() );
1392 
1393  if( n > current ) {
1394  vector_.reserve( vector_.capacity() + n - current );
1395  }
1396 }
1398 //*************************************************************************************************
1399 
1400 
1401 
1402 
1403 //=================================================================================================
1404 //
1405 // INSERTION FUNCTIONS
1406 //
1407 //=================================================================================================
1408 
1409 //*************************************************************************************************
1421 template< typename VT // Type of the sparse vector
1422  , bool AF // Alignment flag
1423  , bool TF > // Transpose flag
1425  Subvector<VT,AF,TF,false>::set( size_t index, const ElementType& value )
1426 {
1427  return Iterator( vector_.set( offset_ + index, value ), offset_ );
1428 }
1430 //*************************************************************************************************
1431 
1432 
1433 //*************************************************************************************************
1446 template< typename VT // Type of the sparse vector
1447  , bool AF // Alignment flag
1448  , bool TF > // Transpose flag
1450  Subvector<VT,AF,TF,false>::insert( size_t index, const ElementType& value )
1451 {
1452  return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1453 }
1455 //*************************************************************************************************
1456 
1457 
1458 //*************************************************************************************************
1483 template< typename VT // Type of the sparse vector
1484  , bool AF // Alignment flag
1485  , bool TF > // Transpose flag
1486 inline void Subvector<VT,AF,TF,false>::append( size_t index, const ElementType& value, bool check )
1487 {
1488  if( offset_ + size_ == vector_.size() )
1489  vector_.append( offset_ + index, value, check );
1490  else if( !check || !isDefault( value ) )
1491  vector_.insert( offset_ + index, value );
1492 }
1494 //*************************************************************************************************
1495 
1496 
1497 
1498 
1499 //=================================================================================================
1500 //
1501 // ERASE FUNCTIONS
1502 //
1503 //=================================================================================================
1504 
1505 //*************************************************************************************************
1514 template< typename VT // Type of the sparse vector
1515  , bool AF // Alignment flag
1516  , bool TF > // Transpose flag
1517 inline void Subvector<VT,AF,TF,false>::erase( size_t index )
1518 {
1519  vector_.erase( offset_ + index );
1520 }
1522 //*************************************************************************************************
1523 
1524 
1525 //*************************************************************************************************
1534 template< typename VT // Type of the sparse vector
1535  , bool AF // Alignment flag
1536  , bool TF > // Transpose flag
1537 inline typename Subvector<VT,AF,TF,false>::Iterator Subvector<VT,AF,TF,false>::erase( Iterator pos )
1538 {
1539  return Iterator( vector_.erase( pos.base() ), offset_ );
1540 }
1542 //*************************************************************************************************
1543 
1544 
1545 //*************************************************************************************************
1555 template< typename VT // Type of the sparse vector
1556  , bool AF // Alignment flag
1557  , bool TF > // Transpose flag
1559  Subvector<VT,AF,TF,false>::erase( Iterator first, Iterator last )
1560 {
1561  return Iterator( vector_.erase( first.base(), last.base() ), offset_ );
1562 }
1564 //*************************************************************************************************
1565 
1566 
1567 //*************************************************************************************************
1590 template< typename VT // Type of the sparse vector
1591  , bool AF // Alignment flag
1592  , bool TF > // Transpose flag
1593 template< typename Pred // Type of the unary predicate
1594  , typename > // Type restriction on the unary predicate
1595 inline void Subvector<VT,AF,TF,false>::erase( Pred predicate )
1596 {
1597  vector_.erase( begin().base(), end().base(), predicate );
1598 }
1600 //*************************************************************************************************
1601 
1602 
1603 //*************************************************************************************************
1629 template< typename VT // Type of the sparse vector
1630  , bool AF // Alignment flag
1631  , bool TF > // Transpose flag
1632 template< typename Pred > // Type of the unary predicate
1633 inline void Subvector<VT,AF,TF,false>::erase( Iterator first, Iterator last, Pred predicate )
1634 {
1635  vector_.erase( first.base(), last.base(), predicate );
1636 }
1638 //*************************************************************************************************
1639 
1640 
1641 
1642 
1643 //=================================================================================================
1644 //
1645 // LOOKUP FUNCTIONS
1646 //
1647 //=================================================================================================
1648 
1649 //*************************************************************************************************
1663 template< typename VT // Type of the sparse vector
1664  , bool AF // Alignment flag
1665  , bool TF > // Transpose flag
1667  Subvector<VT,AF,TF,false>::find( size_t index )
1668 {
1669  const Iterator_<VT> pos( vector_.find( offset_ + index ) );
1670 
1671  if( pos != vector_.end() )
1672  return Iterator( pos, offset_ );
1673  else
1674  return end();
1675 }
1677 //*************************************************************************************************
1678 
1679 
1680 //*************************************************************************************************
1694 template< typename VT // Type of the sparse vector
1695  , bool AF // Alignment flag
1696  , bool TF > // Transpose flag
1698  Subvector<VT,AF,TF,false>::find( size_t index ) const
1699 {
1700  const ConstIterator_<VT> pos( vector_.find( offset_ + index ) );
1701 
1702  if( pos != vector_.end() )
1703  return Iterator( pos, offset_ );
1704  else
1705  return end();
1706 }
1708 //*************************************************************************************************
1709 
1710 
1711 //*************************************************************************************************
1724 template< typename VT // Type of the sparse vector
1725  , bool AF // Alignment flag
1726  , bool TF > // Transpose flag
1728  Subvector<VT,AF,TF,false>::lowerBound( size_t index )
1729 {
1730  return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1731 }
1733 //*************************************************************************************************
1734 
1735 
1736 //*************************************************************************************************
1749 template< typename VT // Type of the sparse vector
1750  , bool AF // Alignment flag
1751  , bool TF > // Transpose flag
1753  Subvector<VT,AF,TF,false>::lowerBound( size_t index ) const
1754 {
1755  return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1756 }
1758 //*************************************************************************************************
1759 
1760 
1761 //*************************************************************************************************
1774 template< typename VT // Type of the sparse vector
1775  , bool AF // Alignment flag
1776  , bool TF > // Transpose flag
1778  Subvector<VT,AF,TF,false>::upperBound( size_t index )
1779 {
1780  return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1781 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1799 template< typename VT // Type of the sparse vector
1800  , bool AF // Alignment flag
1801  , bool TF > // Transpose flag
1803  Subvector<VT,AF,TF,false>::upperBound( size_t index ) const
1804 {
1805  return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1806 }
1808 //*************************************************************************************************
1809 
1810 
1811 
1812 
1813 //=================================================================================================
1814 //
1815 // NUMERIC FUNCTIONS
1816 //
1817 //=================================================================================================
1818 
1819 //*************************************************************************************************
1826 template< typename VT // Type of the sparse vector
1827  , bool AF // Alignment flag
1828  , bool TF > // Transpose flag
1829 template< typename Other > // Data type of the scalar value
1830 inline Subvector<VT,AF,TF,false>& Subvector<VT,AF,TF,false>::scale( const Other& scalar )
1831 {
1832  for( Iterator element=begin(); element!=end(); ++element )
1833  element->value() *= scalar;
1834  return *this;
1835 }
1837 //*************************************************************************************************
1838 
1839 
1840 
1841 
1842 //=================================================================================================
1843 //
1844 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1845 //
1846 //=================================================================================================
1847 
1848 //*************************************************************************************************
1859 template< typename VT // Type of the sparse vector
1860  , bool AF // Alignment flag
1861  , bool TF > // Transpose flag
1862 template< typename Other > // Data type of the foreign expression
1863 inline bool Subvector<VT,AF,TF,false>::canAlias( const Other* alias ) const noexcept
1864 {
1865  return vector_.isAliased( alias );
1866 }
1868 //*************************************************************************************************
1869 
1870 
1871 //*************************************************************************************************
1882 template< typename VT // Type of the sparse vector
1883  , bool AF // Alignment flag
1884  , bool TF > // Transpose flag
1885 template< typename Other > // Data type of the foreign expression
1886 inline bool Subvector<VT,AF,TF,false>::isAliased( const Other* alias ) const noexcept
1887 {
1888  return vector_.isAliased( alias );
1889 }
1891 //*************************************************************************************************
1892 
1893 
1894 //*************************************************************************************************
1905 template< typename VT // Type of the sparse vector
1906  , bool AF // Alignment flag
1907  , bool TF > // Transpose flag
1908 inline bool Subvector<VT,AF,TF,false>::canSMPAssign() const noexcept
1909 {
1910  return false;
1911 }
1913 //*************************************************************************************************
1914 
1915 
1916 //*************************************************************************************************
1928 template< typename VT // Type of the sparse vector
1929  , bool AF // Alignment flag
1930  , bool TF > // Transpose flag
1931 template< typename VT2 > // Type of the right-hand side dense vector
1932 inline void Subvector<VT,AF,TF,false>::assign( const DenseVector<VT2,TF>& rhs )
1933 {
1934  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1935  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1936 
1937  reserve( (~rhs).size() );
1938 
1939  for( size_t i=0UL; i<size(); ++i ) {
1940  append( i, (~rhs)[i], true );
1941  }
1942 }
1944 //*************************************************************************************************
1945 
1946 
1947 //*************************************************************************************************
1959 template< typename VT // Type of the sparse vector
1960  , bool AF // Alignment flag
1961  , bool TF > // Transpose flag
1962 template< typename VT2 > // Type of the right-hand side sparse vector
1963 inline void Subvector<VT,AF,TF,false>::assign( const SparseVector<VT2,TF>& rhs )
1964 {
1965  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1966  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1967 
1968  reserve( (~rhs).nonZeros() );
1969 
1970  for( ConstIterator_<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1971  append( element->index(), element->value(), true );
1972  }
1973 }
1975 //*************************************************************************************************
1976 
1977 
1978 //*************************************************************************************************
1990 template< typename VT // Type of the sparse vector
1991  , bool AF // Alignment flag
1992  , bool TF > // Transpose flag
1993 template< typename VT2 > // Type of the right-hand side dense vector
1994 inline void Subvector<VT,AF,TF,false>::addAssign( const DenseVector<VT2,TF>& rhs )
1995 {
1996  typedef AddTrait_< ResultType, ResultType_<VT2> > AddType;
1997 
2001 
2002  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2003 
2004  const AddType tmp( serial( *this + (~rhs) ) );
2005  reset();
2006  assign( tmp );
2007 }
2009 //*************************************************************************************************
2010 
2011 
2012 //*************************************************************************************************
2024 template< typename VT // Type of the sparse vector
2025  , bool AF // Alignment flag
2026  , bool TF > // Transpose flag
2027 template< typename VT2 > // Type of the right-hand side sparse vector
2028 inline void Subvector<VT,AF,TF,false>::addAssign( const SparseVector<VT2,TF>& rhs )
2029 {
2030  typedef AddTrait_< ResultType, ResultType_<VT2> > AddType;
2031 
2035 
2036  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2037 
2038  const AddType tmp( serial( *this + (~rhs) ) );
2039  reset();
2040  assign( tmp );
2041 }
2043 //*************************************************************************************************
2044 
2045 
2046 //*************************************************************************************************
2058 template< typename VT // Type of the sparse vector
2059  , bool AF // Alignment flag
2060  , bool TF > // Transpose flag
2061 template< typename VT2 > // Type of the right-hand side dense vector
2062 inline void Subvector<VT,AF,TF,false>::subAssign( const DenseVector<VT2,TF>& rhs )
2063 {
2064  typedef SubTrait_< ResultType, ResultType_<VT2> > SubType;
2065 
2069 
2070  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2071 
2072  const SubType tmp( serial( *this - (~rhs) ) );
2073  reset();
2074  assign( tmp );
2075 }
2077 //*************************************************************************************************
2078 
2079 
2080 //*************************************************************************************************
2092 template< typename VT // Type of the sparse vector
2093  , bool AF // Alignment flag
2094  , bool TF > // Transpose flag
2095 template< typename VT2 > // Type of the right-hand side sparse vector
2096 inline void Subvector<VT,AF,TF,false>::subAssign( const SparseVector<VT2,TF>& rhs )
2097 {
2098  typedef SubTrait_< ResultType, ResultType_<VT2> > SubType;
2099 
2103 
2104  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2105 
2106  const SubType tmp( serial( *this - (~rhs) ) );
2107  reset();
2108  assign( tmp );
2109 }
2111 //*************************************************************************************************
2112 
2113 } // namespace blaze
2114 
2115 #endif
#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.
typename DerestrictTrait< T >::Type DerestrictTrait_
Auxiliary alias declaration for the DerestrictTrait type trait.The DerestrictTrait_ alias declaration...
Definition: DerestrictTrait.h:110
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the alignment flag values.
Header file for the subtraction trait.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:352
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b) noexcept
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:721
Header file for basic type definitions.
Header file for the SparseVector base class.
Header file for the View base class.
Header file for the serial shim.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:261
#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
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1339
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:194
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2935
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
Header file for the IsIntegral type trait.
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2928
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:390
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:731
#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
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1321
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:304
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:238
Constraint on the data type.
SubvectorExprTrait_< VT, unaligned > subvector(Vector< VT, TF > &vector, size_t index, size_t size)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:152
Header file for the DisableIf class template.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2939
#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.
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
Header file for the subvector trait.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:61
Constraint on the data type.
Header file for the SparseElement base class.
Constraint on the data type.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:2932
Constraint on the data type.
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:260
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:2933
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Constraint on the data type.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2937
Header file for the EnableIf class template.
Header file for the DerestrictTrait class template.
Header file for the IsNumeric type trait.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2934
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:1285
Header file for run time assertion macros.
Header file for the addition trait.
Header file for the division trait.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2938
Header file for the isDefault shim.
#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.
#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
SparseMatrix< This, true > BaseType
Base type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:2929
#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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2930
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:249
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2936
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:1303
Header file for the IsRestricted type trait.
const DMatDMatMultExpr< T1, T2, false, false, false, false > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7505
#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.