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/Functions.h>
37 #include <blaze/math/Intrinsics.h>
39 #include <blaze/math/shims/IsNaN.h>
40 #include <blaze/math/shims/Reset.h>
48 #include <blaze/math/Types.h>
52 #include <blaze/system/CacheSize.h>
53 #include <blaze/system/Restrict.h>
55 #include <blaze/util/Assert.h>
64 #include <blaze/util/DisableIf.h>
65 #include <blaze/util/EnableIf.h>
66 #include <blaze/util/Memory.h>
67 #include <blaze/util/mpl/If.h>
68 #include <blaze/util/Null.h>
69 #include <blaze/util/Template.h>
70 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS DEFINITION
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
150 template< typename Type // Data type of the vector
151  , bool TF = defaultTransposeFlag > // Transpose flag
152 class DynamicVector : public DenseVector< DynamicVector<Type,TF>, TF >
153 {
154  private:
155  //**Type definitions****************************************************************************
157  //**********************************************************************************************
158 
159  public:
160  //**Type definitions****************************************************************************
162  typedef This ResultType;
164  typedef Type ElementType;
165  typedef typename IT::Type IntrinsicType;
166  typedef const Type& ReturnType;
167  typedef const DynamicVector& CompositeType;
168  typedef Type& Reference;
169  typedef const Type& ConstReference;
170  typedef Type* Iterator;
171  typedef const Type* ConstIterator;
172 
174 
176  //**********************************************************************************************
177 
178  //**Compilation flags***************************************************************************
180 
184  enum { vectorizable = IsVectorizable<Type>::value };
185 
187 
190  enum { canAlias = 0 };
191  //**********************************************************************************************
192 
193  //**Constructors********************************************************************************
196  explicit inline DynamicVector();
197  explicit inline DynamicVector( size_t n );
198  explicit inline DynamicVector( size_t n, Type init );
199  inline DynamicVector( const DynamicVector& v );
200  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
201 
202  template< typename Other, size_t N >
203  explicit inline DynamicVector( const Other (&rhs)[N] );
205  //**********************************************************************************************
206 
207  //**Destructor**********************************************************************************
210  inline ~DynamicVector();
212  //**********************************************************************************************
213 
214  //**Data access functions***********************************************************************
217  inline Reference operator[]( size_t index );
218  inline ConstReference operator[]( size_t index ) const;
219  inline Type* data ();
220  inline const Type* data () const;
221  inline Iterator begin ();
222  inline ConstIterator begin () const;
223  inline ConstIterator cbegin() const;
224  inline Iterator end ();
225  inline ConstIterator end () const;
226  inline ConstIterator cend () const;
228  //**********************************************************************************************
229 
230  //**Assignment operators************************************************************************
233  template< typename Other, size_t N >
234  inline DynamicVector& operator=( const Other (&rhs)[N] );
235 
236  inline DynamicVector& operator= ( Type rhs );
237  inline DynamicVector& operator= ( const DynamicVector& rhs );
238  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
239  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& rhs );
240  template< typename VT > inline DynamicVector& operator-=( const Vector<VT,TF>& rhs );
241  template< typename VT > inline DynamicVector& operator*=( const Vector<VT,TF>& rhs );
242 
243  template< typename Other >
244  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
245  operator*=( Other rhs );
246 
247  template< typename Other >
248  inline typename EnableIf< IsNumeric<Other>, DynamicVector >::Type&
249  operator/=( Other rhs );
251  //**********************************************************************************************
252 
253  //**Utility functions***************************************************************************
256  inline size_t size() const;
257  inline size_t capacity() const;
258  inline size_t nonZeros() const;
259  inline void reset();
260  inline void clear();
261  inline void resize( size_t n, bool preserve=true );
262  inline void extend( size_t n, bool preserve=true );
263  inline void reserve( size_t n );
264  inline LengthType length() const;
265  inline const Type sqrLength() const;
266  inline DynamicVector& normalize();
267  inline const DynamicVector getNormalized() const;
268  template< typename Other > inline DynamicVector& scale( Other scalar );
269  inline void swap( DynamicVector& v ) /* throw() */;
271  //**********************************************************************************************
272 
273  //**Read/Write functions************************************************************************
276  void read ( const char* file );
277  void write( const char* file, std::streamsize prec=6 ) const;
279  //**********************************************************************************************
280 
281  private:
282  //**********************************************************************************************
284 
285  template< typename VT >
286  struct VectorizedAssign {
287  enum { value = vectorizable && VT::vectorizable &&
288  IsSame<Type,typename VT::ElementType>::value };
289  };
291  //**********************************************************************************************
292 
293  //**********************************************************************************************
295 
296  template< typename VT >
297  struct VectorizedAddAssign {
298  enum { value = vectorizable && VT::vectorizable &&
299  IsSame<Type,typename VT::ElementType>::value &&
300  IntrinsicTrait<Type>::addition };
301  };
303  //**********************************************************************************************
304 
305  //**********************************************************************************************
307 
308  template< typename VT >
309  struct VectorizedSubAssign {
310  enum { value = vectorizable && VT::vectorizable &&
311  IsSame<Type,typename VT::ElementType>::value &&
312  IntrinsicTrait<Type>::subtraction };
313  };
315  //**********************************************************************************************
316 
317  //**********************************************************************************************
319 
320  template< typename VT >
321  struct VectorizedMultAssign {
322  enum { value = vectorizable && VT::vectorizable &&
323  IsSame<Type,typename VT::ElementType>::value &&
324  IntrinsicTrait<Type>::multiplication };
325  };
327  //**********************************************************************************************
328 
329  public:
330  //**Expression template evaluation functions****************************************************
333  template< typename Other > inline bool isAliased( const Other* alias ) const;
334  inline IntrinsicType get ( size_t index ) const;
335 
336  template< typename VT >
337  inline typename DisableIf< VectorizedAssign<VT> >::Type
338  assign( const DenseVector<VT,TF>& rhs );
339 
340  template< typename VT >
341  inline typename EnableIf< VectorizedAssign<VT> >::Type
342  assign( const DenseVector<VT,TF>& rhs );
343 
344  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
345 
346  template< typename VT >
347  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
348  addAssign( const DenseVector<VT,TF>& rhs );
349 
350  template< typename VT >
351  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
352  addAssign( const DenseVector<VT,TF>& rhs );
353 
354  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
355 
356  template< typename VT >
357  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
358  subAssign( const DenseVector<VT,TF>& rhs );
359 
360  template< typename VT >
361  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
362  subAssign( const DenseVector<VT,TF>& rhs );
363 
364  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
365 
366  template< typename VT >
367  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
368  multAssign( const DenseVector<VT,TF>& rhs );
369 
370  template< typename VT >
371  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
372  multAssign( const DenseVector<VT,TF>& rhs );
373 
374  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
376  //**********************************************************************************************
377 
378  private:
379  //**Utility functions***************************************************************************
382  inline size_t adjustCapacity( size_t minCapacity ) const;
384  //**********************************************************************************************
385 
386  //**Member variables****************************************************************************
389  size_t size_;
390  size_t capacity_;
391  Type* BLAZE_RESTRICT v_;
392 
398  //**********************************************************************************************
399 
400  //**Compile time checks*************************************************************************
407  //**********************************************************************************************
408 };
409 //*************************************************************************************************
410 
411 
412 
413 
414 //=================================================================================================
415 //
416 // CONSTRUCTORS
417 //
418 //=================================================================================================
419 
420 //*************************************************************************************************
423 template< typename Type // Data type of the vector
424  , bool TF > // Transpose flag
426  : size_ ( 0UL ) // The current size/dimension of the vector
427  , capacity_( 0UL ) // The maximum capacity of the vector
428  , v_ ( NULL ) // The vector elements
429 {}
430 //*************************************************************************************************
431 
432 
433 //*************************************************************************************************
441 template< typename Type // Data type of the vector
442  , bool TF > // Transpose flag
444  : size_ ( n ) // The current size/dimension of the vector
445  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
446  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
447 {
448  if( IsBuiltin<Type>::value ) {
449  for( size_t i=size_; i<capacity_; ++i )
450  v_[i] = Type();
451  }
452 }
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
464 template< typename Type // Data type of the vector
465  , bool TF > // Transpose flag
466 inline DynamicVector<Type,TF>::DynamicVector( size_t n, Type init )
467  : size_ ( n ) // The current size/dimension of the vector
468  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
469  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
470 {
471  for( size_t i=0UL; i<size_; ++i )
472  v_[i] = init;
473 
474  if( IsBuiltin<Type>::value ) {
475  for( size_t i=size_; i<capacity_; ++i )
476  v_[i] = Type();
477  }
478 }
479 //*************************************************************************************************
480 
481 
482 //*************************************************************************************************
490 template< typename Type // Data type of the vector
491  , bool TF > // Transpose flag
493  : size_ ( v.size_ ) // The current size/dimension of the vector
494  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
495  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
496 {
497  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
498 
499  for( size_t i=0UL; i<capacity_; ++i )
500  v_[i] = v.v_[i];
501 }
502 //*************************************************************************************************
503 
504 
505 //*************************************************************************************************
510 template< typename Type // Data type of the vector
511  , bool TF > // Transpose flag
512 template< typename VT > // Type of the foreign vector
514  : size_ ( (~v).size() ) // The current size/dimension of the vector
515  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
516  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
517 {
518  using blaze::assign;
519 
520  if( IsBuiltin<Type>::value ) {
522  reset();
523  for( size_t i=size_; i<capacity_; ++i )
524  v_[i] = Type();
525  }
526 
527  assign( *this, ~v );
528 }
529 //*************************************************************************************************
530 
531 
532 //*************************************************************************************************
547 template< typename Type // Data type of the vector
548  , bool TF > // Transpose flag
549 template< typename Other // Data type of the initialization array
550  , size_t N > // Dimension of the initialization array
551 inline DynamicVector<Type,TF>::DynamicVector( const Other (&rhs)[N] )
552  : size_ ( N ) // The current size/dimension of the vector
553  , capacity_( adjustCapacity( N ) ) // The maximum capacity of the vector
554  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
555 {
556  for( size_t i=0UL; i<N; ++i )
557  v_[i] = rhs[i];
558 
559  if( IsBuiltin<Type>::value ) {
560  for( size_t i=size_; i<capacity_; ++i )
561  v_[i] = Type();
562  }
563 }
564 //*************************************************************************************************
565 
566 
567 
568 
569 //=================================================================================================
570 //
571 // DESTRUCTOR
572 //
573 //=================================================================================================
574 
575 //*************************************************************************************************
578 template< typename Type // Data type of the vector
579  , bool TF > // Transpose flag
581 {
582  deallocate( v_ );
583 }
584 //*************************************************************************************************
585 
586 
587 
588 
589 //=================================================================================================
590 //
591 // DATA ACCESS FUNCTIONS
592 //
593 //=================================================================================================
594 
595 //*************************************************************************************************
601 template< typename Type // Data type of the vector
602  , bool TF > // Transpose flag
603 inline typename DynamicVector<Type,TF>::Reference
605 {
606  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
607  return v_[index];
608 }
609 //*************************************************************************************************
610 
611 
612 //*************************************************************************************************
618 template< typename Type // Data type of the vector
619  , bool TF > // Transpose flag
622 {
623  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
624  return v_[index];
625 }
626 //*************************************************************************************************
627 
628 
629 //*************************************************************************************************
634 template< typename Type // Data type of the vector
635  , bool TF > // Transpose flag
637 {
638  return v_;
639 }
640 //*************************************************************************************************
641 
642 
643 //*************************************************************************************************
648 template< typename Type // Data type of the vector
649  , bool TF > // Transpose flag
650 inline const Type* DynamicVector<Type,TF>::data() const
651 {
652  return v_;
653 }
654 //*************************************************************************************************
655 
656 
657 //*************************************************************************************************
662 template< typename Type // Data type of the vector
663  , bool TF > // Transpose flag
665 {
666  return v_;
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
676 template< typename Type // Data type of the vector
677  , bool TF > // Transpose flag
679 {
680  return v_;
681 }
682 //*************************************************************************************************
683 
684 
685 //*************************************************************************************************
690 template< typename Type // Data type of the vector
691  , bool TF > // Transpose flag
693 {
694  return v_;
695 }
696 //*************************************************************************************************
697 
698 
699 //*************************************************************************************************
704 template< typename Type // Data type of the vector
705  , bool TF > // Transpose flag
707 {
708  return v_ + size_;
709 }
710 //*************************************************************************************************
711 
712 
713 //*************************************************************************************************
718 template< typename Type // Data type of the vector
719  , bool TF > // Transpose flag
721 {
722  return v_ + size_;
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
732 template< typename Type // Data type of the vector
733  , bool TF > // Transpose flag
735 {
736  return v_ + size_;
737 }
738 //*************************************************************************************************
739 
740 
741 
742 
743 //=================================================================================================
744 //
745 // ASSIGNMENT OPERATORS
746 //
747 //=================================================================================================
748 
749 //*************************************************************************************************
766 template< typename Type // Data type of the vector
767  , bool TF > // Transpose flag
768 template< typename Other // Data type of the initialization array
769  , size_t N > // Dimension of the initialization array
771 {
772  resize( N, false );
773 
774  for( size_t i=0UL; i<N; ++i )
775  v_[i] = rhs[i];
776 
777  return *this;
778 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
788 template< typename Type // Data type of the vector
789  , bool TF > // Transpose flag
791 {
792  for( size_t i=0UL; i<size_; ++i )
793  v_[i] = rhs;
794  return *this;
795 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
808 template< typename Type // Data type of the vector
809  , bool TF > // Transpose flag
811 {
812  if( &rhs == this ) return *this;
813 
814  resize( rhs.size_, false );
815 
816  for( size_t i=0UL; i<size_; ++i )
817  v_[i] = rhs.v_[i];
818 
819  return *this;
820 }
821 //*************************************************************************************************
822 
823 
824 //*************************************************************************************************
832 template< typename Type // Data type of the vector
833  , bool TF > // Transpose flag
834 template< typename VT > // Type of the right-hand side vector
836 {
837  using blaze::assign;
838 
839  if( CanAlias<VT>::value && (~rhs).isAliased( this ) ) {
840  DynamicVector tmp( ~rhs );
841  swap( tmp );
842  }
843  else {
844  resize( (~rhs).size(), false );
846  reset();
847  assign( *this, ~rhs );
848  }
849 
850  return *this;
851 }
852 //*************************************************************************************************
853 
854 
855 //*************************************************************************************************
865 template< typename Type // Data type of the vector
866  , bool TF > // Transpose flag
867 template< typename VT > // Type of the right-hand side vector
869 {
870  using blaze::addAssign;
871 
872  if( (~rhs).size() != size_ )
873  throw std::invalid_argument( "Vector sizes do not match" );
874 
875  if( CanAlias<VT>::value && (~rhs).isAliased( this ) ) {
876  typename VT::ResultType tmp( ~rhs );
877  addAssign( *this, tmp );
878  }
879  else {
880  addAssign( *this, ~rhs );
881  }
882 
883  return *this;
884 }
885 //*************************************************************************************************
886 
887 
888 //*************************************************************************************************
899 template< typename Type // Data type of the vector
900  , bool TF > // Transpose flag
901 template< typename VT > // Type of the right-hand side vector
903 {
904  using blaze::subAssign;
905 
906  if( (~rhs).size() != size_ )
907  throw std::invalid_argument( "Vector sizes do not match" );
908 
909  if( CanAlias<VT>::value && (~rhs).isAliased( this ) ) {
910  typename VT::ResultType tmp( ~rhs );
911  subAssign( *this, tmp );
912  }
913  else {
914  subAssign( *this, ~rhs );
915  }
916 
917  return *this;
918 }
919 //*************************************************************************************************
920 
921 
922 //*************************************************************************************************
933 template< typename Type // Data type of the vector
934  , bool TF > // Transpose flag
935 template< typename VT > // Type of the right-hand side vector
937 {
938  using blaze::assign;
939 
940  if( (~rhs).size() != size_ )
941  throw std::invalid_argument( "Vector sizes do not match" );
942 
943  if( CanAlias<VT>::value && (~rhs).isAliased( this ) ) {
944  DynamicVector<Type,TF> tmp( *this * (~rhs) );
945  swap( tmp );
946  }
947  else {
948  assign( *this, *this * (~rhs) );
949  }
950 
951  return *this;
952 }
953 //*************************************************************************************************
954 
955 
956 //*************************************************************************************************
963 template< typename Type // Data type of the vector
964  , bool TF > // Transpose flag
965 template< typename Other > // Data type of the right-hand side scalar
966 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
968 {
969  return operator=( (*this) * rhs );
970 }
971 //*************************************************************************************************
972 
973 
974 //*************************************************************************************************
983 template< typename Type // Data type of the vector
984  , bool TF > // Transpose flag
985 template< typename Other > // Data type of the right-hand side scalar
986 inline typename EnableIf< IsNumeric<Other>, DynamicVector<Type,TF> >::Type&
988 {
989  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
990 
991  return operator=( (*this) / rhs );
992 }
993 //*************************************************************************************************
994 
995 
996 
997 
998 //=================================================================================================
999 //
1000 // UTILITY FUNCTIONS
1001 //
1002 //=================================================================================================
1003 
1004 //*************************************************************************************************
1009 template< typename Type // Data type of the vector
1010  , bool TF > // Transpose flag
1011 inline size_t DynamicVector<Type,TF>::size() const
1012 {
1013  return size_;
1014 }
1015 //*************************************************************************************************
1016 
1017 
1018 //*************************************************************************************************
1023 template< typename Type // Data type of the vector
1024  , bool TF > // Transpose flag
1026 {
1027  return capacity_;
1028 }
1029 //*************************************************************************************************
1030 
1031 
1032 //*************************************************************************************************
1040 template< typename Type // Data type of the vector
1041  , bool TF > // Transpose flag
1043 {
1044  size_t nonzeros( 0 );
1045 
1046  for( size_t i=0UL; i<size_; ++i ) {
1047  if( !isDefault( v_[i] ) )
1048  ++nonzeros;
1049  }
1050 
1051  return nonzeros;
1052 }
1053 //*************************************************************************************************
1054 
1055 
1056 //*************************************************************************************************
1061 template< typename Type // Data type of the vector
1062  , bool TF > // Transpose flag
1064 {
1065  using blaze::reset;
1066  for( size_t i=0UL; i<size_; ++i )
1067  reset( v_[i] );
1068 }
1069 //*************************************************************************************************
1070 
1071 
1072 //*************************************************************************************************
1079 template< typename Type // Data type of the vector
1080  , bool TF > // Transpose flag
1082 {
1083  size_ = 0UL;
1084 }
1085 //*************************************************************************************************
1086 
1087 
1088 //*************************************************************************************************
1115 template< typename Type // Data type of the vector
1116  , bool TF > // Transpose flag
1117 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1118 {
1119  if( n > capacity_ )
1120  {
1121  // Allocating a new array
1122  const size_t newCapacity( adjustCapacity( n ) );
1123  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1124 
1125  // Initializing the new array
1126  if( preserve ) {
1127  std::copy( v_, v_+size_, tmp );
1128  }
1129 
1130  if( IsBuiltin<Type>::value ) {
1131  for( size_t i=size_; i<newCapacity; ++i )
1132  tmp[i] = Type();
1133  }
1134 
1135  // Replacing the old array
1136  std::swap( v_, tmp );
1137  deallocate( tmp );
1138  capacity_ = newCapacity;
1139  }
1140 
1141  size_ = n;
1142 }
1143 //*************************************************************************************************
1144 
1145 
1146 //*************************************************************************************************
1158 template< typename Type // Data type of the vector
1159  , bool TF > // Transpose flag
1160 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1161 {
1162  resize( size_+n, preserve );
1163 }
1164 //*************************************************************************************************
1165 
1166 
1167 //*************************************************************************************************
1176 template< typename Type // Data type of the vector
1177  , bool TF > // Transpose flag
1178 inline void DynamicVector<Type,TF>::reserve( size_t n )
1179 {
1180  if( n > capacity_ )
1181  {
1182  // Allocating a new array
1183  const size_t newCapacity( adjustCapacity( n ) );
1184  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1185 
1186  // Initializing the new array
1187  std::copy( v_, v_+size_, tmp );
1188 
1189  if( IsBuiltin<Type>::value ) {
1190  for( size_t i=size_; i<newCapacity; ++i )
1191  tmp[i] = Type();
1192  }
1193 
1194  // Replacing the old array
1195  std::swap( tmp, v_ );
1196  deallocate( tmp );
1197  capacity_ = newCapacity;
1198  }
1199 }
1200 //*************************************************************************************************
1201 
1202 
1203 //*************************************************************************************************
1233 template< typename Type // Data type of the vector
1234  , bool TF > // Transpose flag
1235 #ifndef WIN32
1237 #else
1239 #endif
1240 {
1242 
1243  LengthType sum( 0 );
1244  for( size_t i=0UL; i<size_; ++i )
1245  sum += v_[i] * v_[i];
1246  return std::sqrt( sum );
1247 }
1248 //*************************************************************************************************
1249 
1250 
1251 //*************************************************************************************************
1261 template< typename Type // Data type of the vector
1262  , bool TF > // Transpose flag
1263 inline const Type DynamicVector<Type,TF>::sqrLength() const
1264 {
1266 
1267  Type sum( 0 );
1268  for( size_t i=0UL; i<size_; ++i )
1269  sum += v_[i] * v_[i];
1270  return sum;
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1284 template< typename Type // Data type of the vector
1285  , bool TF > // Transpose flag
1287 {
1289 
1290  const Type len( length() );
1291 
1292  if( len == Type(0) )
1293  return *this;
1294 
1295  const Type ilen( Type(1) / len );
1296 
1297  for( size_t i=0; i<size_; ++i )
1298  v_[i] *= ilen;
1299 
1300  return *this;
1301 }
1302 //*************************************************************************************************
1303 
1304 
1305 //*************************************************************************************************
1314 template< typename Type // Data type of the vector
1315  , bool TF > // Transpose flag
1317 {
1319 
1320  const Type len( length() );
1321 
1322  if( len == Type(0) )
1323  return *this;
1324 
1325  const Type ilen( Type(1) / len );
1326  DynamicVector tmp( size_ );
1327 
1328  for( size_t i=0UL; i<size_; ++i )
1329  tmp[i] = v_[i] * ilen;
1330 
1331  return tmp;
1332 }
1333 //*************************************************************************************************
1334 
1335 
1336 //*************************************************************************************************
1342 template< typename Type // Data type of the vector
1343  , bool TF > // Transpose flag
1344 template< typename Other > // Data type of the scalar value
1346 {
1347  for( size_t i=0UL; i<size_; ++i )
1348  v_[i] *= scalar;
1349  return *this;
1350 }
1351 //*************************************************************************************************
1352 
1353 
1354 //*************************************************************************************************
1361 template< typename Type // Data type of the vector
1362  , bool TF > // Transpose flag
1363 inline void DynamicVector<Type,TF>::swap( DynamicVector& v ) /* throw() */
1364 {
1365  std::swap( size_, v.size_ );
1366  std::swap( capacity_, v.capacity_ );
1367  std::swap( v_, v.v_ );
1368 }
1369 //*************************************************************************************************
1370 
1371 
1372 //*************************************************************************************************
1378 template< typename Type // Data type of the vector
1379  , bool TF > // Transpose flag
1380 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const
1381 {
1383  return minCapacity + ( IT::size - ( minCapacity % IT::size ) ) % IT::size;
1384  else return minCapacity;
1385 }
1386 //*************************************************************************************************
1387 
1388 
1389 
1390 
1391 //=================================================================================================
1392 //
1393 // READ/WRITE FUNCTIONS
1394 //
1395 //=================================================================================================
1396 
1397 //*************************************************************************************************
1418 template< typename Type // Data type of the vector
1419  , bool TF > // Transpose flag
1420 void DynamicVector<Type,TF>::read( const char* file )
1421 {
1422  std::ifstream in( file, std::ifstream::in );
1423  if( !in.is_open() ) {
1424  throw std::runtime_error( "File could not be opened!" );
1425  }
1426 
1427  size_t vsize(0UL);
1428  if( !(in >> vsize) || vsize == 0UL ) {
1429  throw std::runtime_error( "Vector size could not be extracted!" );
1430  }
1431 
1432  DynamicVector tmp( vsize );
1433 
1434  for( size_t i=0UL; i<vsize; ++i ) {
1435  if( !(in >> tmp.v_[i]) ) {
1436  throw std::runtime_error( "Error during vector extraction!" );
1437  }
1438  }
1439 
1440  swap( tmp );
1441 
1442  in.close();
1443 }
1444 //*************************************************************************************************
1445 
1446 
1447 //*************************************************************************************************
1470 template< typename Type // Data type of the vector
1471  , bool TF > // Transpose flag
1472 void DynamicVector<Type,TF>::write( const char* file, std::streamsize prec ) const
1473 {
1474  std::ofstream out( file, std::ofstream::out | std::ostream::trunc );
1475  if( !out.is_open() ) {
1476  throw std::runtime_error( "File could not be opened!" );
1477  }
1478 
1479  out << size_ << "\n";
1480 
1481  out.precision( prec );
1482  for( size_t i=0UL; i<size_; ++i )
1483  out << v_[i] << "\n";
1484 
1485  out.close();
1486 }
1487 //*************************************************************************************************
1488 
1489 
1490 
1491 
1492 //=================================================================================================
1493 //
1494 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1495 //
1496 //=================================================================================================
1497 
1498 //*************************************************************************************************
1504 template< typename Type // Data type of the vector
1505  , bool TF > // Transpose flag
1506 template< typename Other > // Data type of the foreign expression
1507 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const
1508 {
1509  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1510 }
1511 //*************************************************************************************************
1512 
1513 
1514 //*************************************************************************************************
1525 template< typename Type // Data type of the vector
1526  , bool TF > // Transpose flag
1528  DynamicVector<Type,TF>::get( size_t index ) const
1529 {
1531 
1532  BLAZE_INTERNAL_ASSERT( index < size_ , "Invalid vector access index" );
1533  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
1534  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1535 
1536  return load( &v_[index] );
1537 }
1538 //*************************************************************************************************
1539 
1540 
1541 //*************************************************************************************************
1552 template< typename Type // Data type of the vector
1553  , bool TF > // Transpose flag
1554 template< typename VT > // Type of the right-hand side dense vector
1555 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1557 {
1558  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1559 
1560  const size_t iend( (~rhs).size() & size_t(-2) );
1561  for( size_t i=0UL; i<iend; i+=2UL ) {
1562  v_[i ] = (~rhs)[i ];
1563  v_[i+1UL] = (~rhs)[i+1UL];
1564  }
1565  if( iend < (~rhs).size() )
1566  v_[iend] = (~rhs)[iend];
1567 }
1568 //*************************************************************************************************
1569 
1570 
1571 //*************************************************************************************************
1582 template< typename Type // Data type of the vector
1583  , bool TF > // Transpose flag
1584 template< typename VT > // Type of the right-hand side dense vector
1585 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1587 {
1588  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1589 
1591 
1592  if( 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).get(i) );
1596  }
1597  }
1598  else
1599  {
1600  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1601  const size_t iend( size_ & size_t(-IT::size*4) );
1602 
1603  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1604  store( v_+i , (~rhs).get(i ) );
1605  store( v_+i+IT::size , (~rhs).get(i+IT::size ) );
1606  store( v_+i+IT::size*2UL, (~rhs).get(i+IT::size*2UL) );
1607  store( v_+i+IT::size*3UL, (~rhs).get(i+IT::size*3UL) );
1608  }
1609  for( size_t i=iend; i<size_; i+=IT::size ) {
1610  store( v_+i, (~rhs).get(i) );
1611  }
1612  }
1613 }
1614 //*************************************************************************************************
1615 
1616 
1617 //*************************************************************************************************
1628 template< typename Type // Data type of the vector
1629  , bool TF > // Transpose flag
1630 template< typename VT > // Type of the right-hand side sparse vector
1632 {
1633  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1634 
1635  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1636  v_[element->index()] = element->value();
1637 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1652 template< typename Type // Data type of the vector
1653  , bool TF > // Transpose flag
1654 template< typename VT > // Type of the right-hand side dense vector
1655 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1657 {
1658  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1659 
1660  const size_t iend( (~rhs).size() & size_t(-2) );
1661  for( size_t i=0UL; i<iend; i+=2UL ) {
1662  v_[i ] += (~rhs)[i ];
1663  v_[i+1UL] += (~rhs)[i+1UL];
1664  }
1665  if( iend < (~rhs).size() )
1666  v_[iend] += (~rhs)[iend];
1667 }
1668 //*************************************************************************************************
1669 
1670 
1671 //*************************************************************************************************
1682 template< typename Type // Data type of the vector
1683  , bool TF > // Transpose flag
1684 template< typename VT > // Type of the right-hand side dense vector
1685 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1687 {
1688  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1689 
1691 
1692  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1693  const size_t iend( size_ & size_t(-IT::size*4) );
1694 
1695  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1696  store( v_+i , load(v_+i ) + (~rhs).get(i ) );
1697  store( v_+i+IT::size , load(v_+i+IT::size ) + (~rhs).get(i+IT::size ) );
1698  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) + (~rhs).get(i+IT::size*2UL) );
1699  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) + (~rhs).get(i+IT::size*3UL) );
1700  }
1701  for( size_t i=iend; i<size_; i+=IT::size ) {
1702  store( v_+i, load(v_+i) + (~rhs).get(i) );
1703  }
1704 }
1705 //*************************************************************************************************
1706 
1707 
1708 //*************************************************************************************************
1719 template< typename Type // Data type of the vector
1720  , bool TF > // Transpose flag
1721 template< typename VT > // Type of the right-hand side sparse vector
1723 {
1724  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1725 
1726  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1727  v_[element->index()] += element->value();
1728 }
1729 //*************************************************************************************************
1730 
1731 
1732 //*************************************************************************************************
1743 template< typename Type // Data type of the vector
1744  , bool TF > // Transpose flag
1745 template< typename VT > // Type of the right-hand side dense vector
1746 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1748 {
1749  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1750 
1751  const size_t iend( (~rhs).size() & size_t(-2) );
1752  for( size_t i=0UL; i<iend; i+=2UL ) {
1753  v_[i ] -= (~rhs)[i ];
1754  v_[i+1UL] -= (~rhs)[i+1UL];
1755  }
1756  if( iend < (~rhs).size() )
1757  v_[iend] -= (~rhs)[iend];
1758 }
1759 //*************************************************************************************************
1760 
1761 
1762 //*************************************************************************************************
1773 template< typename Type // Data type of the vector
1774  , bool TF > // Transpose flag
1775 template< typename VT > // Type of the right-hand side dense vector
1776 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1778 {
1779  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1780 
1782 
1783  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1784  const size_t iend( size_ & size_t(-IT::size*4) );
1785 
1786  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1787  store( v_+i , load(v_+i ) - (~rhs).get(i ) );
1788  store( v_+i+IT::size , load(v_+i+IT::size ) - (~rhs).get(i+IT::size ) );
1789  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) - (~rhs).get(i+IT::size*2UL) );
1790  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) - (~rhs).get(i+IT::size*3UL) );
1791  }
1792  for( size_t i=iend; i<size_; i+=IT::size ) {
1793  store( v_+i, load(v_+i) - (~rhs).get(i) );
1794  }
1795 }
1796 //*************************************************************************************************
1797 
1798 
1799 //*************************************************************************************************
1810 template< typename Type // Data type of the vector
1811  , bool TF > // Transpose flag
1812 template< typename VT > // Type of the right-hand side sparse vector
1814 {
1815  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1816 
1817  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1818  v_[element->index()] -= element->value();
1819 }
1820 //*************************************************************************************************
1821 
1822 
1823 //*************************************************************************************************
1834 template< typename Type // Data type of the vector
1835  , bool TF > // Transpose flag
1836 template< typename VT > // Type of the right-hand side dense vector
1837 inline typename DisableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1839 {
1840  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1841 
1842  const size_t iend( (~rhs).size() & size_t(-2) );
1843  for( size_t i=0UL; i<iend; i+=2UL ) {
1844  v_[i ] *= (~rhs)[i ];
1845  v_[i+1UL] *= (~rhs)[i+1UL];
1846  }
1847  if( iend < (~rhs).size() )
1848  v_[iend] *= (~rhs)[iend];
1849 }
1850 //*************************************************************************************************
1851 
1852 
1853 //*************************************************************************************************
1864 template< typename Type // Data type of the vector
1865  , bool TF > // Transpose flag
1866 template< typename VT > // Type of the right-hand side dense vector
1867 inline typename EnableIf< typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1869 {
1870  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1871 
1873 
1874  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == ( size_ & size_t(-IT::size*4) ), "Invalid end calculation" );
1875  const size_t iend( size_ & size_t(-IT::size*4) );
1876 
1877  for( size_t i=0UL; i<iend; i+=IT::size*4UL ) {
1878  store( v_+i , load(v_+i ) * (~rhs).get(i ) );
1879  store( v_+i+IT::size , load(v_+i+IT::size ) * (~rhs).get(i+IT::size ) );
1880  store( v_+i+IT::size*2UL, load(v_+i+IT::size*2UL) * (~rhs).get(i+IT::size*2UL) );
1881  store( v_+i+IT::size*3UL, load(v_+i+IT::size*3UL) * (~rhs).get(i+IT::size*3UL) );
1882  }
1883  for( size_t i=iend; i<size_; i+=IT::size ) {
1884  store( v_+i, load(v_+i) * (~rhs).get(i) );
1885  }
1886 }
1887 //*************************************************************************************************
1888 
1889 
1890 //*************************************************************************************************
1901 template< typename Type // Data type of the vector
1902  , bool TF > // Transpose flag
1903 template< typename VT > // Type of the right-hand side sparse vector
1905 {
1906  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1907 
1908  const DynamicVector tmp( *this );
1909 
1910  reset();
1911 
1912  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1913  v_[element->index()] = tmp[element->index()] * element->value();
1914 }
1915 //*************************************************************************************************
1916 
1917 
1918 
1919 
1920 //=================================================================================================
1921 //
1922 // GLOBAL OPERATORS
1923 //
1924 //=================================================================================================
1925 
1926 //*************************************************************************************************
1929 template< typename Type, bool TF >
1930 inline void reset( DynamicVector<Type,TF>& v );
1931 
1932 template< typename Type, bool TF >
1933 inline void clear( DynamicVector<Type,TF>& v );
1934 
1935 template< typename Type, bool TF >
1936 inline bool isnan( const DynamicVector<Type,TF>& v );
1937 
1938 template< typename Type, bool TF >
1939 inline bool isDefault( const DynamicVector<Type,TF>& v );
1940 
1941 template< typename Type, bool TF >
1942 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */;
1944 //*************************************************************************************************
1945 
1946 
1947 //*************************************************************************************************
1954 template< typename Type // Data type of the vector
1955  , bool TF > // Transpose flag
1957 {
1958  v.reset();
1959 }
1960 //*************************************************************************************************
1961 
1962 
1963 //*************************************************************************************************
1970 template< typename Type // Data type of the vector
1971  , bool TF > // Transpose flag
1973 {
1974  v.clear();
1975 }
1976 //*************************************************************************************************
1977 
1978 
1979 //*************************************************************************************************
1996 template< typename Type // Data type of the vector
1997  , bool TF > // Transpose flag
1998 inline bool isnan( const DynamicVector<Type,TF>& v )
1999 {
2000  for( size_t i=0UL; i<v.size(); ++i ) {
2001  if( isnan( v[i] ) ) return true;
2002  }
2003  return false;
2004 }
2005 //*************************************************************************************************
2006 
2007 
2008 //*************************************************************************************************
2027 template< typename Type // Data type of the vector
2028  , bool TF > // Transpose flag
2029 inline bool isDefault( const DynamicVector<Type,TF>& v )
2030 {
2031  for( size_t i=0UL; i<v.size(); ++i )
2032  if( !isDefault( v[i] ) ) return false;
2033  return true;
2034 }
2035 //*************************************************************************************************
2036 
2037 
2038 //*************************************************************************************************
2047 template< typename Type // Data type of the vector
2048  , bool TF > // Transpose flag
2049 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) /* throw() */
2050 {
2051  a.swap( b );
2052 }
2053 //*************************************************************************************************
2054 
2055 
2056 
2057 
2058 //=================================================================================================
2059 //
2060 // ISRESIZABLE SPECIALIZATIONS
2061 //
2062 //=================================================================================================
2063 
2064 //*************************************************************************************************
2066 template< typename T, bool TF >
2067 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2068 {
2069  enum { value = 1 };
2070  typedef TrueType Type;
2071 };
2072 
2073 template< typename T, bool TF >
2074 struct IsResizable< const DynamicVector<T,TF> > : public TrueType
2075 {
2076  enum { value = 1 };
2077  typedef TrueType Type;
2078 };
2079 
2080 template< typename T, bool TF >
2081 struct IsResizable< volatile DynamicVector<T,TF> > : public TrueType
2082 {
2083  enum { value = 1 };
2084  typedef TrueType Type;
2085 };
2086 
2087 template< typename T, bool TF >
2088 struct IsResizable< const volatile DynamicVector<T,TF> > : public TrueType
2089 {
2090  enum { value = 1 };
2091  typedef TrueType Type;
2092 };
2094 //*************************************************************************************************
2095 
2096 
2097 
2098 
2099 //=================================================================================================
2100 //
2101 // ADDTRAIT SPECIALIZATIONS
2102 //
2103 //=================================================================================================
2104 
2105 //*************************************************************************************************
2107 template< typename T1, bool TF, typename T2, size_t N >
2108 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2109 {
2110  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2111 };
2112 
2113 template< typename T1, size_t N, bool TF, typename T2 >
2114 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2115 {
2116  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2117 };
2118 
2119 template< typename T1, bool TF, typename T2 >
2120 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2121 {
2122  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
2123 };
2125 //*************************************************************************************************
2126 
2127 
2128 
2129 
2130 //=================================================================================================
2131 //
2132 // SUBTRAIT SPECIALIZATIONS
2133 //
2134 //=================================================================================================
2135 
2136 //*************************************************************************************************
2138 template< typename T1, bool TF, typename T2, size_t N >
2139 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2140 {
2141  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2142 };
2143 
2144 template< typename T1, size_t N, bool TF, typename T2 >
2145 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2146 {
2147  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2148 };
2149 
2150 template< typename T1, bool TF, typename T2 >
2151 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2152 {
2153  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
2154 };
2156 //*************************************************************************************************
2157 
2158 
2159 
2160 
2161 //=================================================================================================
2162 //
2163 // MULTTRAIT SPECIALIZATIONS
2164 //
2165 //=================================================================================================
2166 
2167 //*************************************************************************************************
2169 template< typename T1, bool TF, typename T2 >
2170 struct MultTrait< DynamicVector<T1,TF>, T2 >
2171 {
2172  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2174 };
2175 
2176 template< typename T1, typename T2, bool TF >
2177 struct MultTrait< T1, DynamicVector<T2,TF> >
2178 {
2179  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2181 };
2182 
2183 template< typename T1, bool TF, typename T2, size_t N >
2184 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2185 {
2186  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2187 };
2188 
2189 template< typename T1, typename T2, size_t N >
2190 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2191 {
2192  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2193 };
2194 
2195 template< typename T1, typename T2, size_t N >
2196 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2197 {
2198  typedef typename MultTrait<T1,T2>::Type Type;
2199 };
2200 
2201 template< typename T1, size_t N, bool TF, typename T2 >
2202 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2203 {
2204  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2205 };
2206 
2207 template< typename T1, size_t N, typename T2 >
2208 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2209 {
2210  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2211 };
2212 
2213 template< typename T1, size_t N, typename T2 >
2214 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2215 {
2216  typedef typename MultTrait<T1,T2>::Type Type;
2217 };
2218 
2219 template< typename T1, bool TF, typename T2 >
2220 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2221 {
2222  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
2223 };
2224 
2225 template< typename T1, typename T2 >
2226 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2227 {
2228  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2229 };
2230 
2231 template< typename T1, typename T2 >
2232 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2233 {
2234  typedef typename MultTrait<T1,T2>::Type Type;
2235 };
2237 //*************************************************************************************************
2238 
2239 
2240 
2241 
2242 //=================================================================================================
2243 //
2244 // CROSSTRAIT SPECIALIZATIONS
2245 //
2246 //=================================================================================================
2247 
2248 //*************************************************************************************************
2250 template< typename T1, typename T2 >
2251 struct CrossTrait< DynamicVector<T1,false>, StaticVector<T2,3UL,false> >
2252 {
2253  private:
2254  typedef typename MultTrait<T1,T2>::Type T;
2255 
2256  public:
2257  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2258 };
2259 
2260 template< typename T1, typename T2 >
2261 struct CrossTrait< StaticVector<T1,3UL,false>, DynamicVector<T2,false> >
2262 {
2263  private:
2264  typedef typename MultTrait<T1,T2>::Type T;
2265 
2266  public:
2267  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2268 };
2269 
2270 template< typename T1, typename T2 >
2271 struct CrossTrait< DynamicVector<T1,false>, DynamicVector<T2,false> >
2272 {
2273  private:
2274  typedef typename MultTrait<T1,T2>::Type T;
2275 
2276  public:
2277  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2278 };
2280 //*************************************************************************************************
2281 
2282 
2283 
2284 
2285 //=================================================================================================
2286 //
2287 // DIVTRAIT SPECIALIZATIONS
2288 //
2289 //=================================================================================================
2290 
2291 //*************************************************************************************************
2293 template< typename T1, bool TF, typename T2 >
2294 struct DivTrait< DynamicVector<T1,TF>, T2 >
2295 {
2296  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
2298 };
2300 //*************************************************************************************************
2301 
2302 
2303 
2304 
2305 //=================================================================================================
2306 //
2307 // MATHTRAIT SPECIALIZATIONS
2308 //
2309 //=================================================================================================
2310 
2311 //*************************************************************************************************
2313 template< typename T1, bool TF, typename T2 >
2314 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2315 {
2316  typedef DynamicVector< typename MathTrait<T1,T2>::HighType, TF > HighType;
2317  typedef DynamicVector< typename MathTrait<T1,T2>::LowType , TF > LowType;
2318 };
2320 //*************************************************************************************************
2321 
2322 } // namespace blaze
2323 
2324 #endif