All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
45 #include <stdexcept>
50 #include <blaze/math/Forward.h>
51 #include <blaze/math/Functions.h>
68 #include <blaze/util/Assert.h>
75 #include <blaze/util/EnableIf.h>
76 #include <blaze/util/Memory.h>
77 #include <blaze/util/mpl/If.h>
78 #include <blaze/util/Null.h>
79 #include <blaze/util/Types.h>
82 
83 
84 namespace blaze {
85 
86 //=================================================================================================
87 //
88 // CLASS DEFINITION
89 //
90 //=================================================================================================
91 
92 //*************************************************************************************************
181 template< typename Type // Data type of the vector
182  , bool TF = defaultTransposeFlag > // Transpose flag
183 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
184 {
185  private:
186  //**Type definitions****************************************************************************
188  //**********************************************************************************************
189 
190  //**Private class Element***********************************************************************
194  struct Element : public ElementBase
195  {
196  // This operator is required due to a bug in all versions of the the MSVC compiler.
197  // A simple 'using ElementBase::operator=;' statement results in ambiguity problems.
198  template< typename Other >
199  inline Element& operator=( const Other& rhs )
200  {
201  ElementBase::operator=( rhs );
202  return *this;
203  }
204 
205  friend class CompressedVector;
206  };
208  //**********************************************************************************************
209 
210  //**Private class FindIndex*********************************************************************
214  struct FindIndex : public std::binary_function<Element,size_t,bool>
215  {
216  inline bool operator()( const Element& element, size_t index ) const {
217  return element.index() < index;
218  }
219  inline bool operator()( size_t index, const Element& element ) const {
220  return index < element.index();
221  }
222  inline bool operator()( const Element& element1, const Element& element2 ) const {
223  return element1.index() < element2.index();
224  }
225  };
227  //**********************************************************************************************
228 
229  public:
230  //**Type definitions****************************************************************************
232  typedef This ResultType;
234  typedef Type ElementType;
235  typedef const Type& ReturnType;
238  typedef const Type& ConstReference;
239  typedef Element* Iterator;
240  typedef const Element* ConstIterator;
241  //**********************************************************************************************
242 
243  //**Compilation flags***************************************************************************
245 
248  enum { smpAssignable = !IsSMPAssignable<Type>::value };
249  //**********************************************************************************************
250 
251  //**Constructors********************************************************************************
254  explicit inline CompressedVector();
255  explicit inline CompressedVector( size_t size );
256  explicit inline CompressedVector( size_t size, size_t nonzeros );
257  inline CompressedVector( const CompressedVector& sv );
258  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
259  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
261  //**********************************************************************************************
262 
263  //**Destructor**********************************************************************************
266  inline ~CompressedVector();
268  //**********************************************************************************************
269 
270  //**Data access functions***********************************************************************
273  inline Reference operator[]( size_t index );
274  inline ConstReference operator[]( size_t index ) const;
275  inline Iterator begin ();
276  inline ConstIterator begin () const;
277  inline ConstIterator cbegin() const;
278  inline Iterator end ();
279  inline ConstIterator end () const;
280  inline ConstIterator cend () const;
282  //**********************************************************************************************
283 
284  //**Assignment operators************************************************************************
287  inline CompressedVector& operator= ( const CompressedVector& rhs );
288  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
289  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
290  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
291  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
292  template< typename VT > inline CompressedVector& operator*=( const Vector<VT,TF>& rhs );
293 
294  template< typename Other >
295  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
296  operator*=( Other rhs );
297 
298  template< typename Other >
299  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
300  operator/=( Other rhs );
302  //**********************************************************************************************
303 
304  //**Utility functions***************************************************************************
307  inline size_t size() const;
308  inline size_t capacity() const;
309  inline size_t nonZeros() const;
310  inline void reset();
311  inline void clear();
312  Iterator insert( size_t index, const Type& value );
313  inline void erase ( size_t index );
314  inline Iterator erase ( Iterator pos );
315  inline Iterator erase ( Iterator first, Iterator last );
316  inline void resize( size_t n, bool preserve=true );
317  void reserve( size_t n );
318  template< typename Other > inline CompressedVector& scale( Other scalar );
319  inline void swap( CompressedVector& sv ) /* throw() */;
321  //**********************************************************************************************
322 
323  //**Lookup functions****************************************************************************
326  inline Iterator find ( size_t index );
327  inline ConstIterator find ( size_t index ) const;
328  inline Iterator lowerBound( size_t index );
329  inline ConstIterator lowerBound( size_t index ) const;
330  inline Iterator upperBound( size_t index );
331  inline ConstIterator upperBound( size_t index ) const;
333  //**********************************************************************************************
334 
335  //**Low-level utility functions*****************************************************************
338  inline void append( size_t index, const Type& value, bool check=false );
340  //**********************************************************************************************
341 
342  //**Expression template evaluation functions****************************************************
345  template< typename Other > inline bool canAlias ( const Other* alias ) const;
346  template< typename Other > inline bool isAliased( const Other* alias ) const;
347 
348  inline bool canSMPAssign() const;
349 
350  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
351  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
352  template< typename VT > inline void addAssign( const DenseVector <VT,TF>& rhs );
353  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
354  template< typename VT > inline void subAssign( const DenseVector <VT,TF>& rhs );
355  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
357  //**********************************************************************************************
358 
359  private:
360  //**Utility functions***************************************************************************
363  inline size_t extendCapacity() const;
365  //**********************************************************************************************
366 
367  //**Member variables****************************************************************************
370  size_t size_;
371  size_t capacity_;
374 
375  static const Type zero_;
376 
377  //**********************************************************************************************
378 
379  //**Compile time checks*************************************************************************
387  //**********************************************************************************************
388 };
389 //*************************************************************************************************
390 
391 
392 
393 
394 //=================================================================================================
395 //
396 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
397 //
398 //=================================================================================================
399 
400 template< typename Type // Data type of the vector
401  , bool TF > // Transpose flag
402 const Type CompressedVector<Type,TF>::zero_ = Type();
403 
404 
405 
406 
407 //=================================================================================================
408 //
409 // CONSTRUCTORS
410 //
411 //=================================================================================================
412 
413 //*************************************************************************************************
416 template< typename Type // Data type of the vector
417  , bool TF > // Transpose flag
419  : size_ ( 0UL ) // The current size/dimension of the compressed vector
420  , capacity_( 0UL ) // The maximum capacity of the compressed vector
421  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
422  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
423 {}
424 //*************************************************************************************************
425 
426 
427 //*************************************************************************************************
432 template< typename Type // Data type of the vector
433  , bool TF > // Transpose flag
435  : size_ ( n ) // The current size/dimension of the compressed vector
436  , capacity_( 0UL ) // The maximum capacity of the compressed vector
437  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
438  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
439 {}
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
449 template< typename Type // Data type of the vector
450  , bool TF > // Transpose flag
451 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
452  : size_ ( n ) // The current size/dimension of the compressed vector
453  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
454  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
455  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
456 {}
457 //*************************************************************************************************
458 
459 
460 //*************************************************************************************************
468 template< typename Type // Data type of the vector
469  , bool TF > // Transpose flag
471  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
472  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
473  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
474  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
475 {
476  std::copy( sv.begin_, sv.end_, begin_ );
477 }
478 //*************************************************************************************************
479 
480 
481 //*************************************************************************************************
486 template< typename Type // Data type of the vector
487  , bool TF > // Transpose flag
488 template< typename VT > // Type of the foreign dense vector
490  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
491  , capacity_( 0UL ) // The maximum capacity of the compressed vector
492  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
493  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
494 {
495  using blaze::assign;
496  assign( *this, ~dv );
497 }
498 //*************************************************************************************************
499 
500 
501 //*************************************************************************************************
506 template< typename Type // Data type of the vector
507  , bool TF > // Transpose flag
508 template< typename VT > // Type of the foreign sparse vector
510  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
511  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
512  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
513  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
514 {
515  using blaze::assign;
516  assign( *this, ~sv );
517 }
518 //*************************************************************************************************
519 
520 
521 
522 
523 //=================================================================================================
524 //
525 // DESTRUCTOR
526 //
527 //=================================================================================================
528 
529 //*************************************************************************************************
532 template< typename Type // Data type of the vector
533  , bool TF > // Transpose flag
535 {
536  deallocate( begin_ );
537 }
538 //*************************************************************************************************
539 
540 
541 
542 
543 //=================================================================================================
544 //
545 // DATA ACCESS FUNCTIONS
546 //
547 //=================================================================================================
548 
549 //*************************************************************************************************
560 template< typename Type // Data type of the vector
561  , bool TF > // Transpose flag
564 {
565  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
566 
567  return Reference( *this, index );
568 }
569 //*************************************************************************************************
570 
571 
572 //*************************************************************************************************
578 template< typename Type // Data type of the vector
579  , bool TF > // Transpose flag
582 {
583  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
584 
585  const ConstIterator pos( lowerBound( index ) );
586 
587  if( pos == end_ || pos->index_ != index )
588  return zero_;
589  else
590  return pos->value_;
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
600 template< typename Type // Data type of the vector
601  , bool TF > // Transpose flag
603 {
604  return Iterator( begin_ );
605 }
606 //*************************************************************************************************
607 
608 
609 //*************************************************************************************************
614 template< typename Type // Data type of the vector
615  , bool TF > // Transpose flag
617 {
618  return ConstIterator( begin_ );
619 }
620 //*************************************************************************************************
621 
622 
623 //*************************************************************************************************
628 template< typename Type // Data type of the vector
629  , bool TF > // Transpose flag
631 {
632  return ConstIterator( begin_ );
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
642 template< typename Type // Data type of the vector
643  , bool TF > // Transpose flag
645 {
646  return Iterator( end_ );
647 }
648 //*************************************************************************************************
649 
650 
651 //*************************************************************************************************
656 template< typename Type // Data type of the vector
657  , bool TF > // Transpose flag
659 {
660  return ConstIterator( end_ );
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
670 template< typename Type // Data type of the vector
671  , bool TF > // Transpose flag
673 {
674  return ConstIterator( end_ );
675 }
676 //*************************************************************************************************
677 
678 
679 
680 
681 //=================================================================================================
682 //
683 // ASSIGNMENT OPERATORS
684 //
685 //=================================================================================================
686 
687 //*************************************************************************************************
696 template< typename Type // Data type of the vector
697  , bool TF > // Transpose flag
700 {
701  if( &rhs == this ) return *this;
702 
703  const size_t nonzeros( rhs.nonZeros() );
704 
705  if( nonzeros > capacity_ ) {
706  Iterator newBegin( allocate<Element>( nonzeros ) );
707  end_ = std::copy( rhs.begin_, rhs.end_, newBegin );
708  std::swap( begin_, newBegin );
709  deallocate( newBegin );
710 
711  size_ = rhs.size_;
712  capacity_ = nonzeros;
713  }
714  else {
715  end_ = std::copy( rhs.begin_, rhs.end_, begin_ );
716  size_ = rhs.size_;
717  }
718 
719  return *this;
720 }
721 //*************************************************************************************************
722 
723 
724 //*************************************************************************************************
733 template< typename Type // Data type of the vector
734  , bool TF > // Transpose flag
735 template< typename VT > // Type of the right-hand side dense vector
738 {
739  using blaze::assign;
740 
741  if( (~rhs).canAlias( this ) ) {
742  CompressedVector tmp( rhs );
743  swap( tmp );
744  }
745  else {
746  size_ = (~rhs).size();
747  end_ = begin_;
748  assign( *this, ~rhs );
749  }
750 
751  return *this;
752 }
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
765 template< typename Type // Data type of the vector
766  , bool TF > // Transpose flag
767 template< typename VT > // Type of the right-hand side sparse vector
770 {
771  using blaze::assign;
772 
773  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
774  CompressedVector tmp( rhs );
775  swap( tmp );
776  }
777  else {
778  size_ = (~rhs).size();
779  end_ = begin_;
780  assign( *this, ~rhs );
781  }
782 
783  return *this;
784 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
798 template< typename Type // Data type of the vector
799  , bool TF > // Transpose flag
800 template< typename VT > // Type of the right-hand side vector
802 {
803  using blaze::addAssign;
804 
805  if( (~rhs).size() != size_ )
806  throw std::invalid_argument( "Vector sizes do not match" );
807 
808  addAssign( *this, ~rhs );
809 
810  return *this;
811 }
812 //*************************************************************************************************
813 
814 
815 //*************************************************************************************************
825 template< typename Type // Data type of the vector
826  , bool TF > // Transpose flag
827 template< typename VT > // Type of the right-hand side vector
829 {
830  using blaze::subAssign;
831 
832  if( (~rhs).size() != size_ )
833  throw std::invalid_argument( "Vector sizes do not match" );
834 
835  subAssign( *this, ~rhs );
836 
837  return *this;
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
853 template< typename Type // Data type of the vector
854  , bool TF > // Transpose flag
855 template< typename VT > // Type of the right-hand side vector
857 {
858  if( (~rhs).size() != size_ )
859  throw std::invalid_argument( "Vector sizes do not match" );
860 
861  CompressedVector<Type,TF> tmp( *this * (~rhs) );
862  swap( tmp );
863 
864  return *this;
865 }
866 //*************************************************************************************************
867 
868 
869 //*************************************************************************************************
880 template< typename Type // Data type of the vector
881  , bool TF > // Transpose flag
882 template< typename Other > // Data type of the right-hand side scalar
885 {
886  for( Iterator element=begin_; element!=end_; ++element )
887  element->value_ *= rhs;
888  return *this;
889 }
890 //*************************************************************************************************
891 
892 
893 //*************************************************************************************************
905 template< typename Type // Data type of the vector
906  , bool TF > // Transpose flag
907 template< typename Other > // Data type of the right-hand side scalar
910 {
911  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
912 
913  typedef typename DivTrait<Type,Other>::Type DT;
914  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
915 
916  // Depending on the two involved data types, an integer division is applied or a
917  // floating point division is selected.
919  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
920  for( Iterator element=begin_; element!=end_; ++element )
921  element->value_ *= tmp;
922  }
923  else {
924  for( Iterator element=begin_; element!=end_; ++element )
925  element->value_ /= rhs;
926  }
927 
928  return *this;
929 }
930 //*************************************************************************************************
931 
932 
933 
934 
935 //=================================================================================================
936 //
937 // UTILITY FUNCTIONS
938 //
939 //=================================================================================================
940 
941 //*************************************************************************************************
946 template< typename Type // Data type of the vector
947  , bool TF > // Transpose flag
948 inline size_t CompressedVector<Type,TF>::size() const
949 {
950  return size_;
951 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
960 template< typename Type // Data type of the vector
961  , bool TF > // Transpose flag
963 {
964  return capacity_;
965 }
966 //*************************************************************************************************
967 
968 
969 //*************************************************************************************************
977 template< typename Type // Data type of the vector
978  , bool TF > // Transpose flag
980 {
981  return end_ - begin_;
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
991 template< typename Type // Data type of the vector
992  , bool TF > // Transpose flag
994 {
995  end_ = begin_;
996 }
997 //*************************************************************************************************
998 
999 
1000 //*************************************************************************************************
1007 template< typename Type // Data type of the vector
1008  , bool TF > // Transpose flag
1010 {
1011  size_ = 0UL;
1012  end_ = begin_;
1013 }
1014 //*************************************************************************************************
1015 
1016 
1017 //*************************************************************************************************
1029 template< typename Type // Data type of the vector
1030  , bool TF > // Transpose flag
1032  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1033 {
1034  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1035 
1036  const Iterator pos( lowerBound( index ) );
1037 
1038  if( pos != end_ && pos->index_ == index )
1039  throw std::invalid_argument( "Bad access index" );
1040 
1041  if( nonZeros() != capacity_ ) {
1042  std::copy_backward( pos, end_, end_+1 );
1043  pos->value_ = value;
1044  pos->index_ = index;
1045  ++end_;
1046 
1047  return pos;
1048  }
1049  else {
1050  size_t newCapacity( extendCapacity() );
1051 
1052  Iterator newBegin = allocate<Element>( newCapacity );
1053  Iterator tmp = std::copy( begin_, pos, newBegin );
1054  tmp->value_ = value;
1055  tmp->index_ = index;
1056  end_ = std::copy( pos, end_, tmp+1 );
1057 
1058  std::swap( newBegin, begin_ );
1059  deallocate( newBegin );
1060  capacity_ = newCapacity;
1061 
1062  return tmp;
1063  }
1064 }
1065 //*************************************************************************************************
1066 
1067 
1068 //*************************************************************************************************
1076 template< typename Type // Data type of the vector
1077  , bool TF > // Transpose flag
1078 inline void CompressedVector<Type,TF>::erase( size_t index )
1079 {
1080  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1081 
1082  const Iterator pos( find( index ) );
1083  if( pos != end_ )
1084  end_ = std::copy( pos+1, end_, pos );
1085 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1097 template< typename Type // Data type of the vector
1098  , bool TF > // Transpose flag
1100 {
1101  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1102 
1103  if( pos != end_ )
1104  end_ = std::copy( pos+1, end_, pos );
1105  return pos;
1106 }
1107 //*************************************************************************************************
1108 
1109 
1110 //*************************************************************************************************
1119 template< typename Type // Data type of the vector
1120  , bool TF > // Transpose flag
1123 {
1124  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1125  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1126  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1127 
1128  if( first != last )
1129  end_ = std::copy( last, end_, first );
1130  return first;
1131 }
1132 //*************************************************************************************************
1133 
1134 
1135 //*************************************************************************************************
1149 template< typename Type // Data type of the vector
1150  , bool TF > // Transpose flag
1151 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1152 {
1153  if( preserve ) {
1154  end_ = lowerBound( n );
1155  }
1156  else {
1157  end_ = begin_;
1158  }
1159 
1160  size_ = n;
1161 }
1162 //*************************************************************************************************
1163 
1164 
1165 //*************************************************************************************************
1174 template< typename Type // Data type of the vector
1175  , bool TF > // Transpose flag
1177 {
1178  if( n > capacity_ ) {
1179  const size_t newCapacity( n );
1180 
1181  // Allocating a new data and index array
1182  Iterator newBegin = allocate<Element>( newCapacity );
1183 
1184  // Replacing the old data and index array
1185  end_ = std::copy( begin_, end_, newBegin );
1186  std::swap( newBegin, begin_ );
1187  capacity_ = newCapacity;
1188  deallocate( newBegin );
1189  }
1190 }
1191 //*************************************************************************************************
1192 
1193 
1194 //*************************************************************************************************
1200 template< typename Type // Data type of the vector
1201  , bool TF > // Transpose flag
1202 template< typename Other > // Data type of the scalar value
1204 {
1205  for( Iterator element=begin_; element!=end_; ++element )
1206  element->value_ *= scalar;
1207  return *this;
1208 }
1209 //*************************************************************************************************
1210 
1211 
1212 //*************************************************************************************************
1219 template< typename Type // Data type of the vector
1220  , bool TF > // Transpose flag
1221 inline void CompressedVector<Type,TF>::swap( CompressedVector& sv ) /* throw() */
1222 {
1223  std::swap( size_, sv.size_ );
1224  std::swap( capacity_, sv.capacity_ );
1225  std::swap( begin_, sv.begin_ );
1226  std::swap( end_, sv.end_ );
1227 }
1228 //*************************************************************************************************
1229 
1230 
1231 //*************************************************************************************************
1239 template< typename Type // Data type of the vector
1240  , bool TF > // Transpose flag
1242 {
1243  using blaze::max;
1244  using blaze::min;
1245 
1246  size_t nonzeros( 2UL*capacity_+1UL );
1247  nonzeros = max( nonzeros, 7UL );
1248  nonzeros = min( nonzeros, size_ );
1249 
1250  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1251 
1252  return nonzeros;
1253 }
1254 //*************************************************************************************************
1255 
1256 
1257 
1258 
1259 //=================================================================================================
1260 //
1261 // LOOKUP FUNCTIONS
1262 //
1263 //=================================================================================================
1264 
1265 //*************************************************************************************************
1278 template< typename Type // Data type of the vector
1279  , bool TF > // Transpose flag
1281 {
1282  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1283 }
1284 //*************************************************************************************************
1285 
1286 
1287 //*************************************************************************************************
1300 template< typename Type // Data type of the vector
1301  , bool TF > // Transpose flag
1303 {
1304  const ConstIterator pos( lowerBound( index ) );
1305  if( pos != end_ && pos->index_ == index )
1306  return pos;
1307  else return end_;
1308 }
1309 //*************************************************************************************************
1310 
1311 
1312 //*************************************************************************************************
1324 template< typename Type // Data type of the vector
1325  , bool TF > // Transpose flag
1328 {
1329  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1330 }
1331 //*************************************************************************************************
1332 
1333 
1334 //*************************************************************************************************
1346 template< typename Type // Data type of the vector
1347  , bool TF > // Transpose flag
1350 {
1351  return std::lower_bound( begin_, end_, index, FindIndex() );
1352 }
1353 //*************************************************************************************************
1354 
1355 
1356 //*************************************************************************************************
1368 template< typename Type // Data type of the vector
1369  , bool TF > // Transpose flag
1372 {
1373  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1374 }
1375 //*************************************************************************************************
1376 
1377 
1378 //*************************************************************************************************
1390 template< typename Type // Data type of the vector
1391  , bool TF > // Transpose flag
1394 {
1395  return std::upper_bound( begin_, end_, index, FindIndex() );
1396 }
1397 //*************************************************************************************************
1398 
1399 
1400 
1401 
1402 //=================================================================================================
1403 //
1404 // LOW-LEVEL UTILITY FUNCTIONS
1405 //
1406 //=================================================================================================
1407 
1408 //*************************************************************************************************
1432 template< typename Type // Data type of the vector
1433  , bool TF > // Transpose flag
1434 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1435 {
1436  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1437  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved space" );
1438  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1439 
1440  end_->value_ = value;
1441 
1442  if( !check || !isDefault( end_->value_ ) ) {
1443  end_->index_ = index;
1444  ++end_;
1445  }
1446 }
1447 //*************************************************************************************************
1448 
1449 
1450 
1451 
1452 //=================================================================================================
1453 //
1454 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1455 //
1456 //=================================================================================================
1457 
1458 //*************************************************************************************************
1468 template< typename Type // Data type of the vector
1469  , bool TF > // Transpose flag
1470 template< typename Other > // Data type of the foreign expression
1471 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const
1472 {
1473  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1474 }
1475 //*************************************************************************************************
1476 
1477 
1478 //*************************************************************************************************
1488 template< typename Type // Data type of the vector
1489  , bool TF > // Transpose flag
1490 template< typename Other > // Data type of the foreign expression
1491 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const
1492 {
1493  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1494 }
1495 //*************************************************************************************************
1496 
1497 
1498 //*************************************************************************************************
1508 template< typename Type // Data type of the vector
1509  , bool TF > // Transpose flag
1511 {
1512  return false;
1513 }
1514 //*************************************************************************************************
1515 
1516 
1517 //*************************************************************************************************
1528 template< typename Type // Data type of the vector
1529  , bool TF > // Transpose flag
1530 template< typename VT > // Type of the right-hand side dense vector
1532 {
1533  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1534  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1535 
1536  size_t nonzeros( 0UL );
1537 
1538  for( size_t i=0UL; i<size_; ++i )
1539  {
1540  if( nonzeros == capacity_ )
1541  reserve( extendCapacity() );
1542 
1543  end_->value_ = (~rhs)[i];
1544 
1545  if( !isDefault( end_->value_ ) ) {
1546  end_->index_ = i;
1547  ++end_;
1548  ++nonzeros;
1549  }
1550  }
1551 }
1552 //*************************************************************************************************
1553 
1554 
1555 //*************************************************************************************************
1566 template< typename Type // Data type of the vector
1567  , bool TF > // Transpose flag
1568 template< typename VT > // Type of the right-hand side sparse vector
1570 {
1571  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1572  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1573 
1574  // Using the following formulation instead of a std::copy function call of the form
1575  //
1576  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
1577  //
1578  // results in much less requirements on the ConstIterator type provided from the right-hand
1579  // sparse vector type
1580  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1581  append( element->index(), element->value() );
1582 }
1583 //*************************************************************************************************
1584 
1585 
1586 //*************************************************************************************************
1597 template< typename Type // Data type of the vector
1598  , bool TF > // Transpose flag
1599 template< typename VT > // Type of the right-hand side dense vector
1601 {
1602  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1603 
1607 
1608  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1609 
1610  const AddType tmp( serial( *this + (~rhs) ) );
1611  reset();
1612  assign( tmp );
1613 }
1614 //*************************************************************************************************
1615 
1616 
1617 //*************************************************************************************************
1628 template< typename Type // Data type of the vector
1629  , bool TF > // Transpose flag
1630 template< typename VT > // Type of the right-hand side sparse vector
1632 {
1633  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1634 
1635  CompressedVector<Type,TF> tmp( serial( *this + (~rhs) ) );
1636  swap( tmp );
1637 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1652 template< typename Type // Data type of the vector
1653  , bool TF > // Transpose flag
1654 template< typename VT > // Type of the right-hand side dense vector
1656 {
1657  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1658 
1662 
1663  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1664 
1665  const SubType tmp( serial( *this - (~rhs) ) );
1666  reset();
1667  assign( tmp );
1668 }
1669 //*************************************************************************************************
1670 
1671 
1672 //*************************************************************************************************
1683 template< typename Type // Data type of the vector
1684  , bool TF > // Transpose flag
1685 template< typename VT > // Type of the right-hand side sparse vector
1687 {
1688  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1689 
1690  CompressedVector<Type,TF> tmp( serial( *this - (~rhs) ) );
1691  swap( tmp );
1692 }
1693 //*************************************************************************************************
1694 
1695 
1696 
1697 
1698 //=================================================================================================
1699 //
1700 // COMPRESSEDVECTOR OPERATORS
1701 //
1702 //=================================================================================================
1703 
1704 //*************************************************************************************************
1707 template< typename Type, bool TF >
1708 inline void reset( CompressedVector<Type,TF>& v );
1709 
1710 template< typename Type, bool TF >
1711 inline void clear( CompressedVector<Type,TF>& v );
1712 
1713 template< typename Type, bool TF >
1714 inline bool isDefault( const CompressedVector<Type,TF>& v );
1715 
1716 template< typename Type, bool TF >
1717 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */;
1719 //*************************************************************************************************
1720 
1721 
1722 //*************************************************************************************************
1729 template< typename Type // Data type of the vector
1730  , bool TF > // Transpose flag
1732 {
1733  v.reset();
1734 }
1735 //*************************************************************************************************
1736 
1737 
1738 //*************************************************************************************************
1745 template< typename Type // Data type of the vector
1746  , bool TF > // Transpose flag
1748 {
1749  v.clear();
1750 }
1751 //*************************************************************************************************
1752 
1753 
1754 //*************************************************************************************************
1773 template< typename Type // Data type of the vector
1774  , bool TF > // Transpose flag
1775 inline bool isDefault( const CompressedVector<Type,TF>& v )
1776 {
1778 
1779  for( ConstIterator element=v.begin(); element!=v.end(); ++element )
1780  if( !isDefault( element->value() ) ) return false;
1781  return true;
1782 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1795 template< typename Type // Data type of the vector
1796  , bool TF > // Transpose flag
1797 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */
1798 {
1799  a.swap( b );
1800 }
1801 //*************************************************************************************************
1802 
1803 
1804 
1805 
1806 //=================================================================================================
1807 //
1808 // ISRESIZABLE SPECIALIZATIONS
1809 //
1810 //=================================================================================================
1811 
1812 //*************************************************************************************************
1814 template< typename T, bool TF >
1815 struct IsResizable< CompressedVector<T,TF> > : public TrueType
1816 {
1817  enum { value = 1 };
1818  typedef TrueType Type;
1819 };
1820 
1821 template< typename T, bool TF >
1822 struct IsResizable< const CompressedVector<T,TF> > : public TrueType
1823 {
1824  enum { value = 1 };
1825  typedef TrueType Type;
1826 };
1827 
1828 template< typename T, bool TF >
1829 struct IsResizable< volatile CompressedVector<T,TF> > : public TrueType
1830 {
1831  enum { value = 1 };
1832  typedef TrueType Type;
1833 };
1834 
1835 template< typename T, bool TF >
1836 struct IsResizable< const volatile CompressedVector<T,TF> > : public TrueType
1837 {
1838  enum { value = 1 };
1839  typedef TrueType Type;
1840 };
1842 //*************************************************************************************************
1843 
1844 
1845 
1846 
1847 //=================================================================================================
1848 //
1849 // ADDTRAIT SPECIALIZATIONS
1850 //
1851 //=================================================================================================
1852 
1853 //*************************************************************************************************
1855 template< typename T1, bool TF, typename T2, size_t N >
1856 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1857 {
1858  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1859 };
1860 
1861 template< typename T1, size_t N, bool TF, typename T2 >
1862 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1863 {
1864  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1865 };
1866 
1867 template< typename T1, bool TF, typename T2, size_t N >
1868 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1869 {
1870  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1871 };
1872 
1873 template< typename T1, size_t N, bool TF, typename T2 >
1874 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1875 {
1876  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1877 };
1878 
1879 template< typename T1, bool TF, typename T2 >
1880 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1881 {
1882  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1883 };
1884 
1885 template< typename T1, bool TF, typename T2 >
1886 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1887 {
1888  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1889 };
1890 
1891 template< typename T1, bool TF, typename T2 >
1892 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1893 {
1894  typedef CompressedVector< typename AddTrait<T1,T2>::Type, TF > Type;
1895 };
1897 //*************************************************************************************************
1898 
1899 
1900 
1901 
1902 //=================================================================================================
1903 //
1904 // SUBTRAIT SPECIALIZATIONS
1905 //
1906 //=================================================================================================
1907 
1908 //*************************************************************************************************
1910 template< typename T1, bool TF, typename T2, size_t N >
1911 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1912 {
1913  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1914 };
1915 
1916 template< typename T1, size_t N, bool TF, typename T2 >
1917 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1918 {
1919  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1920 };
1921 
1922 template< typename T1, bool TF, typename T2, size_t N >
1923 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1924 {
1925  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1926 };
1927 
1928 template< typename T1, size_t N, bool TF, typename T2 >
1929 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1930 {
1931  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1932 };
1933 
1934 template< typename T1, bool TF, typename T2 >
1935 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1936 {
1937  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1938 };
1939 
1940 template< typename T1, bool TF, typename T2 >
1941 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1942 {
1943  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1944 };
1945 
1946 template< typename T1, bool TF, typename T2 >
1947 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1948 {
1949  typedef CompressedVector< typename SubTrait<T1,T2>::Type, TF > Type;
1950 };
1952 //*************************************************************************************************
1953 
1954 
1955 
1956 
1957 //=================================================================================================
1958 //
1959 // MULTTRAIT SPECIALIZATIONS
1960 //
1961 //=================================================================================================
1962 
1963 //*************************************************************************************************
1965 template< typename T1, bool TF, typename T2 >
1966 struct MultTrait< CompressedVector<T1,TF>, T2 >
1967 {
1968  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1970 };
1971 
1972 template< typename T1, typename T2, bool TF >
1973 struct MultTrait< T1, CompressedVector<T2,TF> >
1974 {
1975  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1977 };
1978 
1979 template< typename T1, bool TF, typename T2, size_t N >
1980 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1981 {
1982  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1983 };
1984 
1985 template< typename T1, typename T2, size_t N >
1986 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
1987 {
1988  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
1989 };
1990 
1991 template< typename T1, typename T2, size_t N >
1992 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
1993 {
1994  typedef typename MultTrait<T1,T2>::Type Type;
1995 };
1996 
1997 template< typename T1, size_t N, bool TF, typename T2 >
1998 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1999 {
2000  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2001 };
2002 
2003 template< typename T1, size_t N, typename T2 >
2004 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2005 {
2006  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2007 };
2008 
2009 template< typename T1, size_t N, typename T2 >
2010 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2011 {
2012  typedef typename MultTrait<T1,T2>::Type Type;
2013 };
2014 
2015 template< typename T1, bool TF, typename T2, size_t N >
2016 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2017 {
2018  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2019 };
2020 
2021 template< typename T1, typename T2, size_t N >
2022 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2023 {
2024  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2025 };
2026 
2027 template< typename T1, typename T2, size_t N >
2028 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2029 {
2030  typedef typename MultTrait<T1,T2>::Type Type;
2031 };
2032 
2033 template< typename T1, size_t N, bool TF, typename T2 >
2034 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2035 {
2036  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2037 };
2038 
2039 template< typename T1, size_t N, typename T2 >
2040 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2041 {
2042  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2043 };
2044 
2045 template< typename T1, size_t N, typename T2 >
2046 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2047 {
2048  typedef typename MultTrait<T1,T2>::Type Type;
2049 };
2050 
2051 template< typename T1, bool TF, typename T2 >
2052 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2053 {
2054  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2055 };
2056 
2057 template< typename T1, typename T2 >
2058 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2059 {
2060  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2061 };
2062 
2063 template< typename T1, typename T2 >
2064 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2065 {
2066  typedef typename MultTrait<T1,T2>::Type Type;
2067 };
2068 
2069 template< typename T1, bool TF, typename T2 >
2070 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2071 {
2072  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2073 };
2074 
2075 template< typename T1, typename T2 >
2076 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2077 {
2078  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2079 };
2080 
2081 template< typename T1, typename T2 >
2082 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2083 {
2084  typedef typename MultTrait<T1,T2>::Type Type;
2085 };
2086 
2087 template< typename T1, bool TF, typename T2 >
2088 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2089 {
2090  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2091 };
2092 
2093 template< typename T1, typename T2 >
2094 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2095 {
2096  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2097 };
2098 
2099 template< typename T1, typename T2 >
2100 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2101 {
2102  typedef typename MultTrait<T1,T2>::Type Type;
2103 };
2105 //*************************************************************************************************
2106 
2107 
2108 
2109 
2110 //=================================================================================================
2111 //
2112 // CROSSTRAIT SPECIALIZATIONS
2113 //
2114 //=================================================================================================
2115 
2116 //*************************************************************************************************
2118 template< typename T1, typename T2 >
2119 struct CrossTrait< CompressedVector<T1,false>, StaticVector<T2,3UL,false> >
2120 {
2121  private:
2122  typedef typename MultTrait<T1,T2>::Type T;
2123 
2124  public:
2125  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2126 };
2127 
2128 template< typename T1, typename T2 >
2129 struct CrossTrait< StaticVector<T1,3UL,false>, CompressedVector<T2,false> >
2130 {
2131  private:
2132  typedef typename MultTrait<T1,T2>::Type T;
2133 
2134  public:
2135  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2136 };
2137 
2138 template< typename T1, typename T2, size_t N >
2139 struct CrossTrait< CompressedVector<T1,false>, HybridVector<T2,N,false> >
2140 {
2141  private:
2142  typedef typename MultTrait<T1,T2>::Type T;
2143 
2144  public:
2145  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2146 };
2147 
2148 template< typename T1, size_t N, typename T2 >
2149 struct CrossTrait< HybridVector<T1,N,false>, CompressedVector<T2,false> >
2150 {
2151  private:
2152  typedef typename MultTrait<T1,T2>::Type T;
2153 
2154  public:
2155  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2156 };
2157 
2158 template< typename T1, typename T2 >
2159 struct CrossTrait< CompressedVector<T1,false>, DynamicVector<T2,false> >
2160 {
2161  private:
2162  typedef typename MultTrait<T1,T2>::Type T;
2163 
2164  public:
2165  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2166 };
2167 
2168 template< typename T1, typename T2 >
2169 struct CrossTrait< DynamicVector<T1,false>, CompressedVector<T2,false> >
2170 {
2171  private:
2172  typedef typename MultTrait<T1,T2>::Type T;
2173 
2174  public:
2175  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2176 };
2177 
2178 template< typename T1, typename T2 >
2179 struct CrossTrait< CompressedVector<T1,false>, CompressedVector<T2,false> >
2180 {
2181  private:
2182  typedef typename MultTrait<T1,T2>::Type T;
2183 
2184  public:
2185  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2186 };
2188 //*************************************************************************************************
2189 
2190 
2191 
2192 
2193 //=================================================================================================
2194 //
2195 // DIVTRAIT SPECIALIZATIONS
2196 //
2197 //=================================================================================================
2198 
2199 //*************************************************************************************************
2201 template< typename T1, bool TF, typename T2 >
2202 struct DivTrait< CompressedVector<T1,TF>, T2 >
2203 {
2204  typedef CompressedVector< typename DivTrait<T1,T2>::Type, TF > Type;
2206 };
2208 //*************************************************************************************************
2209 
2210 
2211 
2212 
2213 //=================================================================================================
2214 //
2215 // MATHTRAIT SPECIALIZATIONS
2216 //
2217 //=================================================================================================
2218 
2219 //*************************************************************************************************
2221 template< typename T1, bool TF, typename T2 >
2222 struct MathTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2223 {
2224  typedef CompressedVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2225  typedef CompressedVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2226 };
2228 //*************************************************************************************************
2229 
2230 
2231 
2232 
2233 //=================================================================================================
2234 //
2235 // SUBVECTORTRAIT SPECIALIZATIONS
2236 //
2237 //=================================================================================================
2238 
2239 //*************************************************************************************************
2241 template< typename T1, bool TF >
2242 struct SubvectorTrait< CompressedVector<T1,TF> >
2243 {
2244  typedef CompressedVector<T1,TF> Type;
2245 };
2247 //*************************************************************************************************
2248 
2249 } // namespace blaze
2250 
2251 #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
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: CompressedVector.h:1491
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
Constraint on the data type.
Header file for mathematical functions.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#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 the SparseVector base class.
size_t capacity() const
Returns the maximum capacity of the compressed vector.
Definition: CompressedVector.h:962
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:1531
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1371
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:187
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:233
const blaze::Null NULL
Global NULL pointer.This instance of the Null class replaces the NULL macro to ensure a type-safe NUL...
Definition: Null.h:300
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:89
void swap(CompressedVector &sv)
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1221
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2408
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:237
Header file for a safe C++ NULL pointer implementation.
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:238
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:1600
Iterator end()
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:644
#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:1009
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
Header file for memory allocation and deallocation functionality.
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:370
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:236
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2557
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
size_t extendCapacity() const
Calculating a new vector capacity.
Definition: CompressedVector.h:1241
Header file for the ValueIndexPair class.
void subAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: CompressedVector.h:1655
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1434
Header file for the multiplication trait.
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
CompressedVector()
The default constructor for CompressedVector.
Definition: CompressedVector.h:418
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4605
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1471
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1032
#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:672
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2559
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:372
size_t nonZeros(const Matrix< MT, SO > &m)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:224
#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.
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:271
Constraint on the data type.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:235
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:630
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.
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
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:1510
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:371
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:232
Header file for the serial shim.
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1078
Reference operator[](size_t index)
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:563
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1327
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1280
Header file for the IsNumeric type trait.
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:993
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1151
Header file for the IsSparseVector type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4671
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:301
Constraint on the data type.
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:231
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:331
const VT::ElementType max(const SparseVector< VT, TF > &sv)
Returns the largest element of the sparse vector.
Definition: SparseVector.h:408
#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:948
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2411
Header file for the VectorAccessProxy class.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:240
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:239
Constraint on the data type.
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2558
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:84
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:979
Base template for the DivTrait class.
Definition: DivTrait.h:141
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:69
Constraint on the size of two data types.
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:534
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:699
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2561
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:373
Iterator begin()
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:602
Header file for basic type definitions.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2409
Base template for the SubTrait class.
Definition: SubTrait.h:141
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:351
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:234
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:375
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:238
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:183
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1176
size_t capacity(const Matrix< MT, SO > &m)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:186