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>
77 #include <blaze/util/Assert.h>
83 #include <blaze/util/DisableIf.h>
84 #include <blaze/util/EnableIf.h>
85 #include <blaze/util/Memory.h>
86 #include <blaze/util/mpl/And.h>
87 #include <blaze/util/mpl/If.h>
88 #include <blaze/util/mpl/Not.h>
89 #include <blaze/util/Types.h>
93 
94 
95 namespace blaze {
96 
97 //=================================================================================================
98 //
99 // CLASS DEFINITION
100 //
101 //=================================================================================================
102 
103 //*************************************************************************************************
197 template< typename Type // Data type of the vector
198  , bool TF = defaultTransposeFlag > // Transpose flag
200  : public SparseVector< CompressedVector<Type,TF>, TF >
201 {
202  private:
203  //**Type definitions****************************************************************************
206  //**********************************************************************************************
207 
208  //**Private class Element***********************************************************************
215  struct Element
216  : public ElementBase
217  {
218  //**Constructors*****************************************************************************
219  explicit Element() = default;
220  Element( const Element& rhs ) = default;
221  Element( Element&& rhs ) = default;
222  //*******************************************************************************************
223 
224  //**Assignment operators*********************************************************************
225  inline Element& operator=( const Element& rhs )
226  {
227  this->value_ = rhs.value_;
228  return *this;
229  }
230 
231  inline Element& operator=( Element&& rhs )
232  {
233  this->value_ = std::move( rhs.value_ );
234  return *this;
235  }
236 
237  template< typename Other >
238  inline EnableIf_< IsSparseElement<Other>, Element& >
239  operator=( const Other& rhs )
240  {
241  this->value_ = rhs.value();
242  return *this;
243  }
244 
245  template< typename Other >
247  , IsRValueReference<Other&&> >, Element& >
248  operator=( Other&& rhs )
249  {
250  this->value_ = std::move( rhs.value() );
251  return *this;
252  }
253 
254  template< typename Other >
255  inline EnableIf_< Not< IsSparseElement<Other> >, Element& >
256  operator=( const Other& v )
257  {
258  this->value_ = v;
259  return *this;
260  }
261 
262  template< typename Other >
264  , IsRValueReference<Other&&> >, Element& >
265  operator=( Other&& v )
266  {
267  this->value_ = std::move( v );
268  return *this;
269  }
270  //*******************************************************************************************
271 
272  //**Friend declarations**********************************************************************
273  friend class CompressedVector;
274  //*******************************************************************************************
275  };
277  //**********************************************************************************************
278 
279  public:
280  //**Type definitions****************************************************************************
283  using ResultType = This;
285  using ElementType = Type;
286  using ReturnType = const Type&;
289  using ConstReference = const Type&;
290  using Iterator = Element*;
291  using ConstIterator = const Element*;
292  //**********************************************************************************************
293 
294  //**Rebind struct definition********************************************************************
297  template< typename NewType > // Data type of the other vector
298  struct Rebind {
300  };
301  //**********************************************************************************************
302 
303  //**Resize struct definition********************************************************************
306  template< size_t NewN > // Number of elements of the other vector
307  struct Resize {
309  };
310  //**********************************************************************************************
311 
312  //**Compilation flags***************************************************************************
314 
317  enum : bool { smpAssignable = !IsSMPAssignable<Type>::value };
318  //**********************************************************************************************
319 
320  //**Constructors********************************************************************************
323  explicit inline CompressedVector() noexcept;
324  explicit inline CompressedVector( size_t size ) noexcept;
325  explicit inline CompressedVector( size_t size, size_t nonzeros );
326  explicit inline CompressedVector( initializer_list<Type> list );
327 
328  inline CompressedVector( const CompressedVector& sv );
329  inline CompressedVector( CompressedVector&& sv ) noexcept;
330 
331  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
332  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
334  //**********************************************************************************************
335 
336  //**Destructor**********************************************************************************
339  inline ~CompressedVector();
341  //**********************************************************************************************
342 
343  //**Data access functions***********************************************************************
346  inline Reference operator[]( size_t index ) noexcept;
347  inline ConstReference operator[]( size_t index ) const noexcept;
348  inline Reference at( size_t index );
349  inline ConstReference at( size_t index ) const;
350  inline Iterator begin () noexcept;
351  inline ConstIterator begin () const noexcept;
352  inline ConstIterator cbegin() const noexcept;
353  inline Iterator end () noexcept;
354  inline ConstIterator end () const noexcept;
355  inline ConstIterator cend () const noexcept;
357  //**********************************************************************************************
358 
359  //**Assignment operators************************************************************************
363  inline CompressedVector& operator=( const CompressedVector& rhs );
364  inline CompressedVector& operator=( CompressedVector&& rhs ) noexcept;
365 
366  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
367  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
368  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
369  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
370  template< typename VT > inline CompressedVector& operator*=( const DenseVector<VT,TF>& rhs );
371  template< typename VT > inline CompressedVector& operator*=( const SparseVector<VT,TF>& rhs );
372  template< typename VT > inline CompressedVector& operator/=( const DenseVector<VT,TF>& rhs );
373  template< typename VT > inline CompressedVector& operator%=( const Vector<VT,TF>& rhs );
375  //**********************************************************************************************
376 
377  //**Utility functions***************************************************************************
380  inline size_t size() const noexcept;
381  inline size_t capacity() const noexcept;
382  inline size_t nonZeros() const;
383  inline void reset();
384  inline void clear();
385  inline void resize( size_t n, bool preserve=true );
386  void reserve( size_t n );
387  inline void shrinkToFit();
388  inline void swap( CompressedVector& sv ) noexcept;
390  //**********************************************************************************************
391 
392  //**Insertion functions*************************************************************************
395  inline Iterator set ( size_t index, const Type& value );
396  inline Iterator insert( size_t index, const Type& value );
397  inline void append( size_t index, const Type& value, bool check=false );
399  //**********************************************************************************************
400 
401  //**Erase functions*****************************************************************************
404  inline void erase( size_t index );
405  inline Iterator erase( Iterator pos );
406  inline Iterator erase( Iterator first, Iterator last );
407 
408  template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > >
409  inline void erase( Pred predicate );
410 
411  template< typename Pred >
412  inline void erase( Iterator first, Iterator last, Pred predicate );
414  //**********************************************************************************************
415 
416  //**Lookup functions****************************************************************************
419  inline Iterator find ( size_t index );
420  inline ConstIterator find ( size_t index ) const;
421  inline Iterator lowerBound( size_t index );
422  inline ConstIterator lowerBound( size_t index ) const;
423  inline Iterator upperBound( size_t index );
424  inline ConstIterator upperBound( size_t index ) const;
426  //**********************************************************************************************
427 
428  //**Numeric functions***************************************************************************
431  template< typename Other > inline CompressedVector& scale( const Other& scalar );
433  //**********************************************************************************************
434 
435  //**Expression template evaluation functions****************************************************
438  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
439  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
440 
441  inline bool canSMPAssign() const noexcept;
442 
443  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
444  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
445  template< typename VT > inline void addAssign ( const DenseVector <VT,TF>& rhs );
446  template< typename VT > inline void addAssign ( const SparseVector<VT,TF>& rhs );
447  template< typename VT > inline void subAssign ( const DenseVector <VT,TF>& rhs );
448  template< typename VT > inline void subAssign ( const SparseVector<VT,TF>& rhs );
449  template< typename VT > inline void multAssign( const DenseVector <VT,TF>& rhs );
450  template< typename VT > inline void divAssign ( const DenseVector <VT,TF>& rhs );
452  //**********************************************************************************************
453 
454  private:
455  //**Utility functions***************************************************************************
458  inline size_t extendCapacity() const noexcept;
459  inline Iterator castDown( IteratorBase it ) const noexcept;
460  inline IteratorBase castUp ( Iterator it ) const noexcept;
462  //**********************************************************************************************
463 
464  //**Insertion functions***************************************************************************
467  Iterator insert( Iterator pos, size_t index, const Type& value );
469  //**********************************************************************************************
470 
471  //**Member variables****************************************************************************
474  size_t size_;
475  size_t capacity_;
478 
479  static const Type zero_;
480 
481  //**********************************************************************************************
482 
483  //**Compile time checks*************************************************************************
491  //**********************************************************************************************
492 };
493 //*************************************************************************************************
494 
495 
496 
497 
498 //=================================================================================================
499 //
500 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
501 //
502 //=================================================================================================
503 
504 template< typename Type // Data type of the vector
505  , bool TF > // Transpose flag
507 
508 
509 
510 
511 //=================================================================================================
512 //
513 // CONSTRUCTORS
514 //
515 //=================================================================================================
516 
517 //*************************************************************************************************
520 template< typename Type // Data type of the vector
521  , bool TF > // Transpose flag
523  : size_ ( 0UL ) // The current size/dimension of the compressed vector
524  , capacity_( 0UL ) // The maximum capacity of the compressed vector
525  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
526  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
527 {}
528 //*************************************************************************************************
529 
530 
531 //*************************************************************************************************
536 template< typename Type // Data type of the vector
537  , bool TF > // Transpose flag
539  : size_ ( n ) // The current size/dimension of the compressed vector
540  , capacity_( 0UL ) // The maximum capacity of the compressed vector
541  , begin_ ( nullptr ) // Pointer to the first non-zero element of the compressed vector
542  , end_ ( nullptr ) // Pointer to the last non-zero element of the compressed vector
543 {}
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
553 template< typename Type // Data type of the vector
554  , bool TF > // Transpose flag
555 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
556  : size_ ( n ) // The current size/dimension of the compressed vector
557  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
558  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
559  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
560 {}
561 //*************************************************************************************************
562 
563 
564 //*************************************************************************************************
579 template< typename Type // Data type of the vector
580  , bool TF > // Transpose flag
582  : CompressedVector( list.size(), blaze::nonZeros( list ) )
583 {
584  size_t i( 0UL );
585 
586  for( const Type& element : list ) {
587  if( !isDefault<strict>( element ) )
588  append( i, element );
589  ++i;
590  }
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
603 template< typename Type // Data type of the vector
604  , bool TF > // Transpose flag
606  : CompressedVector( sv.size_, sv.nonZeros() )
607 {
608  end_ = begin_ + capacity_;
609  std::copy( sv.begin_, sv.end_, castUp( begin_ ) );
610 }
611 //*************************************************************************************************
612 
613 
614 //*************************************************************************************************
619 template< typename Type // Data type of the vector
620  , bool TF > // Transpose flag
622  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
623  , capacity_( sv.capacity_ ) // The maximum capacity of the compressed vector
624  , begin_ ( sv.begin_ ) // Pointer to the first non-zero element of the compressed vector
625  , end_ ( sv.end_ ) // Pointer to the last non-zero element of the compressed vector
626 {
627  sv.size_ = 0UL;
628  sv.capacity_ = 0UL;
629  sv.begin_ = nullptr;
630  sv.end_ = nullptr;
631 }
632 //*************************************************************************************************
633 
634 
635 //*************************************************************************************************
640 template< typename Type // Data type of the vector
641  , bool TF > // Transpose flag
642 template< typename VT > // Type of the foreign dense vector
644  : CompressedVector( (~dv).size() )
645 {
646  using blaze::assign;
647 
648  assign( *this, ~dv );
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
658 template< typename Type // Data type of the vector
659  , bool TF > // Transpose flag
660 template< typename VT > // Type of the foreign sparse vector
662  : CompressedVector( (~sv).size(), (~sv).nonZeros() )
663 {
664  using blaze::assign;
665 
666  assign( *this, ~sv );
667 }
668 //*************************************************************************************************
669 
670 
671 
672 
673 //=================================================================================================
674 //
675 // DESTRUCTOR
676 //
677 //=================================================================================================
678 
679 //*************************************************************************************************
682 template< typename Type // Data type of the vector
683  , bool TF > // Transpose flag
685 {
686  deallocate( begin_ );
687 }
688 //*************************************************************************************************
689 
690 
691 
692 
693 //=================================================================================================
694 //
695 // DATA ACCESS FUNCTIONS
696 //
697 //=================================================================================================
698 
699 //*************************************************************************************************
710 template< typename Type // Data type of the vector
711  , bool TF > // Transpose flag
713  CompressedVector<Type,TF>::operator[]( size_t index ) noexcept
714 {
715  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
716 
717  return Reference( *this, index );
718 }
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
728 template< typename Type // Data type of the vector
729  , bool TF > // Transpose flag
731  CompressedVector<Type,TF>::operator[]( size_t index ) const noexcept
732 {
733  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
734 
735  const ConstIterator pos( lowerBound( index ) );
736 
737  if( pos == end_ || pos->index_ != index )
738  return zero_;
739  else
740  return pos->value_;
741 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
757 template< typename Type // Data type of the vector
758  , bool TF > // Transpose flag
761 {
762  if( index >= size_ ) {
763  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
764  }
765  return (*this)[index];
766 }
767 //*************************************************************************************************
768 
769 
770 //*************************************************************************************************
782 template< typename Type // Data type of the vector
783  , bool TF > // Transpose flag
785  CompressedVector<Type,TF>::at( size_t index ) const
786 {
787  if( index >= size_ ) {
788  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
789  }
790  return (*this)[index];
791 }
792 //*************************************************************************************************
793 
794 
795 //*************************************************************************************************
800 template< typename Type // Data type of the vector
801  , bool TF > // Transpose flag
803 {
804  return Iterator( begin_ );
805 }
806 //*************************************************************************************************
807 
808 
809 //*************************************************************************************************
814 template< typename Type // Data type of the vector
815  , bool TF > // Transpose flag
818 {
819  return ConstIterator( begin_ );
820 }
821 //*************************************************************************************************
822 
823 
824 //*************************************************************************************************
829 template< typename Type // Data type of the vector
830  , bool TF > // Transpose flag
833 {
834  return ConstIterator( begin_ );
835 }
836 //*************************************************************************************************
837 
838 
839 //*************************************************************************************************
844 template< typename Type // Data type of the vector
845  , bool TF > // Transpose flag
847 {
848  return Iterator( end_ );
849 }
850 //*************************************************************************************************
851 
852 
853 //*************************************************************************************************
858 template< typename Type // Data type of the vector
859  , bool TF > // Transpose flag
862 {
863  return ConstIterator( end_ );
864 }
865 //*************************************************************************************************
866 
867 
868 //*************************************************************************************************
873 template< typename Type // Data type of the vector
874  , bool TF > // Transpose flag
877 {
878  return ConstIterator( end_ );
879 }
880 //*************************************************************************************************
881 
882 
883 
884 
885 //=================================================================================================
886 //
887 // ASSIGNMENT OPERATORS
888 //
889 //=================================================================================================
890 
891 //*************************************************************************************************
907 template< typename Type // Data type of the vector
908  , bool TF > // Transpose flag
911 {
912  using blaze::nonZeros;
913 
914  resize( list.size(), false );
915  reserve( nonZeros( list ) );
916 
917  size_t i( 0UL );
918 
919  for( const Type& element : list ) {
920  if( !isDefault<strict>( element ) )
921  append( i, element );
922  ++i;
923  }
924 
925  return *this;
926 }
927 //*************************************************************************************************
928 
929 
930 //*************************************************************************************************
939 template< typename Type // Data type of the vector
940  , bool TF > // Transpose flag
943 {
944  using std::swap;
945 
946  if( &rhs == this ) return *this;
947 
948  const size_t nonzeros( rhs.nonZeros() );
949 
950  if( nonzeros > capacity_ ) {
951  Iterator newBegin( allocate<Element>( nonzeros ) );
952  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( newBegin ) ) );
953  swap( begin_, newBegin );
954  deallocate( newBegin );
955 
956  size_ = rhs.size_;
957  capacity_ = nonzeros;
958  }
959  else {
960  end_ = castDown( std::copy( rhs.begin_, rhs.end_, castUp( begin_ ) ) );
961  size_ = rhs.size_;
962  }
963 
964  return *this;
965 }
966 //*************************************************************************************************
967 
968 
969 //*************************************************************************************************
975 template< typename Type // Data type of the vector
976  , bool TF > // Transpose flag
979 {
980  deallocate( begin_ );
981 
982  size_ = rhs.size_;
983  capacity_ = rhs.capacity_;
984  begin_ = rhs.begin_;
985  end_ = rhs.end_;
986 
987  rhs.size_ = 0UL;
988  rhs.capacity_ = 0UL;
989  rhs.begin_ = nullptr;
990  rhs.end_ = nullptr;
991 
992  return *this;
993 }
994 //*************************************************************************************************
995 
996 
997 //*************************************************************************************************
1006 template< typename Type // Data type of the vector
1007  , bool TF > // Transpose flag
1008 template< typename VT > // Type of the right-hand side dense vector
1011 {
1012  using blaze::assign;
1013 
1014  if( (~rhs).canAlias( this ) ) {
1015  CompressedVector tmp( ~rhs );
1016  swap( tmp );
1017  }
1018  else {
1019  size_ = (~rhs).size();
1020  end_ = begin_;
1021  assign( *this, ~rhs );
1022  }
1023 
1024  return *this;
1025 }
1026 //*************************************************************************************************
1027 
1028 
1029 //*************************************************************************************************
1038 template< typename Type // Data type of the vector
1039  , bool TF > // Transpose flag
1040 template< typename VT > // Type of the right-hand side sparse vector
1043 {
1044  using blaze::assign;
1045 
1046  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
1047  CompressedVector tmp( ~rhs );
1048  swap( tmp );
1049  }
1050  else {
1051  size_ = (~rhs).size();
1052  end_ = begin_;
1053  assign( *this, ~rhs );
1054  }
1055 
1056  return *this;
1057 }
1058 //*************************************************************************************************
1059 
1060 
1061 //*************************************************************************************************
1071 template< typename Type // Data type of the vector
1072  , bool TF > // Transpose flag
1073 template< typename VT > // Type of the right-hand side vector
1075 {
1076  using blaze::addAssign;
1077 
1078  if( (~rhs).size() != size_ ) {
1079  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1080  }
1081 
1082  addAssign( *this, ~rhs );
1083 
1084  return *this;
1085 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1099 template< typename Type // Data type of the vector
1100  , bool TF > // Transpose flag
1101 template< typename VT > // Type of the right-hand side vector
1103 {
1104  using blaze::subAssign;
1105 
1106  if( (~rhs).size() != size_ ) {
1107  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1108  }
1109 
1110  subAssign( *this, ~rhs );
1111 
1112  return *this;
1113 }
1114 //*************************************************************************************************
1115 
1116 
1117 //*************************************************************************************************
1128 template< typename Type // Data type of the vector
1129  , bool TF > // Transpose flag
1130 template< typename VT > // Type of the right-hand side vector
1133 {
1134  using blaze::multAssign;
1135 
1136  if( (~rhs).size() != size_ ) {
1137  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1138  }
1139 
1140  if( (~rhs).canAlias( this ) ) {
1141  CompressedVector tmp( *this * (~rhs) );
1142  swap( tmp );
1143  }
1144  else {
1145  CompositeType_<VT> tmp( ~rhs );
1146  multAssign( *this, tmp );
1147  }
1148 
1149  return *this;
1150 }
1151 //*************************************************************************************************
1152 
1153 
1154 //*************************************************************************************************
1165 template< typename Type // Data type of the vector
1166  , bool TF > // Transpose flag
1167 template< typename VT > // Type of the right-hand side vector
1170 {
1171  if( (~rhs).size() != size_ ) {
1172  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1173  }
1174 
1175  CompressedVector tmp( *this * (~rhs) );
1176  swap( tmp );
1177 
1178  return *this;
1179 }
1180 //*************************************************************************************************
1181 
1182 
1183 //*************************************************************************************************
1193 template< typename Type // Data type of the vector
1194  , bool TF > // Transpose flag
1195 template< typename VT > // Type of the right-hand side vector
1197 {
1198  using blaze::divAssign;
1199 
1200  if( (~rhs).size() != size_ ) {
1201  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1202  }
1203 
1204  if( (~rhs).canAlias( this ) ) {
1205  CompressedVector tmp( *this / (~rhs) );
1206  swap( tmp );
1207  }
1208  else {
1209  CompositeType_<VT> tmp( ~rhs );
1210  divAssign( *this, tmp );
1211  }
1212 
1213  return *this;
1214 }
1215 //*************************************************************************************************
1216 
1217 
1218 //*************************************************************************************************
1229 template< typename Type // Data type of the vector
1230  , bool TF > // Transpose flag
1231 template< typename VT > // Type of the right-hand side vector
1233 {
1234  using blaze::assign;
1235 
1236  using CrossType = CrossTrait_< This, ResultType_<VT> >;
1237 
1241 
1242  if( size_ != 3UL || (~rhs).size() != 3UL ) {
1243  BLAZE_THROW_INVALID_ARGUMENT( "Invalid vector size for cross product" );
1244  }
1245 
1246  const CrossType tmp( *this % (~rhs) );
1247  end_ = begin_;
1248  assign( *this, tmp );
1249 
1250  return *this;
1251 }
1252 //*************************************************************************************************
1253 
1254 
1255 
1256 
1257 //=================================================================================================
1258 //
1259 // UTILITY FUNCTIONS
1260 //
1261 //=================================================================================================
1262 
1263 //*************************************************************************************************
1268 template< typename Type // Data type of the vector
1269  , bool TF > // Transpose flag
1270 inline size_t CompressedVector<Type,TF>::size() const noexcept
1271 {
1272  return size_;
1273 }
1274 //*************************************************************************************************
1275 
1276 
1277 //*************************************************************************************************
1282 template< typename Type // Data type of the vector
1283  , bool TF > // Transpose flag
1284 inline size_t CompressedVector<Type,TF>::capacity() const noexcept
1285 {
1286  return capacity_;
1287 }
1288 //*************************************************************************************************
1289 
1290 
1291 //*************************************************************************************************
1299 template< typename Type // Data type of the vector
1300  , bool TF > // Transpose flag
1302 {
1303  return end_ - begin_;
1304 }
1305 //*************************************************************************************************
1306 
1307 
1308 //*************************************************************************************************
1313 template< typename Type // Data type of the vector
1314  , bool TF > // Transpose flag
1316 {
1317  end_ = begin_;
1318 }
1319 //*************************************************************************************************
1320 
1321 
1322 //*************************************************************************************************
1329 template< typename Type // Data type of the vector
1330  , bool TF > // Transpose flag
1332 {
1333  size_ = 0UL;
1334  end_ = begin_;
1335 }
1336 //*************************************************************************************************
1337 
1338 
1339 //*************************************************************************************************
1353 template< typename Type // Data type of the vector
1354  , bool TF > // Transpose flag
1355 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1356 {
1357  if( preserve ) {
1358  end_ = lowerBound( n );
1359  }
1360  else {
1361  end_ = begin_;
1362  }
1363 
1364  size_ = n;
1365 }
1366 //*************************************************************************************************
1367 
1368 
1369 //*************************************************************************************************
1378 template< typename Type // Data type of the vector
1379  , bool TF > // Transpose flag
1381 {
1382  using std::swap;
1383 
1384  if( n > capacity_ ) {
1385  const size_t newCapacity( n );
1386 
1387  // Allocating a new data and index array
1388  Iterator newBegin = allocate<Element>( newCapacity );
1389 
1390  // Replacing the old data and index array
1391  end_ = castDown( transfer( begin_, end_, castUp( newBegin ) ) );
1392  swap( newBegin, begin_ );
1393  capacity_ = newCapacity;
1394  deallocate( newBegin );
1395  }
1396 }
1397 //*************************************************************************************************
1398 
1399 
1400 //*************************************************************************************************
1409 template< typename Type // Data type of the vector
1410  , bool TF > // Transpose flag
1412 {
1413  if( nonZeros() < capacity_ ) {
1414  CompressedVector( *this ).swap( *this );
1415  }
1416 }
1417 //*************************************************************************************************
1418 
1419 
1420 //*************************************************************************************************
1426 template< typename Type // Data type of the vector
1427  , bool TF > // Transpose flag
1429 {
1430  using std::swap;
1431 
1432  swap( size_, sv.size_ );
1433  swap( capacity_, sv.capacity_ );
1434  swap( begin_, sv.begin_ );
1435  swap( end_, sv.end_ );
1436 }
1437 //*************************************************************************************************
1438 
1439 
1440 //*************************************************************************************************
1448 template< typename Type // Data type of the vector
1449  , bool TF > // Transpose flag
1450 inline size_t CompressedVector<Type,TF>::extendCapacity() const noexcept
1451 {
1452  using blaze::max;
1453  using blaze::min;
1454 
1455  size_t nonzeros( 2UL*capacity_+1UL );
1456  nonzeros = max( nonzeros, 7UL );
1457  nonzeros = min( nonzeros, size_ );
1458 
1459  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1460 
1461  return nonzeros;
1462 }
1463 //*************************************************************************************************
1464 
1465 
1466 //*************************************************************************************************
1474 template< typename Type // Data type of the vector
1475  , bool TF > // Transpose flag
1478 {
1479  return static_cast<Iterator>( it );
1480 }
1481 //*************************************************************************************************
1482 
1483 
1484 //*************************************************************************************************
1492 template< typename Type // Data type of the vector
1493  , bool TF > // Transpose flag
1496 {
1497  return static_cast<IteratorBase>( it );
1498 }
1499 //*************************************************************************************************
1500 
1501 
1502 
1503 
1504 //=================================================================================================
1505 //
1506 // INSERTION FUNCTIONS
1507 //
1508 //=================================================================================================
1509 
1510 //*************************************************************************************************
1521 template< typename Type // Data type of the vector
1522  , bool TF > // Transpose flag
1524  CompressedVector<Type,TF>::set( size_t index, const Type& value )
1525 {
1526  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1527 
1528  const Iterator pos( lowerBound( index ) );
1529 
1530  if( pos != end_ && pos->index_ == index ) {
1531  pos->value() = value;
1532  return pos;
1533  }
1534  else return insert( pos, index, value );
1535 }
1536 //*************************************************************************************************
1537 
1538 
1539 //*************************************************************************************************
1551 template< typename Type // Data type of the vector
1552  , bool TF > // Transpose flag
1554  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1555 {
1556  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1557 
1558  const Iterator pos( lowerBound( index ) );
1559 
1560  if( pos != end_ && pos->index_ == index ) {
1561  BLAZE_THROW_INVALID_ARGUMENT( "Bad access index" );
1562  }
1563 
1564  return insert( pos, index, value );
1565 }
1566 //*************************************************************************************************
1567 
1568 
1569 //*************************************************************************************************
1578 template< typename Type // Data type of the vector
1579  , bool TF > // Transpose flag
1581  CompressedVector<Type,TF>::insert( Iterator pos, size_t index, const Type& value )
1582 {
1583  using std::swap;
1584 
1585  if( nonZeros() != capacity_ ) {
1586  std::move_backward( pos, end_, castUp( end_+1 ) );
1587  pos->value_ = value;
1588  pos->index_ = index;
1589  ++end_;
1590 
1591  return pos;
1592  }
1593  else {
1594  size_t newCapacity( extendCapacity() );
1595 
1596  Iterator newBegin = allocate<Element>( newCapacity );
1597  Iterator tmp = castDown( std::move( begin_, pos, castUp( newBegin ) ) );
1598  tmp->value_ = value;
1599  tmp->index_ = index;
1600  end_ = castDown( std::move( pos, end_, castUp( tmp+1 ) ) );
1601 
1602  swap( newBegin, begin_ );
1603  deallocate( newBegin );
1604  capacity_ = newCapacity;
1605 
1606  return tmp;
1607  }
1608 }
1609 //*************************************************************************************************
1610 
1611 
1612 //*************************************************************************************************
1636 template< typename Type // Data type of the vector
1637  , bool TF > // Transpose flag
1638 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1639 {
1640  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1641  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved capacity" );
1642  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1643 
1644  end_->value_ = value;
1645 
1646  if( !check || !isDefault<strict>( end_->value_ ) ) {
1647  end_->index_ = index;
1648  ++end_;
1649  }
1650 }
1651 //*************************************************************************************************
1652 
1653 
1654 
1655 
1656 //=================================================================================================
1657 //
1658 // ERASE FUNCTIONS
1659 //
1660 //=================================================================================================
1661 
1662 //*************************************************************************************************
1670 template< typename Type // Data type of the vector
1671  , bool TF > // Transpose flag
1672 inline void CompressedVector<Type,TF>::erase( size_t index )
1673 {
1674  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1675 
1676  const Iterator pos( find( index ) );
1677  if( pos != end_ )
1678  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1679 }
1680 //*************************************************************************************************
1681 
1682 
1683 //*************************************************************************************************
1691 template< typename Type // Data type of the vector
1692  , bool TF > // Transpose flag
1695 {
1696  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1697 
1698  if( pos != end_ )
1699  end_ = castDown( std::move( pos+1, end_, castUp( pos ) ) );
1700  return pos;
1701 }
1702 //*************************************************************************************************
1703 
1704 
1705 //*************************************************************************************************
1714 template< typename Type // Data type of the vector
1715  , bool TF > // Transpose flag
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  if( first != last )
1724  end_ = castDown( std::move( last, end_, castUp( first ) ) );
1725  return first;
1726 }
1727 //*************************************************************************************************
1728 
1729 
1730 //*************************************************************************************************
1751 template< typename Type // Data type of the vector
1752  , bool TF > // Transpose flag
1753 template< typename Pred // Type of the unary predicate
1754  , typename > // Type restriction on the unary predicate
1755 inline void CompressedVector<Type,TF>::erase( Pred predicate )
1756 {
1757  end_ = castDown( std::remove_if( castUp( begin_ ), castUp( end_ ),
1758  [predicate=predicate]( const ElementBase& element ) {
1759  return predicate( element.value() );
1760  } ) );
1761 }
1762 //*************************************************************************************************
1763 
1764 
1765 //*************************************************************************************************
1788 template< typename Type // Data type of the vector
1789  , bool TF > // Transpose flag
1790 template< typename Pred > // Type of the unary predicate
1791 inline void CompressedVector<Type,TF>::erase( Iterator first, Iterator last, Pred predicate )
1792 {
1793  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1794  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1795  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1796 
1797  const auto pos = std::remove_if( castUp( first ), castUp( last ),
1798  [predicate=predicate]( const ElementBase& element ) {
1799  return predicate( element.value() );
1800  } );
1801 
1802  end_ = castDown( std::move( last, end_, pos ) );
1803 }
1804 //*************************************************************************************************
1805 
1806 
1807 
1808 
1809 //=================================================================================================
1810 //
1811 // LOOKUP FUNCTIONS
1812 //
1813 //=================================================================================================
1814 
1815 //*************************************************************************************************
1828 template< typename Type // Data type of the vector
1829  , bool TF > // Transpose flag
1831 {
1832  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1833 }
1834 //*************************************************************************************************
1835 
1836 
1837 //*************************************************************************************************
1850 template< typename Type // Data type of the vector
1851  , bool TF > // Transpose flag
1853 {
1854  const ConstIterator pos( lowerBound( index ) );
1855  if( pos != end_ && pos->index_ == index )
1856  return pos;
1857  else return end_;
1858 }
1859 //*************************************************************************************************
1860 
1861 
1862 //*************************************************************************************************
1874 template< typename Type // Data type of the vector
1875  , bool TF > // Transpose flag
1878 {
1879  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1880 }
1881 //*************************************************************************************************
1882 
1883 
1884 //*************************************************************************************************
1896 template< typename Type // Data type of the vector
1897  , bool TF > // Transpose flag
1900 {
1901  return std::lower_bound( begin_, end_, index,
1902  []( const Element& element, size_t i )
1903  {
1904  return element.index() < i;
1905  } );
1906 }
1907 //*************************************************************************************************
1908 
1909 
1910 //*************************************************************************************************
1922 template< typename Type // Data type of the vector
1923  , bool TF > // Transpose flag
1926 {
1927  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1928 }
1929 //*************************************************************************************************
1930 
1931 
1932 //*************************************************************************************************
1944 template< typename Type // Data type of the vector
1945  , bool TF > // Transpose flag
1948 {
1949  return std::upper_bound( begin_, end_, index,
1950  []( size_t i, const Element& element )
1951  {
1952  return i < element.index();
1953  } );
1954 }
1955 //*************************************************************************************************
1956 
1957 
1958 
1959 
1960 //=================================================================================================
1961 //
1962 // NUMERIC FUNCTIONS
1963 //
1964 //=================================================================================================
1965 
1966 //*************************************************************************************************
1983 template< typename Type // Data type of the vector
1984  , bool TF > // Transpose flag
1985 template< typename Other > // Data type of the scalar value
1987 {
1988  for( Iterator element=begin_; element!=end_; ++element )
1989  element->value_ *= scalar;
1990  return *this;
1991 }
1992 //*************************************************************************************************
1993 
1994 
1995 
1996 
1997 //=================================================================================================
1998 //
1999 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2000 //
2001 //=================================================================================================
2002 
2003 //*************************************************************************************************
2013 template< typename Type // Data type of the vector
2014  , bool TF > // Transpose flag
2015 template< typename Other > // Data type of the foreign expression
2016 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const noexcept
2017 {
2018  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2019 }
2020 //*************************************************************************************************
2021 
2022 
2023 //*************************************************************************************************
2033 template< typename Type // Data type of the vector
2034  , bool TF > // Transpose flag
2035 template< typename Other > // Data type of the foreign expression
2036 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const noexcept
2037 {
2038  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
2039 }
2040 //*************************************************************************************************
2041 
2042 
2043 //*************************************************************************************************
2053 template< typename Type // Data type of the vector
2054  , bool TF > // Transpose flag
2055 inline bool CompressedVector<Type,TF>::canSMPAssign() const noexcept
2056 {
2057  return false;
2058 }
2059 //*************************************************************************************************
2060 
2061 
2062 //*************************************************************************************************
2073 template< typename Type // Data type of the vector
2074  , bool TF > // Transpose flag
2075 template< typename VT > // Type of the right-hand side dense vector
2077 {
2078  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2079  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2080 
2081  size_t nonzeros( 0UL );
2082 
2083  for( size_t i=0UL; i<size_; ++i )
2084  {
2085  if( nonzeros == capacity_ )
2086  reserve( extendCapacity() );
2087 
2088  end_->value_ = (~rhs)[i];
2089 
2090  if( !isDefault<strict>( end_->value_ ) ) {
2091  end_->index_ = i;
2092  ++end_;
2093  ++nonzeros;
2094  }
2095  }
2096 }
2097 //*************************************************************************************************
2098 
2099 
2100 //*************************************************************************************************
2111 template< typename Type // Data type of the vector
2112  , bool TF > // Transpose flag
2113 template< typename VT > // Type of the right-hand side sparse vector
2115 {
2116  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2117  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
2118 
2119  // Using the following formulation instead of a std::copy function call of the form
2120  //
2121  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
2122  //
2123  // results in much less requirements on the ConstIterator type provided from the right-hand
2124  // sparse vector type
2125  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2126  append( element->index(), element->value() );
2127 }
2128 //*************************************************************************************************
2129 
2130 
2131 //*************************************************************************************************
2142 template< typename Type // Data type of the vector
2143  , bool TF > // Transpose flag
2144 template< typename VT > // Type of the right-hand side dense vector
2146 {
2147  using AddType = AddTrait_< This, ResultType_<VT> >;
2148 
2152 
2153  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2154 
2155  const AddType tmp( serial( *this + (~rhs) ) );
2156  reset();
2157  assign( tmp );
2158 }
2159 //*************************************************************************************************
2160 
2161 
2162 //*************************************************************************************************
2173 template< typename Type // Data type of the vector
2174  , bool TF > // Transpose flag
2175 template< typename VT > // Type of the right-hand side sparse vector
2177 {
2178  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2179 
2180  CompressedVector tmp( serial( *this + (~rhs) ) );
2181  swap( tmp );
2182 }
2183 //*************************************************************************************************
2184 
2185 
2186 //*************************************************************************************************
2197 template< typename Type // Data type of the vector
2198  , bool TF > // Transpose flag
2199 template< typename VT > // Type of the right-hand side dense vector
2201 {
2202  using SubType = SubTrait_< This, ResultType_<VT> >;
2203 
2207 
2208  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2209 
2210  const SubType tmp( serial( *this - (~rhs) ) );
2211  reset();
2212  assign( tmp );
2213 }
2214 //*************************************************************************************************
2215 
2216 
2217 //*************************************************************************************************
2228 template< typename Type // Data type of the vector
2229  , bool TF > // Transpose flag
2230 template< typename VT > // Type of the right-hand side sparse vector
2232 {
2233  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2234 
2235  CompressedVector tmp( serial( *this - (~rhs) ) );
2236  swap( tmp );
2237 }
2238 //*************************************************************************************************
2239 
2240 
2241 //*************************************************************************************************
2252 template< typename Type // Data type of the vector
2253  , bool TF > // Transpose flag
2254 template< typename VT > // Type of the right-hand side dense vector
2256 {
2257  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2258 
2260 
2261  for( Iterator element=begin_; element!=end_; ++element ) {
2262  element->value_ *= (~rhs)[element->index_];
2263  }
2264 }
2265 //*************************************************************************************************
2266 
2267 
2268 //*************************************************************************************************
2279 template< typename Type // Data type of the vector
2280  , bool TF > // Transpose flag
2281 template< typename VT > // Type of the right-hand side dense vector
2283 {
2284  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2285 
2287 
2288  for( Iterator element=begin_; element!=end_; ++element ) {
2289  element->value_ /= (~rhs)[element->index_];
2290  }
2291 }
2292 //*************************************************************************************************
2293 
2294 
2295 
2296 
2297 //=================================================================================================
2298 //
2299 // COMPRESSEDVECTOR OPERATORS
2300 //
2301 //=================================================================================================
2302 
2303 //*************************************************************************************************
2306 template< typename Type, bool TF >
2307 inline void reset( CompressedVector<Type,TF>& v );
2308 
2309 template< typename Type, bool TF >
2310 inline void clear( CompressedVector<Type,TF>& v );
2311 
2312 template< bool RF, typename Type, bool TF >
2313 inline bool isDefault( const CompressedVector<Type,TF>& v );
2314 
2315 template< typename Type, bool TF >
2316 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept;
2317 
2318 template< typename Type, bool TF >
2319 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) noexcept;
2321 //*************************************************************************************************
2322 
2323 
2324 //*************************************************************************************************
2331 template< typename Type // Data type of the vector
2332  , bool TF > // Transpose flag
2334 {
2335  v.reset();
2336 }
2337 //*************************************************************************************************
2338 
2339 
2340 //*************************************************************************************************
2347 template< typename Type // Data type of the vector
2348  , bool TF > // Transpose flag
2350 {
2351  v.clear();
2352 }
2353 //*************************************************************************************************
2354 
2355 
2356 //*************************************************************************************************
2380 template< bool RF // Relaxation flag
2381  , typename Type // Data type of the vector
2382  , bool TF > // Transpose flag
2383 inline bool isDefault( const CompressedVector<Type,TF>& v )
2384 {
2385  return ( v.size() == 0UL );
2386 }
2387 //*************************************************************************************************
2388 
2389 
2390 //*************************************************************************************************
2408 template< typename Type // Data type of the vector
2409  , bool TF > // Transpose flag
2410 inline bool isIntact( const CompressedVector<Type,TF>& v ) noexcept
2411 {
2412  return ( v.nonZeros() <= v.capacity() );
2413 }
2414 //*************************************************************************************************
2415 
2416 
2417 //*************************************************************************************************
2425 template< typename Type // Data type of the vector
2426  , bool TF > // Transpose flag
2428 {
2429  a.swap( b );
2430 }
2431 //*************************************************************************************************
2432 
2433 
2434 
2435 
2436 //=================================================================================================
2437 //
2438 // ISRESIZABLE SPECIALIZATIONS
2439 //
2440 //=================================================================================================
2441 
2442 //*************************************************************************************************
2444 template< typename T, bool TF >
2445 struct IsResizable< CompressedVector<T,TF> >
2446  : public TrueType
2447 {};
2449 //*************************************************************************************************
2450 
2451 
2452 
2453 
2454 //=================================================================================================
2455 //
2456 // ISSHRINKABLE SPECIALIZATIONS
2457 //
2458 //=================================================================================================
2459 
2460 //*************************************************************************************************
2462 template< typename T, bool TF >
2463 struct IsShrinkable< CompressedVector<T,TF> >
2464  : public TrueType
2465 {};
2467 //*************************************************************************************************
2468 
2469 
2470 
2471 
2472 //=================================================================================================
2473 //
2474 // ADDTRAIT SPECIALIZATIONS
2475 //
2476 //=================================================================================================
2477 
2478 //*************************************************************************************************
2480 template< typename T1, bool TF, typename T2, size_t N >
2481 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2482 {
2483  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2484 };
2485 
2486 template< typename T1, size_t N, bool TF, typename T2 >
2487 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2488 {
2489  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2490 };
2491 
2492 template< typename T1, bool TF, typename T2, size_t N >
2493 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2494 {
2495  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2496 };
2497 
2498 template< typename T1, size_t N, bool TF, typename T2 >
2499 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2500 {
2501  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2502 };
2503 
2504 template< typename T1, bool TF, typename T2 >
2505 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2506 {
2507  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2508 };
2509 
2510 template< typename T1, bool TF, typename T2 >
2511 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2512 {
2513  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2514 };
2515 
2516 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2517 struct AddTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2518 {
2519  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2520 };
2521 
2522 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2523 struct AddTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2524 {
2525  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2526 };
2527 
2528 template< typename T1, bool TF, typename T2 >
2529 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2530 {
2531  using Type = CompressedVector< AddTrait_<T1,T2>, TF >;
2532 };
2534 //*************************************************************************************************
2535 
2536 
2537 
2538 
2539 //=================================================================================================
2540 //
2541 // SUBTRAIT SPECIALIZATIONS
2542 //
2543 //=================================================================================================
2544 
2545 //*************************************************************************************************
2547 template< typename T1, bool TF, typename T2, size_t N >
2548 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2549 {
2550  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2551 };
2552 
2553 template< typename T1, size_t N, bool TF, typename T2 >
2554 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2555 {
2556  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2557 };
2558 
2559 template< typename T1, bool TF, typename T2, size_t N >
2560 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2561 {
2562  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2563 };
2564 
2565 template< typename T1, size_t N, bool TF, typename T2 >
2566 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2567 {
2568  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2569 };
2570 
2571 template< typename T1, bool TF, typename T2 >
2572 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2573 {
2574  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2575 };
2576 
2577 template< typename T1, bool TF, typename T2 >
2578 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2579 {
2580  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2581 };
2582 
2583 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2584 struct SubTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2585 {
2586  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2587 };
2588 
2589 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2590 struct SubTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2591 {
2592  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2593 };
2594 
2595 template< typename T1, bool TF, typename T2 >
2596 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2597 {
2598  using Type = CompressedVector< SubTrait_<T1,T2>, TF >;
2599 };
2601 //*************************************************************************************************
2602 
2603 
2604 
2605 
2606 //=================================================================================================
2607 //
2608 // MULTTRAIT SPECIALIZATIONS
2609 //
2610 //=================================================================================================
2611 
2612 //*************************************************************************************************
2614 template< typename T1, bool TF, typename T2 >
2615 struct MultTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2616 {
2617  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2618 };
2619 
2620 template< typename T1, typename T2, bool TF >
2621 struct MultTrait< T1, CompressedVector<T2,TF>, EnableIf_< IsNumeric<T1> > >
2622 {
2623  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2624 };
2625 
2626 template< typename T1, bool TF, typename T2, size_t N >
2627 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2628 {
2629  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2630 };
2631 
2632 template< typename T1, typename T2, size_t N >
2633 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
2634 {
2635  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2636 };
2637 
2638 template< typename T1, typename T2, size_t N >
2639 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
2640 {
2641  using Type = MultTrait_<T1,T2>;
2642 };
2643 
2644 template< typename T1, size_t N, bool TF, typename T2 >
2645 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2646 {
2647  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2648 };
2649 
2650 template< typename T1, size_t N, typename T2 >
2651 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2652 {
2653  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2654 };
2655 
2656 template< typename T1, size_t N, typename T2 >
2657 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2658 {
2659  using Type = MultTrait_<T1,T2>;
2660 };
2661 
2662 template< typename T1, bool TF, typename T2, size_t N >
2663 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2664 {
2665  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2666 };
2667 
2668 template< typename T1, typename T2, size_t N >
2669 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2670 {
2671  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2672 };
2673 
2674 template< typename T1, typename T2, size_t N >
2675 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2676 {
2677  using Type = MultTrait_<T1,T2>;
2678 };
2679 
2680 template< typename T1, size_t N, bool TF, typename T2 >
2681 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2682 {
2683  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2684 };
2685 
2686 template< typename T1, size_t N, typename T2 >
2687 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2688 {
2689  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2690 };
2691 
2692 template< typename T1, size_t N, typename T2 >
2693 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2694 {
2695  using Type = MultTrait_<T1,T2>;
2696 };
2697 
2698 template< typename T1, bool TF, typename T2 >
2699 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2700 {
2701  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2702 };
2703 
2704 template< typename T1, typename T2 >
2705 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2706 {
2707  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2708 };
2709 
2710 template< typename T1, typename T2 >
2711 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2712 {
2713  using Type = MultTrait_<T1,T2>;
2714 };
2715 
2716 template< typename T1, bool TF, typename T2 >
2717 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2718 {
2719  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2720 };
2721 
2722 template< typename T1, typename T2 >
2723 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2724 {
2725  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2726 };
2727 
2728 template< typename T1, typename T2 >
2729 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2730 {
2731  using Type = MultTrait_<T1,T2>;
2732 };
2733 
2734 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2735 struct MultTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2736 {
2737  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2738 };
2739 
2740 template< typename T1, typename T2, bool AF, bool PF >
2741 struct MultTrait< CompressedVector<T1,false>, CustomVector<T2,AF,PF,true> >
2742 {
2743  using Type = CompressedMatrix< MultTrait_<T1,T2>, true >;
2744 };
2745 
2746 template< typename T1, typename T2, bool AF, bool PF >
2747 struct MultTrait< CompressedVector<T1,true>, CustomVector<T2,AF,PF,false> >
2748 {
2749  using Type = MultTrait_<T1,T2>;
2750 };
2751 
2752 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2753 struct MultTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2754 {
2755  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2756 };
2757 
2758 template< typename T1, bool AF, bool PF, typename T2 >
2759 struct MultTrait< CustomVector<T1,AF,PF,false>, CompressedVector<T2,true> >
2760 {
2761  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2762 };
2763 
2764 template< typename T1, bool AF, bool PF, typename T2 >
2765 struct MultTrait< CustomVector<T1,AF,PF,true>, CompressedVector<T2,false> >
2766 {
2767  using Type = MultTrait_<T1,T2>;
2768 };
2769 
2770 template< typename T1, bool TF, typename T2 >
2771 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2772 {
2773  using Type = CompressedVector< MultTrait_<T1,T2>, TF >;
2774 };
2775 
2776 template< typename T1, typename T2 >
2777 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2778 {
2779  using Type = CompressedMatrix< MultTrait_<T1,T2>, false >;
2780 };
2781 
2782 template< typename T1, typename T2 >
2783 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2784 {
2785  using Type = MultTrait_<T1,T2>;
2786 };
2788 //*************************************************************************************************
2789 
2790 
2791 
2792 
2793 //=================================================================================================
2794 //
2795 // DIVTRAIT SPECIALIZATIONS
2796 //
2797 //=================================================================================================
2798 
2799 //*************************************************************************************************
2801 template< typename T1, bool TF, typename T2 >
2802 struct DivTrait< CompressedVector<T1,TF>, T2, EnableIf_< IsNumeric<T2> > >
2803 {
2804  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2805 };
2806 
2807 template< typename T1, bool TF, typename T2, size_t N >
2808 struct DivTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2809 {
2810  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2811 };
2812 
2813 template< typename T1, size_t N, bool TF, typename T2 >
2814 struct DivTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2815 {
2816  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2817 };
2818 
2819 template< typename T1, bool TF, typename T2, size_t N >
2820 struct DivTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2821 {
2822  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2823 };
2824 
2825 template< typename T1, size_t N, bool TF, typename T2 >
2826 struct DivTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2827 {
2828  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2829 };
2830 
2831 template< typename T1, bool TF, typename T2 >
2832 struct DivTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2833 {
2834  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2835 };
2836 
2837 template< typename T1, bool TF, typename T2 >
2838 struct DivTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2839 {
2840  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2841 };
2842 
2843 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2844 struct DivTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2845 {
2846  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2847 };
2848 
2849 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2850 struct DivTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2851 {
2852  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2853 };
2854 
2855 template< typename T1, bool TF, typename T2 >
2856 struct DivTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2857 {
2858  using Type = CompressedVector< DivTrait_<T1,T2>, TF >;
2859 };
2861 //*************************************************************************************************
2862 
2863 
2864 
2865 
2866 //=================================================================================================
2867 //
2868 // CROSSTRAIT SPECIALIZATIONS
2869 //
2870 //=================================================================================================
2871 
2872 //*************************************************************************************************
2874 template< typename T1, bool TF, typename T2 >
2875 struct CrossTrait< CompressedVector<T1,TF>, StaticVector<T2,3UL,TF> >
2876 {
2877  private:
2878  using T = MultTrait_<T1,T2>;
2879 
2880  public:
2881  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2882 };
2883 
2884 template< typename T1, bool TF, typename T2 >
2885 struct CrossTrait< StaticVector<T1,3UL,TF>, CompressedVector<T2,TF> >
2886 {
2887  private:
2888  using T = MultTrait_<T1,T2>;
2889 
2890  public:
2891  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2892 };
2893 
2894 template< typename T1, bool TF, typename T2, size_t N >
2895 struct CrossTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2896 {
2897  private:
2898  using T = MultTrait_<T1,T2>;
2899 
2900  public:
2901  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2902 };
2903 
2904 template< typename T1, size_t N, bool TF, typename T2 >
2905 struct CrossTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2906 {
2907  private:
2908  using T = MultTrait_<T1,T2>;
2909 
2910  public:
2911  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2912 };
2913 
2914 template< typename T1, bool TF, typename T2 >
2915 struct CrossTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2916 {
2917  private:
2918  using T = MultTrait_<T1,T2>;
2919 
2920  public:
2921  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2922 };
2923 
2924 template< typename T1, bool TF, typename T2 >
2925 struct CrossTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2926 {
2927  private:
2928  using T = MultTrait_<T1,T2>;
2929 
2930  public:
2931  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2932 };
2933 
2934 template< typename T1, bool TF, typename T2 >
2935 struct CrossTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2936 {
2937  private:
2938  using T = MultTrait_<T1,T2>;
2939 
2940  public:
2941  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2942 };
2944 //*************************************************************************************************
2945 
2946 
2947 
2948 
2949 //=================================================================================================
2950 //
2951 // UNARYMAPTRAIT SPECIALIZATIONS
2952 //
2953 //=================================================================================================
2954 
2955 //*************************************************************************************************
2957 template< typename T, bool TF, typename OP >
2958 struct UnaryMapTrait< CompressedVector<T,TF>, OP >
2959 {
2960  using Type = CompressedVector< UnaryMapTrait_<T,OP>, TF >;
2961 };
2963 //*************************************************************************************************
2964 
2965 
2966 
2967 
2968 //=================================================================================================
2969 //
2970 // HIGHTYPE SPECIALIZATIONS
2971 //
2972 //=================================================================================================
2973 
2974 //*************************************************************************************************
2976 template< typename T1, bool TF, typename T2 >
2977 struct HighType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2978 {
2980 };
2982 //*************************************************************************************************
2983 
2984 
2985 
2986 
2987 //=================================================================================================
2988 //
2989 // MATHTRAIT SPECIALIZATIONS
2990 //
2991 //=================================================================================================
2992 
2993 //*************************************************************************************************
2995 template< typename T1, bool TF, typename T2 >
2996 struct LowType< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2997 {
2999 };
3001 //*************************************************************************************************
3002 
3003 
3004 
3005 
3006 //=================================================================================================
3007 //
3008 // SUBVECTORTRAIT SPECIALIZATIONS
3009 //
3010 //=================================================================================================
3011 
3012 //*************************************************************************************************
3014 template< typename T, bool TF, size_t... CSAs >
3015 struct SubvectorTrait< CompressedVector<T,TF>, CSAs... >
3016 {
3017  using Type = CompressedVector<T,TF>;
3018 };
3020 //*************************************************************************************************
3021 
3022 
3023 
3024 
3025 //=================================================================================================
3026 //
3027 // ELEMENTSTRAIT SPECIALIZATIONS
3028 //
3029 //=================================================================================================
3030 
3031 //*************************************************************************************************
3033 template< typename T, bool TF, size_t... CEAs >
3034 struct ElementsTrait< CompressedVector<T,TF>, CEAs... >
3035 {
3036  using Type = CompressedVector<T,TF>;
3037 };
3039 //*************************************************************************************************
3040 
3041 } // namespace blaze
3042 
3043 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
#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:2076
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1925
Resize mechanism to obtain a CompressedVector with a different fixed number of elements.
Definition: CompressedVector.h:307
Header file for the serial shim.
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:221
Generic wrapper for a compile time constant integral value.The IntegralConstant class template repres...
Definition: IntegralConstant.h:71
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:101
Header file for the IsIntegral type trait.
IteratorBase castUp(Iterator it) const noexcept
Performs an up-cast of the given iterator.
Definition: CompressedVector.h:1495
Header file for the And class template.
const ElementType_< MT > min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1903
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:2145
#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:1331
typename MultTrait< T1, T2 >::Type MultTrait_
Auxiliary alias declaration for the MultTrait class template.The MultTrait_ alias declaration provide...
Definition: MultTrait.h:291
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:560
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:185
Header file for memory allocation and deallocation functionality.
Header file for the extended initializer_list functionality.
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:474
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1950
Header file for the elements trait.
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:713
Constraint on the data type.
Base template for the CrossTrait class.
Definition: CrossTrait.h:113
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:61
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:288
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:109
Efficient implementation of a dynamically sized vector with static memory.The HybridVector class temp...
Definition: Forward.h:59
EnableIf_< IsBuiltin< T >, T *> allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:155
Type ElementType
Type of the compressed vector elements.
Definition: CompressedVector.h:285
typename T::CompositeType CompositeType_
Alias declaration for nested CompositeType type definitions.The CompositeType_ alias declaration prov...
Definition: Aliases.h:83
Headerfile for the generic max algorithm.
Header file for the ValueIndexPair class.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition: CompressedVector.h:298
CompressedVector() noexcept
The default constructor for CompressedVector.
Definition: CompressedVector.h:522
Header file for the DisableIf class template.
Iterator set(size_t index, const Type &value)
Setting an element of the compressed vector.
Definition: CompressedVector.h:1524
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:2200
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1638
Header file for the multiplication trait.
Header file for the unary map trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5908
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
Header file for the IsShrinkable type trait.
Header file for all forward declarations of the math module.
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1554
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:476
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
size_t size() const noexcept
Returns the current size/dimension of the compressed vector.
Definition: CompressedVector.h:1270
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:286
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.In case the types T1 and T2 don&#39;t have the same size...
Definition: SameSize.h:60
Header file for the Not class template.
void shrinkToFit()
Requesting the removal of unused capacity.
Definition: CompressedVector.h:1411
Header file for the subvector trait.
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:1301
Iterator castDown(IteratorBase it) const noexcept
Performs a down-cast of the given iterator.
Definition: CompressedVector.h:1477
Constraint on the data type.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
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 data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:123
Base template for the ElementsTrait class.
Definition: ElementsTrait.h:108
typename CrossTrait< T1, T2 >::Type CrossTrait_
Auxiliary alias declaration for the CrossTrait class template.The CrossTrait_ alias declaration provi...
Definition: CrossTrait.h:209
Constraint on the data type.
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:475
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1672
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1877
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1830
Compile time check for shrinkable data types.This type trait tests whether the given data type is a s...
Definition: IsShrinkable.h:75
Header file for the IsNumeric type trait.
Base template for the LowType type trait.
Definition: LowType.h:133
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:1315
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:1355
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:291
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:119
Header file for the relaxation flag types.
CompressedVector & operator=(initializer_list< Type > list)
List assignment to all vector elements.
Definition: CompressedVector.h:910
Base template for the MultTrait class.
Definition: MultTrait.h:119
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Constraint on the data type.
size_t extendCapacity() const noexcept
Calculating a new vector capacity.
Definition: CompressedVector.h:1450
Reference at(size_t index)
Checked access to the compressed vector elements.
Definition: CompressedVector.h:760
Headerfile for the generic transfer algorithm.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
Header file for the VectorAccessProxy class.
Header file for the isDefault shim.
Constraint on the data type.
decltype(auto) serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:816
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:290
#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:2255
void divAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the division assignment of a dense vector.
Definition: CompressedVector.h:2282
EnableIf_< IsBuiltin< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:230
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: CompressedVector.h:2036
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
Base template for the DivTrait class.
Definition: DivTrait.h:120
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:289
void swap(CompressedVector &sv) noexcept
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1428
ConstIterator cbegin() const noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:832
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
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
Iterator end() noexcept
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:846
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Constraint on the size of two data types.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:177
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:684
typename SubTrait< T1, T2 >::Type SubTrait_
Auxiliary alias declaration for the SubTrait class template.The SubTrait_ alias declaration provides ...
Definition: SubTrait.h:291
size_t capacity() const noexcept
Returns the maximum capacity of the compressed vector.
Definition: CompressedVector.h:1284
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:130
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:477
Compile time type check.This class tests whether the given template parameter T is an rvalue referenc...
Definition: IsRValueReference.h:77
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:281
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:254
ConstIterator cend() const noexcept
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:876
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:628
Base template for the SubTrait class.
Definition: SubTrait.h:119
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition: Transfer.h:70
Iterator begin() noexcept
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:802
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:479
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:2016
Header file for the IsResizable type trait.
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:2055
Base template for the UnaryMapTrait class.
Definition: UnaryMapTrait.h:95
#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:291
#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:199
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:362
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1380
Header file for the HighType type trait.