All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynamicVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
36 #define _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <stdexcept>
48 #include <blaze/math/Forward.h>
49 #include <blaze/math/Intrinsics.h>
51 #include <blaze/math/shims/Reset.h>
61 #include <blaze/system/CacheSize.h>
62 #include <blaze/system/Restrict.h>
63 #include <blaze/system/Streaming.h>
65 #include <blaze/util/Assert.h>
72 #include <blaze/util/DisableIf.h>
73 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/Memory.h>
75 #include <blaze/util/Null.h>
76 #include <blaze/util/Template.h>
77 #include <blaze/util/Types.h>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS DEFINITION
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
155 template< typename Type // Data type of the vector
156  , bool TF = defaultTransposeFlag > // Transpose flag
157 class DynamicVector : public DenseVector< DynamicVector<Type,TF>, TF >
158 {
159  private:
160  //**Type definitions****************************************************************************
162  //**********************************************************************************************
163 
164  public:
165  //**Type definitions****************************************************************************
167  typedef This ResultType;
169  typedef Type ElementType;
170  typedef typename IT::Type IntrinsicType;
171  typedef const Type& ReturnType;
172  typedef const DynamicVector& CompositeType;
173  typedef Type& Reference;
174  typedef const Type& ConstReference;
177  //**********************************************************************************************
178 
179  //**Compilation flags***************************************************************************
181 
185  enum { vectorizable = IsVectorizable<Type>::value };
186 
188 
191  enum { smpAssignable = 0 };
192  //**********************************************************************************************
193 
194  //**Constructors********************************************************************************
197  explicit inline DynamicVector();
198  explicit inline DynamicVector( size_t n );
199  explicit inline DynamicVector( size_t n, const Type& init );
200  template< typename Other > explicit inline DynamicVector( size_t n, const Other* array );
201 
202  template< typename Other, size_t N >
203  explicit inline DynamicVector( const Other (&array)[N] );
204 
205  inline DynamicVector( const DynamicVector& v );
206  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
208  //**********************************************************************************************
209 
210  //**Destructor**********************************************************************************
213  inline ~DynamicVector();
215  //**********************************************************************************************
216 
217  //**Data access functions***********************************************************************
220  inline Reference operator[]( size_t index );
221  inline ConstReference operator[]( size_t index ) const;
222  inline Type* data ();
223  inline const Type* data () const;
224  inline Iterator begin ();
225  inline ConstIterator begin () const;
226  inline ConstIterator cbegin() const;
227  inline Iterator end ();
228  inline ConstIterator end () const;
229  inline ConstIterator cend () const;
231  //**********************************************************************************************
232 
233  //**Assignment operators************************************************************************
236  template< typename Other, size_t N >
237  inline DynamicVector& operator=( const Other (&array)[N] );
238 
239  inline DynamicVector& operator= ( const Type& rhs );
240  inline DynamicVector& operator= ( const DynamicVector& rhs );
241  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
242  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& rhs );
243  template< typename VT > inline DynamicVector& operator-=( const Vector<VT,TF>& rhs );
244  template< typename VT > inline DynamicVector& operator*=( const Vector<VT,TF>& rhs );
245 
246  template< typename Other >
247  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
248  operator*=( Other rhs );
249 
250  template< typename Other >
251  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
252  operator/=( Other rhs );
254  //**********************************************************************************************
255 
256  //**Utility functions***************************************************************************
259  inline size_t size() const;
260  inline size_t capacity() const;
261  inline size_t nonZeros() const;
262  inline void reset();
263  inline void clear();
264  inline void resize( size_t n, bool preserve=true );
265  inline void extend( size_t n, bool preserve=true );
266  inline void reserve( size_t n );
267  template< typename Other > inline DynamicVector& scale( Other scalar );
268  inline void swap( DynamicVector& v ) /* throw() */;
270  //**********************************************************************************************
271 
272  private:
273  //**********************************************************************************************
275  template< typename VT >
277  struct VectorizedAssign {
278  enum { value = vectorizable && VT::vectorizable &&
279  IsSame<Type,typename VT::ElementType>::value };
280  };
282  //**********************************************************************************************
283 
284  //**********************************************************************************************
286  template< typename VT >
288  struct VectorizedAddAssign {
289  enum { value = vectorizable && VT::vectorizable &&
290  IsSame<Type,typename VT::ElementType>::value &&
291  IntrinsicTrait<Type>::addition };
292  };
294  //**********************************************************************************************
295 
296  //**********************************************************************************************
298  template< typename VT >
300  struct VectorizedSubAssign {
301  enum { value = vectorizable && VT::vectorizable &&
302  IsSame<Type,typename VT::ElementType>::value &&
303  IntrinsicTrait<Type>::subtraction };
304  };
306  //**********************************************************************************************
307 
308  //**********************************************************************************************
310  template< typename VT >
312  struct VectorizedMultAssign {
313  enum { value = vectorizable && VT::vectorizable &&
314  IsSame<Type,typename VT::ElementType>::value &&
315  IntrinsicTrait<Type>::multiplication };
316  };
318  //**********************************************************************************************
319 
320  public:
321  //**Expression template evaluation functions****************************************************
324  template< typename Other > inline bool canAlias ( const Other* alias ) const;
325  template< typename Other > inline bool isAliased( const Other* alias ) const;
326 
327  inline IntrinsicType load ( size_t index ) const;
328  inline IntrinsicType loadu ( size_t index ) const;
329  inline void store ( size_t index, const IntrinsicType& value );
330  inline void storeu( size_t index, const IntrinsicType& value );
331  inline void stream( size_t index, const IntrinsicType& value );
332 
333  template< typename VT >
334  inline typename DisableIf< VectorizedAssign<VT> >::Type
335  assign( const DenseVector<VT,TF>& rhs );
336 
337  template< typename VT >
338  inline typename EnableIf< VectorizedAssign<VT> >::Type
339  assign( const DenseVector<VT,TF>& rhs );
340 
341  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
342 
343  template< typename VT >
344  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
345  addAssign( const DenseVector<VT,TF>& rhs );
346 
347  template< typename VT >
348  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
349  addAssign( const DenseVector<VT,TF>& rhs );
350 
351  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
352 
353  template< typename VT >
354  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
355  subAssign( const DenseVector<VT,TF>& rhs );
356 
357  template< typename VT >
358  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
359  subAssign( const DenseVector<VT,TF>& rhs );
360 
361  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
362 
363  template< typename VT >
364  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
365  multAssign( const DenseVector<VT,TF>& rhs );
366 
367  template< typename VT >
368  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
369  multAssign( const DenseVector<VT,TF>& rhs );
370 
371  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
373  //**********************************************************************************************
374 
375  private:
376  //**Utility functions***************************************************************************
379  inline size_t adjustCapacity( size_t minCapacity ) const;
381  //**********************************************************************************************
382 
383  //**Member variables****************************************************************************
386  size_t size_;
387  size_t capacity_;
389 
395  //**********************************************************************************************
396 
397  //**Compile time checks*************************************************************************
404  //**********************************************************************************************
405 };
406 //*************************************************************************************************
407 
408 
409 
410 
411 //=================================================================================================
412 //
413 // CONSTRUCTORS
414 //
415 //=================================================================================================
416 
417 //*************************************************************************************************
420 template< typename Type // Data type of the vector
421  , bool TF > // Transpose flag
423  : size_ ( 0UL ) // The current size/dimension of the vector
424  , capacity_( 0UL ) // The maximum capacity of the vector
425  , v_ ( NULL ) // The vector elements
426 {}
427 //*************************************************************************************************
428 
429 
430 //*************************************************************************************************
438 template< typename Type // Data type of the vector
439  , bool TF > // Transpose flag
441  : size_ ( n ) // The current size/dimension of the vector
442  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
443  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
444 {
445  if( IsNumeric<Type>::value ) {
446  for( size_t i=size_; i<capacity_; ++i )
447  v_[i] = Type();
448  }
449 }
450 //*************************************************************************************************
451 
452 
453 //*************************************************************************************************
461 template< typename Type // Data type of the vector
462  , bool TF > // Transpose flag
463 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Type& init )
464  : size_ ( n ) // The current size/dimension of the vector
465  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
466  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
467 {
468  for( size_t i=0UL; i<size_; ++i )
469  v_[i] = init;
470 
471  if( IsNumeric<Type>::value ) {
472  for( size_t i=size_; i<capacity_; ++i )
473  v_[i] = Type();
474  }
475 }
476 //*************************************************************************************************
477 
478 
479 //*************************************************************************************************
499 template< typename Type // Data type of the vector
500  , bool TF > // Transpose flag
501 template< typename Other > // Data type of the initialization array
502 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Other* array )
503  : size_ ( n ) // The current size/dimension of the vector
504  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
505  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
506 {
507  for( size_t i=0UL; i<n; ++i )
508  v_[i] = array[i];
509 
510  if( IsNumeric<Type>::value ) {
511  for( size_t i=n; i<capacity_; ++i )
512  v_[i] = Type();
513  }
514 }
515 //*************************************************************************************************
516 
517 
518 //*************************************************************************************************
535 template< typename Type // Data type of the vector
536  , bool TF > // Transpose flag
537 template< typename Other // Data type of the initialization array
538  , size_t N > // Dimension of the initialization array
539 inline DynamicVector<Type,TF>::DynamicVector( const Other (&array)[N] )
540  : size_ ( N ) // The current size/dimension of the vector
541  , capacity_( adjustCapacity( N ) ) // The maximum capacity of the vector
542  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
543 {
544  for( size_t i=0UL; i<N; ++i )
545  v_[i] = array[i];
546 
547  if( IsNumeric<Type>::value ) {
548  for( size_t i=N; i<capacity_; ++i )
549  v_[i] = Type();
550  }
551 }
552 //*************************************************************************************************
553 
554 
555 //*************************************************************************************************
563 template< typename Type // Data type of the vector
564  , bool TF > // Transpose flag
566  : size_ ( v.size_ ) // The current size/dimension of the vector
567  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
568  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
569 {
570  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
571 
572  for( size_t i=0UL; i<capacity_; ++i )
573  v_[i] = v.v_[i];
574 }
575 //*************************************************************************************************
576 
577 
578 //*************************************************************************************************
583 template< typename Type // Data type of the vector
584  , bool TF > // Transpose flag
585 template< typename VT > // Type of the foreign vector
587  : size_ ( (~v).size() ) // The current size/dimension of the vector
588  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
589  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
590 {
591  using blaze::assign;
592 
593  if( IsNumeric<Type>::value ) {
595  reset();
596  for( size_t i=size_; i<capacity_; ++i )
597  v_[i] = Type();
598  }
599 
600  assign( *this, ~v );
601 }
602 //*************************************************************************************************
603 
604 
605 
606 
607 //=================================================================================================
608 //
609 // DESTRUCTOR
610 //
611 //=================================================================================================
612 
613 //*************************************************************************************************
616 template< typename Type // Data type of the vector
617  , bool TF > // Transpose flag
619 {
620  deallocate( v_ );
621 }
622 //*************************************************************************************************
623 
624 
625 
626 
627 //=================================================================================================
628 //
629 // DATA ACCESS FUNCTIONS
630 //
631 //=================================================================================================
632 
633 //*************************************************************************************************
639 template< typename Type // Data type of the vector
640  , bool TF > // Transpose flag
641 inline typename DynamicVector<Type,TF>::Reference
643 {
644  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
645  return v_[index];
646 }
647 //*************************************************************************************************
648 
649 
650 //*************************************************************************************************
656 template< typename Type // Data type of the vector
657  , bool TF > // Transpose flag
660 {
661  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
662  return v_[index];
663 }
664 //*************************************************************************************************
665 
666 
667 //*************************************************************************************************
674 template< typename Type // Data type of the vector
675  , bool TF > // Transpose flag
677 {
678  return v_;
679 }
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
690 template< typename Type // Data type of the vector
691  , bool TF > // Transpose flag
692 inline const Type* DynamicVector<Type,TF>::data() const
693 {
694  return v_;
695 }
696 //*************************************************************************************************
697 
698 
699 //*************************************************************************************************
704 template< typename Type // Data type of the vector
705  , bool TF > // Transpose flag
707 {
708  return Iterator( v_ );
709 }
710 //*************************************************************************************************
711 
712 
713 //*************************************************************************************************
718 template< typename Type // Data type of the vector
719  , bool TF > // Transpose flag
721 {
722  return ConstIterator( v_ );
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
732 template< typename Type // Data type of the vector
733  , bool TF > // Transpose flag
735 {
736  return ConstIterator( v_ );
737 }
738 //*************************************************************************************************
739 
740 
741 //*************************************************************************************************
746 template< typename Type // Data type of the vector
747  , bool TF > // Transpose flag
749 {
750  return Iterator( v_ + size_ );
751 }
752 //*************************************************************************************************
753 
754 
755 //*************************************************************************************************
760 template< typename Type // Data type of the vector
761  , bool TF > // Transpose flag
763 {
764  return ConstIterator( v_ + size_ );
765 }
766 //*************************************************************************************************
767 
768 
769 //*************************************************************************************************
774 template< typename Type // Data type of the vector
775  , bool TF > // Transpose flag
777 {
778  return ConstIterator( v_ + size_ );
779 }
780 //*************************************************************************************************
781 
782 
783 
784 
785 //=================================================================================================
786 //
787 // ASSIGNMENT OPERATORS
788 //
789 //=================================================================================================
790 
791 //*************************************************************************************************
809 template< typename Type // Data type of the vector
810  , bool TF > // Transpose flag
811 template< typename Other // Data type of the initialization array
812  , size_t N > // Dimension of the initialization array
814 {
815  resize( N, false );
816 
817  for( size_t i=0UL; i<N; ++i )
818  v_[i] = array[i];
819 
820  return *this;
821 }
822 //*************************************************************************************************
823 
824 
825 //*************************************************************************************************
831 template< typename Type // Data type of the vector
832  , bool TF > // Transpose flag
834 {
835  for( size_t i=0UL; i<size_; ++i )
836  v_[i] = rhs;
837  return *this;
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
851 template< typename Type // Data type of the vector
852  , bool TF > // Transpose flag
854 {
855  if( &rhs == this ) return *this;
856 
857  resize( rhs.size_, false );
858 
859  for( size_t i=0UL; i<size_; ++i )
860  v_[i] = rhs.v_[i];
861 
862  return *this;
863 }
864 //*************************************************************************************************
865 
866 
867 //*************************************************************************************************
875 template< typename Type // Data type of the vector
876  , bool TF > // Transpose flag
877 template< typename VT > // Type of the right-hand side vector
879 {
880  using blaze::assign;
881 
882  if( (~rhs).canAlias( this ) ) {
883  DynamicVector tmp( ~rhs );
884  swap( tmp );
885  }
886  else {
887  resize( (~rhs).size(), false );
889  reset();
890  assign( *this, ~rhs );
891  }
892 
893  return *this;
894 }
895 //*************************************************************************************************
896 
897 
898 //*************************************************************************************************
908 template< typename Type // Data type of the vector
909  , bool TF > // Transpose flag
910 template< typename VT > // Type of the right-hand side vector
912 {
913  using blaze::addAssign;
914 
915  if( (~rhs).size() != size_ )
916  throw std::invalid_argument( "Vector sizes do not match" );
917 
918  if( (~rhs).canAlias( this ) ) {
919  typename VT::ResultType tmp( ~rhs );
920  addAssign( *this, tmp );
921  }
922  else {
923  addAssign( *this, ~rhs );
924  }
925 
926  return *this;
927 }
928 //*************************************************************************************************
929 
930 
931 //*************************************************************************************************
942 template< typename Type // Data type of the vector
943  , bool TF > // Transpose flag
944 template< typename VT > // Type of the right-hand side vector
946 {
947  using blaze::subAssign;
948 
949  if( (~rhs).size() != size_ )
950  throw std::invalid_argument( "Vector sizes do not match" );
951 
952  if( (~rhs).canAlias( this ) ) {
953  typename VT::ResultType tmp( ~rhs );
954  subAssign( *this, tmp );
955  }
956  else {
957  subAssign( *this, ~rhs );
958  }
959 
960  return *this;
961 }
962 //*************************************************************************************************
963 
964 
965 //*************************************************************************************************
976 template< typename Type // Data type of the vector
977  , bool TF > // Transpose flag
978 template< typename VT > // Type of the right-hand side vector
980 {
981  using blaze::assign;
982 
983  if( (~rhs).size() != size_ )
984  throw std::invalid_argument( "Vector sizes do not match" );
985 
986  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
987  DynamicVector<Type,TF> tmp( *this * (~rhs) );
988  swap( tmp );
989  }
990  else {
991  assign( *this, *this * (~rhs) );
992  }
993 
994  return *this;
995 }
996 //*************************************************************************************************
997 
998 
999 //*************************************************************************************************
1006 template< typename Type // Data type of the vector
1007  , bool TF > // Transpose flag
1008 template< typename Other > // Data type of the right-hand side scalar
1009 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
1011 {
1012  using blaze::assign;
1013 
1014  assign( *this, (*this) * rhs );
1015  return *this;
1016 }
1017 //*************************************************************************************************
1018 
1019 
1020 //*************************************************************************************************
1029 template< typename Type // Data type of the vector
1030  , bool TF > // Transpose flag
1031 template< typename Other > // Data type of the right-hand side scalar
1032 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
1034 {
1035  using blaze::assign;
1036 
1037  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1038 
1039  assign( *this, (*this) / rhs );
1040  return *this;
1041 }
1042 //*************************************************************************************************
1043 
1044 
1045 
1046 
1047 //=================================================================================================
1048 //
1049 // UTILITY FUNCTIONS
1050 //
1051 //=================================================================================================
1052 
1053 //*************************************************************************************************
1058 template< typename Type // Data type of the vector
1059  , bool TF > // Transpose flag
1060 inline size_t DynamicVector<Type,TF>::size() const
1061 {
1062  return size_;
1063 }
1064 //*************************************************************************************************
1065 
1066 
1067 //*************************************************************************************************
1072 template< typename Type // Data type of the vector
1073  , bool TF > // Transpose flag
1075 {
1076  return capacity_;
1077 }
1078 //*************************************************************************************************
1079 
1080 
1081 //*************************************************************************************************
1089 template< typename Type // Data type of the vector
1090  , bool TF > // Transpose flag
1092 {
1093  size_t nonzeros( 0 );
1094 
1095  for( size_t i=0UL; i<size_; ++i ) {
1096  if( !isDefault( v_[i] ) )
1097  ++nonzeros;
1098  }
1099 
1100  return nonzeros;
1101 }
1102 //*************************************************************************************************
1103 
1104 
1105 //*************************************************************************************************
1110 template< typename Type // Data type of the vector
1111  , bool TF > // Transpose flag
1113 {
1114  using blaze::reset;
1115  for( size_t i=0UL; i<size_; ++i )
1116  reset( v_[i] );
1117 }
1118 //*************************************************************************************************
1119 
1120 
1121 //*************************************************************************************************
1128 template< typename Type // Data type of the vector
1129  , bool TF > // Transpose flag
1131 {
1132  resize( 0UL, false );
1133 }
1134 //*************************************************************************************************
1135 
1136 
1137 //*************************************************************************************************
1164 template< typename Type // Data type of the vector
1165  , bool TF > // Transpose flag
1166 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1167 {
1168  if( n > capacity_ )
1169  {
1170  // Allocating a new array
1171  const size_t newCapacity( adjustCapacity( n ) );
1172  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1173 
1174  // Initializing the new array
1175  if( preserve ) {
1176  std::copy( v_, v_+size_, tmp );
1177  }
1178 
1179  if( IsNumeric<Type>::value ) {
1180  for( size_t i=size_; i<newCapacity; ++i )
1181  tmp[i] = Type();
1182  }
1183 
1184  // Replacing the old array
1185  std::swap( v_, tmp );
1186  deallocate( tmp );
1187  capacity_ = newCapacity;
1188  }
1189  else if( IsNumeric<Type>::value && n < size_ )
1190  {
1191  for( size_t i=n; i<size_; ++i )
1192  v_[i] = Type();
1193  }
1194 
1195  size_ = n;
1196 }
1197 //*************************************************************************************************
1198 
1199 
1200 //*************************************************************************************************
1212 template< typename Type // Data type of the vector
1213  , bool TF > // Transpose flag
1214 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1215 {
1216  resize( size_+n, preserve );
1217 }
1218 //*************************************************************************************************
1219 
1220 
1221 //*************************************************************************************************
1230 template< typename Type // Data type of the vector
1231  , bool TF > // Transpose flag
1232 inline void DynamicVector<Type,TF>::reserve( size_t n )
1233 {
1234  if( n > capacity_ )
1235  {
1236  // Allocating a new array
1237  const size_t newCapacity( adjustCapacity( n ) );
1238  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1239 
1240  // Initializing the new array
1241  std::copy( v_, v_+size_, tmp );
1242 
1243  if( IsNumeric<Type>::value ) {
1244  for( size_t i=size_; i<newCapacity; ++i )
1245  tmp[i] = Type();
1246  }
1247 
1248  // Replacing the old array
1249  std::swap( tmp, v_ );
1250  deallocate( tmp );
1251  capacity_ = newCapacity;
1252  }
1253 }
1254 //*************************************************************************************************
1255 
1256 
1257 //*************************************************************************************************
1263 template< typename Type // Data type of the vector
1264  , bool TF > // Transpose flag
1265 template< typename Other > // Data type of the scalar value
1267 {
1268  for( size_t i=0UL; i<size_; ++i )
1269  v_[i] *= scalar;
1270  return *this;
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1282 template< typename Type // Data type of the vector
1283  , bool TF > // Transpose flag
1284 inline void DynamicVector<Type,TF>::swap( DynamicVector& v ) /* throw() */
1285 {
1286  std::swap( size_, v.size_ );
1288  std::swap( v_, v.v_ );
1289 }
1290 //*************************************************************************************************
1291 
1292 
1293 //*************************************************************************************************
1299 template< typename Type // Data type of the vector
1300  , bool TF > // Transpose flag
1301 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const
1302 {
1304  return minCapacity + ( IT::size - ( minCapacity % IT::size ) ) % IT::size;
1305  else return minCapacity;
1306 }
1307 //*************************************************************************************************
1308 
1309 
1310 
1311 
1312 //=================================================================================================
1313 //
1314 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1315 //
1316 //=================================================================================================
1317 
1318 //*************************************************************************************************
1328 template< typename Type // Data type of the vector
1329  , bool TF > // Transpose flag
1330 template< typename Other > // Data type of the foreign expression
1331 inline bool DynamicVector<Type,TF>::canAlias( const Other* alias ) const
1332 {
1333  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1334 }
1335 //*************************************************************************************************
1336 
1337 
1338 //*************************************************************************************************
1348 template< typename Type // Data type of the vector
1349  , bool TF > // Transpose flag
1350 template< typename Other > // Data type of the foreign expression
1351 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const
1352 {
1353  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1354 }
1355 //*************************************************************************************************
1356 
1357 
1358 //*************************************************************************************************
1371 template< typename Type // Data type of the vector
1372  , bool TF > // Transpose flag
1374  DynamicVector<Type,TF>::load( size_t index ) const
1375 {
1376  using blaze::load;
1377 
1379 
1380  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1381  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1382  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1383 
1384  return load( v_+index );
1385 }
1386 //*************************************************************************************************
1387 
1388 
1389 //*************************************************************************************************
1402 template< typename Type // Data type of the vector
1403  , bool TF > // Transpose flag
1405  DynamicVector<Type,TF>::loadu( size_t index ) const
1406 {
1407  using blaze::loadu;
1408 
1410 
1411  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1412  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1413 
1414  return loadu( v_+index );
1415 }
1416 //*************************************************************************************************
1417 
1418 
1419 //*************************************************************************************************
1433 template< typename Type // Data type of the vector
1434  , bool TF > // Transpose flag
1435 inline void DynamicVector<Type,TF>::store( size_t index, const IntrinsicType& value )
1436 {
1437  using blaze::store;
1438 
1440 
1441  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1442  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1443  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1444 
1445  store( v_+index, value );
1446 }
1447 //*************************************************************************************************
1448 
1449 
1450 //*************************************************************************************************
1464 template< typename Type // Data type of the vector
1465  , bool TF > // Transpose flag
1466 inline void DynamicVector<Type,TF>::storeu( size_t index, const IntrinsicType& value )
1467 {
1468  using blaze::storeu;
1469 
1471 
1472  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1473  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1474 
1475  storeu( v_+index, value );
1476 }
1477 //*************************************************************************************************
1478 
1479 
1480 //*************************************************************************************************
1494 template< typename Type // Data type of the vector
1495  , bool TF > // Transpose flag
1496 inline void DynamicVector<Type,TF>::stream( size_t index, const IntrinsicType& value )
1497 {
1498  using blaze::stream;
1499 
1501 
1502  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1503  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1504  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1505 
1506  stream( v_+index, value );
1507 }
1508 //*************************************************************************************************
1509 
1510 
1511 //*************************************************************************************************
1522 template< typename Type // Data type of the vector
1523  , bool TF > // Transpose flag
1524 template< typename VT > // Type of the right-hand side dense vector
1525 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1527 {
1528  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1529 
1530  const size_t iend( (~rhs).size() & size_t(-2) );
1531  for( size_t i=0UL; i<iend; i+=2UL ) {
1532  v_[i ] = (~rhs)[i ];
1533  v_[i+1UL] = (~rhs)[i+1UL];
1534  }
1535  if( iend < (~rhs).size() )
1536  v_[iend] = (~rhs)[iend];
1537 }
1538 //*************************************************************************************************
1539 
1540 
1541 //*************************************************************************************************
1552 template< typename Type // Data type of the vector
1553  , bool TF > // Transpose flag
1554 template< typename VT > // Type of the right-hand side dense vector
1555 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1557 {
1558  using blaze::store;
1559  using blaze::stream;
1560 
1561  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1562 
1564 
1565  if( useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1566  {
1567  for( size_t i=0UL; i<size_; i+=IT::size ) {
1568  stream( v_+i, (~rhs).load(i) );
1569  }
1570  }
1571  else
1572  {
1573  const size_t iend( size_ & size_t(-IT::size*4) );
1574  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1575 
1576  typename VT::ConstIterator it( (~rhs).begin() );
1577  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1578  store( v_+i , it.load() ); it += IT::size;
1579  store( v_+i+IT::size , it.load() ); it += IT::size;
1580  store( v_+i+IT::size*2UL, it.load() ); it += IT::size;
1581  store( v_+i+IT::size*3UL, it.load() ); it += IT::size;
1582  }
1583  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1584  store( v_+i, it.load() );
1585  }
1586  }
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  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1610  v_[element->index()] = element->value();
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
1629 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1631 {
1632  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1633 
1634  const size_t iend( (~rhs).size() & size_t(-2) );
1635  for( size_t i=0UL; i<iend; i+=2UL ) {
1636  v_[i ] += (~rhs)[i ];
1637  v_[i+1UL] += (~rhs)[i+1UL];
1638  }
1639  if( iend < (~rhs).size() )
1640  v_[iend] += (~rhs)[iend];
1641 }
1642 //*************************************************************************************************
1643 
1644 
1645 //*************************************************************************************************
1656 template< typename Type // Data type of the vector
1657  , bool TF > // Transpose flag
1658 template< typename VT > // Type of the right-hand side dense vector
1659 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1661 {
1662  using blaze::load;
1663  using blaze::store;
1664 
1665  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1666 
1668 
1669  const size_t iend( size_ & size_t(-IT::size*4) );
1670  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1671 
1672  typename VT::ConstIterator it( (~rhs).begin() );
1673  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1674  store( v_+i , load(v_+i ) + it.load() ); it += IT::size;
1675  store( v_+i+IT::size , load(v_+i+IT::size ) + it.load() ); it += IT::size;
1676  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) + it.load() ); it += IT::size;
1677  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) + it.load() ); it += IT::size;
1678  }
1679  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1680  store( v_+i, load(v_+i) + it.load() );
1681  }
1682 }
1683 //*************************************************************************************************
1684 
1685 
1686 //*************************************************************************************************
1697 template< typename Type // Data type of the vector
1698  , bool TF > // Transpose flag
1699 template< typename VT > // Type of the right-hand side sparse vector
1701 {
1702  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1703 
1704  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1705  v_[element->index()] += element->value();
1706 }
1707 //*************************************************************************************************
1708 
1709 
1710 //*************************************************************************************************
1721 template< typename Type // Data type of the vector
1722  , bool TF > // Transpose flag
1723 template< typename VT > // Type of the right-hand side dense vector
1724 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1726 {
1727  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1728 
1729  const size_t iend( (~rhs).size() & size_t(-2) );
1730  for( size_t i=0UL; i<iend; i+=2UL ) {
1731  v_[i ] -= (~rhs)[i ];
1732  v_[i+1UL] -= (~rhs)[i+1UL];
1733  }
1734  if( iend < (~rhs).size() )
1735  v_[iend] -= (~rhs)[iend];
1736 }
1737 //*************************************************************************************************
1738 
1739 
1740 //*************************************************************************************************
1751 template< typename Type // Data type of the vector
1752  , bool TF > // Transpose flag
1753 template< typename VT > // Type of the right-hand side dense vector
1754 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1756 {
1757  using blaze::load;
1758  using blaze::store;
1759 
1760  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1761 
1763 
1764  const size_t iend( size_ & size_t(-IT::size*4) );
1765  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1766 
1767  typename VT::ConstIterator it( (~rhs).begin() );
1768  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1769  store( v_+i , load(v_+i ) - it.load() ); it += IT::size;
1770  store( v_+i+IT::size , load(v_+i+IT::size ) - it.load() ); it += IT::size;
1771  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) - it.load() ); it += IT::size;
1772  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) - it.load() ); it += IT::size;
1773  }
1774  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1775  store( v_+i, load(v_+i) - it.load() );
1776  }
1777 }
1778 //*************************************************************************************************
1779 
1780 
1781 //*************************************************************************************************
1792 template< typename Type // Data type of the vector
1793  , bool TF > // Transpose flag
1794 template< typename VT > // Type of the right-hand side sparse vector
1796 {
1797  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1798 
1799  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1800  v_[element->index()] -= element->value();
1801 }
1802 //*************************************************************************************************
1803 
1804 
1805 //*************************************************************************************************
1816 template< typename Type // Data type of the vector
1817  , bool TF > // Transpose flag
1818 template< typename VT > // Type of the right-hand side dense vector
1819 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1821 {
1822  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1823 
1824  const size_t iend( (~rhs).size() & size_t(-2) );
1825  for( size_t i=0UL; i<iend; i+=2UL ) {
1826  v_[i ] *= (~rhs)[i ];
1827  v_[i+1UL] *= (~rhs)[i+1UL];
1828  }
1829  if( iend < (~rhs).size() )
1830  v_[iend] *= (~rhs)[iend];
1831 }
1832 //*************************************************************************************************
1833 
1834 
1835 //*************************************************************************************************
1846 template< typename Type // Data type of the vector
1847  , bool TF > // Transpose flag
1848 template< typename VT > // Type of the right-hand side dense vector
1849 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1851 {
1852  using blaze::load;
1853  using blaze::store;
1854 
1855  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1856 
1858 
1859  const size_t iend( size_ & size_t(-IT::size*4) );
1860  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1861 
1862  typename VT::ConstIterator it( (~rhs).begin() );
1863  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1864  store( v_+i , load(v_+i ) * it.load() ); it += IT::size;
1865  store( v_+i+IT::size , load(v_+i+IT::size ) * it.load() ); it += IT::size;
1866  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) * it.load() ); it += IT::size;
1867  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) * it.load() ); it += IT::size;
1868  }
1869  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1870  store( v_+i, load(v_+i) * it.load() );
1871  }
1872 }
1873 //*************************************************************************************************
1874 
1875 
1876 //*************************************************************************************************
1887 template< typename Type // Data type of the vector
1888  , bool TF > // Transpose flag
1889 template< typename VT > // Type of the right-hand side sparse vector
1891 {
1892  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1893 
1894  const DynamicVector tmp( *this );
1895 
1896  reset();
1897 
1898  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1899  v_[element->index()] = tmp[element->index()] * element->value();
1900 }
1901 //*************************************************************************************************
1902 
1903 
1904 
1905 
1906 //=================================================================================================
1907 //
1908 // DYNAMICVECTOR OPERATORS
1909 //
1910 //=================================================================================================
1911 
1912 //*************************************************************************************************
1915 template< typename Type, bool TF >
1916 inline void reset( DynamicVector<Type,TF>& v );
1917 
1918 template< typename Type, bool TF >
1919 inline void clear( DynamicVector<Type,TF>& v );
1920 
1921 template< typename Type, bool TF >
1922 inline bool isDefault( const DynamicVector<Type,TF>& v );
1923 
1924 template< typename Type, bool TF >
1925 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */;
1927 //*************************************************************************************************
1928 
1929 
1930 //*************************************************************************************************
1937 template< typename Type // Data type of the vector
1938  , bool TF > // Transpose flag
1940 {
1941  v.reset();
1942 }
1943 //*************************************************************************************************
1944 
1945 
1946 //*************************************************************************************************
1953 template< typename Type // Data type of the vector
1954  , bool TF > // Transpose flag
1956 {
1957  v.clear();
1958 }
1959 //*************************************************************************************************
1960 
1961 
1962 //*************************************************************************************************
1981 template< typename Type // Data type of the vector
1982  , bool TF > // Transpose flag
1983 inline bool isDefault( const DynamicVector<Type,TF>& v )
1984 {
1985  for( size_t i=0UL; i<v.size(); ++i )
1986  if( !isDefault( v[i] ) ) return false;
1987  return true;
1988 }
1989 //*************************************************************************************************
1990 
1991 
1992 //*************************************************************************************************
2001 template< typename Type // Data type of the vector
2002  , bool TF > // Transpose flag
2003 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */
2004 {
2005  a.swap( b );
2006 }
2007 //*************************************************************************************************
2008 
2009 
2010 
2011 
2012 //=================================================================================================
2013 //
2014 // ISRESIZABLE SPECIALIZATIONS
2015 //
2016 //=================================================================================================
2017 
2018 //*************************************************************************************************
2020 template< typename T, bool TF >
2021 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2022 {
2023  enum { value = 1 };
2024  typedef TrueType Type;
2025 };
2026 
2027 template< typename T, bool TF >
2028 struct IsResizable< const DynamicVector<T,TF> > : public TrueType
2029 {
2030  enum { value = 1 };
2031  typedef TrueType Type;
2032 };
2033 
2034 template< typename T, bool TF >
2035 struct IsResizable< volatile DynamicVector<T,TF> > : public TrueType
2036 {
2037  enum { value = 1 };
2038  typedef TrueType Type;
2039 };
2040 
2041 template< typename T, bool TF >
2042 struct IsResizable< const volatile DynamicVector<T,TF> > : public TrueType
2043 {
2044  enum { value = 1 };
2045  typedef TrueType Type;
2046 };
2048 //*************************************************************************************************
2049 
2050 
2051 
2052 
2053 //=================================================================================================
2054 //
2055 // ADDTRAIT SPECIALIZATIONS
2056 //
2057 //=================================================================================================
2058 
2059 //*************************************************************************************************
2061 template< typename T1, bool TF, typename T2, size_t N >
2062 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2063 {
2064  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2065 };
2066 
2067 template< typename T1, size_t N, bool TF, typename T2 >
2068 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2069 {
2070  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2071 };
2072 
2073 template< typename T1, bool TF, typename T2, size_t N >
2074 struct AddTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2075 {
2076  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2077 };
2078 
2079 template< typename T1, size_t N, bool TF, typename T2 >
2080 struct AddTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2081 {
2082  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2083 };
2084 
2085 template< typename T1, bool TF, typename T2 >
2086 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2087 {
2088  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2089 };
2091 //*************************************************************************************************
2092 
2093 
2094 
2095 
2096 //=================================================================================================
2097 //
2098 // SUBTRAIT SPECIALIZATIONS
2099 //
2100 //=================================================================================================
2101 
2102 //*************************************************************************************************
2104 template< typename T1, bool TF, typename T2, size_t N >
2105 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2106 {
2107  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2108 };
2109 
2110 template< typename T1, size_t N, bool TF, typename T2 >
2111 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2112 {
2113  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2114 };
2115 
2116 template< typename T1, bool TF, typename T2, size_t N >
2117 struct SubTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2118 {
2119  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2120 };
2121 
2122 template< typename T1, size_t N, bool TF, typename T2 >
2123 struct SubTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2124 {
2125  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2126 };
2127 
2128 template< typename T1, bool TF, typename T2 >
2129 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2130 {
2131  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2132 };
2134 //*************************************************************************************************
2135 
2136 
2137 
2138 
2139 //=================================================================================================
2140 //
2141 // MULTTRAIT SPECIALIZATIONS
2142 //
2143 //=================================================================================================
2144 
2145 //*************************************************************************************************
2147 template< typename T1, bool TF, typename T2 >
2148 struct MultTrait< DynamicVector<T1,TF>, T2 >
2149 {
2150  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2152 };
2153 
2154 template< typename T1, typename T2, bool TF >
2155 struct MultTrait< T1, DynamicVector<T2,TF> >
2156 {
2157  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2159 };
2160 
2161 template< typename T1, bool TF, typename T2, size_t N >
2162 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2163 {
2164  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2165 };
2166 
2167 template< typename T1, typename T2, size_t N >
2168 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2169 {
2170  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2171 };
2172 
2173 template< typename T1, typename T2, size_t N >
2174 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2175 {
2176  typedef typename MultTrait<T1,T2>::Type Type;
2177 };
2178 
2179 template< typename T1, size_t N, bool TF, typename T2 >
2180 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2181 {
2182  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2183 };
2184 
2185 template< typename T1, size_t N, typename T2 >
2186 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2187 {
2188  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2189 };
2190 
2191 template< typename T1, size_t N, typename T2 >
2192 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2193 {
2194  typedef typename MultTrait<T1,T2>::Type Type;
2195 };
2196 
2197 template< typename T1, bool TF, typename T2, size_t N >
2198 struct MultTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2199 {
2200  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2201 };
2202 
2203 template< typename T1, typename T2, size_t N >
2204 struct MultTrait< DynamicVector<T1,false>, HybridVector<T2,N,true> >
2205 {
2206  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2207 };
2208 
2209 template< typename T1, typename T2, size_t N >
2210 struct MultTrait< DynamicVector<T1,true>, HybridVector<T2,N,false> >
2211 {
2212  typedef typename MultTrait<T1,T2>::Type Type;
2213 };
2214 
2215 template< typename T1, size_t N, bool TF, typename T2 >
2216 struct MultTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2217 {
2218  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2219 };
2220 
2221 template< typename T1, size_t N, typename T2 >
2222 struct MultTrait< HybridVector<T1,N,false>, DynamicVector<T2,true> >
2223 {
2224  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2225 };
2226 
2227 template< typename T1, size_t N, typename T2 >
2228 struct MultTrait< HybridVector<T1,N,true>, DynamicVector<T2,false> >
2229 {
2230  typedef typename MultTrait<T1,T2>::Type Type;
2231 };
2232 
2233 template< typename T1, bool TF, typename T2 >
2234 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2235 {
2236  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2237 };
2238 
2239 template< typename T1, typename T2 >
2240 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2241 {
2242  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2243 };
2244 
2245 template< typename T1, typename T2 >
2246 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2247 {
2248  typedef typename MultTrait<T1,T2>::Type Type;
2249 };
2251 //*************************************************************************************************
2252 
2253 
2254 
2255 
2256 //=================================================================================================
2257 //
2258 // CROSSTRAIT SPECIALIZATIONS
2259 //
2260 //=================================================================================================
2261 
2262 //*************************************************************************************************
2264 template< typename T1, typename T2 >
2265 struct CrossTrait< DynamicVector<T1,false>, StaticVector<T2,3UL,false> >
2266 {
2267  private:
2268  typedef typename MultTrait<T1,T2>::Type T;
2269 
2270  public:
2271  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2272 };
2273 
2274 template< typename T1, typename T2 >
2275 struct CrossTrait< StaticVector<T1,3UL,false>, DynamicVector<T2,false> >
2276 {
2277  private:
2278  typedef typename MultTrait<T1,T2>::Type T;
2279 
2280  public:
2281  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2282 };
2283 
2284 template< typename T1, typename T2, size_t N >
2285 struct CrossTrait< DynamicVector<T1,false>, HybridVector<T2,N,false> >
2286 {
2287  private:
2288  typedef typename MultTrait<T1,T2>::Type T;
2289 
2290  public:
2291  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2292 };
2293 
2294 template< typename T1, size_t N, typename T2 >
2295 struct CrossTrait< HybridVector<T1,N,false>, DynamicVector<T2,false> >
2296 {
2297  private:
2298  typedef typename MultTrait<T1,T2>::Type T;
2299 
2300  public:
2301  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2302 };
2303 
2304 template< typename T1, typename T2 >
2305 struct CrossTrait< DynamicVector<T1,false>, DynamicVector<T2,false> >
2306 {
2307  private:
2308  typedef typename MultTrait<T1,T2>::Type T;
2309 
2310  public:
2311  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2312 };
2314 //*************************************************************************************************
2315 
2316 
2317 
2318 
2319 //=================================================================================================
2320 //
2321 // DIVTRAIT SPECIALIZATIONS
2322 //
2323 //=================================================================================================
2324 
2325 //*************************************************************************************************
2327 template< typename T1, bool TF, typename T2 >
2328 struct DivTrait< DynamicVector<T1,TF>, T2 >
2329 {
2330  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
2332 };
2334 //*************************************************************************************************
2335 
2336 
2337 
2338 
2339 //=================================================================================================
2340 //
2341 // MATHTRAIT SPECIALIZATIONS
2342 //
2343 //=================================================================================================
2344 
2345 //*************************************************************************************************
2347 template< typename T1, bool TF, typename T2 >
2348 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2349 {
2350  typedef DynamicVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2351  typedef DynamicVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2352 };
2354 //*************************************************************************************************
2355 
2356 
2357 
2358 
2359 //=================================================================================================
2360 //
2361 // SUBVECTORTRAIT SPECIALIZATIONS
2362 //
2363 //=================================================================================================
2364 
2365 //*************************************************************************************************
2367 template< typename T1, bool TF >
2368 struct SubvectorTrait< DynamicVector<T1,TF> >
2369 {
2370  typedef DynamicVector<T1,TF> Type;
2371 };
2373 //*************************************************************************************************
2374 
2375 } // namespace blaze
2376 
2377 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:107
Constraint on the data type.
#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
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
Type *BLAZE_RESTRICT v_
The dynamically allocated vector elements.
Definition: DynamicVector.h:388
Constraint on the data type.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4512
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
Header file for the subtraction trait.
Header file for the SparseVector base class.
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: DynamicVector.h:1091
void swap(DynamicVector &v)
Swapping the contents of two vectors.
Definition: DynamicVector.h:1284
Iterator begin()
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:706
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:113
void clear()
Clearing the vector.
Definition: DynamicVector.h:1130
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4555
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DynamicVector.h:170
EnableIf< IsIntegral< T >, Loadu< T, sizeof(T)> >::Type::Type loadu(const T *address)
Loads a vector of integral values.
Definition: Loadu.h:219
Header file for the IsSame and IsStrictlySame type traits.
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
const bool useStreaming
Configuration of the streaming behavior.For large vectors and matrices non-temporal stores can provid...
Definition: Streaming.h:50
void storeu(float *address, const sse_float_t &value)
Unaligned store of a vector of &#39;float&#39; values.
Definition: Storeu.h:234
Header file for a safe C++ NULL pointer implementation.
Header file for the DenseVector base class.
#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
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:157
Header file for memory allocation and deallocation functionality.
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: DynamicVector.h:1435
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4528
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2513
~DynamicVector()
The destructor for DynamicVector.
Definition: DynamicVector.h:618
ConstIterator cbegin() const
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:734
void stream(float *address, const sse_float_t &value)
Aligned, non-temporal store of a vector of &#39;float&#39; values.
Definition: Stream.h:233
Header file for the DisableIf class template.
This ResultType
Result type for expression template evaluations.
Definition: DynamicVector.h:167
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: DynamicVector.h:1166
Header file for the multiplication trait.
Header file for nested template disabiguation.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4541
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the dense vector.
Definition: DynamicVector.h:1466
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2379
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicVector.h:171
#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 DenseIterator class template.
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.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Compile time check for sparse vector types.This type trait tests whether or not the given template pa...
Definition: IsSparseVector.h:103
void reset()
Reset to the default initial values.
Definition: DynamicVector.h:1112
size_t size() const
Returns the current size/dimension of the vector.
Definition: DynamicVector.h:1060
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: DynamicVector.h:175
size_t size_
The current size/dimension of the vector.
Definition: DynamicVector.h:386
#define BLAZE_RESTRICT
Platform dependent setup of the restrict keyword.
Definition: Restrict.h:81
Type & Reference
Reference to a non-constant vector value.
Definition: DynamicVector.h:173
#define BLAZE_CONSTRAINT_MUST_BE_VECTORIZABLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a vectorizable data type...
Definition: Vectorizable.h:79
const Type & ConstReference
Reference to a constant vector value.
Definition: DynamicVector.h:174
size_t adjustCapacity(size_t minCapacity) const
Adjusting the new capacity of the vector according to its data type Type.
Definition: DynamicVector.h:1301
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1374
System settings for streaming (non-temporal stores)
DynamicVector()
The default constructor for DynamicVector.
Definition: DynamicVector.h:422
Header file for the EnableIf class template.
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:85
Header file for the IsVectorizable type trait.
ColumnIterator< const MT > ConstIterator
Iterator over constant elements.
Definition: DenseColumn.h:1972
Header file for the IsNumeric type trait.
size_t capacity_
The maximum capacity of the vector.
Definition: DynamicVector.h:387
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DynamicVector.h:1351
Header file for the IsSparseVector type trait.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:648
ConstIterator cend() const
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:776
Header file for run time assertion macros.
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4584
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: DynamicVector.h:161
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.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
const DynamicVector & CompositeType
Data type for composite expression templates.
Definition: DynamicVector.h:172
#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 extend(size_t n, bool preserve=true)
Extending the size of the vector.
Definition: DynamicVector.h:1214
Header file for the reset shim.
Header file for the cache size of the target architecture.
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
#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
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2378
Header file for the isDefault shim.
System settings for the restrict keyword.
Type ElementType
Type of the vector elements.
Definition: DynamicVector.h:169
Type * data()
Low-level data access to the vector elements.
Definition: DynamicVector.h:676
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: DynamicVector.h:1074
Constraint on the data type.
void reserve(size_t n)
Setting the minimum capacity of the vector.
Definition: DynamicVector.h:1232
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the dense vector.
Definition: DynamicVector.h:1496
Header file for all intrinsic functionality.
Header file for the mathematical trait.
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: DynamicVector.h:1331
Header file for the default transpose flag for all vectors of the Blaze library.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2370
Header file for basic type definitions.
SelectType< useConst, ConstIterator, ColumnIterator< MT > >::Type Iterator
Iterator over non-constant elements.
Definition: DenseColumn.h:1980
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1405
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
Iterator end()
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:748
const size_t cacheSize
Cache size of the target architecture.This setting specifies the available cache size in Byte of the ...
Definition: CacheSize.h:48
Header file for the IsResizable type trait.
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: DynamicVector.h:176
#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
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: DynamicVector.h:642
void store(float *address, const sse_float_t &value)
Aligned store of a vector of &#39;float&#39; values.
Definition: Store.h:242
DynamicVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: DynamicVector.h:168
DynamicVector< Type, TF > This
Type of this DynamicVector instance.
Definition: DynamicVector.h:166