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/Memory.h>
75 #include <blaze/util/mpl/If.h>
76 #include <blaze/util/Null.h>
77 #include <blaze/util/Types.h>
80 
81 
82 namespace blaze {
83 
84 //=================================================================================================
85 //
86 // CLASS DEFINITION
87 //
88 //=================================================================================================
89 
90 //*************************************************************************************************
179 template< typename Type // Data type of the vector
180  , bool TF = defaultTransposeFlag > // Transpose flag
181 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
182 {
183  private:
184  //**Type definitions****************************************************************************
186  //**********************************************************************************************
187 
188  //**Private class Element***********************************************************************
192  struct Element : public ElementBase
193  {
194  // This operator is required due to a bug in all versions of the the MSVC compiler.
195  // A simple 'using ElementBase::operator=;' statement results in ambiguity problems.
196  template< typename Other >
197  inline Element& operator=( const Other& rhs )
198  {
199  ElementBase::operator=( rhs );
200  return *this;
201  }
202 
203  friend class CompressedVector;
204  };
206  //**********************************************************************************************
207 
208  //**Private class FindIndex*********************************************************************
212  struct FindIndex : public std::binary_function<Element,size_t,bool>
213  {
214  inline bool operator()( const Element& element, size_t index ) const {
215  return element.index() < index;
216  }
217  inline bool operator()( size_t index, const Element& element ) const {
218  return index < element.index();
219  }
220  inline bool operator()( const Element& element1, const Element& element2 ) const {
221  return element1.index() < element2.index();
222  }
223  };
225  //**********************************************************************************************
226 
227  public:
228  //**Type definitions****************************************************************************
230  typedef This ResultType;
232  typedef Type ElementType;
233  typedef const Type& ReturnType;
236  typedef const Type& ConstReference;
237  typedef Element* Iterator;
238  typedef const Element* ConstIterator;
239  //**********************************************************************************************
240 
241  //**Compilation flags***************************************************************************
243 
246  enum { smpAssignable = 0 };
247  //**********************************************************************************************
248 
249  //**Constructors********************************************************************************
252  explicit inline CompressedVector();
253  explicit inline CompressedVector( size_t size );
254  explicit inline CompressedVector( size_t size, size_t nonzeros );
255  inline CompressedVector( const CompressedVector& sv );
256  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
257  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
259  //**********************************************************************************************
260 
261  //**Destructor**********************************************************************************
264  inline ~CompressedVector();
266  //**********************************************************************************************
267 
268  //**Data access functions***********************************************************************
271  inline Reference operator[]( size_t index );
272  inline ConstReference operator[]( size_t index ) const;
273  inline Iterator begin ();
274  inline ConstIterator begin () const;
275  inline ConstIterator cbegin() const;
276  inline Iterator end ();
277  inline ConstIterator end () const;
278  inline ConstIterator cend () const;
280  //**********************************************************************************************
281 
282  //**Assignment operators************************************************************************
285  inline CompressedVector& operator= ( const CompressedVector& rhs );
286  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
287  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
288  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
289  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
290  template< typename VT > inline CompressedVector& operator*=( const Vector<VT,TF>& rhs );
291 
292  template< typename Other >
293  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
294  operator*=( Other rhs );
295 
296  template< typename Other >
297  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
298  operator/=( Other rhs );
300  //**********************************************************************************************
301 
302  //**Utility functions***************************************************************************
305  inline size_t size() const;
306  inline size_t capacity() const;
307  inline size_t nonZeros() const;
308  inline void reset();
309  inline void clear();
310  Iterator insert( size_t index, const Type& value );
311  inline void erase ( size_t index );
312  inline Iterator erase ( Iterator pos );
313  inline Iterator erase ( Iterator first, Iterator last );
314  inline void resize( size_t n, bool preserve=true );
315  void reserve( size_t n );
316  template< typename Other > inline CompressedVector& scale( Other scalar );
317  inline void swap( CompressedVector& sv ) /* throw() */;
319  //**********************************************************************************************
320 
321  //**Lookup functions****************************************************************************
324  inline Iterator find ( size_t index );
325  inline ConstIterator find ( size_t index ) const;
326  inline Iterator lowerBound( size_t index );
327  inline ConstIterator lowerBound( size_t index ) const;
328  inline Iterator upperBound( size_t index );
329  inline ConstIterator upperBound( size_t index ) const;
331  //**********************************************************************************************
332 
333  //**Low-level utility functions*****************************************************************
336  inline void append( size_t index, const Type& value, bool check=false );
338  //**********************************************************************************************
339 
340  //**Expression template evaluation functions****************************************************
343  template< typename Other > inline bool canAlias ( const Other* alias ) const;
344  template< typename Other > inline bool isAliased( const Other* alias ) const;
345  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
346  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
347  template< typename VT > inline void addAssign( const DenseVector <VT,TF>& rhs );
348  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
349  template< typename VT > inline void subAssign( const DenseVector <VT,TF>& rhs );
350  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
352  //**********************************************************************************************
353 
354  private:
355  //**Utility functions***************************************************************************
358  inline size_t extendCapacity() const;
360  //**********************************************************************************************
361 
362  //**Member variables****************************************************************************
365  size_t size_;
366  size_t capacity_;
369 
370  static const Type zero_;
371 
372  //**********************************************************************************************
373 
374  //**Compile time checks*************************************************************************
382  //**********************************************************************************************
383 };
384 //*************************************************************************************************
385 
386 
387 
388 
389 //=================================================================================================
390 //
391 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
392 //
393 //=================================================================================================
394 
395 template< typename Type // Data type of the vector
396  , bool TF > // Transpose flag
397 const Type CompressedVector<Type,TF>::zero_ = Type();
398 
399 
400 
401 
402 //=================================================================================================
403 //
404 // CONSTRUCTORS
405 //
406 //=================================================================================================
407 
408 //*************************************************************************************************
411 template< typename Type // Data type of the vector
412  , bool TF > // Transpose flag
414  : size_ ( 0UL ) // The current size/dimension of the compressed vector
415  , capacity_( 0UL ) // The maximum capacity of the compressed vector
416  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
417  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
418 {}
419 //*************************************************************************************************
420 
421 
422 //*************************************************************************************************
427 template< typename Type // Data type of the vector
428  , bool TF > // Transpose flag
430  : size_ ( n ) // The current size/dimension of the compressed vector
431  , capacity_( 0UL ) // The maximum capacity of the compressed vector
432  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
433  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
434 {}
435 //*************************************************************************************************
436 
437 
438 //*************************************************************************************************
444 template< typename Type // Data type of the vector
445  , bool TF > // Transpose flag
446 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
447  : size_ ( n ) // The current size/dimension of the compressed vector
448  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
449  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
450  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
451 {}
452 //*************************************************************************************************
453 
454 
455 //*************************************************************************************************
463 template< typename Type // Data type of the vector
464  , bool TF > // Transpose flag
466  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
467  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
468  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
469  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
470 {
471  std::copy( sv.begin_, sv.end_, begin_ );
472 }
473 //*************************************************************************************************
474 
475 
476 //*************************************************************************************************
481 template< typename Type // Data type of the vector
482  , bool TF > // Transpose flag
483 template< typename VT > // Type of the foreign dense vector
485  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
486  , capacity_( 0UL ) // The maximum capacity of the compressed vector
487  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
488  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
489 {
490  using blaze::assign;
491  assign( *this, ~dv );
492 }
493 //*************************************************************************************************
494 
495 
496 //*************************************************************************************************
501 template< typename Type // Data type of the vector
502  , bool TF > // Transpose flag
503 template< typename VT > // Type of the foreign sparse vector
505  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
506  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
507  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
508  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
509 {
510  using blaze::assign;
511  assign( *this, ~sv );
512 }
513 //*************************************************************************************************
514 
515 
516 
517 
518 //=================================================================================================
519 //
520 // DESTRUCTOR
521 //
522 //=================================================================================================
523 
524 //*************************************************************************************************
527 template< typename Type // Data type of the vector
528  , bool TF > // Transpose flag
530 {
531  deallocate( begin_ );
532 }
533 //*************************************************************************************************
534 
535 
536 
537 
538 //=================================================================================================
539 //
540 // DATA ACCESS FUNCTIONS
541 //
542 //=================================================================================================
543 
544 //*************************************************************************************************
555 template< typename Type // Data type of the vector
556  , bool TF > // Transpose flag
559 {
560  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
561 
562  return Reference( *this, index );
563 }
564 //*************************************************************************************************
565 
566 
567 //*************************************************************************************************
573 template< typename Type // Data type of the vector
574  , bool TF > // Transpose flag
577 {
578  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
579 
580  const ConstIterator pos( lowerBound( index ) );
581 
582  if( pos == end_ || pos->index_ != index )
583  return zero_;
584  else
585  return pos->value_;
586 }
587 //*************************************************************************************************
588 
589 
590 //*************************************************************************************************
595 template< typename Type // Data type of the vector
596  , bool TF > // Transpose flag
598 {
599  return Iterator( begin_ );
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
609 template< typename Type // Data type of the vector
610  , bool TF > // Transpose flag
612 {
613  return ConstIterator( begin_ );
614 }
615 //*************************************************************************************************
616 
617 
618 //*************************************************************************************************
623 template< typename Type // Data type of the vector
624  , bool TF > // Transpose flag
626 {
627  return ConstIterator( begin_ );
628 }
629 //*************************************************************************************************
630 
631 
632 //*************************************************************************************************
637 template< typename Type // Data type of the vector
638  , bool TF > // Transpose flag
640 {
641  return Iterator( end_ );
642 }
643 //*************************************************************************************************
644 
645 
646 //*************************************************************************************************
651 template< typename Type // Data type of the vector
652  , bool TF > // Transpose flag
654 {
655  return ConstIterator( end_ );
656 }
657 //*************************************************************************************************
658 
659 
660 //*************************************************************************************************
665 template< typename Type // Data type of the vector
666  , bool TF > // Transpose flag
668 {
669  return ConstIterator( end_ );
670 }
671 //*************************************************************************************************
672 
673 
674 
675 
676 //=================================================================================================
677 //
678 // ASSIGNMENT OPERATORS
679 //
680 //=================================================================================================
681 
682 //*************************************************************************************************
691 template< typename Type // Data type of the vector
692  , bool TF > // Transpose flag
695 {
696  if( &rhs == this ) return *this;
697 
698  const size_t nonzeros( rhs.nonZeros() );
699 
700  if( nonzeros > capacity_ ) {
701  Iterator newBegin( allocate<Element>( nonzeros ) );
702  end_ = std::copy( rhs.begin_, rhs.end_, newBegin );
703  std::swap( begin_, newBegin );
704  deallocate( newBegin );
705 
706  size_ = rhs.size_;
707  capacity_ = nonzeros;
708  }
709  else {
710  end_ = std::copy( rhs.begin_, rhs.end_, begin_ );
711  size_ = rhs.size_;
712  }
713 
714  return *this;
715 }
716 //*************************************************************************************************
717 
718 
719 //*************************************************************************************************
728 template< typename Type // Data type of the vector
729  , bool TF > // Transpose flag
730 template< typename VT > // Type of the right-hand side dense vector
733 {
734  using blaze::assign;
735 
736  if( (~rhs).canAlias( this ) ) {
737  CompressedVector tmp( rhs );
738  swap( tmp );
739  }
740  else {
741  size_ = (~rhs).size();
742  end_ = begin_;
743  assign( *this, ~rhs );
744  }
745 
746  return *this;
747 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
760 template< typename Type // Data type of the vector
761  , bool TF > // Transpose flag
762 template< typename VT > // Type of the right-hand side sparse vector
765 {
766  using blaze::assign;
767 
768  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
769  CompressedVector tmp( rhs );
770  swap( tmp );
771  }
772  else {
773  size_ = (~rhs).size();
774  end_ = begin_;
775  assign( *this, ~rhs );
776  }
777 
778  return *this;
779 }
780 //*************************************************************************************************
781 
782 
783 //*************************************************************************************************
793 template< typename Type // Data type of the vector
794  , bool TF > // Transpose flag
795 template< typename VT > // Type of the right-hand side vector
797 {
798  using blaze::addAssign;
799 
800  if( (~rhs).size() != size_ )
801  throw std::invalid_argument( "Vector sizes do not match" );
802 
803  addAssign( *this, ~rhs );
804 
805  return *this;
806 }
807 //*************************************************************************************************
808 
809 
810 //*************************************************************************************************
820 template< typename Type // Data type of the vector
821  , bool TF > // Transpose flag
822 template< typename VT > // Type of the right-hand side vector
824 {
825  using blaze::subAssign;
826 
827  if( (~rhs).size() != size_ )
828  throw std::invalid_argument( "Vector sizes do not match" );
829 
830  subAssign( *this, ~rhs );
831 
832  return *this;
833 }
834 //*************************************************************************************************
835 
836 
837 //*************************************************************************************************
848 template< typename Type // Data type of the vector
849  , bool TF > // Transpose flag
850 template< typename VT > // Type of the right-hand side vector
852 {
853  if( (~rhs).size() != size_ )
854  throw std::invalid_argument( "Vector sizes do not match" );
855 
856  CompressedVector<Type,TF> tmp( *this * (~rhs) );
857  swap( tmp );
858 
859  return *this;
860 }
861 //*************************************************************************************************
862 
863 
864 //*************************************************************************************************
875 template< typename Type // Data type of the vector
876  , bool TF > // Transpose flag
877 template< typename Other > // Data type of the right-hand side scalar
880 {
881  for( Iterator element=begin_; element!=end_; ++element )
882  element->value_ *= rhs;
883  return *this;
884 }
885 //*************************************************************************************************
886 
887 
888 //*************************************************************************************************
900 template< typename Type // Data type of the vector
901  , bool TF > // Transpose flag
902 template< typename Other > // Data type of the right-hand side scalar
905 {
906  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
907 
908  typedef typename DivTrait<Type,Other>::Type DT;
909  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
910 
911  // Depending on the two involved data types, an integer division is applied or a
912  // floating point division is selected.
914  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
915  for( Iterator element=begin_; element!=end_; ++element )
916  element->value_ *= tmp;
917  }
918  else {
919  for( Iterator element=begin_; element!=end_; ++element )
920  element->value_ /= rhs;
921  }
922 
923  return *this;
924 }
925 //*************************************************************************************************
926 
927 
928 
929 
930 //=================================================================================================
931 //
932 // UTILITY FUNCTIONS
933 //
934 //=================================================================================================
935 
936 //*************************************************************************************************
941 template< typename Type // Data type of the vector
942  , bool TF > // Transpose flag
943 inline size_t CompressedVector<Type,TF>::size() const
944 {
945  return size_;
946 }
947 //*************************************************************************************************
948 
949 
950 //*************************************************************************************************
955 template< typename Type // Data type of the vector
956  , bool TF > // Transpose flag
958 {
959  return capacity_;
960 }
961 //*************************************************************************************************
962 
963 
964 //*************************************************************************************************
972 template< typename Type // Data type of the vector
973  , bool TF > // Transpose flag
975 {
976  return end_ - begin_;
977 }
978 //*************************************************************************************************
979 
980 
981 //*************************************************************************************************
986 template< typename Type // Data type of the vector
987  , bool TF > // Transpose flag
989 {
990  end_ = begin_;
991 }
992 //*************************************************************************************************
993 
994 
995 //*************************************************************************************************
1002 template< typename Type // Data type of the vector
1003  , bool TF > // Transpose flag
1005 {
1006  size_ = 0UL;
1007  end_ = begin_;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1024 template< typename Type // Data type of the vector
1025  , bool TF > // Transpose flag
1027  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1028 {
1029  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1030 
1031  const Iterator pos( lowerBound( index ) );
1032 
1033  if( pos != end_ && pos->index_ == index )
1034  throw std::invalid_argument( "Bad access index" );
1035 
1036  if( nonZeros() != capacity_ ) {
1037  std::copy_backward( pos, end_, end_+1 );
1038  pos->value_ = value;
1039  pos->index_ = index;
1040  ++end_;
1041 
1042  return pos;
1043  }
1044  else {
1045  size_t newCapacity( extendCapacity() );
1046 
1047  Iterator newBegin = allocate<Element>( newCapacity );
1048  Iterator tmp = std::copy( begin_, pos, newBegin );
1049  tmp->value_ = value;
1050  tmp->index_ = index;
1051  end_ = std::copy( pos, end_, tmp+1 );
1052 
1053  std::swap( newBegin, begin_ );
1054  deallocate( newBegin );
1055  capacity_ = newCapacity;
1056 
1057  return tmp;
1058  }
1059 }
1060 //*************************************************************************************************
1061 
1062 
1063 //*************************************************************************************************
1071 template< typename Type // Data type of the vector
1072  , bool TF > // Transpose flag
1073 inline void CompressedVector<Type,TF>::erase( size_t index )
1074 {
1075  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1076 
1077  const Iterator pos( find( index ) );
1078  if( pos != end_ )
1079  end_ = std::copy( pos+1, end_, pos );
1080 }
1081 //*************************************************************************************************
1082 
1083 
1084 //*************************************************************************************************
1092 template< typename Type // Data type of the vector
1093  , bool TF > // Transpose flag
1095 {
1096  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1097 
1098  if( pos != end_ )
1099  end_ = std::copy( pos+1, end_, pos );
1100  return pos;
1101 }
1102 //*************************************************************************************************
1103 
1104 
1105 //*************************************************************************************************
1114 template< typename Type // Data type of the vector
1115  , bool TF > // Transpose flag
1118 {
1119  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1120  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1121  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1122 
1123  if( first != last )
1124  end_ = std::copy( last, end_, first );
1125  return first;
1126 }
1127 //*************************************************************************************************
1128 
1129 
1130 //*************************************************************************************************
1142 template< typename Type // Data type of the vector
1143  , bool TF > // Transpose flag
1144 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1145 {
1146  if( preserve ) {
1147  end_ = lowerBound( n );
1148  }
1149  else {
1150  end_ = begin_;
1151  }
1152 
1153  size_ = n;
1154 }
1155 //*************************************************************************************************
1156 
1157 
1158 //*************************************************************************************************
1167 template< typename Type // Data type of the vector
1168  , bool TF > // Transpose flag
1170 {
1171  if( n > capacity_ ) {
1172  const size_t newCapacity( n );
1173 
1174  // Allocating a new data and index array
1175  Iterator newBegin = allocate<Element>( newCapacity );
1176 
1177  // Replacing the old data and index array
1178  end_ = std::copy( begin_, end_, newBegin );
1179  std::swap( newBegin, begin_ );
1180  capacity_ = newCapacity;
1181  deallocate( newBegin );
1182  }
1183 }
1184 //*************************************************************************************************
1185 
1186 
1187 //*************************************************************************************************
1193 template< typename Type // Data type of the vector
1194  , bool TF > // Transpose flag
1195 template< typename Other > // Data type of the scalar value
1197 {
1198  for( Iterator element=begin_; element!=end_; ++element )
1199  element->value_ *= scalar;
1200  return *this;
1201 }
1202 //*************************************************************************************************
1203 
1204 
1205 //*************************************************************************************************
1212 template< typename Type // Data type of the vector
1213  , bool TF > // Transpose flag
1214 inline void CompressedVector<Type,TF>::swap( CompressedVector& sv ) /* throw() */
1215 {
1216  std::swap( size_, sv.size_ );
1217  std::swap( capacity_, sv.capacity_ );
1218  std::swap( begin_, sv.begin_ );
1219  std::swap( end_, sv.end_ );
1220 }
1221 //*************************************************************************************************
1222 
1223 
1224 //*************************************************************************************************
1232 template< typename Type // Data type of the vector
1233  , bool TF > // Transpose flag
1235 {
1236  using blaze::max;
1237  using blaze::min;
1238 
1239  size_t nonzeros( 2UL*capacity_+1UL );
1240  nonzeros = max( nonzeros, 7UL );
1241  nonzeros = min( nonzeros, size_ );
1242 
1243  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1244 
1245  return nonzeros;
1246 }
1247 //*************************************************************************************************
1248 
1249 
1250 
1251 
1252 //=================================================================================================
1253 //
1254 // LOOKUP FUNCTIONS
1255 //
1256 //=================================================================================================
1257 
1258 //*************************************************************************************************
1271 template< typename Type // Data type of the vector
1272  , bool TF > // Transpose flag
1274 {
1275  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1276 }
1277 //*************************************************************************************************
1278 
1279 
1280 //*************************************************************************************************
1293 template< typename Type // Data type of the vector
1294  , bool TF > // Transpose flag
1296 {
1297  const ConstIterator pos( lowerBound( index ) );
1298  if( pos != end_ && pos->index_ == index )
1299  return pos;
1300  else return end_;
1301 }
1302 //*************************************************************************************************
1303 
1304 
1305 //*************************************************************************************************
1317 template< typename Type // Data type of the vector
1318  , bool TF > // Transpose flag
1321 {
1322  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1323 }
1324 //*************************************************************************************************
1325 
1326 
1327 //*************************************************************************************************
1339 template< typename Type // Data type of the vector
1340  , bool TF > // Transpose flag
1343 {
1344  return std::lower_bound( begin_, end_, index, FindIndex() );
1345 }
1346 //*************************************************************************************************
1347 
1348 
1349 //*************************************************************************************************
1361 template< typename Type // Data type of the vector
1362  , bool TF > // Transpose flag
1365 {
1366  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1367 }
1368 //*************************************************************************************************
1369 
1370 
1371 //*************************************************************************************************
1383 template< typename Type // Data type of the vector
1384  , bool TF > // Transpose flag
1387 {
1388  return std::upper_bound( begin_, end_, index, FindIndex() );
1389 }
1390 //*************************************************************************************************
1391 
1392 
1393 
1394 
1395 //=================================================================================================
1396 //
1397 // LOW-LEVEL UTILITY FUNCTIONS
1398 //
1399 //=================================================================================================
1400 
1401 //*************************************************************************************************
1425 template< typename Type // Data type of the vector
1426  , bool TF > // Transpose flag
1427 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1428 {
1429  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1430  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved space" );
1431  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1432 
1433  end_->value_ = value;
1434 
1435  if( !check || !isDefault( end_->value_ ) ) {
1436  end_->index_ = index;
1437  ++end_;
1438  }
1439 }
1440 //*************************************************************************************************
1441 
1442 
1443 
1444 
1445 //=================================================================================================
1446 //
1447 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1448 //
1449 //=================================================================================================
1450 
1451 //*************************************************************************************************
1461 template< typename Type // Data type of the vector
1462  , bool TF > // Transpose flag
1463 template< typename Other > // Data type of the foreign expression
1464 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const
1465 {
1466  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1467 }
1468 //*************************************************************************************************
1469 
1470 
1471 //*************************************************************************************************
1481 template< typename Type // Data type of the vector
1482  , bool TF > // Transpose flag
1483 template< typename Other > // Data type of the foreign expression
1484 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const
1485 {
1486  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1487 }
1488 //*************************************************************************************************
1489 
1490 
1491 //*************************************************************************************************
1502 template< typename Type // Data type of the vector
1503  , bool TF > // Transpose flag
1504 template< typename VT > // Type of the right-hand side dense vector
1506 {
1507  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1508  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1509 
1510  size_t nonzeros( 0UL );
1511 
1512  for( size_t i=0UL; i<size_; ++i )
1513  {
1514  if( nonzeros == capacity_ )
1515  reserve( extendCapacity() );
1516 
1517  end_->value_ = (~rhs)[i];
1518 
1519  if( !isDefault( end_->value_ ) ) {
1520  end_->index_ = i;
1521  ++end_;
1522  ++nonzeros;
1523  }
1524  }
1525 }
1526 //*************************************************************************************************
1527 
1528 
1529 //*************************************************************************************************
1540 template< typename Type // Data type of the vector
1541  , bool TF > // Transpose flag
1542 template< typename VT > // Type of the right-hand side sparse vector
1544 {
1545  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1546  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1547 
1548  // Using the following formulation instead of a std::copy function call of the form
1549  //
1550  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
1551  //
1552  // results in much less requirements on the ConstIterator type provided from the right-hand
1553  // sparse vector type
1554  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1555  append( element->index(), element->value() );
1556 }
1557 //*************************************************************************************************
1558 
1559 
1560 //*************************************************************************************************
1571 template< typename Type // Data type of the vector
1572  , bool TF > // Transpose flag
1573 template< typename VT > // Type of the right-hand side dense vector
1575 {
1576  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1577 
1581 
1582  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1583 
1584  const AddType tmp( *this + (~rhs) );
1585  reset();
1586  assign( tmp );
1587 }
1588 //*************************************************************************************************
1589 
1590 
1591 //*************************************************************************************************
1602 template< typename Type // Data type of the vector
1603  , bool TF > // Transpose flag
1604 template< typename VT > // Type of the right-hand side sparse vector
1606 {
1607  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1608 
1609  CompressedVector<Type,TF> tmp( *this + (~rhs) );
1610  swap( tmp );
1611 }
1612 //*************************************************************************************************
1613 
1614 
1615 //*************************************************************************************************
1626 template< typename Type // Data type of the vector
1627  , bool TF > // Transpose flag
1628 template< typename VT > // Type of the right-hand side dense vector
1630 {
1631  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1632 
1636 
1637  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1638 
1639  const SubType tmp( *this - (~rhs) );
1640  reset();
1641  assign( tmp );
1642 }
1643 //*************************************************************************************************
1644 
1645 
1646 //*************************************************************************************************
1657 template< typename Type // Data type of the vector
1658  , bool TF > // Transpose flag
1659 template< typename VT > // Type of the right-hand side sparse vector
1661 {
1662  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1663 
1664  CompressedVector<Type,TF> tmp( *this - (~rhs) );
1665  swap( tmp );
1666 }
1667 //*************************************************************************************************
1668 
1669 
1670 
1671 
1672 //=================================================================================================
1673 //
1674 // COMPRESSEDVECTOR OPERATORS
1675 //
1676 //=================================================================================================
1677 
1678 //*************************************************************************************************
1681 template< typename Type, bool TF >
1682 inline void reset( CompressedVector<Type,TF>& v );
1683 
1684 template< typename Type, bool TF >
1685 inline void clear( CompressedVector<Type,TF>& v );
1686 
1687 template< typename Type, bool TF >
1688 inline bool isDefault( const CompressedVector<Type,TF>& v );
1689 
1690 template< typename Type, bool TF >
1691 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */;
1693 //*************************************************************************************************
1694 
1695 
1696 //*************************************************************************************************
1703 template< typename Type // Data type of the vector
1704  , bool TF > // Transpose flag
1706 {
1707  v.reset();
1708 }
1709 //*************************************************************************************************
1710 
1711 
1712 //*************************************************************************************************
1719 template< typename Type // Data type of the vector
1720  , bool TF > // Transpose flag
1722 {
1723  v.clear();
1724 }
1725 //*************************************************************************************************
1726 
1727 
1728 //*************************************************************************************************
1747 template< typename Type // Data type of the vector
1748  , bool TF > // Transpose flag
1749 inline bool isDefault( const CompressedVector<Type,TF>& v )
1750 {
1752 
1753  for( ConstIterator element=v.begin(); element!=v.end(); ++element )
1754  if( !isDefault( element->value() ) ) return false;
1755  return true;
1756 }
1757 //*************************************************************************************************
1758 
1759 
1760 //*************************************************************************************************
1769 template< typename Type // Data type of the vector
1770  , bool TF > // Transpose flag
1771 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */
1772 {
1773  a.swap( b );
1774 }
1775 //*************************************************************************************************
1776 
1777 
1778 
1779 
1780 //=================================================================================================
1781 //
1782 // ISRESIZABLE SPECIALIZATIONS
1783 //
1784 //=================================================================================================
1785 
1786 //*************************************************************************************************
1788 template< typename T, bool TF >
1789 struct IsResizable< CompressedVector<T,TF> > : public TrueType
1790 {
1791  enum { value = 1 };
1792  typedef TrueType Type;
1793 };
1794 
1795 template< typename T, bool TF >
1796 struct IsResizable< const CompressedVector<T,TF> > : public TrueType
1797 {
1798  enum { value = 1 };
1799  typedef TrueType Type;
1800 };
1801 
1802 template< typename T, bool TF >
1803 struct IsResizable< volatile CompressedVector<T,TF> > : public TrueType
1804 {
1805  enum { value = 1 };
1806  typedef TrueType Type;
1807 };
1808 
1809 template< typename T, bool TF >
1810 struct IsResizable< const volatile CompressedVector<T,TF> > : public TrueType
1811 {
1812  enum { value = 1 };
1813  typedef TrueType Type;
1814 };
1816 //*************************************************************************************************
1817 
1818 
1819 
1820 
1821 //=================================================================================================
1822 //
1823 // ADDTRAIT SPECIALIZATIONS
1824 //
1825 //=================================================================================================
1826 
1827 //*************************************************************************************************
1829 template< typename T1, bool TF, typename T2, size_t N >
1830 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1831 {
1832  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1833 };
1834 
1835 template< typename T1, size_t N, bool TF, typename T2 >
1836 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1837 {
1838  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1839 };
1840 
1841 template< typename T1, bool TF, typename T2, size_t N >
1842 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1843 {
1844  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1845 };
1846 
1847 template< typename T1, size_t N, bool TF, typename T2 >
1848 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1849 {
1850  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1851 };
1852 
1853 template< typename T1, bool TF, typename T2 >
1854 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1855 {
1856  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1857 };
1858 
1859 template< typename T1, bool TF, typename T2 >
1860 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1861 {
1862  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1863 };
1864 
1865 template< typename T1, bool TF, typename T2 >
1866 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1867 {
1868  typedef CompressedVector< typename AddTrait<T1,T2>::Type, TF > Type;
1869 };
1871 //*************************************************************************************************
1872 
1873 
1874 
1875 
1876 //=================================================================================================
1877 //
1878 // SUBTRAIT SPECIALIZATIONS
1879 //
1880 //=================================================================================================
1881 
1882 //*************************************************************************************************
1884 template< typename T1, bool TF, typename T2, size_t N >
1885 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1886 {
1887  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1888 };
1889 
1890 template< typename T1, size_t N, bool TF, typename T2 >
1891 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1892 {
1893  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1894 };
1895 
1896 template< typename T1, bool TF, typename T2, size_t N >
1897 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1898 {
1899  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1900 };
1901 
1902 template< typename T1, size_t N, bool TF, typename T2 >
1903 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1904 {
1905  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1906 };
1907 
1908 template< typename T1, bool TF, typename T2 >
1909 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1910 {
1911  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1912 };
1913 
1914 template< typename T1, bool TF, typename T2 >
1915 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1916 {
1917  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1918 };
1919 
1920 template< typename T1, bool TF, typename T2 >
1921 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1922 {
1923  typedef CompressedVector< typename SubTrait<T1,T2>::Type, TF > Type;
1924 };
1926 //*************************************************************************************************
1927 
1928 
1929 
1930 
1931 //=================================================================================================
1932 //
1933 // MULTTRAIT SPECIALIZATIONS
1934 //
1935 //=================================================================================================
1936 
1937 //*************************************************************************************************
1939 template< typename T1, bool TF, typename T2 >
1940 struct MultTrait< CompressedVector<T1,TF>, T2 >
1941 {
1942  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1944 };
1945 
1946 template< typename T1, typename T2, bool TF >
1947 struct MultTrait< T1, CompressedVector<T2,TF> >
1948 {
1949  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1951 };
1952 
1953 template< typename T1, bool TF, typename T2, size_t N >
1954 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1955 {
1956  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1957 };
1958 
1959 template< typename T1, typename T2, size_t N >
1960 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
1961 {
1962  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
1963 };
1964 
1965 template< typename T1, typename T2, size_t N >
1966 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
1967 {
1968  typedef typename MultTrait<T1,T2>::Type Type;
1969 };
1970 
1971 template< typename T1, size_t N, bool TF, typename T2 >
1972 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1973 {
1974  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1975 };
1976 
1977 template< typename T1, size_t N, typename T2 >
1978 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
1979 {
1980  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
1981 };
1982 
1983 template< typename T1, size_t N, typename T2 >
1984 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
1985 {
1986  typedef typename MultTrait<T1,T2>::Type Type;
1987 };
1988 
1989 template< typename T1, bool TF, typename T2, size_t N >
1990 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1991 {
1992  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
1993 };
1994 
1995 template< typename T1, typename T2, size_t N >
1996 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
1997 {
1998  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
1999 };
2000 
2001 template< typename T1, typename T2, size_t N >
2002 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2003 {
2004  typedef typename MultTrait<T1,T2>::Type Type;
2005 };
2006 
2007 template< typename T1, size_t N, bool TF, typename T2 >
2008 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2009 {
2010  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2011 };
2012 
2013 template< typename T1, size_t N, typename T2 >
2014 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2015 {
2016  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2017 };
2018 
2019 template< typename T1, size_t N, typename T2 >
2020 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2021 {
2022  typedef typename MultTrait<T1,T2>::Type Type;
2023 };
2024 
2025 template< typename T1, bool TF, typename T2 >
2026 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2027 {
2028  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2029 };
2030 
2031 template< typename T1, typename T2 >
2032 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2033 {
2034  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2035 };
2036 
2037 template< typename T1, typename T2 >
2038 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2039 {
2040  typedef typename MultTrait<T1,T2>::Type Type;
2041 };
2042 
2043 template< typename T1, bool TF, typename T2 >
2044 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2045 {
2046  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2047 };
2048 
2049 template< typename T1, typename T2 >
2050 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2051 {
2052  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2053 };
2054 
2055 template< typename T1, typename T2 >
2056 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2057 {
2058  typedef typename MultTrait<T1,T2>::Type Type;
2059 };
2060 
2061 template< typename T1, bool TF, typename T2 >
2062 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2063 {
2064  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2065 };
2066 
2067 template< typename T1, typename T2 >
2068 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2069 {
2070  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2071 };
2072 
2073 template< typename T1, typename T2 >
2074 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2075 {
2076  typedef typename MultTrait<T1,T2>::Type Type;
2077 };
2079 //*************************************************************************************************
2080 
2081 
2082 
2083 
2084 //=================================================================================================
2085 //
2086 // CROSSTRAIT SPECIALIZATIONS
2087 //
2088 //=================================================================================================
2089 
2090 //*************************************************************************************************
2092 template< typename T1, typename T2 >
2093 struct CrossTrait< CompressedVector<T1,false>, StaticVector<T2,3UL,false> >
2094 {
2095  private:
2096  typedef typename MultTrait<T1,T2>::Type T;
2097 
2098  public:
2099  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2100 };
2101 
2102 template< typename T1, typename T2 >
2103 struct CrossTrait< StaticVector<T1,3UL,false>, CompressedVector<T2,false> >
2104 {
2105  private:
2106  typedef typename MultTrait<T1,T2>::Type T;
2107 
2108  public:
2109  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2110 };
2111 
2112 template< typename T1, typename T2, size_t N >
2113 struct CrossTrait< CompressedVector<T1,false>, HybridVector<T2,N,false> >
2114 {
2115  private:
2116  typedef typename MultTrait<T1,T2>::Type T;
2117 
2118  public:
2119  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2120 };
2121 
2122 template< typename T1, size_t N, typename T2 >
2123 struct CrossTrait< HybridVector<T1,N,false>, CompressedVector<T2,false> >
2124 {
2125  private:
2126  typedef typename MultTrait<T1,T2>::Type T;
2127 
2128  public:
2129  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2130 };
2131 
2132 template< typename T1, typename T2 >
2133 struct CrossTrait< CompressedVector<T1,false>, DynamicVector<T2,false> >
2134 {
2135  private:
2136  typedef typename MultTrait<T1,T2>::Type T;
2137 
2138  public:
2139  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2140 };
2141 
2142 template< typename T1, typename T2 >
2143 struct CrossTrait< DynamicVector<T1,false>, CompressedVector<T2,false> >
2144 {
2145  private:
2146  typedef typename MultTrait<T1,T2>::Type T;
2147 
2148  public:
2149  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2150 };
2151 
2152 template< typename T1, typename T2 >
2153 struct CrossTrait< CompressedVector<T1,false>, CompressedVector<T2,false> >
2154 {
2155  private:
2156  typedef typename MultTrait<T1,T2>::Type T;
2157 
2158  public:
2159  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2160 };
2162 //*************************************************************************************************
2163 
2164 
2165 
2166 
2167 //=================================================================================================
2168 //
2169 // DIVTRAIT SPECIALIZATIONS
2170 //
2171 //=================================================================================================
2172 
2173 //*************************************************************************************************
2175 template< typename T1, bool TF, typename T2 >
2176 struct DivTrait< CompressedVector<T1,TF>, T2 >
2177 {
2178  typedef CompressedVector< typename DivTrait<T1,T2>::Type, TF > Type;
2180 };
2182 //*************************************************************************************************
2183 
2184 
2185 
2186 
2187 //=================================================================================================
2188 //
2189 // MATHTRAIT SPECIALIZATIONS
2190 //
2191 //=================================================================================================
2192 
2193 //*************************************************************************************************
2195 template< typename T1, bool TF, typename T2 >
2196 struct MathTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2197 {
2198  typedef CompressedVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2199  typedef CompressedVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2200 };
2202 //*************************************************************************************************
2203 
2204 
2205 
2206 
2207 //=================================================================================================
2208 //
2209 // SUBVECTORTRAIT SPECIALIZATIONS
2210 //
2211 //=================================================================================================
2212 
2213 //*************************************************************************************************
2215 template< typename T1, bool TF >
2216 struct SubvectorTrait< CompressedVector<T1,TF> >
2217 {
2218  typedef CompressedVector<T1,TF> Type;
2219 };
2221 //*************************************************************************************************
2222 
2223 } // namespace blaze
2224 
2225 #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:1484
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:4579
#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:957
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:1505
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1364
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:185
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:231
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:1214
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:235
Header file for a safe C++ NULL pointer implementation.
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:236
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:1574
Iterator end()
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:639
#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:1004
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:365
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:234
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2530
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:114
Header file for the floating point precision of the Blaze library.
size_t extendCapacity() const
Calculating a new vector capacity.
Definition: CompressedVector.h:1234
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:1629
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1427
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:413
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4558
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1464
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1027
#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:667
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2532
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:367
#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:233
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:625
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
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2386
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:366
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:230
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1073
Reference operator[](size_t index)
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:558
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1320
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1273
Header file for the IsNumeric type trait.
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:988
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1144
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:4651
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:229
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:943
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2387
Header file for the VectorAccessProxy class.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:238
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:237
Constraint on the data type.
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2531
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:83
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:974
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:529
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:694
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2534
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:368
Iterator begin()
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:597
Header file for basic type definitions.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2385
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:232
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:370
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:181
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1169