All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StaticVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_STATICVECTOR_H_
36 #define _BLAZE_MATH_DENSE_STATICVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <stdexcept>
48 #include <blaze/math/Forward.h>
49 #include <blaze/math/Intrinsics.h>
50 #include <blaze/math/shims/Clear.h>
64 #include <blaze/util/Assert.h>
71 #include <blaze/util/DisableIf.h>
72 #include <blaze/util/EnableIf.h>
73 #include <blaze/util/Memory.h>
75 #include <blaze/util/Template.h>
76 #include <blaze/util/Types.h>
80 #include <blaze/util/Unused.h>
81 
82 
83 namespace blaze {
84 
85 //=================================================================================================
86 //
87 // CLASS DEFINITION
88 //
89 //=================================================================================================
90 
91 //*************************************************************************************************
157 template< typename Type // Data type of the vector
158  , size_t N // Number of elements
159  , bool TF = defaultTransposeFlag > // Transpose flag
160 class StaticVector : public DenseVector< StaticVector<Type,N,TF>, TF >
161 {
162  private:
163  //**Type definitions****************************************************************************
165  //**********************************************************************************************
166 
167  //**********************************************************************************************
169  enum { NN = N + ( IT::size - ( N % IT::size ) ) % IT::size };
170  //**********************************************************************************************
171 
172  public:
173  //**Type definitions****************************************************************************
175  typedef This ResultType;
177  typedef Type ElementType;
178  typedef typename IT::Type IntrinsicType;
179  typedef const Type& ReturnType;
180  typedef const StaticVector& CompositeType;
181  typedef Type& Reference;
182  typedef const Type& ConstReference;
183  typedef Type* Pointer;
184  typedef const Type* ConstPointer;
187  //**********************************************************************************************
188 
189  //**Rebind struct definition********************************************************************
192  template< typename ET > // Data type of the other vector
193  struct Rebind {
195  };
196  //**********************************************************************************************
197 
198  //**Compilation flags***************************************************************************
200 
204  enum { vectorizable = IsVectorizable<Type>::value };
205 
207 
210  enum { smpAssignable = 0 };
211  //**********************************************************************************************
212 
213  //**Constructors********************************************************************************
216  explicit inline StaticVector();
217  explicit inline StaticVector( const Type& init );
218  template< typename Other > explicit inline StaticVector( size_t n, const Other* array );
219 
220  template< typename Other >
221  explicit inline StaticVector( const Other (&array)[N] );
222 
223  inline StaticVector( const StaticVector& v );
224  template< typename Other > inline StaticVector( const StaticVector<Other,N,TF>& v );
225  template< typename VT > inline StaticVector( const Vector<VT,TF>& v );
226 
227  inline StaticVector( const Type& v1, const Type& v2 );
228  inline StaticVector( const Type& v1, const Type& v2, const Type& v3 );
229  inline StaticVector( const Type& v1, const Type& v2, const Type& v3, const Type& v4 );
230  inline StaticVector( const Type& v1, const Type& v2, const Type& v3,
231  const Type& v4, const Type& v5 );
232  inline StaticVector( const Type& v1, const Type& v2, const Type& v3,
233  const Type& v4, const Type& v5, const Type& v6 );
235  //**********************************************************************************************
236 
237  //**Destructor**********************************************************************************
238  // No explicitly declared destructor.
239  //**********************************************************************************************
240 
241  //**Data access functions***********************************************************************
244  inline Reference operator[]( size_t index );
245  inline ConstReference operator[]( size_t index ) const;
246  inline Pointer data ();
247  inline ConstPointer data () const;
248  inline Iterator begin ();
249  inline ConstIterator begin () const;
250  inline ConstIterator cbegin() const;
251  inline Iterator end ();
252  inline ConstIterator end () const;
253  inline ConstIterator cend () const;
255  //**********************************************************************************************
256 
257  //**Assignment operators************************************************************************
260  template< typename Other >
261  inline StaticVector& operator=( const Other (&array)[N] );
262 
263  inline StaticVector& operator= ( const Type& rhs );
264  inline StaticVector& operator= ( const StaticVector& rhs );
265  template< typename Other > inline StaticVector& operator= ( const StaticVector<Other,N,TF>& rhs );
266  template< typename VT > inline StaticVector& operator= ( const Vector<VT,TF>& rhs );
267  template< typename VT > inline StaticVector& operator+=( const Vector<VT,TF>& rhs );
268  template< typename VT > inline StaticVector& operator-=( const Vector<VT,TF>& rhs );
269  template< typename VT > inline StaticVector& operator*=( const Vector<VT,TF>& rhs );
270 
271  template< typename Other >
272  inline typename EnableIf< IsNumeric<Other>, StaticVector >::Type&
273  operator*=( Other rhs );
274 
275  template< typename Other >
276  inline typename EnableIf< IsNumeric<Other>, StaticVector >::Type&
277  operator/=( Other rhs );
279  //**********************************************************************************************
280 
281  //**Utility functions***************************************************************************
284  inline size_t size() const;
285  inline size_t capacity() const;
286  inline size_t nonZeros() const;
287  inline void reset();
288  template< typename Other > inline StaticVector& scale( const Other& scalar );
289  inline void swap( StaticVector& v ) /* throw() */;
291  //**********************************************************************************************
292 
293  //**Memory functions****************************************************************************
296  static inline void* operator new ( std::size_t size );
297  static inline void* operator new[]( std::size_t size );
298  static inline void* operator new ( std::size_t size, const std::nothrow_t& );
299  static inline void* operator new[]( std::size_t size, const std::nothrow_t& );
300 
301  static inline void operator delete ( void* ptr );
302  static inline void operator delete[]( void* ptr );
303  static inline void operator delete ( void* ptr, const std::nothrow_t& );
304  static inline void operator delete[]( void* ptr, const std::nothrow_t& );
306  //**********************************************************************************************
307 
308  private:
309  //**********************************************************************************************
311  template< typename VT >
313  struct VectorizedAssign {
314  enum { value = vectorizable && VT::vectorizable &&
315  IsSame<Type,typename VT::ElementType>::value };
316  };
318  //**********************************************************************************************
319 
320  //**********************************************************************************************
322  template< typename VT >
324  struct VectorizedAddAssign {
325  enum { value = vectorizable && VT::vectorizable &&
326  IsSame<Type,typename VT::ElementType>::value &&
327  IntrinsicTrait<Type>::addition };
328  };
330  //**********************************************************************************************
331 
332  //**********************************************************************************************
334  template< typename VT >
336  struct VectorizedSubAssign {
337  enum { value = vectorizable && VT::vectorizable &&
338  IsSame<Type,typename VT::ElementType>::value &&
339  IntrinsicTrait<Type>::subtraction };
340  };
342  //**********************************************************************************************
343 
344  //**********************************************************************************************
346  template< typename VT >
348  struct VectorizedMultAssign {
349  enum { value = vectorizable && VT::vectorizable &&
350  IsSame<Type,typename VT::ElementType>::value &&
351  IntrinsicTrait<Type>::multiplication };
352  };
354  //**********************************************************************************************
355 
356  public:
357  //**Expression template evaluation functions****************************************************
360  template< typename Other > inline bool canAlias ( const Other* alias ) const;
361  template< typename Other > inline bool isAliased( const Other* alias ) const;
362 
363  inline bool isAligned() const;
364 
365  inline IntrinsicType load ( size_t index ) const;
366  inline IntrinsicType loadu ( size_t index ) const;
367  inline void store ( size_t index, const IntrinsicType& value );
368  inline void storeu( size_t index, const IntrinsicType& value );
369  inline void stream( size_t index, const IntrinsicType& value );
370 
371  template< typename VT >
372  inline typename DisableIf< VectorizedAssign<VT> >::Type
373  assign( const DenseVector<VT,TF>& rhs );
374 
375  template< typename VT >
376  inline typename EnableIf< VectorizedAssign<VT> >::Type
377  assign( const DenseVector<VT,TF>& rhs );
378 
379  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
380 
381  template< typename VT >
382  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
383  addAssign( const DenseVector<VT,TF>& rhs );
384 
385  template< typename VT >
386  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
387  addAssign( const DenseVector<VT,TF>& rhs );
388 
389  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
390 
391  template< typename VT >
392  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
393  subAssign( const DenseVector<VT,TF>& rhs );
394 
395  template< typename VT >
396  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
397  subAssign( const DenseVector<VT,TF>& rhs );
398 
399  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
400 
401  template< typename VT >
402  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
403  multAssign( const DenseVector<VT,TF>& rhs );
404 
405  template< typename VT >
406  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
407  multAssign( const DenseVector<VT,TF>& rhs );
408 
409  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
411  //**********************************************************************************************
412 
413  private:
414  //**Member variables****************************************************************************
418 
424  //**********************************************************************************************
425 
426  //**Compile time checks*************************************************************************
432  BLAZE_STATIC_ASSERT( NN % IT::size == 0UL );
433  BLAZE_STATIC_ASSERT( NN >= N );
435  //**********************************************************************************************
436 };
437 //*************************************************************************************************
438 
439 
440 
441 
442 //=================================================================================================
443 //
444 // CONSTRUCTORS
445 //
446 //=================================================================================================
447 
448 //*************************************************************************************************
453 template< typename Type // Data type of the vector
454  , size_t N // Number of elements
455  , bool TF > // Transpose flag
457  : v_() // The statically allocated vector elements
458 {
460 
461  if( IsNumeric<Type>::value ) {
462  for( size_t i=0UL; i<NN; ++i )
463  v_[i] = Type();
464  }
465 }
466 //*************************************************************************************************
467 
468 
469 //*************************************************************************************************
474 template< typename Type // Data type of the vector
475  , size_t N // Number of elements
476  , bool TF > // Transpose flag
477 inline StaticVector<Type,N,TF>::StaticVector( const Type& init )
478  : v_() // The statically allocated vector elements
479 {
481 
482  for( size_t i=0UL; i<N; ++i )
483  v_[i] = init;
484 
485  for( size_t i=N; i<NN; ++i )
486  v_[i] = Type();
487 }
488 //*************************************************************************************************
489 
490 
491 //*************************************************************************************************
513 template< typename Type // Data type of the vector
514  , size_t N // Number of elements
515  , bool TF > // Transpose flag
516 template< typename Other > // Data type of the initialization array
517 inline StaticVector<Type,N,TF>::StaticVector( size_t n, const Other* array )
518  : v_() // The statically allocated vector elements
519 {
521 
522  if( n > N )
523  throw std::invalid_argument( "Invalid setup of static vector" );
524 
525  for( size_t i=0UL; i<n; ++i )
526  v_[i] = array[i];
527 
528  if( IsNumeric<Type>::value ) {
529  for( size_t i=n; i<NN; ++i )
530  v_[i] = Type();
531  }
532 }
533 //*************************************************************************************************
534 
535 
536 //*************************************************************************************************
552 template< typename Type // Data type of the vector
553  , size_t N // Number of elements
554  , bool TF > // Transpose flag
555 template< typename Other > // Data type of the initialization array
556 inline StaticVector<Type,N,TF>::StaticVector( const Other (&array)[N] )
557  : v_() // The statically allocated vector elements
558 {
560 
561  for( size_t i=0UL; i<N; ++i )
562  v_[i] = array[i];
563 
564  for( size_t i=N; i<NN; ++i )
565  v_[i] = Type();
566 }
567 //*************************************************************************************************
568 
569 
570 //*************************************************************************************************
577 template< typename Type // Data type of the vector
578  , size_t N // Number of elements
579  , bool TF > // Transpose flag
581  : v_() // The statically allocated vector elements
582 {
584 
585  for( size_t i=0UL; i<NN; ++i )
586  v_[i] = v.v_[i];
587 }
588 //*************************************************************************************************
589 
590 
591 //*************************************************************************************************
596 template< typename Type // Data type of the vector
597  , size_t N // Number of elements
598  , bool TF > // Transpose flag
599 template< typename Other > // Data type of the foreign vector
601  : v_() // The statically allocated vector elements
602 {
604 
605  for( size_t i=0UL; i<N; ++i )
606  v_[i] = v[i];
607 
608  for( size_t i=N; i<NN; ++i )
609  v_[i] = Type();
610 }
611 //*************************************************************************************************
612 
613 
614 //*************************************************************************************************
624 template< typename Type // Data type of the vector
625  , size_t N // Number of elements
626  , bool TF > // Transpose flag
627 template< typename VT > // Type of the foreign vector
629  : v_() // The statically allocated vector elements
630 {
631  using blaze::assign;
632 
634 
635  if( (~v).size() != N )
636  throw std::invalid_argument( "Invalid setup of static vector" );
637 
638  for( size_t i=( IsSparseVector<VT>::value ? 0UL : N ); i<NN; ++i ) {
639  v_[i] = Type();
640  }
641 
642  assign( *this, ~v );
643 }
644 //*************************************************************************************************
645 
646 
647 //*************************************************************************************************
659 template< typename Type // Data type of the vector
660  , size_t N // Number of elements
661  , bool TF > // Transpose flag
662 inline StaticVector<Type,N,TF>::StaticVector( const Type& v1, const Type& v2 )
663  : v_() // The statically allocated vector elements
664 {
665  BLAZE_STATIC_ASSERT( N == 2UL );
667 
668  v_[0UL] = v1;
669  v_[1UL] = v2;
670 
671  for( size_t i=N; i<NN; ++i )
672  v_[i] = Type();
673 }
674 //*************************************************************************************************
675 
676 
677 //*************************************************************************************************
690 template< typename Type // Data type of the vector
691  , size_t N // Number of elements
692  , bool TF > // Transpose flag
693 inline StaticVector<Type,N,TF>::StaticVector( const Type& v1, const Type& v2, const Type& v3 )
694  : v_() // The statically allocated vector elements
695 {
696  BLAZE_STATIC_ASSERT( N == 3UL );
698 
699  v_[0UL] = v1;
700  v_[1UL] = v2;
701  v_[2UL] = v3;
702 
703  for( size_t i=N; i<NN; ++i )
704  v_[i] = Type();
705 }
706 //*************************************************************************************************
707 
708 
709 //*************************************************************************************************
723 template< typename Type // Data type of the vector
724  , size_t N // Number of elements
725  , bool TF > // Transpose flag
726 inline StaticVector<Type,N,TF>::StaticVector( const Type& v1, const Type& v2,
727  const Type& v3, const Type& v4 )
728  : v_() // The statically allocated vector elements
729 {
730  BLAZE_STATIC_ASSERT( N == 4UL );
732 
733  v_[0UL] = v1;
734  v_[1UL] = v2;
735  v_[2UL] = v3;
736  v_[3UL] = v4;
737 
738  for( size_t i=N; i<NN; ++i )
739  v_[i] = Type();
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
759 template< typename Type // Data type of the vector
760  , size_t N // Number of elements
761  , bool TF > // Transpose flag
762 inline StaticVector<Type,N,TF>::StaticVector( const Type& v1, const Type& v2, const Type& v3,
763  const Type& v4, const Type& v5 )
764  : v_() // The statically allocated vector elements
765 {
766  BLAZE_STATIC_ASSERT( N == 5UL );
768 
769  v_[0UL] = v1;
770  v_[1UL] = v2;
771  v_[2UL] = v3;
772  v_[3UL] = v4;
773  v_[4UL] = v5;
774 
775  for( size_t i=N; i<NN; ++i )
776  v_[i] = Type();
777 }
778 //*************************************************************************************************
779 
780 
781 //*************************************************************************************************
797 template< typename Type // Data type of the vector
798  , size_t N // Number of elements
799  , bool TF > // Transpose flag
800 inline StaticVector<Type,N,TF>::StaticVector( const Type& v1, const Type& v2, const Type& v3,
801  const Type& v4, const Type& v5, const Type& v6 )
802  : v_() // The statically allocated vector elements
803 {
804  BLAZE_STATIC_ASSERT( N == 6UL );
806 
807  v_[0UL] = v1;
808  v_[1UL] = v2;
809  v_[2UL] = v3;
810  v_[3UL] = v4;
811  v_[4UL] = v5;
812  v_[5UL] = v6;
813 
814  for( size_t i=N; i<NN; ++i )
815  v_[i] = Type();
816 }
817 //*************************************************************************************************
818 
819 
820 
821 
822 //=================================================================================================
823 //
824 // DATA ACCESS FUNCTIONS
825 //
826 //=================================================================================================
827 
828 //*************************************************************************************************
836 template< typename Type // Data type of the vector
837  , size_t N // Number of elements
838  , bool TF > // Transpose flag
841 {
842  BLAZE_USER_ASSERT( index < N, "Invalid vector access index" );
843  return v_[index];
844 }
845 //*************************************************************************************************
846 
847 
848 //*************************************************************************************************
856 template< typename Type // Data type of the vector
857  , size_t N // Number of elements
858  , bool TF > // Transpose flag
861 {
862  BLAZE_USER_ASSERT( index < N, "Invalid vector access index" );
863  return v_[index];
864 }
865 //*************************************************************************************************
866 
867 
868 //*************************************************************************************************
875 template< typename Type // Data type of the vector
876  , size_t N // Number of elements
877  , bool TF > // Transpose flag
879 {
880  return v_;
881 }
882 //*************************************************************************************************
883 
884 
885 //*************************************************************************************************
892 template< typename Type // Data type of the vector
893  , size_t N // Number of elements
894  , bool TF > // Transpose flag
896 {
897  return v_;
898 }
899 //*************************************************************************************************
900 
901 
902 //*************************************************************************************************
907 template< typename Type // Data type of the vector
908  , size_t N // Number of elements
909  , bool TF > // Transpose flag
911 {
912  return Iterator( v_ );
913 }
914 //*************************************************************************************************
915 
916 
917 //*************************************************************************************************
922 template< typename Type // Data type of the vector
923  , size_t N // Number of elements
924  , bool TF > // Transpose flag
926 {
927  return ConstIterator( v_ );
928 }
929 //*************************************************************************************************
930 
931 
932 //*************************************************************************************************
937 template< typename Type // Data type of the vector
938  , size_t N // Number of elements
939  , bool TF > // Transpose flag
941 {
942  return ConstIterator( v_ );
943 }
944 //*************************************************************************************************
945 
946 
947 //*************************************************************************************************
952 template< typename Type // Data type of the vector
953  , size_t N // Number of elements
954  , bool TF > // Transpose flag
956 {
957  return Iterator( v_ + N );
958 }
959 //*************************************************************************************************
960 
961 
962 //*************************************************************************************************
967 template< typename Type // Data type of the vector
968  , size_t N // Number of elements
969  , bool TF > // Transpose flag
971 {
972  return ConstIterator( v_ + N );
973 }
974 //*************************************************************************************************
975 
976 
977 //*************************************************************************************************
982 template< typename Type // Data type of the vector
983  , size_t N // Number of elements
984  , bool TF > // Transpose flag
986 {
987  return ConstIterator( v_ + N );
988 }
989 //*************************************************************************************************
990 
991 
992 
993 
994 //=================================================================================================
995 //
996 // ASSIGNMENT OPERATORS
997 //
998 //=================================================================================================
999 
1000 //*************************************************************************************************
1017 template< typename Type // Data type of the vector
1018  , size_t N // Number of elements
1019  , bool TF > // Transpose flag
1020 template< typename Other > // Data type of the initialization array
1022 {
1023  for( size_t i=0UL; i<N; ++i )
1024  v_[i] = array[i];
1025  return *this;
1026 }
1027 //*************************************************************************************************
1028 
1029 
1030 //*************************************************************************************************
1036 template< typename Type // Data type of the vector
1037  , size_t N // Number of elements
1038  , bool TF > // Transpose flag
1040 {
1041  for( size_t i=0UL; i<N; ++i )
1042  v_[i] = rhs;
1043  return *this;
1044 }
1045 //*************************************************************************************************
1046 
1047 
1048 //*************************************************************************************************
1056 template< typename Type // Data type of the vector
1057  , size_t N // Number of elements
1058  , bool TF > // Transpose flag
1060 {
1061  using blaze::assign;
1062 
1063  assign( *this, ~rhs );
1064  return *this;
1065 }
1066 //*************************************************************************************************
1067 
1068 
1069 //*************************************************************************************************
1075 template< typename Type // Data type of the vector
1076  , size_t N // Number of elements
1077  , bool TF > // Transpose flag
1078 template< typename Other > // Data type of the foreign vector
1080 {
1081  using blaze::assign;
1082 
1083  assign( *this, ~rhs );
1084  return *this;
1085 }
1086 //*************************************************************************************************
1087 
1088 
1089 //*************************************************************************************************
1099 template< typename Type // Data type of the vector
1100  , size_t N // Number of elements
1101  , bool TF > // Transpose flag
1102 template< typename VT > // Type of the right-hand side vector
1104 {
1105  using blaze::assign;
1106 
1107  if( (~rhs).size() != N )
1108  throw std::invalid_argument( "Invalid assignment to static vector" );
1109 
1110  if( (~rhs).canAlias( this ) ) {
1111  StaticVector tmp( ~rhs );
1112  swap( tmp );
1113  }
1114  else {
1116  reset();
1117  assign( *this, ~rhs );
1118  }
1119 
1120  return *this;
1121 }
1122 //*************************************************************************************************
1123 
1124 
1125 //*************************************************************************************************
1135 template< typename Type // Data type of the vector
1136  , size_t N // Number of elements
1137  , bool TF > // Transpose flag
1138 template< typename VT > // Type of the right-hand side vector
1140 {
1141  using blaze::addAssign;
1142 
1143  if( (~rhs).size() != N )
1144  throw std::invalid_argument( "Vector sizes do not match" );
1145 
1146  if( (~rhs).canAlias( this ) ) {
1147  StaticVector tmp( ~rhs );
1148  addAssign( *this, tmp );
1149  }
1150  else {
1151  addAssign( *this, ~rhs );
1152  }
1153 
1154  return *this;
1155 }
1156 //*************************************************************************************************
1157 
1158 
1159 //*************************************************************************************************
1169 template< typename Type // Data type of the vector
1170  , size_t N // Number of elements
1171  , bool TF > // Transpose flag
1172 template< typename VT > // Type of the right-hand side vector
1174 {
1175  using blaze::subAssign;
1176 
1177  if( (~rhs).size() != N )
1178  throw std::invalid_argument( "Vector sizes do not match" );
1179 
1180  if( (~rhs).canAlias( this ) ) {
1181  StaticVector tmp( ~rhs );
1182  subAssign( *this, tmp );
1183  }
1184  else {
1185  subAssign( *this, ~rhs );
1186  }
1187 
1188  return *this;
1189 }
1190 //*************************************************************************************************
1191 
1192 
1193 //*************************************************************************************************
1204 template< typename Type // Data type of the vector
1205  , size_t N // Number of elements
1206  , bool TF > // Transpose flag
1207 template< typename VT > // Type of the right-hand side vector
1209 {
1210  using blaze::multAssign;
1211 
1212  if( (~rhs).size() != N )
1213  throw std::invalid_argument( "Vector sizes do not match" );
1214 
1215  if( (~rhs).canAlias( this ) || IsSparseVector<VT>::value ) {
1216  StaticVector tmp( *this * (~rhs) );
1217  this->operator=( tmp );
1218  }
1219  else {
1220  multAssign( *this, ~rhs );
1221  }
1222 
1223  return *this;
1224 }
1225 //*************************************************************************************************
1226 
1227 
1228 //*************************************************************************************************
1235 template< typename Type // Data type of the vector
1236  , size_t N // Number of elements
1237  , bool TF > // Transpose flag
1238 template< typename Other > // Data type of the right-hand side scalar
1239 inline typename EnableIf< IsNumeric<Other>, StaticVector<Type,N,TF> >::Type&
1241 {
1242  using blaze::assign;
1243 
1244  assign( *this, (*this) * rhs );
1245  return *this;
1246 }
1247 //*************************************************************************************************
1248 
1249 
1250 //*************************************************************************************************
1259 template< typename Type // Data type of the vector
1260  , size_t N // Number of elements
1261  , bool TF > // Transpose flag
1262 template< typename Other > // Data type of the right-hand side scalar
1263 inline typename EnableIf< IsNumeric<Other>, StaticVector<Type,N,TF> >::Type&
1265 {
1266  using blaze::assign;
1267 
1268  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1269 
1270  assign( *this, (*this) / rhs );
1271  return *this;
1272 }
1273 //*************************************************************************************************
1274 
1275 
1276 
1277 
1278 //=================================================================================================
1279 //
1280 // UTILITY FUNCTIONS
1281 //
1282 //=================================================================================================
1283 
1284 //*************************************************************************************************
1289 template< typename Type // Data type of the vector
1290  , size_t N // Number of elements
1291  , bool TF > // Transpose flag
1292 inline size_t StaticVector<Type,N,TF>::size() const
1293 {
1294  return N;
1295 }
1296 //*************************************************************************************************
1297 
1298 
1299 //*************************************************************************************************
1304 template< typename Type // Data type of the vector
1305  , size_t N // Number of elements
1306  , bool TF > // Transpose flag
1308 {
1309  return NN;
1310 }
1311 //*************************************************************************************************
1312 
1313 
1314 //*************************************************************************************************
1322 template< typename Type // Data type of the vector
1323  , size_t N // Number of elements
1324  , bool TF > // Transpose flag
1326 {
1327  size_t nonzeros( 0 );
1328 
1329  for( size_t i=0UL; i<N; ++i ) {
1330  if( !isDefault( v_[i] ) )
1331  ++nonzeros;
1332  }
1333 
1334  return nonzeros;
1335 }
1336 //*************************************************************************************************
1337 
1338 
1339 //*************************************************************************************************
1344 template< typename Type // Data type of the vector
1345  , size_t N // Number of elements
1346  , bool TF > // Transpose flag
1348 {
1349  using blaze::clear;
1350  for( size_t i=0UL; i<N; ++i )
1351  clear( v_[i] );
1352 }
1353 //*************************************************************************************************
1354 
1355 
1356 //*************************************************************************************************
1362 template< typename Type // Data type of the vector
1363  , size_t N // Number of elements
1364  , bool TF > // Transpose flag
1365 template< typename Other > // Data type of the scalar value
1367 {
1368  for( size_t i=0; i<N; ++i )
1369  v_[i] *= scalar;
1370  return *this;
1371 }
1372 //*************************************************************************************************
1373 
1374 
1375 //*************************************************************************************************
1382 template< typename Type // Data type of the vector
1383  , size_t N // Number of elements
1384  , bool TF > // Transpose flag
1385 inline void StaticVector<Type,N,TF>::swap( StaticVector& v ) /* throw() */
1386 {
1387  using std::swap;
1388 
1389  for( size_t i=0UL; i<N; ++i )
1390  swap( v_[i], v.v_[i] );
1391 }
1392 //*************************************************************************************************
1393 
1394 
1395 
1396 
1397 //=================================================================================================
1398 //
1399 // MEMORY FUNCTIONS
1400 //
1401 //=================================================================================================
1402 
1403 //*************************************************************************************************
1413 template< typename Type // Data type of the vector
1414  , size_t N // Number of elements
1415  , bool TF > // Transpose flag
1416 inline void* StaticVector<Type,N,TF>::operator new( std::size_t size )
1417 {
1419 
1420  BLAZE_INTERNAL_ASSERT( size == sizeof( StaticVector ), "Invalid number of bytes detected" );
1421 
1422  return allocate<StaticVector>( 1UL );
1423 }
1424 //*************************************************************************************************
1425 
1426 
1427 //*************************************************************************************************
1437 template< typename Type // Data type of the vector
1438  , size_t N // Number of elements
1439  , bool TF > // Transpose flag
1440 inline void* StaticVector<Type,N,TF>::operator new[]( std::size_t size )
1441 {
1442  BLAZE_INTERNAL_ASSERT( size >= sizeof( StaticVector ) , "Invalid number of bytes detected" );
1443  BLAZE_INTERNAL_ASSERT( size % sizeof( StaticVector ) == 0UL, "Invalid number of bytes detected" );
1444 
1445  return allocate<StaticVector>( size/sizeof(StaticVector) );
1446 }
1447 //*************************************************************************************************
1448 
1449 
1450 //*************************************************************************************************
1460 template< typename Type // Data type of the vector
1461  , size_t N // Number of elements
1462  , bool TF > // Transpose flag
1463 inline void* StaticVector<Type,N,TF>::operator new( std::size_t size, const std::nothrow_t& )
1464 {
1466 
1467  BLAZE_INTERNAL_ASSERT( size == sizeof( StaticVector ), "Invalid number of bytes detected" );
1468 
1469  return allocate<StaticVector>( 1UL );
1470 }
1471 //*************************************************************************************************
1472 
1473 
1474 //*************************************************************************************************
1484 template< typename Type // Data type of the vector
1485  , size_t N // Number of elements
1486  , bool TF > // Transpose flag
1487 inline void* StaticVector<Type,N,TF>::operator new[]( std::size_t size, const std::nothrow_t& )
1488 {
1489  BLAZE_INTERNAL_ASSERT( size >= sizeof( StaticVector ) , "Invalid number of bytes detected" );
1490  BLAZE_INTERNAL_ASSERT( size % sizeof( StaticVector ) == 0UL, "Invalid number of bytes detected" );
1491 
1492  return allocate<StaticVector>( size/sizeof(StaticVector) );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1503 template< typename Type // Data type of the vector
1504  , size_t N // Number of elements
1505  , bool TF > // Transpose flag
1506 inline void StaticVector<Type,N,TF>::operator delete( void* ptr )
1507 {
1508  deallocate( static_cast<StaticVector*>( ptr ) );
1509 }
1510 //*************************************************************************************************
1511 
1512 
1513 //*************************************************************************************************
1519 template< typename Type // Data type of the vector
1520  , size_t N // Number of elements
1521  , bool TF > // Transpose flag
1522 inline void StaticVector<Type,N,TF>::operator delete[]( void* ptr )
1523 {
1524  deallocate( static_cast<StaticVector*>( ptr ) );
1525 }
1526 //*************************************************************************************************
1527 
1528 
1529 //*************************************************************************************************
1535 template< typename Type // Data type of the vector
1536  , size_t N // Number of elements
1537  , bool TF > // Transpose flag
1538 inline void StaticVector<Type,N,TF>::operator delete( void* ptr, const std::nothrow_t& )
1539 {
1540  deallocate( static_cast<StaticVector*>( ptr ) );
1541 }
1542 //*************************************************************************************************
1543 
1544 
1545 //*************************************************************************************************
1551 template< typename Type // Data type of the vector
1552  , size_t N // Number of elements
1553  , bool TF > // Transpose flag
1554 inline void StaticVector<Type,N,TF>::operator delete[]( void* ptr, const std::nothrow_t& )
1555 {
1556  deallocate( static_cast<StaticVector*>( ptr ) );
1557 }
1558 //*************************************************************************************************
1559 
1560 
1561 
1562 
1563 //=================================================================================================
1564 //
1565 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1566 //
1567 //=================================================================================================
1568 
1569 //*************************************************************************************************
1579 template< typename Type // Data type of the vector
1580  , size_t N // Number of elements
1581  , bool TF > // Transpose flag
1582 template< typename Other > // Data type of the foreign expression
1583 inline bool StaticVector<Type,N,TF>::canAlias( const Other* alias ) const
1584 {
1585  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1586 }
1587 //*************************************************************************************************
1588 
1589 
1590 //*************************************************************************************************
1600 template< typename Type // Data type of the vector
1601  , size_t N // Number of elements
1602  , bool TF > // Transpose flag
1603 template< typename Other > // Data type of the foreign expression
1604 inline bool StaticVector<Type,N,TF>::isAliased( const Other* alias ) const
1605 {
1606  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1607 }
1608 //*************************************************************************************************
1609 
1610 
1611 //*************************************************************************************************
1620 template< typename Type // Data type of the vector
1621  , size_t N // Number of elements
1622  , bool TF > // Transpose flag
1624 {
1625  return true;
1626 }
1627 //*************************************************************************************************
1628 
1629 
1630 //*************************************************************************************************
1643 template< typename Type // Data type of the vector
1644  , size_t N // Number of elements
1645  , bool TF > // Transpose flag
1647  StaticVector<Type,N,TF>::load( size_t index ) const
1648 {
1649  using blaze::load;
1650 
1652 
1653  BLAZE_INTERNAL_ASSERT( index < N , "Invalid vector access index" );
1654  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1655  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL, "Invalid vector access index" );
1656 
1657  return load( &v_[index] );
1658 }
1659 //*************************************************************************************************
1660 
1661 
1662 //*************************************************************************************************
1675 template< typename Type // Data type of the vector
1676  , size_t N // Number of elements
1677  , bool TF > // Transpose flag
1679  StaticVector<Type,N,TF>::loadu( size_t index ) const
1680 {
1681  using blaze::loadu;
1682 
1684 
1685  BLAZE_INTERNAL_ASSERT( index < N , "Invalid vector access index" );
1686  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1687 
1688  return loadu( &v_[index] );
1689 }
1690 //*************************************************************************************************
1691 
1692 
1693 //*************************************************************************************************
1707 template< typename Type // Data type of the vector
1708  , size_t N // Number of elements
1709  , bool TF > // Transpose flag
1710 inline void StaticVector<Type,N,TF>::store( size_t index, const IntrinsicType& value )
1711 {
1712  using blaze::store;
1713 
1715 
1716  BLAZE_INTERNAL_ASSERT( index < N , "Invalid vector access index" );
1717  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1718  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL, "Invalid vector access index" );
1719 
1720  store( &v_[index], value );
1721 }
1722 //*************************************************************************************************
1723 
1724 
1725 //*************************************************************************************************
1739 template< typename Type // Data type of the vector
1740  , size_t N // Number of elements
1741  , bool TF > // Transpose flag
1742 inline void StaticVector<Type,N,TF>::storeu( size_t index, const IntrinsicType& value )
1743 {
1744  using blaze::storeu;
1745 
1747 
1748  BLAZE_INTERNAL_ASSERT( index < N , "Invalid vector access index" );
1749  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN, "Invalid vector access index" );
1750 
1751  storeu( &v_[index], value );
1752 }
1753 //*************************************************************************************************
1754 
1755 
1756 //*************************************************************************************************
1770 template< typename Type // Data type of the vector
1771  , size_t N // Number of elements
1772  , bool TF > // Transpose flag
1773 inline void StaticVector<Type,N,TF>::stream( size_t index, const IntrinsicType& value )
1774 {
1775  using blaze::stream;
1776 
1778 
1779  BLAZE_INTERNAL_ASSERT( index < N , "Invalid vector access index" );
1780  BLAZE_INTERNAL_ASSERT( index + IT::size <= NN , "Invalid vector access index" );
1781  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL, "Invalid vector access index" );
1782 
1783  stream( &v_[index], value );
1784 }
1785 //*************************************************************************************************
1786 
1787 
1788 //*************************************************************************************************
1799 template< typename Type // Data type of the vector
1800  , size_t N // Number of elements
1801  , bool TF > // Transpose flag
1802 template< typename VT > // Type of the right-hand side dense vector
1803 inline typename DisableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1805 {
1806  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1807 
1808  for( size_t i=0UL; i<N; ++i )
1809  v_[i] = (~rhs)[i];
1810 }
1811 //*************************************************************************************************
1812 
1813 
1814 //*************************************************************************************************
1825 template< typename Type // Data type of the vector
1826  , size_t N // Number of elements
1827  , bool TF > // Transpose flag
1828 template< typename VT > // Type of the right-hand side dense vector
1829 inline typename EnableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
1831 {
1832  using blaze::store;
1833 
1834  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1835 
1837 
1838  for( size_t i=0UL; i<N; i+=IT::size ) {
1839  store( v_+i, (~rhs).load(i) );
1840  }
1841 }
1842 //*************************************************************************************************
1843 
1844 
1845 //*************************************************************************************************
1856 template< typename Type // Data type of the vector
1857  , size_t N // Number of elements
1858  , bool TF > // Transpose flag
1859 template< typename VT > // Type of the right-hand side sparse vector
1861 {
1862  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1863 
1864  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1865  v_[element->index()] = element->value();
1866 }
1867 //*************************************************************************************************
1868 
1869 
1870 //*************************************************************************************************
1881 template< typename Type // Data type of the vector
1882  , size_t N // Number of elements
1883  , bool TF > // Transpose flag
1884 template< typename VT > // Type of the right-hand side dense vector
1885 inline typename DisableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1887 {
1888  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1889 
1890  for( size_t i=0UL; i<N; ++i )
1891  v_[i] += (~rhs)[i];
1892 }
1893 //*************************************************************************************************
1894 
1895 
1896 //*************************************************************************************************
1907 template< typename Type // Data type of the vector
1908  , size_t N // Number of elements
1909  , bool TF > // Transpose flag
1910 template< typename VT > // Type of the right-hand side dense vector
1911 inline typename EnableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
1913 {
1914  using blaze::load;
1915  using blaze::store;
1916 
1917  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1918 
1920 
1921  for( size_t i=0UL; i<N; i+=IT::size ) {
1922  store( v_+i, load( v_+i ) + (~rhs).load(i) );
1923  }
1924 }
1925 //*************************************************************************************************
1926 
1927 
1928 //*************************************************************************************************
1939 template< typename Type // Data type of the vector
1940  , size_t N // Number of elements
1941  , bool TF > // Transpose flag
1942 template< typename VT > // Type of the right-hand side sparse vector
1944 {
1945  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1946 
1947  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
1948  v_[element->index()] += element->value();
1949 }
1950 //*************************************************************************************************
1951 
1952 
1953 //*************************************************************************************************
1964 template< typename Type // Data type of the vector
1965  , size_t N // Number of elements
1966  , bool TF > // Transpose flag
1967 template< typename VT > // Type of the right-hand side dense vector
1968 inline typename DisableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1970 {
1971  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
1972 
1973  for( size_t i=0UL; i<N; ++i )
1974  v_[i] -= (~rhs)[i];
1975 }
1976 //*************************************************************************************************
1977 
1978 
1979 //*************************************************************************************************
1990 template< typename Type // Data type of the vector
1991  , size_t N // Number of elements
1992  , bool TF > // Transpose flag
1993 template< typename VT > // Type of the right-hand side dense vector
1994 inline typename EnableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
1996 {
1997  using blaze::load;
1998  using blaze::store;
1999 
2000  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
2001 
2003 
2004  for( size_t i=0UL; i<N; i+=IT::size ) {
2005  store( v_+i, load( v_+i ) - (~rhs).load(i) );
2006  }
2007 }
2008 //*************************************************************************************************
2009 
2010 
2011 //*************************************************************************************************
2022 template< typename Type // Data type of the vector
2023  , size_t N // Number of elements
2024  , bool TF > // Transpose flag
2025 template< typename VT > // Type of the right-hand side sparse vector
2027 {
2028  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
2029 
2030  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2031  v_[element->index()] -= element->value();
2032 }
2033 //*************************************************************************************************
2034 
2035 
2036 //*************************************************************************************************
2047 template< typename Type // Data type of the vector
2048  , size_t N // Number of elements
2049  , bool TF > // Transpose flag
2050 template< typename VT > // Type of the right-hand side dense vector
2051 inline typename DisableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2053 {
2054  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
2055 
2056  for( size_t i=0UL; i<N; ++i )
2057  v_[i] *= (~rhs)[i];
2058 }
2059 //*************************************************************************************************
2060 
2061 
2062 //*************************************************************************************************
2073 template< typename Type // Data type of the vector
2074  , size_t N // Number of elements
2075  , bool TF > // Transpose flag
2076 template< typename VT > // Type of the right-hand side dense vector
2077 inline typename EnableIf< typename StaticVector<Type,N,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2079 {
2080  using blaze::load;
2081  using blaze::store;
2082 
2083  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
2084 
2086 
2087  for( size_t i=0UL; i<N; i+=IT::size ) {
2088  store( v_+i, load( v_+i ) * (~rhs).load(i) );
2089  }
2090 }
2091 //*************************************************************************************************
2092 
2093 
2094 //*************************************************************************************************
2105 template< typename Type // Data type of the vector
2106  , size_t N // Number of elements
2107  , bool TF > // Transpose flag
2108 template< typename VT > // Type of the right-hand side sparse vector
2110 {
2111  BLAZE_INTERNAL_ASSERT( (~rhs).size() == N, "Invalid vector sizes" );
2112 
2113  const StaticVector tmp( serial( *this ) );
2114 
2115  reset();
2116 
2117  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2118  v_[element->index()] = tmp[element->index()] * element->value();
2119 }
2120 //*************************************************************************************************
2121 
2122 
2123 
2124 
2125 
2126 
2127 
2128 
2129 //=================================================================================================
2130 //
2131 // UNDEFINED CLASS TEMPLATE SPECIALIZATION
2132 //
2133 //=================================================================================================
2134 
2135 //*************************************************************************************************
2143 template< typename Type // Data type of the vector
2144  , bool TF > // Transpose flag
2145 class StaticVector<Type,0UL,TF>;
2147 //*************************************************************************************************
2148 
2149 
2150 
2151 
2152 
2153 
2154 
2155 
2156 //=================================================================================================
2157 //
2158 // STATICVECTOR OPERATORS
2159 //
2160 //=================================================================================================
2161 
2162 //*************************************************************************************************
2165 template< typename Type, size_t N, bool TF >
2166 inline void reset( StaticVector<Type,N,TF>& v );
2167 
2168 template< typename Type, size_t N, bool TF >
2169 inline void clear( StaticVector<Type,N,TF>& v );
2170 
2171 template< typename Type, size_t N, bool TF >
2172 inline bool isDefault( const StaticVector<Type,N,TF>& v );
2173 
2174 template< typename Type, bool TF >
2176 
2177 template< typename Type, bool TF >
2179 
2180 template< typename Type, size_t N, bool TF >
2181 inline void swap( StaticVector<Type,N,TF>& a, StaticVector<Type,N,TF>& b ) /* throw() */;
2182 
2183 template< typename Type, size_t N, bool TF >
2184 inline void move( StaticVector<Type,N,TF>& dst, StaticVector<Type,N,TF>& src ) /* throw() */;
2186 //*************************************************************************************************
2187 
2188 
2189 //*************************************************************************************************
2196 template< typename Type // Data type of the vector
2197  , size_t N // Number of elements
2198  , bool TF > // Transpose flag
2200 {
2201  v.reset();
2202 }
2203 //*************************************************************************************************
2204 
2205 
2206 //*************************************************************************************************
2215 template< typename Type // Data type of the vector
2216  , size_t N // Number of elements
2217  , bool TF > // Transpose flag
2219 {
2220  v.reset();
2221 }
2222 //*************************************************************************************************
2223 
2224 
2225 //*************************************************************************************************
2243 template< typename Type // Data type of the vector
2244  , size_t N // Number of elements
2245  , bool TF > // Transpose flag
2246 inline bool isDefault( const StaticVector<Type,N,TF>& v )
2247 {
2248  for( size_t i=0UL; i<N; ++i )
2249  if( !isDefault( v[i] ) ) return false;
2250  return true;
2251 }
2252 //*************************************************************************************************
2253 
2254 
2255 //*************************************************************************************************
2266 template< typename Type // Data type of the vector
2267  , bool TF > // Transpose flag
2269 {
2270  return StaticVector<Type,2UL,TF>( -v[1UL], v[0UL] );
2271 }
2272 //*************************************************************************************************
2273 
2274 
2275 //*************************************************************************************************
2283 template< typename Type // Data type of the vector
2284  , bool TF > // Transpose flag
2286 {
2287  if( v[0] != Type() || v[1] != Type() )
2288  return StaticVector<Type,3UL,TF>( v[1UL], -v[0UL], Type() );
2289  else
2290  return StaticVector<Type,3UL,TF>( Type(), v[2UL], -v[1UL] );
2291 }
2292 //*************************************************************************************************
2293 
2294 
2295 //*************************************************************************************************
2304 template< typename Type // Data type of the vector
2305  , size_t N // Number of elements
2306  , bool TF > // Transpose flag
2307 inline void swap( StaticVector<Type,N,TF>& a, StaticVector<Type,N,TF>& b ) /* throw() */
2308 {
2309  a.swap( b );
2310 }
2311 //*************************************************************************************************
2312 
2313 
2314 //*************************************************************************************************
2323 template< typename Type // Data type of the vector
2324  , size_t N // Number of elements
2325  , bool TF > // Transpose flag
2326 inline void move( StaticVector<Type,N,TF>& dst, StaticVector<Type,N,TF>& src ) /* throw() */
2327 {
2328  dst = src;
2329 }
2330 //*************************************************************************************************
2331 
2332 
2333 
2334 
2335 //=================================================================================================
2336 //
2337 // SIZE SPECIALIZATIONS
2338 //
2339 //=================================================================================================
2340 
2341 //*************************************************************************************************
2343 template< typename T, size_t N, bool TF >
2344 struct Size< StaticVector<T,N,TF> >
2345 {
2346  static const size_t value = N;
2347 };
2349 //*************************************************************************************************
2350 
2351 
2352 
2353 
2354 //=================================================================================================
2355 //
2356 // ADDTRAIT SPECIALIZATIONS
2357 //
2358 //=================================================================================================
2359 
2360 //*************************************************************************************************
2362 template< typename T1, size_t N, bool TF, typename T2 >
2363 struct AddTrait< StaticVector<T1,N,TF>, StaticVector<T2,N,TF> >
2364 {
2365  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
2366 };
2368 //*************************************************************************************************
2369 
2370 
2371 
2372 
2373 //=================================================================================================
2374 //
2375 // SUBTRAIT SPECIALIZATIONS
2376 //
2377 //=================================================================================================
2378 
2379 //*************************************************************************************************
2381 template< typename T1, size_t N, bool TF, typename T2 >
2382 struct SubTrait< StaticVector<T1,N,TF>, StaticVector<T2,N,TF> >
2383 {
2384  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
2385 };
2387 //*************************************************************************************************
2388 
2389 
2390 
2391 
2392 //=================================================================================================
2393 //
2394 // MULTTRAIT SPECIALIZATIONS
2395 //
2396 //=================================================================================================
2397 
2398 //*************************************************************************************************
2400 template< typename T1, size_t N, bool TF, typename T2 >
2401 struct MultTrait< StaticVector<T1,N,TF>, T2 >
2402 {
2403  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2405 };
2406 
2407 template< typename T1, typename T2, size_t N, bool TF >
2408 struct MultTrait< T1, StaticVector<T2,N,TF> >
2409 {
2410  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2412 };
2413 
2414 template< typename T1, size_t N, bool TF, typename T2 >
2415 struct MultTrait< StaticVector<T1,N,TF>, StaticVector<T2,N,TF> >
2416 {
2417  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
2418 };
2419 
2420 template< typename T1, size_t M, typename T2, size_t N >
2421 struct MultTrait< StaticVector<T1,M,false>, StaticVector<T2,N,true> >
2422 {
2423  typedef StaticMatrix< typename MultTrait<T1,T2>::Type, M, N, false > Type;
2424 };
2425 
2426 template< typename T1, size_t N, typename T2 >
2427 struct MultTrait< StaticVector<T1,N,true>, StaticVector<T2,N,false> >
2428 {
2429  typedef typename MultTrait<T1,T2>::Type Type;
2430 };
2432 //*************************************************************************************************
2433 
2434 
2435 
2436 
2437 //=================================================================================================
2438 //
2439 // CROSSTRAIT SPECIALIZATIONS
2440 //
2441 //=================================================================================================
2442 
2443 //*************************************************************************************************
2445 template< typename T1, typename T2 >
2446 struct CrossTrait< StaticVector<T1,3UL,false>, StaticVector<T2,3UL,false> >
2447 {
2448  private:
2449  typedef typename MultTrait<T1,T2>::Type T;
2450 
2451  public:
2452  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
2453 };
2455 //*************************************************************************************************
2456 
2457 
2458 
2459 
2460 //=================================================================================================
2461 //
2462 // DIVTRAIT SPECIALIZATIONS
2463 //
2464 //=================================================================================================
2465 
2466 //*************************************************************************************************
2468 template< typename T1, size_t N, bool TF, typename T2 >
2469 struct DivTrait< StaticVector<T1,N,TF>, T2 >
2470 {
2471  typedef StaticVector< typename DivTrait<T1,T2>::Type, N, TF > Type;
2473 };
2475 //*************************************************************************************************
2476 
2477 
2478 
2479 
2480 //=================================================================================================
2481 //
2482 // MATHTRAIT SPECIALIZATIONS
2483 //
2484 //=================================================================================================
2485 
2486 //*************************************************************************************************
2488 template< typename T1, size_t N, bool TF, typename T2 >
2489 struct MathTrait< StaticVector<T1,N,TF>, StaticVector<T2,N,TF> >
2490 {
2491  typedef StaticVector< typename MathTrait<T1,T2>::HighType, N, TF > HighType;
2492  typedef StaticVector< typename MathTrait<T1,T2>::LowType , N, TF > LowType;
2493 };
2495 //*************************************************************************************************
2496 
2497 
2498 
2499 
2500 //=================================================================================================
2501 //
2502 // SUBVECTORTRAIT SPECIALIZATIONS
2503 //
2504 //=================================================================================================
2505 
2506 //*************************************************************************************************
2508 template< typename T1, size_t N, bool TF >
2509 struct SubvectorTrait< StaticVector<T1,N,TF> >
2510 {
2511  typedef HybridVector<T1,N,TF> Type;
2512 };
2514 //*************************************************************************************************
2515 
2516 } // namespace blaze
2517 
2518 #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
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: StaticVector.h:1647
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.
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
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the UNUSED_PARAMETER function template.
Header file for the subtraction trait.
Header file for the SparseVector base class.
Type * Pointer
Pointer to a non-constant vector value.
Definition: StaticVector.h:183
Iterator end()
Returns an iterator just past the last element of the static vector.
Definition: StaticVector.h:955
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
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
AlignedArray< Type, NN > v_
The statically allocated vector elements.
Definition: StaticVector.h:417
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.
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.
StaticVector< Type, N,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: StaticVector.h:176
#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
Type & Reference
Reference to a non-constant vector value.
Definition: StaticVector.h:181
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: StaticVector.h:1325
Header file for memory allocation and deallocation functionality.
Constraint on the data type.
Efficient implementation of a fixed-sized vector.The StaticVector class template is the representatio...
Definition: Forward.h:59
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: StaticVector.h:1623
Header file for the DisableIf class template.
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: StaticVector.h:1307
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: StaticVector.h:1583
void swap(StaticVector &v)
Swapping the contents of two static vectors.
Definition: StaticVector.h:1385
Header file for the multiplication trait.
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
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.
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
This ResultType
Result type for expression template evaluations.
Definition: StaticVector.h:175
void reset()
Reset to the default initial values.
Definition: StaticVector.h:1347
#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
ConstIterator cbegin() const
Returns an iterator to the first element of the static vector.
Definition: StaticVector.h:940
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: StaticVector.h:840
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
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: StaticVector.h:178
const StaticVector< Type, 2UL, TF > perp(const StaticVector< Type, 2UL, TF > &v)
Unary perp dot product operator for the calculation of a perpendicular vector ( ).
Definition: StaticVector.h:2268
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: StaticVector.h:1710
Header file for the EnableIf class template.
Header file for the serial shim.
Header file for the IsVectorizable type trait.
Header file for the IsNumeric type trait.
DenseIterator< Type > Iterator
Iterator over non-constant elements.
Definition: StaticVector.h:185
Header file for the IsSparseVector type trait.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:749
StaticVector()
The default constructor for StaticVector.
Definition: StaticVector.h:456
Header file for run time assertion macros.
Header file for the addition trait.
Header file for the cross product trait.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
StaticVector< ET, N, TF > Other
The type of the other StaticVector.
Definition: StaticVector.h:194
Header file for the division trait.
const Type & ReturnType
Return type for expression template evaluations.
Definition: StaticVector.h:179
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
const Type & ConstReference
Reference to a constant vector value.
Definition: StaticVector.h:182
#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
Iterator begin()
Returns an iterator to the first element of the static vector.
Definition: StaticVector.h:910
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.
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: StaticVector.h:1604
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
const StaticVector & CompositeType
Data type for composite expression templates.
Definition: StaticVector.h:180
StaticVector< Type, N, TF > This
Type of this StaticVector instance.
Definition: StaticVector.h:174
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the vector.
Definition: StaticVector.h:1773
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.
DenseIterator< const Type > ConstIterator
Iterator over constant elements.
Definition: StaticVector.h:186
const Type * ConstPointer
Pointer to a constant vector value.
Definition: StaticVector.h:184
Header file for the default transpose flag for all vectors of the Blaze library.
size_t size() const
Returns the current size/dimension of the vector.
Definition: StaticVector.h:1292
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: StaticVector.h:164
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
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
ConstIterator cend() const
Returns an iterator just past the last element of the static vector.
Definition: StaticVector.h:985
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: StaticVector.h:1679
#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
Type ElementType
Type of the vector elements.
Definition: StaticVector.h:177
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
Pointer data()
Low-level data access to the vector elements.
Definition: StaticVector.h:878
Header file for the Size 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
Rebind mechanism to obtain a StaticVector with different data/element type.
Definition: StaticVector.h:193
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the vector.
Definition: StaticVector.h:1742
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