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>
64 #include <blaze/system/Precision.h>
66 #include <blaze/util/Assert.h>
73 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/mpl/If.h>
75 #include <blaze/util/Null.h>
76 #include <blaze/util/Types.h>
79 
80 
81 namespace blaze {
82 
83 //=================================================================================================
84 //
85 // CLASS DEFINITION
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
178 template< typename Type // Data type of the vector
179  , bool TF = defaultTransposeFlag > // Transpose flag
180 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
181 {
182  private:
183  //**Type definitions****************************************************************************
185  //**********************************************************************************************
186 
187  //**Private class Element***********************************************************************
191  struct Element : public ElementBase
192  {
193  // This operator is required due to a bug in all versions of the the MSVC compiler.
194  // A simple 'using ElementBase::operator=;' statement results in ambiguity problems.
195  template< typename Other >
196  inline Element& operator=( const Other& rhs )
197  {
198  ElementBase::operator=( rhs );
199  return *this;
200  }
201 
202  friend class CompressedVector;
203  };
205  //**********************************************************************************************
206 
207  //**Private class FindIndex*********************************************************************
211  struct FindIndex : public std::binary_function<Element,size_t,bool>
212  {
213  inline bool operator()( const Element& element, size_t index ) const {
214  return element.index() < index;
215  }
216  inline bool operator()( size_t index, const Element& element ) const {
217  return index < element.index();
218  }
219  inline bool operator()( const Element& element1, const Element& element2 ) const {
220  return element1.index() < element2.index();
221  }
222  };
224  //**********************************************************************************************
225 
226  public:
227  //**Type definitions****************************************************************************
229  typedef This ResultType;
231  typedef Type ElementType;
232  typedef const Type& ReturnType;
235  typedef const Type& ConstReference;
236  typedef Element* Iterator;
237  typedef const Element* ConstIterator;
238  //**********************************************************************************************
239 
240  //**Constructors********************************************************************************
243  explicit inline CompressedVector();
244  explicit inline CompressedVector( size_t size );
245  explicit inline CompressedVector( size_t size, size_t nonzeros );
246  inline CompressedVector( const CompressedVector& sv );
247  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
248  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
250  //**********************************************************************************************
251 
252  //**Destructor**********************************************************************************
255  inline ~CompressedVector();
257  //**********************************************************************************************
258 
259  //**Data access functions***********************************************************************
262  inline Reference operator[]( size_t index );
263  inline ConstReference operator[]( size_t index ) const;
264  inline Iterator begin ();
265  inline ConstIterator begin () const;
266  inline ConstIterator cbegin() const;
267  inline Iterator end ();
268  inline ConstIterator end () const;
269  inline ConstIterator cend () const;
271  //**********************************************************************************************
272 
273  //**Assignment operators************************************************************************
276  inline CompressedVector& operator= ( const CompressedVector& rhs );
277  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
278  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
279  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
280  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
281  template< typename VT > inline CompressedVector& operator*=( const Vector<VT,TF>& rhs );
282 
283  template< typename Other >
284  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
285  operator*=( Other rhs );
286 
287  template< typename Other >
288  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
289  operator/=( Other rhs );
291  //**********************************************************************************************
292 
293  //**Utility functions***************************************************************************
296  inline size_t size() const;
297  inline size_t capacity() const;
298  inline size_t nonZeros() const;
299  inline void reset();
300  inline void clear();
301  Iterator insert( size_t index, const Type& value );
302  inline void erase ( size_t index );
303  inline Iterator erase ( Iterator pos );
304  inline Iterator erase ( Iterator first, Iterator last );
305  inline void resize( size_t n, bool preserve=true );
306  void reserve( size_t n );
307  template< typename Other > inline CompressedVector& scale( Other scalar );
308  inline void swap( CompressedVector& sv ) /* throw() */;
310  //**********************************************************************************************
311 
312  //**Lookup functions****************************************************************************
315  inline Iterator find ( size_t index );
316  inline ConstIterator find ( size_t index ) const;
317  inline Iterator lowerBound( size_t index );
318  inline ConstIterator lowerBound( size_t index ) const;
319  inline Iterator upperBound( size_t index );
320  inline ConstIterator upperBound( size_t index ) const;
322  //**********************************************************************************************
323 
324  //**Low-level utility functions*****************************************************************
327  inline void append( size_t index, const Type& value, bool check=false );
329  //**********************************************************************************************
330 
331  //**Expression template evaluation functions****************************************************
334  template< typename Other > inline bool canAlias ( const Other* alias ) const;
335  template< typename Other > inline bool isAliased( const Other* alias ) const;
336  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
337  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
338  template< typename VT > inline void addAssign( const DenseVector <VT,TF>& rhs );
339  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
340  template< typename VT > inline void subAssign( const DenseVector <VT,TF>& rhs );
341  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
343  //**********************************************************************************************
344 
345  private:
346  //**Utility functions***************************************************************************
349  inline size_t extendCapacity() const;
351  //**********************************************************************************************
352 
353  //**Member variables****************************************************************************
356  size_t size_;
357  size_t capacity_;
360 
361  static const Type zero_;
362 
363  //**********************************************************************************************
364 
365  //**Compile time checks*************************************************************************
373  //**********************************************************************************************
374 };
375 //*************************************************************************************************
376 
377 
378 
379 
380 //=================================================================================================
381 //
382 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
383 //
384 //=================================================================================================
385 
386 template< typename Type // Data type of the vector
387  , bool TF > // Transpose flag
388 const Type CompressedVector<Type,TF>::zero_ = Type();
389 
390 
391 
392 
393 //=================================================================================================
394 //
395 // CONSTRUCTORS
396 //
397 //=================================================================================================
398 
399 //*************************************************************************************************
402 template< typename Type // Data type of the vector
403  , bool TF > // Transpose flag
405  : size_ ( 0UL ) // The current size/dimension of the compressed vector
406  , capacity_( 0UL ) // The maximum capacity of the compressed vector
407  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
408  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
409 {}
410 //*************************************************************************************************
411 
412 
413 //*************************************************************************************************
418 template< typename Type // Data type of the vector
419  , bool TF > // Transpose flag
421  : size_ ( n ) // The current size/dimension of the compressed vector
422  , capacity_( 0UL ) // The maximum capacity of the compressed vector
423  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
424  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
425 {}
426 //*************************************************************************************************
427 
428 
429 //*************************************************************************************************
435 template< typename Type // Data type of the vector
436  , bool TF > // Transpose flag
437 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
438  : size_ ( n ) // The current size/dimension of the compressed vector
439  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
440  , begin_ ( new Element[capacity_] ) // Pointer to the first non-zero element of the compressed vector
441  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
442 {}
443 //*************************************************************************************************
444 
445 
446 //*************************************************************************************************
454 template< typename Type // Data type of the vector
455  , bool TF > // Transpose flag
457  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
458  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
459  , begin_ ( new Element[capacity_] ) // Pointer to the first non-zero element of the compressed vector
460  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
461 {
462  std::copy( sv.begin_, sv.end_, begin_ );
463 }
464 //*************************************************************************************************
465 
466 
467 //*************************************************************************************************
472 template< typename Type // Data type of the vector
473  , bool TF > // Transpose flag
474 template< typename VT > // Type of the foreign dense vector
476  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
477  , capacity_( 0UL ) // The maximum capacity of the compressed vector
478  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
479  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
480 {
481  using blaze::assign;
482  assign( *this, ~dv );
483 }
484 //*************************************************************************************************
485 
486 
487 //*************************************************************************************************
492 template< typename Type // Data type of the vector
493  , bool TF > // Transpose flag
494 template< typename VT > // Type of the foreign sparse vector
496  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
497  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
498  , begin_ ( new Element[capacity_] ) // Pointer to the first non-zero element of the compressed vector
499  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
500 {
501  using blaze::assign;
502  assign( *this, ~sv );
503 }
504 //*************************************************************************************************
505 
506 
507 
508 
509 //=================================================================================================
510 //
511 // DESTRUCTOR
512 //
513 //=================================================================================================
514 
515 //*************************************************************************************************
518 template< typename Type // Data type of the vector
519  , bool TF > // Transpose flag
521 {
522  delete [] begin_;
523 }
524 //*************************************************************************************************
525 
526 
527 
528 
529 //=================================================================================================
530 //
531 // DATA ACCESS FUNCTIONS
532 //
533 //=================================================================================================
534 
535 //*************************************************************************************************
546 template< typename Type // Data type of the vector
547  , bool TF > // Transpose flag
550 {
551  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
552 
553  return Reference( *this, index );
554 }
555 //*************************************************************************************************
556 
557 
558 //*************************************************************************************************
564 template< typename Type // Data type of the vector
565  , bool TF > // Transpose flag
568 {
569  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
570 
571  const ConstIterator pos( lowerBound( index ) );
572 
573  if( pos == end_ || pos->index_ != index )
574  return zero_;
575  else
576  return pos->value_;
577 }
578 //*************************************************************************************************
579 
580 
581 //*************************************************************************************************
586 template< typename Type // Data type of the vector
587  , bool TF > // Transpose flag
589 {
590  return Iterator( begin_ );
591 }
592 //*************************************************************************************************
593 
594 
595 //*************************************************************************************************
600 template< typename Type // Data type of the vector
601  , bool TF > // Transpose flag
603 {
604  return ConstIterator( 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 Iterator( end_ );
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
642 template< typename Type // Data type of the vector
643  , bool TF > // Transpose flag
645 {
646  return ConstIterator( 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 
666 
667 //=================================================================================================
668 //
669 // ASSIGNMENT OPERATORS
670 //
671 //=================================================================================================
672 
673 //*************************************************************************************************
682 template< typename Type // Data type of the vector
683  , bool TF > // Transpose flag
686 {
687  if( &rhs == this ) return *this;
688 
689  const size_t nonzeros( rhs.nonZeros() );
690 
691  if( nonzeros > capacity_ ) {
692  Iterator newBegin( new Element[nonzeros] );
693  end_ = std::copy( rhs.begin_, rhs.end_, newBegin );
694  std::swap( begin_, newBegin );
695  delete [] newBegin;
696 
697  size_ = rhs.size_;
698  capacity_ = nonzeros;
699  }
700  else {
701  end_ = std::copy( rhs.begin_, rhs.end_, begin_ );
702  size_ = rhs.size_;
703  }
704 
705  return *this;
706 }
707 //*************************************************************************************************
708 
709 
710 //*************************************************************************************************
719 template< typename Type // Data type of the vector
720  , bool TF > // Transpose flag
721 template< typename VT > // Type of the right-hand side dense vector
724 {
725  using blaze::assign;
726 
727  if( (~rhs).canAlias( this ) ) {
728  CompressedVector tmp( rhs );
729  swap( tmp );
730  }
731  else {
732  size_ = (~rhs).size();
733  end_ = begin_;
734  assign( *this, ~rhs );
735  }
736 
737  return *this;
738 }
739 //*************************************************************************************************
740 
741 
742 //*************************************************************************************************
751 template< typename Type // Data type of the vector
752  , bool TF > // Transpose flag
753 template< typename VT > // Type of the right-hand side sparse vector
756 {
757  using blaze::assign;
758 
759  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
760  CompressedVector tmp( rhs );
761  swap( tmp );
762  }
763  else {
764  size_ = (~rhs).size();
765  end_ = begin_;
766  assign( *this, ~rhs );
767  }
768 
769  return *this;
770 }
771 //*************************************************************************************************
772 
773 
774 //*************************************************************************************************
784 template< typename Type // Data type of the vector
785  , bool TF > // Transpose flag
786 template< typename VT > // Type of the right-hand side vector
788 {
789  using blaze::addAssign;
790 
791  if( (~rhs).size() != size_ )
792  throw std::invalid_argument( "Vector sizes do not match" );
793 
794  addAssign( *this, ~rhs );
795 
796  return *this;
797 }
798 //*************************************************************************************************
799 
800 
801 //*************************************************************************************************
811 template< typename Type // Data type of the vector
812  , bool TF > // Transpose flag
813 template< typename VT > // Type of the right-hand side vector
815 {
816  using blaze::subAssign;
817 
818  if( (~rhs).size() != size_ )
819  throw std::invalid_argument( "Vector sizes do not match" );
820 
821  subAssign( *this, ~rhs );
822 
823  return *this;
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
839 template< typename Type // Data type of the vector
840  , bool TF > // Transpose flag
841 template< typename VT > // Type of the right-hand side vector
843 {
844  if( (~rhs).size() != size_ )
845  throw std::invalid_argument( "Vector sizes do not match" );
846 
847  CompressedVector<Type,TF> tmp( *this * (~rhs) );
848  swap( tmp );
849 
850  return *this;
851 }
852 //*************************************************************************************************
853 
854 
855 //*************************************************************************************************
866 template< typename Type // Data type of the vector
867  , bool TF > // Transpose flag
868 template< typename Other > // Data type of the right-hand side scalar
871 {
872  for( Iterator element=begin_; element!=end_; ++element )
873  element->value_ *= rhs;
874  return *this;
875 }
876 //*************************************************************************************************
877 
878 
879 //*************************************************************************************************
891 template< typename Type // Data type of the vector
892  , bool TF > // Transpose flag
893 template< typename Other > // Data type of the right-hand side scalar
896 {
897  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
898 
899  typedef typename DivTrait<Type,Other>::Type DT;
900  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
901 
902  // Depending on the two involved data types, an integer division is applied or a
903  // floating point division is selected.
905  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
906  for( Iterator element=begin_; element!=end_; ++element )
907  element->value_ *= tmp;
908  }
909  else {
910  for( Iterator element=begin_; element!=end_; ++element )
911  element->value_ /= rhs;
912  }
913 
914  return *this;
915 }
916 //*************************************************************************************************
917 
918 
919 
920 
921 //=================================================================================================
922 //
923 // UTILITY FUNCTIONS
924 //
925 //=================================================================================================
926 
927 //*************************************************************************************************
932 template< typename Type // Data type of the vector
933  , bool TF > // Transpose flag
934 inline size_t CompressedVector<Type,TF>::size() const
935 {
936  return size_;
937 }
938 //*************************************************************************************************
939 
940 
941 //*************************************************************************************************
946 template< typename Type // Data type of the vector
947  , bool TF > // Transpose flag
949 {
950  return capacity_;
951 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
963 template< typename Type // Data type of the vector
964  , bool TF > // Transpose flag
966 {
967  return end_ - begin_;
968 }
969 //*************************************************************************************************
970 
971 
972 //*************************************************************************************************
977 template< typename Type // Data type of the vector
978  , bool TF > // Transpose flag
980 {
981  end_ = begin_;
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
993 template< typename Type // Data type of the vector
994  , bool TF > // Transpose flag
996 {
997  size_ = 0UL;
998  end_ = begin_;
999 }
1000 //*************************************************************************************************
1001 
1002 
1003 //*************************************************************************************************
1015 template< typename Type // Data type of the vector
1016  , bool TF > // Transpose flag
1018  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1019 {
1020  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1021 
1022  const Iterator pos( lowerBound( index ) );
1023 
1024  if( pos != end_ && pos->index_ == index )
1025  throw std::invalid_argument( "Bad access index" );
1026 
1027  if( nonZeros() != capacity_ ) {
1028  std::copy_backward( pos, end_, end_+1 );
1029  pos->value_ = value;
1030  pos->index_ = index;
1031  ++end_;
1032 
1033  return pos;
1034  }
1035  else {
1036  size_t newCapacity( extendCapacity() );
1037 
1038  Iterator newBegin = new Element[newCapacity];
1039  Iterator tmp = std::copy( begin_, pos, newBegin );
1040  tmp->value_ = value;
1041  tmp->index_ = index;
1042  end_ = std::copy( pos, end_, tmp+1 );
1043 
1044  std::swap( newBegin, begin_ );
1045  delete [] newBegin;
1046  capacity_ = newCapacity;
1047 
1048  return tmp;
1049  }
1050 }
1051 //*************************************************************************************************
1052 
1053 
1054 //*************************************************************************************************
1062 template< typename Type // Data type of the vector
1063  , bool TF > // Transpose flag
1064 inline void CompressedVector<Type,TF>::erase( size_t index )
1065 {
1066  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1067 
1068  const Iterator pos( find( index ) );
1069  if( pos != end_ )
1070  end_ = std::copy( pos+1, end_, pos );
1071 }
1072 //*************************************************************************************************
1073 
1074 
1075 //*************************************************************************************************
1083 template< typename Type // Data type of the vector
1084  , bool TF > // Transpose flag
1086 {
1087  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1088 
1089  if( pos != end_ )
1090  end_ = std::copy( pos+1, end_, pos );
1091  return pos;
1092 }
1093 //*************************************************************************************************
1094 
1095 
1096 //*************************************************************************************************
1105 template< typename Type // Data type of the vector
1106  , bool TF > // Transpose flag
1109 {
1110  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1111  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1112  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1113 
1114  if( first != last )
1115  end_ = std::copy( last, end_, first );
1116  return first;
1117 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1133 template< typename Type // Data type of the vector
1134  , bool TF > // Transpose flag
1135 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1136 {
1137  if( preserve ) {
1138  end_ = lowerBound( n );
1139  }
1140  else {
1141  end_ = begin_;
1142  }
1143 
1144  size_ = n;
1145 }
1146 //*************************************************************************************************
1147 
1148 
1149 //*************************************************************************************************
1158 template< typename Type // Data type of the vector
1159  , bool TF > // Transpose flag
1161 {
1162  if( n > capacity_ ) {
1163  const size_t newCapacity( n );
1164 
1165  // Allocating a new data and index array
1166  Iterator newBegin = new Element[newCapacity];
1167 
1168  // Replacing the old data and index array
1169  end_ = std::copy( begin_, end_, newBegin );
1170  std::swap( newBegin, begin_ );
1171  capacity_ = newCapacity;
1172  delete [] newBegin;
1173  }
1174 }
1175 //*************************************************************************************************
1176 
1177 
1178 //*************************************************************************************************
1184 template< typename Type // Data type of the vector
1185  , bool TF > // Transpose flag
1186 template< typename Other > // Data type of the scalar value
1188 {
1189  for( Iterator element=begin_; element!=end_; ++element )
1190  element->value_ *= scalar;
1191  return *this;
1192 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1203 template< typename Type // Data type of the vector
1204  , bool TF > // Transpose flag
1205 inline void CompressedVector<Type,TF>::swap( CompressedVector& sv ) /* throw() */
1206 {
1207  std::swap( size_, sv.size_ );
1208  std::swap( capacity_, sv.capacity_ );
1209  std::swap( begin_, sv.begin_ );
1210  std::swap( end_, sv.end_ );
1211 }
1212 //*************************************************************************************************
1213 
1214 
1215 //*************************************************************************************************
1223 template< typename Type // Data type of the vector
1224  , bool TF > // Transpose flag
1226 {
1227  using blaze::max;
1228  using blaze::min;
1229 
1230  size_t nonzeros( 2UL*capacity_+1UL );
1231  nonzeros = max( nonzeros, 7UL );
1232  nonzeros = min( nonzeros, size_ );
1233 
1234  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1235 
1236  return nonzeros;
1237 }
1238 //*************************************************************************************************
1239 
1240 
1241 
1242 
1243 //=================================================================================================
1244 //
1245 // LOOKUP FUNCTIONS
1246 //
1247 //=================================================================================================
1248 
1249 //*************************************************************************************************
1262 template< typename Type // Data type of the vector
1263  , bool TF > // Transpose flag
1265 {
1266  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1267 }
1268 //*************************************************************************************************
1269 
1270 
1271 //*************************************************************************************************
1284 template< typename Type // Data type of the vector
1285  , bool TF > // Transpose flag
1287 {
1288  const ConstIterator pos( lowerBound( index ) );
1289  if( pos != end_ && pos->index_ == index )
1290  return pos;
1291  else return end_;
1292 }
1293 //*************************************************************************************************
1294 
1295 
1296 //*************************************************************************************************
1308 template< typename Type // Data type of the vector
1309  , bool TF > // Transpose flag
1312 {
1313  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1314 }
1315 //*************************************************************************************************
1316 
1317 
1318 //*************************************************************************************************
1330 template< typename Type // Data type of the vector
1331  , bool TF > // Transpose flag
1334 {
1335  return std::lower_bound( begin_, end_, index, FindIndex() );
1336 }
1337 //*************************************************************************************************
1338 
1339 
1340 //*************************************************************************************************
1352 template< typename Type // Data type of the vector
1353  , bool TF > // Transpose flag
1356 {
1357  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1358 }
1359 //*************************************************************************************************
1360 
1361 
1362 //*************************************************************************************************
1374 template< typename Type // Data type of the vector
1375  , bool TF > // Transpose flag
1378 {
1379  return std::upper_bound( begin_, end_, index, FindIndex() );
1380 }
1381 //*************************************************************************************************
1382 
1383 
1384 
1385 
1386 //=================================================================================================
1387 //
1388 // LOW-LEVEL UTILITY FUNCTIONS
1389 //
1390 //=================================================================================================
1391 
1392 //*************************************************************************************************
1416 template< typename Type // Data type of the vector
1417  , bool TF > // Transpose flag
1418 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1419 {
1420  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1421  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved space" );
1422  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1423 
1424  end_->value_ = value;
1425 
1426  if( !check || !isDefault( end_->value_ ) ) {
1427  end_->index_ = index;
1428  ++end_;
1429  }
1430 }
1431 //*************************************************************************************************
1432 
1433 
1434 
1435 
1436 //=================================================================================================
1437 //
1438 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1439 //
1440 //=================================================================================================
1441 
1442 //*************************************************************************************************
1452 template< typename Type // Data type of the vector
1453  , bool TF > // Transpose flag
1454 template< typename Other > // Data type of the foreign expression
1455 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const
1456 {
1457  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1458 }
1459 //*************************************************************************************************
1460 
1461 
1462 //*************************************************************************************************
1472 template< typename Type // Data type of the vector
1473  , bool TF > // Transpose flag
1474 template< typename Other > // Data type of the foreign expression
1475 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const
1476 {
1477  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1478 }
1479 //*************************************************************************************************
1480 
1481 
1482 //*************************************************************************************************
1493 template< typename Type // Data type of the vector
1494  , bool TF > // Transpose flag
1495 template< typename VT > // Type of the right-hand side dense vector
1497 {
1498  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1499  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1500 
1501  size_t nonzeros( 0UL );
1502 
1503  for( size_t i=0UL; i<size_; ++i )
1504  {
1505  if( nonzeros == capacity_ )
1506  reserve( extendCapacity() );
1507 
1508  end_->value_ = (~rhs)[i];
1509 
1510  if( !isDefault( end_->value_ ) ) {
1511  end_->index_ = i;
1512  ++end_;
1513  ++nonzeros;
1514  }
1515  }
1516 }
1517 //*************************************************************************************************
1518 
1519 
1520 //*************************************************************************************************
1531 template< typename Type // Data type of the vector
1532  , bool TF > // Transpose flag
1533 template< typename VT > // Type of the right-hand side sparse vector
1535 {
1536  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1537  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1538 
1539  // Using the following formulation instead of a std::copy function call of the form
1540  //
1541  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
1542  //
1543  // results in much less requirements on the ConstIterator type provided from the right-hand
1544  // sparse vector type
1545  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1546  append( element->index(), element->value() );
1547 }
1548 //*************************************************************************************************
1549 
1550 
1551 //*************************************************************************************************
1562 template< typename Type // Data type of the vector
1563  , bool TF > // Transpose flag
1564 template< typename VT > // Type of the right-hand side dense vector
1566 {
1567  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1568 
1572 
1573  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1574 
1575  const AddType tmp( *this + (~rhs) );
1576  reset();
1577  assign( tmp );
1578 }
1579 //*************************************************************************************************
1580 
1581 
1582 //*************************************************************************************************
1593 template< typename Type // Data type of the vector
1594  , bool TF > // Transpose flag
1595 template< typename VT > // Type of the right-hand side sparse vector
1597 {
1598  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1599 
1600  CompressedVector<Type,TF> tmp( *this + (~rhs) );
1601  swap( tmp );
1602 }
1603 //*************************************************************************************************
1604 
1605 
1606 //*************************************************************************************************
1617 template< typename Type // Data type of the vector
1618  , bool TF > // Transpose flag
1619 template< typename VT > // Type of the right-hand side dense vector
1621 {
1622  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1623 
1627 
1628  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1629 
1630  const SubType tmp( *this - (~rhs) );
1631  reset();
1632  assign( tmp );
1633 }
1634 //*************************************************************************************************
1635 
1636 
1637 //*************************************************************************************************
1648 template< typename Type // Data type of the vector
1649  , bool TF > // Transpose flag
1650 template< typename VT > // Type of the right-hand side sparse vector
1652 {
1653  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1654 
1655  CompressedVector<Type,TF> tmp( *this - (~rhs) );
1656  swap( tmp );
1657 }
1658 //*************************************************************************************************
1659 
1660 
1661 
1662 
1663 //=================================================================================================
1664 //
1665 // COMPRESSEDVECTOR OPERATORS
1666 //
1667 //=================================================================================================
1668 
1669 //*************************************************************************************************
1672 template< typename Type, bool TF >
1673 inline void reset( CompressedVector<Type,TF>& v );
1674 
1675 template< typename Type, bool TF >
1676 inline void clear( CompressedVector<Type,TF>& v );
1677 
1678 template< typename Type, bool TF >
1679 inline bool isDefault( const CompressedVector<Type,TF>& v );
1680 
1681 template< typename Type, bool TF >
1682 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */;
1684 //*************************************************************************************************
1685 
1686 
1687 //*************************************************************************************************
1694 template< typename Type // Data type of the vector
1695  , bool TF > // Transpose flag
1697 {
1698  v.reset();
1699 }
1700 //*************************************************************************************************
1701 
1702 
1703 //*************************************************************************************************
1710 template< typename Type // Data type of the vector
1711  , bool TF > // Transpose flag
1713 {
1714  v.clear();
1715 }
1716 //*************************************************************************************************
1717 
1718 
1719 //*************************************************************************************************
1738 template< typename Type // Data type of the vector
1739  , bool TF > // Transpose flag
1740 inline bool isDefault( const CompressedVector<Type,TF>& v )
1741 {
1743 
1744  for( ConstIterator element=v.begin(); element!=v.end(); ++element )
1745  if( !isDefault( element->value() ) ) return false;
1746  return true;
1747 }
1748 //*************************************************************************************************
1749 
1750 
1751 //*************************************************************************************************
1760 template< typename Type // Data type of the vector
1761  , bool TF > // Transpose flag
1762 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */
1763 {
1764  a.swap( b );
1765 }
1766 //*************************************************************************************************
1767 
1768 
1769 
1770 
1771 //=================================================================================================
1772 //
1773 // ISRESIZABLE SPECIALIZATIONS
1774 //
1775 //=================================================================================================
1776 
1777 //*************************************************************************************************
1779 template< typename T, bool TF >
1780 struct IsResizable< CompressedVector<T,TF> > : public TrueType
1781 {
1782  enum { value = 1 };
1783  typedef TrueType Type;
1784 };
1785 
1786 template< typename T, bool TF >
1787 struct IsResizable< const CompressedVector<T,TF> > : public TrueType
1788 {
1789  enum { value = 1 };
1790  typedef TrueType Type;
1791 };
1792 
1793 template< typename T, bool TF >
1794 struct IsResizable< volatile CompressedVector<T,TF> > : public TrueType
1795 {
1796  enum { value = 1 };
1797  typedef TrueType Type;
1798 };
1799 
1800 template< typename T, bool TF >
1801 struct IsResizable< const volatile CompressedVector<T,TF> > : public TrueType
1802 {
1803  enum { value = 1 };
1804  typedef TrueType Type;
1805 };
1807 //*************************************************************************************************
1808 
1809 
1810 
1811 
1812 //=================================================================================================
1813 //
1814 // ADDTRAIT SPECIALIZATIONS
1815 //
1816 //=================================================================================================
1817 
1818 //*************************************************************************************************
1820 template< typename T1, bool TF, typename T2, size_t N >
1821 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1822 {
1823  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1824 };
1825 
1826 template< typename T1, size_t N, bool TF, typename T2 >
1827 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1828 {
1829  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1830 };
1831 
1832 template< typename T1, bool TF, typename T2, size_t N >
1833 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1834 {
1835  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1836 };
1837 
1838 template< typename T1, size_t N, bool TF, typename T2 >
1839 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1840 {
1841  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1842 };
1843 
1844 template< typename T1, bool TF, typename T2 >
1845 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1846 {
1847  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1848 };
1849 
1850 template< typename T1, bool TF, typename T2 >
1851 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1852 {
1853  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1854 };
1855 
1856 template< typename T1, bool TF, typename T2 >
1857 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1858 {
1859  typedef CompressedVector< typename AddTrait<T1,T2>::Type, TF > Type;
1860 };
1862 //*************************************************************************************************
1863 
1864 
1865 
1866 
1867 //=================================================================================================
1868 //
1869 // SUBTRAIT SPECIALIZATIONS
1870 //
1871 //=================================================================================================
1872 
1873 //*************************************************************************************************
1875 template< typename T1, bool TF, typename T2, size_t N >
1876 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1877 {
1878  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1879 };
1880 
1881 template< typename T1, size_t N, bool TF, typename T2 >
1882 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1883 {
1884  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1885 };
1886 
1887 template< typename T1, bool TF, typename T2, size_t N >
1888 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1889 {
1890  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1891 };
1892 
1893 template< typename T1, size_t N, bool TF, typename T2 >
1894 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1895 {
1896  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1897 };
1898 
1899 template< typename T1, bool TF, typename T2 >
1900 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1901 {
1902  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1903 };
1904 
1905 template< typename T1, bool TF, typename T2 >
1906 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1907 {
1908  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1909 };
1910 
1911 template< typename T1, bool TF, typename T2 >
1912 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1913 {
1914  typedef CompressedVector< typename SubTrait<T1,T2>::Type, TF > Type;
1915 };
1917 //*************************************************************************************************
1918 
1919 
1920 
1921 
1922 //=================================================================================================
1923 //
1924 // MULTTRAIT SPECIALIZATIONS
1925 //
1926 //=================================================================================================
1927 
1928 //*************************************************************************************************
1930 template< typename T1, bool TF, typename T2 >
1931 struct MultTrait< CompressedVector<T1,TF>, T2 >
1932 {
1933  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1935 };
1936 
1937 template< typename T1, typename T2, bool TF >
1938 struct MultTrait< T1, CompressedVector<T2,TF> >
1939 {
1940  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1942 };
1943 
1944 template< typename T1, bool TF, typename T2, size_t N >
1945 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1946 {
1947  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1948 };
1949 
1950 template< typename T1, typename T2, size_t N >
1951 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
1952 {
1953  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
1954 };
1955 
1956 template< typename T1, typename T2, size_t N >
1957 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
1958 {
1959  typedef typename MultTrait<T1,T2>::Type Type;
1960 };
1961 
1962 template< typename T1, size_t N, bool TF, typename T2 >
1963 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1964 {
1965  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1966 };
1967 
1968 template< typename T1, size_t N, typename T2 >
1969 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
1970 {
1971  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
1972 };
1973 
1974 template< typename T1, size_t N, typename T2 >
1975 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
1976 {
1977  typedef typename MultTrait<T1,T2>::Type Type;
1978 };
1979 
1980 template< typename T1, bool TF, typename T2, size_t N >
1981 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1982 {
1983  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1984 };
1985 
1986 template< typename T1, typename T2, size_t N >
1987 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
1988 {
1989  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
1990 };
1991 
1992 template< typename T1, typename T2, size_t N >
1993 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
1994 {
1995  typedef typename MultTrait<T1,T2>::Type Type;
1996 };
1997 
1998 template< typename T1, size_t N, bool TF, typename T2 >
1999 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2000 {
2001  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2002 };
2003 
2004 template< typename T1, size_t N, typename T2 >
2005 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2006 {
2007  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2008 };
2009 
2010 template< typename T1, size_t N, typename T2 >
2011 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2012 {
2013  typedef typename MultTrait<T1,T2>::Type Type;
2014 };
2015 
2016 template< typename T1, bool TF, typename T2 >
2017 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2018 {
2019  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2020 };
2021 
2022 template< typename T1, typename T2 >
2023 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2024 {
2025  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2026 };
2027 
2028 template< typename T1, typename T2 >
2029 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2030 {
2031  typedef typename MultTrait<T1,T2>::Type Type;
2032 };
2033 
2034 template< typename T1, bool TF, typename T2 >
2035 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2036 {
2037  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2038 };
2039 
2040 template< typename T1, typename T2 >
2041 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2042 {
2043  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2044 };
2045 
2046 template< typename T1, typename T2 >
2047 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2048 {
2049  typedef typename MultTrait<T1,T2>::Type Type;
2050 };
2051 
2052 template< typename T1, bool TF, typename T2 >
2053 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2054 {
2055  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2056 };
2057 
2058 template< typename T1, typename T2 >
2059 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2060 {
2061  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2062 };
2063 
2064 template< typename T1, typename T2 >
2065 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2066 {
2067  typedef typename MultTrait<T1,T2>::Type Type;
2068 };
2070 //*************************************************************************************************
2071 
2072 
2073 
2074 
2075 //=================================================================================================
2076 //
2077 // CROSSTRAIT SPECIALIZATIONS
2078 //
2079 //=================================================================================================
2080 
2081 //*************************************************************************************************
2083 template< typename T1, typename T2 >
2084 struct CrossTrait< CompressedVector<T1,false>, StaticVector<T2,3UL,false> >
2085 {
2086  private:
2087  typedef typename MultTrait<T1,T2>::Type T;
2088 
2089  public:
2090  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2091 };
2092 
2093 template< typename T1, typename T2 >
2094 struct CrossTrait< StaticVector<T1,3UL,false>, CompressedVector<T2,false> >
2095 {
2096  private:
2097  typedef typename MultTrait<T1,T2>::Type T;
2098 
2099  public:
2100  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2101 };
2102 
2103 template< typename T1, typename T2, size_t N >
2104 struct CrossTrait< CompressedVector<T1,false>, HybridVector<T2,N,false> >
2105 {
2106  private:
2107  typedef typename MultTrait<T1,T2>::Type T;
2108 
2109  public:
2110  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2111 };
2112 
2113 template< typename T1, size_t N, typename T2 >
2114 struct CrossTrait< HybridVector<T1,N,false>, CompressedVector<T2,false> >
2115 {
2116  private:
2117  typedef typename MultTrait<T1,T2>::Type T;
2118 
2119  public:
2120  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2121 };
2122 
2123 template< typename T1, typename T2 >
2124 struct CrossTrait< CompressedVector<T1,false>, DynamicVector<T2,false> >
2125 {
2126  private:
2127  typedef typename MultTrait<T1,T2>::Type T;
2128 
2129  public:
2130  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2131 };
2132 
2133 template< typename T1, typename T2 >
2134 struct CrossTrait< DynamicVector<T1,false>, CompressedVector<T2,false> >
2135 {
2136  private:
2137  typedef typename MultTrait<T1,T2>::Type T;
2138 
2139  public:
2140  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2141 };
2142 
2143 template< typename T1, typename T2 >
2144 struct CrossTrait< CompressedVector<T1,false>, CompressedVector<T2,false> >
2145 {
2146  private:
2147  typedef typename MultTrait<T1,T2>::Type T;
2148 
2149  public:
2150  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2151 };
2153 //*************************************************************************************************
2154 
2155 
2156 
2157 
2158 //=================================================================================================
2159 //
2160 // DIVTRAIT SPECIALIZATIONS
2161 //
2162 //=================================================================================================
2163 
2164 //*************************************************************************************************
2166 template< typename T1, bool TF, typename T2 >
2167 struct DivTrait< CompressedVector<T1,TF>, T2 >
2168 {
2169  typedef CompressedVector< typename DivTrait<T1,T2>::Type, TF > Type;
2171 };
2173 //*************************************************************************************************
2174 
2175 
2176 
2177 
2178 //=================================================================================================
2179 //
2180 // MATHTRAIT SPECIALIZATIONS
2181 //
2182 //=================================================================================================
2183 
2184 //*************************************************************************************************
2186 template< typename T1, bool TF, typename T2 >
2187 struct MathTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2188 {
2189  typedef CompressedVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2190  typedef CompressedVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2191 };
2193 //*************************************************************************************************
2194 
2195 
2196 
2197 
2198 //=================================================================================================
2199 //
2200 // SUBVECTORTRAIT SPECIALIZATIONS
2201 //
2202 //=================================================================================================
2203 
2204 //*************************************************************************************************
2206 template< typename T1, bool TF >
2207 struct SubvectorTrait< CompressedVector<T1,TF> >
2208 {
2209  typedef CompressedVector<T1,TF> Type;
2210 };
2212 //*************************************************************************************************
2213 
2214 } // namespace blaze
2215 
2216 #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:1475
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:4512
#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:948
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:1496
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1355
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4555
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:184
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:230
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:1205
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2375
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:234
Header file for a safe C++ NULL pointer implementation.
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:235
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:1565
Iterator end()
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:630
#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:995
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:356
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:233
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4528
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2513
Header file for the floating point precision of the Blaze library.
size_t extendCapacity() const
Calculating a new vector capacity.
Definition: CompressedVector.h:1225
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:1620
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1418
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:404
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4541
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1455
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1018
#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
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:658
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2515
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:358
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.In case the types T1 and T2 don&#39;t have the same size...
Definition: SameSize.h: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:179
Constraint on the data type.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:232
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:616
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
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:357
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:229
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1064
Reference operator[](size_t index)
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:549
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1311
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1264
Header file for the IsNumeric type trait.
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:979
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1135
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:4584
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:209
Constraint on the data type.
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:228
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:239
const VT::ElementType max(const SparseVector< VT, TF > &sv)
Returns the largest element of the sparse vector.
Definition: SparseVector.h:405
#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:934
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2378
Header file for the VectorAccessProxy class.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:237
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:236
Constraint on the data type.
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2514
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:965
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:520
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:685
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2517
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:359
Iterator begin()
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:588
Header file for basic type definitions.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2376
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:348
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:231
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:361
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
#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:180
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1160