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>
63 #include <blaze/system/CacheSize.h>
64 #include <blaze/system/Restrict.h>
65 #include <blaze/system/Streaming.h>
68 #include <blaze/util/Assert.h>
75 #include <blaze/util/DisableIf.h>
76 #include <blaze/util/EnableIf.h>
77 #include <blaze/util/Memory.h>
78 #include <blaze/util/Null.h>
79 #include <blaze/util/Template.h>
80 #include <blaze/util/Types.h>
84 
85 
86 namespace blaze {
87 
88 //=================================================================================================
89 //
90 // CLASS DEFINITION
91 //
92 //=================================================================================================
93 
94 //*************************************************************************************************
158 template< typename Type // Data type of the vector
159  , bool TF = defaultTransposeFlag > // Transpose flag
160 class DynamicVector : public DenseVector< DynamicVector<Type,TF>, TF >
161 {
162  private:
163  //**Type definitions****************************************************************************
165  //**********************************************************************************************
166 
167  public:
168  //**Type definitions****************************************************************************
170  typedef This ResultType;
172  typedef Type ElementType;
173  typedef typename IT::Type IntrinsicType;
174  typedef const Type& ReturnType;
175  typedef const DynamicVector& CompositeType;
176  typedef Type& Reference;
177  typedef const Type& ConstReference;
178  typedef Type* Pointer;
179  typedef const Type* ConstPointer;
182  //**********************************************************************************************
183 
184  //**Compilation flags***************************************************************************
186 
190  enum { vectorizable = IsVectorizable<Type>::value };
191 
193 
196  enum { smpAssignable = !IsSMPAssignable<Type>::value };
197  //**********************************************************************************************
198 
199  //**Constructors********************************************************************************
202  explicit inline DynamicVector();
203  explicit inline DynamicVector( size_t n );
204  explicit inline DynamicVector( size_t n, const Type& init );
205  template< typename Other > explicit inline DynamicVector( size_t n, const Other* array );
206 
207  template< typename Other, size_t N >
208  explicit inline DynamicVector( const Other (&array)[N] );
209 
210  inline DynamicVector( const DynamicVector& v );
211  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
213  //**********************************************************************************************
214 
215  //**Destructor**********************************************************************************
218  inline ~DynamicVector();
220  //**********************************************************************************************
221 
222  //**Data access functions***********************************************************************
225  inline Reference operator[]( size_t index );
226  inline ConstReference operator[]( size_t index ) const;
227  inline Pointer data ();
228  inline ConstPointer data () const;
229  inline Iterator begin ();
230  inline ConstIterator begin () const;
231  inline ConstIterator cbegin() const;
232  inline Iterator end ();
233  inline ConstIterator end () const;
234  inline ConstIterator cend () const;
236  //**********************************************************************************************
237 
238  //**Assignment operators************************************************************************
241  template< typename Other, size_t N >
242  inline DynamicVector& operator=( const Other (&array)[N] );
243 
244  inline DynamicVector& operator= ( const Type& rhs );
245  inline DynamicVector& operator= ( const DynamicVector& rhs );
246  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
247  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& rhs );
248  template< typename VT > inline DynamicVector& operator-=( const Vector<VT,TF>& rhs );
249  template< typename VT > inline DynamicVector& operator*=( const Vector<VT,TF>& rhs );
250 
251  template< typename Other >
252  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
253  operator*=( Other rhs );
254 
255  template< typename Other >
256  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
257  operator/=( Other rhs );
259  //**********************************************************************************************
260 
261  //**Utility functions***************************************************************************
264  inline size_t size() const;
265  inline size_t capacity() const;
266  inline size_t nonZeros() const;
267  inline void reset();
268  inline void clear();
269  inline void resize( size_t n, bool preserve=true );
270  inline void extend( size_t n, bool preserve=true );
271  inline void reserve( size_t n );
272  template< typename Other > inline DynamicVector& scale( Other scalar );
273  inline void swap( DynamicVector& v ) /* throw() */;
275  //**********************************************************************************************
276 
277  private:
278  //**********************************************************************************************
280  template< typename VT >
282  struct VectorizedAssign {
283  enum { value = vectorizable && VT::vectorizable &&
284  IsSame<Type,typename VT::ElementType>::value };
285  };
287  //**********************************************************************************************
288 
289  //**********************************************************************************************
291  template< typename VT >
293  struct VectorizedAddAssign {
294  enum { value = vectorizable && VT::vectorizable &&
295  IsSame<Type,typename VT::ElementType>::value &&
296  IntrinsicTrait<Type>::addition };
297  };
299  //**********************************************************************************************
300 
301  //**********************************************************************************************
303  template< typename VT >
305  struct VectorizedSubAssign {
306  enum { value = vectorizable && VT::vectorizable &&
307  IsSame<Type,typename VT::ElementType>::value &&
308  IntrinsicTrait<Type>::subtraction };
309  };
311  //**********************************************************************************************
312 
313  //**********************************************************************************************
315  template< typename VT >
317  struct VectorizedMultAssign {
318  enum { value = vectorizable && VT::vectorizable &&
319  IsSame<Type,typename VT::ElementType>::value &&
320  IntrinsicTrait<Type>::multiplication };
321  };
323  //**********************************************************************************************
324 
325  public:
326  //**Expression template evaluation functions****************************************************
329  template< typename Other > inline bool canAlias ( const Other* alias ) const;
330  template< typename Other > inline bool isAliased( const Other* alias ) const;
331 
332  inline bool isAligned () const;
333  inline bool canSMPAssign() const;
334 
335  inline IntrinsicType load ( size_t index ) const;
336  inline IntrinsicType loadu ( size_t index ) const;
337  inline void store ( size_t index, const IntrinsicType& value );
338  inline void storeu( size_t index, const IntrinsicType& value );
339  inline void stream( size_t index, const IntrinsicType& value );
340 
341  template< typename VT >
342  inline typename DisableIf< VectorizedAssign<VT> >::Type
343  assign( const DenseVector<VT,TF>& rhs );
344 
345  template< typename VT >
346  inline typename EnableIf< VectorizedAssign<VT> >::Type
347  assign( const DenseVector<VT,TF>& rhs );
348 
349  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
350 
351  template< typename VT >
352  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
353  addAssign( const DenseVector<VT,TF>& rhs );
354 
355  template< typename VT >
356  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
357  addAssign( const DenseVector<VT,TF>& rhs );
358 
359  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
360 
361  template< typename VT >
362  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
363  subAssign( const DenseVector<VT,TF>& rhs );
364 
365  template< typename VT >
366  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
367  subAssign( const DenseVector<VT,TF>& rhs );
368 
369  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
370 
371  template< typename VT >
372  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
373  multAssign( const DenseVector<VT,TF>& rhs );
374 
375  template< typename VT >
376  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
377  multAssign( const DenseVector<VT,TF>& rhs );
378 
379  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
381  //**********************************************************************************************
382 
383  private:
384  //**Utility functions***************************************************************************
387  inline size_t adjustCapacity( size_t minCapacity ) const;
389  //**********************************************************************************************
390 
391  //**Member variables****************************************************************************
394  size_t size_;
395  size_t capacity_;
397 
403  //**********************************************************************************************
404 
405  //**Compile time checks*************************************************************************
412  //**********************************************************************************************
413 };
414 //*************************************************************************************************
415 
416 
417 
418 
419 //=================================================================================================
420 //
421 // CONSTRUCTORS
422 //
423 //=================================================================================================
424 
425 //*************************************************************************************************
428 template< typename Type // Data type of the vector
429  , bool TF > // Transpose flag
431  : size_ ( 0UL ) // The current size/dimension of the vector
432  , capacity_( 0UL ) // The maximum capacity of the vector
433  , v_ ( NULL ) // The vector elements
434 {}
435 //*************************************************************************************************
436 
437 
438 //*************************************************************************************************
446 template< typename Type // Data type of the vector
447  , bool TF > // Transpose flag
449  : size_ ( n ) // The current size/dimension of the vector
450  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
451  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
452 {
454  for( size_t i=size_; i<capacity_; ++i )
455  v_[i] = Type();
456  }
457 }
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
469 template< typename Type // Data type of the vector
470  , bool TF > // Transpose flag
471 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Type& init )
472  : size_ ( n ) // The current size/dimension of the vector
473  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
474  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
475 {
476  for( size_t i=0UL; i<size_; ++i )
477  v_[i] = init;
478 
480  for( size_t i=size_; i<capacity_; ++i )
481  v_[i] = Type();
482  }
483 }
484 //*************************************************************************************************
485 
486 
487 //*************************************************************************************************
507 template< typename Type // Data type of the vector
508  , bool TF > // Transpose flag
509 template< typename Other > // Data type of the initialization array
510 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Other* array )
511  : size_ ( n ) // The current size/dimension of the vector
512  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
513  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
514 {
515  for( size_t i=0UL; i<n; ++i )
516  v_[i] = array[i];
517 
519  for( size_t i=n; i<capacity_; ++i )
520  v_[i] = Type();
521  }
522 }
523 //*************************************************************************************************
524 
525 
526 //*************************************************************************************************
543 template< typename Type // Data type of the vector
544  , bool TF > // Transpose flag
545 template< typename Other // Data type of the initialization array
546  , size_t N > // Dimension of the initialization array
547 inline DynamicVector<Type,TF>::DynamicVector( const Other (&array)[N] )
548  : size_ ( N ) // The current size/dimension of the vector
549  , capacity_( adjustCapacity( N ) ) // The maximum capacity of the vector
550  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
551 {
552  for( size_t i=0UL; i<N; ++i )
553  v_[i] = array[i];
554 
556  for( size_t i=N; i<capacity_; ++i )
557  v_[i] = Type();
558  }
559 }
560 //*************************************************************************************************
561 
562 
563 //*************************************************************************************************
571 template< typename Type // Data type of the vector
572  , bool TF > // Transpose flag
574  : size_ ( v.size_ ) // The current size/dimension of the vector
575  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
576  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
577 {
578  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
579 
580  for( size_t i=0UL; i<capacity_; ++i )
581  v_[i] = v.v_[i];
582 }
583 //*************************************************************************************************
584 
585 
586 //*************************************************************************************************
591 template< typename Type // Data type of the vector
592  , bool TF > // Transpose flag
593 template< typename VT > // Type of the foreign vector
595  : size_ ( (~v).size() ) // The current size/dimension of the vector
596  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
597  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
598 {
599  for( size_t i=( IsSparseVector<VT>::value ? 0UL : size_ );
600  i<( IsVectorizable<Type>::value ? capacity_ : size_ ); ++i ) {
601  v_[i] = Type();
602  }
603 
604  smpAssign( *this, ~v );
605 }
606 //*************************************************************************************************
607 
608 
609 
610 
611 //=================================================================================================
612 //
613 // DESTRUCTOR
614 //
615 //=================================================================================================
616 
617 //*************************************************************************************************
620 template< typename Type // Data type of the vector
621  , bool TF > // Transpose flag
623 {
624  deallocate( v_ );
625 }
626 //*************************************************************************************************
627 
628 
629 
630 
631 //=================================================================================================
632 //
633 // DATA ACCESS FUNCTIONS
634 //
635 //=================================================================================================
636 
637 //*************************************************************************************************
643 template< typename Type // Data type of the vector
644  , bool TF > // Transpose flag
645 inline typename DynamicVector<Type,TF>::Reference
647 {
648  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
649  return v_[index];
650 }
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
660 template< typename Type // Data type of the vector
661  , bool TF > // Transpose flag
664 {
665  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
666  return v_[index];
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
678 template< typename Type // Data type of the vector
679  , bool TF > // Transpose flag
681 {
682  return v_;
683 }
684 //*************************************************************************************************
685 
686 
687 //*************************************************************************************************
694 template< typename Type // Data type of the vector
695  , bool TF > // Transpose flag
697 {
698  return v_;
699 }
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
708 template< typename Type // Data type of the vector
709  , bool TF > // Transpose flag
711 {
712  return Iterator( v_ );
713 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
722 template< typename Type // Data type of the vector
723  , bool TF > // Transpose flag
725 {
726  return ConstIterator( v_ );
727 }
728 //*************************************************************************************************
729 
730 
731 //*************************************************************************************************
736 template< typename Type // Data type of the vector
737  , bool TF > // Transpose flag
739 {
740  return ConstIterator( v_ );
741 }
742 //*************************************************************************************************
743 
744 
745 //*************************************************************************************************
750 template< typename Type // Data type of the vector
751  , bool TF > // Transpose flag
753 {
754  return Iterator( v_ + size_ );
755 }
756 //*************************************************************************************************
757 
758 
759 //*************************************************************************************************
764 template< typename Type // Data type of the vector
765  , bool TF > // Transpose flag
767 {
768  return ConstIterator( v_ + size_ );
769 }
770 //*************************************************************************************************
771 
772 
773 //*************************************************************************************************
778 template< typename Type // Data type of the vector
779  , bool TF > // Transpose flag
781 {
782  return ConstIterator( v_ + size_ );
783 }
784 //*************************************************************************************************
785 
786 
787 
788 
789 //=================================================================================================
790 //
791 // ASSIGNMENT OPERATORS
792 //
793 //=================================================================================================
794 
795 //*************************************************************************************************
813 template< typename Type // Data type of the vector
814  , bool TF > // Transpose flag
815 template< typename Other // Data type of the initialization array
816  , size_t N > // Dimension of the initialization array
818 {
819  resize( N, false );
820 
821  for( size_t i=0UL; i<N; ++i )
822  v_[i] = array[i];
823 
824  return *this;
825 }
826 //*************************************************************************************************
827 
828 
829 //*************************************************************************************************
835 template< typename Type // Data type of the vector
836  , bool TF > // Transpose flag
838 {
839  for( size_t i=0UL; i<size_; ++i )
840  v_[i] = rhs;
841  return *this;
842 }
843 //*************************************************************************************************
844 
845 
846 //*************************************************************************************************
855 template< typename Type // Data type of the vector
856  , bool TF > // Transpose flag
858 {
859  if( &rhs == this ) return *this;
860 
861  resize( rhs.size_, false );
862  smpAssign( *this, ~rhs );
863 
864  return *this;
865 }
866 //*************************************************************************************************
867 
868 
869 //*************************************************************************************************
877 template< typename Type // Data type of the vector
878  , bool TF > // Transpose flag
879 template< typename VT > // Type of the right-hand side vector
881 {
882  if( (~rhs).canAlias( this ) ) {
883  DynamicVector tmp( ~rhs );
884  swap( tmp );
885  }
886  else {
887  resize( (~rhs).size(), false );
889  reset();
890  smpAssign( *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  if( (~rhs).size() != size_ )
914  throw std::invalid_argument( "Vector sizes do not match" );
915 
916  if( (~rhs).canAlias( this ) ) {
917  typename VT::ResultType tmp( ~rhs );
918  smpAddAssign( *this, tmp );
919  }
920  else {
921  smpAddAssign( *this, ~rhs );
922  }
923 
924  return *this;
925 }
926 //*************************************************************************************************
927 
928 
929 //*************************************************************************************************
940 template< typename Type // Data type of the vector
941  , bool TF > // Transpose flag
942 template< typename VT > // Type of the right-hand side vector
944 {
945  if( (~rhs).size() != size_ )
946  throw std::invalid_argument( "Vector sizes do not match" );
947 
948  if( (~rhs).canAlias( this ) ) {
949  typename VT::ResultType tmp( ~rhs );
950  smpSubAssign( *this, tmp );
951  }
952  else {
953  smpSubAssign( *this, ~rhs );
954  }
955 
956  return *this;
957 }
958 //*************************************************************************************************
959 
960 
961 //*************************************************************************************************
972 template< typename Type // Data type of the vector
973  , bool TF > // Transpose flag
974 template< typename VT > // Type of the right-hand side vector
976 {
977  if( (~rhs).size() != size_ )
978  throw std::invalid_argument( "Vector sizes do not match" );
979 
980  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
981  DynamicVector<Type,TF> tmp( *this * (~rhs) );
982  swap( tmp );
983  }
984  else {
985  smpMultAssign( *this, ~rhs );
986  }
987 
988  return *this;
989 }
990 //*************************************************************************************************
991 
992 
993 //*************************************************************************************************
1000 template< typename Type // Data type of the vector
1001  , bool TF > // Transpose flag
1002 template< typename Other > // Data type of the right-hand side scalar
1003 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
1005 {
1006  smpAssign( *this, (*this) * rhs );
1007  return *this;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1021 template< typename Type // Data type of the vector
1022  , bool TF > // Transpose flag
1023 template< typename Other > // Data type of the right-hand side scalar
1024 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
1026 {
1027  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1028 
1029  smpAssign( *this, (*this) / rhs );
1030  return *this;
1031 }
1032 //*************************************************************************************************
1033 
1034 
1035 
1036 
1037 //=================================================================================================
1038 //
1039 // UTILITY FUNCTIONS
1040 //
1041 //=================================================================================================
1042 
1043 //*************************************************************************************************
1048 template< typename Type // Data type of the vector
1049  , bool TF > // Transpose flag
1050 inline size_t DynamicVector<Type,TF>::size() const
1051 {
1052  return size_;
1053 }
1054 //*************************************************************************************************
1055 
1056 
1057 //*************************************************************************************************
1062 template< typename Type // Data type of the vector
1063  , bool TF > // Transpose flag
1065 {
1066  return capacity_;
1067 }
1068 //*************************************************************************************************
1069 
1070 
1071 //*************************************************************************************************
1079 template< typename Type // Data type of the vector
1080  , bool TF > // Transpose flag
1082 {
1083  size_t nonzeros( 0 );
1084 
1085  for( size_t i=0UL; i<size_; ++i ) {
1086  if( !isDefault( v_[i] ) )
1087  ++nonzeros;
1088  }
1089 
1090  return nonzeros;
1091 }
1092 //*************************************************************************************************
1093 
1094 
1095 //*************************************************************************************************
1100 template< typename Type // Data type of the vector
1101  , bool TF > // Transpose flag
1103 {
1104  using blaze::reset;
1105  for( size_t i=0UL; i<size_; ++i )
1106  reset( v_[i] );
1107 }
1108 //*************************************************************************************************
1109 
1110 
1111 //*************************************************************************************************
1118 template< typename Type // Data type of the vector
1119  , bool TF > // Transpose flag
1121 {
1122  resize( 0UL, false );
1123 }
1124 //*************************************************************************************************
1125 
1126 
1127 //*************************************************************************************************
1156 template< typename Type // Data type of the vector
1157  , bool TF > // Transpose flag
1158 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1159 {
1160  if( n > capacity_ )
1161  {
1162  // Allocating a new array
1163  const size_t newCapacity( adjustCapacity( n ) );
1164  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1165 
1166  // Initializing the new array
1167  if( preserve ) {
1168  std::copy( v_, v_+size_, tmp );
1169  }
1170 
1172  for( size_t i=size_; i<newCapacity; ++i )
1173  tmp[i] = Type();
1174  }
1175 
1176  // Replacing the old array
1177  std::swap( v_, tmp );
1178  deallocate( tmp );
1179  capacity_ = newCapacity;
1180  }
1181  else if( IsVectorizable<Type>::value && n < size_ )
1182  {
1183  for( size_t i=n; i<size_; ++i )
1184  v_[i] = Type();
1185  }
1186 
1187  size_ = n;
1188 }
1189 //*************************************************************************************************
1190 
1191 
1192 //*************************************************************************************************
1204 template< typename Type // Data type of the vector
1205  , bool TF > // Transpose flag
1206 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1207 {
1208  resize( size_+n, preserve );
1209 }
1210 //*************************************************************************************************
1211 
1212 
1213 //*************************************************************************************************
1222 template< typename Type // Data type of the vector
1223  , bool TF > // Transpose flag
1224 inline void DynamicVector<Type,TF>::reserve( size_t n )
1225 {
1226  if( n > capacity_ )
1227  {
1228  // Allocating a new array
1229  const size_t newCapacity( adjustCapacity( n ) );
1230  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1231 
1232  // Initializing the new array
1233  std::copy( v_, v_+size_, tmp );
1234 
1236  for( size_t i=size_; i<newCapacity; ++i )
1237  tmp[i] = Type();
1238  }
1239 
1240  // Replacing the old array
1241  std::swap( tmp, v_ );
1242  deallocate( tmp );
1243  capacity_ = newCapacity;
1244  }
1245 }
1246 //*************************************************************************************************
1247 
1248 
1249 //*************************************************************************************************
1255 template< typename Type // Data type of the vector
1256  , bool TF > // Transpose flag
1257 template< typename Other > // Data type of the scalar value
1259 {
1260  for( size_t i=0UL; i<size_; ++i )
1261  v_[i] *= scalar;
1262  return *this;
1263 }
1264 //*************************************************************************************************
1265 
1266 
1267 //*************************************************************************************************
1274 template< typename Type // Data type of the vector
1275  , bool TF > // Transpose flag
1276 inline void DynamicVector<Type,TF>::swap( DynamicVector& v ) /* throw() */
1277 {
1278  std::swap( size_, v.size_ );
1280  std::swap( v_, v.v_ );
1281 }
1282 //*************************************************************************************************
1283 
1284 
1285 //*************************************************************************************************
1291 template< typename Type // Data type of the vector
1292  , bool TF > // Transpose flag
1293 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const
1294 {
1296  return minCapacity + ( IT::size - ( minCapacity % IT::size ) ) % IT::size;
1297  else return minCapacity;
1298 }
1299 //*************************************************************************************************
1300 
1301 
1302 
1303 
1304 //=================================================================================================
1305 //
1306 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1307 //
1308 //=================================================================================================
1309 
1310 //*************************************************************************************************
1320 template< typename Type // Data type of the vector
1321  , bool TF > // Transpose flag
1322 template< typename Other > // Data type of the foreign expression
1323 inline bool DynamicVector<Type,TF>::canAlias( const Other* alias ) const
1324 {
1325  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1326 }
1327 //*************************************************************************************************
1328 
1329 
1330 //*************************************************************************************************
1340 template< typename Type // Data type of the vector
1341  , bool TF > // Transpose flag
1342 template< typename Other > // Data type of the foreign expression
1343 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const
1344 {
1345  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1346 }
1347 //*************************************************************************************************
1348 
1349 
1350 //*************************************************************************************************
1359 template< typename Type // Data type of the vector
1360  , bool TF > // Transpose flag
1362 {
1363  return true;
1364 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1378 template< typename Type // Data type of the vector
1379  , bool TF > // Transpose flag
1381 {
1382  return ( size() > SMP_DVECASSIGN_THRESHOLD );
1383 }
1384 //*************************************************************************************************
1385 
1386 
1387 //*************************************************************************************************
1400 template< typename Type // Data type of the vector
1401  , bool TF > // Transpose flag
1403  DynamicVector<Type,TF>::load( size_t index ) const
1404 {
1405  using blaze::load;
1406 
1408 
1409  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1410  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1411  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1412 
1413  return load( v_+index );
1414 }
1415 //*************************************************************************************************
1416 
1417 
1418 //*************************************************************************************************
1431 template< typename Type // Data type of the vector
1432  , bool TF > // Transpose flag
1434  DynamicVector<Type,TF>::loadu( size_t index ) const
1435 {
1436  using blaze::loadu;
1437 
1439 
1440  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1441  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1442 
1443  return loadu( v_+index );
1444 }
1445 //*************************************************************************************************
1446 
1447 
1448 //*************************************************************************************************
1462 template< typename Type // Data type of the vector
1463  , bool TF > // Transpose flag
1464 inline void DynamicVector<Type,TF>::store( size_t index, const IntrinsicType& value )
1465 {
1466  using blaze::store;
1467 
1469 
1470  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1471  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1472  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1473 
1474  store( v_+index, value );
1475 }
1476 //*************************************************************************************************
1477 
1478 
1479 //*************************************************************************************************
1493 template< typename Type // Data type of the vector
1494  , bool TF > // Transpose flag
1495 inline void DynamicVector<Type,TF>::storeu( size_t index, const IntrinsicType& value )
1496 {
1497  using blaze::storeu;
1498 
1500 
1501  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1502  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1503 
1504  storeu( v_+index, value );
1505 }
1506 //*************************************************************************************************
1507 
1508 
1509 //*************************************************************************************************
1523 template< typename Type // Data type of the vector
1524  , bool TF > // Transpose flag
1525 inline void DynamicVector<Type,TF>::stream( size_t index, const IntrinsicType& value )
1526 {
1527  using blaze::stream;
1528 
1530 
1531  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1532  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1533  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1534 
1535  stream( v_+index, value );
1536 }
1537 //*************************************************************************************************
1538 
1539 
1540 //*************************************************************************************************
1551 template< typename Type // Data type of the vector
1552  , bool TF > // Transpose flag
1553 template< typename VT > // Type of the right-hand side dense vector
1554 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1556 {
1557  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1558 
1559  const size_t iend( (~rhs).size() & size_t(-2) );
1560  for( size_t i=0UL; i<iend; i+=2UL ) {
1561  v_[i ] = (~rhs)[i ];
1562  v_[i+1UL] = (~rhs)[i+1UL];
1563  }
1564  if( iend < (~rhs).size() )
1565  v_[iend] = (~rhs)[iend];
1566 }
1567 //*************************************************************************************************
1568 
1569 
1570 //*************************************************************************************************
1581 template< typename Type // Data type of the vector
1582  , bool TF > // Transpose flag
1583 template< typename VT > // Type of the right-hand side dense vector
1584 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1586 {
1587  using blaze::store;
1588  using blaze::stream;
1589 
1590  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1591 
1593 
1594  if( useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1595  {
1596  for( size_t i=0UL; i<size_; i+=IT::size ) {
1597  stream( v_+i, (~rhs).load(i) );
1598  }
1599  }
1600  else
1601  {
1602  const size_t iend( size_ & size_t(-IT::size*4) );
1603  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1604 
1605  typename VT::ConstIterator it( (~rhs).begin() );
1606  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1607  store( v_+i , it.load() ); it += IT::size;
1608  store( v_+i+IT::size , it.load() ); it += IT::size;
1609  store( v_+i+IT::size*2UL, it.load() ); it += IT::size;
1610  store( v_+i+IT::size*3UL, it.load() ); it += IT::size;
1611  }
1612  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1613  store( v_+i, it.load() );
1614  }
1615  }
1616 }
1617 //*************************************************************************************************
1618 
1619 
1620 //*************************************************************************************************
1631 template< typename Type // Data type of the vector
1632  , bool TF > // Transpose flag
1633 template< typename VT > // Type of the right-hand side sparse vector
1635 {
1636  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1637 
1638  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1639  v_[element->index()] = element->value();
1640 }
1641 //*************************************************************************************************
1642 
1643 
1644 //*************************************************************************************************
1655 template< typename Type // Data type of the vector
1656  , bool TF > // Transpose flag
1657 template< typename VT > // Type of the right-hand side dense vector
1658 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1660 {
1661  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1662 
1663  const size_t iend( (~rhs).size() & size_t(-2) );
1664  for( size_t i=0UL; i<iend; i+=2UL ) {
1665  v_[i ] += (~rhs)[i ];
1666  v_[i+1UL] += (~rhs)[i+1UL];
1667  }
1668  if( iend < (~rhs).size() )
1669  v_[iend] += (~rhs)[iend];
1670 }
1671 //*************************************************************************************************
1672 
1673 
1674 //*************************************************************************************************
1685 template< typename Type // Data type of the vector
1686  , bool TF > // Transpose flag
1687 template< typename VT > // Type of the right-hand side dense vector
1688 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1690 {
1691  using blaze::load;
1692  using blaze::store;
1693 
1694  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1695 
1697 
1698  const size_t iend( size_ & size_t(-IT::size*4) );
1699  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1700 
1701  typename VT::ConstIterator it( (~rhs).begin() );
1702  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1703  store( v_+i , load(v_+i ) + it.load() ); it += IT::size;
1704  store( v_+i+IT::size , load(v_+i+IT::size ) + it.load() ); it += IT::size;
1705  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) + it.load() ); it += IT::size;
1706  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) + it.load() ); it += IT::size;
1707  }
1708  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1709  store( v_+i, load(v_+i) + it.load() );
1710  }
1711 }
1712 //*************************************************************************************************
1713 
1714 
1715 //*************************************************************************************************
1726 template< typename Type // Data type of the vector
1727  , bool TF > // Transpose flag
1728 template< typename VT > // Type of the right-hand side sparse vector
1730 {
1731  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1732 
1733  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1734  v_[element->index()] += element->value();
1735 }
1736 //*************************************************************************************************
1737 
1738 
1739 //*************************************************************************************************
1750 template< typename Type // Data type of the vector
1751  , bool TF > // Transpose flag
1752 template< typename VT > // Type of the right-hand side dense vector
1753 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1755 {
1756  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1757 
1758  const size_t iend( (~rhs).size() & size_t(-2) );
1759  for( size_t i=0UL; i<iend; i+=2UL ) {
1760  v_[i ] -= (~rhs)[i ];
1761  v_[i+1UL] -= (~rhs)[i+1UL];
1762  }
1763  if( iend < (~rhs).size() )
1764  v_[iend] -= (~rhs)[iend];
1765 }
1766 //*************************************************************************************************
1767 
1768 
1769 //*************************************************************************************************
1780 template< typename Type // Data type of the vector
1781  , bool TF > // Transpose flag
1782 template< typename VT > // Type of the right-hand side dense vector
1783 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1785 {
1786  using blaze::load;
1787  using blaze::store;
1788 
1789  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1790 
1792 
1793  const size_t iend( size_ & size_t(-IT::size*4) );
1794  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1795 
1796  typename VT::ConstIterator it( (~rhs).begin() );
1797  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1798  store( v_+i , load(v_+i ) - it.load() ); it += IT::size;
1799  store( v_+i+IT::size , load(v_+i+IT::size ) - it.load() ); it += IT::size;
1800  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) - it.load() ); it += IT::size;
1801  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) - it.load() ); it += IT::size;
1802  }
1803  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1804  store( v_+i, load(v_+i) - it.load() );
1805  }
1806 }
1807 //*************************************************************************************************
1808 
1809 
1810 //*************************************************************************************************
1821 template< typename Type // Data type of the vector
1822  , bool TF > // Transpose flag
1823 template< typename VT > // Type of the right-hand side sparse vector
1825 {
1826  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1827 
1828  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1829  v_[element->index()] -= element->value();
1830 }
1831 //*************************************************************************************************
1832 
1833 
1834 //*************************************************************************************************
1845 template< typename Type // Data type of the vector
1846  , bool TF > // Transpose flag
1847 template< typename VT > // Type of the right-hand side dense vector
1848 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1850 {
1851  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1852 
1853  const size_t iend( (~rhs).size() & size_t(-2) );
1854  for( size_t i=0UL; i<iend; i+=2UL ) {
1855  v_[i ] *= (~rhs)[i ];
1856  v_[i+1UL] *= (~rhs)[i+1UL];
1857  }
1858  if( iend < (~rhs).size() )
1859  v_[iend] *= (~rhs)[iend];
1860 }
1861 //*************************************************************************************************
1862 
1863 
1864 //*************************************************************************************************
1875 template< typename Type // Data type of the vector
1876  , bool TF > // Transpose flag
1877 template< typename VT > // Type of the right-hand side dense vector
1878 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1880 {
1881  using blaze::load;
1882  using blaze::store;
1883 
1884  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1885 
1887 
1888  const size_t iend( size_ & size_t(-IT::size*4) );
1889  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1890 
1891  typename VT::ConstIterator it( (~rhs).begin() );
1892  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1893  store( v_+i , load(v_+i ) * it.load() ); it += IT::size;
1894  store( v_+i+IT::size , load(v_+i+IT::size ) * it.load() ); it += IT::size;
1895  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) * it.load() ); it += IT::size;
1896  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) * it.load() ); it += IT::size;
1897  }
1898  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1899  store( v_+i, load(v_+i) * it.load() );
1900  }
1901 }
1902 //*************************************************************************************************
1903 
1904 
1905 //*************************************************************************************************
1916 template< typename Type // Data type of the vector
1917  , bool TF > // Transpose flag
1918 template< typename VT > // Type of the right-hand side sparse vector
1920 {
1921  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1922 
1923  const DynamicVector tmp( serial( *this ) );
1924 
1925  reset();
1926 
1927  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1928  v_[element->index()] = tmp[element->index()] * element->value();
1929 }
1930 //*************************************************************************************************
1931 
1932 
1933 
1934 
1935 //=================================================================================================
1936 //
1937 // DYNAMICVECTOR OPERATORS
1938 //
1939 //=================================================================================================
1940 
1941 //*************************************************************************************************
1944 template< typename Type, bool TF >
1945 inline void reset( DynamicVector<Type,TF>& v );
1946 
1947 template< typename Type, bool TF >
1948 inline void clear( DynamicVector<Type,TF>& v );
1949 
1950 template< typename Type, bool TF >
1951 inline bool isDefault( const DynamicVector<Type,TF>& v );
1952 
1953 template< typename Type, bool TF >
1954 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */;
1956 //*************************************************************************************************
1957 
1958 
1959 //*************************************************************************************************
1966 template< typename Type // Data type of the vector
1967  , bool TF > // Transpose flag
1969 {
1970  v.reset();
1971 }
1972 //*************************************************************************************************
1973 
1974 
1975 //*************************************************************************************************
1982 template< typename Type // Data type of the vector
1983  , bool TF > // Transpose flag
1985 {
1986  v.clear();
1987 }
1988 //*************************************************************************************************
1989 
1990 
1991 //*************************************************************************************************
2010 template< typename Type // Data type of the vector
2011  , bool TF > // Transpose flag
2012 inline bool isDefault( const DynamicVector<Type,TF>& v )
2013 {
2014  for( size_t i=0UL; i<v.size(); ++i )
2015  if( !isDefault( v[i] ) ) return false;
2016  return true;
2017 }
2018 //*************************************************************************************************
2019 
2020 
2021 //*************************************************************************************************
2030 template< typename Type // Data type of the vector
2031  , bool TF > // Transpose flag
2032 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */
2033 {
2034  a.swap( b );
2035 }
2036 //*************************************************************************************************
2037 
2038 
2039 
2040 
2041 //=================================================================================================
2042 //
2043 // ISRESIZABLE SPECIALIZATIONS
2044 //
2045 //=================================================================================================
2046 
2047 //*************************************************************************************************
2049 template< typename T, bool TF >
2050 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2051 {
2052  enum { value = 1 };
2053  typedef TrueType Type;
2054 };
2055 
2056 template< typename T, bool TF >
2057 struct IsResizable< const DynamicVector<T,TF> > : public TrueType
2058 {
2059  enum { value = 1 };
2060  typedef TrueType Type;
2061 };
2062 
2063 template< typename T, bool TF >
2064 struct IsResizable< volatile DynamicVector<T,TF> > : public TrueType
2065 {
2066  enum { value = 1 };
2067  typedef TrueType Type;
2068 };
2069 
2070 template< typename T, bool TF >
2071 struct IsResizable< const volatile DynamicVector<T,TF> > : public TrueType
2072 {
2073  enum { value = 1 };
2074  typedef TrueType Type;
2075 };
2077 //*************************************************************************************************
2078 
2079 
2080 
2081 
2082 //=================================================================================================
2083 //
2084 // ADDTRAIT SPECIALIZATIONS
2085 //
2086 //=================================================================================================
2087 
2088 //*************************************************************************************************
2090 template< typename T1, bool TF, typename T2, size_t N >
2091 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2092 {
2093  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2094 };
2095 
2096 template< typename T1, size_t N, bool TF, typename T2 >
2097 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2098 {
2099  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2100 };
2101 
2102 template< typename T1, bool TF, typename T2, size_t N >
2103 struct AddTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2104 {
2105  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2106 };
2107 
2108 template< typename T1, size_t N, bool TF, typename T2 >
2109 struct AddTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2110 {
2111  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2112 };
2113 
2114 template< typename T1, bool TF, typename T2 >
2115 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2116 {
2117  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2118 };
2120 //*************************************************************************************************
2121 
2122 
2123 
2124 
2125 //=================================================================================================
2126 //
2127 // SUBTRAIT SPECIALIZATIONS
2128 //
2129 //=================================================================================================
2130 
2131 //*************************************************************************************************
2133 template< typename T1, bool TF, typename T2, size_t N >
2134 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2135 {
2136  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2137 };
2138 
2139 template< typename T1, size_t N, bool TF, typename T2 >
2140 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2141 {
2142  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2143 };
2144 
2145 template< typename T1, bool TF, typename T2, size_t N >
2146 struct SubTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2147 {
2148  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2149 };
2150 
2151 template< typename T1, size_t N, bool TF, typename T2 >
2152 struct SubTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2153 {
2154  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2155 };
2156 
2157 template< typename T1, bool TF, typename T2 >
2158 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2159 {
2160  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2161 };
2163 //*************************************************************************************************
2164 
2165 
2166 
2167 
2168 //=================================================================================================
2169 //
2170 // MULTTRAIT SPECIALIZATIONS
2171 //
2172 //=================================================================================================
2173 
2174 //*************************************************************************************************
2176 template< typename T1, bool TF, typename T2 >
2177 struct MultTrait< DynamicVector<T1,TF>, T2 >
2178 {
2179  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2181 };
2182 
2183 template< typename T1, typename T2, bool TF >
2184 struct MultTrait< T1, DynamicVector<T2,TF> >
2185 {
2186  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2188 };
2189 
2190 template< typename T1, bool TF, typename T2, size_t N >
2191 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2192 {
2193  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2194 };
2195 
2196 template< typename T1, typename T2, size_t N >
2197 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2198 {
2199  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2200 };
2201 
2202 template< typename T1, typename T2, size_t N >
2203 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2204 {
2205  typedef typename MultTrait<T1,T2>::Type Type;
2206 };
2207 
2208 template< typename T1, size_t N, bool TF, typename T2 >
2209 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2210 {
2211  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2212 };
2213 
2214 template< typename T1, size_t N, typename T2 >
2215 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2216 {
2217  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2218 };
2219 
2220 template< typename T1, size_t N, typename T2 >
2221 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2222 {
2223  typedef typename MultTrait<T1,T2>::Type Type;
2224 };
2225 
2226 template< typename T1, bool TF, typename T2, size_t N >
2227 struct MultTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2228 {
2229  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2230 };
2231 
2232 template< typename T1, typename T2, size_t N >
2233 struct MultTrait< DynamicVector<T1,false>, HybridVector<T2,N,true> >
2234 {
2235  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2236 };
2237 
2238 template< typename T1, typename T2, size_t N >
2239 struct MultTrait< DynamicVector<T1,true>, HybridVector<T2,N,false> >
2240 {
2241  typedef typename MultTrait<T1,T2>::Type Type;
2242 };
2243 
2244 template< typename T1, size_t N, bool TF, typename T2 >
2245 struct MultTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2246 {
2247  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2248 };
2249 
2250 template< typename T1, size_t N, typename T2 >
2251 struct MultTrait< HybridVector<T1,N,false>, DynamicVector<T2,true> >
2252 {
2253  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2254 };
2255 
2256 template< typename T1, size_t N, typename T2 >
2257 struct MultTrait< HybridVector<T1,N,true>, DynamicVector<T2,false> >
2258 {
2259  typedef typename MultTrait<T1,T2>::Type Type;
2260 };
2261 
2262 template< typename T1, bool TF, typename T2 >
2263 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2264 {
2265  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2266 };
2267 
2268 template< typename T1, typename T2 >
2269 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2270 {
2271  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2272 };
2273 
2274 template< typename T1, typename T2 >
2275 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2276 {
2277  typedef typename MultTrait<T1,T2>::Type Type;
2278 };
2280 //*************************************************************************************************
2281 
2282 
2283 
2284 
2285 //=================================================================================================
2286 //
2287 // CROSSTRAIT SPECIALIZATIONS
2288 //
2289 //=================================================================================================
2290 
2291 //*************************************************************************************************
2293 template< typename T1, typename T2 >
2294 struct CrossTrait< DynamicVector<T1,false>, StaticVector<T2,3UL,false> >
2295 {
2296  private:
2297  typedef typename MultTrait<T1,T2>::Type T;
2298 
2299  public:
2300  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2301 };
2302 
2303 template< typename T1, typename T2 >
2304 struct CrossTrait< StaticVector<T1,3UL,false>, DynamicVector<T2,false> >
2305 {
2306  private:
2307  typedef typename MultTrait<T1,T2>::Type T;
2308 
2309  public:
2310  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2311 };
2312 
2313 template< typename T1, typename T2, size_t N >
2314 struct CrossTrait< DynamicVector<T1,false>, HybridVector<T2,N,false> >
2315 {
2316  private:
2317  typedef typename MultTrait<T1,T2>::Type T;
2318 
2319  public:
2320  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2321 };
2322 
2323 template< typename T1, size_t N, typename T2 >
2324 struct CrossTrait< HybridVector<T1,N,false>, DynamicVector<T2,false> >
2325 {
2326  private:
2327  typedef typename MultTrait<T1,T2>::Type T;
2328 
2329  public:
2330  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2331 };
2332 
2333 template< typename T1, typename T2 >
2334 struct CrossTrait< DynamicVector<T1,false>, DynamicVector<T2,false> >
2335 {
2336  private:
2337  typedef typename MultTrait<T1,T2>::Type T;
2338 
2339  public:
2340  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2341 };
2343 //*************************************************************************************************
2344 
2345 
2346 
2347 
2348 //=================================================================================================
2349 //
2350 // DIVTRAIT SPECIALIZATIONS
2351 //
2352 //=================================================================================================
2353 
2354 //*************************************************************************************************
2356 template< typename T1, bool TF, typename T2 >
2357 struct DivTrait< DynamicVector<T1,TF>, T2 >
2358 {
2359  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
2361 };
2363 //*************************************************************************************************
2364 
2365 
2366 
2367 
2368 //=================================================================================================
2369 //
2370 // MATHTRAIT SPECIALIZATIONS
2371 //
2372 //=================================================================================================
2373 
2374 //*************************************************************************************************
2376 template< typename T1, bool TF, typename T2 >
2377 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2378 {
2379  typedef DynamicVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2380  typedef DynamicVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2381 };
2383 //*************************************************************************************************
2384 
2385 
2386 
2387 
2388 //=================================================================================================
2389 //
2390 // SUBVECTORTRAIT SPECIALIZATIONS
2391 //
2392 //=================================================================================================
2393 
2394 //*************************************************************************************************
2396 template< typename T1, bool TF >
2397 struct SubvectorTrait< DynamicVector<T1,TF> >
2398 {
2399  typedef DynamicVector<T1,TF> Type;
2400 };
2402 //*************************************************************************************************
2403 
2404 } // namespace blaze
2405 
2406 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:108
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
Type *BLAZE_RESTRICT v_
The dynamically allocated vector elements.
Definition: DynamicVector.h:396
Constraint on the data type.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
EnableIf< IsIntegral< T > >::Type store(T *address, const typename Store< T, sizeof(T)>::Type &value)
Aligned store of a vector of integral values.
Definition: Store.h:223
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.
Pointer data()
Low-level data access to the vector elements.
Definition: DynamicVector.h:680
Header file for the SparseVector base class.
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: DynamicVector.h:1081
void smpSubAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:152
void swap(DynamicVector &v)
Swapping the contents of two vectors.
Definition: DynamicVector.h:1276
Iterator begin()
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:710
void clear()
Clearing the vector.
Definition: DynamicVector.h:1120
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DynamicVector.h:173
void smpMultAssign(DenseVector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:179
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
const Type * ConstPointer
Pointer to a constant vector value.
Definition: DynamicVector.h:179
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
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:160
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:1464
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2557
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
~DynamicVector()
The destructor for DynamicVector.
Definition: DynamicVector.h:622
ConstIterator cbegin() const
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:738
void smpAddAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:122
Header file for the DisableIf class template.
This ResultType
Result type for expression template evaluations.
Definition: DynamicVector.h:170
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: DynamicVector.h:1158
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:4605
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: DynamicVector.h:1361
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the dense vector.
Definition: DynamicVector.h:1495
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicVector.h:174
#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.
Header file for the DenseIterator class template.
Header file for the subvector trait.
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:1102
size_t size() const
Returns the current size/dimension of the vector.
Definition: DynamicVector.h:1050
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: DynamicVector.h:180
size_t size_
The current size/dimension of the vector.
Definition: DynamicVector.h:394
#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:176
#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:177
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
size_t adjustCapacity(size_t minCapacity) const
Adjusting the new capacity of the vector according to its data type Type.
Definition: DynamicVector.h:1293
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1403
System settings for streaming (non-temporal stores)
DynamicVector()
The default constructor for DynamicVector.
Definition: DynamicVector.h:430
Header file for the EnableIf class template.
EnableIf< IsIntegral< T > >::Type storeu(T *address, const typename Storeu< T, sizeof(T)>::Type &value)
Unaligned store of a vector of integral values.
Definition: Storeu.h:216
Header file for the serial shim.
Header file for the IsVectorizable type trait.
void smpAssign(DenseMatrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:92
Header file for the IsNumeric type trait.
size_t capacity_
The maximum capacity of the vector.
Definition: DynamicVector.h:395
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DynamicVector.h:1343
Header file for the IsSparseVector type trait.
EnableIf< IsIntegral< T > >::Type stream(T *address, const typename Stream< T, sizeof(T)>::Type &value)
Aligned, non-temporal store of a vector of integral values.
Definition: Stream.h:218
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
ConstIterator cend() const
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:780
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:4671
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: DynamicVector.h:164
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:175
#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:1206
Header file for the reset shim.
Header file for the cache size of the target architecture.
#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:2411
Header file for the isDefault shim.
System settings for the restrict keyword.
Type ElementType
Type of the vector elements.
Definition: DynamicVector.h:172
Type * Pointer
Pointer to a non-constant vector value.
Definition: DynamicVector.h:178
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: DynamicVector.h:1064
Constraint on the data type.
void reserve(size_t n)
Setting the minimum capacity of the vector.
Definition: DynamicVector.h:1224
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:84
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:1525
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:1323
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:108
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: DynamicVector.h:1380
Header file for basic type definitions.
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1434
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:752
const size_t SMP_DVECASSIGN_THRESHOLD
SMP dense vector assignment threshold.This threshold specifies when an assignment of a plain dense ve...
Definition: Thresholds.h:207
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:181
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
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: DynamicVector.h:646
DynamicVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: DynamicVector.h:171
DynamicVector< Type, TF > This
Type of this DynamicVector instance.
Definition: DynamicVector.h:169