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>
43 #include <blaze/math/shims/Reset.h>
55 #include <blaze/util/Assert.h>
62 #include <blaze/util/DisableIf.h>
63 #include <blaze/util/EnableIf.h>
64 #include <blaze/util/Memory.h>
66 #include <blaze/util/Template.h>
67 #include <blaze/util/Types.h>
71 #include <blaze/util/Unused.h>
72 
73 
74 namespace blaze {
75 
76 //=================================================================================================
77 //
78 // CLASS DEFINITION
79 //
80 //=================================================================================================
81 
82 //*************************************************************************************************
152 template< typename Type // Data type of the vector
153  , size_t N // Number of elements
154  , bool TF = defaultTransposeFlag > // Transpose flag
155 class HybridVector : public DenseVector< HybridVector<Type,N,TF>, TF >
156 {
157  private:
158  //**Type definitions****************************************************************************
160  //**********************************************************************************************
161 
162  //**********************************************************************************************
164  enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
165  //**********************************************************************************************
166 
167  public:
168  //**Type definitions****************************************************************************
170  typedef This ResultType;
172  typedef Type ElementType;
173  typedef typename IT::Type IntrinsicType;
174  typedef const Type& ReturnType;
175  typedef const HybridVector& CompositeType;
176  typedef Type& Reference;
177  typedef const Type& ConstReference;
178  typedef Type* Pointer;
179  typedef const Type* ConstPointer;
182  //**********************************************************************************************
183 
184  //**Compilation flags***************************************************************************
186 
190  enum { vectorizable = IsVectorizable<Type>::value };
191 
193 
196  enum { smpAssignable = 0 };
197  //**********************************************************************************************
198 
199  //**Constructors********************************************************************************
202  explicit inline HybridVector();
203  explicit inline HybridVector( size_t n );
204  explicit inline HybridVector( size_t n, const Type& init );
205  template< typename Other > explicit inline HybridVector( size_t n, const Other* array );
206 
207  template< typename Other, size_t M >
208  explicit inline HybridVector( const Other (&array)[M] );
209 
210  inline HybridVector( const HybridVector& v );
211  template< typename VT > inline HybridVector( const Vector<VT,TF>& v );
213  //**********************************************************************************************
214 
215  //**Destructor**********************************************************************************
216  // No explicitly declared destructor.
217  //**********************************************************************************************
218 
219  //**Data access functions***********************************************************************
222  inline Reference operator[]( size_t index );
223  inline ConstReference operator[]( size_t index ) const;
224  inline Pointer data ();
225  inline ConstPointer data () const;
226  inline Iterator begin ();
227  inline ConstIterator begin () const;
228  inline ConstIterator cbegin() const;
229  inline Iterator end ();
230  inline ConstIterator end () const;
231  inline ConstIterator cend () const;
233  //**********************************************************************************************
234 
235  //**Assignment operators************************************************************************
238  template< typename Other, size_t M >
239  inline HybridVector& operator=( const Other (&array)[M] );
240 
241  inline HybridVector& operator= ( const Type& rhs );
242  inline HybridVector& operator= ( const HybridVector& rhs );
243  template< typename VT > inline HybridVector& operator= ( const Vector<VT,TF>& rhs );
244  template< typename VT > inline HybridVector& operator+=( const Vector<VT,TF>& rhs );
245  template< typename VT > inline HybridVector& operator-=( const Vector<VT,TF>& rhs );
246  template< typename VT > inline HybridVector& operator*=( const Vector<VT,TF>& rhs );
247 
248  template< typename Other >
249  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
250  operator*=( Other rhs );
251 
252  template< typename Other >
253  inline typename EnableIf< IsNumeric<Other>, HybridVector >::Type&
254  operator/=( Other rhs );
256  //**********************************************************************************************
257 
258  //**Utility functions***************************************************************************
261  inline size_t size() const;
262  inline size_t capacity() const;
263  inline size_t nonZeros() const;
264  inline void reset();
265  inline void clear();
266  inline void resize( size_t n, bool preserve=true );
267  inline void extend( size_t n, bool preserve=true );
268  template< typename Other > inline HybridVector& scale( Other scalar );
269  inline void swap( HybridVector& v ) /* throw() */;
271  //**********************************************************************************************
272 
273  //**Memory functions****************************************************************************
276  static inline void* operator new ( std::size_t size );
277  static inline void* operator new[]( std::size_t size );
278  static inline void* operator new ( std::size_t size, const std::nothrow_t& );
279  static inline void* operator new[]( std::size_t size, const std::nothrow_t& );
280 
281  static inline void operator delete ( void* ptr );
282  static inline void operator delete[]( void* ptr );
283  static inline void operator delete ( void* ptr, const std::nothrow_t& );
284  static inline void operator delete[]( void* ptr, const std::nothrow_t& );
286  //**********************************************************************************************
287 
288  private:
289  //**********************************************************************************************
291  template< typename VT >
293  struct VectorizedAssign {
294  enum { value = vectorizable && VT::vectorizable &&
295  IsSame<Type,typename VT::ElementType>::value };
296  };
298  //**********************************************************************************************
299 
300  //**********************************************************************************************
302  template< typename VT >
304  struct VectorizedAddAssign {
305  enum { value = vectorizable && VT::vectorizable &&
306  IsSame<Type,typename VT::ElementType>::value &&
307  IntrinsicTrait<Type>::addition };
308  };
310  //**********************************************************************************************
311 
312  //**********************************************************************************************
314  template< typename VT >
316  struct VectorizedSubAssign {
317  enum { value = vectorizable && VT::vectorizable &&
318  IsSame<Type,typename VT::ElementType>::value &&
319  IntrinsicTrait<Type>::subtraction };
320  };
322  //**********************************************************************************************
323 
324  //**********************************************************************************************
326  template< typename VT >
328  struct VectorizedMultAssign {
329  enum { value = vectorizable && VT::vectorizable &&
330  IsSame<Type,typename VT::ElementType>::value &&
331  IntrinsicTrait<Type>::multiplication };
332  };
334  //**********************************************************************************************
335 
336  public:
337  //**Expression template evaluation functions****************************************************
340  template< typename Other > inline bool canAlias ( const Other* alias ) const;
341  template< typename Other > inline bool isAliased( const Other* alias ) const;
342 
343  inline bool isAligned() const;
344 
345  inline IntrinsicType load ( size_t index ) const;
346  inline IntrinsicType loadu ( size_t index ) const;
347  inline void store ( size_t index, const IntrinsicType& value );
348  inline void storeu( size_t index, const IntrinsicType& value );
349  inline void stream( size_t index, const IntrinsicType& value );
350 
351  template< typename VT >
352  inline typename DisableIf< VectorizedAssign<VT> >::Type
353  assign( const DenseVector<VT,TF>& rhs );
354 
355  template< typename VT >
356  inline typename EnableIf< VectorizedAssign<VT> >::Type
357  assign( const DenseVector<VT,TF>& rhs );
358 
359  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
360 
361  template< typename VT >
362  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
363  addAssign( const DenseVector<VT,TF>& rhs );
364 
365  template< typename VT >
366  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
367  addAssign( const DenseVector<VT,TF>& rhs );
368 
369  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
370 
371  template< typename VT >
372  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
373  subAssign( const DenseVector<VT,TF>& rhs );
374 
375  template< typename VT >
376  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
377  subAssign( const DenseVector<VT,TF>& rhs );
378 
379  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
380 
381  template< typename VT >
382  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
383  multAssign( const DenseVector<VT,TF>& rhs );
384 
385  template< typename VT >
386  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
387  multAssign( const DenseVector<VT,TF>& rhs );
388 
389  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
391  //**********************************************************************************************
392 
393  private:
394  //**Member variables****************************************************************************
398 
403  size_t size_;
404 
405  //**********************************************************************************************
406 
407  //**Compile time checks*************************************************************************
413  BLAZE_STATIC_ASSERT( NN % IT::size == 0UL );
414  BLAZE_STATIC_ASSERT( NN >= N );
416  //**********************************************************************************************
417 };
418 //*************************************************************************************************
419 
420 
421 
422 
423 //=================================================================================================
424 //
425 // CONSTRUCTORS
426 //
427 //=================================================================================================
428 
429 //*************************************************************************************************
434 template< typename Type // Data type of the vector
435  , size_t N // Number of elements
436  , bool TF > // Transpose flag
438  : v_ () // The statically allocated vector elements
439  , size_( 0UL ) // The current size/dimension of the vector
440 {
442  for( size_t i=0UL; i<NN; ++i )
443  v_[i] = Type();
444  }
445 }
446 //*************************************************************************************************
447 
448 
449 //*************************************************************************************************
459 template< typename Type // Data type of the vector
460  , size_t N // Number of elements
461  , bool TF > // Transpose flag
463  : v_ () // The statically allocated vector elements
464  , size_( n ) // The current size/dimension of the vector
465 {
466  if( n > N )
467  throw std::invalid_argument( "Invalid size for hybrid vector" );
468 
470  for( size_t i=0UL; i<NN; ++i )
471  v_[i] = Type();
472  }
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
488 template< typename Type // Data type of the vector
489  , size_t N // Number of elements
490  , bool TF > // Transpose flag
491 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Type& init )
492  : v_ () // The statically allocated vector elements
493  , size_( n ) // The current size/dimension of the vector
494 {
495  if( n > N )
496  throw std::invalid_argument( "Invalid size for hybrid vector" );
497 
498  for( size_t i=0UL; i<n; ++i )
499  v_[i] = init;
500 
502  for( size_t i=n; i<NN; ++i )
503  v_[i] = Type();
504  }
505 }
506 //*************************************************************************************************
507 
508 
509 //*************************************************************************************************
532 template< typename Type // Data type of the vector
533  , size_t N // Number of elements
534  , bool TF > // Transpose flag
535 template< typename Other > // Data type of the initialization array
536 inline HybridVector<Type,N,TF>::HybridVector( size_t n, const Other* array )
537  : v_ () // The statically allocated vector elements
538  , size_( n ) // The current size/dimension of the vector
539 {
540  if( n > N )
541  throw std::invalid_argument( "Invalid setup of hybrid vector" );
542 
543  for( size_t i=0UL; i<n; ++i )
544  v_[i] = array[i];
545 
547  for( size_t i=n; i<NN; ++i )
548  v_[i] = Type();
549  }
550 }
551 //*************************************************************************************************
552 
553 
554 //*************************************************************************************************
572 template< typename Type // Data type of the vector
573  , size_t N // Number of elements
574  , bool TF > // Transpose flag
575 template< typename Other // Data type of the initialization array
576  , size_t M > // Number of elements of the initialization array
577 inline HybridVector<Type,N,TF>::HybridVector( const Other (&array)[M] )
578  : v_ () // The statically allocated vector elements
579  , size_( M ) // The current size/dimension of the vector
580 {
581  BLAZE_STATIC_ASSERT( M <= N );
582 
583  for( size_t i=0UL; i<M; ++i )
584  v_[i] = array[i];
585 
587  for( size_t i=M; i<NN; ++i )
588  v_[i] = Type();
589  }
590 }
591 //*************************************************************************************************
592 
593 
594 //*************************************************************************************************
601 template< typename Type // Data type of the vector
602  , size_t N // Number of elements
603  , bool TF > // Transpose flag
605  : v_ () // The statically allocated vector elements
606  , size_( v.size_ ) // The current size/dimension of the vector
607 {
608  for( size_t i=0UL; i<size_; ++i )
609  v_[i] = v.v_[i];
610 
612  for( size_t i=size_; i<NN; ++i )
613  v_[i] = Type();
614  }
615 }
616 //*************************************************************************************************
617 
618 
619 //*************************************************************************************************
629 template< typename Type // Data type of the vector
630  , size_t N // Number of elements
631  , bool TF > // Transpose flag
632 template< typename VT > // Type of the foreign vector
634  : v_ () // The statically allocated vector elements
635  , size_( (~v).size() ) // The current size/dimension of the vector
636 {
637  using blaze::assign;
638 
639  if( (~v).size() > N )
640  throw std::invalid_argument( "Invalid setup of hybrid vector" );
641 
642  for( size_t i=( IsSparseVector<VT>::value ? 0UL : size_ );
643  i<( IsVectorizable<Type>::value ? NN : size_ ); ++i ) {
644  v_[i] = Type();
645  }
646 
647  assign( *this, ~v );
648 }
649 //*************************************************************************************************
650 
651 
652 
653 
654 //=================================================================================================
655 //
656 // DATA ACCESS FUNCTIONS
657 //
658 //=================================================================================================
659 
660 //*************************************************************************************************
668 template< typename Type // Data type of the vector
669  , size_t N // Number of elements
670  , bool TF > // Transpose flag
673 {
674  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
675  return v_[index];
676 }
677 //*************************************************************************************************
678 
679 
680 //*************************************************************************************************
688 template< typename Type // Data type of the vector
689  , size_t N // Number of elements
690  , bool TF > // Transpose flag
693 {
694  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
695  return v_[index];
696 }
697 //*************************************************************************************************
698 
699 
700 //*************************************************************************************************
707 template< typename Type // Data type of the vector
708  , size_t N // Number of elements
709  , bool TF > // Transpose flag
711 {
712  return v_;
713 }
714 //*************************************************************************************************
715 
716 
717 //*************************************************************************************************
724 template< typename Type // Data type of the vector
725  , size_t N // Number of elements
726  , bool TF > // Transpose flag
728 {
729  return v_;
730 }
731 //*************************************************************************************************
732 
733 
734 //*************************************************************************************************
739 template< typename Type // Data type of the vector
740  , size_t N // Number of elements
741  , bool TF > // Transpose flag
743 {
744  return Iterator( v_ );
745 }
746 //*************************************************************************************************
747 
748 
749 //*************************************************************************************************
754 template< typename Type // Data type of the vector
755  , size_t N // Number of elements
756  , bool TF > // Transpose flag
758 {
759  return ConstIterator( v_ );
760 }
761 //*************************************************************************************************
762 
763 
764 //*************************************************************************************************
769 template< typename Type // Data type of the vector
770  , size_t N // Number of elements
771  , bool TF > // Transpose flag
773 {
774  return ConstIterator( v_ );
775 }
776 //*************************************************************************************************
777 
778 
779 //*************************************************************************************************
784 template< typename Type // Data type of the vector
785  , size_t N // Number of elements
786  , bool TF > // Transpose flag
788 {
789  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
790  return Iterator( v_ + size_ );
791 }
792 //*************************************************************************************************
793 
794 
795 //*************************************************************************************************
800 template< typename Type // Data type of the vector
801  , size_t N // Number of elements
802  , bool TF > // Transpose flag
804 {
805  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
806  return ConstIterator( v_ + size_ );
807 }
808 //*************************************************************************************************
809 
810 
811 //*************************************************************************************************
816 template< typename Type // Data type of the vector
817  , size_t N // Number of elements
818  , bool TF > // Transpose flag
820 {
821  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
822  return ConstIterator( v_ + size_ );
823 }
824 //*************************************************************************************************
825 
826 
827 
828 
829 //=================================================================================================
830 //
831 // ASSIGNMENT OPERATORS
832 //
833 //=================================================================================================
834 
835 //*************************************************************************************************
854 template< typename Type // Data type of the vector
855  , size_t N // Number of elements
856  , bool TF > // Transpose flag
857 template< typename Other // Data type of the initialization array
858  , size_t M > // Number of elements of the initialization array
860 {
861  BLAZE_STATIC_ASSERT( M <= N );
862 
863  resize( M );
864 
865  for( size_t i=0UL; i<M; ++i )
866  v_[i] = array[i];
867 
868  return *this;
869 }
870 //*************************************************************************************************
871 
872 
873 //*************************************************************************************************
879 template< typename Type // Data type of the vector
880  , size_t N // Number of elements
881  , bool TF > // Transpose flag
883 {
884  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
885 
886  for( size_t i=0UL; i<size_; ++i )
887  v_[i] = rhs;
888  return *this;
889 }
890 //*************************************************************************************************
891 
892 
893 //*************************************************************************************************
901 template< typename Type // Data type of the vector
902  , size_t N // Number of elements
903  , bool TF > // Transpose flag
905 {
906  using blaze::assign;
907 
908  BLAZE_INTERNAL_ASSERT( size_ <= N, "Invalid size detected" );
909 
910  resize( rhs.size() );
911  assign( *this, ~rhs );
912 
913  return *this;
914 }
915 //*************************************************************************************************
916 
917 
918 //*************************************************************************************************
928 template< typename Type // Data type of the vector
929  , size_t N // Number of elements
930  , bool TF > // Transpose flag
931 template< typename VT > // Type of the right-hand side vector
933 {
934  using blaze::assign;
935 
936  if( (~rhs).size() > N )
937  throw std::invalid_argument( "Invalid assignment to hybrid vector" );
938 
939  if( (~rhs).canAlias( this ) ) {
940  HybridVector tmp( ~rhs );
941  swap( tmp );
942  }
943  else {
944  resize( (~rhs).size() );
946  reset();
947  assign( *this, ~rhs );
948  }
949 
950  return *this;
951 }
952 //*************************************************************************************************
953 
954 
955 //*************************************************************************************************
965 template< typename Type // Data type of the vector
966  , size_t N // Number of elements
967  , bool TF > // Transpose flag
968 template< typename VT > // Type of the right-hand side vector
970 {
971  using blaze::addAssign;
972 
973  if( (~rhs).size() != size_ )
974  throw std::invalid_argument( "Vector sizes do not match" );
975 
976  if( (~rhs).canAlias( this ) ) {
977  typename VT::ResultType tmp( ~rhs );
978  addAssign( *this, tmp );
979  }
980  else {
981  addAssign( *this, ~rhs );
982  }
983 
984  return *this;
985 }
986 //*************************************************************************************************
987 
988 
989 //*************************************************************************************************
999 template< typename Type // Data type of the vector
1000  , size_t N // Number of elements
1001  , bool TF > // Transpose flag
1002 template< typename VT > // Type of the right-hand side vector
1004 {
1005  using blaze::subAssign;
1006 
1007  if( (~rhs).size() != size_ )
1008  throw std::invalid_argument( "Vector sizes do not match" );
1009 
1010  if( (~rhs).canAlias( this ) ) {
1011  typename VT::ResultType tmp( ~rhs );
1012  subAssign( *this, tmp );
1013  }
1014  else {
1015  subAssign( *this, ~rhs );
1016  }
1017 
1018  return *this;
1019 }
1020 //*************************************************************************************************
1021 
1022 
1023 //*************************************************************************************************
1034 template< typename Type // Data type of the vector
1035  , size_t N // Number of elements
1036  , bool TF > // Transpose flag
1037 template< typename VT > // Type of the right-hand side vector
1039 {
1040  using blaze::multAssign;
1041 
1042  if( (~rhs).size() != size_ )
1043  throw std::invalid_argument( "Vector sizes do not match" );
1044 
1045  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
1046  HybridVector tmp( *this * (~rhs) );
1047  this->operator=( tmp );
1048  }
1049  else {
1050  multAssign( *this, ~rhs );
1051  }
1052 
1053  return *this;
1054 }
1055 //*************************************************************************************************
1056 
1057 
1058 //*************************************************************************************************
1065 template< typename Type // Data type of the vector
1066  , size_t N // Number of elements
1067  , bool TF > // Transpose flag
1068 template< typename Other > // Data type of the right-hand side scalar
1069 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1071 {
1072  using blaze::assign;
1073 
1074  assign( *this, (*this) * rhs );
1075  return *this;
1076 }
1077 //*************************************************************************************************
1078 
1079 
1080 //*************************************************************************************************
1089 template< typename Type // Data type of the vector
1090  , size_t N // Number of elements
1091  , bool TF > // Transpose flag
1092 template< typename Other > // Data type of the right-hand side scalar
1093 inline typename EnableIf< IsNumeric<Other>, HybridVector<Type,N,TF> >::Type&
1095 {
1096  using blaze::assign;
1097 
1098  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1099 
1100  assign( *this, (*this) / rhs );
1101  return *this;
1102 }
1103 //*************************************************************************************************
1104 
1105 
1106 
1107 
1108 //=================================================================================================
1109 //
1110 // UTILITY FUNCTIONS
1111 //
1112 //=================================================================================================
1113 
1114 //*************************************************************************************************
1119 template< typename Type // Data type of the vector
1120  , size_t N // Number of elements
1121  , bool TF > // Transpose flag
1122 inline size_t HybridVector<Type,N,TF>::size() const
1123 {
1124  return size_;
1125 }
1126 //*************************************************************************************************
1127 
1128 
1129 //*************************************************************************************************
1134 template< typename Type // Data type of the vector
1135  , size_t N // Number of elements
1136  , bool TF > // Transpose flag
1138 {
1139  return NN;
1140 }
1141 //*************************************************************************************************
1142 
1143 
1144 //*************************************************************************************************
1152 template< typename Type // Data type of the vector
1153  , size_t N // Number of elements
1154  , bool TF > // Transpose flag
1156 {
1157  size_t nonzeros( 0 );
1158 
1159  for( size_t i=0UL; i<size_; ++i ) {
1160  if( !isDefault( v_[i] ) )
1161  ++nonzeros;
1162  }
1163 
1164  return nonzeros;
1165 }
1166 //*************************************************************************************************
1167 
1168 
1169 //*************************************************************************************************
1174 template< typename Type // Data type of the vector
1175  , size_t N // Number of elements
1176  , bool TF > // Transpose flag
1178 {
1179  using blaze::reset;
1180  for( size_t i=0UL; i<size_; ++i )
1181  reset( v_[i] );
1182 }
1183 //*************************************************************************************************
1184 
1185 
1186 //*************************************************************************************************
1193 template< typename Type // Data type of the vector
1194  , size_t N // Number of elements
1195  , bool TF > // Transpose flag
1197 {
1198  resize( 0UL );
1199 }
1200 //*************************************************************************************************
1201 
1202 
1203 //*************************************************************************************************
1234 template< typename Type // Data type of the vector
1235  , size_t N // Number of elements
1236  , bool TF > // Transpose flag
1237 inline void HybridVector<Type,N,TF>::resize( size_t n, bool preserve )
1238 {
1239  UNUSED_PARAMETER( preserve );
1240 
1241  if( n > N )
1242  throw std::invalid_argument( "Invalid size for hybrid vector" );
1243 
1244  if( IsVectorizable<Type>::value && n < size_ ) {
1245  for( size_t i=n; i<size_; ++i )
1246  v_[i] = Type();
1247  }
1248 
1249  size_ = n;
1250 }
1251 //*************************************************************************************************
1252 
1253 
1254 //*************************************************************************************************
1268 template< typename Type // Data type of the vector
1269  , size_t N // Number of elements
1270  , bool TF > // Transpose flag
1271 inline void HybridVector<Type,N,TF>::extend( size_t n, bool preserve )
1272 {
1273  UNUSED_PARAMETER( preserve );
1274  resize( size_+n );
1275 }
1276 //*************************************************************************************************
1277 
1278 
1279 //*************************************************************************************************
1285 template< typename Type // Data type of the vector
1286  , size_t N // Number of elements
1287  , bool TF > // Transpose flag
1288 template< typename Other > // Data type of the scalar value
1290 {
1291  for( size_t i=0; i<size_; ++i )
1292  v_[i] *= scalar;
1293  return *this;
1294 }
1295 //*************************************************************************************************
1296 
1297 
1298 //*************************************************************************************************
1305 template< typename Type // Data type of the vector
1306  , size_t N // Number of elements
1307  , bool TF > // Transpose flag
1308 inline void HybridVector<Type,N,TF>::swap( HybridVector& v ) /* throw() */
1309 {
1310  using std::swap;
1311 
1312  const size_t maxsize( max( size_, v.size_ ) );
1313  for( size_t i=0UL; i<maxsize; ++i )
1314  swap( v_[i], v.v_[i] );
1315  swap( size_, v.size_ );
1316 }
1317 //*************************************************************************************************
1318 
1319 
1320 
1321 
1322 //=================================================================================================
1323 //
1324 // MEMORY FUNCTIONS
1325 //
1326 //=================================================================================================
1327 
1328 //*************************************************************************************************
1338 template< typename Type // Data type of the vector
1339  , size_t N // Number of elements
1340  , bool TF > // Transpose flag
1341 inline void* HybridVector<Type,N,TF>::operator new( std::size_t size )
1342 {
1343  UNUSED_PARAMETER( size );
1344 
1345  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1346 
1347  return allocate<HybridVector>( 1UL );
1348 }
1349 //*************************************************************************************************
1350 
1351 
1352 //*************************************************************************************************
1362 template< typename Type // Data type of the vector
1363  , size_t N // Number of elements
1364  , bool TF > // Transpose flag
1365 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size )
1366 {
1367  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1368  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1369 
1370  return allocate<HybridVector>( size/sizeof(HybridVector) );
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, const std::nothrow_t& )
1389 {
1390  UNUSED_PARAMETER( size );
1391 
1392  BLAZE_INTERNAL_ASSERT( size == sizeof( HybridVector ), "Invalid number of bytes detected" );
1393 
1394  return allocate<HybridVector>( 1UL );
1395 }
1396 //*************************************************************************************************
1397 
1398 
1399 //*************************************************************************************************
1409 template< typename Type // Data type of the vector
1410  , size_t N // Number of elements
1411  , bool TF > // Transpose flag
1412 inline void* HybridVector<Type,N,TF>::operator new[]( std::size_t size, const std::nothrow_t& )
1413 {
1414  BLAZE_INTERNAL_ASSERT( size >= sizeof( HybridVector ) , "Invalid number of bytes detected" );
1415  BLAZE_INTERNAL_ASSERT( size % sizeof( HybridVector ) == 0UL, "Invalid number of bytes detected" );
1416 
1417  return allocate<HybridVector>( size/sizeof(HybridVector) );
1418 }
1419 //*************************************************************************************************
1420 
1421 
1422 //*************************************************************************************************
1428 template< typename Type // Data type of the vector
1429  , size_t N // Number of elements
1430  , bool TF > // Transpose flag
1431 inline void HybridVector<Type,N,TF>::operator delete( void* ptr )
1432 {
1433  deallocate( static_cast<HybridVector*>( ptr ) );
1434 }
1435 //*************************************************************************************************
1436 
1437 
1438 //*************************************************************************************************
1444 template< typename Type // Data type of the vector
1445  , size_t N // Number of elements
1446  , bool TF > // Transpose flag
1447 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr )
1448 {
1449  deallocate( static_cast<HybridVector*>( ptr ) );
1450 }
1451 //*************************************************************************************************
1452 
1453 
1454 //*************************************************************************************************
1460 template< typename Type // Data type of the vector
1461  , size_t N // Number of elements
1462  , bool TF > // Transpose flag
1463 inline void HybridVector<Type,N,TF>::operator delete( void* ptr, const std::nothrow_t& )
1464 {
1465  deallocate( static_cast<HybridVector*>( ptr ) );
1466 }
1467 //*************************************************************************************************
1468 
1469 
1470 //*************************************************************************************************
1476 template< typename Type // Data type of the vector
1477  , size_t N // Number of elements
1478  , bool TF > // Transpose flag
1479 inline void HybridVector<Type,N,TF>::operator delete[]( void* ptr, const std::nothrow_t& )
1480 {
1481  deallocate( static_cast<HybridVector*>( ptr ) );
1482 }
1483 //*************************************************************************************************
1484 
1485 
1486 
1487 
1488 //=================================================================================================
1489 //
1490 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1491 //
1492 //=================================================================================================
1493 
1494 //*************************************************************************************************
1504 template< typename Type // Data type of the vector
1505  , size_t N // Number of elements
1506  , bool TF > // Transpose flag
1507 template< typename Other > // Data type of the foreign expression
1508 inline bool HybridVector<Type,N,TF>::canAlias( const Other* alias ) const
1509 {
1510  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1511 }
1512 //*************************************************************************************************
1513 
1514 
1515 //*************************************************************************************************
1525 template< typename Type // Data type of the vector
1526  , size_t N // Number of elements
1527  , bool TF > // Transpose flag
1528 template< typename Other > // Data type of the foreign expression
1529 inline bool HybridVector<Type,N,TF>::isAliased( const Other* alias ) const
1530 {
1531  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1532 }
1533 //*************************************************************************************************
1534 
1535 
1536 //*************************************************************************************************
1545 template< typename Type // Data type of the vector
1546  , size_t N // Number of elements
1547  , bool TF > // Transpose flag
1549 {
1550  return true;
1551 }
1552 //*************************************************************************************************
1553 
1554 
1555 //*************************************************************************************************
1568 template< typename Type // Data type of the vector
1569  , size_t N // Number of elements
1570  , bool TF > // Transpose flag
1572  HybridVector<Type,N,TF>::load( size_t index ) const
1573 {
1574  using blaze::load;
1575 
1577 
1578  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1579  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1580  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1581 
1582  return load( &v_[index] );
1583 }
1584 //*************************************************************************************************
1585 
1586 
1587 //*************************************************************************************************
1600 template< typename Type // Data type of the vector
1601  , size_t N // Number of elements
1602  , bool TF > // Transpose flag
1604  HybridVector<Type,N,TF>::loadu( size_t index ) const
1605 {
1606  using blaze::loadu;
1607 
1609 
1610  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1611  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1612 
1613  return loadu( &v_[index] );
1614 }
1615 //*************************************************************************************************
1616 
1617 
1618 //*************************************************************************************************
1632 template< typename Type // Data type of the vector
1633  , size_t N // Number of elements
1634  , bool TF > // Transpose flag
1635 inline void HybridVector<Type,N,TF>::store( size_t index, const IntrinsicType& value )
1636 {
1637  using blaze::store;
1638 
1640 
1641  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1642  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1643  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1644 
1645  store( &v_[index], value );
1646 }
1647 //*************************************************************************************************
1648 
1649 
1650 //*************************************************************************************************
1664 template< typename Type // Data type of the vector
1665  , size_t N // Number of elements
1666  , bool TF > // Transpose flag
1667 inline void HybridVector<Type,N,TF>::storeu( size_t index, const IntrinsicType& value )
1668 {
1669  using blaze::storeu;
1670 
1672 
1673  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1674  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1675 
1676  storeu( &v_[index], value );
1677 }
1678 //*************************************************************************************************
1679 
1680 
1681 //*************************************************************************************************
1695 template< typename Type // Data type of the vector
1696  , size_t N // Number of elements
1697  , bool TF > // Transpose flag
1698 inline void HybridVector<Type,N,TF>::stream( size_t index, const IntrinsicType& value )
1699 {
1700  using blaze::stream;
1701 
1703 
1704  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1705  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1706  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid vector access index" );
1707 
1708  stream( &v_[index], value );
1709 }
1710 //*************************************************************************************************
1711 
1712 
1713 //*************************************************************************************************
1724 template< typename Type // Data type of the vector
1725  , size_t N // Number of elements
1726  , bool TF > // Transpose flag
1727 template< typename VT > // Type of the right-hand side dense vector
1728 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1730 {
1731  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1732 
1733  for( size_t i=0UL; i<size_; ++i )
1734  v_[i] = (~rhs)[i];
1735 }
1736 //*************************************************************************************************
1737 
1738 
1739 //*************************************************************************************************
1750 template< typename Type // Data type of the vector
1751  , size_t N // Number of elements
1752  , bool TF > // Transpose flag
1753 template< typename VT > // Type of the right-hand side dense vector
1754 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1756 {
1757  using blaze::store;
1758 
1759  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1760 
1762 
1763  for( size_t i=0UL; i<size_; i+=IT::size ) {
1764  store( v_+i, (~rhs).load(i) );
1765  }
1766 }
1767 //*************************************************************************************************
1768 
1769 
1770 //*************************************************************************************************
1781 template< typename Type // Data type of the vector
1782  , size_t N // Number of elements
1783  , bool TF > // Transpose flag
1784 template< typename VT > // Type of the right-hand side sparse vector
1786 {
1787  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1788 
1789  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1790  v_[element->index()] = element->value();
1791 }
1792 //*************************************************************************************************
1793 
1794 
1795 //*************************************************************************************************
1806 template< typename Type // Data type of the vector
1807  , size_t N // Number of elements
1808  , bool TF > // Transpose flag
1809 template< typename VT > // Type of the right-hand side dense vector
1810 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1812 {
1813  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1814 
1815  for( size_t i=0UL; i<size_; ++i )
1816  v_[i] += (~rhs)[i];
1817 }
1818 //*************************************************************************************************
1819 
1820 
1821 //*************************************************************************************************
1832 template< typename Type // Data type of the vector
1833  , size_t N // Number of elements
1834  , bool TF > // Transpose flag
1835 template< typename VT > // Type of the right-hand side dense vector
1836 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1838 {
1839  using blaze::load;
1840  using blaze::store;
1841 
1842  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1843 
1845 
1846  for( size_t i=0UL; i<size_; i+=IT::size ) {
1847  store( v_+i, load( v_+i ) + (~rhs).load(i) );
1848  }
1849 }
1850 //*************************************************************************************************
1851 
1852 
1853 //*************************************************************************************************
1864 template< typename Type // Data type of the vector
1865  , size_t N // Number of elements
1866  , bool TF > // Transpose flag
1867 template< typename VT > // Type of the right-hand side sparse vector
1869 {
1870  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1871 
1872  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1873  v_[element->index()] += element->value();
1874 }
1875 //*************************************************************************************************
1876 
1877 
1878 //*************************************************************************************************
1889 template< typename Type // Data type of the vector
1890  , size_t N // Number of elements
1891  , bool TF > // Transpose flag
1892 template< typename VT > // Type of the right-hand side dense vector
1893 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1895 {
1896  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1897 
1898  for( size_t i=0UL; i<size_; ++i )
1899  v_[i] -= (~rhs)[i];
1900 }
1901 //*************************************************************************************************
1902 
1903 
1904 //*************************************************************************************************
1915 template< typename Type // Data type of the vector
1916  , size_t N // Number of elements
1917  , bool TF > // Transpose flag
1918 template< typename VT > // Type of the right-hand side dense vector
1919 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1921 {
1922  using blaze::load;
1923  using blaze::store;
1924 
1925  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1926 
1928 
1929  for( size_t i=0UL; i<size_; i+=IT::size ) {
1930  store( v_+i, load( v_+i ) - (~rhs).load(i) );
1931  }
1932 }
1933 //*************************************************************************************************
1934 
1935 
1936 //*************************************************************************************************
1947 template< typename Type // Data type of the vector
1948  , size_t N // Number of elements
1949  , bool TF > // Transpose flag
1950 template< typename VT > // Type of the right-hand side sparse vector
1952 {
1953  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1954 
1955  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1956  v_[element->index()] -= element->value();
1957 }
1958 //*************************************************************************************************
1959 
1960 
1961 //*************************************************************************************************
1972 template< typename Type // Data type of the vector
1973  , size_t N // Number of elements
1974  , bool TF > // Transpose flag
1975 template< typename VT > // Type of the right-hand side dense vector
1976 inline typename DisableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
1978 {
1979  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
1980 
1981  for( size_t i=0UL; i<size_; ++i )
1982  v_[i] *= (~rhs)[i];
1983 }
1984 //*************************************************************************************************
1985 
1986 
1987 //*************************************************************************************************
1998 template< typename Type // Data type of the vector
1999  , size_t N // Number of elements
2000  , bool TF > // Transpose flag
2001 template< typename VT > // Type of the right-hand side dense vector
2002 inline typename EnableIf< typename HybridVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2004 {
2005  using blaze::load;
2006  using blaze::store;
2007 
2008  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2009 
2011 
2012  for( size_t i=0UL; i<size_; i+=IT::size ) {
2013  store( v_+i, load( v_+i ) * (~rhs).load(i) );
2014  }
2015 }
2016 //*************************************************************************************************
2017 
2018 
2019 //*************************************************************************************************
2030 template< typename Type // Data type of the vector
2031  , size_t N // Number of elements
2032  , bool TF > // Transpose flag
2033 template< typename VT > // Type of the right-hand side sparse vector
2035 {
2036  BLAZE_INTERNAL_ASSERT( (~rhs).size() == size_, "Invalid vector sizes" );
2037 
2038  const HybridVector tmp( serial( *this ) );
2039 
2040  reset();
2041 
2042  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2043  v_[element->index()] = tmp[element->index()] * element->value();
2044 }
2045 //*************************************************************************************************
2046 
2047 
2048 
2049 
2050 
2051 
2052 
2053 
2054 //=================================================================================================
2055 //
2056 // UNDEFINED CLASS TEMPLATE SPECIALIZATION
2057 //
2058 //=================================================================================================
2059 
2060 //*************************************************************************************************
2068 template< typename Type // Data type of the vector
2069  , bool TF > // Transpose flag
2070 class HybridVector<Type,0UL,TF>;
2072 //*************************************************************************************************
2073 
2074 
2075 
2076 
2077 
2078 
2079 
2080 
2081 //=================================================================================================
2082 //
2083 // HYBRIDVECTOR OPERATORS
2084 //
2085 //=================================================================================================
2086 
2087 //*************************************************************************************************
2090 template< typename Type, size_t N, bool TF >
2091 inline void reset( HybridVector<Type,N,TF>& v );
2092 
2093 template< typename Type, size_t N, bool TF >
2094 inline void clear( HybridVector<Type,N,TF>& v );
2095 
2096 template< typename Type, size_t N, bool TF >
2097 inline bool isDefault( const HybridVector<Type,N,TF>& v );
2098 
2099 template< typename Type, size_t N, bool TF >
2100 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */;
2102 //*************************************************************************************************
2103 
2104 
2105 //*************************************************************************************************
2112 template< typename Type // Data type of the vector
2113  , size_t N // Number of elements
2114  , bool TF > // Transpose flag
2116 {
2117  v.reset();
2118 }
2119 //*************************************************************************************************
2120 
2121 
2122 //*************************************************************************************************
2131 template< typename Type // Data type of the vector
2132  , size_t N // Number of elements
2133  , bool TF > // Transpose flag
2135 {
2136  v.clear();
2137 }
2138 //*************************************************************************************************
2139 
2140 
2141 //*************************************************************************************************
2159 template< typename Type // Data type of the vector
2160  , size_t N // Number of elements
2161  , bool TF > // Transpose flag
2162 inline bool isDefault( const HybridVector<Type,N,TF>& v )
2163 {
2164  for( size_t i=0UL; i<v.size(); ++i )
2165  if( !isDefault( v[i] ) ) return false;
2166  return true;
2167 }
2168 //*************************************************************************************************
2169 
2170 
2171 //*************************************************************************************************
2180 template< typename Type // Data type of the vector
2181  , size_t N // Number of elements
2182  , bool TF > // Transpose flag
2183 inline void swap( HybridVector<Type,N,TF>& a, HybridVector<Type,N,TF>& b ) /* throw() */
2184 {
2185  a.swap( b );
2186 }
2187 //*************************************************************************************************
2188 
2189 
2190 
2191 
2192 //=================================================================================================
2193 //
2194 // ADDTRAIT SPECIALIZATIONS
2195 //
2196 //=================================================================================================
2197 
2198 //*************************************************************************************************
2200 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2201 struct AddTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2202 {
2203  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2204 };
2205 
2206 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2207 struct AddTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2208 {
2209  typedef StaticVector< typename AddTrait<T1,T2>::Type, M, TF > Type;
2210 };
2211 
2212 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2213 struct AddTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2214 {
2215  typedef HybridVector< typename AddTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2216 };
2218 //*************************************************************************************************
2219 
2220 
2221 
2222 
2223 //=================================================================================================
2224 //
2225 // SUBTRAIT SPECIALIZATIONS
2226 //
2227 //=================================================================================================
2228 
2229 //*************************************************************************************************
2231 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2232 struct SubTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2233 {
2234  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2235 };
2236 
2237 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2238 struct SubTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2239 {
2240  typedef StaticVector< typename SubTrait<T1,T2>::Type, M, TF > Type;
2241 };
2242 
2243 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2244 struct SubTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2245 {
2246  typedef HybridVector< typename SubTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2247 };
2249 //*************************************************************************************************
2250 
2251 
2252 
2253 
2254 //=================================================================================================
2255 //
2256 // MULTTRAIT SPECIALIZATIONS
2257 //
2258 //=================================================================================================
2259 
2260 //*************************************************************************************************
2262 template< typename T1, size_t N, bool TF, typename T2 >
2263 struct MultTrait< HybridVector<T1,N,TF>, T2 >
2264 {
2265  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2267 };
2268 
2269 template< typename T1, typename T2, size_t N, bool TF >
2270 struct MultTrait< T1, HybridVector<T2,N,TF> >
2271 {
2272  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2274 };
2275 
2276 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2277 struct MultTrait< HybridVector<T1,M,TF>, StaticVector<T2,N,TF> >
2278 {
2279  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2280 };
2281 
2282 template< typename T1, size_t M, typename T2, size_t N >
2283 struct MultTrait< HybridVector<T1,M,false>, StaticVector<T2,N,true> >
2284 {
2285  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2286 };
2287 
2288 template< typename T1, size_t M, typename T2, size_t N >
2289 struct MultTrait< HybridVector<T1,M,true>, StaticVector<T2,N,false> >
2290 {
2291  typedef typename MultTrait<T1,T2>::Type Type;
2292 };
2293 
2294 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2295 struct MultTrait< StaticVector<T1,M,TF>, HybridVector<T2,N,TF> >
2296 {
2297  typedef StaticVector< typename MultTrait<T1,T2>::Type, M, TF > Type;
2298 };
2299 
2300 template< typename T1, size_t M, typename T2, size_t N >
2301 struct MultTrait< StaticVector<T1,M,false>, HybridVector<T2,N,true> >
2302 {
2303  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2304 };
2305 
2306 template< typename T1, size_t M, typename T2, size_t N >
2307 struct MultTrait< StaticVector<T1,M,true>, HybridVector<T2,N,false> >
2308 {
2309  typedef typename MultTrait<T1,T2>::Type Type;
2310 };
2311 
2312 template< typename T1, size_t M, bool TF, typename T2, size_t N >
2313 struct MultTrait< HybridVector<T1,M,TF>, HybridVector<T2,N,TF> >
2314 {
2315  typedef HybridVector< typename MultTrait<T1,T2>::Type, ( M < N )?( M ):( N ), TF > Type;
2316 };
2317 
2318 template< typename T1, size_t M, typename T2, size_t N >
2319 struct MultTrait< HybridVector<T1,M,false>, HybridVector<T2,N,true> >
2320 {
2321  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
2322 };
2323 
2324 template< typename T1, size_t M, typename T2, size_t N >
2325 struct MultTrait< HybridVector<T1,M,true>, HybridVector<T2,N,false> >
2326 {
2327  typedef typename MultTrait<T1,T2>::Type Type;
2328 };
2330 //*************************************************************************************************
2331 
2332 
2333 
2334 
2335 //=================================================================================================
2336 //
2337 // CROSSTRAIT SPECIALIZATIONS
2338 //
2339 //=================================================================================================
2340 
2341 //*************************************************************************************************
2343 template< typename T1, size_t N, typename T2 >
2344 struct CrossTrait< HybridVector<T1,N,false>, StaticVector<T2,3UL,false> >
2345 {
2346  private:
2347  typedef typename MultTrait<T1,T2>::Type T;
2348 
2349  public:
2350  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2351 };
2352 
2353 template< typename T1, typename T2, size_t N >
2354 struct CrossTrait< StaticVector<T1,3UL,false>, HybridVector<T2,N,false> >
2355 {
2356  private:
2357  typedef typename MultTrait<T1,T2>::Type T;
2358 
2359  public:
2360  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2361 };
2362 
2363 template< typename T1, size_t M, typename T2, size_t N >
2364 struct CrossTrait< HybridVector<T1,M,false>, HybridVector<T2,N,false> >
2365 {
2366  private:
2367  typedef typename MultTrait<T1,T2>::Type T;
2368 
2369  public:
2370  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2371 };
2373 //*************************************************************************************************
2374 
2375 
2376 
2377 
2378 //=================================================================================================
2379 //
2380 // DIVTRAIT SPECIALIZATIONS
2381 //
2382 //=================================================================================================
2383 
2384 //*************************************************************************************************
2386 template< typename T1, size_t N, bool TF, typename T2 >
2387 struct DivTrait< HybridVector<T1,N,TF>, T2 >
2388 {
2389  typedef HybridVector< typename DivTrait<T1,T2>::Type, N, TF > Type;
2391 };
2393 //*************************************************************************************************
2394 
2395 
2396 
2397 
2398 //=================================================================================================
2399 //
2400 // MATHTRAIT SPECIALIZATIONS
2401 //
2402 //=================================================================================================
2403 
2404 //*************************************************************************************************
2406 template< typename T1, size_t N, bool TF, typename T2 >
2407 struct MathTrait< HybridVector<T1,N,TF>, HybridVector<T2,N,TF> >
2408 {
2409  typedef StaticVector< typename MathTrait<T1,T2>::HighType, N, TF > HighType;
2410  typedef StaticVector< typename MathTrait<T1,T2>::LowType , N, TF > LowType;
2411 };
2413 //*************************************************************************************************
2414 
2415 
2416 
2417 
2418 //=================================================================================================
2419 //
2420 // SUBVECTORTRAIT SPECIALIZATIONS
2421 //
2422 //=================================================================================================
2423 
2424 //*************************************************************************************************
2426 template< typename T1, size_t N, bool TF >
2427 struct SubvectorTrait< HybridVector<T1,N,TF> >
2428 {
2429  typedef HybridVector<T1,N,TF> Type;
2430 };
2432 //*************************************************************************************************
2433 
2434 } // namespace blaze
2435 
2436 #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 bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
Constraint on the data type.
Header file for mathematical functions.
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#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
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:223
EnableIf< IsIntegral< T >, Load< T, sizeof(T)> >::Type::Type load(const T *address)
Loads a vector of integral values.
Definition: Load.h:222
void extend(size_t n, bool preserve=true)
Extending the size of the vector.
Definition: HybridVector.h:1271
Header file for the UNUSED_PARAMETER function template.
HybridVector()
The default constructor for HybridVector.
Definition: HybridVector.h:437
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:397
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: HybridVector.h:1137
HybridVector< Type, N,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: HybridVector.h:171
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1572
EnableIf< IsIntegral< T >, Loadu< T, sizeof(T)> >::Type::Type loadu(const T *address)
Loads a vector of integral values.
Definition: Loadu.h:219
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:1667
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: HybridVector.h:1548
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
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:690
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: HybridVector.h:1155
Type * Pointer
Pointer to a non-constant vector value.
Definition: HybridVector.h:178
Header file for memory allocation and deallocation functionality.
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
Constraint on the data type.
Iterator begin()
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:742
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: HybridVector.h:1604
Efficient implementation of a dynamically sized vector with static memory.The HybridVector class temp...
Definition: Forward.h:50
void deallocate(T *address)
Deallocation of memory.
Definition: Memory.h:115
const HybridVector & CompositeType
Data type for composite expression templates.
Definition: HybridVector.h:175
ConstIterator cbegin() const
Returns an iterator to the first element of the hybrid vector.
Definition: HybridVector.h:772
Header file for the DisableIf class template.
const Type * ConstPointer
Pointer to a constant vector value.
Definition: HybridVector.h:179
Header file for the multiplication trait.
ConstIterator cend() const
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:819
Header file for nested template disabiguation.
Compile time assertion.
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two sparse matrices.
Definition: CompressedMatrix.h:4605
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
#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:1122
Header file for the DenseIterator class template.
Header file for the subvector trait.
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:271
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: HybridVector.h:181
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
const Type & ConstReference
Reference to a constant vector value.
Definition: HybridVector.h:177
Type ElementType
Type of the vector elements.
Definition: HybridVector.h:172
#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:672
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:361
This ResultType
Result type for expression template evaluations.
Definition: HybridVector.h:170
void clear()
Clearing the vector.
Definition: HybridVector.h:1196
Header file for the EnableIf class template.
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:216
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: HybridVector.h:1698
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:173
void resize(size_t n, bool preserve=true)
Changing the size of the vector.
Definition: HybridVector.h:1237
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: HybridVector.h:180
Header file for the IsSparseVector type trait.
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:218
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:748
Header file for run time assertion macros.
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: HybridVector.h:159
Header file for the addition trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: HybridVector.h:174
Header file for the cross product trait.
Header file for the division trait.
void swap(DynamicMatrix< Type, SO > &a, DynamicMatrix< Type, SO > &b)
Swapping the contents of two matrices.
Definition: DynamicMatrix.h:4671
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:301
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
Header file for the reset shim.
Header file for the AlignedArray implementation.
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:331
#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:2411
Header file for the isDefault shim.
Constraint on the data type.
Pointer data()
Low-level data access to the vector elements.
Definition: HybridVector.h:710
void swap(HybridVector &v)
Swapping the contents of two hybrid vectors.
Definition: HybridVector.h:1308
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:1529
Type & Reference
Reference to a non-constant vector value.
Definition: HybridVector.h:176
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:1177
size_t size_
The current size/dimension of the vector.
Definition: HybridVector.h:403
Iterator end()
Returns an iterator just past the last element of the hybrid vector.
Definition: HybridVector.h:787
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: HybridVector.h:1508
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:2403
Header file for basic type definitions.
#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
#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:1635
HybridVector< Type, N, TF > This
Type of this HybridVector instance.
Definition: HybridVector.h:169