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 <functional>
49 #include <blaze/math/Forward.h>
50 #include <blaze/math/Functions.h>
67 #include <blaze/util/Assert.h>
73 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/Exception.h>
75 #include <blaze/util/Memory.h>
76 #include <blaze/util/mpl/If.h>
77 #include <blaze/util/Null.h>
78 #include <blaze/util/Types.h>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS DEFINITION
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
185 template< typename Type // Data type of the vector
186  , bool TF = defaultTransposeFlag > // Transpose flag
187 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
188 {
189  private:
190  //**Type definitions****************************************************************************
192  //**********************************************************************************************
193 
194  //**Private class Element***********************************************************************
198  struct Element : public ElementBase
199  {
200  // This operator is required due to a bug in all versions of the the MSVC compiler.
201  // A simple 'using ElementBase::operator=;' statement results in ambiguity problems.
202  template< typename Other >
203  inline Element& operator=( const Other& rhs )
204  {
205  ElementBase::operator=( rhs );
206  return *this;
207  }
208 
209  friend class CompressedVector;
210  };
212  //**********************************************************************************************
213 
214  //**Private class FindIndex*********************************************************************
218  struct FindIndex : public std::binary_function<Element,size_t,bool>
219  {
220  inline bool operator()( const Element& element, size_t index ) const {
221  return element.index() < index;
222  }
223  inline bool operator()( size_t index, const Element& element ) const {
224  return index < element.index();
225  }
226  inline bool operator()( const Element& element1, const Element& element2 ) const {
227  return element1.index() < element2.index();
228  }
229  };
231  //**********************************************************************************************
232 
233  public:
234  //**Type definitions****************************************************************************
236  typedef This ResultType;
238  typedef Type ElementType;
239  typedef const Type& ReturnType;
242  typedef const Type& ConstReference;
243  typedef Element* Iterator;
244  typedef const Element* ConstIterator;
245  //**********************************************************************************************
246 
247  //**Rebind struct definition********************************************************************
250  template< typename ET > // Data type of the other vector
251  struct Rebind {
253  };
254  //**********************************************************************************************
255 
256  //**Compilation flags***************************************************************************
258 
261  enum { smpAssignable = !IsSMPAssignable<Type>::value };
262  //**********************************************************************************************
263 
264  //**Constructors********************************************************************************
267  explicit inline CompressedVector();
268  explicit inline CompressedVector( size_t size );
269  explicit inline CompressedVector( size_t size, size_t nonzeros );
270  inline CompressedVector( const CompressedVector& sv );
271  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
272  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
274  //**********************************************************************************************
275 
276  //**Destructor**********************************************************************************
279  inline ~CompressedVector();
281  //**********************************************************************************************
282 
283  //**Data access functions***********************************************************************
286  inline Reference operator[]( size_t index );
287  inline ConstReference operator[]( size_t index ) const;
288  inline Reference at( size_t index );
289  inline ConstReference at( size_t index ) const;
290  inline Iterator begin ();
291  inline ConstIterator begin () const;
292  inline ConstIterator cbegin() const;
293  inline Iterator end ();
294  inline ConstIterator end () const;
295  inline ConstIterator cend () const;
297  //**********************************************************************************************
298 
299  //**Assignment operators************************************************************************
302  inline CompressedVector& operator= ( const CompressedVector& rhs );
303  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
304  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
305  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
306  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
307  template< typename VT > inline CompressedVector& operator*=( const Vector<VT,TF>& rhs );
308 
309  template< typename Other >
310  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
311  operator*=( Other rhs );
312 
313  template< typename Other >
314  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
315  operator/=( Other rhs );
317  //**********************************************************************************************
318 
319  //**Utility functions***************************************************************************
322  inline size_t size() const;
323  inline size_t capacity() const;
324  inline size_t nonZeros() const;
325  inline void reset();
326  inline void clear();
327  inline Iterator set ( size_t index, const Type& value );
328  inline Iterator insert( size_t index, const Type& value );
329  inline void erase ( size_t index );
330  inline Iterator erase ( Iterator pos );
331  inline Iterator erase ( Iterator first, Iterator last );
332  inline void resize( size_t n, bool preserve=true );
333  void reserve( size_t n );
334  template< typename Other > inline CompressedVector& scale( const Other& scalar );
335  inline void swap( CompressedVector& sv ) /* throw() */;
337  //**********************************************************************************************
338 
339  //**Lookup functions****************************************************************************
342  inline Iterator find ( size_t index );
343  inline ConstIterator find ( size_t index ) const;
344  inline Iterator lowerBound( size_t index );
345  inline ConstIterator lowerBound( size_t index ) const;
346  inline Iterator upperBound( size_t index );
347  inline ConstIterator upperBound( size_t index ) const;
349  //**********************************************************************************************
350 
351  //**Low-level utility functions*****************************************************************
354  inline void append( size_t index, const Type& value, bool check=false );
356  //**********************************************************************************************
357 
358  //**Expression template evaluation functions****************************************************
361  template< typename Other > inline bool canAlias ( const Other* alias ) const;
362  template< typename Other > inline bool isAliased( const Other* alias ) const;
363 
364  inline bool canSMPAssign() const;
365 
366  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
367  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
368  template< typename VT > inline void addAssign( const DenseVector <VT,TF>& rhs );
369  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
370  template< typename VT > inline void subAssign( const DenseVector <VT,TF>& rhs );
371  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
373  //**********************************************************************************************
374 
375  private:
376  //**Utility functions***************************************************************************
379  Iterator insert( Iterator pos, size_t index, const Type& value );
380  inline size_t extendCapacity() const;
382  //**********************************************************************************************
383 
384  //**Member variables****************************************************************************
387  size_t size_;
388  size_t capacity_;
389  Iterator begin_;
390  Iterator end_;
391 
392  static const Type zero_;
393 
394  //**********************************************************************************************
395 
396  //**Compile time checks*************************************************************************
402  BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE( ElementBase, Element );
404  //**********************************************************************************************
405 };
406 //*************************************************************************************************
407 
408 
409 
410 
411 //=================================================================================================
412 //
413 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
414 //
415 //=================================================================================================
416 
417 template< typename Type // Data type of the vector
418  , bool TF > // Transpose flag
419 const Type CompressedVector<Type,TF>::zero_ = Type();
420 
421 
422 
423 
424 //=================================================================================================
425 //
426 // CONSTRUCTORS
427 //
428 //=================================================================================================
429 
430 //*************************************************************************************************
433 template< typename Type // Data type of the vector
434  , bool TF > // Transpose flag
436  : size_ ( 0UL ) // The current size/dimension of the compressed vector
437  , capacity_( 0UL ) // The maximum capacity of the compressed vector
438  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
439  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
440 {}
441 //*************************************************************************************************
442 
443 
444 //*************************************************************************************************
449 template< typename Type // Data type of the vector
450  , bool TF > // Transpose flag
452  : size_ ( n ) // The current size/dimension of the compressed vector
453  , capacity_( 0UL ) // The maximum capacity of the compressed vector
454  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
455  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
456 {}
457 //*************************************************************************************************
458 
459 
460 //*************************************************************************************************
466 template< typename Type // Data type of the vector
467  , bool TF > // Transpose flag
468 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
469  : size_ ( n ) // The current size/dimension of the compressed vector
470  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
471  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
472  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
473 {}
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
485 template< typename Type // Data type of the vector
486  , bool TF > // Transpose flag
488  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
489  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
490  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
491  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
492 {
493  std::copy( sv.begin_, sv.end_, begin_ );
494 }
495 //*************************************************************************************************
496 
497 
498 //*************************************************************************************************
503 template< typename Type // Data type of the vector
504  , bool TF > // Transpose flag
505 template< typename VT > // Type of the foreign dense vector
507  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
508  , capacity_( 0UL ) // The maximum capacity of the compressed vector
509  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
510  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
511 {
512  using blaze::assign;
513  assign( *this, ~dv );
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
523 template< typename Type // Data type of the vector
524  , bool TF > // Transpose flag
525 template< typename VT > // Type of the foreign sparse vector
527  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
528  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
529  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
530  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
531 {
532  using blaze::assign;
533  assign( *this, ~sv );
534 }
535 //*************************************************************************************************
536 
537 
538 
539 
540 //=================================================================================================
541 //
542 // DESTRUCTOR
543 //
544 //=================================================================================================
545 
546 //*************************************************************************************************
549 template< typename Type // Data type of the vector
550  , bool TF > // Transpose flag
552 {
553  deallocate( begin_ );
554 }
555 //*************************************************************************************************
556 
557 
558 
559 
560 //=================================================================================================
561 //
562 // DATA ACCESS FUNCTIONS
563 //
564 //=================================================================================================
565 
566 //*************************************************************************************************
577 template< typename Type // Data type of the vector
578  , bool TF > // Transpose flag
581 {
582  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
583 
584  return Reference( *this, index );
585 }
586 //*************************************************************************************************
587 
588 
589 //*************************************************************************************************
595 template< typename Type // Data type of the vector
596  , bool TF > // Transpose flag
599 {
600  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
601 
602  const ConstIterator pos( lowerBound( index ) );
603 
604  if( pos == end_ || pos->index_ != index )
605  return zero_;
606  else
607  return pos->value_;
608 }
609 //*************************************************************************************************
610 
611 
612 //*************************************************************************************************
624 template< typename Type // Data type of the vector
625  , bool TF > // Transpose flag
628 {
629  if( index >= size_ ) {
630  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
631  }
632  return (*this)[index];
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
649 template< typename Type // Data type of the vector
650  , bool TF > // Transpose flag
652  CompressedVector<Type,TF>::at( size_t index ) const
653 {
654  if( index >= size_ ) {
655  BLAZE_THROW_OUT_OF_RANGE( "Invalid compressed vector access index" );
656  }
657  return (*this)[index];
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
667 template< typename Type // Data type of the vector
668  , bool TF > // Transpose flag
670 {
671  return Iterator( begin_ );
672 }
673 //*************************************************************************************************
674 
675 
676 //*************************************************************************************************
681 template< typename Type // Data type of the vector
682  , bool TF > // Transpose flag
684 {
685  return ConstIterator( begin_ );
686 }
687 //*************************************************************************************************
688 
689 
690 //*************************************************************************************************
695 template< typename Type // Data type of the vector
696  , bool TF > // Transpose flag
698 {
699  return ConstIterator( begin_ );
700 }
701 //*************************************************************************************************
702 
703 
704 //*************************************************************************************************
709 template< typename Type // Data type of the vector
710  , bool TF > // Transpose flag
712 {
713  return Iterator( end_ );
714 }
715 //*************************************************************************************************
716 
717 
718 //*************************************************************************************************
723 template< typename Type // Data type of the vector
724  , bool TF > // Transpose flag
726 {
727  return ConstIterator( end_ );
728 }
729 //*************************************************************************************************
730 
731 
732 //*************************************************************************************************
737 template< typename Type // Data type of the vector
738  , bool TF > // Transpose flag
740 {
741  return ConstIterator( end_ );
742 }
743 //*************************************************************************************************
744 
745 
746 
747 
748 //=================================================================================================
749 //
750 // ASSIGNMENT OPERATORS
751 //
752 //=================================================================================================
753 
754 //*************************************************************************************************
763 template< typename Type // Data type of the vector
764  , bool TF > // Transpose flag
767 {
768  if( &rhs == this ) return *this;
769 
770  const size_t nonzeros( rhs.nonZeros() );
771 
772  if( nonzeros > capacity_ ) {
773  Iterator newBegin( allocate<Element>( nonzeros ) );
774  end_ = std::copy( rhs.begin_, rhs.end_, newBegin );
775  std::swap( begin_, newBegin );
776  deallocate( newBegin );
777 
778  size_ = rhs.size_;
779  capacity_ = nonzeros;
780  }
781  else {
782  end_ = std::copy( rhs.begin_, rhs.end_, begin_ );
783  size_ = rhs.size_;
784  }
785 
786  return *this;
787 }
788 //*************************************************************************************************
789 
790 
791 //*************************************************************************************************
800 template< typename Type // Data type of the vector
801  , bool TF > // Transpose flag
802 template< typename VT > // Type of the right-hand side dense vector
805 {
806  using blaze::assign;
807 
808  if( (~rhs).canAlias( this ) ) {
809  CompressedVector tmp( ~rhs );
810  swap( tmp );
811  }
812  else {
813  size_ = (~rhs).size();
814  end_ = begin_;
815  assign( *this, ~rhs );
816  }
817 
818  return *this;
819 }
820 //*************************************************************************************************
821 
822 
823 //*************************************************************************************************
832 template< typename Type // Data type of the vector
833  , bool TF > // Transpose flag
834 template< typename VT > // Type of the right-hand side sparse vector
837 {
838  using blaze::assign;
839 
840  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
841  CompressedVector tmp( ~rhs );
842  swap( tmp );
843  }
844  else {
845  size_ = (~rhs).size();
846  end_ = begin_;
847  assign( *this, ~rhs );
848  }
849 
850  return *this;
851 }
852 //*************************************************************************************************
853 
854 
855 //*************************************************************************************************
865 template< typename Type // Data type of the vector
866  , bool TF > // Transpose flag
867 template< typename VT > // Type of the right-hand side vector
869 {
870  using blaze::addAssign;
871 
872  if( (~rhs).size() != size_ ) {
873  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
874  }
875 
876  addAssign( *this, ~rhs );
877 
878  return *this;
879 }
880 //*************************************************************************************************
881 
882 
883 //*************************************************************************************************
893 template< typename Type // Data type of the vector
894  , bool TF > // Transpose flag
895 template< typename VT > // Type of the right-hand side vector
897 {
898  using blaze::subAssign;
899 
900  if( (~rhs).size() != size_ ) {
901  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
902  }
903 
904  subAssign( *this, ~rhs );
905 
906  return *this;
907 }
908 //*************************************************************************************************
909 
910 
911 //*************************************************************************************************
922 template< typename Type // Data type of the vector
923  , bool TF > // Transpose flag
924 template< typename VT > // Type of the right-hand side vector
926 {
927  if( (~rhs).size() != size_ ) {
928  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
929  }
930 
931  CompressedVector<Type,TF> tmp( *this * (~rhs) );
932  swap( tmp );
933 
934  return *this;
935 }
936 //*************************************************************************************************
937 
938 
939 //*************************************************************************************************
950 template< typename Type // Data type of the vector
951  , bool TF > // Transpose flag
952 template< typename Other > // Data type of the right-hand side scalar
955 {
956  for( Iterator element=begin_; element!=end_; ++element )
957  element->value_ *= rhs;
958  return *this;
959 }
960 //*************************************************************************************************
961 
962 
963 //*************************************************************************************************
975 template< typename Type // Data type of the vector
976  , bool TF > // Transpose flag
977 template< typename Other > // Data type of the right-hand side scalar
978 inline typename EnableIf< IsNumeric<Other>, CompressedVector<Type,TF> >::Type&
980 {
981  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
982 
983  typedef typename DivTrait<Type,Other>::Type DT;
984  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
985 
986  // Depending on the two involved data types, an integer division is applied or a
987  // floating point division is selected.
989  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
990  for( Iterator element=begin_; element!=end_; ++element )
991  element->value_ *= tmp;
992  }
993  else {
994  for( Iterator element=begin_; element!=end_; ++element )
995  element->value_ /= rhs;
996  }
997 
998  return *this;
999 }
1000 //*************************************************************************************************
1001 
1002 
1003 
1004 
1005 //=================================================================================================
1006 //
1007 // UTILITY FUNCTIONS
1008 //
1009 //=================================================================================================
1010 
1011 //*************************************************************************************************
1016 template< typename Type // Data type of the vector
1017  , bool TF > // Transpose flag
1018 inline size_t CompressedVector<Type,TF>::size() const
1019 {
1020  return size_;
1021 }
1022 //*************************************************************************************************
1023 
1024 
1025 //*************************************************************************************************
1030 template< typename Type // Data type of the vector
1031  , bool TF > // Transpose flag
1033 {
1034  return capacity_;
1035 }
1036 //*************************************************************************************************
1037 
1038 
1039 //*************************************************************************************************
1047 template< typename Type // Data type of the vector
1048  , bool TF > // Transpose flag
1050 {
1051  return end_ - begin_;
1052 }
1053 //*************************************************************************************************
1054 
1055 
1056 //*************************************************************************************************
1061 template< typename Type // Data type of the vector
1062  , bool TF > // Transpose flag
1064 {
1065  end_ = begin_;
1066 }
1067 //*************************************************************************************************
1068 
1069 
1070 //*************************************************************************************************
1077 template< typename Type // Data type of the vector
1078  , bool TF > // Transpose flag
1080 {
1081  size_ = 0UL;
1082  end_ = begin_;
1083 }
1084 //*************************************************************************************************
1085 
1086 
1087 //*************************************************************************************************
1098 template< typename Type // Data type of the vector
1099  , bool TF > // Transpose flag
1101  CompressedVector<Type,TF>::set( size_t index, const Type& value )
1102 {
1103  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1104 
1105  const Iterator pos( lowerBound( index ) );
1106 
1107  if( pos != end_ && pos->index_ == index ) {
1108  pos->value() = value;
1109  return pos;
1110  }
1111  else return insert( pos, index, value );
1112 }
1113 //*************************************************************************************************
1114 
1115 
1116 //*************************************************************************************************
1128 template< typename Type // Data type of the vector
1129  , bool TF > // Transpose flag
1131  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1132 {
1133  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1134 
1135  const Iterator pos( lowerBound( index ) );
1136 
1137  if( pos != end_ && pos->index_ == index ) {
1138  BLAZE_THROW_INVALID_ARGUMENT( "Bad access index" );
1139  }
1140 
1141  return insert( pos, index, value );
1142 }
1143 //*************************************************************************************************
1144 
1145 
1146 //*************************************************************************************************
1155 template< typename Type // Data type of the vector
1156  , bool TF > // Transpose flag
1158  CompressedVector<Type,TF>::insert( Iterator pos, size_t index, const Type& value )
1159 {
1160  if( nonZeros() != capacity_ ) {
1161  std::copy_backward( pos, end_, end_+1 );
1162  pos->value_ = value;
1163  pos->index_ = index;
1164  ++end_;
1165 
1166  return pos;
1167  }
1168  else {
1169  size_t newCapacity( extendCapacity() );
1170 
1171  Iterator newBegin = allocate<Element>( newCapacity );
1172  Iterator tmp = std::copy( begin_, pos, newBegin );
1173  tmp->value_ = value;
1174  tmp->index_ = index;
1175  end_ = std::copy( pos, end_, tmp+1 );
1176 
1177  std::swap( newBegin, begin_ );
1178  deallocate( newBegin );
1179  capacity_ = newCapacity;
1180 
1181  return tmp;
1182  }
1183 }
1184 //*************************************************************************************************
1185 
1186 
1187 //*************************************************************************************************
1195 template< typename Type // Data type of the vector
1196  , bool TF > // Transpose flag
1197 inline void CompressedVector<Type,TF>::erase( size_t index )
1198 {
1199  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1200 
1201  const Iterator pos( find( index ) );
1202  if( pos != end_ )
1203  end_ = std::copy( pos+1, end_, pos );
1204 }
1205 //*************************************************************************************************
1206 
1207 
1208 //*************************************************************************************************
1216 template< typename Type // Data type of the vector
1217  , bool TF > // Transpose flag
1219 {
1220  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1221 
1222  if( pos != end_ )
1223  end_ = std::copy( pos+1, end_, pos );
1224  return pos;
1225 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1238 template< typename Type // Data type of the vector
1239  , bool TF > // Transpose flag
1242 {
1243  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1244  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1245  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1246 
1247  if( first != last )
1248  end_ = std::copy( last, end_, first );
1249  return first;
1250 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1268 template< typename Type // Data type of the vector
1269  , bool TF > // Transpose flag
1270 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1271 {
1272  if( preserve ) {
1273  end_ = lowerBound( n );
1274  }
1275  else {
1276  end_ = begin_;
1277  }
1278 
1279  size_ = n;
1280 }
1281 //*************************************************************************************************
1282 
1283 
1284 //*************************************************************************************************
1293 template< typename Type // Data type of the vector
1294  , bool TF > // Transpose flag
1296 {
1297  if( n > capacity_ ) {
1298  const size_t newCapacity( n );
1299 
1300  // Allocating a new data and index array
1301  Iterator newBegin = allocate<Element>( newCapacity );
1302 
1303  // Replacing the old data and index array
1304  end_ = std::copy( begin_, end_, newBegin );
1305  std::swap( newBegin, begin_ );
1306  capacity_ = newCapacity;
1307  deallocate( newBegin );
1308  }
1309 }
1310 //*************************************************************************************************
1311 
1312 
1313 //*************************************************************************************************
1319 template< typename Type // Data type of the vector
1320  , bool TF > // Transpose flag
1321 template< typename Other > // Data type of the scalar value
1323 {
1324  for( Iterator element=begin_; element!=end_; ++element )
1325  element->value_ *= scalar;
1326  return *this;
1327 }
1328 //*************************************************************************************************
1329 
1330 
1331 //*************************************************************************************************
1338 template< typename Type // Data type of the vector
1339  , bool TF > // Transpose flag
1340 inline void CompressedVector<Type,TF>::swap( CompressedVector& sv ) /* throw() */
1341 {
1342  std::swap( size_, sv.size_ );
1343  std::swap( capacity_, sv.capacity_ );
1344  std::swap( begin_, sv.begin_ );
1345  std::swap( end_, sv.end_ );
1346 }
1347 //*************************************************************************************************
1348 
1349 
1350 //*************************************************************************************************
1358 template< typename Type // Data type of the vector
1359  , bool TF > // Transpose flag
1361 {
1362  using blaze::max;
1363  using blaze::min;
1364 
1365  size_t nonzeros( 2UL*capacity_+1UL );
1366  nonzeros = max( nonzeros, 7UL );
1367  nonzeros = min( nonzeros, size_ );
1368 
1369  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1370 
1371  return nonzeros;
1372 }
1373 //*************************************************************************************************
1374 
1375 
1376 
1377 
1378 //=================================================================================================
1379 //
1380 // LOOKUP FUNCTIONS
1381 //
1382 //=================================================================================================
1383 
1384 //*************************************************************************************************
1397 template< typename Type // Data type of the vector
1398  , bool TF > // Transpose flag
1400 {
1401  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1402 }
1403 //*************************************************************************************************
1404 
1405 
1406 //*************************************************************************************************
1419 template< typename Type // Data type of the vector
1420  , bool TF > // Transpose flag
1422 {
1423  const ConstIterator pos( lowerBound( index ) );
1424  if( pos != end_ && pos->index_ == index )
1425  return pos;
1426  else return end_;
1427 }
1428 //*************************************************************************************************
1429 
1430 
1431 //*************************************************************************************************
1443 template< typename Type // Data type of the vector
1444  , bool TF > // Transpose flag
1447 {
1448  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1449 }
1450 //*************************************************************************************************
1451 
1452 
1453 //*************************************************************************************************
1465 template< typename Type // Data type of the vector
1466  , bool TF > // Transpose flag
1469 {
1470  return std::lower_bound( begin_, end_, index, FindIndex() );
1471 }
1472 //*************************************************************************************************
1473 
1474 
1475 //*************************************************************************************************
1487 template< typename Type // Data type of the vector
1488  , bool TF > // Transpose flag
1491 {
1492  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1509 template< typename Type // Data type of the vector
1510  , bool TF > // Transpose flag
1513 {
1514  return std::upper_bound( begin_, end_, index, FindIndex() );
1515 }
1516 //*************************************************************************************************
1517 
1518 
1519 
1520 
1521 //=================================================================================================
1522 //
1523 // LOW-LEVEL UTILITY FUNCTIONS
1524 //
1525 //=================================================================================================
1526 
1527 //*************************************************************************************************
1551 template< typename Type // Data type of the vector
1552  , bool TF > // Transpose flag
1553 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1554 {
1555  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1556  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved capacity" );
1557  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1558 
1559  end_->value_ = value;
1560 
1561  if( !check || !isDefault( end_->value_ ) ) {
1562  end_->index_ = index;
1563  ++end_;
1564  }
1565 }
1566 //*************************************************************************************************
1567 
1568 
1569 
1570 
1571 //=================================================================================================
1572 //
1573 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1574 //
1575 //=================================================================================================
1576 
1577 //*************************************************************************************************
1587 template< typename Type // Data type of the vector
1588  , bool TF > // Transpose flag
1589 template< typename Other > // Data type of the foreign expression
1590 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const
1591 {
1592  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1593 }
1594 //*************************************************************************************************
1595 
1596 
1597 //*************************************************************************************************
1607 template< typename Type // Data type of the vector
1608  , bool TF > // Transpose flag
1609 template< typename Other > // Data type of the foreign expression
1610 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const
1611 {
1612  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1613 }
1614 //*************************************************************************************************
1615 
1616 
1617 //*************************************************************************************************
1627 template< typename Type // Data type of the vector
1628  , bool TF > // Transpose flag
1630 {
1631  return false;
1632 }
1633 //*************************************************************************************************
1634 
1635 
1636 //*************************************************************************************************
1647 template< typename Type // Data type of the vector
1648  , bool TF > // Transpose flag
1649 template< typename VT > // Type of the right-hand side dense vector
1651 {
1652  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1653  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1654 
1655  size_t nonzeros( 0UL );
1656 
1657  for( size_t i=0UL; i<size_; ++i )
1658  {
1659  if( nonzeros == capacity_ )
1660  reserve( extendCapacity() );
1661 
1662  end_->value_ = (~rhs)[i];
1663 
1664  if( !isDefault( end_->value_ ) ) {
1665  end_->index_ = i;
1666  ++end_;
1667  ++nonzeros;
1668  }
1669  }
1670 }
1671 //*************************************************************************************************
1672 
1673 
1674 //*************************************************************************************************
1685 template< typename Type // Data type of the vector
1686  , bool TF > // Transpose flag
1687 template< typename VT > // Type of the right-hand side sparse vector
1689 {
1690  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1691  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1692 
1693  // Using the following formulation instead of a std::copy function call of the form
1694  //
1695  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
1696  //
1697  // results in much less requirements on the ConstIterator type provided from the right-hand
1698  // sparse vector type
1699  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1700  append( element->index(), element->value() );
1701 }
1702 //*************************************************************************************************
1703 
1704 
1705 //*************************************************************************************************
1716 template< typename Type // Data type of the vector
1717  , bool TF > // Transpose flag
1718 template< typename VT > // Type of the right-hand side dense vector
1720 {
1721  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1722 
1726 
1727  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1728 
1729  const AddType tmp( serial( *this + (~rhs) ) );
1730  reset();
1731  assign( tmp );
1732 }
1733 //*************************************************************************************************
1734 
1735 
1736 //*************************************************************************************************
1747 template< typename Type // Data type of the vector
1748  , bool TF > // Transpose flag
1749 template< typename VT > // Type of the right-hand side sparse vector
1751 {
1752  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1753 
1754  CompressedVector<Type,TF> tmp( serial( *this + (~rhs) ) );
1755  swap( tmp );
1756 }
1757 //*************************************************************************************************
1758 
1759 
1760 //*************************************************************************************************
1771 template< typename Type // Data type of the vector
1772  , bool TF > // Transpose flag
1773 template< typename VT > // Type of the right-hand side dense vector
1775 {
1776  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1777 
1781 
1782  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1783 
1784  const SubType tmp( serial( *this - (~rhs) ) );
1785  reset();
1786  assign( tmp );
1787 }
1788 //*************************************************************************************************
1789 
1790 
1791 //*************************************************************************************************
1802 template< typename Type // Data type of the vector
1803  , bool TF > // Transpose flag
1804 template< typename VT > // Type of the right-hand side sparse vector
1806 {
1807  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1808 
1809  CompressedVector<Type,TF> tmp( serial( *this - (~rhs) ) );
1810  swap( tmp );
1811 }
1812 //*************************************************************************************************
1813 
1814 
1815 
1816 
1817 //=================================================================================================
1818 //
1819 // COMPRESSEDVECTOR OPERATORS
1820 //
1821 //=================================================================================================
1822 
1823 //*************************************************************************************************
1826 template< typename Type, bool TF >
1827 inline void reset( CompressedVector<Type,TF>& v );
1828 
1829 template< typename Type, bool TF >
1830 inline void clear( CompressedVector<Type,TF>& v );
1831 
1832 template< typename Type, bool TF >
1833 inline bool isDefault( const CompressedVector<Type,TF>& v );
1834 
1835 template< typename Type, bool TF >
1836 inline bool isIntact( const CompressedVector<Type,TF>& v );
1837 
1838 template< typename Type, bool TF >
1839 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */;
1840 
1841 template< typename Type, bool TF >
1842 inline void move( CompressedVector<Type,TF>& dst, CompressedVector<Type,TF>& src ) /* throw() */;
1844 //*************************************************************************************************
1845 
1846 
1847 //*************************************************************************************************
1854 template< typename Type // Data type of the vector
1855  , bool TF > // Transpose flag
1857 {
1858  v.reset();
1859 }
1860 //*************************************************************************************************
1861 
1862 
1863 //*************************************************************************************************
1870 template< typename Type // Data type of the vector
1871  , bool TF > // Transpose flag
1873 {
1874  v.clear();
1875 }
1876 //*************************************************************************************************
1877 
1878 
1879 //*************************************************************************************************
1896 template< typename Type // Data type of the vector
1897  , bool TF > // Transpose flag
1898 inline bool isDefault( const CompressedVector<Type,TF>& v )
1899 {
1900  return ( v.size() == 0UL );
1901 }
1902 //*************************************************************************************************
1903 
1904 
1905 //*************************************************************************************************
1923 template< typename Type // Data type of the vector
1924  , bool TF > // Transpose flag
1925 inline bool isIntact( const CompressedVector<Type,TF>& v )
1926 {
1927  return ( v.nonZeros() <= v.capacity() );
1928 }
1929 //*************************************************************************************************
1930 
1931 
1932 //*************************************************************************************************
1941 template< typename Type // Data type of the vector
1942  , bool TF > // Transpose flag
1943 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */
1944 {
1945  a.swap( b );
1946 }
1947 //*************************************************************************************************
1948 
1949 
1950 //*************************************************************************************************
1959 template< typename Type // Data type of the vector
1960  , bool TF > // Transpose flag
1961 inline void move( CompressedVector<Type,TF>& dst, CompressedVector<Type,TF>& src ) /* throw() */
1962 {
1963  dst.swap( src );
1964 }
1965 //*************************************************************************************************
1966 
1967 
1968 
1969 
1970 //=================================================================================================
1971 //
1972 // ISRESIZABLE SPECIALIZATIONS
1973 //
1974 //=================================================================================================
1975 
1976 //*************************************************************************************************
1978 template< typename T, bool TF >
1979 struct IsResizable< CompressedVector<T,TF> > : public TrueType
1980 {
1981  enum { value = 1 };
1982  typedef TrueType Type;
1983 };
1985 //*************************************************************************************************
1986 
1987 
1988 
1989 
1990 //=================================================================================================
1991 //
1992 // ADDTRAIT SPECIALIZATIONS
1993 //
1994 //=================================================================================================
1995 
1996 //*************************************************************************************************
1998 template< typename T1, bool TF, typename T2, size_t N >
1999 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2000 {
2001  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2002 };
2003 
2004 template< typename T1, size_t N, bool TF, typename T2 >
2005 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2006 {
2007  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2008 };
2009 
2010 template< typename T1, bool TF, typename T2, size_t N >
2011 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2012 {
2013  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2014 };
2015 
2016 template< typename T1, size_t N, bool TF, typename T2 >
2017 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2018 {
2019  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2020 };
2021 
2022 template< typename T1, bool TF, typename T2 >
2023 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2024 {
2025  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2026 };
2027 
2028 template< typename T1, bool TF, typename T2 >
2029 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2030 {
2031  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2032 };
2033 
2034 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2035 struct AddTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2036 {
2037  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2038 };
2039 
2040 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2041 struct AddTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2042 {
2043  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2044 };
2045 
2046 template< typename T1, bool TF, typename T2 >
2047 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2048 {
2049  typedef CompressedVector< typename AddTrait<T1,T2>::Type, TF > Type;
2050 };
2052 //*************************************************************************************************
2053 
2054 
2055 
2056 
2057 //=================================================================================================
2058 //
2059 // SUBTRAIT SPECIALIZATIONS
2060 //
2061 //=================================================================================================
2062 
2063 //*************************************************************************************************
2065 template< typename T1, bool TF, typename T2, size_t N >
2066 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2067 {
2068  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2069 };
2070 
2071 template< typename T1, size_t N, bool TF, typename T2 >
2072 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2073 {
2074  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2075 };
2076 
2077 template< typename T1, bool TF, typename T2, size_t N >
2078 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2079 {
2080  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2081 };
2082 
2083 template< typename T1, size_t N, bool TF, typename T2 >
2084 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2085 {
2086  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2087 };
2088 
2089 template< typename T1, bool TF, typename T2 >
2090 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2091 {
2092  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2093 };
2094 
2095 template< typename T1, bool TF, typename T2 >
2096 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2097 {
2098  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2099 };
2100 
2101 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2102 struct SubTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2103 {
2104  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2105 };
2106 
2107 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2108 struct SubTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2109 {
2110  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2111 };
2112 
2113 template< typename T1, bool TF, typename T2 >
2114 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2115 {
2116  typedef CompressedVector< typename SubTrait<T1,T2>::Type, TF > Type;
2117 };
2119 //*************************************************************************************************
2120 
2121 
2122 
2123 
2124 //=================================================================================================
2125 //
2126 // MULTTRAIT SPECIALIZATIONS
2127 //
2128 //=================================================================================================
2129 
2130 //*************************************************************************************************
2132 template< typename T1, bool TF, typename T2 >
2133 struct MultTrait< CompressedVector<T1,TF>, T2, typename EnableIf< IsNumeric<T2> >::Type >
2134 {
2135  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2136 };
2137 
2138 template< typename T1, typename T2, bool TF >
2139 struct MultTrait< T1, CompressedVector<T2,TF>, typename EnableIf< IsNumeric<T1> >::Type >
2140 {
2141  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2142 };
2143 
2144 template< typename T1, bool TF, typename T2, size_t N >
2145 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2146 {
2147  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2148 };
2149 
2150 template< typename T1, typename T2, size_t N >
2151 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
2152 {
2153  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2154 };
2155 
2156 template< typename T1, typename T2, size_t N >
2157 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
2158 {
2159  typedef typename MultTrait<T1,T2>::Type Type;
2160 };
2161 
2162 template< typename T1, size_t N, bool TF, typename T2 >
2163 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2164 {
2165  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2166 };
2167 
2168 template< typename T1, size_t N, typename T2 >
2169 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2170 {
2171  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2172 };
2173 
2174 template< typename T1, size_t N, typename T2 >
2175 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2176 {
2177  typedef typename MultTrait<T1,T2>::Type Type;
2178 };
2179 
2180 template< typename T1, bool TF, typename T2, size_t N >
2181 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2182 {
2183  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2184 };
2185 
2186 template< typename T1, typename T2, size_t N >
2187 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2188 {
2189  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2190 };
2191 
2192 template< typename T1, typename T2, size_t N >
2193 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2194 {
2195  typedef typename MultTrait<T1,T2>::Type Type;
2196 };
2197 
2198 template< typename T1, size_t N, bool TF, typename T2 >
2199 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2200 {
2201  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2202 };
2203 
2204 template< typename T1, size_t N, typename T2 >
2205 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2206 {
2207  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2208 };
2209 
2210 template< typename T1, size_t N, typename T2 >
2211 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2212 {
2213  typedef typename MultTrait<T1,T2>::Type Type;
2214 };
2215 
2216 template< typename T1, bool TF, typename T2 >
2217 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2218 {
2219  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2220 };
2221 
2222 template< typename T1, typename T2 >
2223 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2224 {
2225  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2226 };
2227 
2228 template< typename T1, typename T2 >
2229 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2230 {
2231  typedef typename MultTrait<T1,T2>::Type Type;
2232 };
2233 
2234 template< typename T1, bool TF, typename T2 >
2235 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2236 {
2237  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2238 };
2239 
2240 template< typename T1, typename T2 >
2241 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2242 {
2243  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2244 };
2245 
2246 template< typename T1, typename T2 >
2247 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2248 {
2249  typedef typename MultTrait<T1,T2>::Type Type;
2250 };
2251 
2252 template< typename T1, bool TF, typename T2, bool AF, bool PF >
2253 struct MultTrait< CompressedVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
2254 {
2255  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2256 };
2257 
2258 template< typename T1, typename T2, bool AF, bool PF >
2259 struct MultTrait< CompressedVector<T1,false>, CustomVector<T2,AF,PF,true> >
2260 {
2261  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2262 };
2263 
2264 template< typename T1, typename T2, bool AF, bool PF >
2265 struct MultTrait< CompressedVector<T1,true>, CustomVector<T2,AF,PF,false> >
2266 {
2267  typedef typename MultTrait<T1,T2>::Type Type;
2268 };
2269 
2270 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
2271 struct MultTrait< CustomVector<T1,AF,PF,TF>, CompressedVector<T2,TF> >
2272 {
2273  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2274 };
2275 
2276 template< typename T1, bool AF, bool PF, typename T2 >
2277 struct MultTrait< CustomVector<T1,AF,PF,false>, CompressedVector<T2,true> >
2278 {
2279  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2280 };
2281 
2282 template< typename T1, bool AF, bool PF, typename T2 >
2283 struct MultTrait< CustomVector<T1,AF,PF,true>, CompressedVector<T2,false> >
2284 {
2285  typedef typename MultTrait<T1,T2>::Type Type;
2286 };
2287 
2288 template< typename T1, bool TF, typename T2 >
2289 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2290 {
2291  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2292 };
2293 
2294 template< typename T1, typename T2 >
2295 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2296 {
2297  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2298 };
2299 
2300 template< typename T1, typename T2 >
2301 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2302 {
2303  typedef typename MultTrait<T1,T2>::Type Type;
2304 };
2306 //*************************************************************************************************
2307 
2308 
2309 
2310 
2311 //=================================================================================================
2312 //
2313 // CROSSTRAIT SPECIALIZATIONS
2314 //
2315 //=================================================================================================
2316 
2317 //*************************************************************************************************
2319 template< typename T1, typename T2 >
2320 struct CrossTrait< CompressedVector<T1,false>, StaticVector<T2,3UL,false> >
2321 {
2322  private:
2323  typedef typename MultTrait<T1,T2>::Type T;
2324 
2325  public:
2326  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2327 };
2328 
2329 template< typename T1, typename T2 >
2330 struct CrossTrait< StaticVector<T1,3UL,false>, CompressedVector<T2,false> >
2331 {
2332  private:
2333  typedef typename MultTrait<T1,T2>::Type T;
2334 
2335  public:
2336  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2337 };
2338 
2339 template< typename T1, typename T2, size_t N >
2340 struct CrossTrait< CompressedVector<T1,false>, HybridVector<T2,N,false> >
2341 {
2342  private:
2343  typedef typename MultTrait<T1,T2>::Type T;
2344 
2345  public:
2346  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2347 };
2348 
2349 template< typename T1, size_t N, typename T2 >
2350 struct CrossTrait< HybridVector<T1,N,false>, CompressedVector<T2,false> >
2351 {
2352  private:
2353  typedef typename MultTrait<T1,T2>::Type T;
2354 
2355  public:
2356  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2357 };
2358 
2359 template< typename T1, typename T2 >
2360 struct CrossTrait< CompressedVector<T1,false>, DynamicVector<T2,false> >
2361 {
2362  private:
2363  typedef typename MultTrait<T1,T2>::Type T;
2364 
2365  public:
2366  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2367 };
2368 
2369 template< typename T1, typename T2 >
2370 struct CrossTrait< DynamicVector<T1,false>, CompressedVector<T2,false> >
2371 {
2372  private:
2373  typedef typename MultTrait<T1,T2>::Type T;
2374 
2375  public:
2376  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2377 };
2378 
2379 template< typename T1, typename T2 >
2380 struct CrossTrait< CompressedVector<T1,false>, CompressedVector<T2,false> >
2381 {
2382  private:
2383  typedef typename MultTrait<T1,T2>::Type T;
2384 
2385  public:
2386  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2387 };
2389 //*************************************************************************************************
2390 
2391 
2392 
2393 
2394 //=================================================================================================
2395 //
2396 // DIVTRAIT SPECIALIZATIONS
2397 //
2398 //=================================================================================================
2399 
2400 //*************************************************************************************************
2402 template< typename T1, bool TF, typename T2 >
2403 struct DivTrait< CompressedVector<T1,TF>, T2, typename EnableIf< IsNumeric<T2> >::Type >
2404 {
2405  typedef CompressedVector< typename DivTrait<T1,T2>::Type, TF > Type;
2406 };
2408 //*************************************************************************************************
2409 
2410 
2411 
2412 
2413 //=================================================================================================
2414 //
2415 // MATHTRAIT SPECIALIZATIONS
2416 //
2417 //=================================================================================================
2418 
2419 //*************************************************************************************************
2421 template< typename T1, bool TF, typename T2 >
2422 struct MathTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2423 {
2424  typedef CompressedVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2425  typedef CompressedVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2426 };
2428 //*************************************************************************************************
2429 
2430 
2431 
2432 
2433 //=================================================================================================
2434 //
2435 // SUBVECTORTRAIT SPECIALIZATIONS
2436 //
2437 //=================================================================================================
2438 
2439 //*************************************************************************************************
2441 template< typename T1, bool TF >
2442 struct SubvectorTrait< CompressedVector<T1,TF> >
2443 {
2444  typedef CompressedVector<T1,TF> Type;
2445 };
2447 //*************************************************************************************************
2448 
2449 } // namespace blaze
2450 
2451 #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:116
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: CompressedVector.h:1610
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
const bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Header file for the subtraction trait.
Header file for basic type definitions.
Header file for the SparseVector base class.
size_t capacity() const
Returns the maximum capacity of the compressed vector.
Definition: CompressedVector.h:1032
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:250
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:1650
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1490
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:191
CompressedVector< ET, TF > Other
The type of the other CompressedVector.
Definition: CompressedVector.h:252
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:237
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:100
void swap(CompressedVector &sv)
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1340
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:340
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:241
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:242
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:1719
Iterator end()
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:711
#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:116
void clear()
Clearing the compressed vector.
Definition: CompressedVector.h:1079
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
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:378
Header file for memory allocation and deallocation functionality.
void move(CustomMatrix< Type, AF, PF, SO > &dst, CustomMatrix< Type, AF, PF, SO > &src)
Moving the contents of one custom matrix to another.
Definition: CustomMatrix.h:6085
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:387
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:240
EnableIf< IsBuiltin< T >, T * >::Type allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:152
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2751
size_t extendCapacity() const
Calculating a new vector capacity.
Definition: CompressedVector.h:1360
Header file for the ValueIndexPair class.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition: CompressedVector.h:251
Iterator set(size_t index, const Type &value)
Setting an element of the compressed vector.
Definition: CompressedVector.h:1101
void subAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: CompressedVector.h:1774
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1553
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
CompressedVector()
The default constructor for CompressedVector.
Definition: CompressedVector.h:435
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4998
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1590
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1131
#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:116
Header file for the IsSMPAssignable type trait.
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:739
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2753
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:389
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
EnableIf< IsBuiltin< T > >::Type deallocate(T *address)
Deallocation of memory for built-in data types.
Definition: Memory.h:227
#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't have the same size...
Definition: SameSize.h:78
Header file for the subvector trait.
Constraint on the data type.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:239
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
ConstIterator cbegin() const
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:697
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:78
Constraint on the data type.
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:187
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:1629
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:388
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:236
Header file for the serial shim.
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1197
Reference operator[](size_t index)
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:580
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1446
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1399
Header file for the IsNumeric type trait.
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:1063
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1270
Header file for the IsSparseVector type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:138
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Constraint on the data type.
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:235
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Reference at(size_t index)
Checked access to the compressed vector elements.
Definition: CompressedVector.h:627
#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:116
size_t size() const
Returns the current size/dimension of the compressed vector.
Definition: CompressedVector.h:1018
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the VectorAccessProxy class.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:244
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:243
Constraint on the data type.
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2752
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:1049
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:256
Base template for the DivTrait class.
Definition: DivTrait.h:138
Header file for the mathematical trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
Constraint on the size of two data types.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:551
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:766
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2755
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:390
Iterator begin()
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:669
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Base template for the SubTrait class.
Definition: SubTrait.h:138
Header file for exception macros.
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
Type ElementType
Type of the compressed vector elements.
Definition: CompressedVector.h:238
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:392
Header file for the IsResizable type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:81
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#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:187
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1295
Header file for a safe C++ NULL pointer implementation.