HybridVector.h
Go to the documentation of this file.
1 //=================================================================================================
24 //=================================================================================================
25 
26 #ifndef _BLAZE_MATH_DENSE_HYBRIDVECTOR_H_
27 #define _BLAZE_MATH_DENSE_HYBRIDVECTOR_H_
28 
29 
30 //*************************************************************************************************
31 // Includes
32 //*************************************************************************************************
33 
34 #include <algorithm>
35 #include <stdexcept>
39 #include <blaze/math/Forward.h>
40 #include <blaze/math/Functions.h>
41 #include <blaze/math/Intrinsics.h>
42 #include <blaze/math/shims/Clear.h>
56 #include <blaze/system/Inline.h>
59 #include <blaze/util/Assert.h>
66 #include <blaze/util/DisableIf.h>
67 #include <blaze/util/EnableIf.h>
68 #include <blaze/util/Memory.h>
70 #include <blaze/util/Template.h>
71 #include <blaze/util/Types.h>
75 #include <blaze/util/Unused.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS DEFINITION
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
156 template< typename Type // Data type of the vector
157  , size_t N // Number of elements
158  , bool TF = defaultTransposeFlag > // Transpose flag
159 class HybridVector : public DenseVector< HybridVector<Type,N,TF>, TF >
160 {
161  private:
162  //**Type definitions****************************************************************************
164  //**********************************************************************************************
165 
166  //**********************************************************************************************
168  enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
169  //**********************************************************************************************
170 
171  public:
172  //**Type definitions****************************************************************************
174  typedef This ResultType;
176  typedef Type ElementType;
177  typedef typename IT::Type IntrinsicType;
178  typedef const Type& ReturnType;
179  typedef const HybridVector& CompositeType;
180  typedef Type& Reference;
181  typedef const Type& ConstReference;
182  typedef Type* Pointer;
183  typedef const Type* ConstPointer;
186  //**********************************************************************************************
187 
188  //**Rebind struct definition********************************************************************
191  template< typename ET > // Data type of the other vector
192  struct Rebind {
194  };
195  //**********************************************************************************************
196 
197  //**Compilation flags***************************************************************************
199 
203  enum { vectorizable = IsVectorizable<Type>::value };
204 
206 
209  enum { smpAssignable = 0 };
210  //**********************************************************************************************
211 
212  //**Constructors********************************************************************************
215  explicit inline HybridVector();
216  explicit inline HybridVector( size_t n );
217  explicit inline HybridVector( size_t n, const Type& init );
218  template< typename Other > explicit inline HybridVector( size_t n, const Other* array );
219 
220  template< typename Other, size_t M >
221  explicit inline HybridVector( const Other (&array)[M] );
222 
223  inline HybridVector( const HybridVector& v );
224  template< typename VT > inline HybridVector( const Vector<VT,TF>& v );
226  //**********************************************************************************************
227 
228  //**Destructor**********************************************************************************
229  // No explicitly declared destructor.
230  //**********************************************************************************************
231 
232  //**Data access functions***********************************************************************
235  inline Reference operator[]( size_t index );
236  inline ConstReference operator[]( size_t index ) const;
237  inline Pointer data ();
238  inline ConstPointer data () const;
239  inline Iterator begin ();
240  inline ConstIterator begin () const;
241  inline ConstIterator cbegin() const;
242  inline Iterator end ();
243  inline ConstIterator end () const;
244  inline ConstIterator cend () const;
246  //**********************************************************************************************
247 
248  //**Assignment operators************************************************************************
251  template< typename Other, size_t M >
252  inline HybridVector& operator=( const Other (&array)[M] );
253 
254  inline HybridVector& operator= ( const Type& rhs );
255  inline HybridVector& operator= ( const HybridVector& rhs );
256  template< typename VT > inline HybridVector& operator= ( const Vector<VT,TF>& rhs );
257  template< typename VT > inline HybridVector& operator+=( const Vector<VT,TF>& rhs );
258  template< typename VT > inline HybridVector& operator-=( const Vector<VT,TF>& rhs );
259  template< typename VT > inline HybridVector& operator*=( const Vector<VT,TF>& rhs );
260 
261  template< typename Other >
262  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
263  operator*=( Other rhs );
264 
265  template< typename Other >
266  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
267  operator/=( Other rhs );
269  //**********************************************************************************************
270 
271  //**Utility functions***************************************************************************
274  inline size_t size() const;
275  inline size_t capacity() const;
276  inline size_t nonZeros() const;
277  inline void reset();
278  inline void clear();
279  inline void resize( size_t n, bool preserve=true );
280  inline void extend( size_t n, bool preserve=true );
281  template< typename Other > inline HybridVector& scale( const Other& scalar );
282  inline void swap( HybridVector& v ) /* throw() */;
284  //**********************************************************************************************
285 
286  //**Memory functions****************************************************************************
289  static inline void* operator new ( std::size_t size );
290  static inline void* operator new[]( std::size_t size );
291  static inline void* operator new ( std::size_t size, const std::nothrow_t& );
292  static inline void* operator new[]( std::size_t size, const std::nothrow_t& );
293 
294  static inline void operator delete ( void* ptr );
295  static inline void operator delete[]( void* ptr );
296  static inline void operator delete ( void* ptr, const std::nothrow_t& );
297  static inline void operator delete[]( void* ptr, const std::nothrow_t& );
299  //**********************************************************************************************
300 
301  private:
302  //**********************************************************************************************
304  template< typename VT >
306  struct VectorizedAssign {
307  enum { value = vectorizable && VT::vectorizable &&
308  IsSame<Type,typename VT::ElementType>::value };
309  };
311  //**********************************************************************************************
312 
313  //**********************************************************************************************
315  template< typename VT >
317  struct VectorizedAddAssign {
318  enum { value = vectorizable && VT::vectorizable &&
319  IsSame<Type,typename VT::ElementType>::value &&
320  IntrinsicTrait<Type>::addition };
321  };
323  //**********************************************************************************************
324 
325  //**********************************************************************************************
327  template< typename VT >
329  struct VectorizedSubAssign {
330  enum { value = vectorizable && VT::vectorizable &&
331  IsSame<Type,typename VT::ElementType>::value &&
332  IntrinsicTrait<Type>::subtraction };
333  };
335  //**********************************************************************************************
336 
337  //**********************************************************************************************
339  template< typename VT >
341  struct VectorizedMultAssign {
342  enum { value = vectorizable && VT::vectorizable &&
343  IsSame<Type,typename VT::ElementType>::value &&
344  IntrinsicTrait<Type>::multiplication };
345  };
347  //**********************************************************************************************
348 
349  public:
350  //**Expression template evaluation functions****************************************************
353  template< typename Other > inline bool canAlias ( const Other* alias ) const;
354  template< typename Other > inline bool isAliased( const Other* alias ) const;
355 
356  inline bool isAligned() const;
357 
358  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t index ) const;
359  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t index ) const;
360 
361  BLAZE_ALWAYS_INLINE void store ( size_t index, const IntrinsicType& value );
362  BLAZE_ALWAYS_INLINE void storeu( size_t index, const IntrinsicType& value );
363  BLAZE_ALWAYS_INLINE void stream( size_t index, const IntrinsicType& value );
364 
365  template< typename VT >
366  inline typename DisableIf< VectorizedAssign<VT> >::Type
367  assign( const DenseVector<VT,TF>& rhs );
368 
369  template< typename VT >
370  inline typename EnableIf< VectorizedAssign<VT> >::Type
371  assign( const DenseVector<VT,TF>& rhs );
372 
373  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
374 
375  template< typename VT >
376  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
377  addAssign( const DenseVector<VT,TF>& rhs );
378 
379  template< typename VT >
380  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
381  addAssign( const DenseVector<VT,TF>& rhs );
382 
383  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
384 
385  template< typename VT >
386  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
387  subAssign( const DenseVector<VT,TF>& rhs );
388 
389  template< typename VT >
390  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
391  subAssign( const DenseVector<VT,TF>& rhs );
392 
393  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
394 
395  template< typename VT >
396  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
397  multAssign( const DenseVector<VT,TF>& rhs );
398 
399  template< typename VT >
400  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
401  multAssign( const DenseVector<VT,TF>& rhs );
402 
403  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
405  //**********************************************************************************************
406 
407  private:
408  //**Member variables****************************************************************************
412 
417  size_t size_;
418 
419  //**********************************************************************************************
420 
421  //**Compile time checks*************************************************************************
427  BLAZE_STATIC_ASSERT( NN % IT::size == 0UL );
428  BLAZE_STATIC_ASSERT( NN >= N );
430  //**********************************************************************************************
431 };
432 //*************************************************************************************************
433 
434 
435 
436 
437 //=================================================================================================
438 //
439 // CONSTRUCTORS
440 //
441 //=================================================================================================
442 
443 //*************************************************************************************************
448 template< typename Type // Data type of the vector
449  , size_t N // Number of elements
450  , bool TF > // Transpose flag
452  : v_ () // The statically allocated vector elements
453  , size_( 0UL ) // The current size/dimension of the vector
454 {
456 
457  if( IsNumeric<Type>::value ) {
458  for( size_t i=0UL; i<NN; ++i )
459  v_[i] = Type();
460  }
461 }
462 //*************************************************************************************************
463 
464 
465 //*************************************************************************************************
475 template< typename Type // Data type of the vector
476  , size_t N // Number of elements
477  , bool TF > // Transpose flag
479  : v_ () // The statically allocated vector elements
480  , size_( n ) // The current size/dimension of the vector
481 {
483 
484  if( n > N )
485  throw std::invalid_argument( "Invalid size for hybrid vector" );
486 
487  if( IsNumeric<Type>::value ) {
488  for( size_t i=0UL; i<NN; ++i )
489  v_[i] = Type();
490  }
491 }
492 //*************************************************************************************************
493 
494 
495 //*************************************************************************************************
506 template< typename Type // Data type of the vector
507  , size_t N // Number of elements
508  , bool TF > // Transpose flag
509 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Type& init )
510  : v_ () // The statically allocated vector elements
511  , size_( n ) // The current size/dimension of the vector
512 {
514 
515  if( n > N )
516  throw std::invalid_argument( "Invalid size for hybrid vector" );
517 
518  for( size_t i=0UL; i<n; ++i )
519  v_[i] = init;
520 
521  if( IsNumeric<Type>::value ) {
522  for( size_t i=n; i<NN; ++i )
523  v_[i] = Type();
524  }
525 }
526 //*************************************************************************************************
527 
528 
529 //*************************************************************************************************
552 template< typename Type // Data type of the vector
553  , size_t N // Number of elements
554  , bool TF > // Transpose flag
555 template< typename Other > // Data type of the initialization array
556 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Other* array )
557  : v_ () // The statically allocated vector elements
558  , size_( n ) // The current size/dimension of the vector
559 {
561 
562  if( n > N )
563  throw std::invalid_argument( "Invalid setup of hybrid vector" );
564 
565  for( size_t i=0UL; i<n; ++i )
566  v_[i] = array[i];
567 
568  if( IsNumeric<Type>::value ) {
569  for( size_t i=n; i<NN; ++i )
570  v_[i] = Type();
571  }
572 }
573 //*************************************************************************************************
574 
575 
576 //*************************************************************************************************
594 template< typename Type // Data type of the vector
595  , size_t N // Number of elements
596  , bool TF > // Transpose flag
597 template< typename Other // Data type of the initialization array
598  , size_t M > // Number of elements of the initialization array
599 inline HybridVector<Type,N,TF>::HybridVector( const Other (&array)[M] )
600  : v_ () // The statically allocated vector elements
601  , size_( M ) // The current size/dimension of the vector
602 {
603  BLAZE_STATIC_ASSERT( M <= N );
605 
606  for( size_t i=0UL; i<M; ++i )
607  v_[i] = array[i];
608 
609  if( IsNumeric<Type>::value ) {
610  for( size_t i=M; i<NN; ++i )
611  v_[i] = Type();
612  }
613 }
614 //*************************************************************************************************
615 
616 
617 //*************************************************************************************************
624 template< typename Type // Data type of the vector
625  , size_t N // Number of elements
626  , bool TF > // Transpose flag
628  : v_ () // The statically allocated vector elements
629  , size_( v.size_ ) // The current size/dimension of the vector
630 {
632 
633  for( size_t i=0UL; i<size_; ++i )
634  v_[i] = v.v_[i];
635 
636  if( IsNumeric<Type>::value ) {
637  for( size_t i=size_; i<NN; ++i )
638  v_[i] = Type();
639  }
640 }
641 //*************************************************************************************************
642 
643 
644 //*************************************************************************************************
654 template< typename Type // Data type of the vector
655  , size_t N // Number of elements
656  , bool TF > // Transpose flag
657 template< typename VT > // Type of the foreign vector
659  : v_ () // The statically allocated vector elements
660  , size_( (~v).size() ) // The current size/dimension of the vector
661 {
662  using blaze::assign;
663 
665 
666  if( (~v).size() > N )
667  throw std::invalid_argument( "Invalid setup of hybrid vector" );
668 
669  for( size_t i=( IsSparseVector<VT>::value ? 0UL : size_ );
670  i<( IsNumeric<Type>::value ? NN : size_ ); ++i ) {
671  v_[i] = Type();
672  }
673 
674  assign( *this, ~v );
675 }
676 //*************************************************************************************************
677 
678 
679 
680 
681 //=================================================================================================
682 //
683 // DATA ACCESS FUNCTIONS
684 //
685 //=================================================================================================
686 
687 //*************************************************************************************************
695 template< typename Type // Data type of the vector
696  , size_t N // Number of elements
697  , bool TF > // Transpose flag
700 {
701  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
702  return v_[index];
703 }
704 //*************************************************************************************************
705 
706 
707 //*************************************************************************************************
715 template< typename Type // Data type of the vector
716  , size_t N // Number of elements
717  , bool TF > // Transpose flag
720 {
721  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
722  return v_[index];
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
734 template< typename Type // Data type of the vector
735  , size_t N // Number of elements
736  , bool TF > // Transpose flag
738 {
739  return v_;
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
751 template< typename Type // Data type of the vector
752  , size_t N // Number of elements
753  , bool TF > // Transpose flag
755 {
756  return v_;
757 }
758 //*************************************************************************************************
759 
760 
761 //*************************************************************************************************
766 template< typename Type // Data type of the vector
767  , size_t N // Number of elements
768  , bool TF > // Transpose flag
770 {
771  return Iterator( v_ );
772 }
773 //*************************************************************************************************
774 
775 
776 //*************************************************************************************************
781 template< typename Type // Data type of the vector
782  , size_t N // Number of elements
783  , bool TF > // Transpose flag
785 {
786  return ConstIterator( v_ );
787 }
788 //*************************************************************************************************
789 
790 
791 //*************************************************************************************************
796 template< typename Type // Data type of the vector
797  , size_t N // Number of elements
798  , bool TF > // Transpose flag
800 {
801  return ConstIterator( v_ );
802 }
803 //*************************************************************************************************
804 
805 
806 //*************************************************************************************************
811 template< typename Type // Data type of the vector
812  , size_t N // Number of elements
813  , bool TF > // Transpose flag
815 {
816  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
817  return Iterator( v_ + size_ );
818 }
819 //*************************************************************************************************
820 
821 
822 //*************************************************************************************************
827 template< typename Type // Data type of the vector
828  , size_t N // Number of elements
829  , bool TF > // Transpose flag
831 {
832  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
833  return ConstIterator( v_ + size_ );
834 }
835 //*************************************************************************************************
836 
837 
838 //*************************************************************************************************
843 template< typename Type // Data type of the vector
844  , size_t N // Number of elements
845  , bool TF > // Transpose flag
847 {
848  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
849  return ConstIterator( v_ + size_ );
850 }
851 //*************************************************************************************************
852 
853 
854 
855 
856 //=================================================================================================
857 //
858 // ASSIGNMENT OPERATORS
859 //
860 //=================================================================================================
861 
862 //*************************************************************************************************
881 template< typename Type // Data type of the vector
882  , size_t N // Number of elements
883  , bool TF > // Transpose flag
884 template< typename Other // Data type of the initialization array
885  , size_t M > // Number of elements of the initialization array
887 {
888  BLAZE_STATIC_ASSERT( M <= N );
889 
890  resize( M );
891 
892  for( size_t i=0UL; i<M; ++i )
893  v_[i] = array[i];
894 
895  return *this;
896 }
897 //*************************************************************************************************
898 
899 
900 //*************************************************************************************************
906 template< typename Type // Data type of the vector
907  , size_t N // Number of elements
908  , bool TF > // Transpose flag
910 {
911  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
912 
913  for( size_t i=0UL; i<size_; ++i )
914  v_[i] = rhs;
915  return *this;
916 }
917 //*************************************************************************************************
918 
919 
920 //*************************************************************************************************
928 template< typename Type // Data type of the vector
929  , size_t N // Number of elements
930  , bool TF > // Transpose flag
932 {
933  using blaze::assign;
934 
935  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
936 
937  resize( rhs.size() );
938  assign( *this, ~rhs );
939 
940  return *this;
941 }
942 //*************************************************************************************************
943 
944 
945 //*************************************************************************************************
955 template< typename Type // Data type of the vector
956  , size_t N // Number of elements
957  , bool TF > // Transpose flag
958 template< typename VT > // Type of the right-hand side vector
960 {
961  using blaze::assign;
962 
963  if( (~rhs).size() > N )
964  throw std::invalid_argument( "Invalid assignment to hybrid vector" );
965 
966  if( (~rhs).canAlias( this ) ) {
967  HybridVector tmp( ~rhs );
968  swap( tmp );
969  }
970  else {
971  resize( (~rhs).size() );
973  reset();
974  assign( *this, ~rhs );
975  }
976 
977  return *this;
978 }
979 //*************************************************************************************************
980 
981 
982 //*************************************************************************************************
992 template< typename Type // Data type of the vector
993  , size_t N // Number of elements
994  , bool TF > // Transpose flag
995 template< typename VT > // Type of the right-hand side vector
997 {
998  using blaze::addAssign;
999 
1000  if( (~rhs).size() != size_ )
1001  throw std::invalid_argument( "Vector sizes do not match" );
1002 
1003  if( (~rhs).canAlias( this ) ) {
1004  typename VT::ResultType tmp( ~rhs );
1005  addAssign( *this, tmp );
1006  }
1007  else {
1008  addAssign( *this, ~rhs );
1009  }
1010 
1011  return *this;
1012 }
1013 //*************************************************************************************************
1014 
1015 
1016 //*************************************************************************************************
1026 template< typename Type // Data type of the vector
1027  , size_t N // Number of elements
1028  , bool TF > // Transpose flag
1029 template< typename VT > // Type of the right-hand side vector
1031 {
1032  using blaze::subAssign;
1033 
1034  if( (~rhs).size() != size_ )
1035  throw std::invalid_argument( "Vector sizes do not match" );
1036 
1037  if( (~rhs).canAlias( this ) ) {
1038  typename VT::ResultType tmp( ~rhs );
1039  subAssign( *this, tmp );
1040  }
1041  else {
1042  subAssign( *this, ~rhs );
1043  }
1044 
1045  return *this;
1046 }
1047 //*************************************************************************************************
1048 
1049 
1050 //*************************************************************************************************
1061 template< typename Type // Data type of the vector
1062  , size_t N // Number of elements
1063  , bool TF > // Transpose flag
1064 template< typename VT > // Type of the right-hand side vector
1066 {
1067  using blaze::multAssign;
1068 
1069  if( (~rhs).size() != size_ )
1070  throw std::invalid_argument( "Vector sizes do not match" );
1071 
1072  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
1073  HybridVector tmp( *this * (~rhs) );
1074  this->operator=( tmp );
1075  }
1076  else {
1077  multAssign( *this, ~rhs );
1078  }
1079 
1080  return *this;
1081 }
1082 //*************************************************************************************************
1083 
1084 
1085 //*************************************************************************************************
1092 template< typename Type // Data type of the vector
1093  , size_t N // Number of elements
1094  , bool TF > // Transpose flag
1095 template< typename Other > // Data type of the right-hand side scalar
1096 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1098 {
1099  using blaze::assign;
1100 
1101  assign( *this, (*this) * rhs );
1102  return *this;
1103 }
1104 //*************************************************************************************************
1105 
1106 
1107 //*************************************************************************************************
1116 template< typename Type // Data type of the vector
1117  , size_t N // Number of elements
1118  , bool TF > // Transpose flag
1119 template< typename Other > // Data type of the right-hand side scalar
1120 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1122 {
1123  using blaze::assign;
1124 
1125  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1126 
1127  assign( *this, (*this) / rhs );
1128  return *this;
1129 }
1130 //*************************************************************************************************
1131 
1132 
1133 
1134 
1135 //=================================================================================================
1136 //
1137 // UTILITY FUNCTIONS
1138 //
1139 //=================================================================================================
1140 
1141 //*************************************************************************************************
1146 template< typename Type // Data type of the vector
1147  , size_t N // Number of elements
1148  , bool TF > // Transpose flag
1149 inline size_t HybridVector<Type,N,TF>::size() const
1150 {
1151  return size_;
1152 }
1153 //*************************************************************************************************
1154 
1155 
1156 //*************************************************************************************************
1161 template< typename Type // Data type of the vector
1162  , size_t N // Number of elements
1163  , bool TF > // Transpose flag
1165 {
1166  return NN;
1167 }
1168 //*************************************************************************************************
1169 
1170 
1171 //*************************************************************************************************
1179 template< typename Type // Data type of the vector
1180  , size_t N // Number of elements
1181  , bool TF > // Transpose flag
1183 {
1184  size_t nonzeros( 0 );
1185 
1186  for( size_t i=0UL; i<size_; ++i ) {
1187  if( !isDefault( v_[i] ) )
1188  ++nonzeros;
1189  }
1190 
1191  return nonzeros;
1192 }
1193 //*************************************************************************************************
1194 
1195 
1196 //*************************************************************************************************
1201 template< typename Type // Data type of the vector
1202  , size_t N // Number of elements
1203  , bool TF > // Transpose flag
1205 {
1206  using blaze::clear;
1207  for( size_t i=0UL; i<size_; ++i )
1208  clear( v_[i] );
1209 }
1210 //*************************************************************************************************
1211 
1212 
1213 //*************************************************************************************************
1220 template< typename Type // Data type of the vector
1221  , size_t N // Number of elements
1222  , bool TF > // Transpose flag
1224 {
1225  resize( 0UL );
1226 }
1227 //*************************************************************************************************
1228 
1229 
1230 //*************************************************************************************************
1261 template< typename Type // Data type of the vector
1262  , size_t N // Number of elements
1263  , bool TF > // Transpose flag
1264 inline void HybridVector<Type,N,TF>::resize( size_t n, bool preserve )
1265 {
1266  UNUSED_PARAMETER( preserve );
1267 
1268  if( n > N )
1269  throw std::invalid_argument( "Invalid size for hybrid vector" );
1270 
1271  if( IsVectorizable<Type>::value && n < size_ ) {
1272  for( size_t i=n; i<size_; ++i )
1273  v_[i] = Type();
1274  }
1275 
1276  size_ = n;
1277 }
1278 //*************************************************************************************************
1279 
1280 
1281 //*************************************************************************************************
1295 template< typename Type // Data type of the vector
1296  , size_t N // Number of elements
1297  , bool TF > // Transpose flag
1298 inline void HybridVector<Type,N,TF>::extend( size_t n, bool preserve )
1299 {
1300  UNUSED_PARAMETER( preserve );
1301  resize( size_+n );
1302 }
1303 //*************************************************************************************************
1304 
1305 
1306 //*************************************************************************************************
1312 template< typename Type // Data type of the vector
1313  , size_t N // Number of elements
1314  , bool TF > // Transpose flag
1315 template< typename Other > // Data type of the scalar value
1317 {
1318  for( size_t i=0; i<size_; ++i )
1319  v_[i] *= scalar;
1320  return *this;
1321 }
1322 //*************************************************************************************************
1323 
1324 
1325 //*************************************************************************************************
1332 template< typename Type // Data type of the vector
1333  , size_t N // Number of elements
1334  , bool TF > // Transpose flag
1335 inline void HybridVector<Type,N,TF>::swap( HybridVector& v ) /* throw() */
1336 {
1337  using std::swap;
1338 
1339  const size_t maxsize( max( size_, v.size_ ) );
1340  for( size_t i=0UL; i<maxsize; ++i )
1341  swap( v_[i], v.v_[i] );
1342  swap( size_, v.size_ );
1343 }
1344 //*************************************************************************************************
1345 
1346 
1347 
1348 
1349 //=================================================================================================
1350 //
1351 // MEMORY FUNCTIONS
1352 //
1353 //=================================================================================================
1354 
1355 //*************************************************************************************************
1365 template< typename Type // Data type of the vector
1366  , size_t N // Number of elements
1367  , bool TF > // Transpose flag
1368 inline void* HybridVector<Type,N,TF>::operator new( std::size_t size )
1369 {
1371 
1372  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1373 
1374  return allocate<HybridVector>( 1UL );
1375 }
1376 //*************************************************************************************************
1377 
1378 
1379 //*************************************************************************************************
1389 template< typename Type // Data type of the vector
1390  , size_t N // Number of elements
1391  , bool TF > // Transpose flag
1392 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size )
1393 {
1394  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1395  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1396 
1397  return allocate<HybridVector>( size/sizeof(HybridVector) );
1398 }
1399 //*************************************************************************************************
1400 
1401 
1402 //*************************************************************************************************
1412 template< typename Type // Data type of the vector
1413  , size_t N // Number of elements
1414  , bool TF > // Transpose flag
1415 inline void* HybridVector<Type,N,TF>::operator new( std::size_t size, const std::nothrow_t& )
1416 {
1417  UNUSED_PARAMETER( size );
1418 
1419  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1420 
1421  return allocate<HybridVector>( 1UL );
1422 }
1423 //*************************************************************************************************
1424 
1425 
1426 //*************************************************************************************************
1436 template< typename Type // Data type of the vector
1437  , size_t N // Number of elements
1438  , bool TF > // Transpose flag
1439 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size, const std::nothrow_t& )
1440 {
1441  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1442  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1443 
1444  return allocate<HybridVector>( size/sizeof(HybridVector) );
1445 }
1446 //*************************************************************************************************
1447 
1448 
1449 //*************************************************************************************************
1455 template< typename Type // Data type of the vector
1456  , size_t N // Number of elements
1457  , bool TF > // Transpose flag
1458 inline void HybridVector<Type,N,TF>::operator delete( void* ptr )
1459 {
1460  deallocate( static_cast<HybridVector*>( ptr ) );
1461 }
1462 //*************************************************************************************************
1463 
1464 
1465 //*************************************************************************************************
1471 template< typename Type // Data type of the vector
1472  , size_t N // Number of elements
1473  , bool TF > // Transpose flag
1474 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr )
1475 {
1476  deallocate( static_cast<HybridVector*>( ptr ) );
1477 }
1478 //*************************************************************************************************
1479 
1480 
1481 //*************************************************************************************************
1487 template< typename Type // Data type of the vector
1488  , size_t N // Number of elements
1489  , bool TF > // Transpose flag
1490 inline void HybridVector<Type,N,TF>::operator delete( void* ptr, const std::nothrow_t& )
1491 {
1492  deallocate( static_cast<HybridVector*>( ptr ) );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1503 template< typename Type // Data type of the vector
1504  , size_t N // Number of elements
1505  , bool TF > // Transpose flag
1506 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr, const std::nothrow_t& )
1507 {
1508  deallocate( static_cast<HybridVector*>( ptr ) );
1509 }
1510 //*************************************************************************************************
1511 
1512 
1513 
1514 
1515 //=================================================================================================
1516 //
1517 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1518 //
1519 //=================================================================================================
1520 
1521 //*************************************************************************************************
1531 template< typename Type // Data type of the vector
1532  , size_t N // Number of elements
1533  , bool TF > // Transpose flag
1534 template< typename Other > // Data type of the foreign expression
1535 inline bool HybridVector<Type,N,TF>::canAlias( const Other* alias ) const
1536 {
1537  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1538 }
1539 //*************************************************************************************************
1540 
1541 
1542 //*************************************************************************************************
1552 template< typename Type // Data type of the vector
1553  , size_t N // Number of elements
1554  , bool TF > // Transpose flag
1555 template< typename Other > // Data type of the foreign expression
1556 inline bool HybridVector<Type,N,TF>::isAliased( const Other* alias ) const
1557 {
1558  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1559 }
1560 //*************************************************************************************************
1561 
1562 
1563 //*************************************************************************************************
1572 template< typename Type // Data type of the vector
1573  , size_t N // Number of elements
1574  , bool TF > // Transpose flag
1576 {
1577  return true;
1578 }
1579 //*************************************************************************************************
1580 
1581 
1582 //*************************************************************************************************
1595 template< typename Type // Data type of the vector
1596  , size_t N // Number of elements
1597  , bool TF > // Transpose flag
1599  HybridVector<Type,N,TF>::load( size_t index ) const
1600 {
1601  using blaze::load;
1602 
1604 
1605  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1606  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1607  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1608 
1609  return load( &v_[index] );
1610 }
1611 //*************************************************************************************************
1612 
1613 
1614 //*************************************************************************************************
1627 template< typename Type // Data type of the vector
1628  , size_t N // Number of elements
1629  , bool TF > // Transpose flag
1631  HybridVector<Type,N,TF>::loadu( size_t index ) const
1632 {
1633  using blaze::loadu;
1634 
1636 
1637  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1638  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1639 
1640  return loadu( &v_[index] );
1641 }
1642 //*************************************************************************************************
1643 
1644 
1645 //*************************************************************************************************
1659 template< typename Type // Data type of the vector
1660  , size_t N // Number of elements
1661  , bool TF > // Transpose flag
1662 BLAZE_ALWAYS_INLINE void HybridVector<Type,N,TF>::store( size_t index, const IntrinsicType& value )
1663 {
1664  using blaze::store;
1665 
1667 
1668  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1669  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1670  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1671 
1672  store( &v_[index], value );
1673 }
1674 //*************************************************************************************************
1675 
1676 
1677 //*************************************************************************************************
1691 template< typename Type // Data type of the vector
1692  , size_t N // Number of elements
1693  , bool TF > // Transpose flag
1694 BLAZE_ALWAYS_INLINE void HybridVector<Type,N,TF>::storeu( size_t index, const IntrinsicType& value )
1695 {
1696  using blaze::storeu;
1697 
1699 
1700  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1701  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1702 
1703  storeu( &v_[index], value );
1704 }
1705 //*************************************************************************************************
1706 
1707 
1708 //*************************************************************************************************
1722 template< typename Type // Data type of the vector
1723  , size_t N // Number of elements
1724  , bool TF > // Transpose flag
1725 BLAZE_ALWAYS_INLINE void HybridVector<Type,N,TF>::stream( size_t index, const IntrinsicType& value )
1726 {
1727  using blaze::stream;
1728 
1730 
1731  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1732  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1733  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1734 
1735  stream( &v_[index], value );
1736 }
1737 //*************************************************************************************************
1738 
1739 
1740 //*************************************************************************************************
1751 template< typename Type // Data type of the vector
1752  , size_t N // Number of elements
1753  , bool TF > // Transpose flag
1754 template< typename VT > // Type of the right-hand side dense vector
1755 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1757 {
1758  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1759 
1760  for( size_t i=0UL; i<size_; ++i )
1761  v_[i] = (~rhs)[i];
1762 }
1763 //*************************************************************************************************
1764 
1765 
1766 //*************************************************************************************************
1777 template< typename Type // Data type of the vector
1778  , size_t N // Number of elements
1779  , bool TF > // Transpose flag
1780 template< typename VT > // Type of the right-hand side dense vector
1781 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1783 {
1784  using blaze::store;
1785 
1786  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1787 
1789 
1790  for( size_t i=0UL; i<size_; i+=IT::size ) {
1791  store( v_+i, (~rhs).load(i) );
1792  }
1793 }
1794 //*************************************************************************************************
1795 
1796 
1797 //*************************************************************************************************
1808 template< typename Type // Data type of the vector
1809  , size_t N // Number of elements
1810  , bool TF > // Transpose flag
1811 template< typename VT > // Type of the right-hand side sparse vector
1813 {
1814  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1815 
1816  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1817  v_[element->index()] = element->value();
1818 }
1819 //*************************************************************************************************
1820 
1821 
1822 //*************************************************************************************************
1833 template< typename Type // Data type of the vector
1834  , size_t N // Number of elements
1835  , bool TF > // Transpose flag
1836 template< typename VT > // Type of the right-hand side dense vector
1837 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1839 {
1840  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1841 
1842  for( size_t i=0UL; i<size_; ++i )
1843  v_[i] += (~rhs)[i];
1844 }
1845 //*************************************************************************************************
1846 
1847 
1848 //*************************************************************************************************
1859 template< typename Type // Data type of the vector
1860  , size_t N // Number of elements
1861  , bool TF > // Transpose flag
1862 template< typename VT > // Type of the right-hand side dense vector
1863 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1865 {
1866  using blaze::load;
1867  using blaze::store;
1868 
1869  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1870 
1872 
1873  for( size_t i=0UL; i<size_; i+=IT::size ) {
1874  store( v_+i, load( v_+i ) + (~rhs).load(i) );
1875  }
1876 }
1877 //*************************************************************************************************
1878 
1879 
1880 //*************************************************************************************************
1891 template< typename Type // Data type of the vector
1892  , size_t N // Number of elements
1893  , bool TF > // Transpose flag
1894 template< typename VT > // Type of the right-hand side sparse vector
1896 {
1897  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1898 
1899  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1900  v_[element->index()] += element->value();
1901 }
1902 //*************************************************************************************************
1903 
1904 
1905 //*************************************************************************************************
1916 template< typename Type // Data type of the vector
1917  , size_t N // Number of elements
1918  , bool TF > // Transpose flag
1919 template< typename VT > // Type of the right-hand side dense vector
1920 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1922 {
1923  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1924 
1925  for( size_t i=0UL; i<size_; ++i )
1926  v_[i] -= (~rhs)[i];
1927 }
1928 //*************************************************************************************************
1929 
1930 
1931 //*************************************************************************************************
1942 template< typename Type // Data type of the vector
1943  , size_t N // Number of elements
1944  , bool TF > // Transpose flag
1945 template< typename VT > // Type of the right-hand side dense vector
1946 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1948 {
1949  using blaze::load;
1950  using blaze::store;
1951 
1952  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1953 
1955 
1956  for( size_t i=0UL; i<size_; i+=IT::size ) {
1957  store( v_+i, load( v_+i ) - (~rhs).load(i) );
1958  }
1959 }
1960 //*************************************************************************************************
1961 
1962 
1963 //*************************************************************************************************
1974 template< typename Type // Data type of the vector
1975  , size_t N // Number of elements
1976  , bool TF > // Transpose flag
1977 template< typename VT > // Type of the right-hand side sparse vector
1979 {
1980  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1981 
1982  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1983  v_[element->index()] -= element->value();
1984 }
1985 //*************************************************************************************************
1986 
1987 
1988 //*************************************************************************************************
1999 template< typename Type // Data type of the vector
2000  , size_t N // Number of elements
2001  , bool TF > // Transpose flag
2002 template< typename VT > // Type of the right-hand side dense vector
2003 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2005 {
2006  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2007 
2008  for( size_t i=0UL; i<size_; ++i )
2009  v_[i] *= (~rhs)[i];
2010 }
2011 //*************************************************************************************************
2012 
2013 
2014 //*************************************************************************************************
2025 template< typename Type // Data type of the vector
2026  , size_t N // Number of elements
2027  , bool TF > // Transpose flag
2028 template< typename VT > // Type of the right-hand side dense vector
2029 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2031 {
2032  using blaze::load;
2033  using blaze::store;
2034 
2035  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2036 
2038 
2039  for( size_t i=0UL; i<size_; i+=IT::size ) {
2040  store( v_+i, load( v_+i ) * (~rhs).load(i) );
2041  }
2042 }
2043 //*************************************************************************************************
2044 
2045 
2046 //*************************************************************************************************
2057 template< typename Type // Data type of the vector
2058  , size_t N // Number of elements
2059  , bool TF > // Transpose flag
2060 template< typename VT > // Type of the right-hand side sparse vector
2062 {
2063  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2064 
2065  const HybridVector tmp( serial( *this ) );
2066 
2067  reset();
2068 
2069  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2070  v_[element->index()] = tmp[element->index()] * element->value();
2071 }
2072 //*************************************************************************************************
2073 
2074 
2075 
2076 
2077 
2078 
2079 
2080 
2081 //=================================================================================================
2082 //
2083 // UNDEFINED CLASS TEMPLATE SPECIALIZATION
2084 //
2085 //=================================================================================================
2086 
2087 //*************************************************************************************************
2095 template< typename Type // Data type of the vector
2096  , bool TF > // Transpose flag
2097 class HybridVector<Type,0UL,TF>;
2099 //*************************************************************************************************
2100 
2101 
2102 
2103 
2104 
2105 
2106 
2107 
2108 //=================================================================================================
2109 //
2110 // HYBRIDVECTOR OPERATORS
2111 //
2112 //=================================================================================================
2113 
2114 //*************************************************************************************************
2117 template< typename Type, size_t N, bool TF >
2118 inline void reset( HybridVector<Type,N,TF>& v );
2119 
2120 template< typename Type, size_t N, bool TF >
2121 inline void clear( HybridVector<Type,N,TF>& v );
2122 
2123 template< typename Type, size_t N, bool TF >
2124 inline bool isDefault( const HybridVector<Type,N,TF>& v );
2125 
2126 template< typename Type, size_t N, bool TF >
2127 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */;
2128 
2129 template< typename Type, size_t N, bool TF >
2130 inline void move( HybridVector<Type,N,TF>& dst, HybridVector<Type,N,TF>& src ) /* throw() */;
2132 //*************************************************************************************************
2133 
2134 
2135 //*************************************************************************************************
2142 template< typename Type // Data type of the vector
2143  , size_t N // Number of elements
2144  , bool TF > // Transpose flag
2146 {
2147  v.reset();
2148 }
2149 //*************************************************************************************************
2150 
2151 
2152 //*************************************************************************************************
2159 template< typename Type // Data type of the vector
2160  , size_t N // Number of elements
2161  , bool TF > // Transpose flag
2163 {
2164  v.clear();
2165 }
2166 //*************************************************************************************************
2167 
2168 
2169 //*************************************************************************************************
2186 template< typename Type // Data type of the vector
2187  , size_t N // Number of elements
2188  , bool TF > // Transpose flag
2189 inline bool isDefault( const HybridVector<Type,N,TF>& v )
2190 {
2191  return ( v.size() == 0UL );
2192 }
2193 //*************************************************************************************************
2194 
2195 
2196 //*************************************************************************************************
2205 template< typename Type // Data type of the vector
2206  , size_t N // Number of elements
2207  , bool TF > // Transpose flag
2208 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */
2209 {
2210  a.swap( b );
2211 }
2212 //*************************************************************************************************
2213 
2214 
2215 //*************************************************************************************************
2224 template< typename Type // Data type of the vector
2225  , size_t N // Number of elements
2226  , bool TF > // Transpose flag
2227 inline void move( HybridVector<Type,N,TF>& dst, HybridVector<Type,N,TF>& src ) /* throw() */
2228 {
2229  dst = src;
2230 }
2231 //*************************************************************************************************
2232 
2233 
2234 
2235 
2236 //=================================================================================================
2237 //
2238 // HASCONSTDATAACCESS SPECIALIZATIONS
2239 //
2240 //=================================================================================================
2241 
2242 //*************************************************************************************************
2244 template< typename T, size_t N, bool TF >
2245 struct HasConstDataAccess< HybridVector<T,N,TF> > : public TrueType
2246 {
2247  enum { value = 1 };
2248  typedef TrueType Type;
2249 };
2251 //*************************************************************************************************
2252 
2253 
2254 
2255 
2256 //=================================================================================================
2257 //
2258 // HASMUTABLEDATAACCESS SPECIALIZATIONS
2259 //
2260 //=================================================================================================
2261 
2262 //*************************************************************************************************
2264 template< typename T, size_t N, bool TF >
2265 struct HasMutableDataAccess< HybridVector<T,N,TF> > : public TrueType
2266 {
2267  enum { value = 1 };
2268  typedef TrueType Type;
2269 };
2271 //*************************************************************************************************
2272 
2273 
2274 
2275 
2276 //=================================================================================================
2277 //
2278 // ISRESIZABLE SPECIALIZATIONS
2279 //
2280 //=================================================================================================
2281 
2282 //*************************************************************************************************
2284 template< typename T, size_t N, bool TF >
2285 struct IsResizable< HybridVector<T,N,TF> > : public TrueType
2286 {
2287  enum { value = 1 };
2288  typedef TrueType Type;
2289 };
2291 //*************************************************************************************************
2292 
2293 
2294 
2295 
2296 //=================================================================================================
2297 //
2298 // ADDTRAIT SPECIALIZATIONS
2299 //
2300 //=================================================================================================
2301 
2302 //*************************************************************************************************
2304 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2305 struct AddTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2306 {
2307  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2308 };
2309 
2310 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2311 struct AddTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2312 {
2313  typedef StaticVector< typename AddTrait<T1,T2>::Type, M, TF > Type;
2314 };
2315 
2316 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2317 struct AddTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2318 {
2319  typedef HybridVector< typename AddTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2320 };
2322 //*************************************************************************************************
2323 
2324 
2325 
2326 
2327 //=================================================================================================
2328 //
2329 // SUBTRAIT SPECIALIZATIONS
2330 //
2331 //=================================================================================================
2332 
2333 //*************************************************************************************************
2335 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2336 struct SubTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2337 {
2338  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2339 };
2340 
2341 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2342 struct SubTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2343 {
2344  typedef StaticVector< typename SubTrait<T1,T2>::Type, M, TF > Type;
2345 };
2346 
2347 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2348 struct SubTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2349 {
2350  typedef HybridVector< typename SubTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2351 };
2353 //*************************************************************************************************
2354 
2355 
2356 
2357 
2358 //=================================================================================================
2359 //
2360 // MULTTRAIT SPECIALIZATIONS
2361 //
2362 //=================================================================================================
2363 
2364 //*************************************************************************************************
2366 template< typename T1, size_t N, bool TF, typename T2 >
2367 struct MultTrait< HybridVector<T1,N,TF>, T2 >
2368 {
2369  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2371 };
2372 
2373 template< typename T1, typename T2, size_t N, bool TF >
2374 struct MultTrait< T1, HybridVector<T2,N,TF> >
2375 {
2376  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2378 };
2379 
2380 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2381 struct MultTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2382 {
2383  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2384 };
2385 
2386 template< typename T1, size_t M, typename T2, size_t N >
2387 struct MultTrait< HybridVector<T1,M,false>, StaticVector<T2,N,true> >
2388 {
2389  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2390 };
2391 
2392 template< typename T1, size_t M, typename T2, size_t N >
2393 struct MultTrait< HybridVector<T1,M,true>, StaticVector<T2,N,false> >
2394 {
2395  typedef typename MultTrait<T1,T2>::Type Type;
2396 };
2397 
2398 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2399 struct MultTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2400 {
2401  typedef StaticVector< typename MultTrait<T1,T2>::Type, M, TF > Type;
2402 };
2403 
2404 template< typename T1, size_t M, typename T2, size_t N >
2405 struct MultTrait< StaticVector<T1,M,false>, HybridVector<T2,N,true> >
2406 {
2407  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2408 };
2409 
2410 template< typename T1, size_t M, typename T2, size_t N >
2411 struct MultTrait< StaticVector<T1,M,true>, HybridVector<T2,N,false> >
2412 {
2413  typedef typename MultTrait<T1,T2>::Type Type;
2414 };
2415 
2416 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2417 struct MultTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2418 {
2419  typedef HybridVector< typename MultTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2420 };
2421 
2422 template< typename T1, size_t M, typename T2, size_t N >
2423 struct MultTrait< HybridVector<T1,M,false>, HybridVector<T2,N,true> >
2424 {
2425  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2426 };
2427 
2428 template< typename T1, size_t M, typename T2, size_t N >
2429 struct MultTrait< HybridVector<T1,M,true>, HybridVector<T2,N,false> >
2430 {
2431  typedef typename MultTrait<T1,T2>::Type Type;
2432 };
2434 //*************************************************************************************************
2435 
2436 
2437 
2438 
2439 //=================================================================================================
2440 //
2441 // CROSSTRAIT SPECIALIZATIONS
2442 //
2443 //=================================================================================================
2444 
2445 //*************************************************************************************************
2447 template< typename T1, size_t N, typename T2 >
2448 struct CrossTrait< HybridVector<T1,N,false>, StaticVector<T2,3UL,false> >
2449 {
2450  private:
2451  typedef typename MultTrait<T1,T2>::Type T;
2452 
2453  public:
2454  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2455 };
2456 
2457 template< typename T1, typename T2, size_t N >
2458 struct CrossTrait< StaticVector<T1,3UL,false>, HybridVector<T2,N,false> >
2459 {
2460  private:
2461  typedef typename MultTrait<T1,T2>::Type T;
2462 
2463  public:
2464  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2465 };
2466 
2467 template< typename T1, size_t M, typename T2, size_t N >
2468 struct CrossTrait< HybridVector<T1,M,false>, HybridVector<T2,N,false> >
2469 {
2470  private:
2471  typedef typename MultTrait<T1,T2>::Type T;
2472 
2473  public:
2474  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2475 };
2477 //*************************************************************************************************
2478 
2479 
2480 
2481 
2482 //=================================================================================================
2483 //
2484 // DIVTRAIT SPECIALIZATIONS
2485 //
2486 //=================================================================================================
2487 
2488 //*************************************************************************************************
2490 template< typename T1, size_t N, bool TF, typename T2 >
2491 struct DivTrait< HybridVector<T1,N,TF>, T2 >
2492 {
2493  typedef HybridVector< typename DivTrait<T1,T2>::Type, N, TF > Type;
2495 };
2497 //*************************************************************************************************
2498 
2499 
2500 
2501 
2502 //=================================================================================================
2503 //
2504 // MATHTRAIT SPECIALIZATIONS
2505 //
2506 //=================================================================================================
2507 
2508 //*************************************************************************************************
2510 template< typename T1, size_t N, bool TF, typename T2 >
2511 struct MathTrait< HybridVector<T1,N,TF>, HybridVector<T2,N,TF> >
2512 {
2513  typedef StaticVector< typename MathTrait<T1,T2>::HighType, N, TF > HighType;
2514  typedef StaticVector< typename MathTrait<T1,T2>::LowType , N, TF > LowType;
2515 };
2517 //*************************************************************************************************
2518 
2519 
2520 
2521 
2522 //=================================================================================================
2523 //
2524 // SUBVECTORTRAIT SPECIALIZATIONS
2525 //
2526 //=================================================================================================
2527 
2528 //*************************************************************************************************
2530 template< typename T1, size_t N, bool TF >
2531 struct SubvectorTrait< HybridVector<T1,N,TF> >
2532 {
2533  typedef HybridVector<T1,N,TF> Type;
2534 };
2536 //*************************************************************************************************
2537 
2538 } // namespace blaze
2539 
2540 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:108
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: HybridVector.h:163
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1649
const bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Constraint on the data type.
Header file for mathematical functions.
BLAZE_ALWAYS_INLINE void multAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the multiplication assignment of a matrix to a matrix.
Definition: Matrix.h:879
#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
void extend(size_t n, bool preserve=true)
Extending the size of the vector.
Definition: HybridVector.h:1298
Header file for the UNUSED_PARAMETER function template.
HybridVector()
The default constructor for HybridVector.
Definition: HybridVector.h:451
Header file for the subtraction trait.
Header file for basic type definitions.
Header file for the SparseVector base class.
BLAZE_ALWAYS_INLINE void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: HybridVector.h:1725
AlignedArray< Type, NN > v_
The statically allocated vector elements.
Definition: HybridVector.h:411
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type stream(T *address, const sse_int16_t &value)
Aligned, non-temporal store of a vector of 2-byte integral values.
Definition: Stream.h:76
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: HybridVector.h:1164
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:258
BLAZE_ALWAYS_INLINE IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1631
Header file for the IsSame and IsStrictlySame type traits.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: HybridVector.h:1575
Type ElementType
Type of the vector elements.
Definition: HybridVector.h:176
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the DenseVector base class.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: HybridVector.h:1182
Header file for memory allocation and deallocation functionality.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
Iterator begin()
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:769
Efficient implementation of a dynamically sized vector with static memory.The HybridVector class temp...
Definition: Forward.h:57
HybridVector< Type, N,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: HybridVector.h:175
Rebind mechanism to obtain a HybridVector with different data/element type.
Definition: HybridVector.h:192
ConstIterator cbegin() const
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:799
Header file for the DisableIf class template.
HybridVector< ET, N, TF > Other
The type of the other HybridVector.
Definition: HybridVector.h:193
Header file for the multiplication trait.
ConstIterator cend() const
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:846
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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type loadu(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loadu.h:76
Header file for nested template disabiguation.
Compile time assertion.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4807
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type store(T *address, const sse_int16_t &value)
Aligned store of a vector of 2-byte integral values.
Definition: Store.h:80
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: HybridVector.h:185
size_t size() const
Returns the current size/dimension of the vector.
Definition: HybridVector.h:1149
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
EnableIf< IsBuiltin< T > >::Type deallocate(T *address)
Deallocation of memory for built-in data types.
Definition: Memory.h:226
Header file for the DenseIterator class template.
BLAZE_ALWAYS_INLINE void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: HybridVector.h:1662
Header file for the subvector trait.
Constraint on the data type.
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: HybridVector.h:184
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Compile time check for sparse vector types.This type trait tests whether or not the given template pa...
Definition: IsSparseVector.h:103
#define BLAZE_CONSTRAINT_MUST_BE_VECTORIZABLE_TYPE(T)
Constraint on the data type.In case the given data type T is not a vectorizable data type...
Definition: Vectorizable.h:79
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: HybridVector.h:699
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:195
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:535
const Type * ConstPointer
Pointer to a constant vector value.
Definition: HybridVector.h:183
void clear()
Clearing the vector.
Definition: HybridVector.h:1223
const Type & ReturnType
Return type for expression template evaluations.
Definition: HybridVector.h:178
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
Header file for the serial shim.
Header file for the IsVectorizable type trait.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, sse_int16_t >::Type load(const T *address)
Loads a vector of 2-byte integral values.
Definition: Load.h:79
Header file for the IsNumeric type trait.
Header file for the HasConstDataAccess type trait.
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: HybridVector.h:1264
size_t size_
The current size/dimension of the vector.
Definition: HybridVector.h:417
BLAZE_ALWAYS_INLINE void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: HybridVector.h:1694
Header file for the IsSparseVector type trait.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
const HybridVector & CompositeType
Data type for composite expression templates.
Definition: HybridVector.h:179
Header file for run time assertion macros.
Type * Pointer
Pointer to a non-constant vector value.
Definition: HybridVector.h:182
Header file for the addition trait.
Header file for the cross product trait.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
Header file for the division trait.
Constraint on the data type.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
#define BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE(T)
Constraint on the data type.In case the given data type T is not a numeric (integral or floating poin...
Definition: Numeric.h:79
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type storeu(T *address, const sse_int16_t &value)
Unaligned store of a vector of 2-byte integral values.
Definition: Storeu.h:77
void move(DynamicMatrix< Type, SO > &dst, DynamicMatrix< Type, SO > &src)
Moving the contents of one dynamic matrix to another.
Definition: DynamicMatrix.h:4934
Header file for the AlignedArray implementation.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
Header file for the isDefault shim.
Constraint on the data type.
Header file for the HasMutableDataAccess type trait.
Pointer data()
Low-level data access to the vector elements.
Definition: HybridVector.h:737
void swap(HybridVector &v)
Swapping the contents of two hybrid vectors.
Definition: HybridVector.h:1335
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:200
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: HybridVector.h:1556
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:58
Header file for all intrinsic functionality.
Header file for the mathematical trait.
Type & Reference
Reference to a non-constant vector value.
Definition: HybridVector.h:180
void reset()
Reset to the default initial values.
Definition: HybridVector.h:1204
HybridVector< Type, N, TF > This
Type of this HybridVector instance.
Definition: HybridVector.h:173
Iterator end()
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:814
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:151
const Type & ConstReference
Reference to a constant vector value.
Definition: HybridVector.h:181
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: HybridVector.h:1535
Header file for the default transpose flag for all vectors of the Blaze library.
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: HybridVector.h:177
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
BLAZE_ALWAYS_INLINE IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1599
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
Header file for the IsResizable type trait.
System settings for the inline keywords.
#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
This ResultType
Result type for expression template evaluations.
Definition: HybridVector.h:174
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849