Sparse.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_ELEMENTS_SPARSE_H_
36 #define _BLAZE_MATH_VIEWS_ELEMENTS_SPARSE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <blaze/math/Aliases.h>
53 #include <blaze/math/Exception.h>
70 #include <blaze/math/views/Check.h>
73 #include <blaze/util/Assert.h>
75 #include <blaze/util/DisableIf.h>
76 #include <blaze/util/mpl/If.h>
77 #include <blaze/util/TypeList.h>
78 #include <blaze/util/Types.h>
82 
83 
84 namespace blaze {
85 
86 //=================================================================================================
87 //
88 // CLASS TEMPLATE SPECIALIZATION FOR SPARSE VECTORS
89 //
90 //=================================================================================================
91 
92 //*************************************************************************************************
99 template< typename VT // Type of the sparse vector
100  , bool TF // Transpose flag
101  , typename... CEAs > // Compile time element arguments
102 class Elements<VT,TF,false,CEAs...>
103  : public View< SparseVector< Elements<VT,TF,false,CEAs...>, TF > >
104  , private ElementsData<CEAs...>
105 {
106  private:
107  //**Type definitions****************************************************************************
108  using DataType = ElementsData<CEAs...>;
109  using Operand = If_t< IsExpression_v<VT>, VT, VT& >;
110  //**********************************************************************************************
111 
112  //**Compile time flags**************************************************************************
113  using DataType::N;
114  //**********************************************************************************************
115 
116  public:
117  //**Type definitions****************************************************************************
119  using This = Elements<VT,TF,false,CEAs...>;
120 
121  using BaseType = SparseVector<This,TF>;
122  using ViewedType = VT;
123  using ResultType = ElementsTrait_t<VT,N>;
124  using TransposeType = TransposeType_t<ResultType>;
125  using ElementType = ElementType_t<VT>;
126  using ReturnType = ReturnType_t<VT>;
127  using CompositeType = const Elements&;
128 
130  using ConstReference = ConstReference_t<VT>;
131 
133  using Reference = If_t< IsConst_v<VT>, ConstReference, Reference_t<VT> >;
134  //**********************************************************************************************
135 
136  //**ElementsElement class definition************************************************************
139  template< typename IteratorType > // Type of the sparse vector iterator
140  class ElementsElement
141  : private SparseElement
142  {
143  public:
144  //**Constructor******************************************************************************
150  inline ElementsElement( IteratorType pos, size_t index )
151  : pos_ ( pos ) // Iterator to the current position within the element selection
152  , index_( index ) // Index within the according element selection
153  {}
154  //*******************************************************************************************
155 
156  //**Assignment operator**********************************************************************
162  template< typename T > inline ElementsElement& operator=( const T& v ) {
163  *pos_ = v;
164  return *this;
165  }
166  //*******************************************************************************************
167 
168  //**Addition assignment operator*************************************************************
174  template< typename T > inline ElementsElement& operator+=( const T& v ) {
175  *pos_ += v;
176  return *this;
177  }
178  //*******************************************************************************************
179 
180  //**Subtraction assignment operator**********************************************************
186  template< typename T > inline ElementsElement& operator-=( const T& v ) {
187  *pos_ -= v;
188  return *this;
189  }
190  //*******************************************************************************************
191 
192  //**Multiplication assignment operator*******************************************************
198  template< typename T > inline ElementsElement& operator*=( const T& v ) {
199  *pos_ *= v;
200  return *this;
201  }
202  //*******************************************************************************************
203 
204  //**Division assignment operator*************************************************************
210  template< typename T > inline ElementsElement& operator/=( const T& v ) {
211  *pos_ /= v;
212  return *this;
213  }
214  //*******************************************************************************************
215 
216  //**Element access operator******************************************************************
221  inline const ElementsElement* operator->() const {
222  return this;
223  }
224  //*******************************************************************************************
225 
226  //**Value function***************************************************************************
231  inline decltype(auto) value() const {
232  return pos_->value();
233  }
234  //*******************************************************************************************
235 
236  //**Index function***************************************************************************
241  inline size_t index() const {
242  return index_;
243  }
244  //*******************************************************************************************
245 
246  private:
247  //**Member variables*************************************************************************
248  IteratorType pos_;
249  size_t index_;
250  //*******************************************************************************************
251  };
252  //**********************************************************************************************
253 
254  //**ElementsIterator class definition***********************************************************
257  template< typename ET // Type of the element selection
258  , typename IteratorType > // Type of the sparse vector iterator
259  class ElementsIterator
260  {
261  public:
262  //**Type definitions*************************************************************************
263  using IteratorCategory = std::forward_iterator_tag;
264  using ValueType = ElementsElement<IteratorType>;
265  using PointerType = ValueType;
266  using ReferenceType = ValueType;
267  using DifferenceType = ptrdiff_t;
268 
269  // STL iterator requirements
270  using iterator_category = IteratorCategory;
271  using value_type = ValueType;
272  using pointer = PointerType;
273  using reference = ReferenceType;
274  using difference_type = DifferenceType;
275  //*******************************************************************************************
276 
277  //**Constructor******************************************************************************
280  inline ElementsIterator()
281  : elements_( nullptr ) // Pointer to the element selection
282  , index_ ( 0UL) // Index within the according element selection
283  , pos_ () // Iterator to the current position within the element selection
284  {}
285  //*******************************************************************************************
286 
287  //**Constructor******************************************************************************
293  inline ElementsIterator( ET* elements, size_t index )
294  : elements_( elements ) // Pointer to the element selection
295  , index_ ( index ) // Index within the according element selection
296  , pos_ () // Iterator to the current position within the element selection
297  {
298  for( ; index_<elements_->size(); ++index_ ) {
299  pos_ = elements_->operand().find( elements_->idx(index_) );
300  if( pos_ != elements_->operand().end() ) break;
301  }
302  }
303  //*******************************************************************************************
304 
305  //**Constructor******************************************************************************
312  inline ElementsIterator( ET* elements, size_t index, IteratorType pos )
313  : elements_( elements ) // Pointer to the element selection
314  , index_ ( index ) // Index within the according element selection
315  , pos_ ( pos ) // Iterator to the current position within the element selection
316  {}
317  //*******************************************************************************************
318 
319  //**Constructor******************************************************************************
324  template< typename ET2, typename IteratorType2 >
325  inline ElementsIterator( const ElementsIterator<ET2,IteratorType2>& it )
326  : elements_( it.elements_ ) // Pointer to the element selection
327  , index_ ( it.index_ ) // Index within the according element selection
328  , pos_ ( it.pos_ ) // Iterator to the current position within the element selection
329  {}
330  //*******************************************************************************************
331 
332  //**Prefix increment operator****************************************************************
337  inline ElementsIterator& operator++() {
338  ++index_;
339  for( ; index_<elements_->size(); ++index_ ) {
340  pos_ = elements_->operand().find( elements_->idx(index_) );
341  if( pos_ != elements_->operand().end() ) break;
342  }
343  return *this;
344  }
345  //*******************************************************************************************
346 
347  //**Postfix increment operator***************************************************************
352  inline const ElementsIterator operator++( int ) {
353  const ElementsIterator tmp( *this );
354  ++(*this);
355  return tmp;
356  }
357  //*******************************************************************************************
358 
359  //**Element access operator******************************************************************
364  inline ReferenceType operator*() const {
365  return ReferenceType( pos_, index_ );
366  }
367  //*******************************************************************************************
368 
369  //**Element access operator******************************************************************
374  inline PointerType operator->() const {
375  return PointerType( pos_, index_ );
376  }
377  //*******************************************************************************************
378 
379  //**Equality operator************************************************************************
385  inline bool operator==( const ElementsIterator& rhs ) const {
386  return index_ == rhs.index_;
387  }
388  //*******************************************************************************************
389 
390  //**Inequality operator**********************************************************************
396  inline bool operator!=( const ElementsIterator& rhs ) const {
397  return index_ != rhs.index_;
398  }
399  //*******************************************************************************************
400 
401  //**Subtraction operator*********************************************************************
407  inline DifferenceType operator-( const ElementsIterator& rhs ) const {
408  size_t counter( 0UL );
409  for( size_t j=rhs.index_; j<index_; ++j ) {
410  if( elements_->find( j ) != elements_->end() )
411  ++counter;
412  }
413  return counter;
414  }
415  //*******************************************************************************************
416 
417  private:
418  //**Member variables*************************************************************************
419  ET* elements_;
420  size_t index_;
421  IteratorType pos_;
422  //*******************************************************************************************
423 
424  //**Friend declarations**********************************************************************
425  template< typename VT2, bool TF2, bool DF2, typename... CEAs2 > friend class Elements;
426  template< typename ET2, typename IteratorType2 > friend class ElementsIterator;
427  //*******************************************************************************************
428  };
429  //**********************************************************************************************
430 
431  //**Type definitions****************************************************************************
433  using ConstIterator = ElementsIterator< const This, ConstIterator_t<VT> >;
434 
436  using Iterator = If_t< IsConst_v<VT>, ConstIterator, ElementsIterator< This, Iterator_t<VT> > >;
437  //**********************************************************************************************
438 
439  //**Compilation flags***************************************************************************
441  static constexpr bool smpAssignable = false;
442  //**********************************************************************************************
443 
444  //**Constructors********************************************************************************
447  template< typename... REAs >
448  explicit inline Elements( VT& vector, REAs... args );
449 
450  Elements( const Elements& ) = default;
451  Elements( Elements&& ) = default;
453  //**********************************************************************************************
454 
455  //**Destructor**********************************************************************************
458  ~Elements() = default;
460  //**********************************************************************************************
461 
462  //**Data access functions***********************************************************************
465  inline Reference operator[]( size_t index );
466  inline ConstReference operator[]( size_t index ) const;
467  inline Reference at( size_t index );
468  inline ConstReference at( size_t index ) const;
469  inline Iterator begin ();
470  inline ConstIterator begin () const;
471  inline ConstIterator cbegin() const;
472  inline Iterator end ();
473  inline ConstIterator end () const;
474  inline ConstIterator cend () const;
476  //**********************************************************************************************
477 
478  //**Assignment operators************************************************************************
481  inline Elements& operator= ( initializer_list<ElementType> list );
482  inline Elements& operator= ( const Elements& rhs );
483  template< typename VT2 > inline Elements& operator= ( const Vector<VT2,TF>& rhs );
484  template< typename VT2 > inline Elements& operator+=( const Vector<VT2,TF>& rhs );
485  template< typename VT2 > inline Elements& operator-=( const Vector<VT2,TF>& rhs );
486  template< typename VT2 > inline Elements& operator*=( const Vector<VT2,TF>& rhs );
487  template< typename VT2 > inline Elements& operator/=( const DenseVector<VT2,TF>& rhs );
488  template< typename VT2 > inline Elements& operator%=( const Vector<VT2,TF>& rhs );
490  //**********************************************************************************************
491 
492  //**Utility functions***************************************************************************
495  using DataType::idces;
496  using DataType::idx;
497  using DataType::size;
498 
499  inline VT& operand() noexcept;
500  inline const VT& operand() const noexcept;
501 
502  inline size_t capacity() const noexcept;
503  inline size_t nonZeros() const;
504  inline void reset();
505  inline void reserve( size_t n );
507  //**********************************************************************************************
508 
509  //**Insertion functions*************************************************************************
512  inline Iterator set ( size_t index, const ElementType& value );
513  inline Iterator insert( size_t index, const ElementType& value );
514  inline void append( size_t index, const ElementType& value, bool check=false );
516  //**********************************************************************************************
517 
518  //**Erase functions*****************************************************************************
521  inline void erase( size_t index );
522  inline Iterator erase( Iterator pos );
523  inline Iterator erase( Iterator first, Iterator last );
524 
525  template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
526  inline void erase( Pred predicate );
527 
528  template< typename Pred >
529  inline void erase( Iterator first, Iterator last, Pred predicate );
531  //**********************************************************************************************
532 
533  //**Lookup functions****************************************************************************
536  inline Iterator find ( size_t index );
537  inline ConstIterator find ( size_t index ) const;
538  inline Iterator lowerBound( size_t index );
539  inline ConstIterator lowerBound( size_t index ) const;
540  inline Iterator upperBound( size_t index );
541  inline ConstIterator upperBound( size_t index ) const;
543  //**********************************************************************************************
544 
545  //**Numeric functions***************************************************************************
548  template< typename Other > inline Elements& scale( const Other& scalar );
550  //**********************************************************************************************
551 
552  //**Expression template evaluation functions****************************************************
555  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
556  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
557 
558  inline bool canSMPAssign() const noexcept;
559 
560  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
561  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
562  template< typename VT2 > inline void addAssign( const Vector<VT2,TF>& rhs );
563  template< typename VT2 > inline void subAssign( const Vector<VT2,TF>& rhs );
565  //**********************************************************************************************
566 
567  private:
568  //**Member variables****************************************************************************
571  Operand vector_;
572 
573  //**********************************************************************************************
574 
575  //**Compile time checks*************************************************************************
581  //**********************************************************************************************
582 };
584 //*************************************************************************************************
585 
586 
587 
588 
589 //=================================================================================================
590 //
591 // CONSTRUCTORS
592 //
593 //=================================================================================================
594 
595 //*************************************************************************************************
608 template< typename VT // Type of the sparse vector
609  , bool TF // Transpose flag
610  , typename... CEAs > // Compile time element arguments
611 template< typename... REAs > // Optional arguments
612 inline Elements<VT,TF,false,CEAs...>::Elements( VT& vector, REAs... args )
613  : DataType( args... ) // Base class initialization
614  , vector_ ( vector ) // The vector containing the elements
615 {
616  if( !Contains_v< TypeList<REAs...>, Unchecked > ) {
617  for( size_t i=0UL; i<size(); ++i ) {
618  if( vector_.size() <= idx(i) ) {
619  BLAZE_THROW_INVALID_ARGUMENT( "Invalid element access index" );
620  }
621  }
622  }
623 }
625 //*************************************************************************************************
626 
627 
628 
629 
630 //=================================================================================================
631 //
632 // DATA ACCESS FUNCTIONS
633 //
634 //=================================================================================================
635 
636 //*************************************************************************************************
646 template< typename VT // Type of the sparse vector
647  , bool TF // Transpose flag
648  , typename... CEAs > // Compile time element arguments
649 inline typename Elements<VT,TF,false,CEAs...>::Reference
650  Elements<VT,TF,false,CEAs...>::operator[]( size_t index )
651 {
652  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
653  return vector_[idx(index)];
654 }
656 //*************************************************************************************************
657 
658 
659 //*************************************************************************************************
669 template< typename VT // Type of the sparse vector
670  , bool TF // Transpose flag
671  , typename... CEAs > // Compile time element arguments
672 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
673  Elements<VT,TF,false,CEAs...>::operator[]( size_t index ) const
674 {
675  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
676  return const_cast<const VT&>( vector_ )[idx(index)];
677 }
679 //*************************************************************************************************
680 
681 
682 //*************************************************************************************************
693 template< typename VT // Type of the sparse vector
694  , bool TF // Transpose flag
695  , typename... CEAs > // Compile time element arguments
696 inline typename Elements<VT,TF,false,CEAs...>::Reference
697  Elements<VT,TF,false,CEAs...>::at( size_t index )
698 {
699  if( index >= size() ) {
700  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
701  }
702  return (*this)[index];
703 }
705 //*************************************************************************************************
706 
707 
708 //*************************************************************************************************
719 template< typename VT // Type of the sparse vector
720  , bool TF // Transpose flag
721  , typename... CEAs > // Compile time element arguments
722 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
723  Elements<VT,TF,false,CEAs...>::at( size_t index ) const
724 {
725  if( index >= size() ) {
726  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
727  }
728  return (*this)[index];
729 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
742 template< typename VT // Type of the sparse vector
743  , bool TF // Transpose flag
744  , typename... CEAs > // Compile time element arguments
745 inline typename Elements<VT,TF,false,CEAs...>::Iterator
747 {
748  return Iterator( this, 0UL );
749 }
751 //*************************************************************************************************
752 
753 
754 //*************************************************************************************************
762 template< typename VT // Type of the sparse vector
763  , bool TF // Transpose flag
764  , typename... CEAs > // Compile time element arguments
765 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
767 {
768  return ConstIterator( this, 0UL );
769 }
771 //*************************************************************************************************
772 
773 
774 //*************************************************************************************************
782 template< typename VT // Type of the sparse vector
783  , bool TF // Transpose flag
784  , typename... CEAs > // Compile time element arguments
785 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
787 {
788  return ConstIterator( this, 0UL );
789 }
791 //*************************************************************************************************
792 
793 
794 //*************************************************************************************************
802 template< typename VT // Type of the sparse vector
803  , bool TF // Transpose flag
804  , typename... CEAs > // Compile time element arguments
805 inline typename Elements<VT,TF,false,CEAs...>::Iterator
807 {
808  return Iterator( this, size() );
809 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
822 template< typename VT // Type of the sparse vector
823  , bool TF // Transpose flag
824  , typename... CEAs > // Compile time element arguments
825 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
827 {
828  return ConstIterator( this, size() );
829 }
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
842 template< typename VT // Type of the sparse vector
843  , bool TF // Transpose flag
844  , typename... CEAs > // Compile time element arguments
845 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
847 {
848  return ConstIterator( this, size() );
849 }
851 //*************************************************************************************************
852 
853 
854 
855 
856 //=================================================================================================
857 //
858 // ASSIGNMENT OPERATORS
859 //
860 //=================================================================================================
861 
862 //*************************************************************************************************
878 template< typename VT // Type of the sparse vector
879  , bool TF // Transpose flag
880  , typename... CEAs > // Compile time element arguments
881 inline Elements<VT,TF,false,CEAs...>&
882  Elements<VT,TF,false,CEAs...>::operator=( initializer_list<ElementType> list )
883 {
884  using blaze::assign;
885 
886  if( list.size() > size() ) {
887  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to elements" );
888  }
889 
890  const InitializerVector<ElementType,TF> tmp( list, size() );
891 
892  if( IsRestricted_v<VT> ) {
893  for( size_t i=0UL; i<size(); ++i ) {
894  if( !trySet( vector_, idx(i), tmp[i] ) ) {
895  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
896  }
897  }
898  }
899 
900  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
901 
902  assign( left, tmp );
903 
904  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
905 
906  return *this;
907 }
909 //*************************************************************************************************
910 
911 
912 //*************************************************************************************************
924 template< typename VT // Type of the sparse vector
925  , bool TF // Transpose flag
926  , typename... CEAs > // Compile time element arguments
927 inline Elements<VT,TF,false,CEAs...>&
928  Elements<VT,TF,false,CEAs...>::operator=( const Elements& rhs )
929 {
930  using blaze::assign;
931 
934 
935  if( &rhs == this || ( &vector_ == &rhs.vector_ && compareIndices( *this, rhs ) ) )
936  return *this;
937 
938  if( size() != rhs.size() ) {
939  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
940  }
941 
942  if( IsRestricted_v<VT> ) {
943  for( size_t i=0UL; i<size(); ++i ) {
944  if( !trySet( vector_, idx(i), rhs[i] ) ) {
945  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
946  }
947  }
948  }
949 
950  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
951 
952  if( rhs.canAlias( &vector_ ) ) {
953  const ResultType tmp( rhs );
954  assign( left, tmp );
955  }
956  else {
957  assign( left, rhs );
958  }
959 
960  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
961 
962  return *this;
963 }
965 //*************************************************************************************************
966 
967 
968 //*************************************************************************************************
980 template< typename VT // Type of the sparse vector
981  , bool TF // Transpose flag
982  , typename... CEAs > // Compile time element arguments
983 template< typename VT2 > // Type of the right-hand side vector
984 inline Elements<VT,TF,false,CEAs...>&
985  Elements<VT,TF,false,CEAs...>::operator=( const Vector<VT2,TF>& rhs )
986 {
987  using blaze::assign;
988 
991 
992  if( size() != (~rhs).size() ) {
993  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
994  }
995 
996  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
997  Right right( ~rhs );
998 
999  if( IsRestricted_v<VT> ) {
1000  for( size_t i=0UL; i<size(); ++i ) {
1001  if( !trySet( vector_, idx(i), right[i] ) ) {
1002  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1003  }
1004  }
1005  }
1006 
1007  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1008 
1009  if( IsReference_v<Right> || right.canAlias( &vector_ ) ) {
1010  const ResultType_t<VT2> tmp( right );
1011  assign( left, tmp );
1012  }
1013  else {
1014  assign( left, right );
1015  }
1016 
1017  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1018 
1019  return *this;
1020 }
1022 //*************************************************************************************************
1023 
1024 
1025 //*************************************************************************************************
1037 template< typename VT // Type of the sparse vector
1038  , bool TF // Transpose flag
1039  , typename... CEAs > // Compile time element arguments
1040 template< typename VT2 > // Type of the right-hand side vector
1041 inline Elements<VT,TF,false,CEAs...>&
1042  Elements<VT,TF,false,CEAs...>::operator+=( const Vector<VT2,TF>& rhs )
1043 {
1044  using blaze::addAssign;
1045 
1046  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1047  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1048 
1049  if( size() != (~rhs).size() ) {
1050  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1051  }
1052 
1053  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1054  Right right( ~rhs );
1055 
1056  if( IsRestricted_v<VT> ) {
1057  for( size_t i=0UL; i<size(); ++i ) {
1058  if( !tryAdd( vector_, idx(i), right[i] ) ) {
1059  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1060  }
1061  }
1062  }
1063 
1064  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1065 
1066  if( IsReference_v<Right> && right.canAlias( &vector_ ) ) {
1067  const ResultType_t<VT2> tmp( right );
1068  addAssign( left, tmp );
1069  }
1070  else {
1071  addAssign( left, right );
1072  }
1073 
1074  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1075 
1076  return *this;
1077 }
1079 //*************************************************************************************************
1080 
1081 
1082 //*************************************************************************************************
1094 template< typename VT // Type of the sparse vector
1095  , bool TF // Transpose flag
1096  , typename... CEAs > // Compile time element arguments
1097 template< typename VT2 > // Type of the right-hand side vector
1098 inline Elements<VT,TF,false,CEAs...>&
1099  Elements<VT,TF,false,CEAs...>::operator-=( const Vector<VT2,TF>& rhs )
1100 {
1101  using blaze::subAssign;
1102 
1103  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1104  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1105 
1106  if( size() != (~rhs).size() ) {
1107  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1108  }
1109 
1110  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1111  Right right( ~rhs );
1112 
1113  if( IsRestricted_v<VT> ) {
1114  for( size_t i=0UL; i<size(); ++i ) {
1115  if( !trySub( vector_, idx(i), right[i] ) ) {
1116  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1117  }
1118  }
1119  }
1120 
1121  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1122 
1123  if( IsReference_v<Right> && right.canAlias( &vector_ ) ) {
1124  const ResultType_t<VT2> tmp( right );
1125  subAssign( left, tmp );
1126  }
1127  else {
1128  subAssign( left, right );
1129  }
1130 
1131  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1132 
1133  return *this;
1134 }
1136 //*************************************************************************************************
1137 
1138 
1139 //*************************************************************************************************
1152 template< typename VT // Type of the sparse vector
1153  , bool TF // Transpose flag
1154  , typename... CEAs > // Compile time element arguments
1155 template< typename VT2 > // Type of the right-hand side vector
1156 inline Elements<VT,TF,false,CEAs...>&
1157  Elements<VT,TF,false,CEAs...>::operator*=( const Vector<VT2,TF>& rhs )
1158 {
1159  using blaze::assign;
1160 
1163  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1164 
1165  using MultType = MultTrait_t< ResultType, ResultType_t<VT2> >;
1166 
1169 
1170  if( size() != (~rhs).size() ) {
1171  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1172  }
1173 
1174  const MultType tmp( *this * (~rhs) );
1175 
1176  if( IsRestricted_v<VT> ) {
1177  for( size_t i=0UL; i<size(); ++i ) {
1178  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1179  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1180  }
1181  }
1182  }
1183 
1184  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1185 
1186  assign( left, tmp );
1187 
1188  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1189 
1190  return *this;
1191 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1208 template< typename VT // Type of the sparse vector
1209  , bool TF // Transpose flag
1210  , typename... CEAs > // Compile time element arguments
1211 template< typename VT2 > // Type of the right-hand side dense vector
1212 inline Elements<VT,TF,false,CEAs...>&
1213  Elements<VT,TF,false,CEAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1214 {
1215  using blaze::assign;
1216 
1219  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT2> );
1220  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1221 
1222  using DivType = DivTrait_t< ResultType, ResultType_t<VT2> >;
1223 
1227 
1228  if( size() != (~rhs).size() ) {
1229  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1230  }
1231 
1232  const DivType tmp( *this / (~rhs) );
1233 
1234  if( IsRestricted_v<VT> ) {
1235  for( size_t i=0UL; i<size(); ++i ) {
1236  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1237  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1238  }
1239  }
1240  }
1241 
1242  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1243 
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  , bool TF // Transpose flag
1269  , typename... CEAs > // Compile time element arguments
1270 template< typename VT2 > // Type of the right-hand side vector
1271 inline Elements<VT,TF,false,CEAs...>&
1272  Elements<VT,TF,false,CEAs...>::operator%=( const Vector<VT2,TF>& rhs )
1273 {
1274  using blaze::assign;
1275 
1276  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1277  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1278 
1279  using CrossType = CrossTrait_t< ResultType, ResultType_t<VT2> >;
1280 
1284 
1285  if( size() != 3UL || (~rhs).size() != 3UL ) {
1286  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1287  }
1288 
1289  const CrossType tmp( *this % (~rhs) );
1290 
1291  if( IsRestricted_v<VT> ) {
1292  for( size_t i=0UL; i<size(); ++i ) {
1293  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1294  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1295  }
1296  }
1297  }
1298 
1299  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1300 
1301  assign( left, tmp );
1302 
1303  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1304 
1305  return *this;
1306 }
1308 //*************************************************************************************************
1309 
1310 
1311 
1312 
1313 //=================================================================================================
1314 //
1315 // UTILITY FUNCTIONS
1316 //
1317 //=================================================================================================
1318 
1319 //*************************************************************************************************
1325 template< typename VT // Type of the sparse vector
1326  , bool TF // Transpose flag
1327  , typename... CEAs > // Compile time element arguments
1328 inline VT& Elements<VT,TF,false,CEAs...>::operand() noexcept
1329 {
1330  return vector_;
1331 }
1333 //*************************************************************************************************
1334 
1335 
1336 //*************************************************************************************************
1342 template< typename VT // Type of the sparse vector
1343  , bool TF // Transpose flag
1344  , typename... CEAs > // Compile time element arguments
1345 inline const VT& Elements<VT,TF,false,CEAs...>::operand() const noexcept
1346 {
1347  return vector_;
1348 }
1350 //*************************************************************************************************
1351 
1352 
1353 //*************************************************************************************************
1359 template< typename VT // Type of the sparse vector
1360  , bool TF // Transpose flag
1361  , typename... CEAs > // Compile time element arguments
1362 inline size_t Elements<VT,TF,false,CEAs...>::capacity() const noexcept
1363 {
1364  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1365 }
1367 //*************************************************************************************************
1368 
1369 
1370 //*************************************************************************************************
1379 template< typename VT // Type of the sparse vector
1380  , bool TF // Transpose flag
1381  , typename... CEAs > // Compile time element arguments
1382 inline size_t Elements<VT,TF,false,CEAs...>::nonZeros() const
1383 {
1384  size_t counter( 0UL );
1385  for( ConstIterator element=begin(); element!=end(); ++element ) {
1386  ++counter;
1387  }
1388  return counter;
1389 }
1391 //*************************************************************************************************
1392 
1393 
1394 //*************************************************************************************************
1400 template< typename VT // Type of the sparse vector
1401  , bool TF // Transpose flag
1402  , typename... CEAs > // Compile time element arguments
1404 {
1405  for( size_t i=0UL; i<size(); ++i )
1406  vector_.erase( idx(i) );
1407 }
1409 //*************************************************************************************************
1410 
1411 
1412 //*************************************************************************************************
1422 template< typename VT // Type of the sparse vector
1423  , bool TF // Transpose flag
1424  , typename... CEAs > // Compile time element arguments
1425 void Elements<VT,TF,false,CEAs...>::reserve( size_t n )
1426 {
1427  const size_t current( capacity() );
1428 
1429  if( n > current ) {
1430  vector_.reserve( vector_.capacity() + n - current );
1431  }
1432 }
1434 //*************************************************************************************************
1435 
1436 
1437 
1438 
1439 //=================================================================================================
1440 //
1441 // INSERTION FUNCTIONS
1442 //
1443 //=================================================================================================
1444 
1445 //*************************************************************************************************
1457 template< typename VT // Type of the sparse vector
1458  , bool TF // Transpose flag
1459  , typename... CEAs > // Compile time element arguments
1460 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1461  Elements<VT,TF,false,CEAs...>::set( size_t index, const ElementType& value )
1462 {
1463  return Iterator( this, index, vector_.set( idx(index), value ) );
1464 }
1466 //*************************************************************************************************
1467 
1468 
1469 //*************************************************************************************************
1482 template< typename VT // Type of the sparse vector
1483  , bool TF // Transpose flag
1484  , typename... CEAs > // Compile time element arguments
1485 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1486  Elements<VT,TF,false,CEAs...>::insert( size_t index, const ElementType& value )
1487 {
1488  return Iterator( this, index, vector_.insert( idx(index), value ) );
1489 }
1491 //*************************************************************************************************
1492 
1493 
1494 //*************************************************************************************************
1519 template< typename VT // Type of the sparse vector
1520  , bool TF // Transpose flag
1521  , typename... CEAs > // Compile time element arguments
1522 inline void Elements<VT,TF,false,CEAs...>::append( size_t index, const ElementType& value, bool check )
1523 {
1524  if( !check || !isDefault<strict>( value ) )
1525  vector_.insert( idx(index), value );
1526 }
1528 //*************************************************************************************************
1529 
1530 
1531 
1532 
1533 //=================================================================================================
1534 //
1535 // ERASE FUNCTIONS
1536 //
1537 //=================================================================================================
1538 
1539 //*************************************************************************************************
1548 template< typename VT // Type of the sparse vector
1549  , bool TF // Transpose flag
1550  , typename... CEAs > // Compile time element arguments
1551 inline void Elements<VT,TF,false,CEAs...>::erase( size_t index )
1552 {
1553  vector_.erase( idx(index) );
1554 }
1556 //*************************************************************************************************
1557 
1558 
1559 //*************************************************************************************************
1568 template< typename VT // Type of the sparse vector
1569  , bool TF // Transpose flag
1570  , typename... CEAs > // Compile time element arguments
1571 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1572  Elements<VT,TF,false,CEAs...>::erase( Iterator pos )
1573 {
1574  const size_t index( pos.index_ );
1575 
1576  if( index == size() )
1577  return pos;
1578 
1579  vector_.erase( pos.pos_ );
1580  return Iterator( this, index+1UL );
1581 }
1583 //*************************************************************************************************
1584 
1585 
1586 //*************************************************************************************************
1596 template< typename VT // Type of the sparse vector
1597  , bool TF // Transpose flag
1598  , typename... CEAs > // Compile time element arguments
1599 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1600  Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last )
1601 {
1602  for( ; first!=last; ++first ) {
1603  vector_.erase( first.pos_ );
1604  }
1605 
1606  return Iterator( this, last.index_ );
1607 }
1609 //*************************************************************************************************
1610 
1611 
1612 //*************************************************************************************************
1635 template< typename VT // Type of the sparse vector
1636  , bool TF // Transpose flag
1637  , typename... CEAs > // Compile time element arguments
1638 template< typename Pred // Type of the unary predicate
1639  , typename > // Type restriction on the unary predicate
1640 inline void Elements<VT,TF,false,CEAs...>::erase( Pred predicate )
1641 {
1642  erase( begin(), end(), predicate );
1643 }
1645 //*************************************************************************************************
1646 
1647 
1648 //*************************************************************************************************
1674 template< typename VT // Type of the sparse vector
1675  , bool TF // Transpose flag
1676  , typename... CEAs > // Compile time element arguments
1677 template< typename Pred > // Type of the unary predicate
1678 inline void Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last, Pred predicate )
1679 {
1680  for( ; first!=last; ++first ) {
1681  if( predicate( first->value() ) )
1682  vector_.erase( first.pos_ );
1683  }
1684 }
1686 //*************************************************************************************************
1687 
1688 
1689 
1690 
1691 //=================================================================================================
1692 //
1693 // LOOKUP FUNCTIONS
1694 //
1695 //=================================================================================================
1696 
1697 //*************************************************************************************************
1711 template< typename VT // Type of the sparse vector
1712  , bool TF // Transpose flag
1713  , typename... CEAs > // Compile time element arguments
1714 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1715  Elements<VT,TF,false,CEAs...>::find( size_t index )
1716 {
1717  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1718 
1719  if( pos != vector_.end() )
1720  return Iterator( this, index, pos );
1721  else
1722  return end();
1723 }
1725 //*************************************************************************************************
1726 
1727 
1728 //*************************************************************************************************
1742 template< typename VT // Type of the sparse vector
1743  , bool TF // Transpose flag
1744  , typename... CEAs > // Compile time element arguments
1745 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1746  Elements<VT,TF,false,CEAs...>::find( size_t index ) const
1747 {
1748  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1749 
1750  if( pos != vector_.end() )
1751  return ConstIterator( this, index, pos );
1752  else
1753  return end();
1754 }
1756 //*************************************************************************************************
1757 
1758 
1759 //*************************************************************************************************
1772 template< typename VT // Type of the sparse vector
1773  , bool TF // Transpose flag
1774  , typename... CEAs > // Compile time element arguments
1775 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1776  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index )
1777 {
1778  for( ; index<size(); ++index ) {
1779  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1780  if( pos != vector_.end() )
1781  return Iterator( this, index, pos );
1782  }
1783  return end();
1784 }
1786 //*************************************************************************************************
1787 
1788 
1789 //*************************************************************************************************
1802 template< typename VT // Type of the sparse vector
1803  , bool TF // Transpose flag
1804  , typename... CEAs > // Compile time element arguments
1805 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1806  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index ) const
1807 {
1808  for( ; index<size(); ++index ) {
1809  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1810  if( pos != vector_.end() )
1811  return ConstIterator( this, index, pos );
1812  }
1813  return end();
1814 }
1816 //*************************************************************************************************
1817 
1818 
1819 //*************************************************************************************************
1832 template< typename VT // Type of the sparse vector
1833  , bool TF // Transpose flag
1834  , typename... CEAs > // Compile time element arguments
1835 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1836  Elements<VT,TF,false,CEAs...>::upperBound( size_t index )
1837 {
1838  while( (++index) < size() ) {
1839  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1840  if( pos != vector_.end() )
1841  return Iterator( this, index, pos );
1842  }
1843  return end();
1844 }
1846 //*************************************************************************************************
1847 
1848 
1849 //*************************************************************************************************
1862 template< typename VT // Type of the sparse vector
1863  , bool TF // Transpose flag
1864  , typename... CEAs > // Compile time element arguments
1865 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1866  Elements<VT,TF,false,CEAs...>::upperBound( size_t index ) const
1867 {
1868  while( (++index) < size() ) {
1869  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1870  if( pos != vector_.end() )
1871  return ConstIterator( this, index, pos );
1872  }
1873  return end();
1874 }
1876 //*************************************************************************************************
1877 
1878 
1879 
1880 
1881 //=================================================================================================
1882 //
1883 // NUMERIC FUNCTIONS
1884 //
1885 //=================================================================================================
1886 
1887 //*************************************************************************************************
1898 template< typename VT // Type of the sparse vector
1899  , bool TF // Transpose flag
1900  , typename... CEAs > // Compile time element arguments
1901 template< typename Other > // Data type of the scalar value
1902 inline Elements<VT,TF,false,CEAs...>&
1903  Elements<VT,TF,false,CEAs...>::scale( const Other& scalar )
1904 {
1905  for( Iterator element=begin(); element!=end(); ++element )
1906  element->value() *= scalar;
1907  return *this;
1908 }
1910 //*************************************************************************************************
1911 
1912 
1913 
1914 
1915 //=================================================================================================
1916 //
1917 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1918 //
1919 //=================================================================================================
1920 
1921 //*************************************************************************************************
1932 template< typename VT // Type of the sparse vector
1933  , bool TF // Transpose flag
1934  , typename... CEAs > // Compile time element arguments
1935 template< typename Other > // Data type of the foreign expression
1936 inline bool Elements<VT,TF,false,CEAs...>::canAlias( const Other* alias ) const noexcept
1937 {
1938  return vector_.isAliased( alias );
1939 }
1941 //*************************************************************************************************
1942 
1943 
1944 //*************************************************************************************************
1955 template< typename VT // Type of the sparse vector
1956  , bool TF // Transpose flag
1957  , typename... CEAs > // Compile time element arguments
1958 template< typename Other > // Data type of the foreign expression
1959 inline bool Elements<VT,TF,false,CEAs...>::isAliased( const Other* alias ) const noexcept
1960 {
1961  return vector_.isAliased( alias );
1962 }
1964 //*************************************************************************************************
1965 
1966 
1967 //*************************************************************************************************
1979 template< typename VT // Type of the sparse vector
1980  , bool TF // Transpose flag
1981  , typename... CEAs > // Compile time element arguments
1982 template< typename VT2 > // Type of the right-hand side dense vector
1983 inline void Elements<VT,TF,false,CEAs...>::assign( const DenseVector<VT2,TF>& rhs )
1984 {
1985  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1986 
1987  using RT = If_t< IsComputation_v<VT2>, ElementType_t<VT>, const ElementType_t<VT2>& >;
1988 
1989  reserve( (~rhs).size() );
1990 
1991  for( size_t i=0UL; i<size(); ++i ) {
1992  RT value( (~rhs)[i] );
1993  if( !isDefault<strict>( value ) )
1994  vector_.set( idx(i), std::move( value ) );
1995  else vector_.erase( idx(i) );
1996  }
1997 }
1999 //*************************************************************************************************
2000 
2001 
2002 //*************************************************************************************************
2014 template< typename VT // Type of the sparse vector
2015  , bool TF // Transpose flag
2016  , typename... CEAs > // Compile time element arguments
2017 template< typename VT2 > // Type of the right-hand side sparse vector
2018 inline void Elements<VT,TF,false,CEAs...>::assign( const SparseVector<VT2,TF>& rhs )
2019 {
2020  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2021 
2022  using RT = If_t< IsComputation_v<VT2>, ElementType_t<VT>, const ElementType_t<VT2>& >;
2023 
2024  size_t i( 0UL );
2025 
2026  for( ConstIterator_t<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2027  for( ; i<element->index(); ++i )
2028  vector_.erase( idx(i) );
2029  RT value( element->value() );
2030  if( !isDefault<strict>( value ) )
2031  vector_.set( idx(i), std::move( value ) );
2032  else vector_.erase( idx(i) );
2033  ++i;
2034  }
2035  for( ; i<size(); ++i ) {
2036  vector_.erase( idx(i) );
2037  }
2038 }
2040 //*************************************************************************************************
2041 
2042 
2043 //*************************************************************************************************
2055 template< typename VT // Type of the sparse vector
2056  , bool TF // Transpose flag
2057  , typename... CEAs > // Compile time element arguments
2058 template< typename VT2 > // Type of the right-hand side vector
2059 inline void Elements<VT,TF,false,CEAs...>::addAssign( const Vector<VT2,TF>& rhs )
2060 {
2061  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2062 
2065 
2066  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2067 
2068  const AddType tmp( serial( *this + (~rhs) ) );
2069  assign( tmp );
2070 }
2072 //*************************************************************************************************
2073 
2074 
2075 //*************************************************************************************************
2087 template< typename VT // Type of the sparse vector
2088  , bool TF // Transpose flag
2089  , typename... CEAs > // Compile time element arguments
2090 template< typename VT2 > // Type of the right-hand side vector
2091 inline void Elements<VT,TF,false,CEAs...>::subAssign( const Vector<VT2,TF>& rhs )
2092 {
2093  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2094 
2097 
2098  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2099 
2100  const SubType tmp( serial( *this - (~rhs) ) );
2101  assign( tmp );
2102 }
2104 //*************************************************************************************************
2105 
2106 } // namespace blaze
2107 
2108 #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.
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 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
Constraint on the data type.
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
Header file for the decltype(auto) workaround.
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.
Header file for the elements trait.
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
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
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
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_NOT_BE_ELEMENTS_TYPE(T)
Constraint on the data type.In case the given data type T is an element selection (i...
Definition: Elements.h:81
#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.
Header file for the implementation of the Elements base template.
Constraint on the data type.
decltype(auto) elements(Vector< VT, TF > &vector, REAs... args)
Creating a view on a selection of elements of the given vector.
Definition: Elements.h:135
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.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
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
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.
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
Header file for the IsComputation type trait class.
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
Header file for the implementation of the ElementsData class template.
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.