CompressedVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <utility>
45 #include <blaze/math/Aliases.h>
49 #include <blaze/math/Exception.h>
52 #include <blaze/math/Forward.h>
75 #include <blaze/util/Assert.h>
81 #include <blaze/util/DisableIf.h>
82 #include <blaze/util/EnableIf.h>
83 #include <blaze/util/Memory.h>
84 #include <blaze/util/mpl/And.h>
85 #include <blaze/util/mpl/If.h>
86 #include <blaze/util/mpl/Not.h>
87 #include <blaze/util/Types.h>
91 
92 
93 namespace blaze {
94 
95 //=================================================================================================
96 //
97 // CLASS DEFINITION
98 //
99 //=================================================================================================
100 
101 //*************************************************************************************************
195 template< typename Type // Data type of the vector
196  , bool TF = defaultTransposeFlag > // Transpose flag
198  : public SparseVector< CompressedVector<Type,TF>, TF >
199 {
200  private:
201  //**Type definitions****************************************************************************
204  //**********************************************************************************************
205 
206  //**Private class Element***********************************************************************
213  struct Element
214  : public ElementBase
215  {
216  //**Constructors*****************************************************************************
217  explicit Element() = default;
218  Element( const Element& rhs ) = default;
219  Element( Element&& rhs ) = default;
220  //*******************************************************************************************
221 
222  //**Assignment operators*********************************************************************
223  inline Element& operator=( const Element& rhs )
224  {
225  this->value_ = rhs.value_;
226  return *this;
227  }
228 
229  inline Element& operator=( Element&& rhs )
230  {
231  this->value_ = std::move( rhs.value_ );
232  return *this;
233  }
234 
235  template< typename Other >
236  inline EnableIf_< IsSparseElement<Other>, Element& >
237  operator=( const Other& rhs )
238  {
239  this->value_ = rhs.value();
240  return *this;
241  }
242 
243  template< typename Other >
245  , IsRValueReference<Other&&> >, Element& >
246  operator=( Other&& rhs )
247  {
248  this->value_ = std::move( rhs.value() );
249  return *this;
250  }
251 
252  template< typename Other >
253  inline EnableIf_< Not< IsSparseElement<Other> >, Element& >
254  operator=( const Other& v )
255  {
256  this->value_ = v;
257  return *this;
258  }
259 
260  template< typename Other >
262  , IsRValueReference<Other&&> >, Element& >
263  operator=( Other&& v )
264  {
265  this->value_ = std::move( v );
266  return *this;
267  }
268  //*******************************************************************************************
269 
270  //**Friend declarations**********************************************************************
271  friend class CompressedVector;
272  //*******************************************************************************************
273  };
275  //**********************************************************************************************
276 
277  public:
278  //**Type definitions****************************************************************************
281  using ResultType = This;
283  using ElementType = Type;
284  using ReturnType = const Type&;
287  using ConstReference = const Type&;
288  using Iterator = Element*;
289  using ConstIterator = const Element*;
290  //**********************************************************************************************
291 
292  //**Rebind struct definition********************************************************************
295  template< typename NewType > // Data type of the other vector
296  struct Rebind {
298  };
299  //**********************************************************************************************
300 
301  //**Resize struct definition********************************************************************
304  template< size_t NewN > // Number of elements of the other vector
305  struct Resize {
307  };
308  //**********************************************************************************************
309 
310  //**Compilation flags***************************************************************************
312 
315  enum : bool { smpAssignable = !IsSMPAssignable<Type>::value };
316  //**********************************************************************************************
317 
318  //**Constructors********************************************************************************
321  explicit inline CompressedVector() noexcept;
322  explicit inline CompressedVector( size_t size ) noexcept;
323  explicit inline CompressedVector( size_t size, size_t nonzeros );
324  inline CompressedVector( const CompressedVector& sv );
325  inline CompressedVector( CompressedVector&& sv ) noexcept;
326  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
327  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
329  //**********************************************************************************************
330 
331  //**Destructor**********************************************************************************
334  inline ~CompressedVector();
336  //**********************************************************************************************
337 
338  //**Data access functions***********************************************************************
341  inline Reference operator[]( size_t index ) noexcept;
342  inline ConstReference operator[]( size_t index ) const noexcept;
343  inline Reference at( size_t index );
344  inline ConstReference at( size_t index ) const;
345  inline Iterator begin () noexcept;
346  inline ConstIterator begin () const noexcept;
347  inline ConstIterator cbegin() const noexcept;
348  inline Iterator end () noexcept;
349  inline ConstIterator end () const noexcept;
350  inline ConstIterator cend () const noexcept;
352  //**********************************************************************************************
353 
354  //**Assignment operators************************************************************************
357  inline CompressedVector& operator=( const CompressedVector& rhs );
358  inline CompressedVector& operator=( CompressedVector&& rhs ) noexcept;
359 
360  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
361  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
362  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
363  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
364  template< typename VT > inline CompressedVector& operator*=( const DenseVector<VT,TF>& rhs );
365  template< typename VT > inline CompressedVector& operator*=( const SparseVector<VT,TF>& rhs );
366  template< typename VT > inline CompressedVector& operator/=( const DenseVector<VT,TF>& rhs );
367  template< typename VT > inline CompressedVector& operator%=( const Vector<VT,TF>& rhs );
368 
369  template< typename Other >
370  inline EnableIf_< IsNumeric<Other>, CompressedVector >& operator*=( Other rhs );
371 
372  template< typename Other >
373  inline EnableIf_< IsNumeric<Other>, CompressedVector >& operator/=( Other rhs );
375  //**********************************************************************************************
376 
377  //**Utility functions***************************************************************************
380  inline size_t size() const noexcept;
381  inline size_t capacity() const noexcept;
382  inline size_t nonZeros() const;
383  inline void reset();
384  inline void clear();
385  inline void resize( size_t n, bool preserve=true );
386  void reserve( size_t n );
387  inline void shrinkToFit();
388  inline void swap( CompressedVector& sv ) noexcept;
390  //**********************************************************************************************
391 
392  //**Insertion functions*************************************************************************
395  inline Iterator set ( size_t index, const Type& value );
396  inline Iterator insert( size_t index, const Type& value );
397  inline void append( size_t index, const Type& value, bool check=false );
399  //**********************************************************************************************
400 
401  //**Erase functions*****************************************************************************
404  inline void erase( size_t index );
405  inline Iterator erase( Iterator pos );
406  inline Iterator erase( Iterator first, Iterator last );
407 
408  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
409  inline void erase( Pred predicate );
410 
411  template< typename Pred >
412  inline void erase( Iterator first, Iterator last, Pred predicate );
414  //**********************************************************************************************
415 
416  //**Lookup functions****************************************************************************
419  inline Iterator find ( size_t index );
420  inline ConstIterator find ( size_t index ) const;
421  inline Iterator lowerBound( size_t index );
422  inline ConstIterator lowerBound( size_t index ) const;
423  inline Iterator upperBound( size_t index );
424  inline ConstIterator upperBound( size_t index ) const;
426  //**********************************************************************************************
427 
428  //**Numeric functions***************************************************************************
431  template< typename Other > inline CompressedVector& scale( const Other& scalar );
433  //**********************************************************************************************
434 
435  //**Expression template evaluation functions****************************************************
438  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
439  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
440 
441  inline bool canSMPAssign() const noexcept;
442 
443  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
444  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
445  template< typename VT > inline void addAssign ( const DenseVector <VT,TF>& rhs );
446  template< typename VT > inline void addAssign ( const SparseVector<VT,TF>& rhs );
447  template< typename VT > inline void subAssign ( const DenseVector <VT,TF>& rhs );
448  template< typename VT > inline void subAssign ( const SparseVector<VT,TF>& rhs );
449  template< typename VT > inline void multAssign( const DenseVector <VT,TF>& rhs );
450  template< typename VT > inline void divAssign ( const DenseVector <VT,TF>& rhs );
452  //**********************************************************************************************
453 
454  private:
455  //**Utility functions***************************************************************************
458  inline size_t extendCapacity() const noexcept;
459  inline Iterator castDown( IteratorBase it ) const noexcept;
460  inline IteratorBase castUp ( Iterator it ) const noexcept;
462  //**********************************************************************************************
463 
464  //**Insertion functions***************************************************************************
467  Iterator insert( Iterator pos, size_t index, const Type& value );
469  //**********************************************************************************************
470 
471  //**Member variables****************************************************************************
474  size_t size_;
475  size_t capacity_;
478 
479  static const Type zero_;
480 
481  //**********************************************************************************************
482 
483  //**Compile time checks*************************************************************************
491  //**********************************************************************************************
492 };
493 //*************************************************************************************************
494 
495 
496 
497 
498 //=================================================================================================
499 //
500 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
501 //
502 //=================================================================================================
503 
504 template< typename Type // Data type of the vector
505  , bool TF > // Transpose flag
506 const Type CompressedVector<Type,TF>::zero_ = Type();
507 
508 
509 
510 
511 //=================================================================================================
512 //
513 // CONSTRUCTORS
514 //
515 //=================================================================================================
516 
517 //*************************************************************************************************
520 template< typename Type // Data type of the vector
521  , bool TF > // Transpose flag
523  : size_ ( 0UL ) // The current size/dimension of the compressed vector
524  , capacity_( 0UL ) // The maximum capacity of the compressed vector
525  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
526  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
527 {}
528 //*************************************************************************************************
529 
530 
531 //*************************************************************************************************
536 template< typename Type // Data type of the vector
537  , bool TF > // Transpose flag
539  : size_ ( n ) // The current size/dimension of the compressed vector
540  , capacity_( 0UL ) // The maximum capacity of the compressed vector
541  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
542  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
543 {}
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
553 template< typename Type // Data type of the vector
554  , bool TF > // Transpose flag
555 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
556  : size_ ( n ) // The current size/dimension of the compressed vector
557  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
558  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
559  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
560 {}
561 //*************************************************************************************************
562 
563 
564 //*************************************************************************************************
572 template< typename Type // Data type of the vector
573  , bool TF > // Transpose flag
575  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
576  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
577  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
578  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
579 {
580  std::copy( sv.begin_, sv.end_, castUp( begin_ ) );
581 }
582 //*************************************************************************************************
583 
584 
585 //*************************************************************************************************
590 template< typename Type // Data type of the vector
591  , bool TF > // Transpose flag
593  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
594  , capacity_( sv.capacity_ ) // The maximum capacity of the compressed vector
595  , begin_ ( sv.begin_ ) // Pointer to the first non-zero element of the compressed vector
596  , end_ ( sv.end_ ) // Pointer to the last non-zero element of the compressed vector
597 {
598  sv.size_ = 0UL;
599  sv.capacity_ = 0UL;
600  sv.begin_ = nullptr;
601  sv.end_ = nullptr;
602 }
603 //*************************************************************************************************
604 
605 
606 //*************************************************************************************************
611 template< typename Type // Data type of the vector
612  , bool TF > // Transpose flag
613 template< typename VT > // Type of the foreign dense vector
615  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
616  , capacity_( 0UL ) // The maximum capacity of the compressed vector
617  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
618  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
619 {
620  using blaze::assign;
621  assign( *this, ~dv );
622 }
623 //*************************************************************************************************
624 
625 
626 //*************************************************************************************************
631 template< typename Type // Data type of the vector
632  , bool TF > // Transpose flag
633 template< typename VT > // Type of the foreign sparse vector
635  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
636  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
637  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
638  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
639 {
640  using blaze::assign;
641  assign( *this, ~sv );
642 }
643 //*************************************************************************************************
644 
645 
646 
647 
648 //=================================================================================================
649 //
650 // DESTRUCTOR
651 //
652 //=================================================================================================
653 
654 //*************************************************************************************************
657 template< typename Type // Data type of the vector
658  , bool TF > // Transpose flag
660 {
661  deallocate( begin_ );
662 }
663 //*************************************************************************************************
664 
665 
666 
667 
668 //=================================================================================================
669 //
670 // DATA ACCESS FUNCTIONS
671 //
672 //=================================================================================================
673 
674 //*************************************************************************************************
685 template< typename Type // Data type of the vector
686  , bool TF > // Transpose flag
688  CompressedVector<Type,TF>::operator[]( size_t index ) noexcept
689 {
690  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
691 
692  return Reference( *this, index );
693 }
694 //*************************************************************************************************
695 
696 
697 //*************************************************************************************************
703 template< typename Type // Data type of the vector
704  , bool TF > // Transpose flag
706  CompressedVector<Type,TF>::operator[]( size_t index ) const noexcept
707 {
708  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
709 
710  const ConstIterator pos( lowerBound( index ) );
711 
712  if( pos == end_ || pos->index_ != index )
713  return zero_;
714  else
715  return pos->value_;
716 }
717 //*************************************************************************************************
718 
719 
720 //*************************************************************************************************
732 template< typename Type // Data type of the vector
733  , bool TF > // Transpose flag
736 {
737  if( index >= size_ ) {
738  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
739  }
740  return (*this)[index];
741 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
757 template< typename Type // Data type of the vector
758  , bool TF > // Transpose flag
760  CompressedVector<Type,TF>::at( size_t index ) const
761 {
762  if( index >= size_ ) {
763  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
764  }
765  return (*this)[index];
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
775 template< typename Type // Data type of the vector
776  , bool TF > // Transpose flag
778 {
779  return Iterator( begin_ );
780 }
781 //*************************************************************************************************
782 
783 
784 //*************************************************************************************************
789 template< typename Type // Data type of the vector
790  , bool TF > // Transpose flag
793 {
794  return ConstIterator( begin_ );
795 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
804 template< typename Type // Data type of the vector
805  , bool TF > // Transpose flag
808 {
809  return ConstIterator( begin_ );
810 }
811 //*************************************************************************************************
812 
813 
814 //*************************************************************************************************
819 template< typename Type // Data type of the vector
820  , bool TF > // Transpose flag
822 {
823  return Iterator( end_ );
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
833 template< typename Type // Data type of the vector
834  , bool TF > // Transpose flag
837 {
838  return ConstIterator( end_ );
839 }
840 //*************************************************************************************************
841 
842 
843 //*************************************************************************************************
848 template< typename Type // Data type of the vector
849  , bool TF > // Transpose flag
852 {
853  return ConstIterator( end_ );
854 }
855 //*************************************************************************************************
856 
857 
858 
859 
860 //=================================================================================================
861 //
862 // ASSIGNMENT OPERATORS
863 //
864 //=================================================================================================
865 
866 //*************************************************************************************************
875 template< typename Type // Data type of the vector
876  , bool TF > // Transpose flag
879 {
880  if( &rhs == this ) return *this;
881 
882  const size_t nonzeros( rhs.nonZeros() );
883 
884  if( nonzeros > capacity_ ) {
885  Iterator newBegin( allocate<Element>( nonzeros ) );
886  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( newBegin ) ) );
887  std::swap( begin_, newBegin );
888  deallocate( newBegin );
889 
890  size_ = rhs.size_;
891  capacity_ = nonzeros;
892  }
893  else {
894  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( begin_ ) ) );
895  size_ = rhs.size_;
896  }
897 
898  return *this;
899 }
900 //*************************************************************************************************
901 
902 
903 //*************************************************************************************************
909 template< typename Type // Data type of the vector
910  , bool TF > // Transpose flag
913 {
914  deallocate( begin_ );
915 
916  size_ = rhs.size_;
917  capacity_ = rhs.capacity_;
918  begin_ = rhs.begin_;
919  end_ = rhs.end_;
920 
921  rhs.size_ = 0UL;
922  rhs.capacity_ = 0UL;
923  rhs.begin_ = nullptr;
924  rhs.end_ = nullptr;
925 
926  return *this;
927 }
928 //*************************************************************************************************
929 
930 
931 //*************************************************************************************************
940 template< typename Type // Data type of the vector
941  , bool TF > // Transpose flag
942 template< typename VT > // Type of the right-hand side dense vector
945 {
946  using blaze::assign;
947 
948  if( (~rhs).canAlias( this ) ) {
949  CompressedVector tmp( ~rhs );
950  swap( tmp );
951  }
952  else {
953  size_ = (~rhs).size();
954  end_ = begin_;
955  assign( *this, ~rhs );
956  }
957 
958  return *this;
959 }
960 //*************************************************************************************************
961 
962 
963 //*************************************************************************************************
972 template< typename Type // Data type of the vector
973  , bool TF > // Transpose flag
974 template< typename VT > // Type of the right-hand side sparse vector
977 {
978  using blaze::assign;
979 
980  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
981  CompressedVector tmp( ~rhs );
982  swap( tmp );
983  }
984  else {
985  size_ = (~rhs).size();
986  end_ = begin_;
987  assign( *this, ~rhs );
988  }
989 
990  return *this;
991 }
992 //*************************************************************************************************
993 
994 
995 //*************************************************************************************************
1005 template< typename Type // Data type of the vector
1006  , bool TF > // Transpose flag
1007 template< typename VT > // Type of the right-hand side vector
1009 {
1010  using blaze::addAssign;
1011 
1012  if( (~rhs).size() != size_ ) {
1013  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1014  }
1015 
1016  addAssign( *this, ~rhs );
1017 
1018  return *this;
1019 }
1020 //*************************************************************************************************
1021 
1022 
1023 //*************************************************************************************************
1033 template< typename Type // Data type of the vector
1034  , bool TF > // Transpose flag
1035 template< typename VT > // Type of the right-hand side vector
1037 {
1038  using blaze::subAssign;
1039 
1040  if( (~rhs).size() != size_ ) {
1041  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1042  }
1043 
1044  subAssign( *this, ~rhs );
1045 
1046  return *this;
1047 }
1048 //*************************************************************************************************
1049 
1050 
1051 //*************************************************************************************************
1062 template< typename Type // Data type of the vector
1063  , bool TF > // Transpose flag
1064 template< typename VT > // Type of the right-hand side vector
1067 {
1068  using blaze::multAssign;
1069 
1070  if( (~rhs).size() != size_ ) {
1071  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1072  }
1073 
1074  if( (~rhs).canAlias( this ) ) {
1075  CompressedVector tmp( *this * (~rhs) );
1076  swap( tmp );
1077  }
1078  else {
1079  CompositeType_<VT> tmp( ~rhs );
1080  multAssign( *this, tmp );
1081  }
1082 
1083  return *this;
1084 }
1085 //*************************************************************************************************
1086 
1087 
1088 //*************************************************************************************************
1099 template< typename Type // Data type of the vector
1100  , bool TF > // Transpose flag
1101 template< typename VT > // Type of the right-hand side vector
1104 {
1105  if( (~rhs).size() != size_ ) {
1106  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1107  }
1108 
1109  CompressedVector tmp( *this * (~rhs) );
1110  swap( tmp );
1111 
1112  return *this;
1113 }
1114 //*************************************************************************************************
1115 
1116 
1117 //*************************************************************************************************
1127 template< typename Type // Data type of the vector
1128  , bool TF > // Transpose flag
1129 template< typename VT > // Type of the right-hand side vector
1131 {
1132  using blaze::divAssign;
1133 
1134  if( (~rhs).size() != size_ ) {
1135  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1136  }
1137 
1138  if( (~rhs).canAlias( this ) ) {
1139  CompressedVector tmp( *this / (~rhs) );
1140  swap( tmp );
1141  }
1142  else {
1143  CompositeType_<VT> tmp( ~rhs );
1144  divAssign( *this, tmp );
1145  }
1146 
1147  return *this;
1148 }
1149 //*************************************************************************************************
1150 
1151 
1152 //*************************************************************************************************
1163 template< typename Type // Data type of the vector
1164  , bool TF > // Transpose flag
1165 template< typename VT > // Type of the right-hand side vector
1167 {
1168  using blaze::assign;
1169 
1170  using CrossType = CrossTrait_< This, ResultType_<VT> >;
1171 
1175 
1176  if( size_ != 3UL || (~rhs).size() != 3UL ) {
1177  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1178  }
1179 
1180  const CrossType tmp( *this % (~rhs) );
1181  end_ = begin_;
1182  assign( *this, tmp );
1183 
1184  return *this;
1185 }
1186 //*************************************************************************************************
1187 
1188 
1189 //*************************************************************************************************
1200 template< typename Type // Data type of the vector
1201  , bool TF > // Transpose flag
1202 template< typename Other > // Data type of the right-hand side scalar
1205 {
1206  for( Iterator element=begin_; element!=end_; ++element )
1207  element->value_ *= rhs;
1208  return *this;
1209 }
1210 //*************************************************************************************************
1211 
1212 
1213 //*************************************************************************************************
1225 template< typename Type // Data type of the vector
1226  , bool TF > // Transpose flag
1227 template< typename Other > // Data type of the right-hand side scalar
1228 inline EnableIf_< IsNumeric<Other>, CompressedVector<Type,TF> >&
1230 {
1231  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1232 
1233  using DT = DivTrait_<Type,Other>;
1234  using Tmp = If_< IsNumeric<DT>, DT, Other >;
1235 
1236  // Depending on the two involved data types, an integer division is applied or a
1237  // floating point division is selected.
1239  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1240  for( Iterator element=begin_; element!=end_; ++element )
1241  element->value_ *= tmp;
1242  }
1243  else {
1244  for( Iterator element=begin_; element!=end_; ++element )
1245  element->value_ /= rhs;
1246  }
1247 
1248  return *this;
1249 }
1250 //*************************************************************************************************
1251 
1252 
1253 
1254 
1255 //=================================================================================================
1256 //
1257 // UTILITY FUNCTIONS
1258 //
1259 //=================================================================================================
1260 
1261 //*************************************************************************************************
1266 template< typename Type // Data type of the vector
1267  , bool TF > // Transpose flag
1268 inline size_t CompressedVector<Type,TF>::size() const noexcept
1269 {
1270  return size_;
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1280 template< typename Type // Data type of the vector
1281  , bool TF > // Transpose flag
1282 inline size_t CompressedVector<Type,TF>::capacity() const noexcept
1283 {
1284  return capacity_;
1285 }
1286 //*************************************************************************************************
1287 
1288 
1289 //*************************************************************************************************
1297 template< typename Type // Data type of the vector
1298  , bool TF > // Transpose flag
1300 {
1301  return end_ - begin_;
1302 }
1303 //*************************************************************************************************
1304 
1305 
1306 //*************************************************************************************************
1311 template< typename Type // Data type of the vector
1312  , bool TF > // Transpose flag
1314 {
1315  end_ = begin_;
1316 }
1317 //*************************************************************************************************
1318 
1319 
1320 //*************************************************************************************************
1327 template< typename Type // Data type of the vector
1328  , bool TF > // Transpose flag
1330 {
1331  size_ = 0UL;
1332  end_ = begin_;
1333 }
1334 //*************************************************************************************************
1335 
1336 
1337 //*************************************************************************************************
1351 template< typename Type // Data type of the vector
1352  , bool TF > // Transpose flag
1353 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1354 {
1355  if( preserve ) {
1356  end_ = lowerBound( n );
1357  }
1358  else {
1359  end_ = begin_;
1360  }
1361 
1362  size_ = n;
1363 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1376 template< typename Type // Data type of the vector
1377  , bool TF > // Transpose flag
1379 {
1380  if( n > capacity_ ) {
1381  const size_t newCapacity( n );
1382 
1383  // Allocating a new data and index array
1384  Iterator newBegin = allocate<Element>( newCapacity );
1385 
1386  // Replacing the old data and index array
1387  end_ = castDown( transfer( begin_, end_, castUp( newBegin ) ) );
1388  std::swap( newBegin, begin_ );
1389  capacity_ = newCapacity;
1390  deallocate( newBegin );
1391  }
1392 }
1393 //*************************************************************************************************
1394 
1395 
1396 //*************************************************************************************************
1405 template< typename Type // Data type of the vector
1406  , bool TF > // Transpose flag
1408 {
1409  if( nonZeros() < capacity_ ) {
1410  CompressedVector( *this ).swap( *this );
1411  }
1412 }
1413 //*************************************************************************************************
1414 
1415 
1416 //*************************************************************************************************
1422 template< typename Type // Data type of the vector
1423  , bool TF > // Transpose flag
1425 {
1426  std::swap( size_, sv.size_ );
1427  std::swap( capacity_, sv.capacity_ );
1428  std::swap( begin_, sv.begin_ );
1429  std::swap( end_, sv.end_ );
1430 }
1431 //*************************************************************************************************
1432 
1433 
1434 //*************************************************************************************************
1442 template< typename Type // Data type of the vector
1443  , bool TF > // Transpose flag
1444 inline size_t CompressedVector<Type,TF>::extendCapacity() const noexcept
1445 {
1446  using blaze::max;
1447  using blaze::min;
1448 
1449  size_t nonzeros( 2UL*capacity_+1UL );
1450  nonzeros = max( nonzeros, 7UL );
1451  nonzeros = min( nonzeros, size_ );
1452 
1453  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1454 
1455  return nonzeros;
1456 }
1457 //*************************************************************************************************
1458 
1459 
1460 //*************************************************************************************************
1468 template< typename Type // Data type of the vector
1469  , bool TF > // Transpose flag
1472 {
1473  return static_cast<Iterator>( it );
1474 }
1475 //*************************************************************************************************
1476 
1477 
1478 //*************************************************************************************************
1486 template< typename Type // Data type of the vector
1487  , bool TF > // Transpose flag
1490 {
1491  return static_cast<IteratorBase>( it );
1492 }
1493 //*************************************************************************************************
1494 
1495 
1496 
1497 
1498 //=================================================================================================
1499 //
1500 // INSERTION FUNCTIONS
1501 //
1502 //=================================================================================================
1503 
1504 //*************************************************************************************************
1515 template< typename Type // Data type of the vector
1516  , bool TF > // Transpose flag
1518  CompressedVector<Type,TF>::set( size_t index, const Type& value )
1519 {
1520  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1521 
1522  const Iterator pos( lowerBound( index ) );
1523 
1524  if( pos != end_ && pos->index_ == index ) {
1525  pos->value() = value;
1526  return pos;
1527  }
1528  else return insert( pos, index, value );
1529 }
1530 //*************************************************************************************************
1531 
1532 
1533 //*************************************************************************************************
1545 template< typename Type // Data type of the vector
1546  , bool TF > // Transpose flag
1548  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1549 {
1550  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1551 
1552  const Iterator pos( lowerBound( index ) );
1553 
1554  if( pos != end_ && pos->index_ == index ) {
1555  BLAZE_THROW_INVALID_ARGUMENT( "Bad access index" );
1556  }
1557 
1558  return insert( pos, index, value );
1559 }
1560 //*************************************************************************************************
1561 
1562 
1563 //*************************************************************************************************
1572 template< typename Type // Data type of the vector
1573  , bool TF > // Transpose flag
1575  CompressedVector<Type,TF>::insert( Iterator pos, size_t index, const Type& value )
1576 {
1577  if( nonZeros() != capacity_ ) {
1578  std::move_backward( pos, end_, castUp( end_+1 ) );
1579  pos->value_ = value;
1580  pos->index_ = index;
1581  ++end_;
1582 
1583  return pos;
1584  }
1585  else {
1586  size_t newCapacity( extendCapacity() );
1587 
1588  Iterator newBegin = allocate<Element>( newCapacity );
1589  Iterator tmp = castDown( std::move( begin_, pos, castUp( newBegin ) ) );
1590  tmp->value_ = value;
1591  tmp->index_ = index;
1592  end_ = castDown( std::move( pos, end_, castUp( tmp+1 ) ) );
1593 
1594  std::swap( newBegin, begin_ );
1595  deallocate( newBegin );
1596  capacity_ = newCapacity;
1597 
1598  return tmp;
1599  }
1600 }
1601 //*************************************************************************************************
1602 
1603 
1604 //*************************************************************************************************
1628 template< typename Type // Data type of the vector
1629  , bool TF > // Transpose flag
1630 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1631 {
1632  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1633  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved capacity" );
1634  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1635 
1636  end_->value_ = value;
1637 
1638  if( !check || !isDefault<strict>( end_->value_ ) ) {
1639  end_->index_ = index;
1640  ++end_;
1641  }
1642 }
1643 //*************************************************************************************************
1644 
1645 
1646 
1647 
1648 //=================================================================================================
1649 //
1650 // ERASE FUNCTIONS
1651 //
1652 //=================================================================================================
1653 
1654 //*************************************************************************************************
1662 template< typename Type // Data type of the vector
1663  , bool TF > // Transpose flag
1664 inline void CompressedVector<Type,TF>::erase( size_t index )
1665 {
1666  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1667 
1668  const Iterator pos( find( index ) );
1669  if( pos != end_ )
1670  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1671 }
1672 //*************************************************************************************************
1673 
1674 
1675 //*************************************************************************************************
1683 template< typename Type // Data type of the vector
1684  , bool TF > // Transpose flag
1687 {
1688  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1689 
1690  if( pos != end_ )
1691  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1692  return pos;
1693 }
1694 //*************************************************************************************************
1695 
1696 
1697 //*************************************************************************************************
1706 template< typename Type // Data type of the vector
1707  , bool TF > // Transpose flag
1710 {
1711  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1712  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1713  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1714 
1715  if( first != last )
1716  end_ = castDown( std::move( last, end_, castUp( first ) ) );
1717  return first;
1718 }
1719 //*************************************************************************************************
1720 
1721 
1722 //*************************************************************************************************
1743 template< typename Type // Data type of the vector
1744  , bool TF > // Transpose flag
1745 template< typename Pred // Type of the unary predicate
1746  , typename > // Type restriction on the unary predicate
1747 inline void CompressedVector<Type,TF>::erase( Pred predicate )
1748 {
1749  end_ = castDown( std::remove_if( castUp( begin_ ), castUp( end_ ),
1750  [predicate=predicate]( const ElementBase& element ) {
1751  return predicate( element.value() );
1752  } ) );
1753 }
1754 //*************************************************************************************************
1755 
1756 
1757 //*************************************************************************************************
1780 template< typename Type // Data type of the vector
1781  , bool TF > // Transpose flag
1782 template< typename Pred > // Type of the unary predicate
1783 inline void CompressedVector<Type,TF>::erase( Iterator first, Iterator last, Pred predicate )
1784 {
1785  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1786  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1787  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1788 
1789  const auto pos = std::remove_if( castUp( first ), castUp( last ),
1790  [predicate=predicate]( const ElementBase& element ) {
1791  return predicate( element.value() );
1792  } );
1793 
1794  end_ = castDown( std::move( last, end_, pos ) );
1795 }
1796 //*************************************************************************************************
1797 
1798 
1799 
1800 
1801 //=================================================================================================
1802 //
1803 // LOOKUP FUNCTIONS
1804 //
1805 //=================================================================================================
1806 
1807 //*************************************************************************************************
1820 template< typename Type // Data type of the vector
1821  , bool TF > // Transpose flag
1823 {
1824  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1825 }
1826 //*************************************************************************************************
1827 
1828 
1829 //*************************************************************************************************
1842 template< typename Type // Data type of the vector
1843  , bool TF > // Transpose flag
1845 {
1846  const ConstIterator pos( lowerBound( index ) );
1847  if( pos != end_ && pos->index_ == index )
1848  return pos;
1849  else return end_;
1850 }
1851 //*************************************************************************************************
1852 
1853 
1854 //*************************************************************************************************
1866 template< typename Type // Data type of the vector
1867  , bool TF > // Transpose flag
1870 {
1871  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1872 }
1873 //*************************************************************************************************
1874 
1875 
1876 //*************************************************************************************************
1888 template< typename Type // Data type of the vector
1889  , bool TF > // Transpose flag
1892 {
1893  return std::lower_bound( begin_, end_, index,
1894  []( const Element& element, size_t i )
1895  {
1896  return element.index() < i;
1897  } );
1898 }
1899 //*************************************************************************************************
1900 
1901 
1902 //*************************************************************************************************
1914 template< typename Type // Data type of the vector
1915  , bool TF > // Transpose flag
1918 {
1919  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1920 }
1921 //*************************************************************************************************
1922 
1923 
1924 //*************************************************************************************************
1936 template< typename Type // Data type of the vector
1937  , bool TF > // Transpose flag
1940 {
1941  return std::upper_bound( begin_, end_, index,
1942  []( size_t i, const Element& element )
1943  {
1944  return i < element.index();
1945  } );
1946 }
1947 //*************************************************************************************************
1948 
1949 
1950 
1951 
1952 //=================================================================================================
1953 //
1954 // NUMERIC FUNCTIONS
1955 //
1956 //=================================================================================================
1957 
1958 //*************************************************************************************************
1975 template< typename Type // Data type of the vector
1976  , bool TF > // Transpose flag
1977 template< typename Other > // Data type of the scalar value
1979 {
1980  for( Iterator element=begin_; element!=end_; ++element )
1981  element->value_ *= scalar;
1982  return *this;
1983 }
1984 //*************************************************************************************************
1985 
1986 
1987 
1988 
1989 //=================================================================================================
1990 //
1991 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1992 //
1993 //=================================================================================================
1994 
1995 //*************************************************************************************************
2005 template< typename Type // Data type of the vector
2006  , bool TF > // Transpose flag
2007 template< typename Other > // Data type of the foreign expression
2008 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const noexcept
2009 {
2010  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2011 }
2012 //*************************************************************************************************
2013 
2014 
2015 //*************************************************************************************************
2025 template< typename Type // Data type of the vector
2026  , bool TF > // Transpose flag
2027 template< typename Other > // Data type of the foreign expression
2028 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const noexcept
2029 {
2030  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2031 }
2032 //*************************************************************************************************
2033 
2034 
2035 //*************************************************************************************************
2045 template< typename Type // Data type of the vector
2046  , bool TF > // Transpose flag
2047 inline bool CompressedVector<Type,TF>::canSMPAssign() const noexcept
2048 {
2049  return false;
2050 }
2051 //*************************************************************************************************
2052 
2053 
2054 //*************************************************************************************************
2065 template< typename Type // Data type of the vector
2066  , bool TF > // Transpose flag
2067 template< typename VT > // Type of the right-hand side dense vector
2069 {
2070  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2071  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2072 
2073  size_t nonzeros( 0UL );
2074 
2075  for( size_t i=0UL; i<size_; ++i )
2076  {
2077  if( nonzeros == capacity_ )
2078  reserve( extendCapacity() );
2079 
2080  end_->value_ = (~rhs)[i];
2081 
2082  if( !isDefault<strict>( end_->value_ ) ) {
2083  end_->index_ = i;
2084  ++end_;
2085  ++nonzeros;
2086  }
2087  }
2088 }
2089 //*************************************************************************************************
2090 
2091 
2092 //*************************************************************************************************
2103 template< typename Type // Data type of the vector
2104  , bool TF > // Transpose flag
2105 template< typename VT > // Type of the right-hand side sparse vector
2107 {
2108  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2109  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2110 
2111  // Using the following formulation instead of a std::copy function call of the form
2112  //
2113  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
2114  //
2115  // results in much less requirements on the ConstIterator type provided from the right-hand
2116  // sparse vector type
2117  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2118  append( element->index(), element->value() );
2119 }
2120 //*************************************************************************************************
2121 
2122 
2123 //*************************************************************************************************
2134 template< typename Type // Data type of the vector
2135  , bool TF > // Transpose flag
2136 template< typename VT > // Type of the right-hand side dense vector
2138 {
2139  using AddType = AddTrait_< This, ResultType_<VT> >;
2140 
2144 
2145  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2146 
2147  const AddType tmp( serial( *this + (~rhs) ) );
2148  reset();
2149  assign( tmp );
2150 }
2151 //*************************************************************************************************
2152 
2153 
2154 //*************************************************************************************************
2165 template< typename Type // Data type of the vector
2166  , bool TF > // Transpose flag
2167 template< typename VT > // Type of the right-hand side sparse vector
2169 {
2170  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2171 
2172  CompressedVector tmp( serial( *this + (~rhs) ) );
2173  swap( tmp );
2174 }
2175 //*************************************************************************************************
2176 
2177 
2178 //*************************************************************************************************
2189 template< typename Type // Data type of the vector
2190  , bool TF > // Transpose flag
2191 template< typename VT > // Type of the right-hand side dense vector
2193 {
2194  using SubType = SubTrait_< This, ResultType_<VT> >;
2195 
2199 
2200  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2201 
2202  const SubType tmp( serial( *this - (~rhs) ) );
2203  reset();
2204  assign( tmp );
2205 }
2206 //*************************************************************************************************
2207 
2208 
2209 //*************************************************************************************************
2220 template< typename Type // Data type of the vector
2221  , bool TF > // Transpose flag
2222 template< typename VT > // Type of the right-hand side sparse vector
2224 {
2225  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2226 
2227  CompressedVector tmp( serial( *this - (~rhs) ) );
2228  swap( tmp );
2229 }
2230 //*************************************************************************************************
2231 
2232 
2233 //*************************************************************************************************
2244 template< typename Type // Data type of the vector
2245  , bool TF > // Transpose flag
2246 template< typename VT > // Type of the right-hand side dense vector
2248 {
2249  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2250 
2252 
2253  for( Iterator element=begin_; element!=end_; ++element ) {
2254  element->value_ *= (~rhs)[element->index_];
2255  }
2256 }
2257 //*************************************************************************************************
2258 
2259 
2260 //*************************************************************************************************
2271 template< typename Type // Data type of the vector
2272  , bool TF > // Transpose flag
2273 template< typename VT > // Type of the right-hand side dense vector
2275 {
2276  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2277 
2279 
2280  for( Iterator element=begin_; element!=end_; ++element ) {
2281  element->value_ /= (~rhs)[element->index_];
2282  }
2283 }
2284 //*************************************************************************************************
2285 
2286 
2287 
2288 
2289 //=================================================================================================
2290 //
2291 // COMPRESSEDVECTOR OPERATORS
2292 //
2293 //=================================================================================================
2294 
2295 //*************************************************************************************************
2298 template< typename Type, bool TF >
2299 inline void reset( CompressedVector<Type,TF>& v );
2300 
2301 template< typename Type, bool TF >
2302 inline void clear( CompressedVector<Type,TF>& v );
2303 
2304 template< bool RF, typename Type, bool TF >
2305 inline bool isDefault( const CompressedVector<Type,TF>& v );
2306 
2307 template< typename Type, bool TF >
2308 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept;
2309 
2310 template< typename Type, bool TF >
2311 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) noexcept;
2313 //*************************************************************************************************
2314 
2315 
2316 //*************************************************************************************************
2323 template< typename Type // Data type of the vector
2324  , bool TF > // Transpose flag
2326 {
2327  v.reset();
2328 }
2329 //*************************************************************************************************
2330 
2331 
2332 //*************************************************************************************************
2339 template< typename Type // Data type of the vector
2340  , bool TF > // Transpose flag
2342 {
2343  v.clear();
2344 }
2345 //*************************************************************************************************
2346 
2347 
2348 //*************************************************************************************************
2372 template< bool RF // Relaxation flag
2373  , typename Type // Data type of the vector
2374  , bool TF > // Transpose flag
2375 inline bool isDefault( const CompressedVector<Type,TF>& v )
2376 {
2377  return ( v.size() == 0UL );
2378 }
2379 //*************************************************************************************************
2380 
2381 
2382 //*************************************************************************************************
2400 template< typename Type // Data type of the vector
2401  , bool TF > // Transpose flag
2402 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept
2403 {
2404  return ( v.nonZeros() <= v.capacity() );
2405 }
2406 //*************************************************************************************************
2407 
2408 
2409 //*************************************************************************************************
2417 template< typename Type // Data type of the vector
2418  , bool TF > // Transpose flag
2420 {
2421  a.swap( b );
2422 }
2423 //*************************************************************************************************
2424 
2425 
2426 
2427 
2428 //=================================================================================================
2429 //
2430 // ISRESIZABLE SPECIALIZATIONS
2431 //
2432 //=================================================================================================
2433 
2434 //*************************************************************************************************
2436 template< typename T, bool TF >
2437 struct IsResizable< CompressedVector<T,TF> >
2438  : public TrueType
2439 {};
2441 //*************************************************************************************************
2442 
2443 
2444 
2445 
2446 //=================================================================================================
2447 //
2448 // ISSHRINKABLE SPECIALIZATIONS
2449 //
2450 //=================================================================================================
2451 
2452 //*************************************************************************************************
2454 template< typename T, bool TF >
2455 struct IsShrinkable< CompressedVector<T,TF> >
2456  : public TrueType
2457 {};
2459 //*************************************************************************************************
2460 
2461 
2462 
2463 
2464 //=================================================================================================
2465 //
2466 // ADDTRAIT SPECIALIZATIONS
2467 //
2468 //=================================================================================================
2469 
2470 //*************************************************************************************************
2472 template< typename T1, bool TF, typename T2, size_t N >
2473 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2474 {
2475  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2476 };
2477 
2478 template< typename T1, size_t N, bool TF, typename T2 >
2479 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2480 {
2481  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2482 };
2483 
2484 template< typename T1, bool TF, typename T2, size_t N >
2485 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2486 {
2487  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2488 };
2489 
2490 template< typename T1, size_t N, bool TF, typename T2 >
2491 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2492 {
2493  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2494 };
2495 
2496 template< typename T1, bool TF, typename T2 >
2497 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2498 {
2499  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2500 };
2501 
2502 template< typename T1, bool TF, typename T2 >
2503 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2504 {
2505  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2506 };
2507 
2508 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2509 struct AddTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2510 {
2511  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2512 };
2513 
2514 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2515 struct AddTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2516 {
2517  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2518 };
2519 
2520 template< typename T1, bool TF, typename T2 >
2521 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2522 {
2523  using Type = CompressedVector< AddTrait_<T1,T2>, TF >;
2524 };
2526 //*************************************************************************************************
2527 
2528 
2529 
2530 
2531 //=================================================================================================
2532 //
2533 // SUBTRAIT SPECIALIZATIONS
2534 //
2535 //=================================================================================================
2536 
2537 //*************************************************************************************************
2539 template< typename T1, bool TF, typename T2, size_t N >
2540 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2541 {
2542  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2543 };
2544 
2545 template< typename T1, size_t N, bool TF, typename T2 >
2546 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2547 {
2548  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2549 };
2550 
2551 template< typename T1, bool TF, typename T2, size_t N >
2552 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2553 {
2554  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2555 };
2556 
2557 template< typename T1, size_t N, bool TF, typename T2 >
2558 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2559 {
2560  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2561 };
2562 
2563 template< typename T1, bool TF, typename T2 >
2564 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2565 {
2566  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2567 };
2568 
2569 template< typename T1, bool TF, typename T2 >
2570 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2571 {
2572  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2573 };
2574 
2575 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2576 struct SubTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2577 {
2578  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2579 };
2580 
2581 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2582 struct SubTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2583 {
2584  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2585 };
2586 
2587 template< typename T1, bool TF, typename T2 >
2588 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2589 {
2590  using Type = CompressedVector< SubTrait_<T1,T2>, TF >;
2591 };
2593 //*************************************************************************************************
2594 
2595 
2596 
2597 
2598 //=================================================================================================
2599 //
2600 // MULTTRAIT SPECIALIZATIONS
2601 //
2602 //=================================================================================================
2603 
2604 //*************************************************************************************************
2606 template< typename T1, bool TF, typename T2 >
2607 struct MultTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2608 {
2609  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2610 };
2611 
2612 template< typename T1, typename T2, bool TF >
2613 struct MultTrait< T1, CompressedVector<T2,TF>, EnableIf_< IsNumeric<T1> > >
2614 {
2615  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2616 };
2617 
2618 template< typename T1, bool TF, typename T2, size_t N >
2619 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2620 {
2621  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2622 };
2623 
2624 template< typename T1, typename T2, size_t N >
2625 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
2626 {
2627  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2628 };
2629 
2630 template< typename T1, typename T2, size_t N >
2631 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
2632 {
2633  using Type = MultTrait_<T1,T2>;
2634 };
2635 
2636 template< typename T1, size_t N, bool TF, typename T2 >
2637 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2638 {
2639  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2640 };
2641 
2642 template< typename T1, size_t N, typename T2 >
2643 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2644 {
2645  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2646 };
2647 
2648 template< typename T1, size_t N, typename T2 >
2649 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2650 {
2651  using Type = MultTrait_<T1,T2>;
2652 };
2653 
2654 template< typename T1, bool TF, typename T2, size_t N >
2655 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2656 {
2657  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2658 };
2659 
2660 template< typename T1, typename T2, size_t N >
2661 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2662 {
2663  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2664 };
2665 
2666 template< typename T1, typename T2, size_t N >
2667 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2668 {
2669  using Type = MultTrait_<T1,T2>;
2670 };
2671 
2672 template< typename T1, size_t N, bool TF, typename T2 >
2673 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2674 {
2675  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2676 };
2677 
2678 template< typename T1, size_t N, typename T2 >
2679 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2680 {
2681  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2682 };
2683 
2684 template< typename T1, size_t N, typename T2 >
2685 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2686 {
2687  using Type = MultTrait_<T1,T2>;
2688 };
2689 
2690 template< typename T1, bool TF, typename T2 >
2691 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2692 {
2693  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2694 };
2695 
2696 template< typename T1, typename T2 >
2697 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2698 {
2699  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2700 };
2701 
2702 template< typename T1, typename T2 >
2703 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2704 {
2705  using Type = MultTrait_<T1,T2>;
2706 };
2707 
2708 template< typename T1, bool TF, typename T2 >
2709 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2710 {
2711  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2712 };
2713 
2714 template< typename T1, typename T2 >
2715 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2716 {
2717  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2718 };
2719 
2720 template< typename T1, typename T2 >
2721 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2722 {
2723  using Type = MultTrait_<T1,T2>;
2724 };
2725 
2726 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2727 struct MultTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2728 {
2729  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2730 };
2731 
2732 template< typename T1, typename T2, bool AF, bool PF >
2733 struct MultTrait< CompressedVector<T1,false>, CustomVector<T2,AF,PF,true> >
2734 {
2735  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2736 };
2737 
2738 template< typename T1, typename T2, bool AF, bool PF >
2739 struct MultTrait< CompressedVector<T1,true>, CustomVector<T2,AF,PF,false> >
2740 {
2741  using Type = MultTrait_<T1,T2>;
2742 };
2743 
2744 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2745 struct MultTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2746 {
2747  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2748 };
2749 
2750 template< typename T1, bool AF, bool PF, typename T2 >
2751 struct MultTrait< CustomVector<T1,AF,PF,false>, CompressedVector<T2,true> >
2752 {
2753  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2754 };
2755 
2756 template< typename T1, bool AF, bool PF, typename T2 >
2757 struct MultTrait< CustomVector<T1,AF,PF,true>, CompressedVector<T2,false> >
2758 {
2759  using Type = MultTrait_<T1,T2>;
2760 };
2761 
2762 template< typename T1, bool TF, typename T2 >
2763 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2764 {
2765  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2766 };
2767 
2768 template< typename T1, typename T2 >
2769 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2770 {
2771  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2772 };
2773 
2774 template< typename T1, typename T2 >
2775 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2776 {
2777  using Type = MultTrait_<T1,T2>;
2778 };
2780 //*************************************************************************************************
2781 
2782 
2783 
2784 
2785 //=================================================================================================
2786 //
2787 // DIVTRAIT SPECIALIZATIONS
2788 //
2789 //=================================================================================================
2790 
2791 //*************************************************************************************************
2793 template< typename T1, bool TF, typename T2 >
2794 struct DivTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2795 {
2796  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2797 };
2798 
2799 template< typename T1, bool TF, typename T2, size_t N >
2800 struct DivTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2801 {
2802  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2803 };
2804 
2805 template< typename T1, size_t N, bool TF, typename T2 >
2806 struct DivTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2807 {
2808  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2809 };
2810 
2811 template< typename T1, bool TF, typename T2, size_t N >
2812 struct DivTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2813 {
2814  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2815 };
2816 
2817 template< typename T1, size_t N, bool TF, typename T2 >
2818 struct DivTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2819 {
2820  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2821 };
2822 
2823 template< typename T1, bool TF, typename T2 >
2824 struct DivTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2825 {
2826  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2827 };
2828 
2829 template< typename T1, bool TF, typename T2 >
2830 struct DivTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2831 {
2832  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2833 };
2834 
2835 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2836 struct DivTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2837 {
2838  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2839 };
2840 
2841 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2842 struct DivTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2843 {
2844  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2845 };
2846 
2847 template< typename T1, bool TF, typename T2 >
2848 struct DivTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2849 {
2850  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2851 };
2853 //*************************************************************************************************
2854 
2855 
2856 
2857 
2858 //=================================================================================================
2859 //
2860 // CROSSTRAIT SPECIALIZATIONS
2861 //
2862 //=================================================================================================
2863 
2864 //*************************************************************************************************
2866 template< typename T1, bool TF, typename T2 >
2867 struct CrossTrait< CompressedVector<T1,TF>, StaticVector<T2,3UL,TF> >
2868 {
2869  private:
2870  using T = MultTrait_<T1,T2>;
2871 
2872  public:
2873  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2874 };
2875 
2876 template< typename T1, bool TF, typename T2 >
2877 struct CrossTrait< StaticVector<T1,3UL,TF>, CompressedVector<T2,TF> >
2878 {
2879  private:
2880  using T = MultTrait_<T1,T2>;
2881 
2882  public:
2883  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2884 };
2885 
2886 template< typename T1, bool TF, typename T2, size_t N >
2887 struct CrossTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2888 {
2889  private:
2890  using T = MultTrait_<T1,T2>;
2891 
2892  public:
2893  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2894 };
2895 
2896 template< typename T1, size_t N, bool TF, typename T2 >
2897 struct CrossTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2898 {
2899  private:
2900  using T = MultTrait_<T1,T2>;
2901 
2902  public:
2903  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2904 };
2905 
2906 template< typename T1, bool TF, typename T2 >
2907 struct CrossTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2908 {
2909  private:
2910  using T = MultTrait_<T1,T2>;
2911 
2912  public:
2913  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2914 };
2915 
2916 template< typename T1, bool TF, typename T2 >
2917 struct CrossTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2918 {
2919  private:
2920  using T = MultTrait_<T1,T2>;
2921 
2922  public:
2923  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2924 };
2925 
2926 template< typename T1, bool TF, typename T2 >
2927 struct CrossTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2928 {
2929  private:
2930  using T = MultTrait_<T1,T2>;
2931 
2932  public:
2933  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2934 };
2936 //*************************************************************************************************
2937 
2938 
2939 
2940 
2941 //=================================================================================================
2942 //
2943 // UNARYMAPTRAIT SPECIALIZATIONS
2944 //
2945 //=================================================================================================
2946 
2947 //*************************************************************************************************
2949 template< typename T, bool TF, typename OP >
2950 struct UnaryMapTrait< CompressedVector<T,TF>, OP >
2951 {
2952  using Type = CompressedVector< UnaryMapTrait_<T,OP>, TF >;
2953 };
2955 //*************************************************************************************************
2956 
2957 
2958 
2959 
2960 //=================================================================================================
2961 //
2962 // HIGHTYPE SPECIALIZATIONS
2963 //
2964 //=================================================================================================
2965 
2966 //*************************************************************************************************
2968 template< typename T1, bool TF, typename T2 >
2969 struct HighType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2970 {
2972 };
2974 //*************************************************************************************************
2975 
2976 
2977 
2978 
2979 //=================================================================================================
2980 //
2981 // MATHTRAIT SPECIALIZATIONS
2982 //
2983 //=================================================================================================
2984 
2985 //*************************************************************************************************
2987 template< typename T1, bool TF, typename T2 >
2988 struct LowType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2989 {
2991 };
2993 //*************************************************************************************************
2994 
2995 
2996 
2997 
2998 //=================================================================================================
2999 //
3000 // SUBVECTORTRAIT SPECIALIZATIONS
3001 //
3002 //=================================================================================================
3003 
3004 //*************************************************************************************************
3006 template< typename T, bool TF >
3007 struct SubvectorTrait< CompressedVector<T,TF> >
3008 {
3009  using Type = CompressedVector<T,TF>;
3010 };
3012 //*************************************************************************************************
3013 
3014 } // namespace blaze
3015 
3016 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
#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
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
#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.
Header file for basic type definitions.
Header file for the SparseVector base class.
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:2068
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1917
Resize mechanism to obtain a CompressedVector with a different fixed number of elements.
Definition: CompressedVector.h:305
Header file for the serial shim.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:216
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1411
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:101
Header file for the IsIntegral type trait.
IteratorBase castUp(Iterator it) const noexcept
Performs an up-cast of the given iterator.
Definition: CompressedVector.h:1489
Header file for the And class template.
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1762
Header file for the DenseVector base class.
void addAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: CompressedVector.h:2137
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
void clear()
Clearing the compressed vector.
Definition: CompressedVector.h:1329
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:250
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:183
Header file for memory allocation and deallocation functionality.
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:474
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1393
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1809
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:688
Constraint on the data type.
Base template for the CrossTrait class.
Definition: CrossTrait.h:116
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:61
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:286
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:120
Efficient implementation of a dynamically sized vector with static memory.The HybridVector class temp...
Definition: Forward.h:59
EnableIf_< IsBuiltin< T >, T *> allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:155
Type ElementType
Type of the compressed vector elements.
Definition: CompressedVector.h:283
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Headerfile for the generic max algorithm.
Header file for the ValueIndexPair class.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition: CompressedVector.h:296
CompressedVector() noexcept
The default constructor for CompressedVector.
Definition: CompressedVector.h:522
Header file for the DisableIf class template.
Iterator set(size_t index, const Type &value)
Setting an element of the compressed vector.
Definition: CompressedVector.h:1518
Header file for the LowType type trait.
Base template for the HighType type trait.
Definition: HighType.h:133
void subAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: CompressedVector.h:2192
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1630
Header file for the multiplication trait.
Header file for the unary map trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5924
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
Header file for the IsShrinkable type trait.
Header file for all forward declarations of the math module.
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1548
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:476
#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
size_t size() const noexcept
Returns the current size/dimension of the compressed vector.
Definition: CompressedVector.h:1268
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:284
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.In case the types T1 and T2 don&#39;t have the same size...
Definition: SameSize.h:60
Header file for the Not class template.
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: CompressedVector.h:1407
Header file for the subvector trait.
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:1299
Iterator castDown(IteratorBase it) const noexcept
Performs a down-cast of the given iterator.
Definition: CompressedVector.h:1471
Constraint on the data type.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:60
Constraint on the data type.
Header file for the exception macros of the math module.
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:75
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:119
typename CrossTrait< T1, T2 >::Type CrossTrait_
Auxiliary alias declaration for the CrossTrait class template.The CrossTrait_ alias declaration provi...
Definition: CrossTrait.h:159
Constraint on the data type.
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:475
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1664
typename DivTrait< T1, T2 >::Type DivTrait_
Auxiliary alias declaration for the DivTrait class template.The DivTrait_ alias declaration provides ...
Definition: DivTrait.h:250
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1869
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1822
Compile time check for shrinkable data types.This type trait tests whether the given data type is a s...
Definition: IsShrinkable.h:75
Header file for the IsNumeric type trait.
Base template for the LowType type trait.
Definition: LowType.h:133
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:1313
Compile time check for resizable data types.This type trait tests whether the given data type is a re...
Definition: IsResizable.h:75
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1353
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:289
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.
Base template for the AddTrait class.
Definition: AddTrait.h:139
Header file for the relaxation flag types.
Base template for the MultTrait class.
Definition: MultTrait.h:139
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Constraint on the data type.
typename If< T1, T2, T3 >::Type If_
Auxiliary alias declaration for the If class template.The If_ alias declaration provides a convenient...
Definition: If.h:154
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition: CompressedVector.h:1444
Reference at(size_t index)
Checked access to the compressed vector elements.
Definition: CompressedVector.h:735
Headerfile for the generic transfer algorithm.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
Header file for the VectorAccessProxy class.
Header file for the isDefault shim.
Constraint on the data type.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:819
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:288
#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
void multAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the multiplication assignment of a dense vector.
Definition: CompressedVector.h:2247
void divAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the division assignment of a dense vector.
Definition: CompressedVector.h:2274
EnableIf_< IsBuiltin< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:230
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: CompressedVector.h:2028
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
Base template for the DivTrait class.
Definition: DivTrait.h:139
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:287
void swap(CompressedVector &sv) noexcept
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1424
ConstIterator cbegin() const noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:807
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
#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
Iterator end() noexcept
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:821
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Constraint on the size of two data types.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:177
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:659
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:878
typename SubTrait< T1, T2 >::Type SubTrait_
Auxiliary alias declaration for the SubTrait class template.The SubTrait_ alias declaration provides ...
Definition: SubTrait.h:250
size_t capacity() const noexcept
Returns the maximum capacity of the compressed vector.
Definition: CompressedVector.h:1282
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:477
Compile time type check.This class tests whether the given template parameter T is an rvalue referenc...
Definition: IsRValueReference.h:77
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:279
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:252
ConstIterator cend() const noexcept
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:851
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:600
Base template for the SubTrait class.
Definition: SubTrait.h:139
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
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition: Transfer.h:70
Iterator begin() noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:777
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:479
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:2008
Header file for the IsResizable type trait.
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:2047
Base template for the UnaryMapTrait class.
Definition: UnaryMapTrait.h:117
#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
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
typename AddTrait< T1, T2 >::Type AddTrait_
Auxiliary alias declaration for the AddTrait class template.The AddTrait_ alias declaration provides ...
Definition: AddTrait.h:250
#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
Efficient implementation of an arbitrary sized sparse vector.The CompressedVector class is the repres...
Definition: CompressedVector.h:197
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:362
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1378
Header file for the HighType type trait.