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  , size_t... 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_< IsExpression<VT>, VT, VT& >;
110  //**********************************************************************************************
111 
112  public:
113  //**Type definitions****************************************************************************
115  using This = Elements<VT,TF,false,CEAs...>;
116 
117  using BaseType = SparseVector<This,TF>;
118  using ViewedType = VT;
119  using ResultType = ElementsTrait_<VT,CEAs...>;
120  using TransposeType = TransposeType_<ResultType>;
121  using ElementType = ElementType_<VT>;
122  using ReturnType = ReturnType_<VT>;
123  using CompositeType = const Elements&;
124 
126  using ConstReference = ConstReference_<VT>;
127 
129  using Reference = If_< IsConst<VT>, ConstReference, Reference_<VT> >;
130  //**********************************************************************************************
131 
132  //**ElementsElement class definition************************************************************
135  template< typename IteratorType > // Type of the sparse vector iterator
136  class ElementsElement
137  : private SparseElement
138  {
139  public:
140  //**Constructor******************************************************************************
146  inline ElementsElement( IteratorType pos, size_t index )
147  : pos_ ( pos ) // Iterator to the current position within the element selection
148  , index_( index ) // Index within the according element selection
149  {}
150  //*******************************************************************************************
151 
152  //**Assignment operator**********************************************************************
158  template< typename T > inline ElementsElement& operator=( const T& v ) {
159  *pos_ = v;
160  return *this;
161  }
162  //*******************************************************************************************
163 
164  //**Addition assignment operator*************************************************************
170  template< typename T > inline ElementsElement& operator+=( const T& v ) {
171  *pos_ += v;
172  return *this;
173  }
174  //*******************************************************************************************
175 
176  //**Subtraction assignment operator**********************************************************
182  template< typename T > inline ElementsElement& operator-=( const T& v ) {
183  *pos_ -= v;
184  return *this;
185  }
186  //*******************************************************************************************
187 
188  //**Multiplication assignment operator*******************************************************
194  template< typename T > inline ElementsElement& operator*=( const T& v ) {
195  *pos_ *= v;
196  return *this;
197  }
198  //*******************************************************************************************
199 
200  //**Division assignment operator*************************************************************
206  template< typename T > inline ElementsElement& operator/=( const T& v ) {
207  *pos_ /= v;
208  return *this;
209  }
210  //*******************************************************************************************
211 
212  //**Element access operator******************************************************************
217  inline const ElementsElement* operator->() const {
218  return this;
219  }
220  //*******************************************************************************************
221 
222  //**Value function***************************************************************************
227  inline decltype(auto) value() const {
228  return pos_->value();
229  }
230  //*******************************************************************************************
231 
232  //**Index function***************************************************************************
237  inline size_t index() const {
238  return index_;
239  }
240  //*******************************************************************************************
241 
242  private:
243  //**Member variables*************************************************************************
244  IteratorType pos_;
245  size_t index_;
246  //*******************************************************************************************
247  };
248  //**********************************************************************************************
249 
250  //**ElementsIterator class definition***********************************************************
253  template< typename ET // Type of the element selection
254  , typename IteratorType > // Type of the sparse vector iterator
255  class ElementsIterator
256  {
257  public:
258  //**Type definitions*************************************************************************
259  using IteratorCategory = std::forward_iterator_tag;
260  using ValueType = ElementsElement<IteratorType>;
261  using PointerType = ValueType;
262  using ReferenceType = ValueType;
263  using DifferenceType = ptrdiff_t;
264 
265  // STL iterator requirements
266  using iterator_category = IteratorCategory;
267  using value_type = ValueType;
268  using pointer = PointerType;
269  using reference = ReferenceType;
270  using difference_type = DifferenceType;
271  //*******************************************************************************************
272 
273  //**Constructor******************************************************************************
276  inline ElementsIterator()
277  : elements_( nullptr ) // Pointer to the element selection
278  , index_ ( 0UL) // Index within the according element selection
279  , pos_ () // Iterator to the current position within the element selection
280  {}
281  //*******************************************************************************************
282 
283  //**Constructor******************************************************************************
289  inline ElementsIterator( ET* elements, size_t index )
290  : elements_( elements ) // Pointer to the element selection
291  , index_ ( index ) // Index within the according element selection
292  , pos_ () // Iterator to the current position within the element selection
293  {
294  for( ; index_<elements_->size(); ++index_ ) {
295  pos_ = elements_->operand().find( elements_->idx(index_) );
296  if( pos_ != elements_->operand().end() ) break;
297  }
298  }
299  //*******************************************************************************************
300 
301  //**Constructor******************************************************************************
308  inline ElementsIterator( ET* elements, size_t index, IteratorType pos )
309  : elements_( elements ) // Pointer to the element selection
310  , index_ ( index ) // Index within the according element selection
311  , pos_ ( pos ) // Iterator to the current position within the element selection
312  {}
313  //*******************************************************************************************
314 
315  //**Constructor******************************************************************************
320  template< typename ET2, typename IteratorType2 >
321  inline ElementsIterator( const ElementsIterator<ET2,IteratorType2>& it )
322  : elements_( it.elements_ ) // Pointer to the element selection
323  , index_ ( it.index_ ) // Index within the according element selection
324  , pos_ ( it.pos_ ) // Iterator to the current position within the element selection
325  {}
326  //*******************************************************************************************
327 
328  //**Prefix increment operator****************************************************************
333  inline ElementsIterator& operator++() {
334  ++index_;
335  for( ; index_<elements_->size(); ++index_ ) {
336  pos_ = elements_->operand().find( elements_->idx(index_) );
337  if( pos_ != elements_->operand().end() ) break;
338  }
339  return *this;
340  }
341  //*******************************************************************************************
342 
343  //**Postfix increment operator***************************************************************
348  inline const ElementsIterator operator++( int ) {
349  const ElementsIterator tmp( *this );
350  ++(*this);
351  return tmp;
352  }
353  //*******************************************************************************************
354 
355  //**Element access operator******************************************************************
360  inline ReferenceType operator*() const {
361  return ReferenceType( pos_, index_ );
362  }
363  //*******************************************************************************************
364 
365  //**Element access operator******************************************************************
370  inline PointerType operator->() const {
371  return PointerType( pos_, index_ );
372  }
373  //*******************************************************************************************
374 
375  //**Equality operator************************************************************************
381  inline bool operator==( const ElementsIterator& rhs ) const {
382  return index_ == rhs.index_;
383  }
384  //*******************************************************************************************
385 
386  //**Inequality operator**********************************************************************
392  inline bool operator!=( const ElementsIterator& rhs ) const {
393  return index_ != rhs.index_;
394  }
395  //*******************************************************************************************
396 
397  //**Subtraction operator*********************************************************************
403  inline DifferenceType operator-( const ElementsIterator& rhs ) const {
404  size_t counter( 0UL );
405  for( size_t j=rhs.index_; j<index_; ++j ) {
406  if( elements_->find( j ) != elements_->end() )
407  ++counter;
408  }
409  return counter;
410  }
411  //*******************************************************************************************
412 
413  private:
414  //**Member variables*************************************************************************
415  ET* elements_;
416  size_t index_;
417  IteratorType pos_;
418  //*******************************************************************************************
419 
420  //**Friend declarations**********************************************************************
421  template< typename VT2, bool TF2, bool DF2, size_t... CEAs2 > friend class Elements;
422  template< typename ET2, typename IteratorType2 > friend class ElementsIterator;
423  //*******************************************************************************************
424  };
425  //**********************************************************************************************
426 
427  //**Type definitions****************************************************************************
429  using ConstIterator = ElementsIterator< const This, ConstIterator_<VT> >;
430 
432  using Iterator = If_< IsConst<VT>, ConstIterator, ElementsIterator< This, Iterator_<VT> > >;
433  //**********************************************************************************************
434 
435  //**Compilation flags***************************************************************************
437  enum : bool { smpAssignable = false };
438  //**********************************************************************************************
439 
440  //**Constructors********************************************************************************
443  template< typename... REAs >
444  explicit inline Elements( VT& vector, REAs... args );
445 
446  inline Elements( const Elements& ) = default;
447  inline Elements( Elements&& ) = default;
449  //**********************************************************************************************
450 
451  //**Destructor**********************************************************************************
452  // No explicitly declared destructor.
453  //**********************************************************************************************
454 
455  //**Data access functions***********************************************************************
458  inline Reference operator[]( size_t index );
459  inline ConstReference operator[]( size_t index ) const;
460  inline Reference at( size_t index );
461  inline ConstReference at( size_t index ) const;
462  inline Iterator begin ();
463  inline ConstIterator begin () const;
464  inline ConstIterator cbegin() const;
465  inline Iterator end ();
466  inline ConstIterator end () const;
467  inline ConstIterator cend () const;
469  //**********************************************************************************************
470 
471  //**Assignment operators************************************************************************
474  inline Elements& operator= ( initializer_list<ElementType> list );
475  inline Elements& operator= ( const Elements& rhs );
476  template< typename VT2 > inline Elements& operator= ( const Vector<VT2,TF>& rhs );
477  template< typename VT2 > inline Elements& operator+=( const Vector<VT2,TF>& rhs );
478  template< typename VT2 > inline Elements& operator-=( const Vector<VT2,TF>& rhs );
479  template< typename VT2 > inline Elements& operator*=( const Vector<VT2,TF>& rhs );
480  template< typename VT2 > inline Elements& operator/=( const DenseVector<VT2,TF>& rhs );
481  template< typename VT2 > inline Elements& operator%=( const Vector<VT2,TF>& rhs );
483  //**********************************************************************************************
484 
485  //**Utility functions***************************************************************************
488  using DataType::idces;
489  using DataType::idx;
490  using DataType::size;
491 
492  inline VT& operand() noexcept;
493  inline const VT& operand() const noexcept;
494 
495  inline size_t capacity() const noexcept;
496  inline size_t nonZeros() const;
497  inline void reset();
498  inline void reserve( size_t n );
500  //**********************************************************************************************
501 
502  //**Insertion functions*************************************************************************
505  inline Iterator set ( size_t index, const ElementType& value );
506  inline Iterator insert( size_t index, const ElementType& value );
507  inline void append( size_t index, const ElementType& value, bool check=false );
509  //**********************************************************************************************
510 
511  //**Erase functions*****************************************************************************
514  inline void erase( size_t index );
515  inline Iterator erase( Iterator pos );
516  inline Iterator erase( Iterator first, Iterator last );
517 
518  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
519  inline void erase( Pred predicate );
520 
521  template< typename Pred >
522  inline void erase( Iterator first, Iterator last, Pred predicate );
524  //**********************************************************************************************
525 
526  //**Lookup functions****************************************************************************
529  inline Iterator find ( size_t index );
530  inline ConstIterator find ( size_t index ) const;
531  inline Iterator lowerBound( size_t index );
532  inline ConstIterator lowerBound( size_t index ) const;
533  inline Iterator upperBound( size_t index );
534  inline ConstIterator upperBound( size_t index ) const;
536  //**********************************************************************************************
537 
538  //**Numeric functions***************************************************************************
541  template< typename Other > inline Elements& scale( const Other& scalar );
543  //**********************************************************************************************
544 
545  //**Expression template evaluation functions****************************************************
548  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
549  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
550 
551  inline bool canSMPAssign() const noexcept;
552 
553  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
554  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
555  template< typename VT2 > inline void addAssign( const Vector<VT2,TF>& rhs );
556  template< typename VT2 > inline void subAssign( const Vector<VT2,TF>& rhs );
558  //**********************************************************************************************
559 
560  private:
561  //**Member variables****************************************************************************
564  Operand vector_;
565 
566  //**********************************************************************************************
567 
568  //**Compile time checks*************************************************************************
574  //**********************************************************************************************
575 };
577 //*************************************************************************************************
578 
579 
580 
581 
582 //=================================================================================================
583 //
584 // CONSTRUCTORS
585 //
586 //=================================================================================================
587 
588 //*************************************************************************************************
601 template< typename VT // Type of the sparse vector
602  , bool TF // Transpose flag
603  , size_t... CEAs > // Compile time element arguments
604 template< typename... REAs > // Optional arguments
605 inline Elements<VT,TF,false,CEAs...>::Elements( VT& vector, REAs... args )
606  : DataType( args... ) // Base class initialization
607  , vector_ ( vector ) // The vector containing the elements
608 {
609  if( !Contains< TypeList<REAs...>, Unchecked >::value ) {
610  for( size_t i=0UL; i<size(); ++i ) {
611  if( vector_.size() <= idx(i) ) {
612  BLAZE_THROW_INVALID_ARGUMENT( "Invalid element access index" );
613  }
614  }
615  }
616 }
618 //*************************************************************************************************
619 
620 
621 
622 
623 //=================================================================================================
624 //
625 // DATA ACCESS FUNCTIONS
626 //
627 //=================================================================================================
628 
629 //*************************************************************************************************
639 template< typename VT // Type of the sparse vector
640  , bool TF // Transpose flag
641  , size_t... CEAs > // Compile time element arguments
642 inline typename Elements<VT,TF,false,CEAs...>::Reference
643  Elements<VT,TF,false,CEAs...>::operator[]( size_t index )
644 {
645  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
646  return vector_[idx(index)];
647 }
649 //*************************************************************************************************
650 
651 
652 //*************************************************************************************************
662 template< typename VT // Type of the sparse vector
663  , bool TF // Transpose flag
664  , size_t... CEAs > // Compile time element arguments
665 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
666  Elements<VT,TF,false,CEAs...>::operator[]( size_t index ) const
667 {
668  BLAZE_USER_ASSERT( index < size(), "Invalid element access index" );
669  return const_cast<const VT&>( vector_ )[idx(index)];
670 }
672 //*************************************************************************************************
673 
674 
675 //*************************************************************************************************
686 template< typename VT // Type of the sparse vector
687  , bool TF // Transpose flag
688  , size_t... CEAs > // Compile time element arguments
689 inline typename Elements<VT,TF,false,CEAs...>::Reference
690  Elements<VT,TF,false,CEAs...>::at( size_t index )
691 {
692  if( index >= size() ) {
693  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
694  }
695  return (*this)[index];
696 }
698 //*************************************************************************************************
699 
700 
701 //*************************************************************************************************
712 template< typename VT // Type of the sparse vector
713  , bool TF // Transpose flag
714  , size_t... CEAs > // Compile time element arguments
715 inline typename Elements<VT,TF,false,CEAs...>::ConstReference
716  Elements<VT,TF,false,CEAs...>::at( size_t index ) const
717 {
718  if( index >= size() ) {
719  BLAZE_THROW_OUT_OF_RANGE( "Invalid element access index" );
720  }
721  return (*this)[index];
722 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
735 template< typename VT // Type of the sparse vector
736  , bool TF // Transpose flag
737  , size_t... CEAs > // Compile time element arguments
738 inline typename Elements<VT,TF,false,CEAs...>::Iterator
740 {
741  return Iterator( this, 0UL );
742 }
744 //*************************************************************************************************
745 
746 
747 //*************************************************************************************************
755 template< typename VT // Type of the sparse vector
756  , bool TF // Transpose flag
757  , size_t... CEAs > // Compile time element arguments
758 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
760 {
761  return ConstIterator( this, 0UL );
762 }
764 //*************************************************************************************************
765 
766 
767 //*************************************************************************************************
775 template< typename VT // Type of the sparse vector
776  , bool TF // Transpose flag
777  , size_t... CEAs > // Compile time element arguments
778 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
780 {
781  return ConstIterator( this, 0UL );
782 }
784 //*************************************************************************************************
785 
786 
787 //*************************************************************************************************
795 template< typename VT // Type of the sparse vector
796  , bool TF // Transpose flag
797  , size_t... CEAs > // Compile time element arguments
798 inline typename Elements<VT,TF,false,CEAs...>::Iterator
800 {
801  return Iterator( this, size() );
802 }
804 //*************************************************************************************************
805 
806 
807 //*************************************************************************************************
815 template< typename VT // Type of the sparse vector
816  , bool TF // Transpose flag
817  , size_t... CEAs > // Compile time element arguments
818 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
820 {
821  return ConstIterator( this, size() );
822 }
824 //*************************************************************************************************
825 
826 
827 //*************************************************************************************************
835 template< typename VT // Type of the sparse vector
836  , bool TF // Transpose flag
837  , size_t... CEAs > // Compile time element arguments
838 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
840 {
841  return ConstIterator( this, size() );
842 }
844 //*************************************************************************************************
845 
846 
847 
848 
849 //=================================================================================================
850 //
851 // ASSIGNMENT OPERATORS
852 //
853 //=================================================================================================
854 
855 //*************************************************************************************************
871 template< typename VT // Type of the sparse vector
872  , bool TF // Transpose flag
873  , size_t... CEAs > // Compile time element arguments
874 inline Elements<VT,TF,false,CEAs...>&
875  Elements<VT,TF,false,CEAs...>::operator=( initializer_list<ElementType> list )
876 {
877  using blaze::assign;
878 
879  if( list.size() > size() ) {
880  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to elements" );
881  }
882 
883  const InitializerVector<ElementType,TF> tmp( list, size() );
884 
885  if( IsRestricted<VT>::value ) {
886  for( size_t i=0UL; i<size(); ++i ) {
887  if( !trySet( vector_, idx(i), tmp[i] ) ) {
888  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
889  }
890  }
891  }
892 
893  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
894 
895  assign( left, tmp );
896 
897  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
898 
899  return *this;
900 }
902 //*************************************************************************************************
903 
904 
905 //*************************************************************************************************
917 template< typename VT // Type of the sparse vector
918  , bool TF // Transpose flag
919  , size_t... CEAs > // Compile time element arguments
920 inline Elements<VT,TF,false,CEAs...>&
921  Elements<VT,TF,false,CEAs...>::operator=( const Elements& rhs )
922 {
923  using blaze::assign;
924 
927 
928  if( &rhs == this || ( &vector_ == &rhs.vector_ && idces() == rhs.idces() ) )
929  return *this;
930 
931  if( size() != rhs.size() ) {
932  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
933  }
934 
935  if( IsRestricted<VT>::value ) {
936  for( size_t i=0UL; i<size(); ++i ) {
937  if( !trySet( vector_, idx(i), rhs[i] ) ) {
938  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
939  }
940  }
941  }
942 
943  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
944 
945  if( rhs.canAlias( &vector_ ) ) {
946  const ResultType tmp( rhs );
947  assign( left, tmp );
948  }
949  else {
950  assign( left, rhs );
951  }
952 
953  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
954 
955  return *this;
956 }
958 //*************************************************************************************************
959 
960 
961 //*************************************************************************************************
973 template< typename VT // Type of the sparse vector
974  , bool TF // Transpose flag
975  , size_t... CEAs > // Compile time element arguments
976 template< typename VT2 > // Type of the right-hand side vector
977 inline Elements<VT,TF,false,CEAs...>&
978  Elements<VT,TF,false,CEAs...>::operator=( const Vector<VT2,TF>& rhs )
979 {
980  using blaze::assign;
981 
984 
985  if( size() != (~rhs).size() ) {
986  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
987  }
988 
989  using Right = If_< IsRestricted<VT>, CompositeType_<VT2>, const VT2& >;
990  Right right( ~rhs );
991 
992  if( IsRestricted<VT>::value ) {
993  for( size_t i=0UL; i<size(); ++i ) {
994  if( !trySet( vector_, idx(i), right[i] ) ) {
995  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
996  }
997  }
998  }
999 
1000  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1001 
1002  if( IsReference<Right>::value || right.canAlias( &vector_ ) ) {
1003  const ResultType_<VT2> tmp( right );
1004  assign( left, tmp );
1005  }
1006  else {
1007  assign( left, right );
1008  }
1009 
1010  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1011 
1012  return *this;
1013 }
1015 //*************************************************************************************************
1016 
1017 
1018 //*************************************************************************************************
1030 template< typename VT // Type of the sparse vector
1031  , bool TF // Transpose flag
1032  , size_t... CEAs > // Compile time element arguments
1033 template< typename VT2 > // Type of the right-hand side vector
1034 inline Elements<VT,TF,false,CEAs...>&
1035  Elements<VT,TF,false,CEAs...>::operator+=( const Vector<VT2,TF>& rhs )
1036 {
1037  using blaze::addAssign;
1038 
1041 
1042  if( size() != (~rhs).size() ) {
1043  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1044  }
1045 
1046  using Right = If_< IsRestricted<VT>, CompositeType_<VT2>, const VT2& >;
1047  Right right( ~rhs );
1048 
1049  if( IsRestricted<VT>::value ) {
1050  for( size_t i=0UL; i<size(); ++i ) {
1051  if( !tryAdd( vector_, idx(i), right[i] ) ) {
1052  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1053  }
1054  }
1055  }
1056 
1057  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1058 
1059  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1060  const ResultType_<VT2> tmp( right );
1061  addAssign( left, tmp );
1062  }
1063  else {
1064  addAssign( left, right );
1065  }
1066 
1067  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1068 
1069  return *this;
1070 }
1072 //*************************************************************************************************
1073 
1074 
1075 //*************************************************************************************************
1087 template< typename VT // Type of the sparse vector
1088  , bool TF // Transpose flag
1089  , size_t... CEAs > // Compile time element arguments
1090 template< typename VT2 > // Type of the right-hand side vector
1091 inline Elements<VT,TF,false,CEAs...>&
1092  Elements<VT,TF,false,CEAs...>::operator-=( const Vector<VT2,TF>& rhs )
1093 {
1094  using blaze::subAssign;
1095 
1098 
1099  if( size() != (~rhs).size() ) {
1100  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1101  }
1102 
1103  using Right = If_< IsRestricted<VT>, CompositeType_<VT2>, const VT2& >;
1104  Right right( ~rhs );
1105 
1106  if( IsRestricted<VT>::value ) {
1107  for( size_t i=0UL; i<size(); ++i ) {
1108  if( !trySub( vector_, idx(i), right[i] ) ) {
1109  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1110  }
1111  }
1112  }
1113 
1114  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1115 
1116  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1117  const ResultType_<VT2> tmp( right );
1118  subAssign( left, tmp );
1119  }
1120  else {
1121  subAssign( left, right );
1122  }
1123 
1124  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1125 
1126  return *this;
1127 }
1129 //*************************************************************************************************
1130 
1131 
1132 //*************************************************************************************************
1145 template< typename VT // Type of the sparse vector
1146  , bool TF // Transpose flag
1147  , size_t... CEAs > // Compile time element arguments
1148 template< typename VT2 > // Type of the right-hand side vector
1149 inline Elements<VT,TF,false,CEAs...>&
1150  Elements<VT,TF,false,CEAs...>::operator*=( const Vector<VT2,TF>& rhs )
1151 {
1152  using blaze::assign;
1153 
1157 
1158  using MultType = MultTrait_< ResultType, ResultType_<VT2> >;
1159 
1162 
1163  if( size() != (~rhs).size() ) {
1164  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1165  }
1166 
1167  const MultType tmp( *this * (~rhs) );
1168 
1169  if( IsRestricted<VT>::value ) {
1170  for( size_t i=0UL; i<size(); ++i ) {
1171  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1172  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1173  }
1174  }
1175  }
1176 
1177  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1178 
1179  assign( left, tmp );
1180 
1181  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1182 
1183  return *this;
1184 }
1186 //*************************************************************************************************
1187 
1188 
1189 //*************************************************************************************************
1201 template< typename VT // Type of the sparse vector
1202  , bool TF // Transpose flag
1203  , size_t... CEAs > // Compile time element arguments
1204 template< typename VT2 > // Type of the right-hand side dense vector
1205 inline Elements<VT,TF,false,CEAs...>&
1206  Elements<VT,TF,false,CEAs...>::operator/=( const DenseVector<VT2,TF>& rhs )
1207 {
1208  using blaze::assign;
1209 
1212  BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE ( ResultType_<VT2> );
1214 
1215  using DivType = DivTrait_< ResultType, ResultType_<VT2> >;
1216 
1220 
1221  if( size() != (~rhs).size() ) {
1222  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1223  }
1224 
1225  const DivType tmp( *this / (~rhs) );
1226 
1227  if( IsRestricted<VT>::value ) {
1228  for( size_t i=0UL; i<size(); ++i ) {
1229  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1230  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1231  }
1232  }
1233  }
1234 
1235  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1236 
1237  assign( left, tmp );
1238 
1239  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1240 
1241  return *this;
1242 }
1244 //*************************************************************************************************
1245 
1246 
1247 //*************************************************************************************************
1260 template< typename VT // Type of the sparse vector
1261  , bool TF // Transpose flag
1262  , size_t... CEAs > // Compile time element arguments
1263 template< typename VT2 > // Type of the right-hand side vector
1264 inline Elements<VT,TF,false,CEAs...>&
1265  Elements<VT,TF,false,CEAs...>::operator%=( const Vector<VT2,TF>& rhs )
1266 {
1267  using blaze::assign;
1268 
1271 
1272  using CrossType = CrossTrait_< ResultType, ResultType_<VT2> >;
1273 
1277 
1278  if( size() != 3UL || (~rhs).size() != 3UL ) {
1279  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1280  }
1281 
1282  const CrossType tmp( *this % (~rhs) );
1283 
1284  if( IsRestricted<VT>::value ) {
1285  for( size_t i=0UL; i<size(); ++i ) {
1286  if( !trySet( vector_, idx(i), tmp[i] ) ) {
1287  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1288  }
1289  }
1290  }
1291 
1292  BLAZE_DECLTYPE_AUTO( left, derestrict( *this ) );
1293 
1294  assign( left, tmp );
1295 
1296  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1297 
1298  return *this;
1299 }
1301 //*************************************************************************************************
1302 
1303 
1304 
1305 
1306 //=================================================================================================
1307 //
1308 // UTILITY FUNCTIONS
1309 //
1310 //=================================================================================================
1311 
1312 //*************************************************************************************************
1318 template< typename VT // Type of the sparse vector
1319  , bool TF // Transpose flag
1320  , size_t... CEAs > // Compile time element arguments
1321 inline VT& Elements<VT,TF,false,CEAs...>::operand() noexcept
1322 {
1323  return vector_;
1324 }
1326 //*************************************************************************************************
1327 
1328 
1329 //*************************************************************************************************
1335 template< typename VT // Type of the sparse vector
1336  , bool TF // Transpose flag
1337  , size_t... CEAs > // Compile time element arguments
1338 inline const VT& Elements<VT,TF,false,CEAs...>::operand() const noexcept
1339 {
1340  return vector_;
1341 }
1343 //*************************************************************************************************
1344 
1345 
1346 //*************************************************************************************************
1352 template< typename VT // Type of the sparse vector
1353  , bool TF // Transpose flag
1354  , size_t... CEAs > // Compile time element arguments
1355 inline size_t Elements<VT,TF,false,CEAs...>::capacity() const noexcept
1356 {
1357  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1358 }
1360 //*************************************************************************************************
1361 
1362 
1363 //*************************************************************************************************
1372 template< typename VT // Type of the sparse vector
1373  , bool TF // Transpose flag
1374  , size_t... CEAs > // Compile time element arguments
1375 inline size_t Elements<VT,TF,false,CEAs...>::nonZeros() const
1376 {
1377  size_t counter( 0UL );
1378  for( ConstIterator element=begin(); element!=end(); ++element ) {
1379  ++counter;
1380  }
1381  return counter;
1382 }
1384 //*************************************************************************************************
1385 
1386 
1387 //*************************************************************************************************
1393 template< typename VT // Type of the sparse vector
1394  , bool TF // Transpose flag
1395  , size_t... CEAs > // Compile time element arguments
1397 {
1398  for( size_t i=0UL; i<size(); ++i )
1399  vector_.erase( idx(i) );
1400 }
1402 //*************************************************************************************************
1403 
1404 
1405 //*************************************************************************************************
1415 template< typename VT // Type of the sparse vector
1416  , bool TF // Transpose flag
1417  , size_t... CEAs > // Compile time element arguments
1418 void Elements<VT,TF,false,CEAs...>::reserve( size_t n )
1419 {
1420  const size_t current( capacity() );
1421 
1422  if( n > current ) {
1423  vector_.reserve( vector_.capacity() + n - current );
1424  }
1425 }
1427 //*************************************************************************************************
1428 
1429 
1430 
1431 
1432 //=================================================================================================
1433 //
1434 // INSERTION FUNCTIONS
1435 //
1436 //=================================================================================================
1437 
1438 //*************************************************************************************************
1450 template< typename VT // Type of the sparse vector
1451  , bool TF // Transpose flag
1452  , size_t... CEAs > // Compile time element arguments
1453 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1454  Elements<VT,TF,false,CEAs...>::set( size_t index, const ElementType& value )
1455 {
1456  return Iterator( this, index, vector_.set( idx(index), value ) );
1457 }
1459 //*************************************************************************************************
1460 
1461 
1462 //*************************************************************************************************
1475 template< typename VT // Type of the sparse vector
1476  , bool TF // Transpose flag
1477  , size_t... CEAs > // Compile time element arguments
1478 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1479  Elements<VT,TF,false,CEAs...>::insert( size_t index, const ElementType& value )
1480 {
1481  return Iterator( this, index, vector_.insert( idx(index), value ) );
1482 }
1484 //*************************************************************************************************
1485 
1486 
1487 //*************************************************************************************************
1512 template< typename VT // Type of the sparse vector
1513  , bool TF // Transpose flag
1514  , size_t... CEAs > // Compile time element arguments
1515 inline void Elements<VT,TF,false,CEAs...>::append( size_t index, const ElementType& value, bool check )
1516 {
1517  if( !check || !isDefault<strict>( value ) )
1518  vector_.insert( idx(index), value );
1519 }
1521 //*************************************************************************************************
1522 
1523 
1524 
1525 
1526 //=================================================================================================
1527 //
1528 // ERASE FUNCTIONS
1529 //
1530 //=================================================================================================
1531 
1532 //*************************************************************************************************
1541 template< typename VT // Type of the sparse vector
1542  , bool TF // Transpose flag
1543  , size_t... CEAs > // Compile time element arguments
1544 inline void Elements<VT,TF,false,CEAs...>::erase( size_t index )
1545 {
1546  vector_.erase( idx(index) );
1547 }
1549 //*************************************************************************************************
1550 
1551 
1552 //*************************************************************************************************
1561 template< typename VT // Type of the sparse vector
1562  , bool TF // Transpose flag
1563  , size_t... CEAs > // Compile time element arguments
1564 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1565  Elements<VT,TF,false,CEAs...>::erase( Iterator pos )
1566 {
1567  const size_t index( pos.index_ );
1568 
1569  if( index == size() )
1570  return pos;
1571 
1572  vector_.erase( pos.pos_ );
1573  return Iterator( this, index+1UL );
1574 }
1576 //*************************************************************************************************
1577 
1578 
1579 //*************************************************************************************************
1589 template< typename VT // Type of the sparse vector
1590  , bool TF // Transpose flag
1591  , size_t... CEAs > // Compile time element arguments
1592 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1593  Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last )
1594 {
1595  for( ; first!=last; ++first ) {
1596  vector_.erase( first.pos_ );
1597  }
1598 
1599  return Iterator( this, last.index_ );
1600 }
1602 //*************************************************************************************************
1603 
1604 
1605 //*************************************************************************************************
1628 template< typename VT // Type of the sparse vector
1629  , bool TF // Transpose flag
1630  , size_t... CEAs > // Compile time element arguments
1631 template< typename Pred // Type of the unary predicate
1632  , typename > // Type restriction on the unary predicate
1633 inline void Elements<VT,TF,false,CEAs...>::erase( Pred predicate )
1634 {
1635  erase( begin(), end(), predicate );
1636 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1667 template< typename VT // Type of the sparse vector
1668  , bool TF // Transpose flag
1669  , size_t... CEAs > // Compile time element arguments
1670 template< typename Pred > // Type of the unary predicate
1671 inline void Elements<VT,TF,false,CEAs...>::erase( Iterator first, Iterator last, Pred predicate )
1672 {
1673  for( ; first!=last; ++first ) {
1674  if( predicate( first->value() ) )
1675  vector_.erase( first.pos_ );
1676  }
1677 }
1679 //*************************************************************************************************
1680 
1681 
1682 
1683 
1684 //=================================================================================================
1685 //
1686 // LOOKUP FUNCTIONS
1687 //
1688 //=================================================================================================
1689 
1690 //*************************************************************************************************
1704 template< typename VT // Type of the sparse vector
1705  , bool TF // Transpose flag
1706  , size_t... CEAs > // Compile time element arguments
1707 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1708  Elements<VT,TF,false,CEAs...>::find( size_t index )
1709 {
1710  const Iterator_<VT> pos( vector_.find( idx(index) ) );
1711 
1712  if( pos != vector_.end() )
1713  return Iterator( this, index, pos );
1714  else
1715  return end();
1716 }
1718 //*************************************************************************************************
1719 
1720 
1721 //*************************************************************************************************
1735 template< typename VT // Type of the sparse vector
1736  , bool TF // Transpose flag
1737  , size_t... CEAs > // Compile time element arguments
1738 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1739  Elements<VT,TF,false,CEAs...>::find( size_t index ) const
1740 {
1741  const ConstIterator_<VT> pos( vector_.find( idx(index) ) );
1742 
1743  if( pos != vector_.end() )
1744  return ConstIterator( this, index, pos );
1745  else
1746  return end();
1747 }
1749 //*************************************************************************************************
1750 
1751 
1752 //*************************************************************************************************
1765 template< typename VT // Type of the sparse vector
1766  , bool TF // Transpose flag
1767  , size_t... CEAs > // Compile time element arguments
1768 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1769  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index )
1770 {
1771  for( ; index<size(); ++index ) {
1772  const Iterator_<VT> pos( vector_.find( idx(index) ) );
1773  if( pos != vector_.end() )
1774  return Iterator( this, index, pos );
1775  }
1776  return end();
1777 }
1779 //*************************************************************************************************
1780 
1781 
1782 //*************************************************************************************************
1795 template< typename VT // Type of the sparse vector
1796  , bool TF // Transpose flag
1797  , size_t... CEAs > // Compile time element arguments
1798 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1799  Elements<VT,TF,false,CEAs...>::lowerBound( size_t index ) const
1800 {
1801  for( ; index<size(); ++index ) {
1802  const ConstIterator_<VT> pos( vector_.find( idx(index) ) );
1803  if( pos != vector_.end() )
1804  return ConstIterator( this, index, pos );
1805  }
1806  return end();
1807 }
1809 //*************************************************************************************************
1810 
1811 
1812 //*************************************************************************************************
1825 template< typename VT // Type of the sparse vector
1826  , bool TF // Transpose flag
1827  , size_t... CEAs > // Compile time element arguments
1828 inline typename Elements<VT,TF,false,CEAs...>::Iterator
1829  Elements<VT,TF,false,CEAs...>::upperBound( size_t index )
1830 {
1831  while( (++index) < size() ) {
1832  const Iterator_<VT> pos( vector_.find( idx(index) ) );
1833  if( pos != vector_.end() )
1834  return Iterator( this, index, pos );
1835  }
1836  return end();
1837 }
1839 //*************************************************************************************************
1840 
1841 
1842 //*************************************************************************************************
1855 template< typename VT // Type of the sparse vector
1856  , bool TF // Transpose flag
1857  , size_t... CEAs > // Compile time element arguments
1858 inline typename Elements<VT,TF,false,CEAs...>::ConstIterator
1859  Elements<VT,TF,false,CEAs...>::upperBound( size_t index ) const
1860 {
1861  while( (++index) < size() ) {
1862  const ConstIterator_<VT> pos( vector_.find( idx(index) ) );
1863  if( pos != vector_.end() )
1864  return ConstIterator( this, index, pos );
1865  }
1866  return end();
1867 }
1869 //*************************************************************************************************
1870 
1871 
1872 
1873 
1874 //=================================================================================================
1875 //
1876 // NUMERIC FUNCTIONS
1877 //
1878 //=================================================================================================
1879 
1880 //*************************************************************************************************
1891 template< typename VT // Type of the sparse vector
1892  , bool TF // Transpose flag
1893  , size_t... CEAs > // Compile time element arguments
1894 template< typename Other > // Data type of the scalar value
1895 inline Elements<VT,TF,false,CEAs...>&
1896  Elements<VT,TF,false,CEAs...>::scale( const Other& scalar )
1897 {
1898  for( Iterator element=begin(); element!=end(); ++element )
1899  element->value() *= scalar;
1900  return *this;
1901 }
1903 //*************************************************************************************************
1904 
1905 
1906 
1907 
1908 //=================================================================================================
1909 //
1910 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1911 //
1912 //=================================================================================================
1913 
1914 //*************************************************************************************************
1925 template< typename VT // Type of the sparse vector
1926  , bool TF // Transpose flag
1927  , size_t... CEAs > // Compile time element arguments
1928 template< typename Other > // Data type of the foreign expression
1929 inline bool Elements<VT,TF,false,CEAs...>::canAlias( const Other* alias ) const noexcept
1930 {
1931  return vector_.isAliased( alias );
1932 }
1934 //*************************************************************************************************
1935 
1936 
1937 //*************************************************************************************************
1948 template< typename VT // Type of the sparse vector
1949  , bool TF // Transpose flag
1950  , size_t... CEAs > // Compile time element arguments
1951 template< typename Other > // Data type of the foreign expression
1952 inline bool Elements<VT,TF,false,CEAs...>::isAliased( const Other* alias ) const noexcept
1953 {
1954  return vector_.isAliased( alias );
1955 }
1957 //*************************************************************************************************
1958 
1959 
1960 //*************************************************************************************************
1972 template< typename VT // Type of the sparse vector
1973  , bool TF // Transpose flag
1974  , size_t... CEAs > // Compile time element arguments
1975 template< typename VT2 > // Type of the right-hand side dense vector
1976 inline void Elements<VT,TF,false,CEAs...>::assign( const DenseVector<VT2,TF>& rhs )
1977 {
1978  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1979 
1980  using RT = If_< IsComputation<VT2>, ElementType_<VT>, const ElementType_<VT2>& >;
1981 
1982  reserve( (~rhs).size() );
1983 
1984  for( size_t i=0UL; i<size(); ++i ) {
1985  RT value( (~rhs)[i] );
1986  if( !isDefault<strict>( value ) )
1987  vector_.set( idx(i), std::move( value ) );
1988  else vector_.erase( idx(i) );
1989  }
1990 }
1992 //*************************************************************************************************
1993 
1994 
1995 //*************************************************************************************************
2007 template< typename VT // Type of the sparse vector
2008  , bool TF // Transpose flag
2009  , size_t... CEAs > // Compile time element arguments
2010 template< typename VT2 > // Type of the right-hand side sparse vector
2011 inline void Elements<VT,TF,false,CEAs...>::assign( const SparseVector<VT2,TF>& rhs )
2012 {
2013  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2014 
2015  using RT = If_< IsComputation<VT2>, ElementType_<VT>, const ElementType_<VT2>& >;
2016 
2017  size_t i( 0UL );
2018 
2019  for( ConstIterator_<VT2> element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2020  for( ; i<element->index(); ++i )
2021  vector_.erase( idx(i) );
2022  RT value( element->value() );
2023  if( !isDefault<strict>( value ) )
2024  vector_.set( idx(i), std::move( value ) );
2025  else vector_.erase( idx(i) );
2026  ++i;
2027  }
2028  for( ; i<size(); ++i ) {
2029  vector_.erase( idx(i) );
2030  }
2031 }
2033 //*************************************************************************************************
2034 
2035 
2036 //*************************************************************************************************
2048 template< typename VT // Type of the sparse vector
2049  , bool TF // Transpose flag
2050  , size_t... CEAs > // Compile time element arguments
2051 template< typename VT2 > // Type of the right-hand side vector
2052 inline void Elements<VT,TF,false,CEAs...>::addAssign( const Vector<VT2,TF>& rhs )
2053 {
2054  using AddType = AddTrait_< ResultType, ResultType_<VT2> >;
2055 
2058 
2059  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2060 
2061  const AddType tmp( serial( *this + (~rhs) ) );
2062  assign( tmp );
2063 }
2065 //*************************************************************************************************
2066 
2067 
2068 //*************************************************************************************************
2080 template< typename VT // Type of the sparse vector
2081  , bool TF // Transpose flag
2082  , size_t... CEAs > // Compile time element arguments
2083 template< typename VT2 > // Type of the right-hand side vector
2084 inline void Elements<VT,TF,false,CEAs...>::subAssign( const Vector<VT2,TF>& rhs )
2085 {
2086  using SubType = SubTrait_< ResultType, ResultType_<VT2> >;
2087 
2090 
2091  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2092 
2093  const SubType tmp( serial( *this - (~rhs) ) );
2094  assign( tmp );
2095 }
2097 //*************************************************************************************************
2098 
2099 } // namespace blaze
2100 
2101 #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
Header file for the subtraction trait.
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix) noexcept
Returns the maximum capacity of the matrix.
Definition: Matrix.h:522
Header file for basic type definitions.
Header file for the SparseVector base class.
Header file for the View base class.
Header file for the serial shim.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
#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:3076
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:364
CompressedMatrix< Type, true > This
Type of this CompressedMatrix instance.
Definition: CompressedMatrix.h:3074
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:588
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:224
Header file for the IsIntegral type trait.
CompressedMatrix< Type, false > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:3078
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:3083
Constraint on the data type.
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:560
Header file for the decltype(auto) workaround.
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:733
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:3084
typename ElementsTrait< VT, CEAs... >::Type ElementsTrait_
Auxiliary alias declaration for the ElementsTrait type trait.The ElementsTrait_ alias declaration pro...
Definition: ElementsTrait.h:144
#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.
BLAZE_ALWAYS_INLINE MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:474
BLAZE_ALWAYS_INLINE MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:408
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:3082
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:3075
Type ElementType
Type of the compressed matrix elements.
Definition: CompressedMatrix.h:3079
#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:3085
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
#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:134
Constraint on the data type.
Header file for the exception macros of the math module.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:430
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:8893
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:290
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:76
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
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:816
#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:3080
#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
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
Header file for the IsComputation type trait class.
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:3081
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
Header file for the implementation of the ElementsData class template.
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
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
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.