Blaze  3.6
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>
54 #include <blaze/math/Exception.h>
71 #include <blaze/math/views/Check.h>
74 #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 
444  static constexpr bool compileTimeArgs = DataType::compileTimeArgs;
445  //**********************************************************************************************
446 
447  //**Constructors********************************************************************************
450  template< typename... REAs >
451  explicit inline Elements( VT& vector, REAs... args );
452 
453  Elements( const Elements& ) = default;
454  Elements( Elements&& ) = default;
456  //**********************************************************************************************
457 
458  //**Destructor**********************************************************************************
461  ~Elements() = default;
463  //**********************************************************************************************
464 
465  //**Data access functions***********************************************************************
468  inline Reference operator[]( size_t index );
469  inline ConstReference operator[]( size_t index ) const;
470  inline Reference at( size_t index );
471  inline ConstReference at( size_t index ) const;
472  inline Iterator begin ();
473  inline ConstIterator begin () const;
474  inline ConstIterator cbegin() const;
475  inline Iterator end ();
476  inline ConstIterator end () const;
477  inline ConstIterator cend () const;
479  //**********************************************************************************************
480 
481  //**Assignment operators************************************************************************
484  inline Elements& operator= ( initializer_list<ElementType> list );
485  inline Elements& operator= ( const Elements& rhs );
486  template< typename VT2 > inline Elements& operator= ( const Vector<VT2,TF>& rhs );
487  template< typename VT2 > inline Elements& operator+=( const Vector<VT2,TF>& rhs );
488  template< typename VT2 > inline Elements& operator-=( const Vector<VT2,TF>& rhs );
489  template< typename VT2 > inline Elements& operator*=( const Vector<VT2,TF>& rhs );
490  template< typename VT2 > inline Elements& operator/=( const DenseVector<VT2,TF>& rhs );
491  template< typename VT2 > inline Elements& operator%=( const Vector<VT2,TF>& rhs );
493  //**********************************************************************************************
494 
495  //**Utility functions***************************************************************************
498  using DataType::idces;
499  using DataType::idx;
500  using DataType::size;
501 
502  inline VT& operand() noexcept;
503  inline const VT& operand() const noexcept;
504 
505  inline size_t capacity() const noexcept;
506  inline size_t nonZeros() const;
507  inline void reset();
508  inline void reserve( size_t n );
510  //**********************************************************************************************
511 
512  //**Insertion functions*************************************************************************
515  inline Iterator set ( size_t index, const ElementType& value );
516  inline Iterator insert( size_t index, const ElementType& value );
517  inline void append( size_t index, const ElementType& value, bool check=false );
519  //**********************************************************************************************
520 
521  //**Erase functions*****************************************************************************
524  inline void erase( size_t index );
525  inline Iterator erase( Iterator pos );
526  inline Iterator erase( Iterator first, Iterator last );
527 
528  template< typename Pred, typename = DisableIf_t< IsIntegral_v<Pred> > >
529  inline void erase( Pred predicate );
530 
531  template< typename Pred >
532  inline void erase( Iterator first, Iterator last, Pred predicate );
534  //**********************************************************************************************
535 
536  //**Lookup functions****************************************************************************
539  inline Iterator find ( size_t index );
540  inline ConstIterator find ( size_t index ) const;
541  inline Iterator lowerBound( size_t index );
542  inline ConstIterator lowerBound( size_t index ) const;
543  inline Iterator upperBound( size_t index );
544  inline ConstIterator upperBound( size_t index ) const;
546  //**********************************************************************************************
547 
548  //**Numeric functions***************************************************************************
551  template< typename Other > inline Elements& scale( const Other& scalar );
553  //**********************************************************************************************
554 
555  //**Expression template evaluation functions****************************************************
558  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
559  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
560 
561  inline bool canSMPAssign() const noexcept;
562 
563  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
564  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
565  template< typename VT2 > inline void addAssign( const Vector<VT2,TF>& rhs );
566  template< typename VT2 > inline void subAssign( const Vector<VT2,TF>& rhs );
568  //**********************************************************************************************
569 
570  private:
571  //**Member variables****************************************************************************
574  Operand vector_;
575 
576  //**********************************************************************************************
577 
578  //**Compile time checks*************************************************************************
585  //**********************************************************************************************
586 };
588 //*************************************************************************************************
589 
590 
591 
592 
593 //=================================================================================================
594 //
595 // CONSTRUCTORS
596 //
597 //=================================================================================================
598 
599 //*************************************************************************************************
612 template< typename VT // Type of the sparse vector
613  , bool TF // Transpose flag
614  , typename... CEAs > // Compile time element arguments
615 template< typename... REAs > // Optional arguments
616 inline Elements<VT,TF,false,CEAs...>::Elements( VT& vector, REAs... args )
617  : DataType( args... ) // Base class initialization
618  , vector_ ( vector ) // The vector containing the elements
619 {
620  if( !Contains_v< TypeList<REAs...>, Unchecked > ) {
621  for( size_t i=0UL; i<size(); ++i ) {
622  if( vector_.size() <= idx(i) ) {
623  BLAZE_THROW_INVALID_ARGUMENT( "Invalid element access index" );
624  }
625  }
626  }
627 }
629 //*************************************************************************************************
630 
631 
632 
633 
634 //=================================================================================================
635 //
636 // DATA ACCESS FUNCTIONS
637 //
638 //=================================================================================================
639 
640 //*************************************************************************************************
650 template< typename VT // Type of the sparse vector
651  , bool TF // Transpose flag
652  , typename... CEAs > // Compile time element arguments
653 inline typename Elements<VT,TF,false,CEAs...>::Reference
654  Elements<VT,TF,false,CEAs...>::operator[]( size_t index )
655 {
656  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
657  return vector_[idx(index)];
658 }
660 //*************************************************************************************************
661 
662 
663 //*************************************************************************************************
673 template< typename VT // Type of the sparse vector
674  , bool TF // Transpose flag
675  , typename... CEAs > // Compile time element arguments
676 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
677  Elements<VT,TF,false,CEAs...>::operator[]( size_t index ) const
678 {
679  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
680  return const_cast<const VT&>( vector_ )[idx(index)];
681 }
683 //*************************************************************************************************
684 
685 
686 //*************************************************************************************************
697 template< typename VT // Type of the sparse vector
698  , bool TF // Transpose flag
699  , typename... CEAs > // Compile time element arguments
700 inline typename Elements<VT,TF,false,CEAs...>::Reference
701  Elements<VT,TF,false,CEAs...>::at( size_t index )
702 {
703  if( index >= size() ) {
704  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
705  }
706  return (*this)[index];
707 }
709 //*************************************************************************************************
710 
711 
712 //*************************************************************************************************
723 template< typename VT // Type of the sparse vector
724  , bool TF // Transpose flag
725  , typename... CEAs > // Compile time element arguments
726 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
727  Elements<VT,TF,false,CEAs...>::at( size_t index ) const
728 {
729  if( index >= size() ) {
730  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
731  }
732  return (*this)[index];
733 }
735 //*************************************************************************************************
736 
737 
738 //*************************************************************************************************
746 template< typename VT // Type of the sparse vector
747  , bool TF // Transpose flag
748  , typename... CEAs > // Compile time element arguments
749 inline typename Elements<VT,TF,false,CEAs...>::Iterator
751 {
752  return Iterator( this, 0UL );
753 }
755 //*************************************************************************************************
756 
757 
758 //*************************************************************************************************
766 template< typename VT // Type of the sparse vector
767  , bool TF // Transpose flag
768  , typename... CEAs > // Compile time element arguments
769 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
771 {
772  return ConstIterator( this, 0UL );
773 }
775 //*************************************************************************************************
776 
777 
778 //*************************************************************************************************
786 template< typename VT // Type of the sparse vector
787  , bool TF // Transpose flag
788  , typename... CEAs > // Compile time element arguments
789 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
791 {
792  return ConstIterator( this, 0UL );
793 }
795 //*************************************************************************************************
796 
797 
798 //*************************************************************************************************
806 template< typename VT // Type of the sparse vector
807  , bool TF // Transpose flag
808  , typename... CEAs > // Compile time element arguments
809 inline typename Elements<VT,TF,false,CEAs...>::Iterator
811 {
812  return Iterator( this, size() );
813 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
826 template< typename VT // Type of the sparse vector
827  , bool TF // Transpose flag
828  , typename... CEAs > // Compile time element arguments
829 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
831 {
832  return ConstIterator( this, size() );
833 }
835 //*************************************************************************************************
836 
837 
838 //*************************************************************************************************
846 template< typename VT // Type of the sparse vector
847  , bool TF // Transpose flag
848  , typename... CEAs > // Compile time element arguments
849 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
851 {
852  return ConstIterator( this, size() );
853 }
855 //*************************************************************************************************
856 
857 
858 
859 
860 //=================================================================================================
861 //
862 // ASSIGNMENT OPERATORS
863 //
864 //=================================================================================================
865 
866 //*************************************************************************************************
882 template< typename VT // Type of the sparse vector
883  , bool TF // Transpose flag
884  , typename... CEAs > // Compile time element arguments
885 inline Elements<VT,TF,false,CEAs...>&
886  Elements<VT,TF,false,CEAs...>::operator=( initializer_list<ElementType> list )
887 {
888  using blaze::assign;
889 
890  if( list.size() > size() ) {
891  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to elements" );
892  }
893 
894  const InitializerVector<ElementType,TF> tmp( list, size() );
895 
896  if( IsRestricted_v<VT> ) {
897  for( size_t i=0UL; i<size(); ++i ) {
898  if( !trySet( vector_, idx(i), tmp[i] ) ) {
899  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
900  }
901  }
902  }
903 
904  decltype(auto) left( derestrict( *this ) );
905 
906  assign( left, tmp );
907 
908  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
909 
910  return *this;
911 }
913 //*************************************************************************************************
914 
915 
916 //*************************************************************************************************
928 template< typename VT // Type of the sparse vector
929  , bool TF // Transpose flag
930  , typename... CEAs > // Compile time element arguments
931 inline Elements<VT,TF,false,CEAs...>&
932  Elements<VT,TF,false,CEAs...>::operator=( const Elements& rhs )
933 {
934  using blaze::assign;
935 
938 
939  if( &rhs == this || ( &vector_ == &rhs.vector_ && compareIndices( *this, rhs ) ) )
940  return *this;
941 
942  if( size() != rhs.size() ) {
943  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
944  }
945 
946  if( IsRestricted_v<VT> ) {
947  for( size_t i=0UL; i<size(); ++i ) {
948  if( !trySet( vector_, idx(i), rhs[i] ) ) {
949  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
950  }
951  }
952  }
953 
954  decltype(auto) left( derestrict( *this ) );
955 
956  if( rhs.canAlias( &vector_ ) ) {
957  const ResultType tmp( rhs );
958  assign( left, tmp );
959  }
960  else {
961  assign( left, rhs );
962  }
963 
964  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
965 
966  return *this;
967 }
969 //*************************************************************************************************
970 
971 
972 //*************************************************************************************************
984 template< typename VT // Type of the sparse vector
985  , bool TF // Transpose flag
986  , typename... CEAs > // Compile time element arguments
987 template< typename VT2 > // Type of the right-hand side vector
988 inline Elements<VT,TF,false,CEAs...>&
989  Elements<VT,TF,false,CEAs...>::operator=( const Vector<VT2,TF>& rhs )
990 {
991  using blaze::assign;
992 
995 
996  if( size() != (~rhs).size() ) {
997  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
998  }
999 
1000  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1001  Right right( ~rhs );
1002 
1003  if( IsRestricted_v<VT> ) {
1004  for( size_t i=0UL; i<size(); ++i ) {
1005  if( !trySet( vector_, idx(i), right[i] ) ) {
1006  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1007  }
1008  }
1009  }
1010 
1011  decltype(auto) left( derestrict( *this ) );
1012 
1013  if( IsReference_v<Right> || right.canAlias( &vector_ ) ) {
1014  const ResultType_t<VT2> tmp( right );
1015  assign( left, tmp );
1016  }
1017  else {
1018  assign( left, right );
1019  }
1020 
1021  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1022 
1023  return *this;
1024 }
1026 //*************************************************************************************************
1027 
1028 
1029 //*************************************************************************************************
1041 template< typename VT // Type of the sparse vector
1042  , bool TF // Transpose flag
1043  , typename... CEAs > // Compile time element arguments
1044 template< typename VT2 > // Type of the right-hand side vector
1045 inline Elements<VT,TF,false,CEAs...>&
1046  Elements<VT,TF,false,CEAs...>::operator+=( const Vector<VT2,TF>& rhs )
1047 {
1048  using blaze::addAssign;
1049 
1050  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1051  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1052 
1053  if( size() != (~rhs).size() ) {
1054  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1055  }
1056 
1057  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1058  Right right( ~rhs );
1059 
1060  if( IsRestricted_v<VT> ) {
1061  for( size_t i=0UL; i<size(); ++i ) {
1062  if( !tryAdd( vector_, idx(i), right[i] ) ) {
1063  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1064  }
1065  }
1066  }
1067 
1068  decltype(auto) left( derestrict( *this ) );
1069 
1070  if( IsReference_v<Right> && right.canAlias( &vector_ ) ) {
1071  const ResultType_t<VT2> tmp( right );
1072  addAssign( left, tmp );
1073  }
1074  else {
1075  addAssign( left, right );
1076  }
1077 
1078  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1079 
1080  return *this;
1081 }
1083 //*************************************************************************************************
1084 
1085 
1086 //*************************************************************************************************
1098 template< typename VT // Type of the sparse vector
1099  , bool TF // Transpose flag
1100  , typename... CEAs > // Compile time element arguments
1101 template< typename VT2 > // Type of the right-hand side vector
1102 inline Elements<VT,TF,false,CEAs...>&
1103  Elements<VT,TF,false,CEAs...>::operator-=( const Vector<VT2,TF>& rhs )
1104 {
1105  using blaze::subAssign;
1106 
1107  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1108  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1109 
1110  if( size() != (~rhs).size() ) {
1111  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1112  }
1113 
1114  using Right = If_t< IsRestricted_v<VT>, CompositeType_t<VT2>, const VT2& >;
1115  Right right( ~rhs );
1116 
1117  if( IsRestricted_v<VT> ) {
1118  for( size_t i=0UL; i<size(); ++i ) {
1119  if( !trySub( vector_, idx(i), right[i] ) ) {
1120  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1121  }
1122  }
1123  }
1124 
1125  decltype(auto) left( derestrict( *this ) );
1126 
1127  if( IsReference_v<Right> && right.canAlias( &vector_ ) ) {
1128  const ResultType_t<VT2> tmp( right );
1129  subAssign( left, tmp );
1130  }
1131  else {
1132  subAssign( left, right );
1133  }
1134 
1135  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1136 
1137  return *this;
1138 }
1140 //*************************************************************************************************
1141 
1142 
1143 //*************************************************************************************************
1156 template< typename VT // Type of the sparse vector
1157  , bool TF // Transpose flag
1158  , typename... CEAs > // Compile time element arguments
1159 template< typename VT2 > // Type of the right-hand side vector
1160 inline Elements<VT,TF,false,CEAs...>&
1161  Elements<VT,TF,false,CEAs...>::operator*=( const Vector<VT2,TF>& rhs )
1162 {
1163  using blaze::assign;
1164 
1167  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1168 
1169  using MultType = MultTrait_t< ResultType, ResultType_t<VT2> >;
1170 
1173 
1174  if( size() != (~rhs).size() ) {
1175  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1176  }
1177 
1178  const MultType tmp( *this * (~rhs) );
1179 
1180  if( IsRestricted_v<VT> ) {
1181  for( size_t i=0UL; i<size(); ++i ) {
1182  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1183  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1184  }
1185  }
1186  }
1187 
1188  decltype(auto) left( derestrict( *this ) );
1189 
1190  assign( left, tmp );
1191 
1192  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1193 
1194  return *this;
1195 }
1197 //*************************************************************************************************
1198 
1199 
1200 //*************************************************************************************************
1212 template< typename VT // Type of the sparse vector
1213  , bool TF // Transpose flag
1214  , typename... CEAs > // Compile time element arguments
1215 template< typename VT2 > // Type of the right-hand side dense vector
1216 inline Elements<VT,TF,false,CEAs...>&
1217  Elements<VT,TF,false,CEAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1218 {
1219  using blaze::assign;
1220 
1223  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_t<VT2> );
1224  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1225 
1226  using DivType = DivTrait_t< ResultType, ResultType_t<VT2> >;
1227 
1231 
1232  if( size() != (~rhs).size() ) {
1233  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1234  }
1235 
1236  const DivType tmp( *this / (~rhs) );
1237 
1238  if( IsRestricted_v<VT> ) {
1239  for( size_t i=0UL; i<size(); ++i ) {
1240  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1241  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1242  }
1243  }
1244  }
1245 
1246  decltype(auto) left( derestrict( *this ) );
1247 
1248  assign( left, tmp );
1249 
1250  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1251 
1252  return *this;
1253 }
1255 //*************************************************************************************************
1256 
1257 
1258 //*************************************************************************************************
1271 template< typename VT // Type of the sparse vector
1272  , bool TF // Transpose flag
1273  , typename... CEAs > // Compile time element arguments
1274 template< typename VT2 > // Type of the right-hand side vector
1275 inline Elements<VT,TF,false,CEAs...>&
1276  Elements<VT,TF,false,CEAs...>::operator%=( const Vector<VT2,TF>& rhs )
1277 {
1278  using blaze::assign;
1279 
1280  BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG( ResultType_t<VT2>, TF );
1281  BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION( ResultType_t<VT2> );
1282 
1283  using CrossType = CrossTrait_t< ResultType, ResultType_t<VT2> >;
1284 
1288 
1289  if( size() != 3UL || (~rhs).size() != 3UL ) {
1290  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1291  }
1292 
1293  const CrossType tmp( *this % (~rhs) );
1294 
1295  if( IsRestricted_v<VT> ) {
1296  for( size_t i=0UL; i<size(); ++i ) {
1297  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1298  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1299  }
1300  }
1301  }
1302 
1303  decltype(auto) left( derestrict( *this ) );
1304 
1305  assign( left, tmp );
1306 
1307  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1308 
1309  return *this;
1310 }
1312 //*************************************************************************************************
1313 
1314 
1315 
1316 
1317 //=================================================================================================
1318 //
1319 // UTILITY FUNCTIONS
1320 //
1321 //=================================================================================================
1322 
1323 //*************************************************************************************************
1329 template< typename VT // Type of the sparse vector
1330  , bool TF // Transpose flag
1331  , typename... CEAs > // Compile time element arguments
1332 inline VT& Elements<VT,TF,false,CEAs...>::operand() noexcept
1333 {
1334  return vector_;
1335 }
1337 //*************************************************************************************************
1338 
1339 
1340 //*************************************************************************************************
1346 template< typename VT // Type of the sparse vector
1347  , bool TF // Transpose flag
1348  , typename... CEAs > // Compile time element arguments
1349 inline const VT& Elements<VT,TF,false,CEAs...>::operand() const noexcept
1350 {
1351  return vector_;
1352 }
1354 //*************************************************************************************************
1355 
1356 
1357 //*************************************************************************************************
1363 template< typename VT // Type of the sparse vector
1364  , bool TF // Transpose flag
1365  , typename... CEAs > // Compile time element arguments
1366 inline size_t Elements<VT,TF,false,CEAs...>::capacity() const noexcept
1367 {
1368  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1369 }
1371 //*************************************************************************************************
1372 
1373 
1374 //*************************************************************************************************
1383 template< typename VT // Type of the sparse vector
1384  , bool TF // Transpose flag
1385  , typename... CEAs > // Compile time element arguments
1386 inline size_t Elements<VT,TF,false,CEAs...>::nonZeros() const
1387 {
1388  size_t counter( 0UL );
1389  for( ConstIterator element=begin(); element!=end(); ++element ) {
1390  ++counter;
1391  }
1392  return counter;
1393 }
1395 //*************************************************************************************************
1396 
1397 
1398 //*************************************************************************************************
1404 template< typename VT // Type of the sparse vector
1405  , bool TF // Transpose flag
1406  , typename... CEAs > // Compile time element arguments
1408 {
1409  for( size_t i=0UL; i<size(); ++i )
1410  vector_.erase( idx(i) );
1411 }
1413 //*************************************************************************************************
1414 
1415 
1416 //*************************************************************************************************
1426 template< typename VT // Type of the sparse vector
1427  , bool TF // Transpose flag
1428  , typename... CEAs > // Compile time element arguments
1429 void Elements<VT,TF,false,CEAs...>::reserve( size_t n )
1430 {
1431  const size_t current( capacity() );
1432 
1433  if( n > current ) {
1434  vector_.reserve( vector_.capacity() + n - current );
1435  }
1436 }
1438 //*************************************************************************************************
1439 
1440 
1441 
1442 
1443 //=================================================================================================
1444 //
1445 // INSERTION FUNCTIONS
1446 //
1447 //=================================================================================================
1448 
1449 //*************************************************************************************************
1461 template< typename VT // Type of the sparse vector
1462  , bool TF // Transpose flag
1463  , typename... CEAs > // Compile time element arguments
1464 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1465  Elements<VT,TF,false,CEAs...>::set( size_t index, const ElementType& value )
1466 {
1467  return Iterator( this, index, vector_.set( idx(index), value ) );
1468 }
1470 //*************************************************************************************************
1471 
1472 
1473 //*************************************************************************************************
1486 template< typename VT // Type of the sparse vector
1487  , bool TF // Transpose flag
1488  , typename... CEAs > // Compile time element arguments
1489 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1490  Elements<VT,TF,false,CEAs...>::insert( size_t index, const ElementType& value )
1491 {
1492  return Iterator( this, index, vector_.insert( idx(index), value ) );
1493 }
1495 //*************************************************************************************************
1496 
1497 
1498 //*************************************************************************************************
1523 template< typename VT // Type of the sparse vector
1524  , bool TF // Transpose flag
1525  , typename... CEAs > // Compile time element arguments
1526 inline void Elements<VT,TF,false,CEAs...>::append( size_t index, const ElementType& value, bool check )
1527 {
1528  if( !check || !isDefault<strict>( value ) )
1529  vector_.insert( idx(index), value );
1530 }
1532 //*************************************************************************************************
1533 
1534 
1535 
1536 
1537 //=================================================================================================
1538 //
1539 // ERASE FUNCTIONS
1540 //
1541 //=================================================================================================
1542 
1543 //*************************************************************************************************
1552 template< typename VT // Type of the sparse vector
1553  , bool TF // Transpose flag
1554  , typename... CEAs > // Compile time element arguments
1555 inline void Elements<VT,TF,false,CEAs...>::erase( size_t index )
1556 {
1557  vector_.erase( idx(index) );
1558 }
1560 //*************************************************************************************************
1561 
1562 
1563 //*************************************************************************************************
1572 template< typename VT // Type of the sparse vector
1573  , bool TF // Transpose flag
1574  , typename... CEAs > // Compile time element arguments
1575 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1576  Elements<VT,TF,false,CEAs...>::erase( Iterator pos )
1577 {
1578  const size_t index( pos.index_ );
1579 
1580  if( index == size() )
1581  return pos;
1582 
1583  vector_.erase( pos.pos_ );
1584  return Iterator( this, index+1UL );
1585 }
1587 //*************************************************************************************************
1588 
1589 
1590 //*************************************************************************************************
1600 template< typename VT // Type of the sparse vector
1601  , bool TF // Transpose flag
1602  , typename... CEAs > // Compile time element arguments
1603 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1604  Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last )
1605 {
1606  for( ; first!=last; ++first ) {
1607  vector_.erase( first.pos_ );
1608  }
1609 
1610  return Iterator( this, last.index_ );
1611 }
1613 //*************************************************************************************************
1614 
1615 
1616 //*************************************************************************************************
1639 template< typename VT // Type of the sparse vector
1640  , bool TF // Transpose flag
1641  , typename... CEAs > // Compile time element arguments
1642 template< typename Pred // Type of the unary predicate
1643  , typename > // Type restriction on the unary predicate
1644 inline void Elements<VT,TF,false,CEAs...>::erase( Pred predicate )
1645 {
1646  erase( begin(), end(), predicate );
1647 }
1649 //*************************************************************************************************
1650 
1651 
1652 //*************************************************************************************************
1678 template< typename VT // Type of the sparse vector
1679  , bool TF // Transpose flag
1680  , typename... CEAs > // Compile time element arguments
1681 template< typename Pred > // Type of the unary predicate
1682 inline void Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last, Pred predicate )
1683 {
1684  for( ; first!=last; ++first ) {
1685  if( predicate( first->value() ) )
1686  vector_.erase( first.pos_ );
1687  }
1688 }
1690 //*************************************************************************************************
1691 
1692 
1693 
1694 
1695 //=================================================================================================
1696 //
1697 // LOOKUP FUNCTIONS
1698 //
1699 //=================================================================================================
1700 
1701 //*************************************************************************************************
1715 template< typename VT // Type of the sparse vector
1716  , bool TF // Transpose flag
1717  , typename... CEAs > // Compile time element arguments
1718 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1719  Elements<VT,TF,false,CEAs...>::find( size_t index )
1720 {
1721  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1722 
1723  if( pos != vector_.end() )
1724  return Iterator( this, index, pos );
1725  else
1726  return end();
1727 }
1729 //*************************************************************************************************
1730 
1731 
1732 //*************************************************************************************************
1746 template< typename VT // Type of the sparse vector
1747  , bool TF // Transpose flag
1748  , typename... CEAs > // Compile time element arguments
1749 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1750  Elements<VT,TF,false,CEAs...>::find( size_t index ) const
1751 {
1752  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1753 
1754  if( pos != vector_.end() )
1755  return ConstIterator( this, index, pos );
1756  else
1757  return end();
1758 }
1760 //*************************************************************************************************
1761 
1762 
1763 //*************************************************************************************************
1776 template< typename VT // Type of the sparse vector
1777  , bool TF // Transpose flag
1778  , typename... CEAs > // Compile time element arguments
1779 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1780  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index )
1781 {
1782  for( ; index<size(); ++index ) {
1783  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1784  if( pos != vector_.end() )
1785  return Iterator( this, index, pos );
1786  }
1787  return end();
1788 }
1790 //*************************************************************************************************
1791 
1792 
1793 //*************************************************************************************************
1806 template< typename VT // Type of the sparse vector
1807  , bool TF // Transpose flag
1808  , typename... CEAs > // Compile time element arguments
1809 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1810  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index ) const
1811 {
1812  for( ; index<size(); ++index ) {
1813  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1814  if( pos != vector_.end() )
1815  return ConstIterator( this, index, pos );
1816  }
1817  return end();
1818 }
1820 //*************************************************************************************************
1821 
1822 
1823 //*************************************************************************************************
1836 template< typename VT // Type of the sparse vector
1837  , bool TF // Transpose flag
1838  , typename... CEAs > // Compile time element arguments
1839 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1840  Elements<VT,TF,false,CEAs...>::upperBound( size_t index )
1841 {
1842  while( (++index) < size() ) {
1843  const Iterator_t<VT> pos( vector_.find( idx(index) ) );
1844  if( pos != vector_.end() )
1845  return Iterator( this, index, pos );
1846  }
1847  return end();
1848 }
1850 //*************************************************************************************************
1851 
1852 
1853 //*************************************************************************************************
1866 template< typename VT // Type of the sparse vector
1867  , bool TF // Transpose flag
1868  , typename... CEAs > // Compile time element arguments
1869 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1870  Elements<VT,TF,false,CEAs...>::upperBound( size_t index ) const
1871 {
1872  while( (++index) < size() ) {
1873  const ConstIterator_t<VT> pos( vector_.find( idx(index) ) );
1874  if( pos != vector_.end() )
1875  return ConstIterator( this, index, pos );
1876  }
1877  return end();
1878 }
1880 //*************************************************************************************************
1881 
1882 
1883 
1884 
1885 //=================================================================================================
1886 //
1887 // NUMERIC FUNCTIONS
1888 //
1889 //=================================================================================================
1890 
1891 //*************************************************************************************************
1902 template< typename VT // Type of the sparse vector
1903  , bool TF // Transpose flag
1904  , typename... CEAs > // Compile time element arguments
1905 template< typename Other > // Data type of the scalar value
1906 inline Elements<VT,TF,false,CEAs...>&
1907  Elements<VT,TF,false,CEAs...>::scale( const Other& scalar )
1908 {
1909  for( Iterator element=begin(); element!=end(); ++element )
1910  element->value() *= scalar;
1911  return *this;
1912 }
1914 //*************************************************************************************************
1915 
1916 
1917 
1918 
1919 //=================================================================================================
1920 //
1921 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1922 //
1923 //=================================================================================================
1924 
1925 //*************************************************************************************************
1936 template< typename VT // Type of the sparse vector
1937  , bool TF // Transpose flag
1938  , typename... CEAs > // Compile time element arguments
1939 template< typename Other > // Data type of the foreign expression
1940 inline bool Elements<VT,TF,false,CEAs...>::canAlias( const Other* alias ) const noexcept
1941 {
1942  return vector_.isAliased( alias );
1943 }
1945 //*************************************************************************************************
1946 
1947 
1948 //*************************************************************************************************
1959 template< typename VT // Type of the sparse vector
1960  , bool TF // Transpose flag
1961  , typename... CEAs > // Compile time element arguments
1962 template< typename Other > // Data type of the foreign expression
1963 inline bool Elements<VT,TF,false,CEAs...>::isAliased( const Other* alias ) const noexcept
1964 {
1965  return vector_.isAliased( alias );
1966 }
1968 //*************************************************************************************************
1969 
1970 
1971 //*************************************************************************************************
1983 template< typename VT // Type of the sparse vector
1984  , bool TF // Transpose flag
1985  , typename... CEAs > // Compile time element arguments
1986 template< typename VT2 > // Type of the right-hand side dense vector
1987 inline void Elements<VT,TF,false,CEAs...>::assign( const DenseVector<VT2,TF>& rhs )
1988 {
1989  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1990 
1991  using RT = If_t< IsComputation_v<VT2>, ElementType_t<VT>, const ElementType_t<VT2>& >;
1992 
1993  reserve( (~rhs).size() );
1994 
1995  for( size_t i=0UL; i<size(); ++i ) {
1996  RT value( (~rhs)[i] );
1997  if( !isDefault<strict>( value ) )
1998  vector_.set( idx(i), std::move( value ) );
1999  else vector_.erase( idx(i) );
2000  }
2001 }
2003 //*************************************************************************************************
2004 
2005 
2006 //*************************************************************************************************
2018 template< typename VT // Type of the sparse vector
2019  , bool TF // Transpose flag
2020  , typename... CEAs > // Compile time element arguments
2021 template< typename VT2 > // Type of the right-hand side sparse vector
2022 inline void Elements<VT,TF,false,CEAs...>::assign( const SparseVector<VT2,TF>& rhs )
2023 {
2024  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2025 
2026  using RT = If_t< IsComputation_v<VT2>, ElementType_t<VT>, const ElementType_t<VT2>& >;
2027 
2028  size_t i( 0UL );
2029 
2030  for( ConstIterator_t<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2031  for( ; i<element->index(); ++i )
2032  vector_.erase( idx(i) );
2033  RT value( element->value() );
2034  if( !isDefault<strict>( value ) )
2035  vector_.set( idx(i), std::move( value ) );
2036  else vector_.erase( idx(i) );
2037  ++i;
2038  }
2039  for( ; i<size(); ++i ) {
2040  vector_.erase( idx(i) );
2041  }
2042 }
2044 //*************************************************************************************************
2045 
2046 
2047 //*************************************************************************************************
2059 template< typename VT // Type of the sparse vector
2060  , bool TF // Transpose flag
2061  , typename... CEAs > // Compile time element arguments
2062 template< typename VT2 > // Type of the right-hand side vector
2063 inline void Elements<VT,TF,false,CEAs...>::addAssign( const Vector<VT2,TF>& rhs )
2064 {
2065  using AddType = AddTrait_t< ResultType, ResultType_t<VT2> >;
2066 
2069 
2070  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2071 
2072  const AddType tmp( serial( *this + (~rhs) ) );
2073  assign( tmp );
2074 }
2076 //*************************************************************************************************
2077 
2078 
2079 //*************************************************************************************************
2091 template< typename VT // Type of the sparse vector
2092  , bool TF // Transpose flag
2093  , typename... CEAs > // Compile time element arguments
2094 template< typename VT2 > // Type of the right-hand side vector
2095 inline void Elements<VT,TF,false,CEAs...>::subAssign( const Vector<VT2,TF>& rhs )
2096 {
2097  using SubType = SubTrait_t< ResultType, ResultType_t<VT2> >;
2098 
2101 
2102  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2103 
2104  const SubType tmp( serial( *this - (~rhs) ) );
2105  assign( tmp );
2106 }
2108 //*************************************************************************************************
2109 
2110 } // namespace blaze
2111 
2112 #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.
auto operator-=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Subtraction assignment operator for the subtraction of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:432
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for the subtraction trait.
size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:546
Header file for basic type definitions.
constexpr const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:750
Header file for the SparseVector base class.
Header file for the View base class.
Header file for the serial shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i....
Definition: Computation.h:81
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:595
Header file for the IsIntegral type trait.
Constraint on the data type.
constexpr bool IsReference_v
Auxiliary variable template for the IsReference type trait.The IsReference_v variable template provid...
Definition: IsReference.h:95
size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:584
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i....
Definition: TransExpr.h:81
Header file for the extended initializer_list functionality.
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
Constraint on the data type.
Header file for the DisableIf class template.
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the implementation of a vector representation of an initializer list.
decltype(auto) operator *(const DenseMatrix< MT1, false > &lhs, const DenseMatrix< MT2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:9091
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
auto operator+=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Addition assignment operator for the addition of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:370
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:138
#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:139
Constraint on the data type.
Header file for the exception macros of the math module.
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
Constraint on the data type.
Constraint on the data type.
auto operator/=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Division assignment operator for the division of a dense matrix by a scalar value ( ).
Definition: DenseMatrix.h:558
Header file for the IsConst type trait.
Header file for run time assertion macros.
Header file for the relaxation flag types.
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Header file for the Unique class template.
Check< false > Unchecked
Type of the blaze::unchecked instance.blaze::Unchecked is the type of the blaze::unchecked instance,...
Definition: Check.h:96
Header file for all forward declarations for expression class templates.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:808
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:81
Header file for the IsReference type trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type,...
Definition: DenseVector.h:61
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBVECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is a subvector type (i.e....
Definition: Subvector.h:81
Header file for the IsComputation type trait class.
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:264
Header file for the implementation of the ElementsData class template.
auto operator *=(DenseMatrix< MT, SO > &mat, ST scalar) -> EnableIf_t< IsNumeric_v< ST >, MT & >
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( ).
Definition: DenseMatrix.h:494
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.The IsIntegral_v variable template provides...
Definition: IsIntegral.h:95
typename DisableIf< Condition, T >::Type DisableIf_t
Auxiliary type for the DisableIf class template.The DisableIf_t alias declaration provides a convenie...
Definition: DisableIf.h:138
Header file for the IsRestricted type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:63
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
Header file for the IsExpression type trait class.