All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynamicVector.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
23 #define _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <algorithm>
31 #include <cmath>
32 #include <fstream>
33 #include <ostream>
34 #include <stdexcept>
36 #include <blaze/math/Forward.h>
37 #include <blaze/math/Functions.h>
38 #include <blaze/math/Intrinsics.h>
40 #include <blaze/math/shims/IsNaN.h>
41 #include <blaze/math/shims/Reset.h>
51 #include <blaze/system/CacheSize.h>
52 #include <blaze/system/Restrict.h>
54 #include <blaze/util/Assert.h>
63 #include <blaze/util/DisableIf.h>
64 #include <blaze/util/EnableIf.h>
65 #include <blaze/util/Memory.h>
66 #include <blaze/util/mpl/If.h>
67 #include <blaze/util/Null.h>
68 #include <blaze/util/Template.h>
69 #include <blaze/util/Types.h>
75 
76 
77 namespace blaze {
78 
79 //=================================================================================================
80 //
81 // CLASS DEFINITION
82 //
83 //=================================================================================================
84 
85 //*************************************************************************************************
149 template< typename Type // Data type of the vector
150  , bool TF = defaultTransposeFlag > // Transpose flag
151 class DynamicVector : public DenseVector< DynamicVector<Type,TF>, TF >
152 {
153  private:
154  //**Type definitions****************************************************************************
156  //**********************************************************************************************
157 
158  public:
159  //**Type definitions****************************************************************************
161  typedef This ResultType;
163  typedef Type ElementType;
164  typedef typename IT::Type IntrinsicType;
165  typedef const Type& ReturnType;
166  typedef const DynamicVector& CompositeType;
167  typedef Type& Reference;
168  typedef const Type& ConstReference;
169  typedef Type* Iterator;
170  typedef const Type* ConstIterator;
171 
173 
175  //**********************************************************************************************
176 
177  //**Compilation flags***************************************************************************
179 
183  enum { vectorizable = IsVectorizable<Type>::value };
184  //**********************************************************************************************
185 
186  //**Constructors********************************************************************************
189  explicit inline DynamicVector();
190  explicit inline DynamicVector( size_t n );
191  explicit inline DynamicVector( size_t n, Type init );
192  inline DynamicVector( const DynamicVector& v );
193  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
194 
195  template< typename Other, size_t N >
196  explicit inline DynamicVector( const Other (&rhs)[N] );
198  //**********************************************************************************************
199 
200  //**Destructor**********************************************************************************
203  inline ~DynamicVector();
205  //**********************************************************************************************
206 
207  //**Data access functions***********************************************************************
210  inline Reference operator[]( size_t index );
211  inline ConstReference operator[]( size_t index ) const;
212  inline Type* data ();
213  inline const Type* data () const;
214  inline Iterator begin ();
215  inline ConstIterator begin () const;
216  inline ConstIterator cbegin() const;
217  inline Iterator end ();
218  inline ConstIterator end () const;
219  inline ConstIterator cend () const;
221  //**********************************************************************************************
222 
223  //**Assignment operators************************************************************************
226  template< typename Other, size_t N >
227  inline DynamicVector& operator=( const Other (&rhs)[N] );
228 
229  inline DynamicVector& operator= ( Type rhs );
230  inline DynamicVector& operator= ( const DynamicVector& rhs );
231  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
232  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& rhs );
233  template< typename VT > inline DynamicVector& operator-=( const Vector<VT,TF>& rhs );
234  template< typename VT > inline DynamicVector& operator*=( const Vector<VT,TF>& rhs );
235 
236  template< typename Other >
237  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
238  operator*=( Other rhs );
239 
240  template< typename Other >
241  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
242  operator/=( Other rhs );
244  //**********************************************************************************************
245 
246  //**Utility functions***************************************************************************
249  inline size_t size() const;
250  inline size_t capacity() const;
251  inline size_t nonZeros() const;
252  inline void reset();
253  inline void clear();
254  inline void resize( size_t n, bool preserve=true );
255  inline void extend( size_t n, bool preserve=true );
256  inline void reserve( size_t n );
257  inline LengthType length() const;
258  inline const Type sqrLength() const;
259  inline DynamicVector& normalize();
260  inline const DynamicVector getNormalized() const;
261  template< typename Other > inline DynamicVector& scale( Other scalar );
262  inline void swap( DynamicVector& v ) /* throw() */;
264  //**********************************************************************************************
265 
266  //**Read/Write functions************************************************************************
269  void read ( const char* file );
270  void write( const char* file, std::streamsize prec=6 ) const;
272  //**********************************************************************************************
273 
274  private:
275  //**********************************************************************************************
277 
278  template< typename VT >
279  struct VectorizedAssign {
280  enum { value = vectorizable && VT::vectorizable &&
282  };
284  //**********************************************************************************************
285 
286  //**********************************************************************************************
288 
289  template< typename VT >
290  struct VectorizedAddAssign {
291  enum { value = vectorizable && VT::vectorizable &&
292  IsSame<Type,typename VT::ElementType>::value &&
293  IntrinsicTrait<Type>::addition };
294  };
296  //**********************************************************************************************
297 
298  //**********************************************************************************************
300 
301  template< typename VT >
302  struct VectorizedSubAssign {
303  enum { value = vectorizable && VT::vectorizable &&
304  IsSame<Type,typename VT::ElementType>::value &&
305  IntrinsicTrait<Type>::subtraction };
306  };
308  //**********************************************************************************************
309 
310  //**********************************************************************************************
312 
313  template< typename VT >
314  struct VectorizedMultAssign {
315  enum { value = vectorizable && VT::vectorizable &&
316  IsSame<Type,typename VT::ElementType>::value &&
317  IntrinsicTrait<Type>::multiplication };
318  };
320  //**********************************************************************************************
321 
322  public:
323  //**Expression template evaluation functions****************************************************
326  template< typename Other > inline bool canAlias ( const Other* alias ) const;
327  template< typename Other > inline bool isAliased( const Other* alias ) const;
328  inline IntrinsicType get ( size_t index ) const;
329 
330  template< typename VT >
331  inline typename DisableIf< VectorizedAssign<VT> >::Type
332  assign( const DenseVector<VT,TF>& rhs );
333 
334  template< typename VT >
335  inline typename EnableIf< VectorizedAssign<VT> >::Type
336  assign( const DenseVector<VT,TF>& rhs );
337 
338  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
339 
340  template< typename VT >
341  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
342  addAssign( const DenseVector<VT,TF>& rhs );
343 
344  template< typename VT >
345  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
346  addAssign( const DenseVector<VT,TF>& rhs );
347 
348  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
349 
350  template< typename VT >
351  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
352  subAssign( const DenseVector<VT,TF>& rhs );
353 
354  template< typename VT >
355  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
356  subAssign( const DenseVector<VT,TF>& rhs );
357 
358  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
359 
360  template< typename VT >
361  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
362  multAssign( const DenseVector<VT,TF>& rhs );
363 
364  template< typename VT >
365  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
366  multAssign( const DenseVector<VT,TF>& rhs );
367 
368  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
370  //**********************************************************************************************
371 
372  private:
373  //**Utility functions***************************************************************************
376  inline size_t adjustCapacity( size_t minCapacity ) const;
378  //**********************************************************************************************
379 
380  //**Member variables****************************************************************************
383  size_t size_;
384  size_t capacity_;
386 
392  //**********************************************************************************************
393 
394  //**Compile time checks*************************************************************************
401  //**********************************************************************************************
402 };
403 //*************************************************************************************************
404 
405 
406 
407 
408 //=================================================================================================
409 //
410 // CONSTRUCTORS
411 //
412 //=================================================================================================
413 
414 //*************************************************************************************************
417 template< typename Type // Data type of the vector
418  , bool TF > // Transpose flag
420  : size_ ( 0UL ) // The current size/dimension of the vector
421  , capacity_( 0UL ) // The maximum capacity of the vector
422  , v_ ( NULL ) // The vector elements
423 {}
424 //*************************************************************************************************
425 
426 
427 //*************************************************************************************************
435 template< typename Type // Data type of the vector
436  , bool TF > // Transpose flag
438  : size_ ( n ) // The current size/dimension of the vector
439  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
440  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
441 {
442  if( IsBuiltin<Type>::value ) {
443  for( size_t i=size_; i<capacity_; ++i )
444  v_[i] = Type();
445  }
446 }
447 //*************************************************************************************************
448 
449 
450 //*************************************************************************************************
458 template< typename Type // Data type of the vector
459  , bool TF > // Transpose flag
460 inline DynamicVector<Type,TF>::DynamicVector( size_t n, Type init )
461  : size_ ( n ) // The current size/dimension of the vector
462  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
463  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
464 {
465  for( size_t i=0UL; i<size_; ++i )
466  v_[i] = init;
467 
468  if( IsBuiltin<Type>::value ) {
469  for( size_t i=size_; i<capacity_; ++i )
470  v_[i] = Type();
471  }
472 }
473 //*************************************************************************************************
474 
475 
476 //*************************************************************************************************
484 template< typename Type // Data type of the vector
485  , bool TF > // Transpose flag
487  : size_ ( v.size_ ) // The current size/dimension of the vector
488  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
489  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
490 {
491  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
492 
493  for( size_t i=0UL; i<capacity_; ++i )
494  v_[i] = v.v_[i];
495 }
496 //*************************************************************************************************
497 
498 
499 //*************************************************************************************************
504 template< typename Type // Data type of the vector
505  , bool TF > // Transpose flag
506 template< typename VT > // Type of the foreign vector
508  : size_ ( (~v).size() ) // The current size/dimension of the vector
509  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
510  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
511 {
512  using blaze::assign;
513 
514  if( IsBuiltin<Type>::value ) {
516  reset();
517  for( size_t i=size_; i<capacity_; ++i )
518  v_[i] = Type();
519  }
520 
521  assign( *this, ~v );
522 }
523 //*************************************************************************************************
524 
525 
526 //*************************************************************************************************
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 (&rhs)[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] = rhs[i];
552 
553  if( IsBuiltin<Type>::value ) {
554  for( size_t i=size_; i<capacity_; ++i )
555  v_[i] = Type();
556  }
557 }
558 //*************************************************************************************************
559 
560 
561 
562 
563 //=================================================================================================
564 //
565 // DESTRUCTOR
566 //
567 //=================================================================================================
568 
569 //*************************************************************************************************
572 template< typename Type // Data type of the vector
573  , bool TF > // Transpose flag
575 {
576  deallocate( v_ );
577 }
578 //*************************************************************************************************
579 
580 
581 
582 
583 //=================================================================================================
584 //
585 // DATA ACCESS FUNCTIONS
586 //
587 //=================================================================================================
588 
589 //*************************************************************************************************
595 template< typename Type // Data type of the vector
596  , bool TF > // Transpose flag
597 inline typename DynamicVector<Type,TF>::Reference
599 {
600  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
601  return v_[index];
602 }
603 //*************************************************************************************************
604 
605 
606 //*************************************************************************************************
612 template< typename Type // Data type of the vector
613  , bool TF > // Transpose flag
616 {
617  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
618  return v_[index];
619 }
620 //*************************************************************************************************
621 
622 
623 //*************************************************************************************************
628 template< typename Type // Data type of the vector
629  , bool TF > // Transpose flag
631 {
632  return v_;
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
642 template< typename Type // Data type of the vector
643  , bool TF > // Transpose flag
644 inline const Type* DynamicVector<Type,TF>::data() const
645 {
646  return v_;
647 }
648 //*************************************************************************************************
649 
650 
651 //*************************************************************************************************
656 template< typename Type // Data type of the vector
657  , bool TF > // Transpose flag
659 {
660  return v_;
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
670 template< typename Type // Data type of the vector
671  , bool TF > // Transpose flag
673 {
674  return v_;
675 }
676 //*************************************************************************************************
677 
678 
679 //*************************************************************************************************
684 template< typename Type // Data type of the vector
685  , bool TF > // Transpose flag
687 {
688  return v_;
689 }
690 //*************************************************************************************************
691 
692 
693 //*************************************************************************************************
698 template< typename Type // Data type of the vector
699  , bool TF > // Transpose flag
701 {
702  return v_ + size_;
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
712 template< typename Type // Data type of the vector
713  , bool TF > // Transpose flag
715 {
716  return v_ + size_;
717 }
718 //*************************************************************************************************
719 
720 
721 //*************************************************************************************************
726 template< typename Type // Data type of the vector
727  , bool TF > // Transpose flag
729 {
730  return v_ + size_;
731 }
732 //*************************************************************************************************
733 
734 
735 
736 
737 //=================================================================================================
738 //
739 // ASSIGNMENT OPERATORS
740 //
741 //=================================================================================================
742 
743 //*************************************************************************************************
760 template< typename Type // Data type of the vector
761  , bool TF > // Transpose flag
762 template< typename Other // Data type of the initialization array
763  , size_t N > // Dimension of the initialization array
765 {
766  resize( N, false );
767 
768  for( size_t i=0UL; i<N; ++i )
769  v_[i] = rhs[i];
770 
771  return *this;
772 }
773 //*************************************************************************************************
774 
775 
776 //*************************************************************************************************
782 template< typename Type // Data type of the vector
783  , bool TF > // Transpose flag
785 {
786  for( size_t i=0UL; i<size_; ++i )
787  v_[i] = rhs;
788  return *this;
789 }
790 //*************************************************************************************************
791 
792 
793 //*************************************************************************************************
802 template< typename Type // Data type of the vector
803  , bool TF > // Transpose flag
805 {
806  if( &rhs == this ) return *this;
807 
808  resize( rhs.size_, false );
809 
810  for( size_t i=0UL; i<size_; ++i )
811  v_[i] = rhs.v_[i];
812 
813  return *this;
814 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
826 template< typename Type // Data type of the vector
827  , bool TF > // Transpose flag
828 template< typename VT > // Type of the right-hand side vector
830 {
831  using blaze::assign;
832 
833  if( (~rhs).canAlias( this ) ) {
834  DynamicVector tmp( ~rhs );
835  swap( tmp );
836  }
837  else {
838  resize( (~rhs).size(), false );
840  reset();
841  assign( *this, ~rhs );
842  }
843 
844  return *this;
845 }
846 //*************************************************************************************************
847 
848 
849 //*************************************************************************************************
859 template< typename Type // Data type of the vector
860  , bool TF > // Transpose flag
861 template< typename VT > // Type of the right-hand side vector
863 {
864  using blaze::addAssign;
865 
866  if( (~rhs).size() != size_ )
867  throw std::invalid_argument( "Vector sizes do not match" );
868 
869  if( (~rhs).canAlias( this ) ) {
870  typename VT::ResultType tmp( ~rhs );
871  addAssign( *this, tmp );
872  }
873  else {
874  addAssign( *this, ~rhs );
875  }
876 
877  return *this;
878 }
879 //*************************************************************************************************
880 
881 
882 //*************************************************************************************************
893 template< typename Type // Data type of the vector
894  , bool TF > // Transpose flag
895 template< typename VT > // Type of the right-hand side vector
897 {
898  using blaze::subAssign;
899 
900  if( (~rhs).size() != size_ )
901  throw std::invalid_argument( "Vector sizes do not match" );
902 
903  if( (~rhs).canAlias( this ) ) {
904  typename VT::ResultType tmp( ~rhs );
905  subAssign( *this, tmp );
906  }
907  else {
908  subAssign( *this, ~rhs );
909  }
910 
911  return *this;
912 }
913 //*************************************************************************************************
914 
915 
916 //*************************************************************************************************
927 template< typename Type // Data type of the vector
928  , bool TF > // Transpose flag
929 template< typename VT > // Type of the right-hand side vector
931 {
932  using blaze::assign;
933 
934  if( (~rhs).size() != size_ )
935  throw std::invalid_argument( "Vector sizes do not match" );
936 
937  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
938  DynamicVector<Type,TF> tmp( *this * (~rhs) );
939  swap( tmp );
940  }
941  else {
942  assign( *this, *this * (~rhs) );
943  }
944 
945  return *this;
946 }
947 //*************************************************************************************************
948 
949 
950 //*************************************************************************************************
957 template< typename Type // Data type of the vector
958  , bool TF > // Transpose flag
959 template< typename Other > // Data type of the right-hand side scalar
960 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
962 {
963  return operator=( (*this) * rhs );
964 }
965 //*************************************************************************************************
966 
967 
968 //*************************************************************************************************
977 template< typename Type // Data type of the vector
978  , bool TF > // Transpose flag
979 template< typename Other > // Data type of the right-hand side scalar
980 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
982 {
983  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
984 
985  return operator=( (*this) / rhs );
986 }
987 //*************************************************************************************************
988 
989 
990 
991 
992 //=================================================================================================
993 //
994 // UTILITY FUNCTIONS
995 //
996 //=================================================================================================
997 
998 //*************************************************************************************************
1003 template< typename Type // Data type of the vector
1004  , bool TF > // Transpose flag
1005 inline size_t DynamicVector<Type,TF>::size() const
1006 {
1007  return size_;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1017 template< typename Type // Data type of the vector
1018  , bool TF > // Transpose flag
1020 {
1021  return capacity_;
1022 }
1023 //*************************************************************************************************
1024 
1025 
1026 //*************************************************************************************************
1034 template< typename Type // Data type of the vector
1035  , bool TF > // Transpose flag
1037 {
1038  size_t nonzeros( 0 );
1039 
1040  for( size_t i=0UL; i<size_; ++i ) {
1041  if( !isDefault( v_[i] ) )
1042  ++nonzeros;
1043  }
1044 
1045  return nonzeros;
1046 }
1047 //*************************************************************************************************
1048 
1049 
1050 //*************************************************************************************************
1055 template< typename Type // Data type of the vector
1056  , bool TF > // Transpose flag
1058 {
1059  using blaze::reset;
1060  for( size_t i=0UL; i<size_; ++i )
1061  reset( v_[i] );
1062 }
1063 //*************************************************************************************************
1064 
1065 
1066 //*************************************************************************************************
1073 template< typename Type // Data type of the vector
1074  , bool TF > // Transpose flag
1076 {
1077  size_ = 0UL;
1078 }
1079 //*************************************************************************************************
1080 
1081 
1082 //*************************************************************************************************
1109 template< typename Type // Data type of the vector
1110  , bool TF > // Transpose flag
1111 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1112 {
1113  if( n > capacity_ )
1114  {
1115  // Allocating a new array
1116  const size_t newCapacity( adjustCapacity( n ) );
1117  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1118 
1119  // Initializing the new array
1120  if( preserve ) {
1121  std::copy( v_, v_+size_, tmp );
1122  }
1123 
1124  if( IsBuiltin<Type>::value ) {
1125  for( size_t i=size_; i<newCapacity; ++i )
1126  tmp[i] = Type();
1127  }
1128 
1129  // Replacing the old array
1130  std::swap( v_, tmp );
1131  deallocate( tmp );
1132  capacity_ = newCapacity;
1133  }
1134 
1135  size_ = n;
1136 }
1137 //*************************************************************************************************
1138 
1139 
1140 //*************************************************************************************************
1152 template< typename Type // Data type of the vector
1153  , bool TF > // Transpose flag
1154 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1155 {
1156  resize( size_+n, preserve );
1157 }
1158 //*************************************************************************************************
1159 
1160 
1161 //*************************************************************************************************
1170 template< typename Type // Data type of the vector
1171  , bool TF > // Transpose flag
1172 inline void DynamicVector<Type,TF>::reserve( size_t n )
1173 {
1174  if( n > capacity_ )
1175  {
1176  // Allocating a new array
1177  const size_t newCapacity( adjustCapacity( n ) );
1178  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1179 
1180  // Initializing the new array
1181  std::copy( v_, v_+size_, tmp );
1182 
1183  if( IsBuiltin<Type>::value ) {
1184  for( size_t i=size_; i<newCapacity; ++i )
1185  tmp[i] = Type();
1186  }
1187 
1188  // Replacing the old array
1189  std::swap( tmp, v_ );
1190  deallocate( tmp );
1191  capacity_ = newCapacity;
1192  }
1193 }
1194 //*************************************************************************************************
1195 
1196 
1197 //*************************************************************************************************
1227 template< typename Type // Data type of the vector
1228  , bool TF > // Transpose flag
1229 #ifndef WIN32
1231 #else
1233 #endif
1234 {
1236 
1237  LengthType sum( 0 );
1238  for( size_t i=0UL; i<size_; ++i )
1239  sum += v_[i] * v_[i];
1240  return std::sqrt( sum );
1241 }
1242 //*************************************************************************************************
1243 
1244 
1245 //*************************************************************************************************
1255 template< typename Type // Data type of the vector
1256  , bool TF > // Transpose flag
1257 inline const Type DynamicVector<Type,TF>::sqrLength() const
1258 {
1260 
1261  Type sum( 0 );
1262  for( size_t i=0UL; i<size_; ++i )
1263  sum += v_[i] * v_[i];
1264  return sum;
1265 }
1266 //*************************************************************************************************
1267 
1268 
1269 //*************************************************************************************************
1278 template< typename Type // Data type of the vector
1279  , bool TF > // Transpose flag
1281 {
1283 
1284  const Type len( length() );
1285 
1286  if( len == Type(0) )
1287  return *this;
1288 
1289  const Type ilen( Type(1) / len );
1290 
1291  for( size_t i=0; i<size_; ++i )
1292  v_[i] *= ilen;
1293 
1294  return *this;
1295 }
1296 //*************************************************************************************************
1297 
1298 
1299 //*************************************************************************************************
1308 template< typename Type // Data type of the vector
1309  , bool TF > // Transpose flag
1311 {
1313 
1314  const Type len( length() );
1315 
1316  if( len == Type(0) )
1317  return *this;
1318 
1319  const Type ilen( Type(1) / len );
1320  DynamicVector tmp( size_ );
1321 
1322  for( size_t i=0UL; i<size_; ++i )
1323  tmp[i] = v_[i] * ilen;
1324 
1325  return tmp;
1326 }
1327 //*************************************************************************************************
1328 
1329 
1330 //*************************************************************************************************
1336 template< typename Type // Data type of the vector
1337  , bool TF > // Transpose flag
1338 template< typename Other > // Data type of the scalar value
1340 {
1341  for( size_t i=0UL; i<size_; ++i )
1342  v_[i] *= scalar;
1343  return *this;
1344 }
1345 //*************************************************************************************************
1346 
1347 
1348 //*************************************************************************************************
1355 template< typename Type // Data type of the vector
1356  , bool TF > // Transpose flag
1357 inline void DynamicVector<Type,TF>::swap( DynamicVector& v ) /* throw() */
1358 {
1359  std::swap( size_, v.size_ );
1360  std::swap( capacity_, v.capacity_ );
1361  std::swap( v_, v.v_ );
1362 }
1363 //*************************************************************************************************
1364 
1365 
1366 //*************************************************************************************************
1372 template< typename Type // Data type of the vector
1373  , bool TF > // Transpose flag
1374 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const
1375 {
1377  return minCapacity + ( IT::size - ( minCapacity % IT::size ) ) % IT::size;
1378  else return minCapacity;
1379 }
1380 //*************************************************************************************************
1381 
1382 
1383 
1384 
1385 //=================================================================================================
1386 //
1387 // READ/WRITE FUNCTIONS
1388 //
1389 //=================================================================================================
1390 
1391 //*************************************************************************************************
1412 template< typename Type // Data type of the vector
1413  , bool TF > // Transpose flag
1414 void DynamicVector<Type,TF>::read( const char* file )
1415 {
1416  std::ifstream in( file, std::ifstream::in );
1417  if( !in.is_open() ) {
1418  throw std::runtime_error( "File could not be opened!" );
1419  }
1420 
1421  size_t vsize(0UL);
1422  if( !(in >> vsize) || vsize == 0UL ) {
1423  throw std::runtime_error( "Vector size could not be extracted!" );
1424  }
1425 
1426  DynamicVector tmp( vsize );
1427 
1428  for( size_t i=0UL; i<vsize; ++i ) {
1429  if( !(in >> tmp.v_[i]) ) {
1430  throw std::runtime_error( "Error during vector extraction!" );
1431  }
1432  }
1433 
1434  swap( tmp );
1435 
1436  in.close();
1437 }
1438 //*************************************************************************************************
1439 
1440 
1441 //*************************************************************************************************
1464 template< typename Type // Data type of the vector
1465  , bool TF > // Transpose flag
1466 void DynamicVector<Type,TF>::write( const char* file, std::streamsize prec ) const
1467 {
1468  std::ofstream out( file, std::ofstream::out | std::ostream::trunc );
1469  if( !out.is_open() ) {
1470  throw std::runtime_error( "File could not be opened!" );
1471  }
1472 
1473  out << size_ << "\n";
1474 
1475  out.precision( prec );
1476  for( size_t i=0UL; i<size_; ++i )
1477  out << v_[i] << "\n";
1478 
1479  out.close();
1480 }
1481 //*************************************************************************************************
1482 
1483 
1484 
1485 
1486 //=================================================================================================
1487 //
1488 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1489 //
1490 //=================================================================================================
1491 
1492 //*************************************************************************************************
1502 template< typename Type // Data type of the vector
1503  , bool TF > // Transpose flag
1504 template< typename Other > // Data type of the foreign expression
1505 inline bool DynamicVector<Type,TF>::canAlias( const Other* alias ) const
1506 {
1507  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1508 }
1509 //*************************************************************************************************
1510 
1511 
1512 //*************************************************************************************************
1522 template< typename Type // Data type of the vector
1523  , bool TF > // Transpose flag
1524 template< typename Other > // Data type of the foreign expression
1525 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const
1526 {
1527  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1528 }
1529 //*************************************************************************************************
1530 
1531 
1532 //*************************************************************************************************
1543 template< typename Type // Data type of the vector
1544  , bool TF > // Transpose flag
1546  DynamicVector<Type,TF>::get( size_t index ) const
1547 {
1549 
1550  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1551  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1552  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1553 
1554  return load( &v_[index] );
1555 }
1556 //*************************************************************************************************
1557 
1558 
1559 //*************************************************************************************************
1570 template< typename Type // Data type of the vector
1571  , bool TF > // Transpose flag
1572 template< typename VT > // Type of the right-hand side dense vector
1573 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1575 {
1576  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1577 
1578  const size_t iend( (~rhs).size() & size_t(-2) );
1579  for( size_t i=0UL; i<iend; i+=2UL ) {
1580  v_[i ] = (~rhs)[i ];
1581  v_[i+1UL] = (~rhs)[i+1UL];
1582  }
1583  if( iend < (~rhs).size() )
1584  v_[iend] = (~rhs)[iend];
1585 }
1586 //*************************************************************************************************
1587 
1588 
1589 //*************************************************************************************************
1600 template< typename Type // Data type of the vector
1601  , bool TF > // Transpose flag
1602 template< typename VT > // Type of the right-hand side dense vector
1603 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1605 {
1606  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1607 
1609 
1610  if( size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1611  {
1612  for( size_t i=0UL; i<size_; i+=IT::size ) {
1613  stream( v_+i, (~rhs).get(i) );
1614  }
1615  }
1616  else
1617  {
1618  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1619  const size_t iend( size_ & size_t(-IT::size*4) );
1620 
1621  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1622  store( v_+i , (~rhs).get(i ) );
1623  store( v_+i+IT::size , (~rhs).get(i+IT::size ) );
1624  store( v_+i+IT::size*2UL, (~rhs).get(i+IT::size*2UL) );
1625  store( v_+i+IT::size*3UL, (~rhs).get(i+IT::size*3UL) );
1626  }
1627  for( size_t i=iend; i<size_; i+=IT::size ) {
1628  store( v_+i, (~rhs).get(i) );
1629  }
1630  }
1631 }
1632 //*************************************************************************************************
1633 
1634 
1635 //*************************************************************************************************
1646 template< typename Type // Data type of the vector
1647  , bool TF > // Transpose flag
1648 template< typename VT > // Type of the right-hand side sparse vector
1650 {
1651  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1652 
1653  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1654  v_[element->index()] = element->value();
1655 }
1656 //*************************************************************************************************
1657 
1658 
1659 //*************************************************************************************************
1670 template< typename Type // Data type of the vector
1671  , bool TF > // Transpose flag
1672 template< typename VT > // Type of the right-hand side dense vector
1673 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1675 {
1676  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1677 
1678  const size_t iend( (~rhs).size() & size_t(-2) );
1679  for( size_t i=0UL; i<iend; i+=2UL ) {
1680  v_[i ] += (~rhs)[i ];
1681  v_[i+1UL] += (~rhs)[i+1UL];
1682  }
1683  if( iend < (~rhs).size() )
1684  v_[iend] += (~rhs)[iend];
1685 }
1686 //*************************************************************************************************
1687 
1688 
1689 //*************************************************************************************************
1700 template< typename Type // Data type of the vector
1701  , bool TF > // Transpose flag
1702 template< typename VT > // Type of the right-hand side dense vector
1703 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1705 {
1706  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1707 
1709 
1710  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1711  const size_t iend( size_ & size_t(-IT::size*4) );
1712 
1713  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1714  store( v_+i , load(v_+i ) + (~rhs).get(i ) );
1715  store( v_+i+IT::size , load(v_+i+IT::size ) + (~rhs).get(i+IT::size ) );
1716  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) + (~rhs).get(i+IT::size*2UL) );
1717  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) + (~rhs).get(i+IT::size*3UL) );
1718  }
1719  for( size_t i=iend; i<size_; i+=IT::size ) {
1720  store( v_+i, load(v_+i) + (~rhs).get(i) );
1721  }
1722 }
1723 //*************************************************************************************************
1724 
1725 
1726 //*************************************************************************************************
1737 template< typename Type // Data type of the vector
1738  , bool TF > // Transpose flag
1739 template< typename VT > // Type of the right-hand side sparse vector
1741 {
1742  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1743 
1744  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1745  v_[element->index()] += element->value();
1746 }
1747 //*************************************************************************************************
1748 
1749 
1750 //*************************************************************************************************
1761 template< typename Type // Data type of the vector
1762  , bool TF > // Transpose flag
1763 template< typename VT > // Type of the right-hand side dense vector
1764 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1766 {
1767  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1768 
1769  const size_t iend( (~rhs).size() & size_t(-2) );
1770  for( size_t i=0UL; i<iend; i+=2UL ) {
1771  v_[i ] -= (~rhs)[i ];
1772  v_[i+1UL] -= (~rhs)[i+1UL];
1773  }
1774  if( iend < (~rhs).size() )
1775  v_[iend] -= (~rhs)[iend];
1776 }
1777 //*************************************************************************************************
1778 
1779 
1780 //*************************************************************************************************
1791 template< typename Type // Data type of the vector
1792  , bool TF > // Transpose flag
1793 template< typename VT > // Type of the right-hand side dense vector
1794 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1796 {
1797  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1798 
1800 
1801  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1802  const size_t iend( size_ & size_t(-IT::size*4) );
1803 
1804  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1805  store( v_+i , load(v_+i ) - (~rhs).get(i ) );
1806  store( v_+i+IT::size , load(v_+i+IT::size ) - (~rhs).get(i+IT::size ) );
1807  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) - (~rhs).get(i+IT::size*2UL) );
1808  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) - (~rhs).get(i+IT::size*3UL) );
1809  }
1810  for( size_t i=iend; i<size_; i+=IT::size ) {
1811  store( v_+i, load(v_+i) - (~rhs).get(i) );
1812  }
1813 }
1814 //*************************************************************************************************
1815 
1816 
1817 //*************************************************************************************************
1828 template< typename Type // Data type of the vector
1829  , bool TF > // Transpose flag
1830 template< typename VT > // Type of the right-hand side sparse vector
1832 {
1833  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1834 
1835  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1836  v_[element->index()] -= element->value();
1837 }
1838 //*************************************************************************************************
1839 
1840 
1841 //*************************************************************************************************
1852 template< typename Type // Data type of the vector
1853  , bool TF > // Transpose flag
1854 template< typename VT > // Type of the right-hand side dense vector
1855 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1857 {
1858  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1859 
1860  const size_t iend( (~rhs).size() & size_t(-2) );
1861  for( size_t i=0UL; i<iend; i+=2UL ) {
1862  v_[i ] *= (~rhs)[i ];
1863  v_[i+1UL] *= (~rhs)[i+1UL];
1864  }
1865  if( iend < (~rhs).size() )
1866  v_[iend] *= (~rhs)[iend];
1867 }
1868 //*************************************************************************************************
1869 
1870 
1871 //*************************************************************************************************
1882 template< typename Type // Data type of the vector
1883  , bool TF > // Transpose flag
1884 template< typename VT > // Type of the right-hand side dense vector
1885 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1887 {
1888  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1889 
1891 
1892  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1893  const size_t iend( size_ & size_t(-IT::size*4) );
1894 
1895  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1896  store( v_+i , load(v_+i ) * (~rhs).get(i ) );
1897  store( v_+i+IT::size , load(v_+i+IT::size ) * (~rhs).get(i+IT::size ) );
1898  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) * (~rhs).get(i+IT::size*2UL) );
1899  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) * (~rhs).get(i+IT::size*3UL) );
1900  }
1901  for( size_t i=iend; i<size_; i+=IT::size ) {
1902  store( v_+i, load(v_+i) * (~rhs).get(i) );
1903  }
1904 }
1905 //*************************************************************************************************
1906 
1907 
1908 //*************************************************************************************************
1919 template< typename Type // Data type of the vector
1920  , bool TF > // Transpose flag
1921 template< typename VT > // Type of the right-hand side sparse vector
1923 {
1924  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1925 
1926  const DynamicVector tmp( *this );
1927 
1928  reset();
1929 
1930  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1931  v_[element->index()] = tmp[element->index()] * element->value();
1932 }
1933 //*************************************************************************************************
1934 
1935 
1936 
1937 
1938 //=================================================================================================
1939 //
1940 // DYNAMICVECTOR OPERATORS
1941 //
1942 //=================================================================================================
1943 
1944 //*************************************************************************************************
1947 template< typename Type, bool TF >
1948 inline void reset( DynamicVector<Type,TF>& v );
1949 
1950 template< typename Type, bool TF >
1951 inline void clear( DynamicVector<Type,TF>& v );
1952 
1953 template< typename Type, bool TF >
1954 inline bool isnan( const DynamicVector<Type,TF>& v );
1955 
1956 template< typename Type, bool TF >
1957 inline bool isDefault( const DynamicVector<Type,TF>& v );
1958 
1959 template< typename Type, bool TF >
1960 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */;
1962 //*************************************************************************************************
1963 
1964 
1965 //*************************************************************************************************
1972 template< typename Type // Data type of the vector
1973  , bool TF > // Transpose flag
1975 {
1976  v.reset();
1977 }
1978 //*************************************************************************************************
1979 
1980 
1981 //*************************************************************************************************
1988 template< typename Type // Data type of the vector
1989  , bool TF > // Transpose flag
1991 {
1992  v.clear();
1993 }
1994 //*************************************************************************************************
1995 
1996 
1997 //*************************************************************************************************
2014 template< typename Type // Data type of the vector
2015  , bool TF > // Transpose flag
2016 inline bool isnan( const DynamicVector<Type,TF>& v )
2017 {
2018  for( size_t i=0UL; i<v.size(); ++i ) {
2019  if( isnan( v[i] ) ) return true;
2020  }
2021  return false;
2022 }
2023 //*************************************************************************************************
2024 
2025 
2026 //*************************************************************************************************
2045 template< typename Type // Data type of the vector
2046  , bool TF > // Transpose flag
2047 inline bool isDefault( const DynamicVector<Type,TF>& v )
2048 {
2049  for( size_t i=0UL; i<v.size(); ++i )
2050  if( !isDefault( v[i] ) ) return false;
2051  return true;
2052 }
2053 //*************************************************************************************************
2054 
2055 
2056 //*************************************************************************************************
2065 template< typename Type // Data type of the vector
2066  , bool TF > // Transpose flag
2067 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */
2068 {
2069  a.swap( b );
2070 }
2071 //*************************************************************************************************
2072 
2073 
2074 
2075 
2076 //=================================================================================================
2077 //
2078 // ISRESIZABLE SPECIALIZATIONS
2079 //
2080 //=================================================================================================
2081 
2082 //*************************************************************************************************
2084 template< typename T, bool TF >
2085 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2086 {
2087  enum { value = 1 };
2088  typedef TrueType Type;
2089 };
2090 
2091 template< typename T, bool TF >
2092 struct IsResizable< const DynamicVector<T,TF> > : public TrueType
2093 {
2094  enum { value = 1 };
2095  typedef TrueType Type;
2096 };
2097 
2098 template< typename T, bool TF >
2099 struct IsResizable< volatile DynamicVector<T,TF> > : public TrueType
2100 {
2101  enum { value = 1 };
2102  typedef TrueType Type;
2103 };
2104 
2105 template< typename T, bool TF >
2106 struct IsResizable< const volatile DynamicVector<T,TF> > : public TrueType
2107 {
2108  enum { value = 1 };
2109  typedef TrueType Type;
2110 };
2112 //*************************************************************************************************
2113 
2114 
2115 
2116 
2117 //=================================================================================================
2118 //
2119 // ADDTRAIT SPECIALIZATIONS
2120 //
2121 //=================================================================================================
2122 
2123 //*************************************************************************************************
2125 template< typename T1, bool TF, typename T2, size_t N >
2126 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2127 {
2128  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2129 };
2130 
2131 template< typename T1, size_t N, bool TF, typename T2 >
2132 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2133 {
2134  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2135 };
2136 
2137 template< typename T1, bool TF, typename T2 >
2138 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2139 {
2140  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2141 };
2143 //*************************************************************************************************
2144 
2145 
2146 
2147 
2148 //=================================================================================================
2149 //
2150 // SUBTRAIT SPECIALIZATIONS
2151 //
2152 //=================================================================================================
2153 
2154 //*************************************************************************************************
2156 template< typename T1, bool TF, typename T2, size_t N >
2157 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2158 {
2159  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2160 };
2161 
2162 template< typename T1, size_t N, bool TF, typename T2 >
2163 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2164 {
2165  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2166 };
2167 
2168 template< typename T1, bool TF, typename T2 >
2169 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2170 {
2171  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2172 };
2174 //*************************************************************************************************
2175 
2176 
2177 
2178 
2179 //=================================================================================================
2180 //
2181 // MULTTRAIT SPECIALIZATIONS
2182 //
2183 //=================================================================================================
2184 
2185 //*************************************************************************************************
2187 template< typename T1, bool TF, typename T2 >
2188 struct MultTrait< DynamicVector<T1,TF>, T2 >
2189 {
2190  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2192 };
2193 
2194 template< typename T1, typename T2, bool TF >
2195 struct MultTrait< T1, DynamicVector<T2,TF> >
2196 {
2197  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2199 };
2200 
2201 template< typename T1, bool TF, typename T2, size_t N >
2202 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2203 {
2204  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2205 };
2206 
2207 template< typename T1, typename T2, size_t N >
2208 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2209 {
2210  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2211 };
2212 
2213 template< typename T1, typename T2, size_t N >
2214 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2215 {
2216  typedef typename MultTrait<T1,T2>::Type Type;
2217 };
2218 
2219 template< typename T1, size_t N, bool TF, typename T2 >
2220 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2221 {
2222  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2223 };
2224 
2225 template< typename T1, size_t N, typename T2 >
2226 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2227 {
2228  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2229 };
2230 
2231 template< typename T1, size_t N, typename T2 >
2232 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2233 {
2234  typedef typename MultTrait<T1,T2>::Type Type;
2235 };
2236 
2237 template< typename T1, bool TF, typename T2 >
2238 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2239 {
2240  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2241 };
2242 
2243 template< typename T1, typename T2 >
2244 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2245 {
2246  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2247 };
2248 
2249 template< typename T1, typename T2 >
2250 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2251 {
2252  typedef typename MultTrait<T1,T2>::Type Type;
2253 };
2255 //*************************************************************************************************
2256 
2257 
2258 
2259 
2260 //=================================================================================================
2261 //
2262 // CROSSTRAIT SPECIALIZATIONS
2263 //
2264 //=================================================================================================
2265 
2266 //*************************************************************************************************
2268 template< typename T1, typename T2 >
2269 struct CrossTrait< DynamicVector<T1,false>, StaticVector<T2,3UL,false> >
2270 {
2271  private:
2272  typedef typename MultTrait<T1,T2>::Type T;
2273 
2274  public:
2275  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2276 };
2277 
2278 template< typename T1, typename T2 >
2279 struct CrossTrait< StaticVector<T1,3UL,false>, DynamicVector<T2,false> >
2280 {
2281  private:
2282  typedef typename MultTrait<T1,T2>::Type T;
2283 
2284  public:
2285  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2286 };
2287 
2288 template< typename T1, typename T2 >
2289 struct CrossTrait< DynamicVector<T1,false>, DynamicVector<T2,false> >
2290 {
2291  private:
2292  typedef typename MultTrait<T1,T2>::Type T;
2293 
2294  public:
2295  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2296 };
2298 //*************************************************************************************************
2299 
2300 
2301 
2302 
2303 //=================================================================================================
2304 //
2305 // DIVTRAIT SPECIALIZATIONS
2306 //
2307 //=================================================================================================
2308 
2309 //*************************************************************************************************
2311 template< typename T1, bool TF, typename T2 >
2312 struct DivTrait< DynamicVector<T1,TF>, T2 >
2313 {
2314  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
2316 };
2318 //*************************************************************************************************
2319 
2320 
2321 
2322 
2323 //=================================================================================================
2324 //
2325 // MATHTRAIT SPECIALIZATIONS
2326 //
2327 //=================================================================================================
2328 
2329 //*************************************************************************************************
2331 template< typename T1, bool TF, typename T2 >
2332 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2333 {
2334  typedef DynamicVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2335  typedef DynamicVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2336 };
2338 //*************************************************************************************************
2339 
2340 } // namespace blaze
2341 
2342 #endif