DynamicVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
36 #define _BLAZE_MATH_DENSE_DYNAMICVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <utility>
45 #include <blaze/math/Aliases.h>
48 #include <blaze/math/Exception.h>
51 #include <blaze/math/Forward.h>
52 #include <blaze/math/Functions.h>
54 #include <blaze/math/shims/Clear.h>
57 #include <blaze/math/SIMD.h>
77 #include <blaze/system/CacheSize.h>
78 #include <blaze/system/Inline.h>
80 #include <blaze/system/Restrict.h>
83 #include <blaze/util/Algorithm.h>
85 #include <blaze/util/Assert.h>
91 #include <blaze/util/DisableIf.h>
92 #include <blaze/util/EnableIf.h>
94 #include <blaze/util/Memory.h>
95 #include <blaze/util/Template.h>
96 #include <blaze/util/TrueType.h>
97 #include <blaze/util/Types.h>
100 
101 
102 namespace blaze {
103 
104 //=================================================================================================
105 //
106 // CLASS DEFINITION
107 //
108 //=================================================================================================
109 
110 //*************************************************************************************************
174 template< typename Type // Data type of the vector
175  , bool TF = defaultTransposeFlag > // Transpose flag
176 class DynamicVector : public DenseVector< DynamicVector<Type,TF>, TF >
177 {
178  public:
179  //**Type definitions****************************************************************************
182  typedef This ResultType;
184  typedef Type ElementType;
186  typedef const Type& ReturnType;
187  typedef const DynamicVector& CompositeType;
188 
189  typedef Type& Reference;
190  typedef const Type& ConstReference;
191  typedef Type* Pointer;
192  typedef const Type* ConstPointer;
193 
196  //**********************************************************************************************
197 
198  //**Rebind struct definition********************************************************************
201  template< typename ET > // Data type of the other vector
202  struct Rebind {
204  };
205  //**********************************************************************************************
206 
207  //**Compilation flags***************************************************************************
209 
213  enum : bool { simdEnabled = IsVectorizable<Type>::value };
214 
216 
219  enum : bool { smpAssignable = !IsSMPAssignable<Type>::value };
220  //**********************************************************************************************
221 
222  //**Constructors********************************************************************************
225  explicit inline DynamicVector() noexcept;
226  explicit inline DynamicVector( size_t n );
227  explicit inline DynamicVector( size_t n, const Type& init );
228  explicit inline DynamicVector( initializer_list<Type> list );
229 
230  template< typename Other >
231  explicit inline DynamicVector( size_t n, const Other* array );
232 
233  template< typename Other, size_t N >
234  explicit inline DynamicVector( const Other (&array)[N] );
235 
236  inline DynamicVector( const DynamicVector& v );
237  inline DynamicVector( DynamicVector&& v ) noexcept;
238  template< typename VT > inline DynamicVector( const Vector<VT,TF>& v );
240  //**********************************************************************************************
241 
242  //**Destructor**********************************************************************************
245  inline ~DynamicVector();
247  //**********************************************************************************************
248 
249  //**Data access functions***********************************************************************
252  inline Reference operator[]( size_t index ) noexcept;
253  inline ConstReference operator[]( size_t index ) const noexcept;
254  inline Reference at( size_t index );
255  inline ConstReference at( size_t index ) const;
256  inline Pointer data () noexcept;
257  inline ConstPointer data () const noexcept;
258  inline Iterator begin () noexcept;
259  inline ConstIterator begin () const noexcept;
260  inline ConstIterator cbegin() const noexcept;
261  inline Iterator end () noexcept;
262  inline ConstIterator end () const noexcept;
263  inline ConstIterator cend () const noexcept;
265  //**********************************************************************************************
266 
267  //**Assignment operators************************************************************************
270  inline DynamicVector& operator=( const Type& rhs );
271  inline DynamicVector& operator=( initializer_list<Type> list );
272 
273  template< typename Other, size_t N >
274  inline DynamicVector& operator=( const Other (&array)[N] );
275 
276  inline DynamicVector& operator=( const DynamicVector& rhs );
277  inline DynamicVector& operator=( DynamicVector&& rhs ) noexcept;
278 
279  template< typename VT > inline DynamicVector& operator= ( const Vector<VT,TF>& rhs );
280  template< typename VT > inline DynamicVector& operator+=( const Vector<VT,TF>& rhs );
281  template< typename VT > inline DynamicVector& operator-=( const Vector<VT,TF>& rhs );
282  template< typename VT > inline DynamicVector& operator*=( const Vector<VT,TF>& rhs );
283  template< typename VT > inline DynamicVector& operator/=( const DenseVector<VT,TF>& rhs );
284 
285  template< typename Other >
286  inline EnableIf_<IsNumeric<Other>, DynamicVector >& operator*=( Other rhs );
287 
288  template< typename Other >
289  inline EnableIf_<IsNumeric<Other>, DynamicVector >& operator/=( Other rhs );
291  //**********************************************************************************************
292 
293  //**Utility functions***************************************************************************
296  inline size_t size() const noexcept;
297  inline size_t capacity() const noexcept;
298  inline size_t nonZeros() const;
299  inline void reset();
300  inline void clear();
301  inline void resize( size_t n, bool preserve=true );
302  inline void extend( size_t n, bool preserve=true );
303  inline void reserve( size_t n );
304  template< typename Other > inline DynamicVector& scale( const Other& scalar );
305  inline void swap( DynamicVector& v ) noexcept;
307  //**********************************************************************************************
308 
309  private:
310  //**********************************************************************************************
312  template< typename VT >
314  struct VectorizedAssign {
315  enum : bool { value = useOptimizedKernels &&
316  simdEnabled && VT::simdEnabled &&
317  AreSIMDCombinable< Type, ElementType_<VT> >::value };
318  };
320  //**********************************************************************************************
321 
322  //**********************************************************************************************
324  template< typename VT >
326  struct VectorizedAddAssign {
327  enum : bool { value = useOptimizedKernels &&
328  simdEnabled && VT::simdEnabled &&
329  AreSIMDCombinable< Type, ElementType_<VT> >::value &&
330  HasSIMDAdd< Type, ElementType_<VT> >::value };
331  };
333  //**********************************************************************************************
334 
335  //**********************************************************************************************
337  template< typename VT >
339  struct VectorizedSubAssign {
340  enum : bool { value = useOptimizedKernels &&
341  simdEnabled && VT::simdEnabled &&
342  AreSIMDCombinable< Type, ElementType_<VT> >::value &&
343  HasSIMDSub< Type, ElementType_<VT> >::value };
344  };
346  //**********************************************************************************************
347 
348  //**********************************************************************************************
350  template< typename VT >
352  struct VectorizedMultAssign {
353  enum : bool { value = useOptimizedKernels &&
354  simdEnabled && VT::simdEnabled &&
355  AreSIMDCombinable< Type, ElementType_<VT> >::value &&
356  HasSIMDMult< Type, ElementType_<VT> >::value };
357  };
359  //**********************************************************************************************
360 
361  //**********************************************************************************************
363  template< typename VT >
365  struct VectorizedDivAssign {
366  enum : bool { value = useOptimizedKernels &&
367  simdEnabled && VT::simdEnabled &&
368  AreSIMDCombinable< Type, ElementType_<VT> >::value &&
369  HasSIMDDiv< Type, ElementType_<VT> >::value };
370  };
372  //**********************************************************************************************
373 
374  //**********************************************************************************************
376  enum : size_t { SIMDSIZE = SIMDTrait<ElementType>::size };
377  //**********************************************************************************************
378 
379  public:
380  //**Debugging functions*************************************************************************
383  inline bool isIntact() const noexcept;
385  //**********************************************************************************************
386 
387  //**Expression template evaluation functions****************************************************
390  template< typename Other > inline bool canAlias ( const Other* alias ) const noexcept;
391  template< typename Other > inline bool isAliased( const Other* alias ) const noexcept;
392 
393  inline bool isAligned () const noexcept;
394  inline bool canSMPAssign() const noexcept;
395 
396  BLAZE_ALWAYS_INLINE SIMDType load ( size_t index ) const noexcept;
397  BLAZE_ALWAYS_INLINE SIMDType loada( size_t index ) const noexcept;
398  BLAZE_ALWAYS_INLINE SIMDType loadu( size_t index ) const noexcept;
399 
400  BLAZE_ALWAYS_INLINE void store ( size_t index, const SIMDType& value ) noexcept;
401  BLAZE_ALWAYS_INLINE void storea( size_t index, const SIMDType& value ) noexcept;
402  BLAZE_ALWAYS_INLINE void storeu( size_t index, const SIMDType& value ) noexcept;
403  BLAZE_ALWAYS_INLINE void stream( size_t index, const SIMDType& value ) noexcept;
404 
405  template< typename VT >
406  inline DisableIf_<VectorizedAssign<VT> > assign( const DenseVector<VT,TF>& rhs );
407 
408  template< typename VT >
409  inline EnableIf_<VectorizedAssign<VT> > assign( const DenseVector<VT,TF>& rhs );
410 
411  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
412 
413  template< typename VT >
414  inline DisableIf_<VectorizedAddAssign<VT> > addAssign( const DenseVector<VT,TF>& rhs );
415 
416  template< typename VT >
417  inline EnableIf_<VectorizedAddAssign<VT> > addAssign( const DenseVector<VT,TF>& rhs );
418 
419  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
420 
421  template< typename VT >
422  inline DisableIf_<VectorizedSubAssign<VT> > subAssign( const DenseVector<VT,TF>& rhs );
423 
424  template< typename VT >
425  inline EnableIf_<VectorizedSubAssign<VT> > subAssign( const DenseVector<VT,TF>& rhs );
426 
427  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
428 
429  template< typename VT >
430  inline DisableIf_<VectorizedMultAssign<VT> > multAssign( const DenseVector<VT,TF>& rhs );
431 
432  template< typename VT >
433  inline EnableIf_<VectorizedMultAssign<VT> > multAssign( const DenseVector<VT,TF>& rhs );
434 
435  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
436 
437  template< typename VT >
438  inline DisableIf_<VectorizedDivAssign<VT> > divAssign( const DenseVector<VT,TF>& rhs );
439 
440  template< typename VT >
441  inline EnableIf_<VectorizedDivAssign<VT> > divAssign( const DenseVector<VT,TF>& rhs );
443  //**********************************************************************************************
444 
445  private:
446  //**Utility functions***************************************************************************
449  inline size_t adjustCapacity( size_t minCapacity ) const noexcept;
451  //**********************************************************************************************
452 
453  //**Member variables****************************************************************************
456  size_t size_;
457  size_t capacity_;
459 
465  //**********************************************************************************************
466 
467  //**Compile time checks*************************************************************************
474  //**********************************************************************************************
475 };
476 //*************************************************************************************************
477 
478 
479 
480 
481 //=================================================================================================
482 //
483 // CONSTRUCTORS
484 //
485 //=================================================================================================
486 
487 //*************************************************************************************************
490 template< typename Type // Data type of the vector
491  , bool TF > // Transpose flag
492 inline DynamicVector<Type,TF>::DynamicVector() noexcept
493  : size_ ( 0UL ) // The current size/dimension of the vector
494  , capacity_( 0UL ) // The maximum capacity of the vector
495  , v_ ( nullptr ) // The vector elements
496 {}
497 //*************************************************************************************************
498 
499 
500 //*************************************************************************************************
508 template< typename Type // Data type of the vector
509  , bool TF > // Transpose flag
511  : size_ ( n ) // The current size/dimension of the vector
512  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
513  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
514 {
516  for( size_t i=size_; i<capacity_; ++i )
517  v_[i] = Type();
518  }
519 
520  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
533 template< typename Type // Data type of the vector
534  , bool TF > // Transpose flag
535 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Type& init )
536  : size_ ( n ) // The current size/dimension of the vector
537  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
538  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
539 {
540  for( size_t i=0UL; i<size_; ++i )
541  v_[i] = init;
542 
544  for( size_t i=size_; i<capacity_; ++i )
545  v_[i] = Type();
546  }
547 
548  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
549 }
550 //*************************************************************************************************
551 
552 
553 //*************************************************************************************************
568 template< typename Type // Data type of the vector
569  , bool TF > // Transpose flag
571  : size_ ( list.size() ) // The current size/dimension of the vector
572  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
573  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
574 {
575  std::fill( std::copy( list.begin(), list.end(), v_ ), v_+capacity_, Type() );
576 
577  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
578 }
579 //*************************************************************************************************
580 
581 
582 //*************************************************************************************************
602 template< typename Type // Data type of the vector
603  , bool TF > // Transpose flag
604 template< typename Other > // Data type of the initialization array
605 inline DynamicVector<Type,TF>::DynamicVector( size_t n, const Other* array )
606  : size_ ( n ) // The current size/dimension of the vector
607  , capacity_( adjustCapacity( n ) ) // The maximum capacity of the vector
608  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
609 {
610  for( size_t i=0UL; i<n; ++i )
611  v_[i] = array[i];
612 
614  for( size_t i=n; i<capacity_; ++i )
615  v_[i] = Type();
616  }
617 
618  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
619 }
620 //*************************************************************************************************
621 
622 
623 //*************************************************************************************************
640 template< typename Type // Data type of the vector
641  , bool TF > // Transpose flag
642 template< typename Other // Data type of the initialization array
643  , size_t N > // Dimension of the initialization array
644 inline DynamicVector<Type,TF>::DynamicVector( const Other (&array)[N] )
645  : size_ ( N ) // The current size/dimension of the vector
646  , capacity_( adjustCapacity( N ) ) // The maximum capacity of the vector
647  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
648 {
649  for( size_t i=0UL; i<N; ++i )
650  v_[i] = array[i];
651 
653  for( size_t i=N; i<capacity_; ++i )
654  v_[i] = Type();
655  }
656 
657  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
658 }
659 //*************************************************************************************************
660 
661 
662 //*************************************************************************************************
670 template< typename Type // Data type of the vector
671  , bool TF > // Transpose flag
673  : size_ ( v.size_ ) // The current size/dimension of the vector
674  , capacity_( adjustCapacity( v.size_ ) ) // The maximum capacity of the vector
675  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
676 {
677  BLAZE_INTERNAL_ASSERT( capacity_ <= v.capacity_, "Invalid capacity estimation" );
678 
679  for( size_t i=0UL; i<capacity_; ++i )
680  v_[i] = v.v_[i];
681 
682  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
683 }
684 //*************************************************************************************************
685 
686 
687 //*************************************************************************************************
692 template< typename Type // Data type of the vector
693  , bool TF > // Transpose flag
695  : size_ ( v.size_ ) // The current size/dimension of the vector
696  , capacity_( v.capacity_ ) // The maximum capacity of the vector
697  , v_ ( v.v_ ) // The vector elements
698 {
699  v.size_ = 0UL;
700  v.capacity_ = 0UL;
701  v.v_ = nullptr;
702 }
703 //*************************************************************************************************
704 
705 
706 //*************************************************************************************************
711 template< typename Type // Data type of the vector
712  , bool TF > // Transpose flag
713 template< typename VT > // Type of the foreign vector
715  : size_ ( (~v).size() ) // The current size/dimension of the vector
716  , capacity_( adjustCapacity( size_ ) ) // The maximum capacity of the vector
717  , v_ ( allocate<Type>( capacity_ ) ) // The vector elements
718 {
719  for( size_t i=( IsSparseVector<VT>::value ? 0UL : size_ );
720  i<( IsVectorizable<Type>::value ? capacity_ : size_ ); ++i ) {
721  v_[i] = Type();
722  }
723 
724  smpAssign( *this, ~v );
725 
726  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
727 }
728 //*************************************************************************************************
729 
730 
731 
732 
733 //=================================================================================================
734 //
735 // DESTRUCTOR
736 //
737 //=================================================================================================
738 
739 //*************************************************************************************************
742 template< typename Type // Data type of the vector
743  , bool TF > // Transpose flag
745 {
746  deallocate( v_ );
747 }
748 //*************************************************************************************************
749 
750 
751 
752 
753 //=================================================================================================
754 //
755 // DATA ACCESS FUNCTIONS
756 //
757 //=================================================================================================
758 
759 //*************************************************************************************************
768 template< typename Type // Data type of the vector
769  , bool TF > // Transpose flag
770 inline typename DynamicVector<Type,TF>::Reference
771  DynamicVector<Type,TF>::operator[]( size_t index ) noexcept
772 {
773  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
774  return v_[index];
775 }
776 //*************************************************************************************************
777 
778 
779 //*************************************************************************************************
788 template< typename Type // Data type of the vector
789  , bool TF > // Transpose flag
791  DynamicVector<Type,TF>::operator[]( size_t index ) const noexcept
792 {
793  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
794  return v_[index];
795 }
796 //*************************************************************************************************
797 
798 
799 //*************************************************************************************************
809 template< typename Type // Data type of the vector
810  , bool TF > // Transpose flag
811 inline typename DynamicVector<Type,TF>::Reference
813 {
814  if( index >= size_ ) {
815  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
816  }
817  return (*this)[index];
818 }
819 //*************************************************************************************************
820 
821 
822 //*************************************************************************************************
832 template< typename Type // Data type of the vector
833  , bool TF > // Transpose flag
835  DynamicVector<Type,TF>::at( size_t index ) const
836 {
837  if( index >= size_ ) {
838  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
839  }
840  return (*this)[index];
841 }
842 //*************************************************************************************************
843 
844 
845 //*************************************************************************************************
852 template< typename Type // Data type of the vector
853  , bool TF > // Transpose flag
855 {
856  return v_;
857 }
858 //*************************************************************************************************
859 
860 
861 //*************************************************************************************************
868 template< typename Type // Data type of the vector
869  , bool TF > // Transpose flag
871 {
872  return v_;
873 }
874 //*************************************************************************************************
875 
876 
877 //*************************************************************************************************
882 template< typename Type // Data type of the vector
883  , bool TF > // Transpose flag
885 {
886  return Iterator( v_ );
887 }
888 //*************************************************************************************************
889 
890 
891 //*************************************************************************************************
896 template< typename Type // Data type of the vector
897  , bool TF > // Transpose flag
899 {
900  return ConstIterator( v_ );
901 }
902 //*************************************************************************************************
903 
904 
905 //*************************************************************************************************
910 template< typename Type // Data type of the vector
911  , bool TF > // Transpose flag
913 {
914  return ConstIterator( v_ );
915 }
916 //*************************************************************************************************
917 
918 
919 //*************************************************************************************************
924 template< typename Type // Data type of the vector
925  , bool TF > // Transpose flag
927 {
928  return Iterator( v_ + size_ );
929 }
930 //*************************************************************************************************
931 
932 
933 //*************************************************************************************************
938 template< typename Type // Data type of the vector
939  , bool TF > // Transpose flag
941 {
942  return ConstIterator( v_ + size_ );
943 }
944 //*************************************************************************************************
945 
946 
947 //*************************************************************************************************
952 template< typename Type // Data type of the vector
953  , bool TF > // Transpose flag
955 {
956  return ConstIterator( v_ + size_ );
957 }
958 //*************************************************************************************************
959 
960 
961 
962 
963 //=================================================================================================
964 //
965 // ASSIGNMENT OPERATORS
966 //
967 //=================================================================================================
968 
969 //*************************************************************************************************
975 template< typename Type // Data type of the vector
976  , bool TF > // Transpose flag
978 {
979  for( size_t i=0UL; i<size_; ++i )
980  v_[i] = rhs;
981  return *this;
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
1002 template< typename Type // Data type of the vector
1003  , bool TF > // Transpose flag
1005 {
1006  resize( list.size(), false );
1007  std::copy( list.begin(), list.end(), v_ );
1008 
1009  return *this;
1010 }
1011 //*************************************************************************************************
1012 
1013 
1014 //*************************************************************************************************
1032 template< typename Type // Data type of the vector
1033  , bool TF > // Transpose flag
1034 template< typename Other // Data type of the initialization array
1035  , size_t N > // Dimension of the initialization array
1037 {
1038  resize( N, false );
1039 
1040  for( size_t i=0UL; i<N; ++i )
1041  v_[i] = array[i];
1042 
1043  return *this;
1044 }
1045 //*************************************************************************************************
1046 
1047 
1048 //*************************************************************************************************
1057 template< typename Type // Data type of the vector
1058  , bool TF > // Transpose flag
1060 {
1061  if( &rhs == this ) return *this;
1062 
1063  resize( rhs.size_, false );
1064  smpAssign( *this, ~rhs );
1065 
1066  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1067 
1068  return *this;
1069 }
1070 //*************************************************************************************************
1071 
1072 
1073 //*************************************************************************************************
1079 template< typename Type // Data type of the vector
1080  , bool TF > // Transpose flag
1082 {
1083  deallocate( v_ );
1084 
1085  size_ = rhs.size_;
1086  capacity_ = rhs.capacity_;
1087  v_ = rhs.v_;
1088 
1089  rhs.size_ = 0UL;
1090  rhs.capacity_ = 0UL;
1091  rhs.v_ = nullptr;
1092 
1093  return *this;
1094 }
1095 //*************************************************************************************************
1096 
1097 
1098 //*************************************************************************************************
1106 template< typename Type // Data type of the vector
1107  , bool TF > // Transpose flag
1108 template< typename VT > // Type of the right-hand side vector
1110 {
1111  if( (~rhs).canAlias( this ) ) {
1112  DynamicVector tmp( ~rhs );
1113  swap( tmp );
1114  }
1115  else {
1116  resize( (~rhs).size(), false );
1118  reset();
1119  smpAssign( *this, ~rhs );
1120  }
1121 
1122  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1123 
1124  return *this;
1125 }
1126 //*************************************************************************************************
1127 
1128 
1129 //*************************************************************************************************
1139 template< typename Type // Data type of the vector
1140  , bool TF > // Transpose flag
1141 template< typename VT > // Type of the right-hand side vector
1143 {
1144  if( (~rhs).size() != size_ ) {
1145  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1146  }
1147 
1148  if( (~rhs).canAlias( this ) ) {
1149  const ResultType_<VT> tmp( ~rhs );
1150  smpAddAssign( *this, tmp );
1151  }
1152  else {
1153  smpAddAssign( *this, ~rhs );
1154  }
1155 
1156  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1157 
1158  return *this;
1159 }
1160 //*************************************************************************************************
1161 
1162 
1163 //*************************************************************************************************
1174 template< typename Type // Data type of the vector
1175  , bool TF > // Transpose flag
1176 template< typename VT > // Type of the right-hand side vector
1178 {
1179  if( (~rhs).size() != size_ ) {
1180  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1181  }
1182 
1183  if( (~rhs).canAlias( this ) ) {
1184  const ResultType_<VT> tmp( ~rhs );
1185  smpSubAssign( *this, tmp );
1186  }
1187  else {
1188  smpSubAssign( *this, ~rhs );
1189  }
1190 
1191  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1192 
1193  return *this;
1194 }
1195 //*************************************************************************************************
1196 
1197 
1198 //*************************************************************************************************
1209 template< typename Type // Data type of the vector
1210  , bool TF > // Transpose flag
1211 template< typename VT > // Type of the right-hand side vector
1213 {
1214  if( (~rhs).size() != size_ ) {
1215  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1216  }
1217 
1218  if( IsSparseVector<VT>::value || (~rhs).canAlias( this ) ) {
1219  DynamicVector<Type,TF> tmp( *this * (~rhs) );
1220  swap( tmp );
1221  }
1222  else {
1223  smpMultAssign( *this, ~rhs );
1224  }
1225 
1226  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1227 
1228  return *this;
1229 }
1230 //*************************************************************************************************
1231 
1232 
1233 //*************************************************************************************************
1243 template< typename Type // Data type of the vector
1244  , bool TF > // Transpose flag
1245 template< typename VT > // Type of the right-hand side vector
1247 {
1248  if( (~rhs).size() != size_ ) {
1249  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1250  }
1251 
1252  if( (~rhs).canAlias( this ) ) {
1253  DynamicVector<Type,TF> tmp( *this / (~rhs) );
1254  swap( tmp );
1255  }
1256  else {
1257  smpDivAssign( *this, ~rhs );
1258  }
1259 
1260  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1261 
1262  return *this;
1263 }
1264 //*************************************************************************************************
1265 
1266 
1267 //*************************************************************************************************
1274 template< typename Type // Data type of the vector
1275  , bool TF > // Transpose flag
1276 template< typename Other > // Data type of the right-hand side scalar
1279 {
1280  smpAssign( *this, (*this) * rhs );
1281 
1282  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1283 
1284  return *this;
1285 }
1286 //*************************************************************************************************
1287 
1288 
1289 //*************************************************************************************************
1298 template< typename Type // Data type of the vector
1299  , bool TF > // Transpose flag
1300 template< typename Other > // Data type of the right-hand side scalar
1301 inline EnableIf_<IsNumeric<Other>, DynamicVector<Type,TF> >&
1303 {
1304  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1305 
1306  smpAssign( *this, (*this) / rhs );
1307 
1308  BLAZE_INTERNAL_ASSERT( isIntact(), "Invariant violation detected" );
1309 
1310  return *this;
1311 }
1312 //*************************************************************************************************
1313 
1314 
1315 
1316 
1317 //=================================================================================================
1318 //
1319 // UTILITY FUNCTIONS
1320 //
1321 //=================================================================================================
1322 
1323 //*************************************************************************************************
1328 template< typename Type // Data type of the vector
1329  , bool TF > // Transpose flag
1330 inline size_t DynamicVector<Type,TF>::size() const noexcept
1331 {
1332  return size_;
1333 }
1334 //*************************************************************************************************
1335 
1336 
1337 //*************************************************************************************************
1342 template< typename Type // Data type of the vector
1343  , bool TF > // Transpose flag
1344 inline size_t DynamicVector<Type,TF>::capacity() const noexcept
1345 {
1346  return capacity_;
1347 }
1348 //*************************************************************************************************
1349 
1350 
1351 //*************************************************************************************************
1359 template< typename Type // Data type of the vector
1360  , bool TF > // Transpose flag
1362 {
1363  size_t nonzeros( 0 );
1364 
1365  for( size_t i=0UL; i<size_; ++i ) {
1366  if( !isDefault( v_[i] ) )
1367  ++nonzeros;
1368  }
1369 
1370  return nonzeros;
1371 }
1372 //*************************************************************************************************
1373 
1374 
1375 //*************************************************************************************************
1380 template< typename Type // Data type of the vector
1381  , bool TF > // Transpose flag
1383 {
1384  using blaze::clear;
1385  for( size_t i=0UL; i<size_; ++i )
1386  clear( v_[i] );
1387 }
1388 //*************************************************************************************************
1389 
1390 
1391 //*************************************************************************************************
1398 template< typename Type // Data type of the vector
1399  , bool TF > // Transpose flag
1401 {
1402  resize( 0UL, false );
1403 }
1404 //*************************************************************************************************
1405 
1406 
1407 //*************************************************************************************************
1436 template< typename Type // Data type of the vector
1437  , bool TF > // Transpose flag
1438 inline void DynamicVector<Type,TF>::resize( size_t n, bool preserve )
1439 {
1440  if( n > capacity_ )
1441  {
1442  // Allocating a new array
1443  const size_t newCapacity( adjustCapacity( n ) );
1444  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1445 
1446  // Initializing the new array
1447  if( preserve ) {
1448  transfer( v_, v_+size_, tmp );
1449  }
1450 
1452  for( size_t i=size_; i<newCapacity; ++i )
1453  tmp[i] = Type();
1454  }
1455 
1456  // Replacing the old array
1457  std::swap( v_, tmp );
1458  deallocate( tmp );
1459  capacity_ = newCapacity;
1460  }
1461  else if( IsVectorizable<Type>::value && n < size_ )
1462  {
1463  for( size_t i=n; i<size_; ++i )
1464  v_[i] = Type();
1465  }
1466 
1467  size_ = n;
1468 }
1469 //*************************************************************************************************
1470 
1471 
1472 //*************************************************************************************************
1484 template< typename Type // Data type of the vector
1485  , bool TF > // Transpose flag
1486 inline void DynamicVector<Type,TF>::extend( size_t n, bool preserve )
1487 {
1488  resize( size_+n, preserve );
1489 }
1490 //*************************************************************************************************
1491 
1492 
1493 //*************************************************************************************************
1502 template< typename Type // Data type of the vector
1503  , bool TF > // Transpose flag
1504 inline void DynamicVector<Type,TF>::reserve( size_t n )
1505 {
1506  if( n > capacity_ )
1507  {
1508  // Allocating a new array
1509  const size_t newCapacity( adjustCapacity( n ) );
1510  Type* BLAZE_RESTRICT tmp = allocate<Type>( newCapacity );
1511 
1512  // Initializing the new array
1513  transfer( v_, v_+size_, tmp );
1514 
1516  for( size_t i=size_; i<newCapacity; ++i )
1517  tmp[i] = Type();
1518  }
1519 
1520  // Replacing the old array
1521  std::swap( tmp, v_ );
1522  deallocate( tmp );
1523  capacity_ = newCapacity;
1524  }
1525 }
1526 //*************************************************************************************************
1527 
1528 
1529 //*************************************************************************************************
1535 template< typename Type // Data type of the vector
1536  , bool TF > // Transpose flag
1537 template< typename Other > // Data type of the scalar value
1539 {
1540  for( size_t i=0UL; i<size_; ++i )
1541  v_[i] *= scalar;
1542  return *this;
1543 }
1544 //*************************************************************************************************
1545 
1546 
1547 //*************************************************************************************************
1553 template< typename Type // Data type of the vector
1554  , bool TF > // Transpose flag
1556 {
1557  std::swap( size_, v.size_ );
1558  std::swap( capacity_, v.capacity_ );
1559  std::swap( v_, v.v_ );
1560 }
1561 //*************************************************************************************************
1562 
1563 
1564 //*************************************************************************************************
1570 template< typename Type // Data type of the vector
1571  , bool TF > // Transpose flag
1572 inline size_t DynamicVector<Type,TF>::adjustCapacity( size_t minCapacity ) const noexcept
1573 {
1575  return nextMultiple<size_t>( minCapacity, SIMDSIZE );
1576  else return minCapacity;
1577 }
1578 //*************************************************************************************************
1579 
1580 
1581 
1582 
1583 //=================================================================================================
1584 //
1585 // DEBUGGING FUNCTIONS
1586 //
1587 //=================================================================================================
1588 
1589 //*************************************************************************************************
1598 template< typename Type // Data type of the vector
1599  , bool TF > // Transpose flag
1600 inline bool DynamicVector<Type,TF>::isIntact() const noexcept
1601 {
1602  if( size_ > capacity_ )
1603  return false;
1604 
1605  if( IsNumeric<Type>::value ) {
1606  for( size_t i=size_; i<capacity_; ++i ) {
1607  if( v_[i] != Type() )
1608  return false;
1609  }
1610  }
1611 
1612  return true;
1613 }
1614 //*************************************************************************************************
1615 
1616 
1617 
1618 
1619 //=================================================================================================
1620 //
1621 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1622 //
1623 //=================================================================================================
1624 
1625 //*************************************************************************************************
1635 template< typename Type // Data type of the vector
1636  , bool TF > // Transpose flag
1637 template< typename Other > // Data type of the foreign expression
1638 inline bool DynamicVector<Type,TF>::canAlias( const Other* alias ) const noexcept
1639 {
1640  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1641 }
1642 //*************************************************************************************************
1643 
1644 
1645 //*************************************************************************************************
1655 template< typename Type // Data type of the vector
1656  , bool TF > // Transpose flag
1657 template< typename Other > // Data type of the foreign expression
1658 inline bool DynamicVector<Type,TF>::isAliased( const Other* alias ) const noexcept
1659 {
1660  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1661 }
1662 //*************************************************************************************************
1663 
1664 
1665 //*************************************************************************************************
1674 template< typename Type // Data type of the vector
1675  , bool TF > // Transpose flag
1676 inline bool DynamicVector<Type,TF>::isAligned() const noexcept
1677 {
1678  return true;
1679 }
1680 //*************************************************************************************************
1681 
1682 
1683 //*************************************************************************************************
1693 template< typename Type // Data type of the vector
1694  , bool TF > // Transpose flag
1695 inline bool DynamicVector<Type,TF>::canSMPAssign() const noexcept
1696 {
1697  return ( size() > SMP_DVECASSIGN_THRESHOLD );
1698 }
1699 //*************************************************************************************************
1700 
1701 
1702 //*************************************************************************************************
1714 template< typename Type // Data type of the vector
1715  , bool TF > // Transpose flag
1717  DynamicVector<Type,TF>::load( size_t index ) const noexcept
1718 {
1719  return loada( index );
1720 }
1721 //*************************************************************************************************
1722 
1723 
1724 //*************************************************************************************************
1737 template< typename Type // Data type of the vector
1738  , bool TF > // Transpose flag
1740  DynamicVector<Type,TF>::loada( size_t index ) const noexcept
1741 {
1742  using blaze::loada;
1743 
1745 
1746  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1747  BLAZE_INTERNAL_ASSERT( index + SIMDSIZE <= capacity_, "Invalid vector access index" );
1748  BLAZE_INTERNAL_ASSERT( index % SIMDSIZE == 0UL, "Invalid vector access index" );
1749  BLAZE_INTERNAL_ASSERT( checkAlignment( v_+index ), "Invalid alignment detected" );
1750 
1751  return loada( v_+index );
1752 }
1753 //*************************************************************************************************
1754 
1755 
1756 //*************************************************************************************************
1769 template< typename Type // Data type of the vector
1770  , bool TF > // Transpose flag
1772  DynamicVector<Type,TF>::loadu( size_t index ) const noexcept
1773 {
1774  using blaze::loadu;
1775 
1777 
1778  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1779  BLAZE_INTERNAL_ASSERT( index + SIMDSIZE <= capacity_, "Invalid vector access index" );
1780 
1781  return loadu( v_+index );
1782 }
1783 //*************************************************************************************************
1784 
1785 
1786 //*************************************************************************************************
1799 template< typename Type // Data type of the vector
1800  , bool TF > // Transpose flag
1802  DynamicVector<Type,TF>::store( size_t index, const SIMDType& value ) noexcept
1803 {
1804  storea( index, value );
1805 }
1806 //*************************************************************************************************
1807 
1808 
1809 //*************************************************************************************************
1822 template< typename Type // Data type of the vector
1823  , bool TF > // Transpose flag
1825  DynamicVector<Type,TF>::storea( size_t index, const SIMDType& value ) noexcept
1826 {
1827  using blaze::storea;
1828 
1830 
1831  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1832  BLAZE_INTERNAL_ASSERT( index + SIMDSIZE <= capacity_, "Invalid vector access index" );
1833  BLAZE_INTERNAL_ASSERT( index % SIMDSIZE == 0UL, "Invalid vector access index" );
1834  BLAZE_INTERNAL_ASSERT( checkAlignment( v_+index ), "Invalid alignment detected" );
1835 
1836  storea( v_+index, value );
1837 }
1838 //*************************************************************************************************
1839 
1840 
1841 //*************************************************************************************************
1854 template< typename Type // Data type of the vector
1855  , bool TF > // Transpose flag
1857  DynamicVector<Type,TF>::storeu( size_t index, const SIMDType& value ) noexcept
1858 {
1859  using blaze::storeu;
1860 
1862 
1863  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1864  BLAZE_INTERNAL_ASSERT( index + SIMDSIZE <= capacity_, "Invalid vector access index" );
1865 
1866  storeu( v_+index, value );
1867 }
1868 //*************************************************************************************************
1869 
1870 
1871 //*************************************************************************************************
1885 template< typename Type // Data type of the vector
1886  , bool TF > // Transpose flag
1888  DynamicVector<Type,TF>::stream( size_t index, const SIMDType& value ) noexcept
1889 {
1890  using blaze::stream;
1891 
1893 
1894  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1895  BLAZE_INTERNAL_ASSERT( index + SIMDSIZE <= capacity_, "Invalid vector access index" );
1896  BLAZE_INTERNAL_ASSERT( index % SIMDSIZE == 0UL, "Invalid vector access index" );
1897  BLAZE_INTERNAL_ASSERT( checkAlignment( v_+index ), "Invalid alignment detected" );
1898 
1899  stream( v_+index, value );
1900 }
1901 //*************************************************************************************************
1902 
1903 
1904 //*************************************************************************************************
1915 template< typename Type // Data type of the vector
1916  , bool TF > // Transpose flag
1917 template< typename VT > // Type of the right-hand side dense vector
1920 {
1921  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1922 
1923  const size_t ipos( size_ & size_t(-2) );
1924  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
1925 
1926  for( size_t i=0UL; i<ipos; i+=2UL ) {
1927  v_[i ] = (~rhs)[i ];
1928  v_[i+1UL] = (~rhs)[i+1UL];
1929  }
1930  if( ipos < (~rhs).size() )
1931  v_[ipos] = (~rhs)[ipos];
1932 }
1933 //*************************************************************************************************
1934 
1935 
1936 //*************************************************************************************************
1947 template< typename Type // Data type of the vector
1948  , bool TF > // Transpose flag
1949 template< typename VT > // Type of the right-hand side dense vector
1952 {
1954 
1955  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
1956 
1957  const bool remainder( !usePadding || !IsPadded<VT>::value );
1958 
1959  const size_t ipos( ( remainder )?( size_ & size_t(-SIMDSIZE) ):( size_ ) );
1960  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % (SIMDSIZE) ) ) == ipos, "Invalid end calculation" );
1961 
1962  size_t i=0UL;
1963  Iterator left( begin() );
1964  ConstIterator_<VT> right( (~rhs).begin() );
1965 
1966  if( useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
1967  {
1968  for( ; i<ipos; i+=SIMDSIZE ) {
1969  left.stream( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1970  }
1971  for( ; remainder && i<size_; ++i ) {
1972  *left = *right; ++left; ++right;
1973  }
1974  }
1975  else
1976  {
1977  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
1978  left.store( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1979  left.store( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1980  left.store( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1981  left.store( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1982  }
1983  for( ; i<ipos; i+=SIMDSIZE ) {
1984  left.store( right.load() ); left += SIMDSIZE; right += SIMDSIZE;
1985  }
1986  for( ; remainder && i<size_; ++i ) {
1987  *left = *right; ++left; ++right;
1988  }
1989  }
1990 }
1991 //*************************************************************************************************
1992 
1993 
1994 //*************************************************************************************************
2005 template< typename Type // Data type of the vector
2006  , bool TF > // Transpose flag
2007 template< typename VT > // Type of the right-hand side sparse vector
2009 {
2010  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2011 
2012  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2013  v_[element->index()] = element->value();
2014 }
2015 //*************************************************************************************************
2016 
2017 
2018 //*************************************************************************************************
2029 template< typename Type // Data type of the vector
2030  , bool TF > // Transpose flag
2031 template< typename VT > // Type of the right-hand side dense vector
2032 inline DisableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >
2034 {
2035  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2036 
2037  const size_t ipos( size_ & size_t(-2) );
2038  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2039 
2040  for( size_t i=0UL; i<ipos; i+=2UL ) {
2041  v_[i ] += (~rhs)[i ];
2042  v_[i+1UL] += (~rhs)[i+1UL];
2043  }
2044  if( ipos < (~rhs).size() )
2045  v_[ipos] += (~rhs)[ipos];
2046 }
2047 //*************************************************************************************************
2048 
2049 
2050 //*************************************************************************************************
2061 template< typename Type // Data type of the vector
2062  , bool TF > // Transpose flag
2063 template< typename VT > // Type of the right-hand side dense vector
2064 inline EnableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >
2066 {
2068 
2069  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2070 
2071  const bool remainder( !usePadding || !IsPadded<VT>::value );
2072 
2073  const size_t ipos( ( remainder )?( size_ & size_t(-SIMDSIZE) ):( size_ ) );
2074  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % (SIMDSIZE) ) ) == ipos, "Invalid end calculation" );
2075 
2076  size_t i( 0UL );
2077  Iterator left( begin() );
2078  ConstIterator_<VT> right( (~rhs).begin() );
2079 
2080  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
2081  left.store( left.load() + right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2082  left.store( left.load() + right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2083  left.store( left.load() + right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2084  left.store( left.load() + right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2085  }
2086  for( ; i<ipos; i+=SIMDSIZE ) {
2087  left.store( left.load() + right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2088  }
2089  for( ; remainder && i<size_; ++i ) {
2090  *left += *right; ++left; ++right;
2091  }
2092 }
2093 //*************************************************************************************************
2094 
2095 
2096 //*************************************************************************************************
2107 template< typename Type // Data type of the vector
2108  , bool TF > // Transpose flag
2109 template< typename VT > // Type of the right-hand side sparse vector
2111 {
2112  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2113 
2114  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2115  v_[element->index()] += element->value();
2116 }
2117 //*************************************************************************************************
2118 
2119 
2120 //*************************************************************************************************
2131 template< typename Type // Data type of the vector
2132  , bool TF > // Transpose flag
2133 template< typename VT > // Type of the right-hand side dense vector
2134 inline DisableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >
2136 {
2137  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2138 
2139  const size_t ipos( size_ & size_t(-2) );
2140  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2141 
2142  for( size_t i=0UL; i<ipos; i+=2UL ) {
2143  v_[i ] -= (~rhs)[i ];
2144  v_[i+1UL] -= (~rhs)[i+1UL];
2145  }
2146  if( ipos < (~rhs).size() )
2147  v_[ipos] -= (~rhs)[ipos];
2148 }
2149 //*************************************************************************************************
2150 
2151 
2152 //*************************************************************************************************
2163 template< typename Type // Data type of the vector
2164  , bool TF > // Transpose flag
2165 template< typename VT > // Type of the right-hand side dense vector
2166 inline EnableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >
2168 {
2170 
2171  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2172 
2173  const bool remainder( !usePadding || !IsPadded<VT>::value );
2174 
2175  const size_t ipos( ( remainder )?( size_ & size_t(-SIMDSIZE) ):( size_ ) );
2176  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % (SIMDSIZE) ) ) == ipos, "Invalid end calculation" );
2177 
2178  size_t i( 0UL );
2179  Iterator left( begin() );
2180  ConstIterator_<VT> right( (~rhs).begin() );
2181 
2182  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
2183  left.store( left.load() - right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2184  left.store( left.load() - right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2185  left.store( left.load() - right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2186  left.store( left.load() - right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2187  }
2188  for( ; i<ipos; i+=SIMDSIZE ) {
2189  left.store( left.load() - right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2190  }
2191  for( ; remainder && i<size_; ++i ) {
2192  *left -= *right; ++left; ++right;
2193  }
2194 }
2195 //*************************************************************************************************
2196 
2197 
2198 //*************************************************************************************************
2209 template< typename Type // Data type of the vector
2210  , bool TF > // Transpose flag
2211 template< typename VT > // Type of the right-hand side sparse vector
2213 {
2214  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2215 
2216  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2217  v_[element->index()] -= element->value();
2218 }
2219 //*************************************************************************************************
2220 
2221 
2222 //*************************************************************************************************
2233 template< typename Type // Data type of the vector
2234  , bool TF > // Transpose flag
2235 template< typename VT > // Type of the right-hand side dense vector
2236 inline DisableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >
2238 {
2239  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2240 
2241  const size_t ipos( size_ & size_t(-2) );
2242  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2243 
2244  for( size_t i=0UL; i<ipos; i+=2UL ) {
2245  v_[i ] *= (~rhs)[i ];
2246  v_[i+1UL] *= (~rhs)[i+1UL];
2247  }
2248  if( ipos < (~rhs).size() )
2249  v_[ipos] *= (~rhs)[ipos];
2250 }
2251 //*************************************************************************************************
2252 
2253 
2254 //*************************************************************************************************
2265 template< typename Type // Data type of the vector
2266  , bool TF > // Transpose flag
2267 template< typename VT > // Type of the right-hand side dense vector
2268 inline EnableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >
2270 {
2272 
2273  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2274 
2275  const bool remainder( !usePadding || !IsPadded<VT>::value );
2276 
2277  const size_t ipos( ( remainder )?( size_ & size_t(-SIMDSIZE) ):( size_ ) );
2278  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % (SIMDSIZE) ) ) == ipos, "Invalid end calculation" );
2279 
2280  size_t i( 0UL );
2281  Iterator left( begin() );
2282  ConstIterator_<VT> right( (~rhs).begin() );
2283 
2284  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
2285  left.store( left.load() * right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2286  left.store( left.load() * right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2287  left.store( left.load() * right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2288  left.store( left.load() * right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2289  }
2290  for( ; i<ipos; i+=SIMDSIZE ) {
2291  left.store( left.load() * right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2292  }
2293  for( ; remainder && i<size_; ++i ) {
2294  *left *= *right; ++left; ++right;
2295  }
2296 }
2297 //*************************************************************************************************
2298 
2299 
2300 //*************************************************************************************************
2311 template< typename Type // Data type of the vector
2312  , bool TF > // Transpose flag
2313 template< typename VT > // Type of the right-hand side sparse vector
2315 {
2316  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2317 
2318  const DynamicVector tmp( serial( *this ) );
2319 
2320  reset();
2321 
2322  for( ConstIterator_<VT> element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2323  v_[element->index()] = tmp[element->index()] * element->value();
2324 }
2325 //*************************************************************************************************
2326 
2327 
2328 //*************************************************************************************************
2339 template< typename Type // Data type of the vector
2340  , bool TF > // Transpose flag
2341 template< typename VT > // Type of the right-hand side dense vector
2342 inline DisableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedDivAssign<VT> >
2344 {
2345  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2346 
2347  const size_t ipos( size_ & size_t(-2) );
2348  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2349 
2350  for( size_t i=0UL; i<ipos; i+=2UL ) {
2351  v_[i ] /= (~rhs)[i ];
2352  v_[i+1UL] /= (~rhs)[i+1UL];
2353  }
2354  if( ipos < (~rhs).size() )
2355  v_[ipos] /= (~rhs)[ipos];
2356 }
2357 //*************************************************************************************************
2358 
2359 
2360 //*************************************************************************************************
2371 template< typename Type // Data type of the vector
2372  , bool TF > // Transpose flag
2373 template< typename VT > // Type of the right-hand side dense vector
2374 inline EnableIf_<typename DynamicVector<Type,TF>::BLAZE_TEMPLATE VectorizedDivAssign<VT> >
2376 {
2378 
2379  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2380 
2381  const size_t ipos( size_ & size_t(-SIMDSIZE) );
2382  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (SIMDSIZE) ) ) == ipos, "Invalid end calculation" );
2383 
2384  size_t i( 0UL );
2385  Iterator left( begin() );
2386  ConstIterator_<VT> right( (~rhs).begin() );
2387 
2388  for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
2389  left.store( left.load() / right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2390  left.store( left.load() / right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2391  left.store( left.load() / right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2392  left.store( left.load() / right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2393  }
2394  for( ; i<ipos; i+=SIMDSIZE ) {
2395  left.store( left.load() / right.load() ); left += SIMDSIZE; right += SIMDSIZE;
2396  }
2397  for( ; i<size_; ++i ) {
2398  *left /= *right; ++left; ++right;
2399  }
2400 }
2401 //*************************************************************************************************
2402 
2403 
2404 
2405 
2406 //=================================================================================================
2407 //
2408 // DYNAMICVECTOR OPERATORS
2409 //
2410 //=================================================================================================
2411 
2412 //*************************************************************************************************
2415 template< typename Type, bool TF >
2416 inline void reset( DynamicVector<Type,TF>& v );
2417 
2418 template< typename Type, bool TF >
2419 inline void clear( DynamicVector<Type,TF>& v );
2420 
2421 template< typename Type, bool TF >
2422 inline bool isDefault( const DynamicVector<Type,TF>& v );
2423 
2424 template< typename Type, bool TF >
2425 inline bool isIntact( const DynamicVector<Type,TF>& v ) noexcept;
2426 
2427 template< typename Type, bool TF >
2428 inline void swap( DynamicVector<Type,TF>& a, DynamicVector<Type,TF>& b ) noexcept;
2430 //*************************************************************************************************
2431 
2432 
2433 //*************************************************************************************************
2440 template< typename Type // Data type of the vector
2441  , bool TF > // Transpose flag
2443 {
2444  v.reset();
2445 }
2446 //*************************************************************************************************
2447 
2448 
2449 //*************************************************************************************************
2456 template< typename Type // Data type of the vector
2457  , bool TF > // Transpose flag
2459 {
2460  v.clear();
2461 }
2462 //*************************************************************************************************
2463 
2464 
2465 //*************************************************************************************************
2482 template< typename Type // Data type of the vector
2483  , bool TF > // Transpose flag
2484 inline bool isDefault( const DynamicVector<Type,TF>& v )
2485 {
2486  return ( v.size() == 0UL );
2487 }
2488 //*************************************************************************************************
2489 
2490 
2491 //*************************************************************************************************
2509 template< typename Type // Data type of the vector
2510  , bool TF > // Transpose flag
2511 inline bool isIntact( const DynamicVector<Type,TF>& v ) noexcept
2512 {
2513  return v.isIntact();
2514 }
2515 //*************************************************************************************************
2516 
2517 
2518 //*************************************************************************************************
2526 template< typename Type // Data type of the vector
2527  , bool TF > // Transpose flag
2529 {
2530  a.swap( b );
2531 }
2532 //*************************************************************************************************
2533 
2534 
2535 
2536 
2537 //=================================================================================================
2538 //
2539 // HASCONSTDATAACCESS SPECIALIZATIONS
2540 //
2541 //=================================================================================================
2542 
2543 //*************************************************************************************************
2545 template< typename T, bool TF >
2546 struct HasConstDataAccess< DynamicVector<T,TF> > : public TrueType
2547 {};
2549 //*************************************************************************************************
2550 
2551 
2552 
2553 
2554 //=================================================================================================
2555 //
2556 // HASMUTABLEDATAACCESS SPECIALIZATIONS
2557 //
2558 //=================================================================================================
2559 
2560 //*************************************************************************************************
2562 template< typename T, bool TF >
2563 struct HasMutableDataAccess< DynamicVector<T,TF> > : public TrueType
2564 {};
2566 //*************************************************************************************************
2567 
2568 
2569 
2570 
2571 //=================================================================================================
2572 //
2573 // ISALIGNED SPECIALIZATIONS
2574 //
2575 //=================================================================================================
2576 
2577 //*************************************************************************************************
2579 template< typename T, bool TF >
2580 struct IsAligned< DynamicVector<T,TF> > : public TrueType
2581 {};
2583 //*************************************************************************************************
2584 
2585 
2586 
2587 
2588 //=================================================================================================
2589 //
2590 // ISPADDED SPECIALIZATIONS
2591 //
2592 //=================================================================================================
2593 
2594 //*************************************************************************************************
2596 template< typename T, bool TF >
2597 struct IsPadded< DynamicVector<T,TF> > : public BoolConstant<usePadding>
2598 {};
2600 //*************************************************************************************************
2601 
2602 
2603 
2604 
2605 //=================================================================================================
2606 //
2607 // ISRESIZABLE SPECIALIZATIONS
2608 //
2609 //=================================================================================================
2610 
2611 //*************************************************************************************************
2613 template< typename T, bool TF >
2614 struct IsResizable< DynamicVector<T,TF> > : public TrueType
2615 {};
2617 //*************************************************************************************************
2618 
2619 
2620 
2621 
2622 //=================================================================================================
2623 //
2624 // ADDTRAIT SPECIALIZATIONS
2625 //
2626 //=================================================================================================
2627 
2628 //*************************************************************************************************
2630 template< typename T1, bool TF, typename T2, size_t N >
2631 struct AddTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2632 {
2633  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2634 };
2635 
2636 template< typename T1, size_t N, bool TF, typename T2 >
2637 struct AddTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2638 {
2639  using Type = StaticVector< AddTrait_<T1,T2>, N, TF >;
2640 };
2641 
2642 template< typename T1, bool TF, typename T2, size_t N >
2643 struct AddTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2644 {
2645  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2646 };
2647 
2648 template< typename T1, size_t N, bool TF, typename T2 >
2649 struct AddTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2650 {
2651  using Type = HybridVector< AddTrait_<T1,T2>, N, TF >;
2652 };
2653 
2654 template< typename T1, bool TF, typename T2 >
2655 struct AddTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2656 {
2657  using Type = DynamicVector< AddTrait_<T1,T2>, TF >;
2658 };
2660 //*************************************************************************************************
2661 
2662 
2663 
2664 
2665 //=================================================================================================
2666 //
2667 // SUBTRAIT SPECIALIZATIONS
2668 //
2669 //=================================================================================================
2670 
2671 //*************************************************************************************************
2673 template< typename T1, bool TF, typename T2, size_t N >
2674 struct SubTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2675 {
2676  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2677 };
2678 
2679 template< typename T1, size_t N, bool TF, typename T2 >
2680 struct SubTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2681 {
2682  using Type = StaticVector< SubTrait_<T1,T2>, N, TF >;
2683 };
2684 
2685 template< typename T1, bool TF, typename T2, size_t N >
2686 struct SubTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2687 {
2688  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2689 };
2690 
2691 template< typename T1, size_t N, bool TF, typename T2 >
2692 struct SubTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2693 {
2694  using Type = HybridVector< SubTrait_<T1,T2>, N, TF >;
2695 };
2696 
2697 template< typename T1, bool TF, typename T2 >
2698 struct SubTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2699 {
2700  using Type = DynamicVector< SubTrait_<T1,T2>, TF >;
2701 };
2703 //*************************************************************************************************
2704 
2705 
2706 
2707 
2708 //=================================================================================================
2709 //
2710 // MULTTRAIT SPECIALIZATIONS
2711 //
2712 //=================================================================================================
2713 
2714 //*************************************************************************************************
2716 template< typename T1, bool TF, typename T2 >
2717 struct MultTrait< DynamicVector<T1,TF>, T2, EnableIf_<IsNumeric<T2> > >
2718 {
2719  using Type = DynamicVector< MultTrait_<T1,T2>, TF >;
2720 };
2721 
2722 template< typename T1, typename T2, bool TF >
2723 struct MultTrait< T1, DynamicVector<T2,TF>, EnableIf_<IsNumeric<T1> > >
2724 {
2725  using Type = DynamicVector< MultTrait_<T1,T2>, TF >;
2726 };
2727 
2728 template< typename T1, bool TF, typename T2, size_t N >
2729 struct MultTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2730 {
2731  using Type = StaticVector< MultTrait_<T1,T2>, N, TF >;
2732 };
2733 
2734 template< typename T1, typename T2, size_t N >
2735 struct MultTrait< DynamicVector<T1,false>, StaticVector<T2,N,true> >
2736 {
2737  using Type = DynamicMatrix< MultTrait_<T1,T2>, false >;
2738 };
2739 
2740 template< typename T1, typename T2, size_t N >
2741 struct MultTrait< DynamicVector<T1,true>, StaticVector<T2,N,false> >
2742 {
2743  using Type = MultTrait_<T1,T2>;
2744 };
2745 
2746 template< typename T1, size_t N, bool TF, typename T2 >
2747 struct MultTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2748 {
2749  using Type = StaticVector< MultTrait_<T1,T2>, N, TF >;
2750 };
2751 
2752 template< typename T1, size_t N, typename T2 >
2753 struct MultTrait< StaticVector<T1,N,false>, DynamicVector<T2,true> >
2754 {
2755  using Type = DynamicMatrix< MultTrait_<T1,T2>, false >;
2756 };
2757 
2758 template< typename T1, size_t N, typename T2 >
2759 struct MultTrait< StaticVector<T1,N,true>, DynamicVector<T2,false> >
2760 {
2761  using Type = MultTrait_<T1,T2>;
2762 };
2763 
2764 template< typename T1, bool TF, typename T2, size_t N >
2765 struct MultTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2766 {
2767  using Type = HybridVector< MultTrait_<T1,T2>, N, TF >;
2768 };
2769 
2770 template< typename T1, typename T2, size_t N >
2771 struct MultTrait< DynamicVector<T1,false>, HybridVector<T2,N,true> >
2772 {
2773  using Type = DynamicMatrix< MultTrait_<T1,T2>, false >;
2774 };
2775 
2776 template< typename T1, typename T2, size_t N >
2777 struct MultTrait< DynamicVector<T1,true>, HybridVector<T2,N,false> >
2778 {
2779  using Type = MultTrait_<T1,T2>;
2780 };
2781 
2782 template< typename T1, size_t N, bool TF, typename T2 >
2783 struct MultTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2784 {
2785  using Type = HybridVector< MultTrait_<T1,T2>, N, TF >;
2786 };
2787 
2788 template< typename T1, size_t N, typename T2 >
2789 struct MultTrait< HybridVector<T1,N,false>, DynamicVector<T2,true> >
2790 {
2791  using Type = DynamicMatrix< MultTrait_<T1,T2>, false >;
2792 };
2793 
2794 template< typename T1, size_t N, typename T2 >
2795 struct MultTrait< HybridVector<T1,N,true>, DynamicVector<T2,false> >
2796 {
2797  using Type = MultTrait_<T1,T2>;
2798 };
2799 
2800 template< typename T1, bool TF, typename T2 >
2801 struct MultTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2802 {
2803  using Type = DynamicVector< MultTrait_<T1,T2>, TF >;
2804 };
2805 
2806 template< typename T1, typename T2 >
2807 struct MultTrait< DynamicVector<T1,false>, DynamicVector<T2,true> >
2808 {
2809  using Type = DynamicMatrix< MultTrait_<T1,T2>, false >;
2810 };
2811 
2812 template< typename T1, typename T2 >
2813 struct MultTrait< DynamicVector<T1,true>, DynamicVector<T2,false> >
2814 {
2815  using Type = MultTrait_<T1,T2>;
2816 };
2818 //*************************************************************************************************
2819 
2820 
2821 
2822 
2823 //=================================================================================================
2824 //
2825 // CROSSTRAIT SPECIALIZATIONS
2826 //
2827 //=================================================================================================
2828 
2829 //*************************************************************************************************
2831 template< typename T1, bool TF, typename T2 >
2832 struct CrossTrait< DynamicVector<T1,TF>, StaticVector<T2,3UL,TF> >
2833 {
2834  private:
2835  using T = MultTrait_<T1,T2>;
2836 
2837  public:
2838  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2839 };
2840 
2841 template< typename T1, bool TF, typename T2 >
2842 struct CrossTrait< StaticVector<T1,3UL,TF>, DynamicVector<T2,TF> >
2843 {
2844  private:
2845  using T = MultTrait_<T1,T2>;
2846 
2847  public:
2848  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2849 };
2850 
2851 template< typename T1, bool TF, typename T2, size_t N >
2852 struct CrossTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2853 {
2854  private:
2855  using T = MultTrait_<T1,T2>;
2856 
2857  public:
2858  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2859 };
2860 
2861 template< typename T1, size_t N, bool TF, typename T2 >
2862 struct CrossTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2863 {
2864  private:
2865  using T = MultTrait_<T1,T2>;
2866 
2867  public:
2868  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2869 };
2870 
2871 template< typename T1, bool TF, typename T2 >
2872 struct CrossTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2873 {
2874  private:
2875  using T = MultTrait_<T1,T2>;
2876 
2877  public:
2878  using Type = StaticVector< SubTrait_<T,T>, 3UL, TF >;
2879 };
2881 //*************************************************************************************************
2882 
2883 
2884 
2885 
2886 //=================================================================================================
2887 //
2888 // DIVTRAIT SPECIALIZATIONS
2889 //
2890 //=================================================================================================
2891 
2892 //*************************************************************************************************
2894 template< typename T1, bool TF, typename T2 >
2895 struct DivTrait< DynamicVector<T1,TF>, T2, EnableIf_<IsNumeric<T2> > >
2896 {
2897  using Type = DynamicVector< DivTrait_<T1,T2>, TF >;
2898 };
2899 
2900 template< typename T1, bool TF, typename T2, size_t N >
2901 struct DivTrait< DynamicVector<T1,TF>, StaticVector<T2,N,TF> >
2902 {
2903  using Type = StaticVector< DivTrait_<T1,T2>, N, TF >;
2904 };
2905 
2906 template< typename T1, size_t N, bool TF, typename T2 >
2907 struct DivTrait< StaticVector<T1,N,TF>, DynamicVector<T2,TF> >
2908 {
2909  using Type = StaticVector< DivTrait_<T1,T2>, N, TF >;
2910 };
2911 
2912 template< typename T1, bool TF, typename T2, size_t N >
2913 struct DivTrait< DynamicVector<T1,TF>, HybridVector<T2,N,TF> >
2914 {
2915  using Type = HybridVector< DivTrait_<T1,T2>, N, TF >;
2916 };
2917 
2918 template< typename T1, size_t N, bool TF, typename T2 >
2919 struct DivTrait< HybridVector<T1,N,TF>, DynamicVector<T2,TF> >
2920 {
2921  using Type = HybridVector< DivTrait_<T1,T2>, N, TF >;
2922 };
2923 
2924 template< typename T1, bool TF, typename T2 >
2925 struct DivTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2926 {
2927  using Type = DynamicVector< DivTrait_<T1,T2>, TF >;
2928 };
2930 //*************************************************************************************************
2931 
2932 
2933 
2934 
2935 //=================================================================================================
2936 //
2937 // MATHTRAIT SPECIALIZATIONS
2938 //
2939 //=================================================================================================
2940 
2941 //*************************************************************************************************
2943 template< typename T1, bool TF, typename T2 >
2944 struct MathTrait< DynamicVector<T1,TF>, DynamicVector<T2,TF> >
2945 {
2946  using HighType = DynamicVector< typename MathTrait<T1,T2>::HighType, TF >;
2947  using LowType = DynamicVector< typename MathTrait<T1,T2>::LowType , TF >;
2948 };
2950 //*************************************************************************************************
2951 
2952 
2953 
2954 
2955 //=================================================================================================
2956 //
2957 // SUBVECTORTRAIT SPECIALIZATIONS
2958 //
2959 //=================================================================================================
2960 
2961 //*************************************************************************************************
2963 template< typename T1, bool TF >
2964 struct SubvectorTrait< DynamicVector<T1,TF> >
2965 {
2966  using Type = DynamicVector<T1,TF>;
2967 };
2969 //*************************************************************************************************
2970 
2971 } // namespace blaze
2972 
2973 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:133
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
BLAZE_ALWAYS_INLINE void stream(size_t index, const SIMDType &value) noexcept
Aligned, non-temporal store of a SIMD element of the vector.
Definition: DynamicVector.h:1888
BLAZE_ALWAYS_INLINE void store(size_t index, const SIMDType &value) noexcept
Store of a SIMD element of the vector.
Definition: DynamicVector.h:1802
Header file for auxiliary alias declarations.
DenseIterator< Type, aligned > Iterator
Iterator over non-constant elements.
Definition: DynamicVector.h:194
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:79
Type *BLAZE_RESTRICT v_
The dynamically allocated vector elements.
Definition: DynamicVector.h:458
BLAZE_ALWAYS_INLINE SIMDType load(size_t index) const noexcept
Load of a SIMD element of the vector.
Definition: DynamicVector.h:1717
Header file for mathematical functions.
constexpr bool useOptimizedKernels
Configuration switch for optimized kernels.This configuration switch enables/disables all optimized c...
Definition: Optimizations.h:84
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the alignment flag values.
BLAZE_ALWAYS_INLINE void storea(size_t index, const SIMDType &value) noexcept
Aligned store of a SIMD element of the vector.
Definition: DynamicVector.h:1825
Header file for the subtraction trait.
Header file for basic type definitions.
Header file for the SparseVector base class.
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: DynamicVector.h:1361
bool isAligned() const noexcept
Returns whether the vector is properly aligned in memory.
Definition: DynamicVector.h:1676
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > storea(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned store of a vector of 1-byte integral values.
Definition: Storea.h:79
EnableIf_< IsDenseMatrix< MT1 > > smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
void clear()
Clearing the vector.
Definition: DynamicVector.h:1400
Header file for the serial shim.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:258
constexpr size_t cacheSize
Cache size of the target architecture.This setting specifies the available cache size in Byte of the ...
Definition: CacheSize.h:48
SIMDTrait_< ElementType > SIMDType
SIMD type of the vector elements.
Definition: DynamicVector.h:185
bool canSMPAssign() const noexcept
Returns whether the vector can be used in SMP assignments.
Definition: DynamicVector.h:1695
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:188
typename SIMDTrait< T >::Type SIMDTrait_
Auxiliary alias declaration for the SIMDTrait class template.The SIMDTrait_ alias declaration provide...
Definition: SIMDTrait.h:315
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:533
const Type * ConstPointer
Pointer to a constant vector value.
Definition: DynamicVector.h:192
EnableIf_< IsDenseVector< VT1 > > smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:193
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
OutputIterator transfer(InputIterator first, InputIterator last, OutputIterator dest)
Transfers the elements from the given source range to the destination range.
Definition: Algorithm.h:71
Header file for the DenseVector base class.
BLAZE_ALWAYS_INLINE void storeu(size_t index, const SIMDType &value) noexcept
Unaligned store of a SIMD element of the vector.
Definition: DynamicVector.h:1857
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:723
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:176
Header file for memory allocation and deallocation functionality.
System settings for performance optimizations.
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loadu(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loadu.h:77
typename T::ResultType ResultType_
Alias declaration for nested ResultType type definitions.The ResultType_ alias declaration provides a...
Definition: Aliases.h:323
EnableIf_< IsDenseMatrix< MT1 > > smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
DenseVector< This, TF > BaseType
Base type of this DynamicVector instance.
Definition: DynamicVector.h:181
bool canAlias(const Other *alias) const noexcept
Returns whether the vector can alias with the given address alias.
Definition: DynamicVector.h:1638
BLAZE_ALWAYS_INLINE SIMDType loadu(size_t index) const noexcept
Unaligned load of a SIMD element of the vector.
Definition: DynamicVector.h:1772
ConstIterator cend() const noexcept
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:954
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:573
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2807
Header file for the std::initializer_list aliases.
~DynamicVector()
The destructor for DynamicVector.
Definition: DynamicVector.h:744
Iterator begin() noexcept
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:884
EnableIf_< IsBuiltin< T >, T * > allocate(size_t size)
Aligned array allocation for built-in data types.
Definition: Memory.h:150
DynamicVector< ET, TF > Other
The type of the other DynamicVector.
Definition: DynamicVector.h:203
DenseIterator< const Type, aligned > ConstIterator
Iterator over constant elements.
Definition: DynamicVector.h:195
Header file for the DisableIf class template.
This ResultType
Result type for expression template evaluations.
Definition: DynamicVector.h:182
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: DynamicVector.h:1438
Header file for the multiplication trait.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
bool isIntact() const noexcept
Returns whether the invariants of the dynamic vector are intact.
Definition: DynamicVector.h:1600
Header file for nested template disabiguation.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b) noexcept
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:5148
constexpr bool useStreaming
Configuration of the streaming behavior.For large vectors and matrices non-temporal stores can provid...
Definition: Optimizations.h:68
constexpr bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2647
const Type & ReturnType
Return type for expression template evaluations.
Definition: DynamicVector.h:186
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the IsSMPAssignable type trait.
Compile time check for data types with padding.This type trait tests whether the given data type empl...
Definition: IsPadded.h:76
EnableIf_< IsDenseMatrix< MT1 > > smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
DynamicVector() noexcept
The default constructor for DynamicVector.
Definition: DynamicVector.h:492
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
void stream(const SIMDType &value) const noexcept
Aligned, non-temporal store of the SIMD element at the current iterator position. ...
Definition: DenseIterator.h:531
Header file for the HasSIMDAdd type trait.
Header file for the DenseIterator class template.
size_t capacity() const noexcept
Returns the maximum capacity of the vector.
Definition: DynamicVector.h:1344
size_t adjustCapacity(size_t minCapacity) const noexcept
Adjusting the new capacity of the vector according to its data type Type.
Definition: DynamicVector.h:1572
Header file for the subvector trait.
Header file for all SIMD functionality.
Constraint on the data type.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Compile time check for sparse vector types.This type trait tests whether or not the given template pa...
Definition: IsSparseVector.h:78
void reset()
Reset to the default initial values.
Definition: DynamicVector.h:1382
Reference operator[](size_t index) noexcept
Subscript operator for the direct access to the vector elements.
Definition: DynamicVector.h:771
Header file for the IsAligned type trait.
size_t size_
The current size/dimension of the vector.
Definition: DynamicVector.h:456
BLAZE_ALWAYS_INLINE const EnableIf_< And< IsIntegral< T >, HasSize< T, 1UL > >, If_< IsSigned< T >, SIMDint8, SIMDuint8 > > loada(const T *address) noexcept
Loads a vector of 1-byte integral values.
Definition: Loada.h:80
#define BLAZE_RESTRICT
Platform dependent setup of the restrict keyword.
Definition: Restrict.h:81
Type & Reference
Reference to a non-constant vector value.
Definition: DynamicVector.h:189
#define BLAZE_CONSTRAINT_MUST_BE_VECTORIZABLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a vectorizable data type...
Definition: Vectorizable.h:61
const Type & ConstReference
Reference to a constant vector value.
Definition: DynamicVector.h:190
Header file for the exception macros of the math module.
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:119
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:538
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:254
Headerfile for generic algorithms.
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:553
Header file for the IsPadded type trait.
Header file for the IsVectorizable type trait.
Header file for the IsNumeric type trait.
Header file for the HasConstDataAccess type trait.
size_t capacity_
The maximum capacity of the vector.
Definition: DynamicVector.h:457
size_t size() const noexcept
Returns the current size/dimension of the vector.
Definition: DynamicVector.h:1330
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > stream(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned, non-temporal store of a vector of 1-byte integral values.
Definition: Stream.h:75
Header file for the IsSparseVector type trait.
Header file for the HasSIMDMult type trait.
BLAZE_ALWAYS_INLINE SIMDType loada(size_t index) const noexcept
Aligned load of a SIMD element of the vector.
Definition: DynamicVector.h:1740
Header file for run time assertion macros.
ConstIterator cbegin() const noexcept
Returns an iterator to the first element of the dynamic vector.
Definition: DynamicVector.h:912
Header file for the addition trait.
Header file for the cross product trait.
const SIMDType load() const noexcept
Load of the SIMD element at the current iterator position.
Definition: DenseIterator.h:403
Header file for the division trait.
Constraint on the data type.
Pointer data() noexcept
Low-level data access to the vector elements.
Definition: DynamicVector.h:854
EnableIf_< IsDenseVector< VT1 > > smpDivAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP division assignment of a vector to a dense vector.
Definition: DenseVector.h:222
const DynamicVector & CompositeType
Data type for composite expression templates.
Definition: DynamicVector.h:187
void extend(size_t n, bool preserve=true)
Extending the size of the vector.
Definition: DynamicVector.h:1486
Header file for the cache size of the target architecture.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2646
Rebind mechanism to obtain a DynamicVector with different data/element type.
Definition: DynamicVector.h:202
Header file for the isDefault shim.
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:258
System settings for the restrict keyword.
Type ElementType
Type of the vector elements.
Definition: DynamicVector.h:184
Type * Pointer
Pointer to a non-constant vector value.
Definition: DynamicVector.h:191
Constraint on the data type.
Header file for the HasSIMDSub type trait.
Header file for the HasMutableDataAccess type trait.
void reserve(size_t n)
Setting the minimum capacity of the vector.
Definition: DynamicVector.h:1504
IntegralConstant< bool, B > BoolConstant
Generic wrapper for a compile time constant boolean value.The BoolConstant class template represents ...
Definition: IntegralConstant.h:100
void swap(DynamicVector &v) noexcept
Swapping the contents of two vectors.
Definition: DynamicVector.h:1555
EnableIf_< IsBuiltin< T > > deallocate(T *address) noexcept
Deallocation of memory for built-in data types.
Definition: Memory.h:225
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
BLAZE_ALWAYS_INLINE EnableIf_< And< IsIntegral< T1 >, HasSize< T1, 1UL > > > storeu(T1 *address, const SIMDi8< T2 > &value) noexcept
Unaligned store of a vector of 1-byte integral values.
Definition: Storeu.h:76
Header file for the mathematical trait.
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
typename T::ConstIterator ConstIterator_
Alias declaration for nested ConstIterator type definitions.The ConstIterator_ alias declaration prov...
Definition: Aliases.h:103
Header file for the AreSIMDCombinable type trait.
constexpr bool usePadding
Configuration of the padding of dense vectors and matrices.This configuration switch enables/disables...
Definition: Optimizations.h:52
Iterator end() noexcept
Returns an iterator just past the last element of the dynamic vector.
Definition: DynamicVector.h:926
Header file for the HasSIMDDiv type trait.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:154
Header file for the default transpose flag for all vectors of the Blaze library.
Initializer list type of the Blaze library.
Header file for the alignment check function.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:110
DynamicVector & operator=(const Type &rhs)
Homogenous assignment to all vector elements.
Definition: DynamicVector.h:977
Header file for the IntegralConstant class template.
bool isAliased(const Other *alias) const noexcept
Returns whether the vector is aliased with the given address alias.
Definition: DynamicVector.h:1658
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:240
Reference at(size_t index)
Checked access to the vector elements.
Definition: DynamicVector.h:812
void store(const SIMDType &value) const noexcept
Store of the SIMD element at the current iterator position.
Definition: DenseIterator.h:468
Header file for the IsResizable type trait.
System settings for the inline keywords.
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the TrueType type/value trait base class.
DynamicVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: DynamicVector.h:183
DynamicVector< Type, TF > This
Type of this DynamicVector instance.
Definition: DynamicVector.h:180