All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompressedVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
36 #define _BLAZE_MATH_SPARSE_COMPRESSEDVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <functional>
45 #include <stdexcept>
50 #include <blaze/math/Forward.h>
51 #include <blaze/math/Functions.h>
68 #include <blaze/util/Assert.h>
75 #include <blaze/util/EnableIf.h>
76 #include <blaze/util/Memory.h>
77 #include <blaze/util/mpl/If.h>
78 #include <blaze/util/Null.h>
79 #include <blaze/util/Types.h>
82 
83 
84 namespace blaze {
85 
86 //=================================================================================================
87 //
88 // CLASS DEFINITION
89 //
90 //=================================================================================================
91 
92 //*************************************************************************************************
186 template< typename Type // Data type of the vector
187  , bool TF = defaultTransposeFlag > // Transpose flag
188 class CompressedVector : public SparseVector< CompressedVector<Type,TF>, TF >
189 {
190  private:
191  //**Type definitions****************************************************************************
193  //**********************************************************************************************
194 
195  //**Private class Element***********************************************************************
199  struct Element : public ElementBase
200  {
201  // This operator is required due to a bug in all versions of the the MSVC compiler.
202  // A simple 'using ElementBase::operator=;' statement results in ambiguity problems.
203  template< typename Other >
204  inline Element& operator=( const Other& rhs )
205  {
206  ElementBase::operator=( rhs );
207  return *this;
208  }
209 
210  friend class CompressedVector;
211  };
213  //**********************************************************************************************
214 
215  //**Private class FindIndex*********************************************************************
219  struct FindIndex : public std::binary_function<Element,size_t,bool>
220  {
221  inline bool operator()( const Element& element, size_t index ) const {
222  return element.index() < index;
223  }
224  inline bool operator()( size_t index, const Element& element ) const {
225  return index < element.index();
226  }
227  inline bool operator()( const Element& element1, const Element& element2 ) const {
228  return element1.index() < element2.index();
229  }
230  };
232  //**********************************************************************************************
233 
234  public:
235  //**Type definitions****************************************************************************
237  typedef This ResultType;
239  typedef Type ElementType;
240  typedef const Type& ReturnType;
243  typedef const Type& ConstReference;
244  typedef Element* Iterator;
245  typedef const Element* ConstIterator;
246  //**********************************************************************************************
247 
248  //**Rebind struct definition********************************************************************
251  template< typename ET > // Data type of the other vector
252  struct Rebind {
254  };
255  //**********************************************************************************************
256 
257  //**Compilation flags***************************************************************************
259 
262  enum { smpAssignable = !IsSMPAssignable<Type>::value };
263  //**********************************************************************************************
264 
265  //**Constructors********************************************************************************
268  explicit inline CompressedVector();
269  explicit inline CompressedVector( size_t size );
270  explicit inline CompressedVector( size_t size, size_t nonzeros );
271  inline CompressedVector( const CompressedVector& sv );
272  template< typename VT > inline CompressedVector( const DenseVector<VT,TF>& dv );
273  template< typename VT > inline CompressedVector( const SparseVector<VT,TF>& sv );
275  //**********************************************************************************************
276 
277  //**Destructor**********************************************************************************
280  inline ~CompressedVector();
282  //**********************************************************************************************
283 
284  //**Data access functions***********************************************************************
287  inline Reference operator[]( size_t index );
288  inline ConstReference operator[]( size_t index ) const;
289  inline Iterator begin ();
290  inline ConstIterator begin () const;
291  inline ConstIterator cbegin() const;
292  inline Iterator end ();
293  inline ConstIterator end () const;
294  inline ConstIterator cend () const;
296  //**********************************************************************************************
297 
298  //**Assignment operators************************************************************************
301  inline CompressedVector& operator= ( const CompressedVector& rhs );
302  template< typename VT > inline CompressedVector& operator= ( const DenseVector<VT,TF>& rhs );
303  template< typename VT > inline CompressedVector& operator= ( const SparseVector<VT,TF>& rhs );
304  template< typename VT > inline CompressedVector& operator+=( const Vector<VT,TF>& rhs );
305  template< typename VT > inline CompressedVector& operator-=( const Vector<VT,TF>& rhs );
306  template< typename VT > inline CompressedVector& operator*=( const Vector<VT,TF>& rhs );
307 
308  template< typename Other >
309  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
310  operator*=( Other rhs );
311 
312  template< typename Other >
313  inline typename EnableIf< IsNumeric<Other>, CompressedVector >::Type&
314  operator/=( Other rhs );
316  //**********************************************************************************************
317 
318  //**Utility functions***************************************************************************
321  inline size_t size() const;
322  inline size_t capacity() const;
323  inline size_t nonZeros() const;
324  inline void reset();
325  inline void clear();
326  inline Iterator set ( size_t index, const Type& value );
327  inline Iterator insert( size_t index, const Type& value );
328  inline void erase ( size_t index );
329  inline Iterator erase ( Iterator pos );
330  inline Iterator erase ( Iterator first, Iterator last );
331  inline void resize( size_t n, bool preserve=true );
332  void reserve( size_t n );
333  template< typename Other > inline CompressedVector& scale( const Other& scalar );
334  inline void swap( CompressedVector& sv ) /* throw() */;
336  //**********************************************************************************************
337 
338  //**Lookup functions****************************************************************************
341  inline Iterator find ( size_t index );
342  inline ConstIterator find ( size_t index ) const;
343  inline Iterator lowerBound( size_t index );
344  inline ConstIterator lowerBound( size_t index ) const;
345  inline Iterator upperBound( size_t index );
346  inline ConstIterator upperBound( size_t index ) const;
348  //**********************************************************************************************
349 
350  //**Low-level utility functions*****************************************************************
353  inline void append( size_t index, const Type& value, bool check=false );
355  //**********************************************************************************************
356 
357  //**Expression template evaluation functions****************************************************
360  template< typename Other > inline bool canAlias ( const Other* alias ) const;
361  template< typename Other > inline bool isAliased( const Other* alias ) const;
362 
363  inline bool canSMPAssign() const;
364 
365  template< typename VT > inline void assign ( const DenseVector <VT,TF>& rhs );
366  template< typename VT > inline void assign ( const SparseVector<VT,TF>& rhs );
367  template< typename VT > inline void addAssign( const DenseVector <VT,TF>& rhs );
368  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
369  template< typename VT > inline void subAssign( const DenseVector <VT,TF>& rhs );
370  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
372  //**********************************************************************************************
373 
374  private:
375  //**Utility functions***************************************************************************
378  Iterator insert( Iterator pos, size_t index, const Type& value );
379  inline size_t extendCapacity() const;
381  //**********************************************************************************************
382 
383  //**Member variables****************************************************************************
386  size_t size_;
387  size_t capacity_;
390 
391  static const Type zero_;
392 
393  //**********************************************************************************************
394 
395  //**Compile time checks*************************************************************************
403  //**********************************************************************************************
404 };
405 //*************************************************************************************************
406 
407 
408 
409 
410 //=================================================================================================
411 //
412 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
413 //
414 //=================================================================================================
415 
416 template< typename Type // Data type of the vector
417  , bool TF > // Transpose flag
418 const Type CompressedVector<Type,TF>::zero_ = Type();
419 
420 
421 
422 
423 //=================================================================================================
424 //
425 // CONSTRUCTORS
426 //
427 //=================================================================================================
428 
429 //*************************************************************************************************
432 template< typename Type // Data type of the vector
433  , bool TF > // Transpose flag
435  : size_ ( 0UL ) // The current size/dimension of the compressed vector
436  , capacity_( 0UL ) // The maximum capacity of the compressed vector
437  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
438  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
439 {}
440 //*************************************************************************************************
441 
442 
443 //*************************************************************************************************
448 template< typename Type // Data type of the vector
449  , bool TF > // Transpose flag
451  : size_ ( n ) // The current size/dimension of the compressed vector
452  , capacity_( 0UL ) // The maximum capacity of the compressed vector
453  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
454  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
455 {}
456 //*************************************************************************************************
457 
458 
459 //*************************************************************************************************
465 template< typename Type // Data type of the vector
466  , bool TF > // Transpose flag
467 inline CompressedVector<Type,TF>::CompressedVector( size_t n, size_t nonzeros )
468  : size_ ( n ) // The current size/dimension of the compressed vector
469  , capacity_( nonzeros ) // The maximum capacity of the compressed vector
470  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
471  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
472 {}
473 //*************************************************************************************************
474 
475 
476 //*************************************************************************************************
484 template< typename Type // Data type of the vector
485  , bool TF > // Transpose flag
487  : size_ ( sv.size_ ) // The current size/dimension of the compressed vector
488  , capacity_( sv.nonZeros() ) // The maximum capacity of the compressed vector
489  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
490  , end_ ( begin_+capacity_ ) // Pointer to the last non-zero element of the compressed vector
491 {
492  std::copy( sv.begin_, sv.end_, begin_ );
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
502 template< typename Type // Data type of the vector
503  , bool TF > // Transpose flag
504 template< typename VT > // Type of the foreign dense vector
506  : size_ ( (~dv).size() ) // The current size/dimension of the compressed vector
507  , capacity_( 0UL ) // The maximum capacity of the compressed vector
508  , begin_ ( NULL ) // Pointer to the first non-zero element of the compressed vector
509  , end_ ( NULL ) // Pointer to the last non-zero element of the compressed vector
510 {
511  using blaze::assign;
512  assign( *this, ~dv );
513 }
514 //*************************************************************************************************
515 
516 
517 //*************************************************************************************************
522 template< typename Type // Data type of the vector
523  , bool TF > // Transpose flag
524 template< typename VT > // Type of the foreign sparse vector
526  : size_ ( (~sv).size() ) // The current size/dimension of the compressed vector
527  , capacity_( (~sv).nonZeros() ) // The maximum capacity of the compressed vector
528  , begin_ ( allocate<Element>( capacity_ ) ) // Pointer to the first non-zero element of the compressed vector
529  , end_ ( begin_ ) // Pointer to the last non-zero element of the compressed vector
530 {
531  using blaze::assign;
532  assign( *this, ~sv );
533 }
534 //*************************************************************************************************
535 
536 
537 
538 
539 //=================================================================================================
540 //
541 // DESTRUCTOR
542 //
543 //=================================================================================================
544 
545 //*************************************************************************************************
548 template< typename Type // Data type of the vector
549  , bool TF > // Transpose flag
551 {
552  deallocate( begin_ );
553 }
554 //*************************************************************************************************
555 
556 
557 
558 
559 //=================================================================================================
560 //
561 // DATA ACCESS FUNCTIONS
562 //
563 //=================================================================================================
564 
565 //*************************************************************************************************
576 template< typename Type // Data type of the vector
577  , bool TF > // Transpose flag
580 {
581  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
582 
583  return Reference( *this, index );
584 }
585 //*************************************************************************************************
586 
587 
588 //*************************************************************************************************
594 template< typename Type // Data type of the vector
595  , bool TF > // Transpose flag
598 {
599  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
600 
601  const ConstIterator pos( lowerBound( index ) );
602 
603  if( pos == end_ || pos->index_ != index )
604  return zero_;
605  else
606  return pos->value_;
607 }
608 //*************************************************************************************************
609 
610 
611 //*************************************************************************************************
616 template< typename Type // Data type of the vector
617  , bool TF > // Transpose flag
619 {
620  return Iterator( begin_ );
621 }
622 //*************************************************************************************************
623 
624 
625 //*************************************************************************************************
630 template< typename Type // Data type of the vector
631  , bool TF > // Transpose flag
633 {
634  return ConstIterator( begin_ );
635 }
636 //*************************************************************************************************
637 
638 
639 //*************************************************************************************************
644 template< typename Type // Data type of the vector
645  , bool TF > // Transpose flag
647 {
648  return ConstIterator( begin_ );
649 }
650 //*************************************************************************************************
651 
652 
653 //*************************************************************************************************
658 template< typename Type // Data type of the vector
659  , bool TF > // Transpose flag
661 {
662  return Iterator( end_ );
663 }
664 //*************************************************************************************************
665 
666 
667 //*************************************************************************************************
672 template< typename Type // Data type of the vector
673  , bool TF > // Transpose flag
675 {
676  return ConstIterator( end_ );
677 }
678 //*************************************************************************************************
679 
680 
681 //*************************************************************************************************
686 template< typename Type // Data type of the vector
687  , bool TF > // Transpose flag
689 {
690  return ConstIterator( end_ );
691 }
692 //*************************************************************************************************
693 
694 
695 
696 
697 //=================================================================================================
698 //
699 // ASSIGNMENT OPERATORS
700 //
701 //=================================================================================================
702 
703 //*************************************************************************************************
712 template< typename Type // Data type of the vector
713  , bool TF > // Transpose flag
716 {
717  if( &rhs == this ) return *this;
718 
719  const size_t nonzeros( rhs.nonZeros() );
720 
721  if( nonzeros > capacity_ ) {
722  Iterator newBegin( allocate<Element>( nonzeros ) );
723  end_ = std::copy( rhs.begin_, rhs.end_, newBegin );
724  std::swap( begin_, newBegin );
725  deallocate( newBegin );
726 
727  size_ = rhs.size_;
728  capacity_ = nonzeros;
729  }
730  else {
731  end_ = std::copy( rhs.begin_, rhs.end_, begin_ );
732  size_ = rhs.size_;
733  }
734 
735  return *this;
736 }
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
749 template< typename Type // Data type of the vector
750  , bool TF > // Transpose flag
751 template< typename VT > // Type of the right-hand side dense vector
754 {
755  using blaze::assign;
756 
757  if( (~rhs).canAlias( this ) ) {
758  CompressedVector tmp( ~rhs );
759  swap( tmp );
760  }
761  else {
762  size_ = (~rhs).size();
763  end_ = begin_;
764  assign( *this, ~rhs );
765  }
766 
767  return *this;
768 }
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
781 template< typename Type // Data type of the vector
782  , bool TF > // Transpose flag
783 template< typename VT > // Type of the right-hand side sparse vector
786 {
787  using blaze::assign;
788 
789  if( (~rhs).canAlias( this ) || (~rhs).nonZeros() > capacity_ ) {
790  CompressedVector tmp( ~rhs );
791  swap( tmp );
792  }
793  else {
794  size_ = (~rhs).size();
795  end_ = begin_;
796  assign( *this, ~rhs );
797  }
798 
799  return *this;
800 }
801 //*************************************************************************************************
802 
803 
804 //*************************************************************************************************
814 template< typename Type // Data type of the vector
815  , bool TF > // Transpose flag
816 template< typename VT > // Type of the right-hand side vector
818 {
819  using blaze::addAssign;
820 
821  if( (~rhs).size() != size_ )
822  throw std::invalid_argument( "Vector sizes do not match" );
823 
824  addAssign( *this, ~rhs );
825 
826  return *this;
827 }
828 //*************************************************************************************************
829 
830 
831 //*************************************************************************************************
841 template< typename Type // Data type of the vector
842  , bool TF > // Transpose flag
843 template< typename VT > // Type of the right-hand side vector
845 {
846  using blaze::subAssign;
847 
848  if( (~rhs).size() != size_ )
849  throw std::invalid_argument( "Vector sizes do not match" );
850 
851  subAssign( *this, ~rhs );
852 
853  return *this;
854 }
855 //*************************************************************************************************
856 
857 
858 //*************************************************************************************************
869 template< typename Type // Data type of the vector
870  , bool TF > // Transpose flag
871 template< typename VT > // Type of the right-hand side vector
873 {
874  if( (~rhs).size() != size_ )
875  throw std::invalid_argument( "Vector sizes do not match" );
876 
877  CompressedVector<Type,TF> tmp( *this * (~rhs) );
878  swap( tmp );
879 
880  return *this;
881 }
882 //*************************************************************************************************
883 
884 
885 //*************************************************************************************************
896 template< typename Type // Data type of the vector
897  , bool TF > // Transpose flag
898 template< typename Other > // Data type of the right-hand side scalar
901 {
902  for( Iterator element=begin_; element!=end_; ++element )
903  element->value_ *= rhs;
904  return *this;
905 }
906 //*************************************************************************************************
907 
908 
909 //*************************************************************************************************
921 template< typename Type // Data type of the vector
922  , bool TF > // Transpose flag
923 template< typename Other > // Data type of the right-hand side scalar
926 {
927  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
928 
929  typedef typename DivTrait<Type,Other>::Type DT;
930  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
931 
932  // Depending on the two involved data types, an integer division is applied or a
933  // floating point division is selected.
935  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
936  for( Iterator element=begin_; element!=end_; ++element )
937  element->value_ *= tmp;
938  }
939  else {
940  for( Iterator element=begin_; element!=end_; ++element )
941  element->value_ /= rhs;
942  }
943 
944  return *this;
945 }
946 //*************************************************************************************************
947 
948 
949 
950 
951 //=================================================================================================
952 //
953 // UTILITY FUNCTIONS
954 //
955 //=================================================================================================
956 
957 //*************************************************************************************************
962 template< typename Type // Data type of the vector
963  , bool TF > // Transpose flag
964 inline size_t CompressedVector<Type,TF>::size() const
965 {
966  return size_;
967 }
968 //*************************************************************************************************
969 
970 
971 //*************************************************************************************************
976 template< typename Type // Data type of the vector
977  , bool TF > // Transpose flag
979 {
980  return capacity_;
981 }
982 //*************************************************************************************************
983 
984 
985 //*************************************************************************************************
993 template< typename Type // Data type of the vector
994  , bool TF > // Transpose flag
996 {
997  return end_ - begin_;
998 }
999 //*************************************************************************************************
1000 
1001 
1002 //*************************************************************************************************
1007 template< typename Type // Data type of the vector
1008  , bool TF > // Transpose flag
1010 {
1011  end_ = begin_;
1012 }
1013 //*************************************************************************************************
1014 
1015 
1016 //*************************************************************************************************
1023 template< typename Type // Data type of the vector
1024  , bool TF > // Transpose flag
1026 {
1027  size_ = 0UL;
1028  end_ = begin_;
1029 }
1030 //*************************************************************************************************
1031 
1032 
1033 //*************************************************************************************************
1044 template< typename Type // Data type of the vector
1045  , bool TF > // Transpose flag
1047  CompressedVector<Type,TF>::set( size_t index, const Type& value )
1048 {
1049  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1050 
1051  const Iterator pos( lowerBound( index ) );
1052 
1053  if( pos != end_ && pos->index_ == index ) {
1054  pos->value() = value;
1055  return pos;
1056  }
1057  else return insert( pos, index, value );
1058 }
1059 //*************************************************************************************************
1060 
1061 
1062 //*************************************************************************************************
1074 template< typename Type // Data type of the vector
1075  , bool TF > // Transpose flag
1077  CompressedVector<Type,TF>::insert( size_t index, const Type& value )
1078 {
1079  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1080 
1081  const Iterator pos( lowerBound( index ) );
1082 
1083  if( pos != end_ && pos->index_ == index )
1084  throw std::invalid_argument( "Bad access index" );
1085 
1086  return insert( pos, index, value );
1087 }
1088 //*************************************************************************************************
1089 
1090 
1091 //*************************************************************************************************
1100 template< typename Type // Data type of the vector
1101  , bool TF > // Transpose flag
1103  CompressedVector<Type,TF>::insert( Iterator pos, size_t index, const Type& value )
1104 {
1105  if( nonZeros() != capacity_ ) {
1106  std::copy_backward( pos, end_, end_+1 );
1107  pos->value_ = value;
1108  pos->index_ = index;
1109  ++end_;
1110 
1111  return pos;
1112  }
1113  else {
1114  size_t newCapacity( extendCapacity() );
1115 
1116  Iterator newBegin = allocate<Element>( newCapacity );
1117  Iterator tmp = std::copy( begin_, pos, newBegin );
1118  tmp->value_ = value;
1119  tmp->index_ = index;
1120  end_ = std::copy( pos, end_, tmp+1 );
1121 
1122  std::swap( newBegin, begin_ );
1123  deallocate( newBegin );
1124  capacity_ = newCapacity;
1125 
1126  return tmp;
1127  }
1128 }
1129 //*************************************************************************************************
1130 
1131 
1132 //*************************************************************************************************
1140 template< typename Type // Data type of the vector
1141  , bool TF > // Transpose flag
1142 inline void CompressedVector<Type,TF>::erase( size_t index )
1143 {
1144  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1145 
1146  const Iterator pos( find( index ) );
1147  if( pos != end_ )
1148  end_ = std::copy( pos+1, end_, pos );
1149 }
1150 //*************************************************************************************************
1151 
1152 
1153 //*************************************************************************************************
1161 template< typename Type // Data type of the vector
1162  , bool TF > // Transpose flag
1164 {
1165  BLAZE_USER_ASSERT( pos >= begin_ && pos <= end_, "Invalid compressed vector iterator" );
1166 
1167  if( pos != end_ )
1168  end_ = std::copy( pos+1, end_, pos );
1169  return pos;
1170 }
1171 //*************************************************************************************************
1172 
1173 
1174 //*************************************************************************************************
1183 template< typename Type // Data type of the vector
1184  , bool TF > // Transpose flag
1187 {
1188  BLAZE_USER_ASSERT( first <= last, "Invalid iterator range" );
1189  BLAZE_USER_ASSERT( first >= begin_ && first <= end_, "Invalid compressed vector iterator" );
1190  BLAZE_USER_ASSERT( last >= begin_ && last <= end_, "Invalid compressed vector iterator" );
1191 
1192  if( first != last )
1193  end_ = std::copy( last, end_, first );
1194  return first;
1195 }
1196 //*************************************************************************************************
1197 
1198 
1199 //*************************************************************************************************
1213 template< typename Type // Data type of the vector
1214  , bool TF > // Transpose flag
1215 inline void CompressedVector<Type,TF>::resize( size_t n, bool preserve )
1216 {
1217  if( preserve ) {
1218  end_ = lowerBound( n );
1219  }
1220  else {
1221  end_ = begin_;
1222  }
1223 
1224  size_ = n;
1225 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1238 template< typename Type // Data type of the vector
1239  , bool TF > // Transpose flag
1241 {
1242  if( n > capacity_ ) {
1243  const size_t newCapacity( n );
1244 
1245  // Allocating a new data and index array
1246  Iterator newBegin = allocate<Element>( newCapacity );
1247 
1248  // Replacing the old data and index array
1249  end_ = std::copy( begin_, end_, newBegin );
1250  std::swap( newBegin, begin_ );
1251  capacity_ = newCapacity;
1252  deallocate( newBegin );
1253  }
1254 }
1255 //*************************************************************************************************
1256 
1257 
1258 //*************************************************************************************************
1264 template< typename Type // Data type of the vector
1265  , bool TF > // Transpose flag
1266 template< typename Other > // Data type of the scalar value
1268 {
1269  for( Iterator element=begin_; element!=end_; ++element )
1270  element->value_ *= scalar;
1271  return *this;
1272 }
1273 //*************************************************************************************************
1274 
1275 
1276 //*************************************************************************************************
1283 template< typename Type // Data type of the vector
1284  , bool TF > // Transpose flag
1285 inline void CompressedVector<Type,TF>::swap( CompressedVector& sv ) /* throw() */
1286 {
1287  std::swap( size_, sv.size_ );
1288  std::swap( capacity_, sv.capacity_ );
1289  std::swap( begin_, sv.begin_ );
1290  std::swap( end_, sv.end_ );
1291 }
1292 //*************************************************************************************************
1293 
1294 
1295 //*************************************************************************************************
1303 template< typename Type // Data type of the vector
1304  , bool TF > // Transpose flag
1306 {
1307  using blaze::max;
1308  using blaze::min;
1309 
1310  size_t nonzeros( 2UL*capacity_+1UL );
1311  nonzeros = max( nonzeros, 7UL );
1312  nonzeros = min( nonzeros, size_ );
1313 
1314  BLAZE_INTERNAL_ASSERT( nonzeros > capacity_, "Invalid capacity value" );
1315 
1316  return nonzeros;
1317 }
1318 //*************************************************************************************************
1319 
1320 
1321 
1322 
1323 //=================================================================================================
1324 //
1325 // LOOKUP FUNCTIONS
1326 //
1327 //=================================================================================================
1328 
1329 //*************************************************************************************************
1342 template< typename Type // Data type of the vector
1343  , bool TF > // Transpose flag
1345 {
1346  return const_cast<Iterator>( const_cast<const This&>( *this ).find( index ) );
1347 }
1348 //*************************************************************************************************
1349 
1350 
1351 //*************************************************************************************************
1364 template< typename Type // Data type of the vector
1365  , bool TF > // Transpose flag
1367 {
1368  const ConstIterator pos( lowerBound( index ) );
1369  if( pos != end_ && pos->index_ == index )
1370  return pos;
1371  else return end_;
1372 }
1373 //*************************************************************************************************
1374 
1375 
1376 //*************************************************************************************************
1388 template< typename Type // Data type of the vector
1389  , bool TF > // Transpose flag
1392 {
1393  return const_cast<Iterator>( const_cast<const This&>( *this ).lowerBound( index ) );
1394 }
1395 //*************************************************************************************************
1396 
1397 
1398 //*************************************************************************************************
1410 template< typename Type // Data type of the vector
1411  , bool TF > // Transpose flag
1414 {
1415  return std::lower_bound( begin_, end_, index, FindIndex() );
1416 }
1417 //*************************************************************************************************
1418 
1419 
1420 //*************************************************************************************************
1432 template< typename Type // Data type of the vector
1433  , bool TF > // Transpose flag
1436 {
1437  return const_cast<Iterator>( const_cast<const This&>( *this ).upperBound( index ) );
1438 }
1439 //*************************************************************************************************
1440 
1441 
1442 //*************************************************************************************************
1454 template< typename Type // Data type of the vector
1455  , bool TF > // Transpose flag
1458 {
1459  return std::upper_bound( begin_, end_, index, FindIndex() );
1460 }
1461 //*************************************************************************************************
1462 
1463 
1464 
1465 
1466 //=================================================================================================
1467 //
1468 // LOW-LEVEL UTILITY FUNCTIONS
1469 //
1470 //=================================================================================================
1471 
1472 //*************************************************************************************************
1496 template< typename Type // Data type of the vector
1497  , bool TF > // Transpose flag
1498 inline void CompressedVector<Type,TF>::append( size_t index, const Type& value, bool check )
1499 {
1500  BLAZE_USER_ASSERT( index < size_, "Invalid compressed vector access index" );
1501  BLAZE_USER_ASSERT( nonZeros() < capacity(), "Not enough reserved space" );
1502  BLAZE_USER_ASSERT( begin_ == end_ || (end_-1UL)->index_ < index, "Index is not strictly increasing" );
1503 
1504  end_->value_ = value;
1505 
1506  if( !check || !isDefault( end_->value_ ) ) {
1507  end_->index_ = index;
1508  ++end_;
1509  }
1510 }
1511 //*************************************************************************************************
1512 
1513 
1514 
1515 
1516 //=================================================================================================
1517 //
1518 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1519 //
1520 //=================================================================================================
1521 
1522 //*************************************************************************************************
1532 template< typename Type // Data type of the vector
1533  , bool TF > // Transpose flag
1534 template< typename Other > // Data type of the foreign expression
1535 inline bool CompressedVector<Type,TF>::canAlias( const Other* alias ) const
1536 {
1537  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1538 }
1539 //*************************************************************************************************
1540 
1541 
1542 //*************************************************************************************************
1552 template< typename Type // Data type of the vector
1553  , bool TF > // Transpose flag
1554 template< typename Other > // Data type of the foreign expression
1555 inline bool CompressedVector<Type,TF>::isAliased( const Other* alias ) const
1556 {
1557  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1558 }
1559 //*************************************************************************************************
1560 
1561 
1562 //*************************************************************************************************
1572 template< typename Type // Data type of the vector
1573  , bool TF > // Transpose flag
1575 {
1576  return false;
1577 }
1578 //*************************************************************************************************
1579 
1580 
1581 //*************************************************************************************************
1592 template< typename Type // Data type of the vector
1593  , bool TF > // Transpose flag
1594 template< typename VT > // Type of the right-hand side dense vector
1596 {
1597  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1598  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1599 
1600  size_t nonzeros( 0UL );
1601 
1602  for( size_t i=0UL; i<size_; ++i )
1603  {
1604  if( nonzeros == capacity_ )
1605  reserve( extendCapacity() );
1606 
1607  end_->value_ = (~rhs)[i];
1608 
1609  if( !isDefault( end_->value_ ) ) {
1610  end_->index_ = i;
1611  ++end_;
1612  ++nonzeros;
1613  }
1614  }
1615 }
1616 //*************************************************************************************************
1617 
1618 
1619 //*************************************************************************************************
1630 template< typename Type // Data type of the vector
1631  , bool TF > // Transpose flag
1632 template< typename VT > // Type of the right-hand side sparse vector
1634 {
1635  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1636  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1637 
1638  // Using the following formulation instead of a std::copy function call of the form
1639  //
1640  // end_ = std::copy( (~rhs).begin(), (~rhs).end(), begin_ );
1641  //
1642  // results in much less requirements on the ConstIterator type provided from the right-hand
1643  // sparse vector type
1644  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1645  append( element->index(), element->value() );
1646 }
1647 //*************************************************************************************************
1648 
1649 
1650 //*************************************************************************************************
1661 template< typename Type // Data type of the vector
1662  , bool TF > // Transpose flag
1663 template< typename VT > // Type of the right-hand side dense vector
1665 {
1666  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1667 
1671 
1672  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1673 
1674  const AddType tmp( serial( *this + (~rhs) ) );
1675  reset();
1676  assign( tmp );
1677 }
1678 //*************************************************************************************************
1679 
1680 
1681 //*************************************************************************************************
1692 template< typename Type // Data type of the vector
1693  , bool TF > // Transpose flag
1694 template< typename VT > // Type of the right-hand side sparse vector
1696 {
1697  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1698 
1699  CompressedVector<Type,TF> tmp( serial( *this + (~rhs) ) );
1700  swap( tmp );
1701 }
1702 //*************************************************************************************************
1703 
1704 
1705 //*************************************************************************************************
1716 template< typename Type // Data type of the vector
1717  , bool TF > // Transpose flag
1718 template< typename VT > // Type of the right-hand side dense vector
1720 {
1721  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1722 
1726 
1727  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1728 
1729  const SubType tmp( serial( *this - (~rhs) ) );
1730  reset();
1731  assign( tmp );
1732 }
1733 //*************************************************************************************************
1734 
1735 
1736 //*************************************************************************************************
1747 template< typename Type // Data type of the vector
1748  , bool TF > // Transpose flag
1749 template< typename VT > // Type of the right-hand side sparse vector
1751 {
1752  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1753 
1754  CompressedVector<Type,TF> tmp( serial( *this - (~rhs) ) );
1755  swap( tmp );
1756 }
1757 //*************************************************************************************************
1758 
1759 
1760 
1761 
1762 //=================================================================================================
1763 //
1764 // COMPRESSEDVECTOR OPERATORS
1765 //
1766 //=================================================================================================
1767 
1768 //*************************************************************************************************
1771 template< typename Type, bool TF >
1772 inline void reset( CompressedVector<Type,TF>& v );
1773 
1774 template< typename Type, bool TF >
1775 inline void clear( CompressedVector<Type,TF>& v );
1776 
1777 template< typename Type, bool TF >
1778 inline bool isDefault( const CompressedVector<Type,TF>& v );
1779 
1780 template< typename Type, bool TF >
1781 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */;
1782 
1783 template< typename Type, bool TF >
1784 inline void move( CompressedVector<Type,TF>& dst, CompressedVector<Type,TF>& src ) /* throw() */;
1786 //*************************************************************************************************
1787 
1788 
1789 //*************************************************************************************************
1796 template< typename Type // Data type of the vector
1797  , bool TF > // Transpose flag
1799 {
1800  v.reset();
1801 }
1802 //*************************************************************************************************
1803 
1804 
1805 //*************************************************************************************************
1812 template< typename Type // Data type of the vector
1813  , bool TF > // Transpose flag
1815 {
1816  v.clear();
1817 }
1818 //*************************************************************************************************
1819 
1820 
1821 //*************************************************************************************************
1838 template< typename Type // Data type of the vector
1839  , bool TF > // Transpose flag
1840 inline bool isDefault( const CompressedVector<Type,TF>& v )
1841 {
1842  return ( v.size() == 0UL );
1843 }
1844 //*************************************************************************************************
1845 
1846 
1847 //*************************************************************************************************
1856 template< typename Type // Data type of the vector
1857  , bool TF > // Transpose flag
1858 inline void swap( CompressedVector<Type,TF>& a, CompressedVector<Type,TF>& b ) /* throw() */
1859 {
1860  a.swap( b );
1861 }
1862 //*************************************************************************************************
1863 
1864 
1865 //*************************************************************************************************
1874 template< typename Type // Data type of the vector
1875  , bool TF > // Transpose flag
1876 inline void move( CompressedVector<Type,TF>& dst, CompressedVector<Type,TF>& src ) /* throw() */
1877 {
1878  dst.swap( src );
1879 }
1880 //*************************************************************************************************
1881 
1882 
1883 
1884 
1885 //=================================================================================================
1886 //
1887 // ISRESIZABLE SPECIALIZATIONS
1888 //
1889 //=================================================================================================
1890 
1891 //*************************************************************************************************
1893 template< typename T, bool TF >
1894 struct IsResizable< CompressedVector<T,TF> > : public TrueType
1895 {
1896  enum { value = 1 };
1897  typedef TrueType Type;
1898 };
1900 //*************************************************************************************************
1901 
1902 
1903 
1904 
1905 //=================================================================================================
1906 //
1907 // ADDTRAIT SPECIALIZATIONS
1908 //
1909 //=================================================================================================
1910 
1911 //*************************************************************************************************
1913 template< typename T1, bool TF, typename T2, size_t N >
1914 struct AddTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1915 {
1916  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1917 };
1918 
1919 template< typename T1, size_t N, bool TF, typename T2 >
1920 struct AddTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1921 {
1922  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1923 };
1924 
1925 template< typename T1, bool TF, typename T2, size_t N >
1926 struct AddTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1927 {
1928  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1929 };
1930 
1931 template< typename T1, size_t N, bool TF, typename T2 >
1932 struct AddTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1933 {
1934  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
1935 };
1936 
1937 template< typename T1, bool TF, typename T2 >
1938 struct AddTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1939 {
1940  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1941 };
1942 
1943 template< typename T1, bool TF, typename T2 >
1944 struct AddTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
1945 {
1946  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
1947 };
1948 
1949 template< typename T1, bool TF, typename T2 >
1950 struct AddTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
1951 {
1952  typedef CompressedVector< typename AddTrait<T1,T2>::Type, TF > Type;
1953 };
1955 //*************************************************************************************************
1956 
1957 
1958 
1959 
1960 //=================================================================================================
1961 //
1962 // SUBTRAIT SPECIALIZATIONS
1963 //
1964 //=================================================================================================
1965 
1966 //*************************************************************************************************
1968 template< typename T1, bool TF, typename T2, size_t N >
1969 struct SubTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
1970 {
1971  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1972 };
1973 
1974 template< typename T1, size_t N, bool TF, typename T2 >
1975 struct SubTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
1976 {
1977  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1978 };
1979 
1980 template< typename T1, bool TF, typename T2, size_t N >
1981 struct SubTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
1982 {
1983  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1984 };
1985 
1986 template< typename T1, size_t N, bool TF, typename T2 >
1987 struct SubTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
1988 {
1989  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
1990 };
1991 
1992 template< typename T1, bool TF, typename T2 >
1993 struct SubTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
1994 {
1995  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
1996 };
1997 
1998 template< typename T1, bool TF, typename T2 >
1999 struct SubTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2000 {
2001  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2002 };
2003 
2004 template< typename T1, bool TF, typename T2 >
2005 struct SubTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2006 {
2007  typedef CompressedVector< typename SubTrait<T1,T2>::Type, TF > Type;
2008 };
2010 //*************************************************************************************************
2011 
2012 
2013 
2014 
2015 //=================================================================================================
2016 //
2017 // MULTTRAIT SPECIALIZATIONS
2018 //
2019 //=================================================================================================
2020 
2021 //*************************************************************************************************
2023 template< typename T1, bool TF, typename T2 >
2024 struct MultTrait< CompressedVector<T1,TF>, T2 >
2025 {
2026  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2028 };
2029 
2030 template< typename T1, typename T2, bool TF >
2031 struct MultTrait< T1, CompressedVector<T2,TF> >
2032 {
2033  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2035 };
2036 
2037 template< typename T1, bool TF, typename T2, size_t N >
2038 struct MultTrait< CompressedVector<T1,TF>, StaticVector<T2,N,TF> >
2039 {
2040  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2041 };
2042 
2043 template< typename T1, typename T2, size_t N >
2044 struct MultTrait< CompressedVector<T1,false>, StaticVector<T2,N,true> >
2045 {
2046  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2047 };
2048 
2049 template< typename T1, typename T2, size_t N >
2050 struct MultTrait< CompressedVector<T1,true>, StaticVector<T2,N,false> >
2051 {
2052  typedef typename MultTrait<T1,T2>::Type Type;
2053 };
2054 
2055 template< typename T1, size_t N, bool TF, typename T2 >
2056 struct MultTrait< StaticVector<T1,N,TF>, CompressedVector<T2,TF> >
2057 {
2058  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2059 };
2060 
2061 template< typename T1, size_t N, typename T2 >
2062 struct MultTrait< StaticVector<T1,N,false>, CompressedVector<T2,true> >
2063 {
2064  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2065 };
2066 
2067 template< typename T1, size_t N, typename T2 >
2068 struct MultTrait< StaticVector<T1,N,true>, CompressedVector<T2,false> >
2069 {
2070  typedef typename MultTrait<T1,T2>::Type Type;
2071 };
2072 
2073 template< typename T1, bool TF, typename T2, size_t N >
2074 struct MultTrait< CompressedVector<T1,TF>, HybridVector<T2,N,TF> >
2075 {
2076  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2077 };
2078 
2079 template< typename T1, typename T2, size_t N >
2080 struct MultTrait< CompressedVector<T1,false>, HybridVector<T2,N,true> >
2081 {
2082  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2083 };
2084 
2085 template< typename T1, typename T2, size_t N >
2086 struct MultTrait< CompressedVector<T1,true>, HybridVector<T2,N,false> >
2087 {
2088  typedef typename MultTrait<T1,T2>::Type Type;
2089 };
2090 
2091 template< typename T1, size_t N, bool TF, typename T2 >
2092 struct MultTrait< HybridVector<T1,N,TF>, CompressedVector<T2,TF> >
2093 {
2094  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2095 };
2096 
2097 template< typename T1, size_t N, typename T2 >
2098 struct MultTrait< HybridVector<T1,N,false>, CompressedVector<T2,true> >
2099 {
2100  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2101 };
2102 
2103 template< typename T1, size_t N, typename T2 >
2104 struct MultTrait< HybridVector<T1,N,true>, CompressedVector<T2,false> >
2105 {
2106  typedef typename MultTrait<T1,T2>::Type Type;
2107 };
2108 
2109 template< typename T1, bool TF, typename T2 >
2110 struct MultTrait< CompressedVector<T1,TF>, DynamicVector<T2,TF> >
2111 {
2112  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2113 };
2114 
2115 template< typename T1, typename T2 >
2116 struct MultTrait< CompressedVector<T1,false>, DynamicVector<T2,true> >
2117 {
2118  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, true > Type;
2119 };
2120 
2121 template< typename T1, typename T2 >
2122 struct MultTrait< CompressedVector<T1,true>, DynamicVector<T2,false> >
2123 {
2124  typedef typename MultTrait<T1,T2>::Type Type;
2125 };
2126 
2127 template< typename T1, bool TF, typename T2 >
2128 struct MultTrait< DynamicVector<T1,TF>, CompressedVector<T2,TF> >
2129 {
2130  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2131 };
2132 
2133 template< typename T1, typename T2 >
2134 struct MultTrait< DynamicVector<T1,false>, CompressedVector<T2,true> >
2135 {
2136  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2137 };
2138 
2139 template< typename T1, typename T2 >
2140 struct MultTrait< DynamicVector<T1,true>, CompressedVector<T2,false> >
2141 {
2142  typedef typename MultTrait<T1,T2>::Type Type;
2143 };
2144 
2145 template< typename T1, bool TF, typename T2 >
2146 struct MultTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2147 {
2148  typedef CompressedVector< typename MultTrait<T1,T2>::Type, TF > Type;
2149 };
2150 
2151 template< typename T1, typename T2 >
2152 struct MultTrait< CompressedVector<T1,false>, CompressedVector<T2,true> >
2153 {
2154  typedef CompressedMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2155 };
2156 
2157 template< typename T1, typename T2 >
2158 struct MultTrait< CompressedVector<T1,true>, CompressedVector<T2,false> >
2159 {
2160  typedef typename MultTrait<T1,T2>::Type Type;
2161 };
2163 //*************************************************************************************************
2164 
2165 
2166 
2167 
2168 //=================================================================================================
2169 //
2170 // CROSSTRAIT SPECIALIZATIONS
2171 //
2172 //=================================================================================================
2173 
2174 //*************************************************************************************************
2176 template< typename T1, typename T2 >
2177 struct CrossTrait< CompressedVector<T1,false>, StaticVector<T2,3UL,false> >
2178 {
2179  private:
2180  typedef typename MultTrait<T1,T2>::Type T;
2181 
2182  public:
2183  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2184 };
2185 
2186 template< typename T1, typename T2 >
2187 struct CrossTrait< StaticVector<T1,3UL,false>, CompressedVector<T2,false> >
2188 {
2189  private:
2190  typedef typename MultTrait<T1,T2>::Type T;
2191 
2192  public:
2193  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2194 };
2195 
2196 template< typename T1, typename T2, size_t N >
2197 struct CrossTrait< CompressedVector<T1,false>, HybridVector<T2,N,false> >
2198 {
2199  private:
2200  typedef typename MultTrait<T1,T2>::Type T;
2201 
2202  public:
2203  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2204 };
2205 
2206 template< typename T1, size_t N, typename T2 >
2207 struct CrossTrait< HybridVector<T1,N,false>, CompressedVector<T2,false> >
2208 {
2209  private:
2210  typedef typename MultTrait<T1,T2>::Type T;
2211 
2212  public:
2213  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2214 };
2215 
2216 template< typename T1, typename T2 >
2217 struct CrossTrait< CompressedVector<T1,false>, DynamicVector<T2,false> >
2218 {
2219  private:
2220  typedef typename MultTrait<T1,T2>::Type T;
2221 
2222  public:
2223  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2224 };
2225 
2226 template< typename T1, typename T2 >
2227 struct CrossTrait< DynamicVector<T1,false>, CompressedVector<T2,false> >
2228 {
2229  private:
2230  typedef typename MultTrait<T1,T2>::Type T;
2231 
2232  public:
2233  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2234 };
2235 
2236 template< typename T1, typename T2 >
2237 struct CrossTrait< CompressedVector<T1,false>, CompressedVector<T2,false> >
2238 {
2239  private:
2240  typedef typename MultTrait<T1,T2>::Type T;
2241 
2242  public:
2243  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2244 };
2246 //*************************************************************************************************
2247 
2248 
2249 
2250 
2251 //=================================================================================================
2252 //
2253 // DIVTRAIT SPECIALIZATIONS
2254 //
2255 //=================================================================================================
2256 
2257 //*************************************************************************************************
2259 template< typename T1, bool TF, typename T2 >
2260 struct DivTrait< CompressedVector<T1,TF>, T2 >
2261 {
2262  typedef CompressedVector< typename DivTrait<T1,T2>::Type, TF > Type;
2264 };
2266 //*************************************************************************************************
2267 
2268 
2269 
2270 
2271 //=================================================================================================
2272 //
2273 // MATHTRAIT SPECIALIZATIONS
2274 //
2275 //=================================================================================================
2276 
2277 //*************************************************************************************************
2279 template< typename T1, bool TF, typename T2 >
2280 struct MathTrait< CompressedVector<T1,TF>, CompressedVector<T2,TF> >
2281 {
2282  typedef CompressedVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2283  typedef CompressedVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2284 };
2286 //*************************************************************************************************
2287 
2288 
2289 
2290 
2291 //=================================================================================================
2292 //
2293 // SUBVECTORTRAIT SPECIALIZATIONS
2294 //
2295 //=================================================================================================
2296 
2297 //*************************************************************************************************
2299 template< typename T1, bool TF >
2300 struct SubvectorTrait< CompressedVector<T1,TF> >
2301 {
2302  typedef CompressedVector<T1,TF> Type;
2303 };
2305 //*************************************************************************************************
2306 
2307 } // namespace blaze
2308 
2309 #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:1555
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:994
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 swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
#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:978
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
void assign(const DenseVector< VT, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: CompressedVector.h:1595
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: CompressedVector.h:1435
ValueIndexPair< Type > ElementBase
Base class for the compressed vector element.
Definition: CompressedVector.h:192
CompressedVector< ET, TF > Other
The type of the other CompressedVector.
Definition: CompressedVector.h:253
CompressedVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedVector.h:238
Access proxy for sparse, N-dimensional vectors.The VectorAccessProxy provides safe access to the elem...
Definition: VectorAccessProxy.h:95
void swap(CompressedVector &sv)
Swapping the contents of two compressed vectors.
Definition: CompressedVector.h:1285
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
VectorAccessProxy< This > Reference
Reference to a non-constant vector value.
Definition: CompressedVector.h:242
const Type & ConstReference
Reference to a constant vector value.
Definition: CompressedVector.h:243
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:1664
Iterator end()
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:660
#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:1025
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:95
Header file for memory allocation and deallocation functionality.
size_t size_
The current size/dimension of the compressed vector.
Definition: CompressedVector.h:386
const CompressedVector & CompositeType
Data type for composite expression templates.
Definition: CompressedVector.h:241
EnableIf< IsBuiltin< T >, T * >::Type allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:151
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2638
size_t extendCapacity() const
Calculating a new vector capacity.
Definition: CompressedVector.h:1305
Header file for the ValueIndexPair class.
Rebind mechanism to obtain a CompressedVector with different data/element type.
Definition: CompressedVector.h:252
Iterator set(size_t index, const Type &value)
Setting an element of the compressed vector.
Definition: CompressedVector.h:1047
void subAssign(const DenseVector< VT, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: CompressedVector.h:1719
void append(size_t index, const Type &value, bool check=false)
Appending an element to the compressed vector.
Definition: CompressedVector.h:1498
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:434
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4754
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CompressedVector.h:1535
Iterator insert(size_t index, const Type &value)
Inserting an element into the compressed vector.
Definition: CompressedVector.h:1077
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Header file for the IsSMPAssignable type trait.
ConstIterator cend() const
Returns an iterator just past the last non-zero element of the compressed vector. ...
Definition: CompressedVector.h:688
Iterator * end_
Pointers one past the last non-zero element of each column.
Definition: CompressedMatrix.h:2640
Iterator begin_
Pointer to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:388
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:947
BLAZE_ALWAYS_INLINE 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:635
EnableIf< IsBuiltin< T > >::Type deallocate(T *address)
Deallocation of memory for built-in data types.
Definition: Memory.h:226
#define BLAZE_CONSTRAINT_MUST_HAVE_SAME_SIZE(T1, T2)
Constraint on the size of two data types.In case the types T1 and T2 don't have the same size...
Definition: SameSize.h:78
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
Header file for the subvector trait.
Constraint on the data type.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedVector.h:240
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:646
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:78
Constraint on the data type.
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: CompressedVector.h:1574
Header file for the EnableIf class template.
size_t capacity_
The maximum capacity of the compressed vector.
Definition: CompressedVector.h:387
This ResultType
Result type for expression template evaluations.
Definition: CompressedVector.h:237
Header file for the serial shim.
void erase(size_t index)
Erasing an element from the compressed vector.
Definition: CompressedVector.h:1142
Reference operator[](size_t index)
Subscript operator for the direct access to the compressed vector elements.
Definition: CompressedVector.h:579
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: CompressedVector.h:1391
Iterator find(size_t index)
Searches for a specific vector element.
Definition: CompressedVector.h:1344
Header file for the IsNumeric type trait.
void reset()
Reset to the default initial values.
Definition: CompressedVector.h:1009
void resize(size_t n, bool preserve=true)
Changing the size of the compressed vector.
Definition: CompressedVector.h:1215
Header file for the IsSparseVector type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:142
Header file for the addition trait.
Header file for the cross product trait.
BLAZE_ALWAYS_INLINE 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:742
Header file for the division trait.
Constraint on the data type.
CompressedVector< Type, TF > This
Type of this CompressedVector instance.
Definition: CompressedVector.h:236
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 move(DynamicMatrix< Type, SO > &dst, DynamicMatrix< Type, SO > &src)
Moving the contents of one dynamic matrix to another.
Definition: DynamicMatrix.h:4769
#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:964
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the VectorAccessProxy class.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedVector.h:245
Header file for the isDefault shim.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedVector.h:244
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Iterator * begin_
Pointers to the first non-zero element of each column.
Definition: CompressedMatrix.h:2639
size_t nonZeros() const
Returns the number of non-zero elements in the compressed vector.
Definition: CompressedVector.h:995
Base template for the DivTrait class.
Definition: DivTrait.h:142
Header file for the mathematical trait.
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
Constraint on the size of two data types.
Header file for the default transpose flag for all vectors of the Blaze library.
~CompressedVector()
The destructor for CompressedVector.
Definition: CompressedVector.h:550
CompressedVector & operator=(const CompressedVector &rhs)
Copy assignment operator for CompressedVector.
Definition: CompressedVector.h:715
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedMatrix.h:2642
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
Iterator end_
Pointer one past the last non-zero element of the compressed vector.
Definition: CompressedVector.h:389
Iterator begin()
Returns an iterator to the first non-zero element of the compressed vector.
Definition: CompressedVector.h:618
Header file for basic type definitions.
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Base template for the SubTrait class.
Definition: SubTrait.h:142
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:239
static const Type zero_
Neutral element for accesses to zero elements.
Definition: CompressedVector.h:391
Header file for the IsResizable type trait.
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:238
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Efficient implementation of an arbitrary sized sparse vector.The CompressedVector class is the repres...
Definition: CompressedVector.h:188
void reserve(size_t n)
Setting the minimum capacity of the compressed vector.
Definition: CompressedVector.h:1240
BLAZE_ALWAYS_INLINE 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:849
Header file for a safe C++ NULL pointer implementation.