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;
180  //**********************************************************************************************
181 
182  //**Compilation flags***************************************************************************
184 
188  enum { vectorizable = IsVectorizable<Type>::value };
189 
191 
194  enum { smpAssignable = 1 };
195  //**********************************************************************************************
196 
197  //**Constructors********************************************************************************
200  explicit inline DynamicVector();
201  explicit inline DynamicVector( size_t n );
202  explicit inline DynamicVector( size_t n, const Type& init );
203  template< typename Other > explicit inline DynamicVector( size_t n, const Other* array );
204 
205  template< typename Other, size_t N >
206  explicit inline DynamicVector( const Other (&array)[N] );
207 
208  inline DynamicVector( const DynamicVector& v );
209  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
211  //**********************************************************************************************
212 
213  //**Destructor**********************************************************************************
216  inline ~DynamicVector();
218  //**********************************************************************************************
219 
220  //**Data access functions***********************************************************************
223  inline Reference operator[]( size_t index );
224  inline ConstReference operator[]( size_t index ) const;
225  inline Type* data ();
226  inline const Type* data () const;
227  inline Iterator begin ();
228  inline ConstIterator begin () const;
229  inline ConstIterator cbegin() const;
230  inline Iterator end ();
231  inline ConstIterator end () const;
232  inline ConstIterator cend () const;
234  //**********************************************************************************************
235 
236  //**Assignment operators************************************************************************
239  template< typename Other, size_t N >
240  inline DynamicVector& operator=( const Other (&array)[N] );
241 
242  inline DynamicVector& operator= ( const Type& rhs );
243  inline DynamicVector& operator= ( const DynamicVector& rhs );
244  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
245  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& 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 
249  template< typename Other >
250  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
251  operator*=( Other rhs );
252 
253  template< typename Other >
254  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
255  operator/=( Other rhs );
257  //**********************************************************************************************
258 
259  //**Utility functions***************************************************************************
262  inline size_t size() const;
263  inline size_t capacity() const;
264  inline size_t nonZeros() const;
265  inline void reset();
266  inline void clear();
267  inline void resize( size_t n, bool preserve=true );
268  inline void extend( size_t n, bool preserve=true );
269  inline void reserve( size_t n );
270  template< typename Other > inline DynamicVector& scale( Other scalar );
271  inline void swap( DynamicVector& v ) /* throw() */;
273  //**********************************************************************************************
274 
275  private:
276  //**********************************************************************************************
278  template< typename VT >
280  struct VectorizedAssign {
281  enum { value = vectorizable && VT::vectorizable &&
282  IsSame<Type,typename VT::ElementType>::value };
283  };
285  //**********************************************************************************************
286 
287  //**********************************************************************************************
289  template< typename VT >
291  struct VectorizedAddAssign {
292  enum { value = vectorizable && VT::vectorizable &&
293  IsSame<Type,typename VT::ElementType>::value &&
294  IntrinsicTrait<Type>::addition };
295  };
297  //**********************************************************************************************
298 
299  //**********************************************************************************************
301  template< typename VT >
303  struct VectorizedSubAssign {
304  enum { value = vectorizable && VT::vectorizable &&
305  IsSame<Type,typename VT::ElementType>::value &&
306  IntrinsicTrait<Type>::subtraction };
307  };
309  //**********************************************************************************************
310 
311  //**********************************************************************************************
313  template< typename VT >
315  struct VectorizedMultAssign {
316  enum { value = vectorizable && VT::vectorizable &&
317  IsSame<Type,typename VT::ElementType>::value &&
318  IntrinsicTrait<Type>::multiplication };
319  };
321  //**********************************************************************************************
322 
323  public:
324  //**Expression template evaluation functions****************************************************
327  template< typename Other > inline bool canAlias ( const Other* alias ) const;
328  template< typename Other > inline bool isAliased( const Other* alias ) const;
329 
330  inline bool isAligned () const;
331  inline bool canSMPAssign() const;
332 
333  inline IntrinsicType load ( size_t index ) const;
334  inline IntrinsicType loadu ( size_t index ) const;
335  inline void store ( size_t index, const IntrinsicType& value );
336  inline void storeu( size_t index, const IntrinsicType& value );
337  inline void stream( size_t index, const IntrinsicType& value );
338 
339  template< typename VT >
340  inline typename DisableIf< VectorizedAssign<VT> >::Type
341  assign( const DenseVector<VT,TF>& rhs );
342 
343  template< typename VT >
344  inline typename EnableIf< VectorizedAssign<VT> >::Type
345  assign( const DenseVector<VT,TF>& rhs );
346 
347  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
348 
349  template< typename VT >
350  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
351  addAssign( const DenseVector<VT,TF>& rhs );
352 
353  template< typename VT >
354  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
355  addAssign( const DenseVector<VT,TF>& rhs );
356 
357  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
358 
359  template< typename VT >
360  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
361  subAssign( const DenseVector<VT,TF>& rhs );
362 
363  template< typename VT >
364  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
365  subAssign( const DenseVector<VT,TF>& rhs );
366 
367  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
368 
369  template< typename VT >
370  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
371  multAssign( const DenseVector<VT,TF>& rhs );
372 
373  template< typename VT >
374  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
375  multAssign( const DenseVector<VT,TF>& rhs );
376 
377  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
379  //**********************************************************************************************
380 
381  private:
382  //**Utility functions***************************************************************************
385  inline size_t adjustCapacity( size_t minCapacity ) const;
387  //**********************************************************************************************
388 
389  //**Member variables****************************************************************************
392  size_t size_;
393  size_t capacity_;
395 
401  //**********************************************************************************************
402 
403  //**Compile time checks*************************************************************************
410  //**********************************************************************************************
411 };
412 //*************************************************************************************************
413 
414 
415 
416 
417 //=================================================================================================
418 //
419 // CONSTRUCTORS
420 //
421 //=================================================================================================
422 
423 //*************************************************************************************************
426 template< typename Type // Data type of the vector
427  , bool TF > // Transpose flag
429  : size_ ( 0UL ) // The current size/dimension of the vector
430  , capacity_( 0UL ) // The maximum capacity of the vector
431  , v_ ( NULL ) // The vector elements
432 {}
433 //*************************************************************************************************
434 
435 
436 //*************************************************************************************************
444 template< typename Type // Data type of the vector
445  , bool TF > // Transpose flag
447  : size_ ( n ) // The current size/dimension of the vector
448  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
449  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
450 {
451  if( IsNumeric<Type>::value ) {
452  for( size_t i=size_; i<capacity_; ++i )
453  v_[i] = Type();
454  }
455 }
456 //*************************************************************************************************
457 
458 
459 //*************************************************************************************************
467 template< typename Type // Data type of the vector
468  , bool TF > // Transpose flag
469 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Type& init )
470  : size_ ( n ) // The current size/dimension of the vector
471  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
472  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
473 {
474  for( size_t i=0UL; i<size_; ++i )
475  v_[i] = init;
476 
477  if( IsNumeric<Type>::value ) {
478  for( size_t i=size_; i<capacity_; ++i )
479  v_[i] = Type();
480  }
481 }
482 //*************************************************************************************************
483 
484 
485 //*************************************************************************************************
505 template< typename Type // Data type of the vector
506  , bool TF > // Transpose flag
507 template< typename Other > // Data type of the initialization array
508 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Other* array )
509  : size_ ( n ) // The current size/dimension of the vector
510  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
511  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
512 {
513  for( size_t i=0UL; i<n; ++i )
514  v_[i] = array[i];
515 
516  if( IsNumeric<Type>::value ) {
517  for( size_t i=n; i<capacity_; ++i )
518  v_[i] = Type();
519  }
520 }
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
541 template< typename Type // Data type of the vector
542  , bool TF > // Transpose flag
543 template< typename Other // Data type of the initialization array
544  , size_t N > // Dimension of the initialization array
545 inline DynamicVector<Type,TF>::DynamicVector( const Other (&array)[N] )
546  : size_ ( N ) // The current size/dimension of the vector
547  , capacity_( adjustCapacity( N ) ) // The maximum capacity of the vector
548  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
549 {
550  for( size_t i=0UL; i<N; ++i )
551  v_[i] = array[i];
552 
553  if( IsNumeric<Type>::value ) {
554  for( size_t i=N; i<capacity_; ++i )
555  v_[i] = Type();
556  }
557 }
558 //*************************************************************************************************
559 
560 
561 //*************************************************************************************************
569 template< typename Type // Data type of the vector
570  , bool TF > // Transpose flag
572  : size_ ( v.size_ ) // The current size/dimension of the vector
573  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
574  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
575 {
576  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
577 
578  for( size_t i=0UL; i<capacity_; ++i )
579  v_[i] = v.v_[i];
580 }
581 //*************************************************************************************************
582 
583 
584 //*************************************************************************************************
589 template< typename Type // Data type of the vector
590  , bool TF > // Transpose flag
591 template< typename VT > // Type of the foreign vector
593  : size_ ( (~v).size() ) // The current size/dimension of the vector
594  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
595  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
596 {
597  if( IsNumeric<Type>::value ) {
599  reset();
600  for( size_t i=size_; i<capacity_; ++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
696 inline const Type* DynamicVector<Type,TF>::data() const
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  smpAssign( *this, *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 //*************************************************************************************************
1154 template< typename Type // Data type of the vector
1155  , bool TF > // Transpose flag
1156 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1157 {
1158  if( n > capacity_ )
1159  {
1160  // Allocating a new array
1161  const size_t newCapacity( adjustCapacity( n ) );
1162  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1163 
1164  // Initializing the new array
1165  if( preserve ) {
1166  std::copy( v_, v_+size_, tmp );
1167  }
1168 
1169  if( IsNumeric<Type>::value ) {
1170  for( size_t i=size_; i<newCapacity; ++i )
1171  tmp[i] = Type();
1172  }
1173 
1174  // Replacing the old array
1175  std::swap( v_, tmp );
1176  deallocate( tmp );
1177  capacity_ = newCapacity;
1178  }
1179  else if( IsNumeric<Type>::value && n < size_ )
1180  {
1181  for( size_t i=n; i<size_; ++i )
1182  v_[i] = Type();
1183  }
1184 
1185  size_ = n;
1186 }
1187 //*************************************************************************************************
1188 
1189 
1190 //*************************************************************************************************
1202 template< typename Type // Data type of the vector
1203  , bool TF > // Transpose flag
1204 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1205 {
1206  resize( size_+n, preserve );
1207 }
1208 //*************************************************************************************************
1209 
1210 
1211 //*************************************************************************************************
1220 template< typename Type // Data type of the vector
1221  , bool TF > // Transpose flag
1222 inline void DynamicVector<Type,TF>::reserve( size_t n )
1223 {
1224  if( n > capacity_ )
1225  {
1226  // Allocating a new array
1227  const size_t newCapacity( adjustCapacity( n ) );
1228  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1229 
1230  // Initializing the new array
1231  std::copy( v_, v_+size_, tmp );
1232 
1233  if( IsNumeric<Type>::value ) {
1234  for( size_t i=size_; i<newCapacity; ++i )
1235  tmp[i] = Type();
1236  }
1237 
1238  // Replacing the old array
1239  std::swap( tmp, v_ );
1240  deallocate( tmp );
1241  capacity_ = newCapacity;
1242  }
1243 }
1244 //*************************************************************************************************
1245 
1246 
1247 //*************************************************************************************************
1253 template< typename Type // Data type of the vector
1254  , bool TF > // Transpose flag
1255 template< typename Other > // Data type of the scalar value
1257 {
1258  for( size_t i=0UL; i<size_; ++i )
1259  v_[i] *= scalar;
1260  return *this;
1261 }
1262 //*************************************************************************************************
1263 
1264 
1265 //*************************************************************************************************
1272 template< typename Type // Data type of the vector
1273  , bool TF > // Transpose flag
1274 inline void DynamicVector<Type,TF>::swap( DynamicVector& v ) /* throw() */
1275 {
1276  std::swap( size_, v.size_ );
1278  std::swap( v_, v.v_ );
1279 }
1280 //*************************************************************************************************
1281 
1282 
1283 //*************************************************************************************************
1289 template< typename Type // Data type of the vector
1290  , bool TF > // Transpose flag
1291 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const
1292 {
1294  return minCapacity + ( IT::size - ( minCapacity % IT::size ) ) % IT::size;
1295  else return minCapacity;
1296 }
1297 //*************************************************************************************************
1298 
1299 
1300 
1301 
1302 //=================================================================================================
1303 //
1304 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1305 //
1306 //=================================================================================================
1307 
1308 //*************************************************************************************************
1318 template< typename Type // Data type of the vector
1319  , bool TF > // Transpose flag
1320 template< typename Other > // Data type of the foreign expression
1321 inline bool DynamicVector<Type,TF>::canAlias( const Other* alias ) const
1322 {
1323  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1324 }
1325 //*************************************************************************************************
1326 
1327 
1328 //*************************************************************************************************
1338 template< typename Type // Data type of the vector
1339  , bool TF > // Transpose flag
1340 template< typename Other > // Data type of the foreign expression
1341 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const
1342 {
1343  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1344 }
1345 //*************************************************************************************************
1346 
1347 
1348 //*************************************************************************************************
1357 template< typename Type // Data type of the vector
1358  , bool TF > // Transpose flag
1360 {
1361  return true;
1362 }
1363 //*************************************************************************************************
1364 
1365 
1366 //*************************************************************************************************
1376 template< typename Type // Data type of the vector
1377  , bool TF > // Transpose flag
1379 {
1380  return ( size() > OPENMP_DVECASSIGN_THRESHOLD );
1381 }
1382 //*************************************************************************************************
1383 
1384 
1385 //*************************************************************************************************
1398 template< typename Type // Data type of the vector
1399  , bool TF > // Transpose flag
1401  DynamicVector<Type,TF>::load( size_t index ) const
1402 {
1403  using blaze::load;
1404 
1406 
1407  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1408  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1409  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1410 
1411  return load( v_+index );
1412 }
1413 //*************************************************************************************************
1414 
1415 
1416 //*************************************************************************************************
1429 template< typename Type // Data type of the vector
1430  , bool TF > // Transpose flag
1432  DynamicVector<Type,TF>::loadu( size_t index ) const
1433 {
1434  using blaze::loadu;
1435 
1437 
1438  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1439  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1440 
1441  return loadu( v_+index );
1442 }
1443 //*************************************************************************************************
1444 
1445 
1446 //*************************************************************************************************
1460 template< typename Type // Data type of the vector
1461  , bool TF > // Transpose flag
1462 inline void DynamicVector<Type,TF>::store( size_t index, const IntrinsicType& value )
1463 {
1464  using blaze::store;
1465 
1467 
1468  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1469  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1470  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1471 
1472  store( v_+index, value );
1473 }
1474 //*************************************************************************************************
1475 
1476 
1477 //*************************************************************************************************
1491 template< typename Type // Data type of the vector
1492  , bool TF > // Transpose flag
1493 inline void DynamicVector<Type,TF>::storeu( size_t index, const IntrinsicType& value )
1494 {
1495  using blaze::storeu;
1496 
1498 
1499  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1500  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1501 
1502  storeu( v_+index, value );
1503 }
1504 //*************************************************************************************************
1505 
1506 
1507 //*************************************************************************************************
1521 template< typename Type // Data type of the vector
1522  , bool TF > // Transpose flag
1523 inline void DynamicVector<Type,TF>::stream( size_t index, const IntrinsicType& value )
1524 {
1525  using blaze::stream;
1526 
1528 
1529  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1530  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1531  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1532 
1533  stream( v_+index, value );
1534 }
1535 //*************************************************************************************************
1536 
1537 
1538 //*************************************************************************************************
1549 template< typename Type // Data type of the vector
1550  , bool TF > // Transpose flag
1551 template< typename VT > // Type of the right-hand side dense vector
1552 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1554 {
1555  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1556 
1557  const size_t iend( (~rhs).size() & size_t(-2) );
1558  for( size_t i=0UL; i<iend; i+=2UL ) {
1559  v_[i ] = (~rhs)[i ];
1560  v_[i+1UL] = (~rhs)[i+1UL];
1561  }
1562  if( iend < (~rhs).size() )
1563  v_[iend] = (~rhs)[iend];
1564 }
1565 //*************************************************************************************************
1566 
1567 
1568 //*************************************************************************************************
1579 template< typename Type // Data type of the vector
1580  , bool TF > // Transpose flag
1581 template< typename VT > // Type of the right-hand side dense vector
1582 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1584 {
1585  using blaze::store;
1586  using blaze::stream;
1587 
1588  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1589 
1591 
1592  if( useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1593  {
1594  for( size_t i=0UL; i<size_; i+=IT::size ) {
1595  stream( v_+i, (~rhs).load(i) );
1596  }
1597  }
1598  else
1599  {
1600  const size_t iend( size_ & size_t(-IT::size*4) );
1601  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1602 
1603  typename VT::ConstIterator it( (~rhs).begin() );
1604  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1605  store( v_+i , it.load() ); it += IT::size;
1606  store( v_+i+IT::size , it.load() ); it += IT::size;
1607  store( v_+i+IT::size*2UL, it.load() ); it += IT::size;
1608  store( v_+i+IT::size*3UL, it.load() ); it += IT::size;
1609  }
1610  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1611  store( v_+i, it.load() );
1612  }
1613  }
1614 }
1615 //*************************************************************************************************
1616 
1617 
1618 //*************************************************************************************************
1629 template< typename Type // Data type of the vector
1630  , bool TF > // Transpose flag
1631 template< typename VT > // Type of the right-hand side sparse vector
1633 {
1634  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1635 
1636  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1637  v_[element->index()] = element->value();
1638 }
1639 //*************************************************************************************************
1640 
1641 
1642 //*************************************************************************************************
1653 template< typename Type // Data type of the vector
1654  , bool TF > // Transpose flag
1655 template< typename VT > // Type of the right-hand side dense vector
1656 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1658 {
1659  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1660 
1661  const size_t iend( (~rhs).size() & size_t(-2) );
1662  for( size_t i=0UL; i<iend; i+=2UL ) {
1663  v_[i ] += (~rhs)[i ];
1664  v_[i+1UL] += (~rhs)[i+1UL];
1665  }
1666  if( iend < (~rhs).size() )
1667  v_[iend] += (~rhs)[iend];
1668 }
1669 //*************************************************************************************************
1670 
1671 
1672 //*************************************************************************************************
1683 template< typename Type // Data type of the vector
1684  , bool TF > // Transpose flag
1685 template< typename VT > // Type of the right-hand side dense vector
1686 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1688 {
1689  using blaze::load;
1690  using blaze::store;
1691 
1692  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1693 
1695 
1696  const size_t iend( size_ & size_t(-IT::size*4) );
1697  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1698 
1699  typename VT::ConstIterator it( (~rhs).begin() );
1700  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1701  store( v_+i , load(v_+i ) + it.load() ); it += IT::size;
1702  store( v_+i+IT::size , load(v_+i+IT::size ) + it.load() ); it += IT::size;
1703  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) + it.load() ); it += IT::size;
1704  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) + it.load() ); it += IT::size;
1705  }
1706  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1707  store( v_+i, load(v_+i) + it.load() );
1708  }
1709 }
1710 //*************************************************************************************************
1711 
1712 
1713 //*************************************************************************************************
1724 template< typename Type // Data type of the vector
1725  , bool TF > // Transpose flag
1726 template< typename VT > // Type of the right-hand side sparse vector
1728 {
1729  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1730 
1731  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1732  v_[element->index()] += element->value();
1733 }
1734 //*************************************************************************************************
1735 
1736 
1737 //*************************************************************************************************
1748 template< typename Type // Data type of the vector
1749  , bool TF > // Transpose flag
1750 template< typename VT > // Type of the right-hand side dense vector
1751 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1753 {
1754  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1755 
1756  const size_t iend( (~rhs).size() & size_t(-2) );
1757  for( size_t i=0UL; i<iend; i+=2UL ) {
1758  v_[i ] -= (~rhs)[i ];
1759  v_[i+1UL] -= (~rhs)[i+1UL];
1760  }
1761  if( iend < (~rhs).size() )
1762  v_[iend] -= (~rhs)[iend];
1763 }
1764 //*************************************************************************************************
1765 
1766 
1767 //*************************************************************************************************
1778 template< typename Type // Data type of the vector
1779  , bool TF > // Transpose flag
1780 template< typename VT > // Type of the right-hand side dense vector
1781 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1783 {
1784  using blaze::load;
1785  using blaze::store;
1786 
1787  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1788 
1790 
1791  const size_t iend( size_ & size_t(-IT::size*4) );
1792  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1793 
1794  typename VT::ConstIterator it( (~rhs).begin() );
1795  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1796  store( v_+i , load(v_+i ) - it.load() ); it += IT::size;
1797  store( v_+i+IT::size , load(v_+i+IT::size ) - it.load() ); it += IT::size;
1798  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) - it.load() ); it += IT::size;
1799  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) - it.load() ); it += IT::size;
1800  }
1801  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1802  store( v_+i, load(v_+i) - it.load() );
1803  }
1804 }
1805 //*************************************************************************************************
1806 
1807 
1808 //*************************************************************************************************
1819 template< typename Type // Data type of the vector
1820  , bool TF > // Transpose flag
1821 template< typename VT > // Type of the right-hand side sparse vector
1823 {
1824  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1825 
1826  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1827  v_[element->index()] -= element->value();
1828 }
1829 //*************************************************************************************************
1830 
1831 
1832 //*************************************************************************************************
1843 template< typename Type // Data type of the vector
1844  , bool TF > // Transpose flag
1845 template< typename VT > // Type of the right-hand side dense vector
1846 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1848 {
1849  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1850 
1851  const size_t iend( (~rhs).size() & size_t(-2) );
1852  for( size_t i=0UL; i<iend; i+=2UL ) {
1853  v_[i ] *= (~rhs)[i ];
1854  v_[i+1UL] *= (~rhs)[i+1UL];
1855  }
1856  if( iend < (~rhs).size() )
1857  v_[iend] *= (~rhs)[iend];
1858 }
1859 //*************************************************************************************************
1860 
1861 
1862 //*************************************************************************************************
1873 template< typename Type // Data type of the vector
1874  , bool TF > // Transpose flag
1875 template< typename VT > // Type of the right-hand side dense vector
1876 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1878 {
1879  using blaze::load;
1880  using blaze::store;
1881 
1882  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1883 
1885 
1886  const size_t iend( size_ & size_t(-IT::size*4) );
1887  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == iend, "Invalid end calculation" );
1888 
1889  typename VT::ConstIterator it( (~rhs).begin() );
1890  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1891  store( v_+i , load(v_+i ) * it.load() ); it += IT::size;
1892  store( v_+i+IT::size , load(v_+i+IT::size ) * it.load() ); it += IT::size;
1893  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) * it.load() ); it += IT::size;
1894  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) * it.load() ); it += IT::size;
1895  }
1896  for( size_t i=iend; i<size_; i+=IT::size, it+=IT::size ) {
1897  store( v_+i, load(v_+i) * it.load() );
1898  }
1899 }
1900 //*************************************************************************************************
1901 
1902 
1903 //*************************************************************************************************
1914 template< typename Type // Data type of the vector
1915  , bool TF > // Transpose flag
1916 template< typename VT > // Type of the right-hand side sparse vector
1918 {
1919  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1920 
1921  const DynamicVector tmp( *this );
1922 
1923  reset();
1924 
1925  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1926  v_[element->index()] = tmp[element->index()] * element->value();
1927 }
1928 //*************************************************************************************************
1929 
1930 
1931 
1932 
1933 //=================================================================================================
1934 //
1935 // DYNAMICVECTOR OPERATORS
1936 //
1937 //=================================================================================================
1938 
1939 //*************************************************************************************************
1942 template< typename Type, bool TF >
1943 inline void reset( DynamicVector<Type,TF>& v );
1944 
1945 template< typename Type, bool TF >
1946 inline void clear( DynamicVector<Type,TF>& v );
1947 
1948 template< typename Type, bool TF >
1949 inline bool isDefault( const DynamicVector<Type,TF>& v );
1950 
1951 template< typename Type, bool TF >
1952 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */;
1954 //*************************************************************************************************
1955 
1956 
1957 //*************************************************************************************************
1964 template< typename Type // Data type of the vector
1965  , bool TF > // Transpose flag
1967 {
1968  v.reset();
1969 }
1970 //*************************************************************************************************
1971 
1972 
1973 //*************************************************************************************************
1980 template< typename Type // Data type of the vector
1981  , bool TF > // Transpose flag
1983 {
1984  v.clear();
1985 }
1986 //*************************************************************************************************
1987 
1988 
1989 //*************************************************************************************************
2008 template< typename Type // Data type of the vector
2009  , bool TF > // Transpose flag
2010 inline bool isDefault( const DynamicVector<Type,TF>& v )
2011 {
2012  for( size_t i=0UL; i<v.size(); ++i )
2013  if( !isDefault( v[i] ) ) return false;
2014  return true;
2015 }
2016 //*************************************************************************************************
2017 
2018 
2019 //*************************************************************************************************
2028 template< typename Type // Data type of the vector
2029  , bool TF > // Transpose flag
2030 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */
2031 {
2032  a.swap( b );
2033 }
2034 //*************************************************************************************************
2035 
2036 
2037 
2038 
2039 //=================================================================================================
2040 //
2041 // ISRESIZABLE SPECIALIZATIONS
2042 //
2043 //=================================================================================================
2044 
2045 //*************************************************************************************************
2047 template< typename T, bool TF >
2048 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2049 {
2050  enum { value = 1 };
2051  typedef TrueType Type;
2052 };
2053 
2054 template< typename T, bool TF >
2055 struct IsResizable< const DynamicVector<T,TF> > : public TrueType
2056 {
2057  enum { value = 1 };
2058  typedef TrueType Type;
2059 };
2060 
2061 template< typename T, bool TF >
2062 struct IsResizable< volatile DynamicVector<T,TF> > : public TrueType
2063 {
2064  enum { value = 1 };
2065  typedef TrueType Type;
2066 };
2067 
2068 template< typename T, bool TF >
2069 struct IsResizable< const volatile DynamicVector<T,TF> > : public TrueType
2070 {
2071  enum { value = 1 };
2072  typedef TrueType Type;
2073 };
2075 //*************************************************************************************************
2076 
2077 
2078 
2079 
2080 //=================================================================================================
2081 //
2082 // ADDTRAIT SPECIALIZATIONS
2083 //
2084 //=================================================================================================
2085 
2086 //*************************************************************************************************
2088 template< typename T1, bool TF, typename T2, size_t N >
2089 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2090 {
2091  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2092 };
2093 
2094 template< typename T1, size_t N, bool TF, typename T2 >
2095 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2096 {
2097  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2098 };
2099 
2100 template< typename T1, bool TF, typename T2, size_t N >
2101 struct AddTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2102 {
2103  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2104 };
2105 
2106 template< typename T1, size_t N, bool TF, typename T2 >
2107 struct AddTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2108 {
2109  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2110 };
2111 
2112 template< typename T1, bool TF, typename T2 >
2113 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2114 {
2115  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2116 };
2118 //*************************************************************************************************
2119 
2120 
2121 
2122 
2123 //=================================================================================================
2124 //
2125 // SUBTRAIT SPECIALIZATIONS
2126 //
2127 //=================================================================================================
2128 
2129 //*************************************************************************************************
2131 template< typename T1, bool TF, typename T2, size_t N >
2132 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2133 {
2134  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2135 };
2136 
2137 template< typename T1, size_t N, bool TF, typename T2 >
2138 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2139 {
2140  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2141 };
2142 
2143 template< typename T1, bool TF, typename T2, size_t N >
2144 struct SubTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2145 {
2146  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2147 };
2148 
2149 template< typename T1, size_t N, bool TF, typename T2 >
2150 struct SubTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2151 {
2152  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2153 };
2154 
2155 template< typename T1, bool TF, typename T2 >
2156 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2157 {
2158  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2159 };
2161 //*************************************************************************************************
2162 
2163 
2164 
2165 
2166 //=================================================================================================
2167 //
2168 // MULTTRAIT SPECIALIZATIONS
2169 //
2170 //=================================================================================================
2171 
2172 //*************************************************************************************************
2174 template< typename T1, bool TF, typename T2 >
2175 struct MultTrait< DynamicVector<T1,TF>, T2 >
2176 {
2177  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2179 };
2180 
2181 template< typename T1, typename T2, bool TF >
2182 struct MultTrait< T1, DynamicVector<T2,TF> >
2183 {
2184  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2186 };
2187 
2188 template< typename T1, bool TF, typename T2, size_t N >
2189 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2190 {
2191  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2192 };
2193 
2194 template< typename T1, typename T2, size_t N >
2195 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2196 {
2197  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2198 };
2199 
2200 template< typename T1, typename T2, size_t N >
2201 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2202 {
2203  typedef typename MultTrait<T1,T2>::Type Type;
2204 };
2205 
2206 template< typename T1, size_t N, bool TF, typename T2 >
2207 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2208 {
2209  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2210 };
2211 
2212 template< typename T1, size_t N, typename T2 >
2213 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2214 {
2215  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2216 };
2217 
2218 template< typename T1, size_t N, typename T2 >
2219 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2220 {
2221  typedef typename MultTrait<T1,T2>::Type Type;
2222 };
2223 
2224 template< typename T1, bool TF, typename T2, size_t N >
2225 struct MultTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2226 {
2227  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2228 };
2229 
2230 template< typename T1, typename T2, size_t N >
2231 struct MultTrait< DynamicVector<T1,false>, HybridVector<T2,N,true> >
2232 {
2233  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2234 };
2235 
2236 template< typename T1, typename T2, size_t N >
2237 struct MultTrait< DynamicVector<T1,true>, HybridVector<T2,N,false> >
2238 {
2239  typedef typename MultTrait<T1,T2>::Type Type;
2240 };
2241 
2242 template< typename T1, size_t N, bool TF, typename T2 >
2243 struct MultTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2244 {
2245  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2246 };
2247 
2248 template< typename T1, size_t N, typename T2 >
2249 struct MultTrait< HybridVector<T1,N,false>, DynamicVector<T2,true> >
2250 {
2251  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2252 };
2253 
2254 template< typename T1, size_t N, typename T2 >
2255 struct MultTrait< HybridVector<T1,N,true>, DynamicVector<T2,false> >
2256 {
2257  typedef typename MultTrait<T1,T2>::Type Type;
2258 };
2259 
2260 template< typename T1, bool TF, typename T2 >
2261 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2262 {
2263  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2264 };
2265 
2266 template< typename T1, typename T2 >
2267 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2268 {
2269  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2270 };
2271 
2272 template< typename T1, typename T2 >
2273 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2274 {
2275  typedef typename MultTrait<T1,T2>::Type Type;
2276 };
2278 //*************************************************************************************************
2279 
2280 
2281 
2282 
2283 //=================================================================================================
2284 //
2285 // CROSSTRAIT SPECIALIZATIONS
2286 //
2287 //=================================================================================================
2288 
2289 //*************************************************************************************************
2291 template< typename T1, typename T2 >
2292 struct CrossTrait< DynamicVector<T1,false>, StaticVector<T2,3UL,false> >
2293 {
2294  private:
2295  typedef typename MultTrait<T1,T2>::Type T;
2296 
2297  public:
2298  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2299 };
2300 
2301 template< typename T1, typename T2 >
2302 struct CrossTrait< StaticVector<T1,3UL,false>, DynamicVector<T2,false> >
2303 {
2304  private:
2305  typedef typename MultTrait<T1,T2>::Type T;
2306 
2307  public:
2308  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2309 };
2310 
2311 template< typename T1, typename T2, size_t N >
2312 struct CrossTrait< DynamicVector<T1,false>, HybridVector<T2,N,false> >
2313 {
2314  private:
2315  typedef typename MultTrait<T1,T2>::Type T;
2316 
2317  public:
2318  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2319 };
2320 
2321 template< typename T1, size_t N, typename T2 >
2322 struct CrossTrait< HybridVector<T1,N,false>, DynamicVector<T2,false> >
2323 {
2324  private:
2325  typedef typename MultTrait<T1,T2>::Type T;
2326 
2327  public:
2328  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2329 };
2330 
2331 template< typename T1, typename T2 >
2332 struct CrossTrait< DynamicVector<T1,false>, DynamicVector<T2,false> >
2333 {
2334  private:
2335  typedef typename MultTrait<T1,T2>::Type T;
2336 
2337  public:
2338  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2339 };
2341 //*************************************************************************************************
2342 
2343 
2344 
2345 
2346 //=================================================================================================
2347 //
2348 // DIVTRAIT SPECIALIZATIONS
2349 //
2350 //=================================================================================================
2351 
2352 //*************************************************************************************************
2354 template< typename T1, bool TF, typename T2 >
2355 struct DivTrait< DynamicVector<T1,TF>, T2 >
2356 {
2357  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
2359 };
2361 //*************************************************************************************************
2362 
2363 
2364 
2365 
2366 //=================================================================================================
2367 //
2368 // MATHTRAIT SPECIALIZATIONS
2369 //
2370 //=================================================================================================
2371 
2372 //*************************************************************************************************
2374 template< typename T1, bool TF, typename T2 >
2375 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2376 {
2377  typedef DynamicVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2378  typedef DynamicVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2379 };
2381 //*************************************************************************************************
2382 
2383 
2384 
2385 
2386 //=================================================================================================
2387 //
2388 // SUBVECTORTRAIT SPECIALIZATIONS
2389 //
2390 //=================================================================================================
2391 
2392 //*************************************************************************************************
2394 template< typename T1, bool TF >
2395 struct SubvectorTrait< DynamicVector<T1,TF> >
2396 {
2397  typedef DynamicVector<T1,TF> Type;
2398 };
2400 //*************************************************************************************************
2401 
2402 } // namespace blaze
2403 
2404 #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
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:394
Constraint on the data type.
const size_t OPENMP_DVECASSIGN_THRESHOLD
OpenMP dense vector assignment threshold.This threshold specifies when an assignment of a plain dense...
Definition: Thresholds.h:200
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
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: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:151
void swap(DynamicVector &v)
Swapping the contents of two vectors.
Definition: DynamicVector.h:1274
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:4622
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: DynamicVector.h:173
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: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:1462
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2530
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:114
~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:121
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:170
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: DynamicVector.h:1156
Header file for the multiplication trait.
Header file for the dense vector SMP implementation.
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:4558
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: DynamicVector.h:1359
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the dense vector.
Definition: DynamicVector.h:1493
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
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 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:178
size_t size_
The current size/dimension of the vector.
Definition: DynamicVector.h:392
#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
size_t adjustCapacity(size_t minCapacity) const
Adjusting the new capacity of the vector according to its data type Type.
Definition: DynamicVector.h:1291
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1401
System settings for streaming (non-temporal stores)
DynamicVector()
The default constructor for DynamicVector.
Definition: DynamicVector.h:428
Header file for the EnableIf class template.
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:91
Header file for the IsNumeric type trait.
size_t capacity_
The maximum capacity of the vector.
Definition: DynamicVector.h:393
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: DynamicVector.h:1341
Header file for the IsSparseVector type trait.
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:4651
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:1204
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:2387
Header file for the isDefault shim.
System settings for the restrict keyword.
Type ElementType
Type of the vector elements.
Definition: DynamicVector.h:172
Type * data()
Low-level data access to the vector elements.
Definition: DynamicVector.h:680
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:1222
T * allocate(size_t size)
Aligned array allocation.
Definition: Memory.h:83
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:1523
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:1321
Header file for the default transpose flag for all vectors of the Blaze library.
Header file for the sparse vector SMP implementation.
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:2379
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: DynamicVector.h:1378
Header file for basic type definitions.
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: DynamicVector.h:1432
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 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:179
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
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:171
DynamicVector< Type, TF > This
Type of this DynamicVector instance.
Definition: DynamicVector.h:169