All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/util/Assert.h>
63 #include <blaze/util/DisableIf.h>
64 #include <blaze/util/EnableIf.h>
65 #include <blaze/util/Memory.h>
67 #include <blaze/util/Template.h>
68 #include <blaze/util/Types.h>
72 #include <blaze/util/Unused.h>
73 
74 
75 namespace blaze {
76 
77 //=================================================================================================
78 //
79 // CLASS DEFINITION
80 //
81 //=================================================================================================
82 
83 //*************************************************************************************************
153 template< typename Type // Data type of the vector
154  , size_t N // Number of elements
155  , bool TF = defaultTransposeFlag > // Transpose flag
156 class HybridVector : public DenseVector< HybridVector<Type,N,TF>, TF >
157 {
158  private:
159  //**Type definitions****************************************************************************
161  //**********************************************************************************************
162 
163  //**********************************************************************************************
165  enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
166  //**********************************************************************************************
167 
168  public:
169  //**Type definitions****************************************************************************
171  typedef This ResultType;
173  typedef Type ElementType;
174  typedef typename IT::Type IntrinsicType;
175  typedef const Type& ReturnType;
176  typedef const HybridVector& CompositeType;
177  typedef Type& Reference;
178  typedef const Type& ConstReference;
179  typedef Type* Pointer;
180  typedef const Type* ConstPointer;
183  //**********************************************************************************************
184 
185  //**Rebind struct definition********************************************************************
188  template< typename ET > // Data type of the other vector
189  struct Rebind {
191  };
192  //**********************************************************************************************
193 
194  //**Compilation flags***************************************************************************
196 
200  enum { vectorizable = IsVectorizable<Type>::value };
201 
203 
206  enum { smpAssignable = 0 };
207  //**********************************************************************************************
208 
209  //**Constructors********************************************************************************
212  explicit inline HybridVector();
213  explicit inline HybridVector( size_t n );
214  explicit inline HybridVector( size_t n, const Type& init );
215  template< typename Other > explicit inline HybridVector( size_t n, const Other* array );
216 
217  template< typename Other, size_t M >
218  explicit inline HybridVector( const Other (&array)[M] );
219 
220  inline HybridVector( const HybridVector& v );
221  template< typename VT > inline HybridVector( const Vector<VT,TF>& v );
223  //**********************************************************************************************
224 
225  //**Destructor**********************************************************************************
226  // No explicitly declared destructor.
227  //**********************************************************************************************
228 
229  //**Data access functions***********************************************************************
232  inline Reference operator[]( size_t index );
233  inline ConstReference operator[]( size_t index ) const;
234  inline Pointer data ();
235  inline ConstPointer data () const;
236  inline Iterator begin ();
237  inline ConstIterator begin () const;
238  inline ConstIterator cbegin() const;
239  inline Iterator end ();
240  inline ConstIterator end () const;
241  inline ConstIterator cend () const;
243  //**********************************************************************************************
244 
245  //**Assignment operators************************************************************************
248  template< typename Other, size_t M >
249  inline HybridVector& operator=( const Other (&array)[M] );
250 
251  inline HybridVector& operator= ( const Type& rhs );
252  inline HybridVector& operator= ( const HybridVector& rhs );
253  template< typename VT > inline HybridVector& operator= ( const Vector<VT,TF>& rhs );
254  template< typename VT > inline HybridVector& operator+=( const Vector<VT,TF>& rhs );
255  template< typename VT > inline HybridVector& operator-=( const Vector<VT,TF>& rhs );
256  template< typename VT > inline HybridVector& operator*=( const Vector<VT,TF>& rhs );
257 
258  template< typename Other >
259  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
260  operator*=( Other rhs );
261 
262  template< typename Other >
263  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
264  operator/=( Other rhs );
266  //**********************************************************************************************
267 
268  //**Utility functions***************************************************************************
271  inline size_t size() const;
272  inline size_t capacity() const;
273  inline size_t nonZeros() const;
274  inline void reset();
275  inline void clear();
276  inline void resize( size_t n, bool preserve=true );
277  inline void extend( size_t n, bool preserve=true );
278  template< typename Other > inline HybridVector& scale( const Other& scalar );
279  inline void swap( HybridVector& v ) /* throw() */;
281  //**********************************************************************************************
282 
283  //**Memory functions****************************************************************************
286  static inline void* operator new ( std::size_t size );
287  static inline void* operator new[]( std::size_t size );
288  static inline void* operator new ( std::size_t size, const std::nothrow_t& );
289  static inline void* operator new[]( std::size_t size, const std::nothrow_t& );
290 
291  static inline void operator delete ( void* ptr );
292  static inline void operator delete[]( void* ptr );
293  static inline void operator delete ( void* ptr, const std::nothrow_t& );
294  static inline void operator delete[]( void* ptr, const std::nothrow_t& );
296  //**********************************************************************************************
297 
298  private:
299  //**********************************************************************************************
301  template< typename VT >
303  struct VectorizedAssign {
304  enum { value = vectorizable && VT::vectorizable &&
305  IsSame<Type,typename VT::ElementType>::value };
306  };
308  //**********************************************************************************************
309 
310  //**********************************************************************************************
312  template< typename VT >
314  struct VectorizedAddAssign {
315  enum { value = vectorizable && VT::vectorizable &&
316  IsSame<Type,typename VT::ElementType>::value &&
317  IntrinsicTrait<Type>::addition };
318  };
320  //**********************************************************************************************
321 
322  //**********************************************************************************************
324  template< typename VT >
326  struct VectorizedSubAssign {
327  enum { value = vectorizable && VT::vectorizable &&
328  IsSame<Type,typename VT::ElementType>::value &&
329  IntrinsicTrait<Type>::subtraction };
330  };
332  //**********************************************************************************************
333 
334  //**********************************************************************************************
336  template< typename VT >
338  struct VectorizedMultAssign {
339  enum { value = vectorizable && VT::vectorizable &&
340  IsSame<Type,typename VT::ElementType>::value &&
341  IntrinsicTrait<Type>::multiplication };
342  };
344  //**********************************************************************************************
345 
346  public:
347  //**Expression template evaluation functions****************************************************
350  template< typename Other > inline bool canAlias ( const Other* alias ) const;
351  template< typename Other > inline bool isAliased( const Other* alias ) const;
352 
353  inline bool isAligned() const;
354 
355  inline IntrinsicType load ( size_t index ) const;
356  inline IntrinsicType loadu ( size_t index ) const;
357  inline void store ( size_t index, const IntrinsicType& value );
358  inline void storeu( size_t index, const IntrinsicType& value );
359  inline void stream( size_t index, const IntrinsicType& value );
360 
361  template< typename VT >
362  inline typename DisableIf< VectorizedAssign<VT> >::Type
363  assign( const DenseVector<VT,TF>& rhs );
364 
365  template< typename VT >
366  inline typename EnableIf< VectorizedAssign<VT> >::Type
367  assign( const DenseVector<VT,TF>& rhs );
368 
369  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
370 
371  template< typename VT >
372  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
373  addAssign( const DenseVector<VT,TF>& rhs );
374 
375  template< typename VT >
376  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
377  addAssign( const DenseVector<VT,TF>& rhs );
378 
379  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
380 
381  template< typename VT >
382  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
383  subAssign( const DenseVector<VT,TF>& rhs );
384 
385  template< typename VT >
386  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
387  subAssign( const DenseVector<VT,TF>& rhs );
388 
389  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
390 
391  template< typename VT >
392  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
393  multAssign( const DenseVector<VT,TF>& rhs );
394 
395  template< typename VT >
396  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
397  multAssign( const DenseVector<VT,TF>& rhs );
398 
399  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
401  //**********************************************************************************************
402 
403  private:
404  //**Member variables****************************************************************************
408 
413  size_t size_;
414 
415  //**********************************************************************************************
416 
417  //**Compile time checks*************************************************************************
423  BLAZE_STATIC_ASSERT( NN % IT::size == 0UL );
424  BLAZE_STATIC_ASSERT( NN >= N );
426  //**********************************************************************************************
427 };
428 //*************************************************************************************************
429 
430 
431 
432 
433 //=================================================================================================
434 //
435 // CONSTRUCTORS
436 //
437 //=================================================================================================
438 
439 //*************************************************************************************************
444 template< typename Type // Data type of the vector
445  , size_t N // Number of elements
446  , bool TF > // Transpose flag
448  : v_ () // The statically allocated vector elements
449  , size_( 0UL ) // The current size/dimension of the vector
450 {
452 
453  if( IsNumeric<Type>::value ) {
454  for( size_t i=0UL; i<NN; ++i )
455  v_[i] = Type();
456  }
457 }
458 //*************************************************************************************************
459 
460 
461 //*************************************************************************************************
471 template< typename Type // Data type of the vector
472  , size_t N // Number of elements
473  , bool TF > // Transpose flag
475  : v_ () // The statically allocated vector elements
476  , size_( n ) // The current size/dimension of the vector
477 {
479 
480  if( n > N )
481  throw std::invalid_argument( "Invalid size for hybrid vector" );
482 
483  if( IsNumeric<Type>::value ) {
484  for( size_t i=0UL; i<NN; ++i )
485  v_[i] = Type();
486  }
487 }
488 //*************************************************************************************************
489 
490 
491 //*************************************************************************************************
502 template< typename Type // Data type of the vector
503  , size_t N // Number of elements
504  , bool TF > // Transpose flag
505 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Type& init )
506  : v_ () // The statically allocated vector elements
507  , size_( n ) // The current size/dimension of the vector
508 {
510 
511  if( n > N )
512  throw std::invalid_argument( "Invalid size for hybrid vector" );
513 
514  for( size_t i=0UL; i<n; ++i )
515  v_[i] = init;
516 
517  if( IsNumeric<Type>::value ) {
518  for( size_t i=n; i<NN; ++i )
519  v_[i] = Type();
520  }
521 }
522 //*************************************************************************************************
523 
524 
525 //*************************************************************************************************
548 template< typename Type // Data type of the vector
549  , size_t N // Number of elements
550  , bool TF > // Transpose flag
551 template< typename Other > // Data type of the initialization array
552 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Other* array )
553  : v_ () // The statically allocated vector elements
554  , size_( n ) // The current size/dimension of the vector
555 {
557 
558  if( n > N )
559  throw std::invalid_argument( "Invalid setup of hybrid vector" );
560 
561  for( size_t i=0UL; i<n; ++i )
562  v_[i] = array[i];
563 
564  if( IsNumeric<Type>::value ) {
565  for( size_t i=n; i<NN; ++i )
566  v_[i] = Type();
567  }
568 }
569 //*************************************************************************************************
570 
571 
572 //*************************************************************************************************
590 template< typename Type // Data type of the vector
591  , size_t N // Number of elements
592  , bool TF > // Transpose flag
593 template< typename Other // Data type of the initialization array
594  , size_t M > // Number of elements of the initialization array
595 inline HybridVector<Type,N,TF>::HybridVector( const Other (&array)[M] )
596  : v_ () // The statically allocated vector elements
597  , size_( M ) // The current size/dimension of the vector
598 {
599  BLAZE_STATIC_ASSERT( M <= N );
601 
602  for( size_t i=0UL; i<M; ++i )
603  v_[i] = array[i];
604 
605  if( IsNumeric<Type>::value ) {
606  for( size_t i=M; i<NN; ++i )
607  v_[i] = Type();
608  }
609 }
610 //*************************************************************************************************
611 
612 
613 //*************************************************************************************************
620 template< typename Type // Data type of the vector
621  , size_t N // Number of elements
622  , bool TF > // Transpose flag
624  : v_ () // The statically allocated vector elements
625  , size_( v.size_ ) // The current size/dimension of the vector
626 {
628 
629  for( size_t i=0UL; i<size_; ++i )
630  v_[i] = v.v_[i];
631 
632  if( IsNumeric<Type>::value ) {
633  for( size_t i=size_; i<NN; ++i )
634  v_[i] = Type();
635  }
636 }
637 //*************************************************************************************************
638 
639 
640 //*************************************************************************************************
650 template< typename Type // Data type of the vector
651  , size_t N // Number of elements
652  , bool TF > // Transpose flag
653 template< typename VT > // Type of the foreign vector
655  : v_ () // The statically allocated vector elements
656  , size_( (~v).size() ) // The current size/dimension of the vector
657 {
658  using blaze::assign;
659 
661 
662  if( (~v).size() > N )
663  throw std::invalid_argument( "Invalid setup of hybrid vector" );
664 
665  for( size_t i=( IsSparseVector<VT>::value ? 0UL : size_ );
666  i<( IsNumeric<Type>::value ? NN : size_ ); ++i ) {
667  v_[i] = Type();
668  }
669 
670  assign( *this, ~v );
671 }
672 //*************************************************************************************************
673 
674 
675 
676 
677 //=================================================================================================
678 //
679 // DATA ACCESS FUNCTIONS
680 //
681 //=================================================================================================
682 
683 //*************************************************************************************************
691 template< typename Type // Data type of the vector
692  , size_t N // Number of elements
693  , bool TF > // Transpose flag
696 {
697  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
698  return v_[index];
699 }
700 //*************************************************************************************************
701 
702 
703 //*************************************************************************************************
711 template< typename Type // Data type of the vector
712  , size_t N // Number of elements
713  , bool TF > // Transpose flag
716 {
717  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
718  return v_[index];
719 }
720 //*************************************************************************************************
721 
722 
723 //*************************************************************************************************
730 template< typename Type // Data type of the vector
731  , size_t N // Number of elements
732  , bool TF > // Transpose flag
734 {
735  return v_;
736 }
737 //*************************************************************************************************
738 
739 
740 //*************************************************************************************************
747 template< typename Type // Data type of the vector
748  , size_t N // Number of elements
749  , bool TF > // Transpose flag
751 {
752  return v_;
753 }
754 //*************************************************************************************************
755 
756 
757 //*************************************************************************************************
762 template< typename Type // Data type of the vector
763  , size_t N // Number of elements
764  , bool TF > // Transpose flag
766 {
767  return Iterator( v_ );
768 }
769 //*************************************************************************************************
770 
771 
772 //*************************************************************************************************
777 template< typename Type // Data type of the vector
778  , size_t N // Number of elements
779  , bool TF > // Transpose flag
781 {
782  return ConstIterator( v_ );
783 }
784 //*************************************************************************************************
785 
786 
787 //*************************************************************************************************
792 template< typename Type // Data type of the vector
793  , size_t N // Number of elements
794  , bool TF > // Transpose flag
796 {
797  return ConstIterator( v_ );
798 }
799 //*************************************************************************************************
800 
801 
802 //*************************************************************************************************
807 template< typename Type // Data type of the vector
808  , size_t N // Number of elements
809  , bool TF > // Transpose flag
811 {
812  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
813  return Iterator( v_ + size_ );
814 }
815 //*************************************************************************************************
816 
817 
818 //*************************************************************************************************
823 template< typename Type // Data type of the vector
824  , size_t N // Number of elements
825  , bool TF > // Transpose flag
827 {
828  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
829  return ConstIterator( v_ + size_ );
830 }
831 //*************************************************************************************************
832 
833 
834 //*************************************************************************************************
839 template< typename Type // Data type of the vector
840  , size_t N // Number of elements
841  , bool TF > // Transpose flag
843 {
844  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
845  return ConstIterator( v_ + size_ );
846 }
847 //*************************************************************************************************
848 
849 
850 
851 
852 //=================================================================================================
853 //
854 // ASSIGNMENT OPERATORS
855 //
856 //=================================================================================================
857 
858 //*************************************************************************************************
877 template< typename Type // Data type of the vector
878  , size_t N // Number of elements
879  , bool TF > // Transpose flag
880 template< typename Other // Data type of the initialization array
881  , size_t M > // Number of elements of the initialization array
883 {
884  BLAZE_STATIC_ASSERT( M <= N );
885 
886  resize( M );
887 
888  for( size_t i=0UL; i<M; ++i )
889  v_[i] = array[i];
890 
891  return *this;
892 }
893 //*************************************************************************************************
894 
895 
896 //*************************************************************************************************
902 template< typename Type // Data type of the vector
903  , size_t N // Number of elements
904  , bool TF > // Transpose flag
906 {
907  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
908 
909  for( size_t i=0UL; i<size_; ++i )
910  v_[i] = rhs;
911  return *this;
912 }
913 //*************************************************************************************************
914 
915 
916 //*************************************************************************************************
924 template< typename Type // Data type of the vector
925  , size_t N // Number of elements
926  , bool TF > // Transpose flag
928 {
929  using blaze::assign;
930 
931  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
932 
933  resize( rhs.size() );
934  assign( *this, ~rhs );
935 
936  return *this;
937 }
938 //*************************************************************************************************
939 
940 
941 //*************************************************************************************************
951 template< typename Type // Data type of the vector
952  , size_t N // Number of elements
953  , bool TF > // Transpose flag
954 template< typename VT > // Type of the right-hand side vector
956 {
957  using blaze::assign;
958 
959  if( (~rhs).size() > N )
960  throw std::invalid_argument( "Invalid assignment to hybrid vector" );
961 
962  if( (~rhs).canAlias( this ) ) {
963  HybridVector tmp( ~rhs );
964  swap( tmp );
965  }
966  else {
967  resize( (~rhs).size() );
969  reset();
970  assign( *this, ~rhs );
971  }
972 
973  return *this;
974 }
975 //*************************************************************************************************
976 
977 
978 //*************************************************************************************************
988 template< typename Type // Data type of the vector
989  , size_t N // Number of elements
990  , bool TF > // Transpose flag
991 template< typename VT > // Type of the right-hand side vector
993 {
994  using blaze::addAssign;
995 
996  if( (~rhs).size() != size_ )
997  throw std::invalid_argument( "Vector sizes do not match" );
998 
999  if( (~rhs).canAlias( this ) ) {
1000  typename VT::ResultType tmp( ~rhs );
1001  addAssign( *this, tmp );
1002  }
1003  else {
1004  addAssign( *this, ~rhs );
1005  }
1006 
1007  return *this;
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1022 template< typename Type // Data type of the vector
1023  , size_t N // Number of elements
1024  , bool TF > // Transpose flag
1025 template< typename VT > // Type of the right-hand side vector
1027 {
1028  using blaze::subAssign;
1029 
1030  if( (~rhs).size() != size_ )
1031  throw std::invalid_argument( "Vector sizes do not match" );
1032 
1033  if( (~rhs).canAlias( this ) ) {
1034  typename VT::ResultType tmp( ~rhs );
1035  subAssign( *this, tmp );
1036  }
1037  else {
1038  subAssign( *this, ~rhs );
1039  }
1040 
1041  return *this;
1042 }
1043 //*************************************************************************************************
1044 
1045 
1046 //*************************************************************************************************
1057 template< typename Type // Data type of the vector
1058  , size_t N // Number of elements
1059  , bool TF > // Transpose flag
1060 template< typename VT > // Type of the right-hand side vector
1062 {
1063  using blaze::multAssign;
1064 
1065  if( (~rhs).size() != size_ )
1066  throw std::invalid_argument( "Vector sizes do not match" );
1067 
1068  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
1069  HybridVector tmp( *this * (~rhs) );
1070  this->operator=( tmp );
1071  }
1072  else {
1073  multAssign( *this, ~rhs );
1074  }
1075 
1076  return *this;
1077 }
1078 //*************************************************************************************************
1079 
1080 
1081 //*************************************************************************************************
1088 template< typename Type // Data type of the vector
1089  , size_t N // Number of elements
1090  , bool TF > // Transpose flag
1091 template< typename Other > // Data type of the right-hand side scalar
1092 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1094 {
1095  using blaze::assign;
1096 
1097  assign( *this, (*this) * rhs );
1098  return *this;
1099 }
1100 //*************************************************************************************************
1101 
1102 
1103 //*************************************************************************************************
1112 template< typename Type // Data type of the vector
1113  , size_t N // Number of elements
1114  , bool TF > // Transpose flag
1115 template< typename Other > // Data type of the right-hand side scalar
1116 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1118 {
1119  using blaze::assign;
1120 
1121  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1122 
1123  assign( *this, (*this) / rhs );
1124  return *this;
1125 }
1126 //*************************************************************************************************
1127 
1128 
1129 
1130 
1131 //=================================================================================================
1132 //
1133 // UTILITY FUNCTIONS
1134 //
1135 //=================================================================================================
1136 
1137 //*************************************************************************************************
1142 template< typename Type // Data type of the vector
1143  , size_t N // Number of elements
1144  , bool TF > // Transpose flag
1145 inline size_t HybridVector<Type,N,TF>::size() const
1146 {
1147  return size_;
1148 }
1149 //*************************************************************************************************
1150 
1151 
1152 //*************************************************************************************************
1157 template< typename Type // Data type of the vector
1158  , size_t N // Number of elements
1159  , bool TF > // Transpose flag
1161 {
1162  return NN;
1163 }
1164 //*************************************************************************************************
1165 
1166 
1167 //*************************************************************************************************
1175 template< typename Type // Data type of the vector
1176  , size_t N // Number of elements
1177  , bool TF > // Transpose flag
1179 {
1180  size_t nonzeros( 0 );
1181 
1182  for( size_t i=0UL; i<size_; ++i ) {
1183  if( !isDefault( v_[i] ) )
1184  ++nonzeros;
1185  }
1186 
1187  return nonzeros;
1188 }
1189 //*************************************************************************************************
1190 
1191 
1192 //*************************************************************************************************
1197 template< typename Type // Data type of the vector
1198  , size_t N // Number of elements
1199  , bool TF > // Transpose flag
1201 {
1202  using blaze::clear;
1203  for( size_t i=0UL; i<size_; ++i )
1204  clear( v_[i] );
1205 }
1206 //*************************************************************************************************
1207 
1208 
1209 //*************************************************************************************************
1216 template< typename Type // Data type of the vector
1217  , size_t N // Number of elements
1218  , bool TF > // Transpose flag
1220 {
1221  resize( 0UL );
1222 }
1223 //*************************************************************************************************
1224 
1225 
1226 //*************************************************************************************************
1257 template< typename Type // Data type of the vector
1258  , size_t N // Number of elements
1259  , bool TF > // Transpose flag
1260 inline void HybridVector<Type,N,TF>::resize( size_t n, bool preserve )
1261 {
1262  UNUSED_PARAMETER( preserve );
1263 
1264  if( n > N )
1265  throw std::invalid_argument( "Invalid size for hybrid vector" );
1266 
1267  if( IsVectorizable<Type>::value && n < size_ ) {
1268  for( size_t i=n; i<size_; ++i )
1269  v_[i] = Type();
1270  }
1271 
1272  size_ = n;
1273 }
1274 //*************************************************************************************************
1275 
1276 
1277 //*************************************************************************************************
1291 template< typename Type // Data type of the vector
1292  , size_t N // Number of elements
1293  , bool TF > // Transpose flag
1294 inline void HybridVector<Type,N,TF>::extend( size_t n, bool preserve )
1295 {
1296  UNUSED_PARAMETER( preserve );
1297  resize( size_+n );
1298 }
1299 //*************************************************************************************************
1300 
1301 
1302 //*************************************************************************************************
1308 template< typename Type // Data type of the vector
1309  , size_t N // Number of elements
1310  , bool TF > // Transpose flag
1311 template< typename Other > // Data type of the scalar value
1313 {
1314  for( size_t i=0; i<size_; ++i )
1315  v_[i] *= scalar;
1316  return *this;
1317 }
1318 //*************************************************************************************************
1319 
1320 
1321 //*************************************************************************************************
1328 template< typename Type // Data type of the vector
1329  , size_t N // Number of elements
1330  , bool TF > // Transpose flag
1331 inline void HybridVector<Type,N,TF>::swap( HybridVector& v ) /* throw() */
1332 {
1333  using std::swap;
1334 
1335  const size_t maxsize( max( size_, v.size_ ) );
1336  for( size_t i=0UL; i<maxsize; ++i )
1337  swap( v_[i], v.v_[i] );
1338  swap( size_, v.size_ );
1339 }
1340 //*************************************************************************************************
1341 
1342 
1343 
1344 
1345 //=================================================================================================
1346 //
1347 // MEMORY FUNCTIONS
1348 //
1349 //=================================================================================================
1350 
1351 //*************************************************************************************************
1361 template< typename Type // Data type of the vector
1362  , size_t N // Number of elements
1363  , bool TF > // Transpose flag
1364 inline void* HybridVector<Type,N,TF>::operator new( std::size_t size )
1365 {
1367 
1368  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1369 
1370  return allocate<HybridVector>( 1UL );
1371 }
1372 //*************************************************************************************************
1373 
1374 
1375 //*************************************************************************************************
1385 template< typename Type // Data type of the vector
1386  , size_t N // Number of elements
1387  , bool TF > // Transpose flag
1388 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size )
1389 {
1390  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1391  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1392 
1393  return allocate<HybridVector>( size/sizeof(HybridVector) );
1394 }
1395 //*************************************************************************************************
1396 
1397 
1398 //*************************************************************************************************
1408 template< typename Type // Data type of the vector
1409  , size_t N // Number of elements
1410  , bool TF > // Transpose flag
1411 inline void* HybridVector<Type,N,TF>::operator new( std::size_t size, const std::nothrow_t& )
1412 {
1414 
1415  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1416 
1417  return allocate<HybridVector>( 1UL );
1418 }
1419 //*************************************************************************************************
1420 
1421 
1422 //*************************************************************************************************
1432 template< typename Type // Data type of the vector
1433  , size_t N // Number of elements
1434  , bool TF > // Transpose flag
1435 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size, const std::nothrow_t& )
1436 {
1437  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1438  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1439 
1440  return allocate<HybridVector>( size/sizeof(HybridVector) );
1441 }
1442 //*************************************************************************************************
1443 
1444 
1445 //*************************************************************************************************
1451 template< typename Type // Data type of the vector
1452  , size_t N // Number of elements
1453  , bool TF > // Transpose flag
1454 inline void HybridVector<Type,N,TF>::operator delete( void* ptr )
1455 {
1456  deallocate( static_cast<HybridVector*>( ptr ) );
1457 }
1458 //*************************************************************************************************
1459 
1460 
1461 //*************************************************************************************************
1467 template< typename Type // Data type of the vector
1468  , size_t N // Number of elements
1469  , bool TF > // Transpose flag
1470 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr )
1471 {
1472  deallocate( static_cast<HybridVector*>( ptr ) );
1473 }
1474 //*************************************************************************************************
1475 
1476 
1477 //*************************************************************************************************
1483 template< typename Type // Data type of the vector
1484  , size_t N // Number of elements
1485  , bool TF > // Transpose flag
1486 inline void HybridVector<Type,N,TF>::operator delete( void* ptr, const std::nothrow_t& )
1487 {
1488  deallocate( static_cast<HybridVector*>( ptr ) );
1489 }
1490 //*************************************************************************************************
1491 
1492 
1493 //*************************************************************************************************
1499 template< typename Type // Data type of the vector
1500  , size_t N // Number of elements
1501  , bool TF > // Transpose flag
1502 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr, const std::nothrow_t& )
1503 {
1504  deallocate( static_cast<HybridVector*>( ptr ) );
1505 }
1506 //*************************************************************************************************
1507 
1508 
1509 
1510 
1511 //=================================================================================================
1512 //
1513 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1514 //
1515 //=================================================================================================
1516 
1517 //*************************************************************************************************
1527 template< typename Type // Data type of the vector
1528  , size_t N // Number of elements
1529  , bool TF > // Transpose flag
1530 template< typename Other > // Data type of the foreign expression
1531 inline bool HybridVector<Type,N,TF>::canAlias( const Other* alias ) const
1532 {
1533  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1534 }
1535 //*************************************************************************************************
1536 
1537 
1538 //*************************************************************************************************
1548 template< typename Type // Data type of the vector
1549  , size_t N // Number of elements
1550  , bool TF > // Transpose flag
1551 template< typename Other > // Data type of the foreign expression
1552 inline bool HybridVector<Type,N,TF>::isAliased( const Other* alias ) const
1553 {
1554  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1555 }
1556 //*************************************************************************************************
1557 
1558 
1559 //*************************************************************************************************
1568 template< typename Type // Data type of the vector
1569  , size_t N // Number of elements
1570  , bool TF > // Transpose flag
1572 {
1573  return true;
1574 }
1575 //*************************************************************************************************
1576 
1577 
1578 //*************************************************************************************************
1591 template< typename Type // Data type of the vector
1592  , size_t N // Number of elements
1593  , bool TF > // Transpose flag
1595  HybridVector<Type,N,TF>::load( size_t index ) const
1596 {
1597  using blaze::load;
1598 
1600 
1601  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1602  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1603  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1604 
1605  return load( &v_[index] );
1606 }
1607 //*************************************************************************************************
1608 
1609 
1610 //*************************************************************************************************
1623 template< typename Type // Data type of the vector
1624  , size_t N // Number of elements
1625  , bool TF > // Transpose flag
1627  HybridVector<Type,N,TF>::loadu( size_t index ) const
1628 {
1629  using blaze::loadu;
1630 
1632 
1633  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1634  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1635 
1636  return loadu( &v_[index] );
1637 }
1638 //*************************************************************************************************
1639 
1640 
1641 //*************************************************************************************************
1655 template< typename Type // Data type of the vector
1656  , size_t N // Number of elements
1657  , bool TF > // Transpose flag
1658 inline void HybridVector<Type,N,TF>::store( size_t index, const IntrinsicType& value )
1659 {
1660  using blaze::store;
1661 
1663 
1664  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1665  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1666  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1667 
1668  store( &v_[index], value );
1669 }
1670 //*************************************************************************************************
1671 
1672 
1673 //*************************************************************************************************
1687 template< typename Type // Data type of the vector
1688  , size_t N // Number of elements
1689  , bool TF > // Transpose flag
1690 inline void HybridVector<Type,N,TF>::storeu( size_t index, const IntrinsicType& value )
1691 {
1692  using blaze::storeu;
1693 
1695 
1696  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1697  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1698 
1699  storeu( &v_[index], value );
1700 }
1701 //*************************************************************************************************
1702 
1703 
1704 //*************************************************************************************************
1718 template< typename Type // Data type of the vector
1719  , size_t N // Number of elements
1720  , bool TF > // Transpose flag
1721 inline void HybridVector<Type,N,TF>::stream( size_t index, const IntrinsicType& value )
1722 {
1723  using blaze::stream;
1724 
1726 
1727  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1728  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1729  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1730 
1731  stream( &v_[index], value );
1732 }
1733 //*************************************************************************************************
1734 
1735 
1736 //*************************************************************************************************
1747 template< typename Type // Data type of the vector
1748  , size_t N // Number of elements
1749  , bool TF > // Transpose flag
1750 template< typename VT > // Type of the right-hand side dense vector
1751 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1753 {
1754  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1755 
1756  for( size_t i=0UL; i<size_; ++i )
1757  v_[i] = (~rhs)[i];
1758 }
1759 //*************************************************************************************************
1760 
1761 
1762 //*************************************************************************************************
1773 template< typename Type // Data type of the vector
1774  , size_t N // Number of elements
1775  , bool TF > // Transpose flag
1776 template< typename VT > // Type of the right-hand side dense vector
1777 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1779 {
1780  using blaze::store;
1781 
1782  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1783 
1785 
1786  for( size_t i=0UL; i<size_; i+=IT::size ) {
1787  store( v_+i, (~rhs).load(i) );
1788  }
1789 }
1790 //*************************************************************************************************
1791 
1792 
1793 //*************************************************************************************************
1804 template< typename Type // Data type of the vector
1805  , size_t N // Number of elements
1806  , bool TF > // Transpose flag
1807 template< typename VT > // Type of the right-hand side sparse vector
1809 {
1810  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1811 
1812  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1813  v_[element->index()] = element->value();
1814 }
1815 //*************************************************************************************************
1816 
1817 
1818 //*************************************************************************************************
1829 template< typename Type // Data type of the vector
1830  , size_t N // Number of elements
1831  , bool TF > // Transpose flag
1832 template< typename VT > // Type of the right-hand side dense vector
1833 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1835 {
1836  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1837 
1838  for( size_t i=0UL; i<size_; ++i )
1839  v_[i] += (~rhs)[i];
1840 }
1841 //*************************************************************************************************
1842 
1843 
1844 //*************************************************************************************************
1855 template< typename Type // Data type of the vector
1856  , size_t N // Number of elements
1857  , bool TF > // Transpose flag
1858 template< typename VT > // Type of the right-hand side dense vector
1859 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1861 {
1862  using blaze::load;
1863  using blaze::store;
1864 
1865  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1866 
1868 
1869  for( size_t i=0UL; i<size_; i+=IT::size ) {
1870  store( v_+i, load( v_+i ) + (~rhs).load(i) );
1871  }
1872 }
1873 //*************************************************************************************************
1874 
1875 
1876 //*************************************************************************************************
1887 template< typename Type // Data type of the vector
1888  , size_t N // Number of elements
1889  , bool TF > // Transpose flag
1890 template< typename VT > // Type of the right-hand side sparse vector
1892 {
1893  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1894 
1895  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1896  v_[element->index()] += element->value();
1897 }
1898 //*************************************************************************************************
1899 
1900 
1901 //*************************************************************************************************
1912 template< typename Type // Data type of the vector
1913  , size_t N // Number of elements
1914  , bool TF > // Transpose flag
1915 template< typename VT > // Type of the right-hand side dense vector
1916 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1918 {
1919  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1920 
1921  for( size_t i=0UL; i<size_; ++i )
1922  v_[i] -= (~rhs)[i];
1923 }
1924 //*************************************************************************************************
1925 
1926 
1927 //*************************************************************************************************
1938 template< typename Type // Data type of the vector
1939  , size_t N // Number of elements
1940  , bool TF > // Transpose flag
1941 template< typename VT > // Type of the right-hand side dense vector
1942 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1944 {
1945  using blaze::load;
1946  using blaze::store;
1947 
1948  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1949 
1951 
1952  for( size_t i=0UL; i<size_; i+=IT::size ) {
1953  store( v_+i, load( v_+i ) - (~rhs).load(i) );
1954  }
1955 }
1956 //*************************************************************************************************
1957 
1958 
1959 //*************************************************************************************************
1970 template< typename Type // Data type of the vector
1971  , size_t N // Number of elements
1972  , bool TF > // Transpose flag
1973 template< typename VT > // Type of the right-hand side sparse vector
1975 {
1976  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1977 
1978  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1979  v_[element->index()] -= element->value();
1980 }
1981 //*************************************************************************************************
1982 
1983 
1984 //*************************************************************************************************
1995 template< typename Type // Data type of the vector
1996  , size_t N // Number of elements
1997  , bool TF > // Transpose flag
1998 template< typename VT > // Type of the right-hand side dense vector
1999 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2001 {
2002  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2003 
2004  for( size_t i=0UL; i<size_; ++i )
2005  v_[i] *= (~rhs)[i];
2006 }
2007 //*************************************************************************************************
2008 
2009 
2010 //*************************************************************************************************
2021 template< typename Type // Data type of the vector
2022  , size_t N // Number of elements
2023  , bool TF > // Transpose flag
2024 template< typename VT > // Type of the right-hand side dense vector
2025 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2027 {
2028  using blaze::load;
2029  using blaze::store;
2030 
2031  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2032 
2034 
2035  for( size_t i=0UL; i<size_; i+=IT::size ) {
2036  store( v_+i, load( v_+i ) * (~rhs).load(i) );
2037  }
2038 }
2039 //*************************************************************************************************
2040 
2041 
2042 //*************************************************************************************************
2053 template< typename Type // Data type of the vector
2054  , size_t N // Number of elements
2055  , bool TF > // Transpose flag
2056 template< typename VT > // Type of the right-hand side sparse vector
2058 {
2059  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2060 
2061  const HybridVector tmp( serial( *this ) );
2062 
2063  reset();
2064 
2065  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2066  v_[element->index()] = tmp[element->index()] * element->value();
2067 }
2068 //*************************************************************************************************
2069 
2070 
2071 
2072 
2073 
2074 
2075 
2076 
2077 //=================================================================================================
2078 //
2079 // UNDEFINED CLASS TEMPLATE SPECIALIZATION
2080 //
2081 //=================================================================================================
2082 
2083 //*************************************************************************************************
2091 template< typename Type // Data type of the vector
2092  , bool TF > // Transpose flag
2093 class HybridVector<Type,0UL,TF>;
2095 //*************************************************************************************************
2096 
2097 
2098 
2099 
2100 
2101 
2102 
2103 
2104 //=================================================================================================
2105 //
2106 // HYBRIDVECTOR OPERATORS
2107 //
2108 //=================================================================================================
2109 
2110 //*************************************************************************************************
2113 template< typename Type, size_t N, bool TF >
2114 inline void reset( HybridVector<Type,N,TF>& v );
2115 
2116 template< typename Type, size_t N, bool TF >
2117 inline void clear( HybridVector<Type,N,TF>& v );
2118 
2119 template< typename Type, size_t N, bool TF >
2120 inline bool isDefault( const HybridVector<Type,N,TF>& v );
2121 
2122 template< typename Type, size_t N, bool TF >
2123 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */;
2124 
2125 template< typename Type, size_t N, bool TF >
2126 inline void move( HybridVector<Type,N,TF>& dst, HybridVector<Type,N,TF>& src ) /* throw() */;
2128 //*************************************************************************************************
2129 
2130 
2131 //*************************************************************************************************
2138 template< typename Type // Data type of the vector
2139  , size_t N // Number of elements
2140  , bool TF > // Transpose flag
2142 {
2143  v.reset();
2144 }
2145 //*************************************************************************************************
2146 
2147 
2148 //*************************************************************************************************
2155 template< typename Type // Data type of the vector
2156  , size_t N // Number of elements
2157  , bool TF > // Transpose flag
2159 {
2160  v.clear();
2161 }
2162 //*************************************************************************************************
2163 
2164 
2165 //*************************************************************************************************
2182 template< typename Type // Data type of the vector
2183  , size_t N // Number of elements
2184  , bool TF > // Transpose flag
2185 inline bool isDefault( const HybridVector<Type,N,TF>& v )
2186 {
2187  return ( v.size() == 0UL );
2188 }
2189 //*************************************************************************************************
2190 
2191 
2192 //*************************************************************************************************
2201 template< typename Type // Data type of the vector
2202  , size_t N // Number of elements
2203  , bool TF > // Transpose flag
2204 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */
2205 {
2206  a.swap( b );
2207 }
2208 //*************************************************************************************************
2209 
2210 
2211 //*************************************************************************************************
2220 template< typename Type // Data type of the vector
2221  , size_t N // Number of elements
2222  , bool TF > // Transpose flag
2223 inline void move( HybridVector<Type,N,TF>& dst, HybridVector<Type,N,TF>& src ) /* throw() */
2224 {
2225  dst = src;
2226 }
2227 //*************************************************************************************************
2228 
2229 
2230 
2231 
2232 //=================================================================================================
2233 //
2234 // ISRESIZABLE SPECIALIZATIONS
2235 //
2236 //=================================================================================================
2237 
2238 //*************************************************************************************************
2240 template< typename T, size_t N, bool TF >
2241 struct IsResizable< HybridVector<T,N,TF> > : public TrueType
2242 {
2243  enum { value = 1 };
2244  typedef TrueType Type;
2245 };
2247 //*************************************************************************************************
2248 
2249 
2250 
2251 
2252 //=================================================================================================
2253 //
2254 // ADDTRAIT SPECIALIZATIONS
2255 //
2256 //=================================================================================================
2257 
2258 //*************************************************************************************************
2260 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2261 struct AddTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2262 {
2263  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2264 };
2265 
2266 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2267 struct AddTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2268 {
2269  typedef StaticVector< typename AddTrait<T1,T2>::Type, M, TF > Type;
2270 };
2271 
2272 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2273 struct AddTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2274 {
2275  typedef HybridVector< typename AddTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2276 };
2278 //*************************************************************************************************
2279 
2280 
2281 
2282 
2283 //=================================================================================================
2284 //
2285 // SUBTRAIT SPECIALIZATIONS
2286 //
2287 //=================================================================================================
2288 
2289 //*************************************************************************************************
2291 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2292 struct SubTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2293 {
2294  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2295 };
2296 
2297 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2298 struct SubTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2299 {
2300  typedef StaticVector< typename SubTrait<T1,T2>::Type, M, TF > Type;
2301 };
2302 
2303 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2304 struct SubTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2305 {
2306  typedef HybridVector< typename SubTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2307 };
2309 //*************************************************************************************************
2310 
2311 
2312 
2313 
2314 //=================================================================================================
2315 //
2316 // MULTTRAIT SPECIALIZATIONS
2317 //
2318 //=================================================================================================
2319 
2320 //*************************************************************************************************
2322 template< typename T1, size_t N, bool TF, typename T2 >
2323 struct MultTrait< HybridVector<T1,N,TF>, T2 >
2324 {
2325  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2327 };
2328 
2329 template< typename T1, typename T2, size_t N, bool TF >
2330 struct MultTrait< T1, HybridVector<T2,N,TF> >
2331 {
2332  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2334 };
2335 
2336 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2337 struct MultTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2338 {
2339  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2340 };
2341 
2342 template< typename T1, size_t M, typename T2, size_t N >
2343 struct MultTrait< HybridVector<T1,M,false>, StaticVector<T2,N,true> >
2344 {
2345  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2346 };
2347 
2348 template< typename T1, size_t M, typename T2, size_t N >
2349 struct MultTrait< HybridVector<T1,M,true>, StaticVector<T2,N,false> >
2350 {
2351  typedef typename MultTrait<T1,T2>::Type Type;
2352 };
2353 
2354 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2355 struct MultTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2356 {
2357  typedef StaticVector< typename MultTrait<T1,T2>::Type, M, TF > Type;
2358 };
2359 
2360 template< typename T1, size_t M, typename T2, size_t N >
2361 struct MultTrait< StaticVector<T1,M,false>, HybridVector<T2,N,true> >
2362 {
2363  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2364 };
2365 
2366 template< typename T1, size_t M, typename T2, size_t N >
2367 struct MultTrait< StaticVector<T1,M,true>, HybridVector<T2,N,false> >
2368 {
2369  typedef typename MultTrait<T1,T2>::Type Type;
2370 };
2371 
2372 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2373 struct MultTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2374 {
2375  typedef HybridVector< typename MultTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2376 };
2377 
2378 template< typename T1, size_t M, typename T2, size_t N >
2379 struct MultTrait< HybridVector<T1,M,false>, HybridVector<T2,N,true> >
2380 {
2381  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2382 };
2383 
2384 template< typename T1, size_t M, typename T2, size_t N >
2385 struct MultTrait< HybridVector<T1,M,true>, HybridVector<T2,N,false> >
2386 {
2387  typedef typename MultTrait<T1,T2>::Type Type;
2388 };
2390 //*************************************************************************************************
2391 
2392 
2393 
2394 
2395 //=================================================================================================
2396 //
2397 // CROSSTRAIT SPECIALIZATIONS
2398 //
2399 //=================================================================================================
2400 
2401 //*************************************************************************************************
2403 template< typename T1, size_t N, typename T2 >
2404 struct CrossTrait< HybridVector<T1,N,false>, StaticVector<T2,3UL,false> >
2405 {
2406  private:
2407  typedef typename MultTrait<T1,T2>::Type T;
2408 
2409  public:
2410  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2411 };
2412 
2413 template< typename T1, typename T2, size_t N >
2414 struct CrossTrait< StaticVector<T1,3UL,false>, HybridVector<T2,N,false> >
2415 {
2416  private:
2417  typedef typename MultTrait<T1,T2>::Type T;
2418 
2419  public:
2420  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2421 };
2422 
2423 template< typename T1, size_t M, typename T2, size_t N >
2424 struct CrossTrait< HybridVector<T1,M,false>, HybridVector<T2,N,false> >
2425 {
2426  private:
2427  typedef typename MultTrait<T1,T2>::Type T;
2428 
2429  public:
2430  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2431 };
2433 //*************************************************************************************************
2434 
2435 
2436 
2437 
2438 //=================================================================================================
2439 //
2440 // DIVTRAIT SPECIALIZATIONS
2441 //
2442 //=================================================================================================
2443 
2444 //*************************************************************************************************
2446 template< typename T1, size_t N, bool TF, typename T2 >
2447 struct DivTrait< HybridVector<T1,N,TF>, T2 >
2448 {
2449  typedef HybridVector< typename DivTrait<T1,T2>::Type, N, TF > Type;
2451 };
2453 //*************************************************************************************************
2454 
2455 
2456 
2457 
2458 //=================================================================================================
2459 //
2460 // MATHTRAIT SPECIALIZATIONS
2461 //
2462 //=================================================================================================
2463 
2464 //*************************************************************************************************
2466 template< typename T1, size_t N, bool TF, typename T2 >
2467 struct MathTrait< HybridVector<T1,N,TF>, HybridVector<T2,N,TF> >
2468 {
2469  typedef StaticVector< typename MathTrait<T1,T2>::HighType, N, TF > HighType;
2470  typedef StaticVector< typename MathTrait<T1,T2>::LowType , N, TF > LowType;
2471 };
2473 //*************************************************************************************************
2474 
2475 
2476 
2477 
2478 //=================================================================================================
2479 //
2480 // SUBVECTORTRAIT SPECIALIZATIONS
2481 //
2482 //=================================================================================================
2483 
2484 //*************************************************************************************************
2486 template< typename T1, size_t N, bool TF >
2487 struct SubvectorTrait< HybridVector<T1,N,TF> >
2488 {
2489  typedef HybridVector<T1,N,TF> Type;
2490 };
2492 //*************************************************************************************************
2493 
2494 } // namespace blaze
2495 
2496 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:108
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:994
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.
void swap(SymmetricMatrix< MT, SO, DF, NF > &a, SymmetricMatrix< MT, SO, DF, NF > &b)
Swapping the contents of two matrices.
Definition: SymmetricMatrix.h:195
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
HybridVector< ET, N, TF > Other
The type of the other HybridVector.
Definition: HybridVector.h:190
#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:1294
Header file for the UNUSED_PARAMETER function template.
HybridVector()
The default constructor for HybridVector.
Definition: HybridVector.h:447
Header file for the subtraction trait.
Header file for the SparseVector base class.
AlignedArray< Type, NN > v_
The statically allocated vector elements.
Definition: HybridVector.h:407
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: HybridVector.h:1160
HybridVector< Type, N,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: HybridVector.h:172
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
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1595
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T > >::Type stream(T *address, const typename Stream< T, sizeof(T)>::Type &value)
Aligned, non-temporal store of a vector of integral values.
Definition: Stream.h:220
Header file for the IsSame and IsStrictlySame type traits.
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: HybridVector.h:1690
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: HybridVector.h:1571
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:224
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:695
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: HybridVector.h:1178
Type * Pointer
Pointer to a non-constant vector value.
Definition: HybridVector.h:179
Header file for memory allocation and deallocation functionality.
Constraint on the data type.
Iterator begin()
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:765
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1627
Efficient implementation of a dynamically sized vector with static memory.The HybridVector class temp...
Definition: Forward.h:57
const HybridVector & CompositeType
Data type for composite expression templates.
Definition: HybridVector.h:176
Rebind mechanism to obtain a HybridVector with different data/element type.
Definition: HybridVector.h:189
ConstIterator cbegin() const
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:795
Header file for the DisableIf class template.
const Type * ConstPointer
Pointer to a constant vector value.
Definition: HybridVector.h:180
Header file for the multiplication trait.
ConstIterator cend() const
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:842
Header file for the clear shim.
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:4754
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
#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
size_t size() const
Returns the current size/dimension of the vector.
Definition: HybridVector.h:1145
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 clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
Header file for the subvector trait.
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: HybridVector.h:182
Constraint on the data type.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Compile time check for sparse vector types.This type trait tests whether or not the given template pa...
Definition: IsSparseVector.h:103
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T >, Loadu< T, sizeof(T)> >::Type::Type loadu(const T *address)
Loads a vector of integral values.
Definition: Loadu.h:221
const Type & ConstReference
Reference to a constant vector value.
Definition: HybridVector.h:178
Type ElementType
Type of the vector elements.
Definition: HybridVector.h:173
#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:695
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
This ResultType
Result type for expression template evaluations.
Definition: HybridVector.h:171
void clear()
Clearing the vector.
Definition: HybridVector.h:1219
Header file for the EnableIf class template.
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: HybridVector.h:1721
Header file for the serial shim.
Header file for the IsVectorizable type trait.
Header file for the IsNumeric type trait.
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: HybridVector.h:174
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: HybridVector.h:1260
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: HybridVector.h:181
Header file for the IsSparseVector type trait.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
Header file for run time assertion macros.
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: HybridVector.h:160
Header file for the addition trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: HybridVector.h:175
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
void move(DynamicMatrix< Type, SO > &dst, DynamicMatrix< Type, SO > &src)
Moving the contents of one dynamic matrix to another.
Definition: DynamicMatrix.h:4769
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:2481
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
Pointer data()
Low-level data access to the vector elements.
Definition: HybridVector.h:733
void swap(HybridVector &v)
Swapping the contents of two hybrid vectors.
Definition: HybridVector.h:1331
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: HybridVector.h:1552
Type & Reference
Reference to a non-constant vector value.
Definition: HybridVector.h:177
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.
void reset()
Reset to the default initial values.
Definition: HybridVector.h:1200
size_t size_
The current size/dimension of the vector.
Definition: HybridVector.h:413
Iterator end()
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:810
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: HybridVector.h:1531
Header file for the default transpose flag for all vectors of the Blaze library.
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:2473
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T > >::Type storeu(T *address, const typename Storeu< T, sizeof(T)>::Type &value)
Unaligned store of a vector of integral values.
Definition: Storeu.h:218
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
#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
BLAZE_ALWAYS_INLINE EnableIf< IsIntegral< T > >::Type store(T *address, const typename Store< T, sizeof(T)>::Type &value)
Aligned store of a vector of integral values.
Definition: Store.h:225
Header file for the IsResizable type trait.
#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
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: HybridVector.h:1658
HybridVector< Type, N, TF > This
Type of this HybridVector instance.
Definition: HybridVector.h:170
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