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>
53 #include <blaze/math/Functions.h>
71 #include <blaze/util/Algorithm.h>
72 #include <blaze/util/Assert.h>
78 #include <blaze/util/DisableIf.h>
79 #include <blaze/util/EnableIf.h>
80 #include <blaze/util/Memory.h>
81 #include <blaze/util/mpl/If.h>
82 #include <blaze/util/Types.h>
86 
87 
88 namespace blaze {
89 
90 //=================================================================================================
91 //
92 // CLASS DEFINITION
93 //
94 //=================================================================================================
95 
96 //*************************************************************************************************
190 template< typename Type // Data type of the vector
191  , bool TF = defaultTransposeFlag > // Transpose flag
192 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
193 {
194  private:
195  //**Type definitions****************************************************************************
197  typedef ElementBase* IteratorBase;
198  //**********************************************************************************************
199 
200  //**Private class Element***********************************************************************
207  struct Element : public ElementBase
208  {
209  //**Constructors*****************************************************************************
210  explicit Element() = default;
211  Element( const Element& rhs ) = default;
212  Element( Element&& rhs ) = default;
213  //*******************************************************************************************
214 
215  //**Assignment operators*********************************************************************
216  inline Element& operator=( const Element& rhs )
217  {
218  this->value_ = rhs.value_;
219  return *this;
220  }
221 
222  inline Element& operator=( Element&& rhs )
223  {
224  this->value_ = std::move( rhs.value_ );
225  return *this;
226  }
227 
228  template< typename Other >
229  inline EnableIf_< IsSparseElement<Other>, Element& >
230  operator=( const Other& rhs )
231  {
232  this->value_ = rhs.value();
233  return *this;
234  }
235 
236  template< typename Other >
238  , IsRValueReference<Other&&> >, Element& >
239  operator=( Other&& rhs )
240  {
241  this->value_ = std::move( rhs.value() );
242  return *this;
243  }
244 
245  template< typename Other >
246  inline EnableIf_< Not< IsSparseElement<Other> >, Element& >
247  operator=( const Other& v )
248  {
249  this->value_ = v;
250  return *this;
251  }
252 
253  template< typename Other >
255  , IsRValueReference<Other&&> >, Element& >
256  operator=( Other&& v )
257  {
258  this->value_ = std::move( v );
259  return *this;
260  }
261  //*******************************************************************************************
262 
263  //**Friend declarations**********************************************************************
264  friend class CompressedVector;
265  //*******************************************************************************************
266  };
268  //**********************************************************************************************
269 
270  public:
271  //**Type definitions****************************************************************************
274  typedef This ResultType;
276  typedef Type ElementType;
277  typedef const Type& ReturnType;
280  typedef const Type& ConstReference;
281  typedef Element* Iterator;
282  typedef const Element* ConstIterator;
283  //**********************************************************************************************
284 
285  //**Rebind struct definition********************************************************************
288  template< typename NewType > // Data type of the other vector
289  struct Rebind {
291  };
292  //**********************************************************************************************
293 
294  //**Resize struct definition********************************************************************
297  template< size_t NewN > // Number of elements of the other vector
298  struct Resize {
300  };
301  //**********************************************************************************************
302 
303  //**Compilation flags***************************************************************************
305 
308  enum : bool { smpAssignable = !IsSMPAssignable<Type>::value };
309  //**********************************************************************************************
310 
311  //**Constructors********************************************************************************
314  explicit inline CompressedVector() noexcept;
315  explicit inline CompressedVector( size_t size ) noexcept;
316  explicit inline CompressedVector( size_t size, size_t nonzeros );
317  inline CompressedVector( const CompressedVector& sv );
318  inline CompressedVector( CompressedVector&& sv ) noexcept;
319  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
320  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
322  //**********************************************************************************************
323 
324  //**Destructor**********************************************************************************
327  inline ~CompressedVector();
329  //**********************************************************************************************
330 
331  //**Data access functions***********************************************************************
334  inline Reference operator[]( size_t index ) noexcept;
335  inline ConstReference operator[]( size_t index ) const noexcept;
336  inline Reference at( size_t index );
337  inline ConstReference at( size_t index ) const;
338  inline Iterator begin () noexcept;
339  inline ConstIterator begin () const noexcept;
340  inline ConstIterator cbegin() const noexcept;
341  inline Iterator end () noexcept;
342  inline ConstIterator end () const noexcept;
343  inline ConstIterator cend () const noexcept;
345  //**********************************************************************************************
346 
347  //**Assignment operators************************************************************************
350  inline CompressedVector& operator=( const CompressedVector& rhs );
351  inline CompressedVector& operator=( CompressedVector&& rhs ) noexcept;
352 
353  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
354  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
355  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
356  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
357  template< typename VT > inline CompressedVector& operator*=( const DenseVector<VT,TF>& rhs );
358  template< typename VT > inline CompressedVector& operator*=( const SparseVector<VT,TF>& rhs );
359  template< typename VT > inline CompressedVector& operator/=( const DenseVector<VT,TF>& rhs );
360 
361  template< typename Other >
362  inline EnableIf_< IsNumeric<Other>, CompressedVector >& operator*=( Other rhs );
363 
364  template< typename Other >
365  inline EnableIf_< IsNumeric<Other>, CompressedVector >& operator/=( Other rhs );
367  //**********************************************************************************************
368 
369  //**Utility functions***************************************************************************
372  inline size_t size() const noexcept;
373  inline size_t capacity() const noexcept;
374  inline size_t nonZeros() const;
375  inline void reset();
376  inline void clear();
377  inline void resize( size_t n, bool preserve=true );
378  void reserve( size_t n );
379  inline void swap( CompressedVector& sv ) noexcept;
381  //**********************************************************************************************
382 
383  //**Insertion functions*************************************************************************
386  inline Iterator set ( size_t index, const Type& value );
387  inline Iterator insert( size_t index, const Type& value );
388  inline void append( size_t index, const Type& value, bool check=false );
390  //**********************************************************************************************
391 
392  //**Erase functions*****************************************************************************
395  inline void erase( size_t index );
396  inline Iterator erase( Iterator pos );
397  inline Iterator erase( Iterator first, Iterator last );
398 
399  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
400  inline void erase( Pred predicate );
401 
402  template< typename Pred >
403  inline void erase( Iterator first, Iterator last, Pred predicate );
405  //**********************************************************************************************
406 
407  //**Lookup functions****************************************************************************
410  inline Iterator find ( size_t index );
411  inline ConstIterator find ( size_t index ) const;
412  inline Iterator lowerBound( size_t index );
413  inline ConstIterator lowerBound( size_t index ) const;
414  inline Iterator upperBound( size_t index );
415  inline ConstIterator upperBound( size_t index ) const;
417  //**********************************************************************************************
418 
419  //**Numeric functions***************************************************************************
422  template< typename Other > inline CompressedVector& scale( const Other& scalar );
424  //**********************************************************************************************
425 
426  //**Expression template evaluation functions****************************************************
429  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
430  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
431 
432  inline bool canSMPAssign() const noexcept;
433 
434  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
435  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
436  template< typename VT > inline void addAssign ( const DenseVector <VT,TF>& rhs );
437  template< typename VT > inline void addAssign ( const SparseVector<VT,TF>& rhs );
438  template< typename VT > inline void subAssign ( const DenseVector <VT,TF>& rhs );
439  template< typename VT > inline void subAssign ( const SparseVector<VT,TF>& rhs );
440  template< typename VT > inline void multAssign( const DenseVector <VT,TF>& rhs );
441  template< typename VT > inline void divAssign ( const DenseVector <VT,TF>& rhs );
443  //**********************************************************************************************
444 
445  private:
446  //**Utility functions***************************************************************************
449  inline size_t extendCapacity() const noexcept;
450  inline Iterator castDown( IteratorBase it ) const noexcept;
451  inline IteratorBase castUp ( Iterator it ) const noexcept;
453  //**********************************************************************************************
454 
455  //**Insertion functions***************************************************************************
458  Iterator insert( Iterator pos, size_t index, const Type& value );
460  //**********************************************************************************************
461 
462  //**Member variables****************************************************************************
465  size_t size_;
466  size_t capacity_;
467  Iterator begin_;
468  Iterator end_;
469 
470  static const Type zero_;
471 
472  //**********************************************************************************************
473 
474  //**Compile time checks*************************************************************************
480  BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE( ElementBase, Element );
482  //**********************************************************************************************
483 };
484 //*************************************************************************************************
485 
486 
487 
488 
489 //=================================================================================================
490 //
491 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
492 //
493 //=================================================================================================
494 
495 template< typename Type // Data type of the vector
496  , bool TF > // Transpose flag
497 const Type CompressedVector<Type,TF>::zero_ = Type();
498 
499 
500 
501 
502 //=================================================================================================
503 //
504 // CONSTRUCTORS
505 //
506 //=================================================================================================
507 
508 //*************************************************************************************************
511 template< typename Type // Data type of the vector
512  , bool TF > // Transpose flag
514  : size_ ( 0UL ) // The current size/dimension of the compressed vector
515  , capacity_( 0UL ) // The maximum capacity of the compressed vector
516  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
517  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
518 {}
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
527 template< typename Type // Data type of the vector
528  , bool TF > // Transpose flag
530  : size_ ( n ) // The current size/dimension of the compressed vector
531  , capacity_( 0UL ) // The maximum capacity of the compressed vector
532  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
533  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
534 {}
535 //*************************************************************************************************
536 
537 
538 //*************************************************************************************************
544 template< typename Type // Data type of the vector
545  , bool TF > // Transpose flag
546 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
547  : size_ ( n ) // The current size/dimension of the compressed vector
548  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
549  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
550  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
551 {}
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
563 template< typename Type // Data type of the vector
564  , bool TF > // Transpose flag
566  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
567  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
568  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
569  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
570 {
571  std::copy( sv.begin_, sv.end_, castUp( begin_ ) );
572 }
573 //*************************************************************************************************
574 
575 
576 //*************************************************************************************************
581 template< typename Type // Data type of the vector
582  , bool TF > // Transpose flag
584  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
585  , capacity_( sv.capacity_ ) // The maximum capacity of the compressed vector
586  , begin_ ( sv.begin_ ) // Pointer to the first non-zero element of the compressed vector
587  , end_ ( sv.end_ ) // Pointer to the last non-zero element of the compressed vector
588 {
589  sv.size_ = 0UL;
590  sv.capacity_ = 0UL;
591  sv.begin_ = nullptr;
592  sv.end_ = nullptr;
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
602 template< typename Type // Data type of the vector
603  , bool TF > // Transpose flag
604 template< typename VT > // Type of the foreign dense vector
606  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
607  , capacity_( 0UL ) // The maximum capacity of the compressed vector
608  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
609  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
610 {
611  using blaze::assign;
612  assign( *this, ~dv );
613 }
614 //*************************************************************************************************
615 
616 
617 //*************************************************************************************************
622 template< typename Type // Data type of the vector
623  , bool TF > // Transpose flag
624 template< typename VT > // Type of the foreign sparse vector
626  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
627  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
628  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
629  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
630 {
631  using blaze::assign;
632  assign( *this, ~sv );
633 }
634 //*************************************************************************************************
635 
636 
637 
638 
639 //=================================================================================================
640 //
641 // DESTRUCTOR
642 //
643 //=================================================================================================
644 
645 //*************************************************************************************************
648 template< typename Type // Data type of the vector
649  , bool TF > // Transpose flag
651 {
652  deallocate( begin_ );
653 }
654 //*************************************************************************************************
655 
656 
657 
658 
659 //=================================================================================================
660 //
661 // DATA ACCESS FUNCTIONS
662 //
663 //=================================================================================================
664 
665 //*************************************************************************************************
676 template< typename Type // Data type of the vector
677  , bool TF > // Transpose flag
679  CompressedVector<Type,TF>::operator[]( size_t index ) noexcept
680 {
681  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
682 
683  return Reference( *this, index );
684 }
685 //*************************************************************************************************
686 
687 
688 //*************************************************************************************************
694 template< typename Type // Data type of the vector
695  , bool TF > // Transpose flag
697  CompressedVector<Type,TF>::operator[]( size_t index ) const noexcept
698 {
699  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
700 
701  const ConstIterator pos( lowerBound( index ) );
702 
703  if( pos == end_ || pos->index_ != index )
704  return zero_;
705  else
706  return pos->value_;
707 }
708 //*************************************************************************************************
709 
710 
711 //*************************************************************************************************
723 template< typename Type // Data type of the vector
724  , bool TF > // Transpose flag
727 {
728  if( index >= size_ ) {
729  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
730  }
731  return (*this)[index];
732 }
733 //*************************************************************************************************
734 
735 
736 //*************************************************************************************************
748 template< typename Type // Data type of the vector
749  , bool TF > // Transpose flag
751  CompressedVector<Type,TF>::at( size_t index ) const
752 {
753  if( index >= size_ ) {
754  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
755  }
756  return (*this)[index];
757 }
758 //*************************************************************************************************
759 
760 
761 //*************************************************************************************************
766 template< typename Type // Data type of the vector
767  , bool TF > // Transpose flag
769 {
770  return Iterator( begin_ );
771 }
772 //*************************************************************************************************
773 
774 
775 //*************************************************************************************************
780 template< typename Type // Data type of the vector
781  , bool TF > // Transpose flag
784 {
785  return ConstIterator( begin_ );
786 }
787 //*************************************************************************************************
788 
789 
790 //*************************************************************************************************
795 template< typename Type // Data type of the vector
796  , bool TF > // Transpose flag
799 {
800  return ConstIterator( begin_ );
801 }
802 //*************************************************************************************************
803 
804 
805 //*************************************************************************************************
810 template< typename Type // Data type of the vector
811  , bool TF > // Transpose flag
813 {
814  return Iterator( end_ );
815 }
816 //*************************************************************************************************
817 
818 
819 //*************************************************************************************************
824 template< typename Type // Data type of the vector
825  , bool TF > // Transpose flag
828 {
829  return ConstIterator( end_ );
830 }
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
839 template< typename Type // Data type of the vector
840  , bool TF > // Transpose flag
843 {
844  return ConstIterator( end_ );
845 }
846 //*************************************************************************************************
847 
848 
849 
850 
851 //=================================================================================================
852 //
853 // ASSIGNMENT OPERATORS
854 //
855 //=================================================================================================
856 
857 //*************************************************************************************************
866 template< typename Type // Data type of the vector
867  , bool TF > // Transpose flag
870 {
871  if( &rhs == this ) return *this;
872 
873  const size_t nonzeros( rhs.nonZeros() );
874 
875  if( nonzeros > capacity_ ) {
876  Iterator newBegin( allocate<Element>( nonzeros ) );
877  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( newBegin ) ) );
878  std::swap( begin_, newBegin );
879  deallocate( newBegin );
880 
881  size_ = rhs.size_;
882  capacity_ = nonzeros;
883  }
884  else {
885  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( begin_ ) ) );
886  size_ = rhs.size_;
887  }
888 
889  return *this;
890 }
891 //*************************************************************************************************
892 
893 
894 //*************************************************************************************************
900 template< typename Type // Data type of the vector
901  , bool TF > // Transpose flag
904 {
905  deallocate( begin_ );
906 
907  size_ = rhs.size_;
908  capacity_ = rhs.capacity_;
909  begin_ = rhs.begin_;
910  end_ = rhs.end_;
911 
912  rhs.size_ = 0UL;
913  rhs.capacity_ = 0UL;
914  rhs.begin_ = nullptr;
915  rhs.end_ = nullptr;
916 
917  return *this;
918 }
919 //*************************************************************************************************
920 
921 
922 //*************************************************************************************************
931 template< typename Type // Data type of the vector
932  , bool TF > // Transpose flag
933 template< typename VT > // Type of the right-hand side dense vector
936 {
937  using blaze::assign;
938 
939  if( (~rhs).canAlias( this ) ) {
940  CompressedVector tmp( ~rhs );
941  swap( tmp );
942  }
943  else {
944  size_ = (~rhs).size();
945  end_ = begin_;
946  assign( *this, ~rhs );
947  }
948 
949  return *this;
950 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
963 template< typename Type // Data type of the vector
964  , bool TF > // Transpose flag
965 template< typename VT > // Type of the right-hand side sparse vector
968 {
969  using blaze::assign;
970 
971  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
972  CompressedVector tmp( ~rhs );
973  swap( tmp );
974  }
975  else {
976  size_ = (~rhs).size();
977  end_ = begin_;
978  assign( *this, ~rhs );
979  }
980 
981  return *this;
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
996 template< typename Type // Data type of the vector
997  , bool TF > // Transpose flag
998 template< typename VT > // Type of the right-hand side vector
1000 {
1001  using blaze::addAssign;
1002 
1003  if( (~rhs).size() != size_ ) {
1004  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1005  }
1006 
1007  addAssign( *this, ~rhs );
1008 
1009  return *this;
1010 }
1011 //*************************************************************************************************
1012 
1013 
1014 //*************************************************************************************************
1024 template< typename Type // Data type of the vector
1025  , bool TF > // Transpose flag
1026 template< typename VT > // Type of the right-hand side vector
1028 {
1029  using blaze::subAssign;
1030 
1031  if( (~rhs).size() != size_ ) {
1032  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1033  }
1034 
1035  subAssign( *this, ~rhs );
1036 
1037  return *this;
1038 }
1039 //*************************************************************************************************
1040 
1041 
1042 //*************************************************************************************************
1053 template< typename Type // Data type of the vector
1054  , bool TF > // Transpose flag
1055 template< typename VT > // Type of the right-hand side vector
1058 {
1059  using blaze::multAssign;
1060 
1061  if( (~rhs).size() != size_ ) {
1062  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1063  }
1064 
1065  if( (~rhs).canAlias( this ) ) {
1066  CompressedVector tmp( *this * (~rhs) );
1067  swap( tmp );
1068  }
1069  else {
1070  CompositeType_<VT> tmp( ~rhs );
1071  multAssign( *this, tmp );
1072  }
1073 
1074  return *this;
1075 }
1076 //*************************************************************************************************
1077 
1078 
1079 //*************************************************************************************************
1090 template< typename Type // Data type of the vector
1091  , bool TF > // Transpose flag
1092 template< typename VT > // Type of the right-hand side vector
1095 {
1096  if( (~rhs).size() != size_ ) {
1097  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1098  }
1099 
1100  CompressedVector tmp( *this * (~rhs) );
1101  swap( tmp );
1102 
1103  return *this;
1104 }
1105 //*************************************************************************************************
1106 
1107 
1108 //*************************************************************************************************
1118 template< typename Type // Data type of the vector
1119  , bool TF > // Transpose flag
1120 template< typename VT > // Type of the right-hand side vector
1122 {
1123  using blaze::divAssign;
1124 
1125  if( (~rhs).size() != size_ ) {
1126  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1127  }
1128 
1129  if( (~rhs).canAlias( this ) ) {
1130  CompressedVector tmp( *this / (~rhs) );
1131  swap( tmp );
1132  }
1133  else {
1134  CompositeType_<VT> tmp( ~rhs );
1135  divAssign( *this, tmp );
1136  }
1137 
1138  return *this;
1139 }
1140 //*************************************************************************************************
1141 
1142 
1143 //*************************************************************************************************
1154 template< typename Type // Data type of the vector
1155  , bool TF > // Transpose flag
1156 template< typename Other > // Data type of the right-hand side scalar
1159 {
1160  for( Iterator element=begin_; element!=end_; ++element )
1161  element->value_ *= rhs;
1162  return *this;
1163 }
1164 //*************************************************************************************************
1165 
1166 
1167 //*************************************************************************************************
1179 template< typename Type // Data type of the vector
1180  , bool TF > // Transpose flag
1181 template< typename Other > // Data type of the right-hand side scalar
1182 inline EnableIf_< IsNumeric<Other>, CompressedVector<Type,TF> >&
1184 {
1185  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1186 
1187  typedef DivTrait_<Type,Other> DT;
1188  typedef If_< IsNumeric<DT>, DT, Other > Tmp;
1189 
1190  // Depending on the two involved data types, an integer division is applied or a
1191  // floating point division is selected.
1193  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1194  for( Iterator element=begin_; element!=end_; ++element )
1195  element->value_ *= tmp;
1196  }
1197  else {
1198  for( Iterator element=begin_; element!=end_; ++element )
1199  element->value_ /= rhs;
1200  }
1201 
1202  return *this;
1203 }
1204 //*************************************************************************************************
1205 
1206 
1207 
1208 
1209 //=================================================================================================
1210 //
1211 // UTILITY FUNCTIONS
1212 //
1213 //=================================================================================================
1214 
1215 //*************************************************************************************************
1220 template< typename Type // Data type of the vector
1221  , bool TF > // Transpose flag
1222 inline size_t CompressedVector<Type,TF>::size() const noexcept
1223 {
1224  return size_;
1225 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1234 template< typename Type // Data type of the vector
1235  , bool TF > // Transpose flag
1236 inline size_t CompressedVector<Type,TF>::capacity() const noexcept
1237 {
1238  return capacity_;
1239 }
1240 //*************************************************************************************************
1241 
1242 
1243 //*************************************************************************************************
1251 template< typename Type // Data type of the vector
1252  , bool TF > // Transpose flag
1254 {
1255  return end_ - begin_;
1256 }
1257 //*************************************************************************************************
1258 
1259 
1260 //*************************************************************************************************
1265 template< typename Type // Data type of the vector
1266  , bool TF > // Transpose flag
1268 {
1269  end_ = begin_;
1270 }
1271 //*************************************************************************************************
1272 
1273 
1274 //*************************************************************************************************
1281 template< typename Type // Data type of the vector
1282  , bool TF > // Transpose flag
1284 {
1285  size_ = 0UL;
1286  end_ = begin_;
1287 }
1288 //*************************************************************************************************
1289 
1290 
1291 //*************************************************************************************************
1305 template< typename Type // Data type of the vector
1306  , bool TF > // Transpose flag
1307 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1308 {
1309  if( preserve ) {
1310  end_ = lowerBound( n );
1311  }
1312  else {
1313  end_ = begin_;
1314  }
1315 
1316  size_ = n;
1317 }
1318 //*************************************************************************************************
1319 
1320 
1321 //*************************************************************************************************
1330 template< typename Type // Data type of the vector
1331  , bool TF > // Transpose flag
1333 {
1334  if( n > capacity_ ) {
1335  const size_t newCapacity( n );
1336 
1337  // Allocating a new data and index array
1338  Iterator newBegin = allocate<Element>( newCapacity );
1339 
1340  // Replacing the old data and index array
1341  end_ = castDown( transfer( begin_, end_, castUp( newBegin ) ) );
1342  std::swap( newBegin, begin_ );
1343  capacity_ = newCapacity;
1344  deallocate( newBegin );
1345  }
1346 }
1347 //*************************************************************************************************
1348 
1349 
1350 //*************************************************************************************************
1356 template< typename Type // Data type of the vector
1357  , bool TF > // Transpose flag
1359 {
1360  std::swap( size_, sv.size_ );
1361  std::swap( capacity_, sv.capacity_ );
1362  std::swap( begin_, sv.begin_ );
1363  std::swap( end_, sv.end_ );
1364 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1376 template< typename Type // Data type of the vector
1377  , bool TF > // Transpose flag
1378 inline size_t CompressedVector<Type,TF>::extendCapacity() const noexcept
1379 {
1380  using blaze::max;
1381  using blaze::min;
1382 
1383  size_t nonzeros( 2UL*capacity_+1UL );
1384  nonzeros = max( nonzeros, 7UL );
1385  nonzeros = min( nonzeros, size_ );
1386 
1387  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1388 
1389  return nonzeros;
1390 }
1391 //*************************************************************************************************
1392 
1393 
1394 //*************************************************************************************************
1402 template< typename Type // Data type of the vector
1403  , bool TF > // Transpose flag
1406 {
1407  return static_cast<Iterator>( it );
1408 }
1409 //*************************************************************************************************
1410 
1411 
1412 //*************************************************************************************************
1420 template< typename Type // Data type of the vector
1421  , bool TF > // Transpose flag
1424 {
1425  return static_cast<IteratorBase>( it );
1426 }
1427 //*************************************************************************************************
1428 
1429 
1430 
1431 
1432 //=================================================================================================
1433 //
1434 // INSERTION FUNCTIONS
1435 //
1436 //=================================================================================================
1437 
1438 //*************************************************************************************************
1449 template< typename Type // Data type of the vector
1450  , bool TF > // Transpose flag
1452  CompressedVector<Type,TF>::set( size_t index, const Type& value )
1453 {
1454  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1455 
1456  const Iterator pos( lowerBound( index ) );
1457 
1458  if( pos != end_ && pos->index_ == index ) {
1459  pos->value() = value;
1460  return pos;
1461  }
1462  else return insert( pos, index, value );
1463 }
1464 //*************************************************************************************************
1465 
1466 
1467 //*************************************************************************************************
1479 template< typename Type // Data type of the vector
1480  , bool TF > // Transpose flag
1482  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1483 {
1484  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1485 
1486  const Iterator pos( lowerBound( index ) );
1487 
1488  if( pos != end_ && pos->index_ == index ) {
1489  BLAZE_THROW_INVALID_ARGUMENT( "Bad access index" );
1490  }
1491 
1492  return insert( pos, index, value );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1506 template< typename Type // Data type of the vector
1507  , bool TF > // Transpose flag
1509  CompressedVector<Type,TF>::insert( Iterator pos, size_t index, const Type& value )
1510 {
1511  if( nonZeros() != capacity_ ) {
1512  std::move_backward( pos, end_, castUp( end_+1 ) );
1513  pos->value_ = value;
1514  pos->index_ = index;
1515  ++end_;
1516 
1517  return pos;
1518  }
1519  else {
1520  size_t newCapacity( extendCapacity() );
1521 
1522  Iterator newBegin = allocate<Element>( newCapacity );
1523  Iterator tmp = castDown( std::move( begin_, pos, castUp( newBegin ) ) );
1524  tmp->value_ = value;
1525  tmp->index_ = index;
1526  end_ = castDown( std::move( pos, end_, castUp( tmp+1 ) ) );
1527 
1528  std::swap( newBegin, begin_ );
1529  deallocate( newBegin );
1530  capacity_ = newCapacity;
1531 
1532  return tmp;
1533  }
1534 }
1535 //*************************************************************************************************
1536 
1537 
1538 //*************************************************************************************************
1562 template< typename Type // Data type of the vector
1563  , bool TF > // Transpose flag
1564 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1565 {
1566  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1567  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved capacity" );
1568  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1569 
1570  end_->value_ = value;
1571 
1572  if( !check || !isDefault<strict>( end_->value_ ) ) {
1573  end_->index_ = index;
1574  ++end_;
1575  }
1576 }
1577 //*************************************************************************************************
1578 
1579 
1580 
1581 
1582 //=================================================================================================
1583 //
1584 // ERASE FUNCTIONS
1585 //
1586 //=================================================================================================
1587 
1588 //*************************************************************************************************
1596 template< typename Type // Data type of the vector
1597  , bool TF > // Transpose flag
1598 inline void CompressedVector<Type,TF>::erase( size_t index )
1599 {
1600  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1601 
1602  const Iterator pos( find( index ) );
1603  if( pos != end_ )
1604  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1605 }
1606 //*************************************************************************************************
1607 
1608 
1609 //*************************************************************************************************
1617 template< typename Type // Data type of the vector
1618  , bool TF > // Transpose flag
1621 {
1622  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1623 
1624  if( pos != end_ )
1625  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1626  return pos;
1627 }
1628 //*************************************************************************************************
1629 
1630 
1631 //*************************************************************************************************
1640 template< typename Type // Data type of the vector
1641  , bool TF > // Transpose flag
1644 {
1645  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1646  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1647  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1648 
1649  if( first != last )
1650  end_ = castDown( std::move( last, end_, castUp( first ) ) );
1651  return first;
1652 }
1653 //*************************************************************************************************
1654 
1655 
1656 //*************************************************************************************************
1677 template< typename Type // Data type of the vector
1678  , bool TF > // Transpose flag
1679 template< typename Pred // Type of the unary predicate
1680  , typename > // Type restriction on the unary predicate
1681 inline void CompressedVector<Type,TF>::erase( Pred predicate )
1682 {
1683  end_ = castDown( std::remove_if( castUp( begin_ ), castUp( end_ ),
1684  [predicate=predicate]( const ElementBase& element ) {
1685  return predicate( element.value() );
1686  } ) );
1687 }
1688 //*************************************************************************************************
1689 
1690 
1691 //*************************************************************************************************
1714 template< typename Type // Data type of the vector
1715  , bool TF > // Transpose flag
1716 template< typename Pred > // Type of the unary predicate
1717 inline void CompressedVector<Type,TF>::erase( Iterator first, Iterator last, Pred predicate )
1718 {
1719  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1720  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1721  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1722 
1723  const auto pos = std::remove_if( castUp( first ), castUp( last ),
1724  [predicate=predicate]( const ElementBase& element ) {
1725  return predicate( element.value() );
1726  } );
1727 
1728  end_ = castDown( std::move( last, end_, pos ) );
1729 }
1730 //*************************************************************************************************
1731 
1732 
1733 
1734 
1735 //=================================================================================================
1736 //
1737 // LOOKUP FUNCTIONS
1738 //
1739 //=================================================================================================
1740 
1741 //*************************************************************************************************
1754 template< typename Type // Data type of the vector
1755  , bool TF > // Transpose flag
1757 {
1758  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1759 }
1760 //*************************************************************************************************
1761 
1762 
1763 //*************************************************************************************************
1776 template< typename Type // Data type of the vector
1777  , bool TF > // Transpose flag
1779 {
1780  const ConstIterator pos( lowerBound( index ) );
1781  if( pos != end_ && pos->index_ == index )
1782  return pos;
1783  else return end_;
1784 }
1785 //*************************************************************************************************
1786 
1787 
1788 //*************************************************************************************************
1800 template< typename Type // Data type of the vector
1801  , bool TF > // Transpose flag
1804 {
1805  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1806 }
1807 //*************************************************************************************************
1808 
1809 
1810 //*************************************************************************************************
1822 template< typename Type // Data type of the vector
1823  , bool TF > // Transpose flag
1826 {
1827  return std::lower_bound( begin_, end_, index,
1828  []( const Element& element, size_t i )
1829  {
1830  return element.index() < i;
1831  } );
1832 }
1833 //*************************************************************************************************
1834 
1835 
1836 //*************************************************************************************************
1848 template< typename Type // Data type of the vector
1849  , bool TF > // Transpose flag
1852 {
1853  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1854 }
1855 //*************************************************************************************************
1856 
1857 
1858 //*************************************************************************************************
1870 template< typename Type // Data type of the vector
1871  , bool TF > // Transpose flag
1874 {
1875  return std::upper_bound( begin_, end_, index,
1876  []( size_t i, const Element& element )
1877  {
1878  return i < element.index();
1879  } );
1880 }
1881 //*************************************************************************************************
1882 
1883 
1884 
1885 
1886 //=================================================================================================
1887 //
1888 // NUMERIC FUNCTIONS
1889 //
1890 //=================================================================================================
1891 
1892 //*************************************************************************************************
1898 template< typename Type // Data type of the vector
1899  , bool TF > // Transpose flag
1900 template< typename Other > // Data type of the scalar value
1902 {
1903  for( Iterator element=begin_; element!=end_; ++element )
1904  element->value_ *= scalar;
1905  return *this;
1906 }
1907 //*************************************************************************************************
1908 
1909 
1910 
1911 
1912 //=================================================================================================
1913 //
1914 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1915 //
1916 //=================================================================================================
1917 
1918 //*************************************************************************************************
1928 template< typename Type // Data type of the vector
1929  , bool TF > // Transpose flag
1930 template< typename Other > // Data type of the foreign expression
1931 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const noexcept
1932 {
1933  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1934 }
1935 //*************************************************************************************************
1936 
1937 
1938 //*************************************************************************************************
1948 template< typename Type // Data type of the vector
1949  , bool TF > // Transpose flag
1950 template< typename Other > // Data type of the foreign expression
1951 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const noexcept
1952 {
1953  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1954 }
1955 //*************************************************************************************************
1956 
1957 
1958 //*************************************************************************************************
1968 template< typename Type // Data type of the vector
1969  , bool TF > // Transpose flag
1970 inline bool CompressedVector<Type,TF>::canSMPAssign() const noexcept
1971 {
1972  return false;
1973 }
1974 //*************************************************************************************************
1975 
1976 
1977 //*************************************************************************************************
1988 template< typename Type // Data type of the vector
1989  , bool TF > // Transpose flag
1990 template< typename VT > // Type of the right-hand side dense vector
1992 {
1993  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1994  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1995 
1996  size_t nonzeros( 0UL );
1997 
1998  for( size_t i=0UL; i<size_; ++i )
1999  {
2000  if( nonzeros == capacity_ )
2001  reserve( extendCapacity() );
2002 
2003  end_->value_ = (~rhs)[i];
2004 
2005  if( !isDefault<strict>( end_->value_ ) ) {
2006  end_->index_ = i;
2007  ++end_;
2008  ++nonzeros;
2009  }
2010  }
2011 }
2012 //*************************************************************************************************
2013 
2014 
2015 //*************************************************************************************************
2026 template< typename Type // Data type of the vector
2027  , bool TF > // Transpose flag
2028 template< typename VT > // Type of the right-hand side sparse vector
2030 {
2031  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2032  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2033 
2034  // Using the following formulation instead of a std::copy function call of the form
2035  //
2036  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
2037  //
2038  // results in much less requirements on the ConstIterator type provided from the right-hand
2039  // sparse vector type
2040  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2041  append( element->index(), element->value() );
2042 }
2043 //*************************************************************************************************
2044 
2045 
2046 //*************************************************************************************************
2057 template< typename Type // Data type of the vector
2058  , bool TF > // Transpose flag
2059 template< typename VT > // Type of the right-hand side dense vector
2061 {
2062  typedef AddTrait_< This, ResultType_<VT> > AddType;
2063 
2067 
2068  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2069 
2070  const AddType tmp( serial( *this + (~rhs) ) );
2071  reset();
2072  assign( tmp );
2073 }
2074 //*************************************************************************************************
2075 
2076 
2077 //*************************************************************************************************
2088 template< typename Type // Data type of the vector
2089  , bool TF > // Transpose flag
2090 template< typename VT > // Type of the right-hand side sparse vector
2092 {
2093  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2094 
2095  CompressedVector tmp( serial( *this + (~rhs) ) );
2096  swap( tmp );
2097 }
2098 //*************************************************************************************************
2099 
2100 
2101 //*************************************************************************************************
2112 template< typename Type // Data type of the vector
2113  , bool TF > // Transpose flag
2114 template< typename VT > // Type of the right-hand side dense vector
2116 {
2117  typedef SubTrait_< This, ResultType_<VT> > SubType;
2118 
2122 
2123  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2124 
2125  const SubType tmp( serial( *this - (~rhs) ) );
2126  reset();
2127  assign( tmp );
2128 }
2129 //*************************************************************************************************
2130 
2131 
2132 //*************************************************************************************************
2143 template< typename Type // Data type of the vector
2144  , bool TF > // Transpose flag
2145 template< typename VT > // Type of the right-hand side sparse vector
2147 {
2148  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2149 
2150  CompressedVector tmp( serial( *this - (~rhs) ) );
2151  swap( tmp );
2152 }
2153 //*************************************************************************************************
2154 
2155 
2156 //*************************************************************************************************
2167 template< typename Type // Data type of the vector
2168  , bool TF > // Transpose flag
2169 template< typename VT > // Type of the right-hand side dense vector
2171 {
2172  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2173 
2175 
2176  for( Iterator element=begin_; element!=end_; ++element ) {
2177  element->value_ *= (~rhs)[element->index_];
2178  }
2179 }
2180 //*************************************************************************************************
2181 
2182 
2183 //*************************************************************************************************
2194 template< typename Type // Data type of the vector
2195  , bool TF > // Transpose flag
2196 template< typename VT > // Type of the right-hand side dense vector
2198 {
2199  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2200 
2202 
2203  for( Iterator element=begin_; element!=end_; ++element ) {
2204  element->value_ /= (~rhs)[element->index_];
2205  }
2206 }
2207 //*************************************************************************************************
2208 
2209 
2210 
2211 
2212 //=================================================================================================
2213 //
2214 // COMPRESSEDVECTOR OPERATORS
2215 //
2216 //=================================================================================================
2217 
2218 //*************************************************************************************************
2221 template< typename Type, bool TF >
2222 inline void reset( CompressedVector<Type,TF>& v );
2223 
2224 template< typename Type, bool TF >
2225 inline void clear( CompressedVector<Type,TF>& v );
2226 
2227 template< bool RF, typename Type, bool TF >
2228 inline bool isDefault( const CompressedVector<Type,TF>& v );
2229 
2230 template< typename Type, bool TF >
2231 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept;
2232 
2233 template< typename Type, bool TF >
2234 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) noexcept;
2236 //*************************************************************************************************
2237 
2238 
2239 //*************************************************************************************************
2246 template< typename Type // Data type of the vector
2247  , bool TF > // Transpose flag
2249 {
2250  v.reset();
2251 }
2252 //*************************************************************************************************
2253 
2254 
2255 //*************************************************************************************************
2262 template< typename Type // Data type of the vector
2263  , bool TF > // Transpose flag
2265 {
2266  v.clear();
2267 }
2268 //*************************************************************************************************
2269 
2270 
2271 //*************************************************************************************************
2295 template< bool RF // Relaxation flag
2296  , typename Type // Data type of the vector
2297  , bool TF > // Transpose flag
2298 inline bool isDefault( const CompressedVector<Type,TF>& v )
2299 {
2300  return ( v.size() == 0UL );
2301 }
2302 //*************************************************************************************************
2303 
2304 
2305 //*************************************************************************************************
2323 template< typename Type // Data type of the vector
2324  , bool TF > // Transpose flag
2325 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept
2326 {
2327  return ( v.nonZeros() <= v.capacity() );
2328 }
2329 //*************************************************************************************************
2330 
2331 
2332 //*************************************************************************************************
2340 template< typename Type // Data type of the vector
2341  , bool TF > // Transpose flag
2343 {
2344  a.swap( b );
2345 }
2346 //*************************************************************************************************
2347 
2348 
2349 
2350 
2351 //=================================================================================================
2352 //
2353 // ISRESIZABLE SPECIALIZATIONS
2354 //
2355 //=================================================================================================
2356 
2357 //*************************************************************************************************
2359 template< typename T, bool TF >
2360 struct IsResizable< CompressedVector<T,TF> > : public TrueType
2361 {};
2363 //*************************************************************************************************
2364 
2365 
2366 
2367 
2368 //=================================================================================================
2369 //
2370 // ADDTRAIT SPECIALIZATIONS
2371 //
2372 //=================================================================================================
2373 
2374 //*************************************************************************************************
2376 template< typename T1, bool TF, typename T2, size_t N >
2377 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2378 {
2379  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2380 };
2381 
2382 template< typename T1, size_t N, bool TF, typename T2 >
2383 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2384 {
2385  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2386 };
2387 
2388 template< typename T1, bool TF, typename T2, size_t N >
2389 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2390 {
2391  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2392 };
2393 
2394 template< typename T1, size_t N, bool TF, typename T2 >
2395 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2396 {
2397  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2398 };
2399 
2400 template< typename T1, bool TF, typename T2 >
2401 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2402 {
2403  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2404 };
2405 
2406 template< typename T1, bool TF, typename T2 >
2407 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2408 {
2409  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2410 };
2411 
2412 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2413 struct AddTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2414 {
2415  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2416 };
2417 
2418 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2419 struct AddTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2420 {
2421  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2422 };
2423 
2424 template< typename T1, bool TF, typename T2 >
2425 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2426 {
2427  using Type = CompressedVector< AddTrait_<T1,T2>, TF >;
2428 };
2430 //*************************************************************************************************
2431 
2432 
2433 
2434 
2435 //=================================================================================================
2436 //
2437 // SUBTRAIT SPECIALIZATIONS
2438 //
2439 //=================================================================================================
2440 
2441 //*************************************************************************************************
2443 template< typename T1, bool TF, typename T2, size_t N >
2444 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2445 {
2446  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2447 };
2448 
2449 template< typename T1, size_t N, bool TF, typename T2 >
2450 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2451 {
2452  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2453 };
2454 
2455 template< typename T1, bool TF, typename T2, size_t N >
2456 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2457 {
2458  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2459 };
2460 
2461 template< typename T1, size_t N, bool TF, typename T2 >
2462 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2463 {
2464  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2465 };
2466 
2467 template< typename T1, bool TF, typename T2 >
2468 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2469 {
2470  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2471 };
2472 
2473 template< typename T1, bool TF, typename T2 >
2474 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2475 {
2476  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2477 };
2478 
2479 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2480 struct SubTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2481 {
2482  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2483 };
2484 
2485 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2486 struct SubTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2487 {
2488  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2489 };
2490 
2491 template< typename T1, bool TF, typename T2 >
2492 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2493 {
2494  using Type = CompressedVector< SubTrait_<T1,T2>, TF >;
2495 };
2497 //*************************************************************************************************
2498 
2499 
2500 
2501 
2502 //=================================================================================================
2503 //
2504 // MULTTRAIT SPECIALIZATIONS
2505 //
2506 //=================================================================================================
2507 
2508 //*************************************************************************************************
2510 template< typename T1, bool TF, typename T2 >
2511 struct MultTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2512 {
2513  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2514 };
2515 
2516 template< typename T1, typename T2, bool TF >
2517 struct MultTrait< T1, CompressedVector<T2,TF>, EnableIf_< IsNumeric<T1> > >
2518 {
2519  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2520 };
2521 
2522 template< typename T1, bool TF, typename T2, size_t N >
2523 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2524 {
2525  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2526 };
2527 
2528 template< typename T1, typename T2, size_t N >
2529 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
2530 {
2531  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2532 };
2533 
2534 template< typename T1, typename T2, size_t N >
2535 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
2536 {
2537  using Type = MultTrait_<T1,T2>;
2538 };
2539 
2540 template< typename T1, size_t N, bool TF, typename T2 >
2541 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2542 {
2543  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2544 };
2545 
2546 template< typename T1, size_t N, typename T2 >
2547 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2548 {
2549  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2550 };
2551 
2552 template< typename T1, size_t N, typename T2 >
2553 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2554 {
2555  using Type = MultTrait_<T1,T2>;
2556 };
2557 
2558 template< typename T1, bool TF, typename T2, size_t N >
2559 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2560 {
2561  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2562 };
2563 
2564 template< typename T1, typename T2, size_t N >
2565 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2566 {
2567  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2568 };
2569 
2570 template< typename T1, typename T2, size_t N >
2571 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2572 {
2573  using Type = MultTrait_<T1,T2>;
2574 };
2575 
2576 template< typename T1, size_t N, bool TF, typename T2 >
2577 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2578 {
2579  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2580 };
2581 
2582 template< typename T1, size_t N, typename T2 >
2583 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2584 {
2585  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2586 };
2587 
2588 template< typename T1, size_t N, typename T2 >
2589 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2590 {
2591  using Type = MultTrait_<T1,T2>;
2592 };
2593 
2594 template< typename T1, bool TF, typename T2 >
2595 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2596 {
2597  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2598 };
2599 
2600 template< typename T1, typename T2 >
2601 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2602 {
2603  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2604 };
2605 
2606 template< typename T1, typename T2 >
2607 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2608 {
2609  using Type = MultTrait_<T1,T2>;
2610 };
2611 
2612 template< typename T1, bool TF, typename T2 >
2613 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2614 {
2615  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2616 };
2617 
2618 template< typename T1, typename T2 >
2619 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2620 {
2621  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2622 };
2623 
2624 template< typename T1, typename T2 >
2625 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2626 {
2627  using Type = MultTrait_<T1,T2>;
2628 };
2629 
2630 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2631 struct MultTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2632 {
2633  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2634 };
2635 
2636 template< typename T1, typename T2, bool AF, bool PF >
2637 struct MultTrait< CompressedVector<T1,false>, CustomVector<T2,AF,PF,true> >
2638 {
2639  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2640 };
2641 
2642 template< typename T1, typename T2, bool AF, bool PF >
2643 struct MultTrait< CompressedVector<T1,true>, CustomVector<T2,AF,PF,false> >
2644 {
2645  using Type = MultTrait_<T1,T2>;
2646 };
2647 
2648 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2649 struct MultTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2650 {
2651  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2652 };
2653 
2654 template< typename T1, bool AF, bool PF, typename T2 >
2655 struct MultTrait< CustomVector<T1,AF,PF,false>, CompressedVector<T2,true> >
2656 {
2657  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2658 };
2659 
2660 template< typename T1, bool AF, bool PF, typename T2 >
2661 struct MultTrait< CustomVector<T1,AF,PF,true>, CompressedVector<T2,false> >
2662 {
2663  using Type = MultTrait_<T1,T2>;
2664 };
2665 
2666 template< typename T1, bool TF, typename T2 >
2667 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2668 {
2669  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2670 };
2671 
2672 template< typename T1, typename T2 >
2673 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2674 {
2675  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2676 };
2677 
2678 template< typename T1, typename T2 >
2679 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2680 {
2681  using Type = MultTrait_<T1,T2>;
2682 };
2684 //*************************************************************************************************
2685 
2686 
2687 
2688 
2689 //=================================================================================================
2690 //
2691 // CROSSTRAIT SPECIALIZATIONS
2692 //
2693 //=================================================================================================
2694 
2695 //*************************************************************************************************
2697 template< typename T1, bool TF, typename T2 >
2698 struct CrossTrait< CompressedVector<T1,TF>, StaticVector<T2,3UL,TF> >
2699 {
2700  private:
2701  using T = MultTrait_<T1,T2>;
2702 
2703  public:
2704  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2705 };
2706 
2707 template< typename T1, bool TF, typename T2 >
2708 struct CrossTrait< StaticVector<T1,3UL,TF>, CompressedVector<T2,TF> >
2709 {
2710  private:
2711  using T = MultTrait_<T1,T2>;
2712 
2713  public:
2714  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2715 };
2716 
2717 template< typename T1, bool TF, typename T2, size_t N >
2718 struct CrossTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2719 {
2720  private:
2721  using T = MultTrait_<T1,T2>;
2722 
2723  public:
2724  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2725 };
2726 
2727 template< typename T1, size_t N, bool TF, typename T2 >
2728 struct CrossTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2729 {
2730  private:
2731  using T = MultTrait_<T1,T2>;
2732 
2733  public:
2734  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2735 };
2736 
2737 template< typename T1, bool TF, typename T2 >
2738 struct CrossTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2739 {
2740  private:
2741  using T = MultTrait_<T1,T2>;
2742 
2743  public:
2744  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2745 };
2746 
2747 template< typename T1, bool TF, typename T2 >
2748 struct CrossTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2749 {
2750  private:
2751  using T = MultTrait_<T1,T2>;
2752 
2753  public:
2754  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2755 };
2756 
2757 template< typename T1, bool TF, typename T2 >
2758 struct CrossTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2759 {
2760  private:
2761  using T = MultTrait_<T1,T2>;
2762 
2763  public:
2764  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2765 };
2767 //*************************************************************************************************
2768 
2769 
2770 
2771 
2772 //=================================================================================================
2773 //
2774 // DIVTRAIT SPECIALIZATIONS
2775 //
2776 //=================================================================================================
2777 
2778 //*************************************************************************************************
2780 template< typename T1, bool TF, typename T2 >
2781 struct DivTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2782 {
2783  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2784 };
2785 
2786 template< typename T1, bool TF, typename T2, size_t N >
2787 struct DivTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2788 {
2789  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2790 };
2791 
2792 template< typename T1, size_t N, bool TF, typename T2 >
2793 struct DivTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2794 {
2795  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2796 };
2797 
2798 template< typename T1, bool TF, typename T2, size_t N >
2799 struct DivTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2800 {
2801  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2802 };
2803 
2804 template< typename T1, size_t N, bool TF, typename T2 >
2805 struct DivTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2806 {
2807  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2808 };
2809 
2810 template< typename T1, bool TF, typename T2 >
2811 struct DivTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2812 {
2813  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2814 };
2815 
2816 template< typename T1, bool TF, typename T2 >
2817 struct DivTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2818 {
2819  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2820 };
2821 
2822 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2823 struct DivTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2824 {
2825  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2826 };
2827 
2828 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2829 struct DivTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2830 {
2831  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2832 };
2833 
2834 template< typename T1, bool TF, typename T2 >
2835 struct DivTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2836 {
2837  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2838 };
2840 //*************************************************************************************************
2841 
2842 
2843 
2844 
2845 //=================================================================================================
2846 //
2847 // HIGHTYPE SPECIALIZATIONS
2848 //
2849 //=================================================================================================
2850 
2851 //*************************************************************************************************
2853 template< typename T1, bool TF, typename T2 >
2854 struct HighType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2855 {
2857 };
2859 //*************************************************************************************************
2860 
2861 
2862 
2863 
2864 //=================================================================================================
2865 //
2866 // MATHTRAIT SPECIALIZATIONS
2867 //
2868 //=================================================================================================
2869 
2870 //*************************************************************************************************
2872 template< typename T1, bool TF, typename T2 >
2873 struct LowType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2874 {
2876 };
2878 //*************************************************************************************************
2879 
2880 
2881 
2882 
2883 //=================================================================================================
2884 //
2885 // SUBVECTORTRAIT SPECIALIZATIONS
2886 //
2887 //=================================================================================================
2888 
2889 //*************************************************************************************************
2891 template< typename T1, bool TF >
2892 struct SubvectorTrait< CompressedVector<T1,TF> >
2893 {
2894  using Type = CompressedVector<T1,TF>;
2895 };
2897 //*************************************************************************************************
2898 
2899 } // namespace blaze
2900 
2901 #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.
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
Header file for mathematical functions.
#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:1991
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1851
Resize mechanism to obtain a CompressedVector with a different fixed number of elements.
Definition: CompressedVector.h:298
Header file for the serial shim.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:196
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:1339
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:275
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:101
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:279
Header file for the IsIntegral type trait.
IteratorBase castUp(Iterator it) const noexcept
Performs an up-cast of the given iterator.
Definition: CompressedVector.h:1423
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:280
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition: Algorithm.h:71
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1755
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:2060
#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:1283
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:245
ElementBase * IteratorBase
Iterator over non-constant base elements.
Definition: CompressedVector.h:197
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:177
Header file for memory allocation and deallocation functionality.
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:465
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1321
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:278
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1802
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:679
Constraint on the data type.
Base template for the CrossTrait class.
Definition: CrossTrait.h:110
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:61
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:150
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Header file for the ValueIndexPair class.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition: CompressedVector.h:289
CompressedVector() noexcept
The default constructor for CompressedVector.
Definition: CompressedVector.h:513
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:1452
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:2115
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1564
Header file for the multiplication trait.
CompressedVector< NewType, TF > Other
The type of the other CompressedVector.
Definition: CompressedVector.h:290
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:5635
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
constexpr bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
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:1482
#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:467
#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:1222
#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 subvector trait.
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:1253
Iterator castDown(IteratorBase it) const noexcept
Performs a down-cast of the given iterator.
Definition: CompressedVector.h:1405
Constraint on the data type.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:277
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
Constraint on the data type.
Headerfile for generic algorithms.
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:466
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:274
CompressedVector< Type, TF > Other
The type of the other CompressedVector.
Definition: CompressedVector.h:299
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1598
typename DivTrait< T1, T2 >::Type DivTrait_
Auxiliary alias declaration for the DivTrait class template.The DivTrait_ alias declaration provides ...
Definition: DivTrait.h:245
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1803
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1756
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:1267
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:1307
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1285
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:143
Header file for the relaxation flag types.
Base template for the MultTrait class.
Definition: MultTrait.h:143
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:160
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition: CompressedVector.h:1378
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:272
Reference at(size_t index)
Checked access to the compressed vector elements.
Definition: CompressedVector.h:726
#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.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:282
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:281
Constraint on the data type.
#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:2170
void divAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the division assignment of a dense vector.
Definition: CompressedVector.h:2197
EnableIf_< IsBuiltin< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:225
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: CompressedVector.h:1951
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
Base template for the DivTrait class.
Definition: DivTrait.h:143
void swap(CompressedVector &sv) noexcept
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1358
ConstIterator cbegin() const noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:798
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:812
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:164
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:650
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:869
SparseVector< This, TF > BaseType
Base type of this CompressedVector instance.
Definition: CompressedVector.h:273
typename SubTrait< T1, T2 >::Type SubTrait_
Auxiliary alias declaration for the SubTrait class template.The SubTrait_ alias declaration provides ...
Definition: SubTrait.h:245
size_t capacity() const noexcept
Returns the maximum capacity of the compressed vector.
Definition: CompressedVector.h:1236
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:120
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:468
Compile time type check.This class tests whether the given template parameter T is an rvalue referenc...
Definition: IsRValueReference.h:77
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:249
ConstIterator cend() const noexcept
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:842
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Base template for the SubTrait class.
Definition: SubTrait.h:143
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1303
Iterator begin() noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:768
Type ElementType
Type of the compressed vector elements.
Definition: CompressedVector.h:276
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:470
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1931
Header file for the IsResizable type trait.
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:1970
#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:245
#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:192
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:361
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1332
Header file for the HighType type trait.