CustomVector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_DENSE_CUSTOMVECTOR_H_
36 #define _BLAZE_MATH_DENSE_CUSTOMVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <algorithm>
44 #include <boost/smart_ptr/shared_array.hpp>
52 #include <blaze/math/Forward.h>
53 #include <blaze/math/Intrinsics.h>
54 #include <blaze/math/PaddingFlag.h>
55 #include <blaze/math/shims/Clear.h>
70 #include <blaze/system/CacheSize.h>
71 #include <blaze/system/Inline.h>
76 #include <blaze/util/Assert.h>
82 #include <blaze/util/DisableIf.h>
83 #include <blaze/util/EnableIf.h>
84 #include <blaze/util/Exception.h>
85 #include <blaze/util/Null.h>
88 #include <blaze/util/Template.h>
89 #include <blaze/util/Types.h>
94 #include <blaze/util/Unused.h>
96 
97 
98 namespace blaze {
99 
100 //=================================================================================================
101 //
102 // CLASS DEFINITION
103 //
104 //=================================================================================================
105 
106 //*************************************************************************************************
412 template< typename Type // Data type of the vector
413  , bool AF // Alignment flag
414  , bool PF // Padding flag
415  , bool TF = defaultTransposeFlag > // Transpose flag
416 class CustomVector : public DenseVector< CustomVector<Type,AF,PF,TF>, TF >
417 {
418  private:
419  //**Type definitions****************************************************************************
421  //**********************************************************************************************
422 
423  public:
424  //**Type definitions****************************************************************************
428  typedef Type ElementType;
429  typedef typename IT::Type IntrinsicType;
430  typedef const Type& ReturnType;
431  typedef const CustomVector& CompositeType;
432 
433  typedef Type& Reference;
434  typedef const Type& ConstReference;
435  typedef Type* Pointer;
436  typedef const Type* ConstPointer;
437 
440  //**********************************************************************************************
441 
442  //**Rebind struct definition********************************************************************
445  template< typename ET > // Data type of the other vector
446  struct Rebind {
448  };
449  //**********************************************************************************************
450 
451  //**Compilation flags***************************************************************************
453 
457  enum { vectorizable = IsVectorizable<Type>::value };
458 
460 
463  enum { smpAssignable = !IsSMPAssignable<Type>::value };
464  //**********************************************************************************************
465 
466  //**Constructors********************************************************************************
469  explicit inline CustomVector();
470  explicit inline CustomVector( Type* ptr, size_t n );
471  explicit inline CustomVector( Type* ptr, size_t n, size_t nn );
472 
473  template< typename Deleter >
474  explicit inline CustomVector( Type* ptr, size_t n, Deleter d );
475 
476  template< typename Deleter >
477  explicit inline CustomVector( Type* ptr, size_t n, size_t nn, Deleter d );
478 
479  inline CustomVector( const CustomVector& v );
481  //**********************************************************************************************
482 
483  //**Destructor**********************************************************************************
484  // No explicitly declared destructor.
485  //**********************************************************************************************
486 
487  //**Data access functions***********************************************************************
490  inline Reference operator[]( size_t index );
491  inline ConstReference operator[]( size_t index ) const;
492  inline Reference at( size_t index );
493  inline ConstReference at( size_t index ) const;
494  inline Pointer data ();
495  inline ConstPointer data () const;
496  inline Iterator begin ();
497  inline ConstIterator begin () const;
498  inline ConstIterator cbegin() const;
499  inline Iterator end ();
500  inline ConstIterator end () const;
501  inline ConstIterator cend () const;
503  //**********************************************************************************************
504 
505  //**Assignment operators************************************************************************
508  template< typename Other, size_t N >
509  inline CustomVector& operator=( const Other (&array)[N] );
510 
511  inline CustomVector& operator= ( const Type& rhs );
512  inline CustomVector& operator= ( const CustomVector& rhs );
513  template< typename VT > inline CustomVector& operator= ( const Vector<VT,TF>& rhs );
514  template< typename VT > inline CustomVector& operator+=( const Vector<VT,TF>& rhs );
515  template< typename VT > inline CustomVector& operator-=( const Vector<VT,TF>& rhs );
516  template< typename VT > inline CustomVector& operator*=( const Vector<VT,TF>& rhs );
517 
518  template< typename Other >
519  inline typename EnableIf< IsNumeric<Other>, CustomVector >::Type&
520  operator*=( Other rhs );
521 
522  template< typename Other >
523  inline typename EnableIf< IsNumeric<Other>, CustomVector >::Type&
524  operator/=( Other rhs );
526  //**********************************************************************************************
527 
528  //**Utility functions***************************************************************************
531  inline size_t size() const;
532  inline size_t capacity() const;
533  inline size_t nonZeros() const;
534  inline void reset();
535  inline void clear();
536  template< typename Other > inline CustomVector& scale( const Other& scalar );
537  inline void swap( CustomVector& v ) /* throw() */;
539  //**********************************************************************************************
540 
541  //**Resource management functions***************************************************************
544  inline void reset( Type* ptr, size_t n );
545  inline void reset( Type* ptr, size_t n, size_t nn );
546  template< typename Deleter > inline void reset( Type* ptr, size_t n, Deleter d );
547  template< typename Deleter > inline void reset( Type* ptr, size_t n, size_t nn, Deleter d );
549  //**********************************************************************************************
550 
551  private:
552  //**********************************************************************************************
554  template< typename VT >
556  struct VectorizedAssign {
557  enum { value = useOptimizedKernels &&
558  vectorizable && VT::vectorizable &&
559  IsSame<Type,typename VT::ElementType>::value };
560  };
562  //**********************************************************************************************
563 
564  //**********************************************************************************************
566  template< typename VT >
568  struct VectorizedAddAssign {
569  enum { value = useOptimizedKernels &&
570  vectorizable && VT::vectorizable &&
571  IsSame<Type,typename VT::ElementType>::value &&
572  IntrinsicTrait<Type>::addition };
573  };
575  //**********************************************************************************************
576 
577  //**********************************************************************************************
579  template< typename VT >
581  struct VectorizedSubAssign {
582  enum { value = useOptimizedKernels &&
583  vectorizable && VT::vectorizable &&
584  IsSame<Type,typename VT::ElementType>::value &&
585  IntrinsicTrait<Type>::subtraction };
586  };
588  //**********************************************************************************************
589 
590  //**********************************************************************************************
592  template< typename VT >
594  struct VectorizedMultAssign {
595  enum { value = useOptimizedKernels &&
596  vectorizable && VT::vectorizable &&
597  IsSame<Type,typename VT::ElementType>::value &&
598  IntrinsicTrait<Type>::multiplication };
599  };
601  //**********************************************************************************************
602 
603  public:
604  //**Expression template evaluation functions****************************************************
607  template< typename Other > inline bool canAlias ( const Other* alias ) const;
608  template< typename Other > inline bool isAliased( const Other* alias ) const;
609 
610  inline bool isAligned () const;
611  inline bool canSMPAssign() const;
612 
613  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t index ) const;
614  BLAZE_ALWAYS_INLINE IntrinsicType loada( size_t index ) const;
615  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t index ) const;
616 
617  BLAZE_ALWAYS_INLINE void store ( size_t index, const IntrinsicType& value );
618  BLAZE_ALWAYS_INLINE void storea( size_t index, const IntrinsicType& value );
619  BLAZE_ALWAYS_INLINE void storeu( size_t index, const IntrinsicType& value );
620  BLAZE_ALWAYS_INLINE void stream( size_t index, const IntrinsicType& value );
621 
622  template< typename VT >
623  inline typename DisableIf< VectorizedAssign<VT> >::Type
624  assign( const DenseVector<VT,TF>& rhs );
625 
626  template< typename VT >
627  inline typename EnableIf< VectorizedAssign<VT> >::Type
628  assign( const DenseVector<VT,TF>& rhs );
629 
630  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
631 
632  template< typename VT >
633  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
634  addAssign( const DenseVector<VT,TF>& rhs );
635 
636  template< typename VT >
637  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
638  addAssign( const DenseVector<VT,TF>& rhs );
639 
640  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
641 
642  template< typename VT >
643  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
644  subAssign( const DenseVector<VT,TF>& rhs );
645 
646  template< typename VT >
647  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
648  subAssign( const DenseVector<VT,TF>& rhs );
649 
650  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
651 
652  template< typename VT >
653  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
654  multAssign( const DenseVector<VT,TF>& rhs );
655 
656  template< typename VT >
657  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
658  multAssign( const DenseVector<VT,TF>& rhs );
659 
660  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
662  //**********************************************************************************************
663 
664  private:
665  //**Member variables****************************************************************************
668  size_t size_;
669  boost::shared_array<Type> v_;
670 
676  //**********************************************************************************************
677 
678  //**Compile time checks*************************************************************************
685  //**********************************************************************************************
686 };
687 //*************************************************************************************************
688 
689 
690 
691 
692 //=================================================================================================
693 //
694 // CONSTRUCTORS
695 //
696 //=================================================================================================
697 
698 //*************************************************************************************************
701 template< typename Type // Data type of the vector
702  , bool AF // Alignment flag
703  , bool PF // Padding flag
704  , bool TF > // Transpose flag
706  : size_( 0UL ) // The size/dimension of the vector
707  , v_ ( ) // The custom array of elements
708 {}
709 //*************************************************************************************************
710 
711 
712 //*************************************************************************************************
730 template< typename Type // Data type of the vector
731  , bool AF // Alignment flag
732  , bool PF // Padding flag
733  , bool TF > // Transpose flag
734 inline CustomVector<Type,AF,PF,TF>::CustomVector( Type* ptr, size_t n )
735  : size_( n ) // The size/dimension of the vector
736  , v_ ( ) // The custom array of elements
737 {
738  if( ptr == NULL ) {
739  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array of elements" );
740  }
741 
742  if( AF && !checkAlignment( ptr ) ) {
743  BLAZE_THROW_INVALID_ARGUMENT( "Invalid alignment detected" );
744  }
745 
746  v_.reset( ptr, NoDelete() );
747 }
748 //*************************************************************************************************
749 
750 
751 //*************************************************************************************************
773 template< typename Type // Data type of the vector
774  , bool AF // Alignment flag
775  , bool PF // Padding flag
776  , bool TF > // Transpose flag
777 inline CustomVector<Type,AF,PF,TF>::CustomVector( Type* ptr, size_t n, size_t nn )
778  : size_( 0UL ) // The size/dimension of the vector
779  , v_ ( ) // The custom array of elements
780 {
781  BLAZE_STATIC_ASSERT( PF == padded );
782 
783  BLAZE_UNUSED_PARAMETER( ptr, n, nn );
784 }
785 //*************************************************************************************************
786 
787 
788 //*************************************************************************************************
806 template< typename Type // Data type of the vector
807  , bool AF // Alignment flag
808  , bool PF // Padding flag
809  , bool TF > // Transpose flag
810 template< typename Deleter > // Type of the custom deleter
811 inline CustomVector<Type,AF,PF,TF>::CustomVector( Type* ptr, size_t n, Deleter d )
812  : size_( n ) // The size/dimension of the vector
813  , v_ ( ) // The custom array of elements
814 {
815  if( ptr == NULL ) {
816  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array of elements" );
817  }
818 
819  if( AF && !checkAlignment( ptr ) ) {
820  BLAZE_THROW_INVALID_ARGUMENT( "Invalid alignment detected" );
821  }
822 
823  v_.reset( ptr, d );
824 }
825 //*************************************************************************************************
826 
827 
828 //*************************************************************************************************
850 template< typename Type // Data type of the vector
851  , bool AF // Alignment flag
852  , bool PF // Padding flag
853  , bool TF > // Transpose flag
854 template< typename Deleter > // Type of the custom deleter
855 inline CustomVector<Type,AF,PF,TF>::CustomVector( Type* ptr, size_t n, size_t nn, Deleter d )
856  : size_( 0UL ) // The size/dimension of the vector
857  , v_ ( ) // The custom array of elements
858 {
859  BLAZE_STATIC_ASSERT( PF == padded );
860 
861  BLAZE_UNUSED_PARAMETER( ptr, n, nn, d );
862 }
863 //*************************************************************************************************
864 
865 
866 //*************************************************************************************************
873 template< typename Type // Data type of the vector
874  , bool AF // Alignment flag
875  , bool PF // Padding flag
876  , bool TF > // Transpose flag
878  : size_( v.size_ ) // The size/dimension of the vector
879  , v_ ( v.v_ ) // The custom array of elements
880 {}
881 //*************************************************************************************************
882 
883 
884 
885 
886 //=================================================================================================
887 //
888 // DATA ACCESS FUNCTIONS
889 //
890 //=================================================================================================
891 
892 //*************************************************************************************************
901 template< typename Type // Data type of the vector
902  , bool AF // Alignment flag
903  , bool PF // Padding flag
904  , bool TF > // Transpose flag
907 {
908  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
909  return v_[index];
910 }
911 //*************************************************************************************************
912 
913 
914 //*************************************************************************************************
923 template< typename Type // Data type of the vector
924  , bool AF // Alignment flag
925  , bool PF // Padding flag
926  , bool TF > // Transpose flag
929 {
930  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
931  return v_[index];
932 }
933 //*************************************************************************************************
934 
935 
936 //*************************************************************************************************
946 template< typename Type // Data type of the vector
947  , bool AF // Alignment flag
948  , bool PF // Padding flag
949  , bool TF > // Transpose flag
952 {
953  if( index >= size_ ) {
954  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
955  }
956  return (*this)[index];
957 }
958 //*************************************************************************************************
959 
960 
961 //*************************************************************************************************
971 template< typename Type // Data type of the vector
972  , bool AF // Alignment flag
973  , bool PF // Padding flag
974  , bool TF > // Transpose flag
976  CustomVector<Type,AF,PF,TF>::at( size_t index ) const
977 {
978  if( index >= size_ ) {
979  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
980  }
981  return (*this)[index];
982 }
983 //*************************************************************************************************
984 
985 
986 //*************************************************************************************************
993 template< typename Type // Data type of the vector
994  , bool AF // Alignment flag
995  , bool PF // Padding flag
996  , bool TF > // Transpose flag
998 {
999  return v_.get();
1000 }
1001 //*************************************************************************************************
1002 
1003 
1004 //*************************************************************************************************
1011 template< typename Type // Data type of the vector
1012  , bool AF // Alignment flag
1013  , bool PF // Padding flag
1014  , bool TF > // Transpose flag
1016 {
1017  return v_.get();
1018 }
1019 //*************************************************************************************************
1020 
1021 
1022 //*************************************************************************************************
1027 template< typename Type // Data type of the vector
1028  , bool AF // Alignment flag
1029  , bool PF // Padding flag
1030  , bool TF > // Transpose flag
1032 {
1033  return Iterator( v_.get() );
1034 }
1035 //*************************************************************************************************
1036 
1037 
1038 //*************************************************************************************************
1043 template< typename Type // Data type of the vector
1044  , bool AF // Alignment flag
1045  , bool PF // Padding flag
1046  , bool TF > // Transpose flag
1048 {
1049  return ConstIterator( v_.get() );
1050 }
1051 //*************************************************************************************************
1052 
1053 
1054 //*************************************************************************************************
1059 template< typename Type // Data type of the vector
1060  , bool AF // Alignment flag
1061  , bool PF // Padding flag
1062  , bool TF > // Transpose flag
1064 {
1065  return ConstIterator( v_.get() );
1066 }
1067 //*************************************************************************************************
1068 
1069 
1070 //*************************************************************************************************
1075 template< typename Type // Data type of the vector
1076  , bool AF // Alignment flag
1077  , bool PF // Padding flag
1078  , bool TF > // Transpose flag
1080 {
1081  return Iterator( v_.get() + size_ );
1082 }
1083 //*************************************************************************************************
1084 
1085 
1086 //*************************************************************************************************
1091 template< typename Type // Data type of the vector
1092  , bool AF // Alignment flag
1093  , bool PF // Padding flag
1094  , bool TF > // Transpose flag
1096 {
1097  return ConstIterator( v_.get() + size_ );
1098 }
1099 //*************************************************************************************************
1100 
1101 
1102 //*************************************************************************************************
1107 template< typename Type // Data type of the vector
1108  , bool AF // Alignment flag
1109  , bool PF // Padding flag
1110  , bool TF > // Transpose flag
1112 {
1113  return ConstIterator( v_.get() + size_ );
1114 }
1115 //*************************************************************************************************
1116 
1117 
1118 
1119 
1120 //=================================================================================================
1121 //
1122 // ASSIGNMENT OPERATORS
1123 //
1124 //=================================================================================================
1125 
1126 //*************************************************************************************************
1153 template< typename Type // Data type of the vector
1154  , bool AF // Alignment flag
1155  , bool PF // Padding flag
1156  , bool TF > // Transpose flag
1157 template< typename Other // Data type of the initialization array
1158  , size_t N > // Dimension of the initialization array
1160 {
1161  if( size_ != N ) {
1162  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array size" );
1163  }
1164 
1165  for( size_t i=0UL; i<N; ++i )
1166  v_[i] = array[i];
1167 
1168  return *this;
1169 }
1170 //*************************************************************************************************
1171 
1172 
1173 //*************************************************************************************************
1179 template< typename Type // Data type of the vector
1180  , bool AF // Alignment flag
1181  , bool PF // Padding flag
1182  , bool TF > // Transpose flag
1184 {
1185  for( size_t i=0UL; i<size_; ++i )
1186  v_[i] = rhs;
1187  return *this;
1188 }
1189 //*************************************************************************************************
1190 
1191 
1192 //*************************************************************************************************
1202 template< typename Type // Data type of the vector
1203  , bool AF // Alignment flag
1204  , bool PF // Padding flag
1205  , bool TF > // Transpose flag
1207 {
1208  if( rhs.size() != size_ ) {
1209  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1210  }
1211 
1212  smpAssign( *this, ~rhs );
1213 
1214  return *this;
1215 }
1216 //*************************************************************************************************
1217 
1218 
1219 //*************************************************************************************************
1229 template< typename Type // Data type of the vector
1230  , bool AF // Alignment flag
1231  , bool PF // Padding flag
1232  , bool TF > // Transpose flag
1233 template< typename VT > // Type of the right-hand side vector
1235 {
1236  if( (~rhs).size() != size_ ) {
1237  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1238  }
1239 
1240  if( (~rhs).canAlias( this ) ) {
1241  const typename VT::ResultType tmp( ~rhs );
1242  smpAssign( *this, tmp );
1243  }
1244  else {
1246  reset();
1247  smpAssign( *this, ~rhs );
1248  }
1249 
1250  return *this;
1251 }
1252 //*************************************************************************************************
1253 
1254 
1255 //*************************************************************************************************
1265 template< typename Type // Data type of the vector
1266  , bool AF // Alignment flag
1267  , bool PF // Padding flag
1268  , bool TF > // Transpose flag
1269 template< typename VT > // Type of the right-hand side vector
1271 {
1272  if( (~rhs).size() != size_ ) {
1273  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1274  }
1275 
1276  if( (~rhs).canAlias( this ) ) {
1277  const typename VT::ResultType tmp( ~rhs );
1278  smpAddAssign( *this, tmp );
1279  }
1280  else {
1281  smpAddAssign( *this, ~rhs );
1282  }
1283 
1284  return *this;
1285 }
1286 //*************************************************************************************************
1287 
1288 
1289 //*************************************************************************************************
1300 template< typename Type // Data type of the vector
1301  , bool AF // Alignment flag
1302  , bool PF // Padding flag
1303  , bool TF > // Transpose flag
1304 template< typename VT > // Type of the right-hand side vector
1306 {
1307  if( (~rhs).size() != size_ ) {
1308  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1309  }
1310 
1311  if( (~rhs).canAlias( this ) ) {
1312  const typename VT::ResultType tmp( ~rhs );
1313  smpSubAssign( *this, tmp );
1314  }
1315  else {
1316  smpSubAssign( *this, ~rhs );
1317  }
1318 
1319  return *this;
1320 }
1321 //*************************************************************************************************
1322 
1323 
1324 //*************************************************************************************************
1335 template< typename Type // Data type of the vector
1336  , bool AF // Alignment flag
1337  , bool PF // Padding flag
1338  , bool TF > // Transpose flag
1339 template< typename VT > // Type of the right-hand side vector
1341 {
1344 
1345  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
1346 
1349 
1350  if( (~rhs).size() != size_ ) {
1351  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1352  }
1353 
1354  if( IsSparseVector<VT>::value || (~rhs).canAlias( this ) ) {
1355  const MultType tmp( *this * (~rhs) );
1356  this->operator=( tmp );
1357  }
1358  else {
1359  smpMultAssign( *this, ~rhs );
1360  }
1361 
1362  return *this;
1363 }
1364 //*************************************************************************************************
1365 
1366 
1367 //*************************************************************************************************
1374 template< typename Type // Data type of the vector
1375  , bool AF // Alignment flag
1376  , bool PF // Padding flag
1377  , bool TF > // Transpose flag
1378 template< typename Other > // Data type of the right-hand side scalar
1381 {
1382  smpAssign( *this, (*this) * rhs );
1383  return *this;
1384 }
1385 //*************************************************************************************************
1386 
1387 
1388 //*************************************************************************************************
1397 template< typename Type // Data type of the vector
1398  , bool AF // Alignment flag
1399  , bool PF // Padding flag
1400  , bool TF > // Transpose flag
1401 template< typename Other > // Data type of the right-hand side scalar
1402 inline typename EnableIf< IsNumeric<Other>, CustomVector<Type,AF,PF,TF> >::Type&
1404 {
1405  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1406 
1407  smpAssign( *this, (*this) / rhs );
1408  return *this;
1409 }
1410 //*************************************************************************************************
1411 
1412 
1413 
1414 
1415 //=================================================================================================
1416 //
1417 // UTILITY FUNCTIONS
1418 //
1419 //=================================================================================================
1420 
1421 //*************************************************************************************************
1426 template< typename Type // Data type of the vector
1427  , bool AF // Alignment flag
1428  , bool PF // Padding flag
1429  , bool TF > // Transpose flag
1431 {
1432  return size_;
1433 }
1434 //*************************************************************************************************
1435 
1436 
1437 //*************************************************************************************************
1442 template< typename Type // Data type of the vector
1443  , bool AF // Alignment flag
1444  , bool PF // Padding flag
1445  , bool TF > // Transpose flag
1447 {
1448  return size_;
1449 }
1450 //*************************************************************************************************
1451 
1452 
1453 //*************************************************************************************************
1461 template< typename Type // Data type of the vector
1462  , bool AF // Alignment flag
1463  , bool PF // Padding flag
1464  , bool TF > // Transpose flag
1466 {
1467  size_t nonzeros( 0 );
1468 
1469  for( size_t i=0UL; i<size_; ++i ) {
1470  if( !isDefault( v_[i] ) )
1471  ++nonzeros;
1472  }
1473 
1474  return nonzeros;
1475 }
1476 //*************************************************************************************************
1477 
1478 
1479 //*************************************************************************************************
1484 template< typename Type // Data type of the vector
1485  , bool AF // Alignment flag
1486  , bool PF // Padding flag
1487  , bool TF > // Transpose flag
1489 {
1490  using blaze::clear;
1491  for( size_t i=0UL; i<size_; ++i )
1492  clear( v_[i] );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1505 template< typename Type // Data type of the vector
1506  , bool AF // Alignment flag
1507  , bool PF // Padding flag
1508  , bool TF > // Transpose flag
1510 {
1511  size_ = 0UL;
1512  v_.reset();
1513 }
1514 //*************************************************************************************************
1515 
1516 
1517 //*************************************************************************************************
1523 template< typename Type // Data type of the vector
1524  , bool AF // Alignment flag
1525  , bool PF // Padding flag
1526  , bool TF > // Transpose flag
1527 template< typename Other > // Data type of the scalar value
1529 {
1530  for( size_t i=0UL; i<size_; ++i )
1531  v_[i] *= scalar;
1532  return *this;
1533 }
1534 //*************************************************************************************************
1535 
1536 
1537 //*************************************************************************************************
1544 template< typename Type // Data type of the vector
1545  , bool AF // Alignment flag
1546  , bool PF // Padding flag
1547  , bool TF > // Transpose flag
1548 inline void CustomVector<Type,AF,PF,TF>::swap( CustomVector& v ) /* throw() */
1549 {
1550  using std::swap;
1551 
1552  swap( size_, v.size_ );
1553  swap( v_, v.v_ );
1554 }
1555 //*************************************************************************************************
1556 
1557 
1558 
1559 
1560 //=================================================================================================
1561 //
1562 // RESOURCE MANAGEMENT FUNCTIONS
1563 //
1564 //=================================================================================================
1565 
1566 //*************************************************************************************************
1588 template< typename Type // Data type of the vector
1589  , bool AF // Alignment flag
1590  , bool PF // Padding flag
1591  , bool TF > // Transpose flag
1592 inline void CustomVector<Type,AF,PF,TF>::reset( Type* ptr, size_t n )
1593 {
1594  CustomVector tmp( ptr, n );
1595  swap( tmp );
1596 }
1597 //*************************************************************************************************
1598 
1599 
1600 //*************************************************************************************************
1625 template< typename Type // Data type of the vector
1626  , bool AF // Alignment flag
1627  , bool PF // Padding flag
1628  , bool TF > // Transpose flag
1629 inline void CustomVector<Type,AF,PF,TF>::reset( Type* ptr, size_t n, size_t nn )
1630 {
1631  BLAZE_STATIC_ASSERT( PF == padded );
1632 
1633  BLAZE_UNUSED_PARAMETER( ptr, n, nn );
1634 }
1635 //*************************************************************************************************
1636 
1637 
1638 //*************************************************************************************************
1660 template< typename Type // Data type of the vector
1661  , bool AF // Alignment flag
1662  , bool PF // Padding flag
1663  , bool TF > // Transpose flag
1664 template< typename Deleter > // Type of the custom deleter
1665 inline void CustomVector<Type,AF,PF,TF>::reset( Type* ptr, size_t n, Deleter d )
1666 {
1667  CustomVector tmp( ptr, n, d );
1668  swap( tmp );
1669 }
1670 //*************************************************************************************************
1671 
1672 
1673 //*************************************************************************************************
1698 template< typename Type // Data type of the vector
1699  , bool AF // Alignment flag
1700  , bool PF // Padding flag
1701  , bool TF > // Transpose flag
1702 template< typename Deleter > // Type of the custom deleter
1703 inline void CustomVector<Type,AF,PF,TF>::reset( Type* ptr, size_t n, size_t nn, Deleter d )
1704 {
1705  BLAZE_STATIC_ASSERT( PF == padded );
1706 
1707  BLAZE_UNUSED_PARAMETER( ptr, n, nn, d );
1708 }
1709 //*************************************************************************************************
1710 
1711 
1712 
1713 
1714 //=================================================================================================
1715 //
1716 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1717 //
1718 //=================================================================================================
1719 
1720 //*************************************************************************************************
1730 template< typename Type // Data type of the vector
1731  , bool AF // Alignment flag
1732  , bool PF // Padding flag
1733  , bool TF > // Transpose flag
1734 template< typename Other > // Data type of the foreign expression
1735 inline bool CustomVector<Type,AF,PF,TF>::canAlias( const Other* alias ) const
1736 {
1737  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1738 }
1739 //*************************************************************************************************
1740 
1741 
1742 //*************************************************************************************************
1752 template< typename Type // Data type of the vector
1753  , bool AF // Alignment flag
1754  , bool PF // Padding flag
1755  , bool TF > // Transpose flag
1756 template< typename Other > // Data type of the foreign expression
1757 inline bool CustomVector<Type,AF,PF,TF>::isAliased( const Other* alias ) const
1758 {
1759  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
1760 }
1761 //*************************************************************************************************
1762 
1763 
1764 //*************************************************************************************************
1773 template< typename Type // Data type of the vector
1774  , bool AF // Alignment flag
1775  , bool PF // Padding flag
1776  , bool TF > // Transpose flag
1778 {
1779  return ( AF || checkAlignment( v_.get() ) );
1780 }
1781 //*************************************************************************************************
1782 
1783 
1784 //*************************************************************************************************
1794 template< typename Type // Data type of the vector
1795  , bool AF // Alignment flag
1796  , bool PF // Padding flag
1797  , bool TF > // Transpose flag
1799 {
1800  return ( size() > SMP_DVECASSIGN_THRESHOLD );
1801 }
1802 //*************************************************************************************************
1803 
1804 
1805 //*************************************************************************************************
1818 template< typename Type // Data type of the vector
1819  , bool AF // Alignment flag
1820  , bool PF // Padding flag
1821  , bool TF > // Transpose flag
1824 {
1825  if( AF )
1826  return loada( index );
1827  else
1828  return loadu( index );
1829 }
1830 //*************************************************************************************************
1831 
1832 
1833 //*************************************************************************************************
1846 template< typename Type // Data type of the vector
1847  , bool AF // Alignment flag
1848  , bool PF // Padding flag
1849  , bool TF > // Transpose flag
1852 {
1853  using blaze::loada;
1854 
1856 
1857  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1858  BLAZE_INTERNAL_ASSERT( index + IT::size <= size_, "Invalid vector access index" );
1859  BLAZE_INTERNAL_ASSERT( !AF || index % IT::size == 0UL, "Invalid vector access index" );
1860  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
1861 
1862  return loada( v_.get()+index );
1863 }
1864 //*************************************************************************************************
1865 
1866 
1867 //*************************************************************************************************
1880 template< typename Type // Data type of the vector
1881  , bool AF // Alignment flag
1882  , bool PF // Padding flag
1883  , bool TF > // Transpose flag
1886 {
1887  using blaze::loadu;
1888 
1890 
1891  BLAZE_INTERNAL_ASSERT( index< size_, "Invalid vector access index" );
1892  BLAZE_INTERNAL_ASSERT( index + IT::size <= size_, "Invalid vector access index" );
1893 
1894  return loadu( v_.get()+index );
1895 }
1896 //*************************************************************************************************
1897 
1898 
1899 //*************************************************************************************************
1913 template< typename Type // Data type of the vector
1914  , bool AF // Alignment flag
1915  , bool PF // Padding flag
1916  , bool TF > // Transpose flag
1917 BLAZE_ALWAYS_INLINE void CustomVector<Type,AF,PF,TF>::store( size_t index, const IntrinsicType& value )
1918 {
1919  if( AF )
1920  storea( index, value );
1921  else
1922  storeu( index, value );
1923 }
1924 //*************************************************************************************************
1925 
1926 
1927 //*************************************************************************************************
1941 template< typename Type // Data type of the vector
1942  , bool AF // Alignment flag
1943  , bool PF // Padding flag
1944  , bool TF > // Transpose flag
1945 BLAZE_ALWAYS_INLINE void CustomVector<Type,AF,PF,TF>::storea( size_t index, const IntrinsicType& value )
1946 {
1947  using blaze::storea;
1948 
1950 
1951  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1952  BLAZE_INTERNAL_ASSERT( index + IT::size <= size_, "Invalid vector access index" );
1953  BLAZE_INTERNAL_ASSERT( !AF || index % IT::size == 0UL, "Invalid vector access index" );
1954  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
1955 
1956  storea( v_.get()+index, value );
1957 }
1958 //*************************************************************************************************
1959 
1960 
1961 //*************************************************************************************************
1975 template< typename Type // Data type of the vector
1976  , bool AF // Alignment flag
1977  , bool PF // Padding flag
1978  , bool TF > // Transpose flag
1979 BLAZE_ALWAYS_INLINE void CustomVector<Type,AF,PF,TF>::storeu( size_t index, const IntrinsicType& value )
1980 {
1981  using blaze::storeu;
1982 
1984 
1985  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
1986  BLAZE_INTERNAL_ASSERT( index + IT::size <= size_, "Invalid vector access index" );
1987 
1988  storeu( v_.get()+index, value );
1989 }
1990 //*************************************************************************************************
1991 
1992 
1993 //*************************************************************************************************
2007 template< typename Type // Data type of the vector
2008  , bool AF // Alignment flag
2009  , bool PF // Padding flag
2010  , bool TF > // Transpose flag
2011 BLAZE_ALWAYS_INLINE void CustomVector<Type,AF,PF,TF>::stream( size_t index, const IntrinsicType& value )
2012 {
2013  using blaze::stream;
2014 
2016 
2017  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
2018  BLAZE_INTERNAL_ASSERT( index + IT::size <= size_, "Invalid vector access index" );
2019  BLAZE_INTERNAL_ASSERT( !AF || index % IT::size == 0UL, "Invalid vector access index" );
2020  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
2021 
2022  stream( v_.get()+index, value );
2023 }
2024 //*************************************************************************************************
2025 
2026 
2027 //*************************************************************************************************
2038 template< typename Type // Data type of the vector
2039  , bool AF // Alignment flag
2040  , bool PF // Padding flag
2041  , bool TF > // Transpose flag
2042 template< typename VT > // Type of the right-hand side dense vector
2043 inline typename DisableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
2045 {
2046  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2047 
2048  const size_t ipos( size_ & size_t(-2) );
2049  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2050 
2051  for( size_t i=0UL; i<ipos; i+=2UL ) {
2052  v_[i ] = (~rhs)[i ];
2053  v_[i+1UL] = (~rhs)[i+1UL];
2054  }
2055  if( ipos < (~rhs).size() )
2056  v_[ipos] = (~rhs)[ipos];
2057 }
2058 //*************************************************************************************************
2059 
2060 
2061 //*************************************************************************************************
2072 template< typename Type // Data type of the vector
2073  , bool AF // Alignment flag
2074  , bool PF // Padding flag
2075  , bool TF > // Transpose flag
2076 template< typename VT > // Type of the right-hand side dense vector
2077 inline typename EnableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
2079 {
2081 
2082  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2083 
2084  const size_t ipos( size_ & size_t(-IT::size) );
2085  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
2086 
2087  if( AF && useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
2088  {
2089  size_t i( 0UL );
2090 
2091  for( ; i<ipos; i+=IT::size ) {
2092  stream( i, (~rhs).load(i) );
2093  }
2094  for( ; i<size_; ++i ) {
2095  v_[i] = (~rhs)[i];
2096  }
2097  }
2098  else
2099  {
2100  const size_t i4way( size_ & size_t(-IT::size*4) );
2101  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
2102  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
2103 
2104  size_t i( 0UL );
2105  typename VT::ConstIterator it( (~rhs).begin() );
2106 
2107  for( ; i<i4way; i+=IT::size*4UL ) {
2108  store( i , it.load() ); it += IT::size;
2109  store( i+IT::size , it.load() ); it += IT::size;
2110  store( i+IT::size*2UL, it.load() ); it += IT::size;
2111  store( i+IT::size*3UL, it.load() ); it += IT::size;
2112  }
2113  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2114  store( i, it.load() );
2115  }
2116  for( ; i<size_; ++i, ++it ) {
2117  v_[i] = *it;
2118  }
2119  }
2120 }
2121 //*************************************************************************************************
2122 
2123 
2124 //*************************************************************************************************
2135 template< typename Type // Data type of the vector
2136  , bool AF // Alignment flag
2137  , bool PF // Padding flag
2138  , bool TF > // Transpose flag
2139 template< typename VT > // Type of the right-hand side sparse vector
2141 {
2142  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2143 
2144  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2145  v_[element->index()] = element->value();
2146 }
2147 //*************************************************************************************************
2148 
2149 
2150 //*************************************************************************************************
2161 template< typename Type // Data type of the vector
2162  , bool AF // Alignment flag
2163  , bool PF // Padding flag
2164  , bool TF > // Transpose flag
2165 template< typename VT > // Type of the right-hand side dense vector
2166 inline typename DisableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
2168 {
2169  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2170 
2171  const size_t ipos( size_ & size_t(-2) );
2172  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2173 
2174  for( size_t i=0UL; i<ipos; i+=2UL ) {
2175  v_[i ] += (~rhs)[i ];
2176  v_[i+1UL] += (~rhs)[i+1UL];
2177  }
2178  if( ipos < (~rhs).size() )
2179  v_[ipos] += (~rhs)[ipos];
2180 }
2181 //*************************************************************************************************
2182 
2183 
2184 //*************************************************************************************************
2195 template< typename Type // Data type of the vector
2196  , bool AF // Alignment flag
2197  , bool PF // Padding flag
2198  , bool TF > // Transpose flag
2199 template< typename VT > // Type of the right-hand side dense vector
2200 inline typename EnableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
2202 {
2204 
2205  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2206 
2207  const size_t ipos( size_ & size_t(-IT::size) );
2208  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
2209 
2210  const size_t i4way( size_ & size_t(-IT::size*4) );
2211  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
2212  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
2213 
2214  size_t i( 0UL );
2215  typename VT::ConstIterator it( (~rhs).begin() );
2216 
2217  for( ; i<i4way; i+=IT::size*4UL ) {
2218  store( i , load(i ) + it.load() ); it += IT::size;
2219  store( i+IT::size , load(i+IT::size ) + it.load() ); it += IT::size;
2220  store( i+IT::size*2UL, load(i+IT::size*2UL) + it.load() ); it += IT::size;
2221  store( i+IT::size*3UL, load(i+IT::size*3UL) + it.load() ); it += IT::size;
2222  }
2223  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2224  store( i, load(i) + it.load() );
2225  }
2226  for( ; i<size_; ++i, ++it ) {
2227  v_[i] += *it;
2228  }
2229 }
2230 //*************************************************************************************************
2231 
2232 
2233 //*************************************************************************************************
2244 template< typename Type // Data type of the vector
2245  , bool AF // Alignment flag
2246  , bool PF // Padding flag
2247  , bool TF > // Transpose flag
2248 template< typename VT > // Type of the right-hand side sparse vector
2250 {
2251  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2252 
2253  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2254  v_[element->index()] += element->value();
2255 }
2256 //*************************************************************************************************
2257 
2258 
2259 //*************************************************************************************************
2270 template< typename Type // Data type of the vector
2271  , bool AF // Alignment flag
2272  , bool PF // Padding flag
2273  , bool TF > // Transpose flag
2274 template< typename VT > // Type of the right-hand side dense vector
2275 inline typename DisableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
2277 {
2278  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2279 
2280  const size_t ipos( size_ & size_t(-2) );
2281  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2282 
2283  for( size_t i=0UL; i<ipos; i+=2UL ) {
2284  v_[i ] -= (~rhs)[i ];
2285  v_[i+1UL] -= (~rhs)[i+1UL];
2286  }
2287  if( ipos < (~rhs).size() )
2288  v_[ipos] -= (~rhs)[ipos];
2289 }
2290 //*************************************************************************************************
2291 
2292 
2293 //*************************************************************************************************
2304 template< typename Type // Data type of the vector
2305  , bool AF // Alignment flag
2306  , bool PF // Padding flag
2307  , bool TF > // Transpose flag
2308 template< typename VT > // Type of the right-hand side dense vector
2309 inline typename EnableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
2311 {
2313 
2314  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2315 
2316  const size_t ipos( size_ & size_t(-IT::size) );
2317  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
2318 
2319  const size_t i4way( size_ & size_t(-IT::size*4) );
2320  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
2321  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
2322 
2323  size_t i( 0UL );
2324  typename VT::ConstIterator it( (~rhs).begin() );
2325 
2326  for( ; i<i4way; i+=IT::size*4UL ) {
2327  store( i , load(i ) - it.load() ); it += IT::size;
2328  store( i+IT::size , load(i+IT::size ) - it.load() ); it += IT::size;
2329  store( i+IT::size*2UL, load(i+IT::size*2UL) - it.load() ); it += IT::size;
2330  store( i+IT::size*3UL, load(i+IT::size*3UL) - it.load() ); it += IT::size;
2331  }
2332  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2333  store( i, load(i) - it.load() );
2334  }
2335  for( ; i<size_; ++i, ++it ) {
2336  v_[i] -= *it;
2337  }
2338 }
2339 //*************************************************************************************************
2340 
2341 
2342 //*************************************************************************************************
2353 template< typename Type // Data type of the vector
2354  , bool AF // Alignment flag
2355  , bool PF // Padding flag
2356  , bool TF > // Transpose flag
2357 template< typename VT > // Type of the right-hand side sparse vector
2359 {
2360  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2361 
2362  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2363  v_[element->index()] -= element->value();
2364 }
2365 //*************************************************************************************************
2366 
2367 
2368 //*************************************************************************************************
2379 template< typename Type // Data type of the vector
2380  , bool AF // Alignment flag
2381  , bool PF // Padding flag
2382  , bool TF > // Transpose flag
2383 template< typename VT > // Type of the right-hand side dense vector
2384 inline typename DisableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2386 {
2387  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2388 
2389  const size_t ipos( size_ & size_t(-2) );
2390  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
2391 
2392  for( size_t i=0UL; i<ipos; i+=2UL ) {
2393  v_[i ] *= (~rhs)[i ];
2394  v_[i+1UL] *= (~rhs)[i+1UL];
2395  }
2396  if( ipos < (~rhs).size() )
2397  v_[ipos] *= (~rhs)[ipos];
2398 }
2399 //*************************************************************************************************
2400 
2401 
2402 //*************************************************************************************************
2413 template< typename Type // Data type of the vector
2414  , bool AF // Alignment flag
2415  , bool PF // Padding flag
2416  , bool TF > // Transpose flag
2417 template< typename VT > // Type of the right-hand side dense vector
2418 inline typename EnableIf< typename CustomVector<Type,AF,PF,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
2420 {
2422 
2423  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2424 
2425  const size_t ipos( size_ & size_t(-IT::size) );
2426  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
2427 
2428  const size_t i4way( size_ & size_t(-IT::size*4) );
2429  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
2430  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
2431 
2432  size_t i( 0UL );
2433  typename VT::ConstIterator it( (~rhs).begin() );
2434 
2435  for( ; i<i4way; i+=IT::size*4UL ) {
2436  store( i , load(i ) * it.load() ); it += IT::size;
2437  store( i+IT::size , load(i+IT::size ) * it.load() ); it += IT::size;
2438  store( i+IT::size*2UL, load(i+IT::size*2UL) * it.load() ); it += IT::size;
2439  store( i+IT::size*3UL, load(i+IT::size*3UL) * it.load() ); it += IT::size;
2440  }
2441  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2442  store( i, load(i) * it.load() );
2443  }
2444  for( ; i<size_; ++i, ++it ) {
2445  v_[i] *= *it;
2446  }
2447 }
2448 //*************************************************************************************************
2449 
2450 
2451 //*************************************************************************************************
2462 template< typename Type // Data type of the vector
2463  , bool AF // Alignment flag
2464  , bool PF // Padding flag
2465  , bool TF > // Transpose flag
2466 template< typename VT > // Type of the right-hand side sparse vector
2468 {
2469  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
2470 
2471  const DynamicVector<Type,TF> tmp( serial( *this ) );
2472 
2473  reset();
2474 
2475  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2476  v_[element->index()] = tmp[element->index()] * element->value();
2477 }
2478 //*************************************************************************************************
2479 
2480 
2481 
2482 
2483 
2484 
2485 
2486 
2487 //=================================================================================================
2488 //
2489 // CLASS TEMPLATE SPECIALIZATION FOR PADDED VECTORS
2490 //
2491 //=================================================================================================
2492 
2493 //*************************************************************************************************
2501 template< typename Type // Data type of the vector
2502  , bool AF // Alignment flag
2503  , bool TF > // Transpose flag
2504 class CustomVector<Type,AF,padded,TF>
2505  : public DenseVector< CustomVector<Type,AF,padded,TF>, TF >
2506 {
2507  private:
2508  //**Type definitions****************************************************************************
2509  typedef IntrinsicTrait<Type> IT;
2510  //**********************************************************************************************
2511 
2512  public:
2513  //**Type definitions****************************************************************************
2517  typedef Type ElementType;
2518  typedef typename IT::Type IntrinsicType;
2519  typedef const Type& ReturnType;
2520  typedef const CustomVector& CompositeType;
2521 
2522  typedef Type& Reference;
2523  typedef const Type& ConstReference;
2524  typedef Type* Pointer;
2525  typedef const Type* ConstPointer;
2526 
2529  //**********************************************************************************************
2530 
2531  //**Rebind struct definition********************************************************************
2534  template< typename ET > // Data type of the other vector
2535  struct Rebind {
2537  };
2538  //**********************************************************************************************
2539 
2540  //**Compilation flags***************************************************************************
2542 
2546  enum { vectorizable = IsVectorizable<Type>::value };
2547 
2549 
2552  enum { smpAssignable = !IsSMPAssignable<Type>::value };
2553  //**********************************************************************************************
2554 
2555  //**Constructors********************************************************************************
2558  explicit inline CustomVector();
2559  explicit inline CustomVector( Type* ptr, size_t n, size_t nn );
2560 
2561  template< typename Deleter >
2562  explicit inline CustomVector( Type* ptr, size_t n, size_t nn, Deleter d );
2563 
2564  inline CustomVector( const CustomVector& v );
2566  //**********************************************************************************************
2567 
2568  //**Destructor**********************************************************************************
2569  // No explicitly declared destructor.
2570  //**********************************************************************************************
2571 
2572  //**Data access functions***********************************************************************
2575  inline Reference operator[]( size_t index );
2576  inline ConstReference operator[]( size_t index ) const;
2577  inline Reference at( size_t index );
2578  inline ConstReference at( size_t index ) const;
2579  inline Pointer data ();
2580  inline ConstPointer data () const;
2581  inline Iterator begin ();
2582  inline ConstIterator begin () const;
2583  inline ConstIterator cbegin() const;
2584  inline Iterator end ();
2585  inline ConstIterator end () const;
2586  inline ConstIterator cend () const;
2588  //**********************************************************************************************
2589 
2590  //**Assignment operators************************************************************************
2593  template< typename Other, size_t N >
2594  inline CustomVector& operator=( const Other (&array)[N] );
2595 
2596  inline CustomVector& operator= ( const Type& rhs );
2597  inline CustomVector& operator= ( const CustomVector& rhs );
2598  template< typename VT > inline CustomVector& operator= ( const Vector<VT,TF>& rhs );
2599  template< typename VT > inline CustomVector& operator+=( const Vector<VT,TF>& rhs );
2600  template< typename VT > inline CustomVector& operator-=( const Vector<VT,TF>& rhs );
2601  template< typename VT > inline CustomVector& operator*=( const Vector<VT,TF>& rhs );
2602 
2603  template< typename Other >
2604  inline typename EnableIf< IsNumeric<Other>, CustomVector >::Type&
2605  operator*=( Other rhs );
2606 
2607  template< typename Other >
2608  inline typename EnableIf< IsNumeric<Other>, CustomVector >::Type&
2609  operator/=( Other rhs );
2611  //**********************************************************************************************
2612 
2613  //**Utility functions***************************************************************************
2616  inline size_t size() const;
2617  inline size_t capacity() const;
2618  inline size_t nonZeros() const;
2619  inline void reset();
2620  inline void clear();
2621  template< typename Other > inline CustomVector& scale( const Other& scalar );
2622  inline void swap( CustomVector& v ) /* throw() */;
2624  //**********************************************************************************************
2625 
2626  //**Resource management functions***************************************************************
2629  inline void reset( Type* ptr, size_t n, size_t nn );
2630  template< typename Deleter > inline void reset( Type* ptr, size_t n, size_t nn, Deleter d );
2632  //**********************************************************************************************
2633 
2634  private:
2635  //**********************************************************************************************
2637  template< typename VT >
2638  struct VectorizedAssign {
2639  enum { value = useOptimizedKernels &&
2640  vectorizable && VT::vectorizable &&
2641  IsSame<Type,typename VT::ElementType>::value };
2642  };
2643  //**********************************************************************************************
2644 
2645  //**********************************************************************************************
2647  template< typename VT >
2648  struct VectorizedAddAssign {
2649  enum { value = useOptimizedKernels &&
2650  vectorizable && VT::vectorizable &&
2651  IsSame<Type,typename VT::ElementType>::value &&
2652  IntrinsicTrait<Type>::addition };
2653  };
2654  //**********************************************************************************************
2655 
2656  //**********************************************************************************************
2658  template< typename VT >
2659  struct VectorizedSubAssign {
2660  enum { value = useOptimizedKernels &&
2661  vectorizable && VT::vectorizable &&
2662  IsSame<Type,typename VT::ElementType>::value &&
2663  IntrinsicTrait<Type>::subtraction };
2664  };
2665  //**********************************************************************************************
2666 
2667  //**********************************************************************************************
2669  template< typename VT >
2670  struct VectorizedMultAssign {
2671  enum { value = useOptimizedKernels &&
2672  vectorizable && VT::vectorizable &&
2673  IsSame<Type,typename VT::ElementType>::value &&
2674  IntrinsicTrait<Type>::multiplication };
2675  };
2676  //**********************************************************************************************
2677 
2678  public:
2679  //**Expression template evaluation functions****************************************************
2682  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2683  template< typename Other > inline bool isAliased( const Other* alias ) const;
2684 
2685  inline bool isAligned () const;
2686  inline bool canSMPAssign() const;
2687 
2688  BLAZE_ALWAYS_INLINE IntrinsicType load ( size_t index ) const;
2689  BLAZE_ALWAYS_INLINE IntrinsicType loada( size_t index ) const;
2690  BLAZE_ALWAYS_INLINE IntrinsicType loadu( size_t index ) const;
2691 
2692  BLAZE_ALWAYS_INLINE void store ( size_t index, const IntrinsicType& value );
2693  BLAZE_ALWAYS_INLINE void storea( size_t index, const IntrinsicType& value );
2694  BLAZE_ALWAYS_INLINE void storeu( size_t index, const IntrinsicType& value );
2695  BLAZE_ALWAYS_INLINE void stream( size_t index, const IntrinsicType& value );
2696 
2697  template< typename VT >
2698  inline typename DisableIf< VectorizedAssign<VT> >::Type
2699  assign( const DenseVector<VT,TF>& rhs );
2700 
2701  template< typename VT >
2702  inline typename EnableIf< VectorizedAssign<VT> >::Type
2703  assign( const DenseVector<VT,TF>& rhs );
2704 
2705  template< typename VT > inline void assign( const SparseVector<VT,TF>& rhs );
2706 
2707  template< typename VT >
2708  inline typename DisableIf< VectorizedAddAssign<VT> >::Type
2709  addAssign( const DenseVector<VT,TF>& rhs );
2710 
2711  template< typename VT >
2712  inline typename EnableIf< VectorizedAddAssign<VT> >::Type
2713  addAssign( const DenseVector<VT,TF>& rhs );
2714 
2715  template< typename VT > inline void addAssign( const SparseVector<VT,TF>& rhs );
2716 
2717  template< typename VT >
2718  inline typename DisableIf< VectorizedSubAssign<VT> >::Type
2719  subAssign( const DenseVector<VT,TF>& rhs );
2720 
2721  template< typename VT >
2722  inline typename EnableIf< VectorizedSubAssign<VT> >::Type
2723  subAssign( const DenseVector<VT,TF>& rhs );
2724 
2725  template< typename VT > inline void subAssign( const SparseVector<VT,TF>& rhs );
2726 
2727  template< typename VT >
2728  inline typename DisableIf< VectorizedMultAssign<VT> >::Type
2729  multAssign( const DenseVector<VT,TF>& rhs );
2730 
2731  template< typename VT >
2732  inline typename EnableIf< VectorizedMultAssign<VT> >::Type
2733  multAssign( const DenseVector<VT,TF>& rhs );
2734 
2735  template< typename VT > inline void multAssign( const SparseVector<VT,TF>& rhs );
2737  //**********************************************************************************************
2738 
2739  private:
2740  //**Member variables****************************************************************************
2743  size_t size_;
2744  size_t capacity_;
2745  boost::shared_array<Type> v_;
2746 
2752  //**********************************************************************************************
2753 
2754  //**Compile time checks*************************************************************************
2759  //**********************************************************************************************
2760 };
2762 //*************************************************************************************************
2763 
2764 
2765 
2766 
2767 //=================================================================================================
2768 //
2769 // CONSTRUCTORS
2770 //
2771 //=================================================================================================
2772 
2773 //*************************************************************************************************
2777 template< typename Type // Data type of the vector
2778  , bool AF // Alignment flag
2779  , bool TF > // Transpose flag
2781  : size_ ( 0UL ) // The size/dimension of the vector
2782  , capacity_( 0UL ) // The maximum capacity of the vector
2783  , v_ ( ) // The custom array of elements
2784 {}
2786 //*************************************************************************************************
2787 
2788 
2789 //*************************************************************************************************
2811 template< typename Type // Data type of the vector
2812  , bool AF // Alignment flag
2813  , bool TF > // Transpose flag
2814 inline CustomVector<Type,AF,padded,TF>::CustomVector( Type* ptr, size_t n, size_t nn )
2815  : size_ ( n ) // The size/dimension of the vector
2816  , capacity_( nn ) // The maximum capacity of the vector
2817  , v_ ( ) // The custom array of elements
2818 {
2819  if( ptr == NULL ) {
2820  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array of elements" );
2821  }
2822 
2823  if( AF && !checkAlignment( ptr ) ) {
2824  BLAZE_THROW_INVALID_ARGUMENT( "Invalid alignment detected" );
2825  }
2826 
2827  if( IsVectorizable<Type>::value && capacity_ < nextMultiple<size_t>( size_, IT::size ) ) {
2828  BLAZE_THROW_INVALID_ARGUMENT( "Insufficient capacity for padded vector" );
2829  }
2830 
2831  v_.reset( ptr, NoDelete() );
2832 
2833  if( IsVectorizable<Type>::value ) {
2834  for( size_t i=size_; i<capacity_; ++i )
2835  v_[i] = Type();
2836  }
2837 }
2839 //*************************************************************************************************
2840 
2841 
2842 //*************************************************************************************************
2863 template< typename Type // Data type of the vector
2864  , bool AF // Alignment flag
2865  , bool TF > // Transpose flag
2866 template< typename Deleter > // Type of the custom deleter
2867 inline CustomVector<Type,AF,padded,TF>::CustomVector( Type* ptr, size_t n, size_t nn, Deleter d )
2868  : size_ ( n ) // The custom array of elements
2869  , capacity_( nn ) // The maximum capacity of the vector
2870  , v_ ( ) // The custom array of elements
2871 {
2872  if( ptr == NULL ) {
2873  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array of elements" );
2874  }
2875 
2876  if( AF && !checkAlignment( ptr ) ) {
2877  BLAZE_THROW_INVALID_ARGUMENT( "Invalid alignment detected" );
2878  }
2879 
2880  if( IsVectorizable<Type>::value && capacity_ < nextMultiple<size_t>( size_, IT::size ) ) {
2881  BLAZE_THROW_INVALID_ARGUMENT( "Insufficient capacity for padded vector" );
2882  }
2883 
2884  v_.reset( ptr, d );
2885 
2886  if( IsVectorizable<Type>::value ) {
2887  for( size_t i=size_; i<capacity_; ++i )
2888  v_[i] = Type();
2889  }
2890 }
2892 //*************************************************************************************************
2893 
2894 
2895 //*************************************************************************************************
2903 template< typename Type // Data type of the vector
2904  , bool AF // Alignment flag
2905  , bool TF > // Transpose flag
2906 inline CustomVector<Type,AF,padded,TF>::CustomVector( const CustomVector& v )
2907  : size_ ( v.size_ ) // The size/dimension of the vector
2908  , capacity_( v.capacity_ ) // The maximum capacity of the vector
2909  , v_ ( v.v_ ) // The custom array of elements
2910 {}
2912 //*************************************************************************************************
2913 
2914 
2915 
2916 
2917 //=================================================================================================
2918 //
2919 // DATA ACCESS FUNCTIONS
2920 //
2921 //=================================================================================================
2922 
2923 //*************************************************************************************************
2933 template< typename Type // Data type of the vector
2934  , bool AF // Alignment flag
2935  , bool TF > // Transpose flag
2938 {
2939  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
2940  return v_[index];
2941 }
2943 //*************************************************************************************************
2944 
2945 
2946 //*************************************************************************************************
2956 template< typename Type // Data type of the vector
2957  , bool AF // Alignment flag
2958  , bool TF > // Transpose flag
2960  CustomVector<Type,AF,padded,TF>::operator[]( size_t index ) const
2961 {
2962  BLAZE_USER_ASSERT( index < size_, "Invalid vector access index" );
2963  return v_[index];
2964 }
2966 //*************************************************************************************************
2967 
2968 
2969 //*************************************************************************************************
2980 template< typename Type // Data type of the vector
2981  , bool AF // Alignment flag
2982  , bool TF > // Transpose flag
2984  CustomVector<Type,AF,padded,TF>::at( size_t index )
2985 {
2986  if( index >= size_ ) {
2987  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
2988  }
2989  return (*this)[index];
2990 }
2992 //*************************************************************************************************
2993 
2994 
2995 //*************************************************************************************************
3006 template< typename Type // Data type of the vector
3007  , bool AF // Alignment flag
3008  , bool TF > // Transpose flag
3010  CustomVector<Type,AF,padded,TF>::at( size_t index ) const
3011 {
3012  if( index >= size_ ) {
3013  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
3014  }
3015  return (*this)[index];
3016 }
3018 //*************************************************************************************************
3019 
3020 
3021 //*************************************************************************************************
3029 template< typename Type // Data type of the vector
3030  , bool AF // Alignment flag
3031  , bool TF > // Transpose flag
3032 inline typename CustomVector<Type,AF,padded,TF>::Pointer
3034 {
3035  return v_.get();
3036 }
3038 //*************************************************************************************************
3039 
3040 
3041 //*************************************************************************************************
3049 template< typename Type // Data type of the vector
3050  , bool AF // Alignment flag
3051  , bool TF > // Transpose flag
3052 inline typename CustomVector<Type,AF,padded,TF>::ConstPointer
3054 {
3055  return v_.get();
3056 }
3058 //*************************************************************************************************
3059 
3060 
3061 //*************************************************************************************************
3067 template< typename Type // Data type of the vector
3068  , bool AF // Alignment flag
3069  , bool TF > // Transpose flag
3072 {
3073  return Iterator( v_.get() );
3074 }
3076 //*************************************************************************************************
3077 
3078 
3079 //*************************************************************************************************
3085 template< typename Type // Data type of the vector
3086  , bool AF // Alignment flag
3087  , bool TF > // Transpose flag
3090 {
3091  return ConstIterator( v_.get() );
3092 }
3094 //*************************************************************************************************
3095 
3096 
3097 //*************************************************************************************************
3103 template< typename Type // Data type of the vector
3104  , bool AF // Alignment flag
3105  , bool TF > // Transpose flag
3108 {
3109  return ConstIterator( v_.get() );
3110 }
3112 //*************************************************************************************************
3113 
3114 
3115 //*************************************************************************************************
3121 template< typename Type // Data type of the vector
3122  , bool AF // Alignment flag
3123  , bool TF > // Transpose flag
3126 {
3127  return Iterator( v_.get() + size_ );
3128 }
3130 //*************************************************************************************************
3131 
3132 
3133 //*************************************************************************************************
3139 template< typename Type // Data type of the vector
3140  , bool AF // Alignment flag
3141  , bool TF > // Transpose flag
3144 {
3145  return ConstIterator( v_.get() + size_ );
3146 }
3148 //*************************************************************************************************
3149 
3150 
3151 //*************************************************************************************************
3157 template< typename Type // Data type of the vector
3158  , bool AF // Alignment flag
3159  , bool TF > // Transpose flag
3162 {
3163  return ConstIterator( v_.get() + size_ );
3164 }
3166 //*************************************************************************************************
3167 
3168 
3169 
3170 
3171 //=================================================================================================
3172 //
3173 // ASSIGNMENT OPERATORS
3174 //
3175 //=================================================================================================
3176 
3177 //*************************************************************************************************
3205 template< typename Type // Data type of the vector
3206  , bool AF // Alignment flag
3207  , bool TF > // Transpose flag
3208 template< typename Other // Data type of the initialization array
3209  , size_t N > // Dimension of the initialization array
3210 inline CustomVector<Type,AF,padded,TF>&
3211  CustomVector<Type,AF,padded,TF>::operator=( const Other (&array)[N] )
3212 {
3213  if( size_ != N ) {
3214  BLAZE_THROW_INVALID_ARGUMENT( "Invalid array size" );
3215  }
3216 
3217  for( size_t i=0UL; i<N; ++i )
3218  v_[i] = array[i];
3219 
3220  return *this;
3221 }
3223 //*************************************************************************************************
3224 
3225 
3226 //*************************************************************************************************
3233 template< typename Type // Data type of the vector
3234  , bool AF // Alignment flag
3235  , bool TF > // Transpose flag
3236 inline CustomVector<Type,AF,padded,TF>&
3237  CustomVector<Type,AF,padded,TF>::operator=( const Type& rhs )
3238 {
3239  for( size_t i=0UL; i<size_; ++i )
3240  v_[i] = rhs;
3241  return *this;
3242 }
3244 //*************************************************************************************************
3245 
3246 
3247 //*************************************************************************************************
3258 template< typename Type // Data type of the vector
3259  , bool AF // Alignment flag
3260  , bool TF > // Transpose flag
3261 inline CustomVector<Type,AF,padded,TF>&
3262  CustomVector<Type,AF,padded,TF>::operator=( const CustomVector& rhs )
3263 {
3264  if( rhs.size() != size_ ) {
3265  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3266  }
3267 
3268  smpAssign( *this, ~rhs );
3269 
3270  return *this;
3271 }
3273 //*************************************************************************************************
3274 
3275 
3276 //*************************************************************************************************
3287 template< typename Type // Data type of the vector
3288  , bool AF // Alignment flag
3289  , bool TF > // Transpose flag
3290 template< typename VT > // Type of the right-hand side vector
3291 inline CustomVector<Type,AF,padded,TF>&
3292  CustomVector<Type,AF,padded,TF>::operator=( const Vector<VT,TF>& rhs )
3293 {
3294  if( (~rhs).size() != size_ ) {
3295  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3296  }
3297 
3298  if( (~rhs).canAlias( this ) ) {
3299  const typename VT::ResultType tmp( ~rhs );
3300  smpAssign( *this, tmp );
3301  }
3302  else {
3303  if( IsSparseVector<VT>::value )
3304  reset();
3305  smpAssign( *this, ~rhs );
3306  }
3307 
3308  return *this;
3309 }
3311 //*************************************************************************************************
3312 
3313 
3314 //*************************************************************************************************
3325 template< typename Type // Data type of the vector
3326  , bool AF // Alignment flag
3327  , bool TF > // Transpose flag
3328 template< typename VT > // Type of the right-hand side vector
3329 inline CustomVector<Type,AF,padded,TF>&
3330  CustomVector<Type,AF,padded,TF>::operator+=( const Vector<VT,TF>& rhs )
3331 {
3332  if( (~rhs).size() != size_ ) {
3333  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3334  }
3335 
3336  if( (~rhs).canAlias( this ) ) {
3337  const typename VT::ResultType tmp( ~rhs );
3338  smpAddAssign( *this, tmp );
3339  }
3340  else {
3341  smpAddAssign( *this, ~rhs );
3342  }
3343 
3344  return *this;
3345 }
3347 //*************************************************************************************************
3348 
3349 
3350 //*************************************************************************************************
3362 template< typename Type // Data type of the vector
3363  , bool AF // Alignment flag
3364  , bool TF > // Transpose flag
3365 template< typename VT > // Type of the right-hand side vector
3366 inline CustomVector<Type,AF,padded,TF>&
3367  CustomVector<Type,AF,padded,TF>::operator-=( const Vector<VT,TF>& rhs )
3368 {
3369  if( (~rhs).size() != size_ ) {
3370  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3371  }
3372 
3373  if( (~rhs).canAlias( this ) ) {
3374  const typename VT::ResultType tmp( ~rhs );
3375  smpSubAssign( *this, tmp );
3376  }
3377  else {
3378  smpSubAssign( *this, ~rhs );
3379  }
3380 
3381  return *this;
3382 }
3384 //*************************************************************************************************
3385 
3386 
3387 //*************************************************************************************************
3399 template< typename Type // Data type of the vector
3400  , bool AF // Alignment flag
3401  , bool TF > // Transpose flag
3402 template< typename VT > // Type of the right-hand side vector
3403 inline CustomVector<Type,AF,padded,TF>&
3404  CustomVector<Type,AF,padded,TF>::operator*=( const Vector<VT,TF>& rhs )
3405 {
3408 
3409  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
3410 
3413 
3414  if( (~rhs).size() != size_ ) {
3415  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3416  }
3417 
3418  if( IsSparseVector<VT>::value || (~rhs).canAlias( this ) ) {
3419  const MultType tmp( *this * (~rhs) );
3420  this->operator=( tmp );
3421  }
3422  else {
3423  smpMultAssign( *this, ~rhs );
3424  }
3425 
3426  return *this;
3427 }
3429 //*************************************************************************************************
3430 
3431 
3432 //*************************************************************************************************
3440 template< typename Type // Data type of the vector
3441  , bool AF // Alignment flag
3442  , bool TF > // Transpose flag
3443 template< typename Other > // Data type of the right-hand side scalar
3444 inline typename EnableIf< IsNumeric<Other>, CustomVector<Type,AF,padded,TF> >::Type&
3445  CustomVector<Type,AF,padded,TF>::operator*=( Other rhs )
3446 {
3447  smpAssign( *this, (*this) * rhs );
3448  return *this;
3449 }
3451 //*************************************************************************************************
3452 
3453 
3454 //*************************************************************************************************
3464 template< typename Type // Data type of the vector
3465  , bool AF // Alignment flag
3466  , bool TF > // Transpose flag
3467 template< typename Other > // Data type of the right-hand side scalar
3468 inline typename EnableIf< IsNumeric<Other>, CustomVector<Type,AF,padded,TF> >::Type&
3469  CustomVector<Type,AF,padded,TF>::operator/=( Other rhs )
3470 {
3471  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3472 
3473  smpAssign( *this, (*this) / rhs );
3474  return *this;
3475 }
3477 //*************************************************************************************************
3478 
3479 
3480 
3481 
3482 //=================================================================================================
3483 //
3484 // UTILITY FUNCTIONS
3485 //
3486 //=================================================================================================
3487 
3488 //*************************************************************************************************
3494 template< typename Type // Data type of the vector
3495  , bool AF // Alignment flag
3496  , bool TF > // Transpose flag
3497 inline size_t CustomVector<Type,AF,padded,TF>::size() const
3498 {
3499  return size_;
3500 }
3502 //*************************************************************************************************
3503 
3504 
3505 //*************************************************************************************************
3511 template< typename Type // Data type of the vector
3512  , bool AF // Alignment flag
3513  , bool TF > // Transpose flag
3514 inline size_t CustomVector<Type,AF,padded,TF>::capacity() const
3515 {
3516  return capacity_;
3517 }
3519 //*************************************************************************************************
3520 
3521 
3522 //*************************************************************************************************
3531 template< typename Type // Data type of the vector
3532  , bool AF // Alignment flag
3533  , bool TF > // Transpose flag
3534 inline size_t CustomVector<Type,AF,padded,TF>::nonZeros() const
3535 {
3536  size_t nonzeros( 0 );
3537 
3538  for( size_t i=0UL; i<size_; ++i ) {
3539  if( !isDefault( v_[i] ) )
3540  ++nonzeros;
3541  }
3542 
3543  return nonzeros;
3544 }
3546 //*************************************************************************************************
3547 
3548 
3549 //*************************************************************************************************
3555 template< typename Type // Data type of the vector
3556  , bool AF // Alignment flag
3557  , bool TF > // Transpose flag
3559 {
3560  using blaze::clear;
3561  for( size_t i=0UL; i<size_; ++i )
3562  clear( v_[i] );
3563 }
3565 //*************************************************************************************************
3566 
3567 
3568 //*************************************************************************************************
3577 template< typename Type // Data type of the vector
3578  , bool AF // Alignment flag
3579  , bool TF > // Transpose flag
3581 {
3582  size_ = 0UL;
3583  capacity_ = 0UL;
3584  v_.reset();
3585 }
3587 //*************************************************************************************************
3588 
3589 
3590 //*************************************************************************************************
3597 template< typename Type // Data type of the vector
3598  , bool AF // Alignment flag
3599  , bool TF > // Transpose flag
3600 template< typename Other > // Data type of the scalar value
3601 inline CustomVector<Type,AF,padded,TF>&
3602  CustomVector<Type,AF,padded,TF>::scale( const Other& scalar )
3603 {
3604  for( size_t i=0UL; i<size_; ++i )
3605  v_[i] *= scalar;
3606  return *this;
3607 }
3609 //*************************************************************************************************
3610 
3611 
3612 //*************************************************************************************************
3620 template< typename Type // Data type of the vector
3621  , bool AF // Alignment flag
3622  , bool TF > // Transpose flag
3623 inline void CustomVector<Type,AF,padded,TF>::swap( CustomVector& v ) /* throw() */
3624 {
3625  using std::swap;
3626 
3627  swap( size_, v.size_ );
3628  swap( capacity_, v.capacity_ );
3629  swap( v_, v.v_ );
3630 }
3632 //*************************************************************************************************
3633 
3634 
3635 
3636 
3637 //=================================================================================================
3638 //
3639 // RESOURCE MANAGEMENT FUNCTIONS
3640 //
3641 //=================================================================================================
3642 
3643 //*************************************************************************************************
3666 template< typename Type // Data type of the vector
3667  , bool AF // Alignment flag
3668  , bool TF > // Transpose flag
3669 inline void CustomVector<Type,AF,padded,TF>::reset( Type* ptr, size_t n, size_t nn )
3670 {
3671  CustomVector tmp( ptr, n, nn );
3672  swap( tmp );
3673 }
3675 //*************************************************************************************************
3676 
3677 
3678 //*************************************************************************************************
3701 template< typename Type // Data type of the vector
3702  , bool AF // Alignment flag
3703  , bool TF > // Transpose flag
3704 template< typename Deleter > // Type of the custom deleter
3705 inline void CustomVector<Type,AF,padded,TF>::reset( Type* ptr, size_t n, size_t nn, Deleter d )
3706 {
3707  CustomVector tmp( ptr, n, nn, d );
3708  swap( tmp );
3709 }
3711 //*************************************************************************************************
3712 
3713 
3714 
3715 
3716 //=================================================================================================
3717 //
3718 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3719 //
3720 //=================================================================================================
3721 
3722 //*************************************************************************************************
3733 template< typename Type // Data type of the vector
3734  , bool AF // Alignment flag
3735  , bool TF > // Transpose flag
3736 template< typename Other > // Data type of the foreign expression
3737 inline bool CustomVector<Type,AF,padded,TF>::canAlias( const Other* alias ) const
3738 {
3739  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3740 }
3742 //*************************************************************************************************
3743 
3744 
3745 //*************************************************************************************************
3756 template< typename Type // Data type of the vector
3757  , bool AF // Alignment flag
3758  , bool TF > // Transpose flag
3759 template< typename Other > // Data type of the foreign expression
3760 inline bool CustomVector<Type,AF,padded,TF>::isAliased( const Other* alias ) const
3761 {
3762  return static_cast<const void*>( this ) == static_cast<const void*>( alias );
3763 }
3765 //*************************************************************************************************
3766 
3767 
3768 //*************************************************************************************************
3778 template< typename Type // Data type of the vector
3779  , bool AF // Alignment flag
3780  , bool TF > // Transpose flag
3782 {
3783  return ( AF || checkAlignment( v_.get() ) );
3784 }
3786 //*************************************************************************************************
3787 
3788 
3789 //*************************************************************************************************
3800 template< typename Type // Data type of the vector
3801  , bool AF // Alignment flag
3802  , bool TF > // Transpose flag
3804 {
3805  return ( size() > SMP_DVECASSIGN_THRESHOLD );
3806 }
3808 //*************************************************************************************************
3809 
3810 
3811 //*************************************************************************************************
3825 template< typename Type // Data type of the vector
3826  , bool AF // Alignment flag
3827  , bool TF > // Transpose flag
3828 BLAZE_ALWAYS_INLINE typename CustomVector<Type,AF,padded,TF>::IntrinsicType
3829  CustomVector<Type,AF,padded,TF>::load( size_t index ) const
3830 {
3831  if( AF )
3832  return loada( index );
3833  else
3834  return loadu( index );
3835 }
3837 //*************************************************************************************************
3838 
3839 
3840 //*************************************************************************************************
3854 template< typename Type // Data type of the vector
3855  , bool AF // Alignment flag
3856  , bool TF > // Transpose flag
3857 BLAZE_ALWAYS_INLINE typename CustomVector<Type,AF,padded,TF>::IntrinsicType
3858  CustomVector<Type,AF,padded,TF>::loada( size_t index ) const
3859 {
3860  using blaze::loada;
3861 
3863 
3864  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
3865  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
3866  BLAZE_INTERNAL_ASSERT( !AF || index % IT::size == 0UL, "Invalid vector access index" );
3867  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
3868 
3869  return loada( v_.get()+index );
3870 }
3872 //*************************************************************************************************
3873 
3874 
3875 //*************************************************************************************************
3889 template< typename Type // Data type of the vector
3890  , bool AF // Alignment flag
3891  , bool TF > // Transpose flag
3892 BLAZE_ALWAYS_INLINE typename CustomVector<Type,AF,padded,TF>::IntrinsicType
3893  CustomVector<Type,AF,padded,TF>::loadu( size_t index ) const
3894 {
3895  using blaze::loadu;
3896 
3898 
3899  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
3900  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
3901 
3902  return loadu( v_.get()+index );
3903 }
3905 //*************************************************************************************************
3906 
3907 
3908 //*************************************************************************************************
3923 template< typename Type // Data type of the vector
3924  , bool AF // Alignment flag
3925  , bool TF > // Transpose flag
3927  CustomVector<Type,AF,padded,TF>::store( size_t index, const IntrinsicType& value )
3928 {
3929  if( AF )
3930  storea( index, value );
3931  else
3932  storeu( index, value );
3933 }
3935 //*************************************************************************************************
3936 
3937 
3938 //*************************************************************************************************
3953 template< typename Type // Data type of the vector
3954  , bool AF // Alignment flag
3955  , bool TF > // Transpose flag
3957  CustomVector<Type,AF,padded,TF>::storea( size_t index, const IntrinsicType& value )
3958 {
3959  using blaze::storea;
3960 
3962 
3963  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
3964  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
3965  BLAZE_INTERNAL_ASSERT( !AF || index % IT::size == 0UL, "Invalid vector access index" );
3966  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
3967 
3968  storea( v_.get()+index, value );
3969 }
3971 //*************************************************************************************************
3972 
3973 
3974 //*************************************************************************************************
3989 template< typename Type // Data type of the vector
3990  , bool AF // Alignment flag
3991  , bool TF > // Transpose flag
3993  CustomVector<Type,AF,padded,TF>::storeu( size_t index, const IntrinsicType& value )
3994 {
3995  using blaze::storeu;
3996 
3998 
3999  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
4000  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
4001 
4002  storeu( v_.get()+index, value );
4003 }
4005 //*************************************************************************************************
4006 
4007 
4008 //*************************************************************************************************
4023 template< typename Type // Data type of the vector
4024  , bool AF // Alignment flag
4025  , bool TF > // Transpose flag
4027  CustomVector<Type,AF,padded,TF>::stream( size_t index, const IntrinsicType& value )
4028 {
4029  using blaze::stream;
4030 
4032 
4033  BLAZE_INTERNAL_ASSERT( index < size_, "Invalid vector access index" );
4034  BLAZE_INTERNAL_ASSERT( index + IT::size <= capacity_, "Invalid vector access index" );
4035  BLAZE_INTERNAL_ASSERT( checkAlignment( v_.get()+index ), "Invalid vector access index" );
4036 
4037  stream( v_.get()+index, value );
4038 }
4040 //*************************************************************************************************
4041 
4042 
4043 //*************************************************************************************************
4055 template< typename Type // Data type of the vector
4056  , bool AF // Alignment flag
4057  , bool TF > // Transpose flag
4058 template< typename VT > // Type of the right-hand side dense vector
4059 inline typename DisableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
4060  CustomVector<Type,AF,padded,TF>::assign( const DenseVector<VT,TF>& rhs )
4061 {
4062  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4063 
4064  const size_t ipos( size_ & size_t(-2) );
4065  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
4066 
4067  for( size_t i=0UL; i<ipos; i+=2UL ) {
4068  v_[i ] = (~rhs)[i ];
4069  v_[i+1UL] = (~rhs)[i+1UL];
4070  }
4071  if( ipos < (~rhs).size() )
4072  v_[ipos] = (~rhs)[ipos];
4073 }
4075 //*************************************************************************************************
4076 
4077 
4078 //*************************************************************************************************
4090 template< typename Type // Data type of the vector
4091  , bool AF // Alignment flag
4092  , bool TF > // Transpose flag
4093 template< typename VT > // Type of the right-hand side dense vector
4094 inline typename EnableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedAssign<VT> >::Type
4095  CustomVector<Type,AF,padded,TF>::assign( const DenseVector<VT,TF>& rhs )
4096 {
4098 
4099  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4100 
4101  const bool remainder( !IsPadded<VT>::value );
4102 
4103  const size_t ipos( ( remainder )?( size_ & size_t(-IT::size) ):( size_ ) );
4104  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
4105 
4106  if( AF && useStreaming && size_ > ( cacheSize/( sizeof(Type) * 3UL ) ) && !(~rhs).isAliased( this ) )
4107  {
4108  size_t i( 0UL );
4109 
4110  for( ; i<ipos; i+=IT::size ) {
4111  stream( i, (~rhs).load(i) );
4112  }
4113  for( ; remainder && i<size_; ++i ) {
4114  v_[i] = (~rhs)[i];
4115  }
4116  }
4117  else
4118  {
4119  const size_t i4way( size_ & size_t(-IT::size*4) );
4120  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
4121  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
4122 
4123  size_t i( 0UL );
4124  typename VT::ConstIterator it( (~rhs).begin() );
4125 
4126  for( ; i<i4way; i+=IT::size*4UL ) {
4127  store( i , it.load() ); it += IT::size;
4128  store( i+IT::size , it.load() ); it += IT::size;
4129  store( i+IT::size*2UL, it.load() ); it += IT::size;
4130  store( i+IT::size*3UL, it.load() ); it += IT::size;
4131  }
4132  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4133  store( i, it.load() );
4134  }
4135  for( ; remainder && i<size_; ++i, ++it ) {
4136  v_[i] = *it;
4137  }
4138  }
4139 }
4141 //*************************************************************************************************
4142 
4143 
4144 //*************************************************************************************************
4156 template< typename Type // Data type of the vector
4157  , bool AF // Alignment flag
4158  , bool TF > // Transpose flag
4159 template< typename VT > // Type of the right-hand side sparse vector
4160 inline void CustomVector<Type,AF,padded,TF>::assign( const SparseVector<VT,TF>& rhs )
4161 {
4162  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4163 
4164  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4165  v_[element->index()] = element->value();
4166 }
4168 //*************************************************************************************************
4169 
4170 
4171 //*************************************************************************************************
4183 template< typename Type // Data type of the vector
4184  , bool AF // Alignment flag
4185  , bool TF > // Transpose flag
4186 template< typename VT > // Type of the right-hand side dense vector
4187 inline typename DisableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
4188  CustomVector<Type,AF,padded,TF>::addAssign( const DenseVector<VT,TF>& rhs )
4189 {
4190  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4191 
4192  const size_t ipos( size_ & size_t(-2) );
4193  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
4194 
4195  for( size_t i=0UL; i<ipos; i+=2UL ) {
4196  v_[i ] += (~rhs)[i ];
4197  v_[i+1UL] += (~rhs)[i+1UL];
4198  }
4199  if( ipos < (~rhs).size() )
4200  v_[ipos] += (~rhs)[ipos];
4201 }
4203 //*************************************************************************************************
4204 
4205 
4206 //*************************************************************************************************
4218 template< typename Type // Data type of the vector
4219  , bool AF // Alignment flag
4220  , bool TF > // Transpose flag
4221 template< typename VT > // Type of the right-hand side dense vector
4222 inline typename EnableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT> >::Type
4223  CustomVector<Type,AF,padded,TF>::addAssign( const DenseVector<VT,TF>& rhs )
4224 {
4226 
4227  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4228 
4229  const bool remainder( !IsPadded<VT>::value );
4230 
4231  const size_t ipos( ( remainder )?( size_ & size_t(-IT::size) ):( size_ ) );
4232  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
4233 
4234  const size_t i4way( size_ & size_t(-IT::size*4) );
4235  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
4236  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
4237 
4238  size_t i( 0UL );
4239  typename VT::ConstIterator it( (~rhs).begin() );
4240 
4241  for( ; i<i4way; i+=IT::size*4UL ) {
4242  store( i , load(i ) + it.load() ); it += IT::size;
4243  store( i+IT::size , load(i+IT::size ) + it.load() ); it += IT::size;
4244  store( i+IT::size*2UL, load(i+IT::size*2UL) + it.load() ); it += IT::size;
4245  store( i+IT::size*3UL, load(i+IT::size*3UL) + it.load() ); it += IT::size;
4246  }
4247  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4248  store( i, load(i) + it.load() );
4249  }
4250  for( ; remainder && i<size_; ++i, ++it ) {
4251  v_[i] += *it;
4252  }
4253 }
4255 //*************************************************************************************************
4256 
4257 
4258 //*************************************************************************************************
4270 template< typename Type // Data type of the vector
4271  , bool AF // Alignment flag
4272  , bool TF > // Transpose flag
4273 template< typename VT > // Type of the right-hand side sparse vector
4274 inline void CustomVector<Type,AF,padded,TF>::addAssign( const SparseVector<VT,TF>& rhs )
4275 {
4276  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4277 
4278  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4279  v_[element->index()] += element->value();
4280 }
4282 //*************************************************************************************************
4283 
4284 
4285 //*************************************************************************************************
4297 template< typename Type // Data type of the vector
4298  , bool AF // Alignment flag
4299  , bool TF > // Transpose flag
4300 template< typename VT > // Type of the right-hand side dense vector
4301 inline typename DisableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
4302  CustomVector<Type,AF,padded,TF>::subAssign( const DenseVector<VT,TF>& rhs )
4303 {
4304  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4305 
4306  const size_t ipos( size_ & size_t(-2) );
4307  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
4308 
4309  for( size_t i=0UL; i<ipos; i+=2UL ) {
4310  v_[i ] -= (~rhs)[i ];
4311  v_[i+1UL] -= (~rhs)[i+1UL];
4312  }
4313  if( ipos < (~rhs).size() )
4314  v_[ipos] -= (~rhs)[ipos];
4315 }
4317 //*************************************************************************************************
4318 
4319 
4320 //*************************************************************************************************
4332 template< typename Type // Data type of the vector
4333  , bool AF // Alignment flag
4334  , bool TF > // Transpose flag
4335 template< typename VT > // Type of the right-hand side dense vector
4336 inline typename EnableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT> >::Type
4337  CustomVector<Type,AF,padded,TF>::subAssign( const DenseVector<VT,TF>& rhs )
4338 {
4340 
4341  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4342 
4343  const bool remainder( !IsPadded<VT>::value );
4344 
4345  const size_t ipos( ( remainder )?( size_ & size_t(-IT::size) ):( size_ ) );
4346  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
4347 
4348  const size_t i4way( size_ & size_t(-IT::size*4) );
4349  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
4350  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
4351 
4352  size_t i( 0UL );
4353  typename VT::ConstIterator it( (~rhs).begin() );
4354 
4355  for( ; i<i4way; i+=IT::size*4UL ) {
4356  store( i , load(i ) - it.load() ); it += IT::size;
4357  store( i+IT::size , load(i+IT::size ) - it.load() ); it += IT::size;
4358  store( i+IT::size*2UL, load(i+IT::size*2UL) - it.load() ); it += IT::size;
4359  store( i+IT::size*3UL, load(i+IT::size*3UL) - it.load() ); it += IT::size;
4360  }
4361  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4362  store( i, load(i) - it.load() );
4363  }
4364  for( ; remainder && i<size_; ++i, ++it ) {
4365  v_[i] -= *it;
4366  }
4367 }
4369 //*************************************************************************************************
4370 
4371 
4372 //*************************************************************************************************
4384 template< typename Type // Data type of the vector
4385  , bool AF // Alignment flag
4386  , bool TF > // Transpose flag
4387 template< typename VT > // Type of the right-hand side sparse vector
4388 inline void CustomVector<Type,AF,padded,TF>::subAssign( const SparseVector<VT,TF>& rhs )
4389 {
4390  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4391 
4392  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4393  v_[element->index()] -= element->value();
4394 }
4396 //*************************************************************************************************
4397 
4398 
4399 //*************************************************************************************************
4411 template< typename Type // Data type of the vector
4412  , bool AF // Alignment flag
4413  , bool TF > // Transpose flag
4414 template< typename VT > // Type of the right-hand side dense vector
4415 inline typename DisableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
4416  CustomVector<Type,AF,padded,TF>::multAssign( const DenseVector<VT,TF>& rhs )
4417 {
4418  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4419 
4420  const size_t ipos( size_ & size_t(-2) );
4421  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % 2UL ) ) == ipos, "Invalid end calculation" );
4422 
4423  for( size_t i=0UL; i<ipos; i+=2UL ) {
4424  v_[i ] *= (~rhs)[i ];
4425  v_[i+1UL] *= (~rhs)[i+1UL];
4426  }
4427  if( ipos < (~rhs).size() )
4428  v_[ipos] *= (~rhs)[ipos];
4429 }
4431 //*************************************************************************************************
4432 
4433 
4434 //*************************************************************************************************
4446 template< typename Type // Data type of the vector
4447  , bool AF // Alignment flag
4448  , bool TF > // Transpose flag
4449 template< typename VT > // Type of the right-hand side dense vector
4450 inline typename EnableIf< typename CustomVector<Type,AF,padded,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT> >::Type
4451  CustomVector<Type,AF,padded,TF>::multAssign( const DenseVector<VT,TF>& rhs )
4452 {
4454 
4455  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4456 
4457  const bool remainder( !IsPadded<VT>::value );
4458 
4459  const size_t ipos( ( remainder )?( size_ & size_t(-IT::size) ):( size_ ) );
4460  BLAZE_INTERNAL_ASSERT( !remainder || ( size_ - ( size_ % IT::size ) ) == ipos, "Invalid end calculation" );
4461 
4462  const size_t i4way( size_ & size_t(-IT::size*4) );
4463  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size*4UL) ) ) == i4way, "Invalid end calculation" );
4464  BLAZE_INTERNAL_ASSERT( i4way <= ipos, "Invalid end calculation" );
4465 
4466  size_t i( 0UL );
4467  typename VT::ConstIterator it( (~rhs).begin() );
4468 
4469  for( ; i<i4way; i+=IT::size*4UL ) {
4470  store( i , load(i ) * it.load() ); it += IT::size;
4471  store( i+IT::size , load(i+IT::size ) * it.load() ); it += IT::size;
4472  store( i+IT::size*2UL, load(i+IT::size*2UL) * it.load() ); it += IT::size;
4473  store( i+IT::size*3UL, load(i+IT::size*3UL) * it.load() ); it += IT::size;
4474  }
4475  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4476  store( i, load(i) * it.load() );
4477  }
4478  for( ; remainder && i<size_; ++i, ++it ) {
4479  v_[i] *= *it;
4480  }
4481 }
4483 //*************************************************************************************************
4484 
4485 
4486 //*************************************************************************************************
4498 template< typename Type // Data type of the vector
4499  , bool AF // Alignment flag
4500  , bool TF > // Transpose flag
4501 template< typename VT > // Type of the right-hand side sparse vector
4502 inline void CustomVector<Type,AF,padded,TF>::multAssign( const SparseVector<VT,TF>& rhs )
4503 {
4504  BLAZE_INTERNAL_ASSERT( size_ == (~rhs).size(), "Invalid vector sizes" );
4505 
4506  const DynamicVector<Type,TF> tmp( serial( *this ) );
4507 
4508  reset();
4509 
4510  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4511  v_[element->index()] = tmp[element->index()] * element->value();
4512 }
4514 //*************************************************************************************************
4515 
4516 
4517 
4518 
4519 
4520 
4521 
4522 
4523 //=================================================================================================
4524 //
4525 // CUSTOMVECTOR OPERATORS
4526 //
4527 //=================================================================================================
4528 
4529 //*************************************************************************************************
4532 template< typename Type, bool AF, bool PF, bool TF >
4533 inline void reset( CustomVector<Type,AF,PF,TF>& v );
4534 
4535 template< typename Type, bool AF, bool PF, bool TF >
4536 inline void clear( CustomVector<Type,AF,PF,TF>& v );
4537 
4538 template< typename Type, bool AF, bool PF, bool TF >
4539 inline bool isDefault( const CustomVector<Type,AF,PF,TF>& v );
4540 
4541 template< typename Type, bool AF, bool PF, bool TF >
4542 inline bool isIntact( const CustomVector<Type,AF,PF,TF>& v );
4543 
4544 template< typename Type, bool AF, bool PF, bool TF >
4545 inline void swap( CustomVector<Type,AF,PF,TF>& a, CustomVector<Type,AF,PF,TF>& b ) /* throw() */;
4546 
4547 template< typename Type, bool AF, bool PF, bool TF >
4548 inline void move( CustomVector<Type,AF,PF,TF>& dst, CustomVector<Type,AF,PF,TF>& src ) /* throw() */;
4550 //*************************************************************************************************
4551 
4552 
4553 //*************************************************************************************************
4560 template< typename Type // Data type of the vector
4561  , bool AF // Alignment flag
4562  , bool PF // Padding flag
4563  , bool TF > // Transpose flag
4565 {
4566  v.reset();
4567 }
4568 //*************************************************************************************************
4569 
4570 
4571 //*************************************************************************************************
4578 template< typename Type // Data type of the vector
4579  , bool AF // Alignment flag
4580  , bool PF // Padding flag
4581  , bool TF > // Transpose flag
4583 {
4584  v.clear();
4585 }
4586 //*************************************************************************************************
4587 
4588 
4589 //*************************************************************************************************
4610 template< typename Type // Data type of the vector
4611  , bool AF // Alignment flag
4612  , bool PF // Padding flag
4613  , bool TF > // Transpose flag
4615 {
4616  return ( v.size() == 0UL );
4617 }
4618 //*************************************************************************************************
4619 
4620 
4621 //*************************************************************************************************
4642 template< typename Type // Data type of the vector
4643  , bool AF // Alignment flag
4644  , bool PF // Padding flag
4645  , bool TF > // Transpose flag
4646 inline bool isIntact( const CustomVector<Type,AF,PF,TF>& v )
4647 {
4648  return ( v.size() <= v.capacity() );
4649 }
4650 //*************************************************************************************************
4651 
4652 
4653 //*************************************************************************************************
4662 template< typename Type // Data type of the vector
4663  , bool AF // Alignment flag
4664  , bool PF // Padding flag
4665  , bool TF > // Transpose flag
4667 {
4668  a.swap( b );
4669 }
4670 //*************************************************************************************************
4671 
4672 
4673 //*************************************************************************************************
4682 template< typename Type // Data type of the vector
4683  , bool AF // Alignment flag
4684  , bool PF // Padding flag
4685  , bool TF > // Transpose flag
4686 inline void move( CustomVector<Type,AF,PF,TF>& dst, CustomVector<Type,AF,PF,TF>& src ) /* throw() */
4687 {
4688  dst.swap( src );
4689 }
4690 //*************************************************************************************************
4691 
4692 
4693 
4694 
4695 //=================================================================================================
4696 //
4697 // HASCONSTDATAACCESS SPECIALIZATIONS
4698 //
4699 //=================================================================================================
4700 
4701 //*************************************************************************************************
4703 template< typename T, bool AF, bool PF, bool TF >
4704 struct HasConstDataAccess< CustomVector<T,AF,PF,TF> > : public IsTrue<true>
4705 {};
4707 //*************************************************************************************************
4708 
4709 
4710 
4711 
4712 //=================================================================================================
4713 //
4714 // HASMUTABLEDATAACCESS SPECIALIZATIONS
4715 //
4716 //=================================================================================================
4717 
4718 //*************************************************************************************************
4720 template< typename T, bool AF, bool PF, bool TF >
4721 struct HasMutableDataAccess< CustomVector<T,AF,PF,TF> > : public IsTrue<true>
4722 {};
4724 //*************************************************************************************************
4725 
4726 
4727 
4728 
4729 //=================================================================================================
4730 //
4731 // ISCUSTOM SPECIALIZATIONS
4732 //
4733 //=================================================================================================
4734 
4735 //*************************************************************************************************
4737 template< typename T, bool AF, bool PF, bool TF >
4738 struct IsCustom< CustomVector<T,AF,PF,TF> > : public IsTrue<true>
4739 {};
4741 //*************************************************************************************************
4742 
4743 
4744 
4745 
4746 //=================================================================================================
4747 //
4748 // ISALIGNED SPECIALIZATIONS
4749 //
4750 //=================================================================================================
4751 
4752 //*************************************************************************************************
4754 template< typename T, bool PF, bool TF >
4755 struct IsAligned< CustomVector<T,aligned,PF,TF> > : public IsTrue<true>
4756 {};
4758 //*************************************************************************************************
4759 
4760 
4761 
4762 
4763 //=================================================================================================
4764 //
4765 // ISPADDED SPECIALIZATIONS
4766 //
4767 //=================================================================================================
4768 
4769 //*************************************************************************************************
4771 template< typename T, bool AF, bool TF >
4772 struct IsPadded< CustomVector<T,AF,padded,TF> > : public IsTrue<true>
4773 {};
4775 //*************************************************************************************************
4776 
4777 
4778 
4779 
4780 //=================================================================================================
4781 //
4782 // ADDTRAIT SPECIALIZATIONS
4783 //
4784 //=================================================================================================
4785 
4786 //*************************************************************************************************
4788 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4789 struct AddTrait< CustomVector<T1,AF,PF,TF>, StaticVector<T2,N,TF> >
4790 {
4791  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
4792 };
4793 
4794 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4795 struct AddTrait< StaticVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4796 {
4797  typedef StaticVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
4798 };
4799 
4800 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4801 struct AddTrait< CustomVector<T1,AF,PF,TF>, HybridVector<T2,N,TF> >
4802 {
4803  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
4804 };
4805 
4806 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4807 struct AddTrait< HybridVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4808 {
4809  typedef HybridVector< typename AddTrait<T1,T2>::Type, N, TF > Type;
4810 };
4811 
4812 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
4813 struct AddTrait< CustomVector<T1,AF,PF,TF>, DynamicVector<T2,TF> >
4814 {
4815  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
4816 };
4817 
4818 template< typename T1, bool TF, typename T2, bool AF, bool PF >
4819 struct AddTrait< DynamicVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
4820 {
4821  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
4822 };
4823 
4824 template< typename T1, bool AF1, bool PF1, bool TF, typename T2, bool AF2, bool PF2 >
4825 struct AddTrait< CustomVector<T1,AF1,PF1,TF>, CustomVector<T2,AF2,PF2,TF> >
4826 {
4827  typedef DynamicVector< typename AddTrait<T1,T2>::Type, TF > Type;
4828 };
4830 //*************************************************************************************************
4831 
4832 
4833 
4834 
4835 //=================================================================================================
4836 //
4837 // SUBTRAIT SPECIALIZATIONS
4838 //
4839 //=================================================================================================
4840 
4841 //*************************************************************************************************
4843 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4844 struct SubTrait< CustomVector<T1,AF,PF,TF>, StaticVector<T2,N,TF> >
4845 {
4846  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
4847 };
4848 
4849 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4850 struct SubTrait< StaticVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4851 {
4852  typedef StaticVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
4853 };
4854 
4855 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4856 struct SubTrait< CustomVector<T1,AF,PF,TF>, HybridVector<T2,N,TF> >
4857 {
4858  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
4859 };
4860 
4861 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4862 struct SubTrait< HybridVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4863 {
4864  typedef HybridVector< typename SubTrait<T1,T2>::Type, N, TF > Type;
4865 };
4866 
4867 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
4868 struct SubTrait< CustomVector<T1,AF,PF,TF>, DynamicVector<T2,TF> >
4869 {
4870  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
4871 };
4872 
4873 template< typename T1, bool TF, typename T2, bool AF, bool PF >
4874 struct SubTrait< DynamicVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
4875 {
4876  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
4877 };
4878 
4879 template< typename T1, bool AF1, bool PF1, bool TF, typename T2, bool AF2, bool PF2 >
4880 struct SubTrait< CustomVector<T1,AF1,PF1,TF>, CustomVector<T2,AF2,PF2,TF> >
4881 {
4882  typedef DynamicVector< typename SubTrait<T1,T2>::Type, TF > Type;
4883 };
4885 //*************************************************************************************************
4886 
4887 
4888 
4889 
4890 //=================================================================================================
4891 //
4892 // MULTTRAIT SPECIALIZATIONS
4893 //
4894 //=================================================================================================
4895 
4896 //*************************************************************************************************
4898 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
4899 struct MultTrait< CustomVector<T1,AF,PF,TF>, T2, typename EnableIf< IsNumeric<T2> >::Type >
4900 {
4901  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
4902 };
4903 
4904 template< typename T1, typename T2, bool AF, bool PF, bool TF >
4905 struct MultTrait< T1, CustomVector<T2,AF,PF,TF>, typename EnableIf< IsNumeric<T1> >::Type >
4906 {
4907  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
4908 };
4909 
4910 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4911 struct MultTrait< CustomVector<T1,AF,PF,TF>, StaticVector<T2,N,TF> >
4912 {
4913  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
4914 };
4915 
4916 template< typename T1, bool AF, bool PF, typename T2, size_t N >
4917 struct MultTrait< CustomVector<T1,AF,PF,false>, StaticVector<T2,N,true> >
4918 {
4919  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
4920 };
4921 
4922 template< typename T1, bool AF, bool PF, typename T2, size_t N >
4923 struct MultTrait< CustomVector<T1,AF,PF,true>, StaticVector<T2,N,false> >
4924 {
4925  typedef typename MultTrait<T1,T2>::Type Type;
4926 };
4927 
4928 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4929 struct MultTrait< StaticVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4930 {
4931  typedef StaticVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
4932 };
4933 
4934 template< typename T1, size_t N, typename T2, bool AF, bool PF >
4935 struct MultTrait< StaticVector<T1,N,false>, CustomVector<T2,AF,PF,true> >
4936 {
4937  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
4938 };
4939 
4940 template< typename T1, size_t N, typename T2, bool AF, bool PF >
4941 struct MultTrait< StaticVector<T1,N,true>, CustomVector<T2,AF,PF,false> >
4942 {
4943  typedef typename MultTrait<T1,T2>::Type Type;
4944 };
4945 
4946 template< typename T1, bool AF, bool PF, bool TF, typename T2, size_t N >
4947 struct MultTrait< CustomVector<T1,AF,PF,TF>, HybridVector<T2,N,TF> >
4948 {
4949  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
4950 };
4951 
4952 template< typename T1, bool AF, bool PF, typename T2, size_t N >
4953 struct MultTrait< CustomVector<T1,AF,PF,false>, HybridVector<T2,N,true> >
4954 {
4955  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
4956 };
4957 
4958 template< typename T1, bool AF, bool PF, typename T2, size_t N >
4959 struct MultTrait< CustomVector<T1,AF,PF,true>, HybridVector<T2,N,false> >
4960 {
4961  typedef typename MultTrait<T1,T2>::Type Type;
4962 };
4963 
4964 template< typename T1, size_t N, bool TF, typename T2, bool AF, bool PF >
4965 struct MultTrait< HybridVector<T1,N,TF>, CustomVector<T2,AF,PF,TF> >
4966 {
4967  typedef HybridVector< typename MultTrait<T1,T2>::Type, N, TF > Type;
4968 };
4969 
4970 template< typename T1, size_t N, typename T2, bool AF, bool PF >
4971 struct MultTrait< HybridVector<T1,N,false>, CustomVector<T2,AF,PF,true> >
4972 {
4973  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
4974 };
4975 
4976 template< typename T1, size_t N, typename T2, bool AF, bool PF >
4977 struct MultTrait< HybridVector<T1,N,true>, CustomVector<T2,AF,PF,false> >
4978 {
4979  typedef typename MultTrait<T1,T2>::Type Type;
4980 };
4981 
4982 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
4983 struct MultTrait< CustomVector<T1,AF,PF,TF>, DynamicVector<T2,TF> >
4984 {
4985  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
4986 };
4987 
4988 template< typename T1, bool AF, bool PF, typename T2 >
4989 struct MultTrait< CustomVector<T1,AF,PF,false>, DynamicVector<T2,true> >
4990 {
4991  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
4992 };
4993 
4994 template< typename T1, bool AF, bool PF, typename T2 >
4995 struct MultTrait< CustomVector<T1,AF,PF,true>, DynamicVector<T2,false> >
4996 {
4997  typedef typename MultTrait<T1,T2>::Type Type;
4998 };
4999 
5000 template< typename T1, bool TF, typename T2, bool AF, bool PF >
5001 struct MultTrait< DynamicVector<T1,TF>, CustomVector<T2,AF,PF,TF> >
5002 {
5003  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
5004 };
5005 
5006 template< typename T1, typename T2, bool AF, bool PF >
5007 struct MultTrait< DynamicVector<T1,false>, CustomVector<T2,AF,PF,true> >
5008 {
5009  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
5010 };
5011 
5012 template< typename T1, typename T2, bool AF, bool PF >
5013 struct MultTrait< DynamicVector<T1,true>, CustomVector<T2,AF,PF,false> >
5014 {
5015  typedef typename MultTrait<T1,T2>::Type Type;
5016 };
5017 
5018 template< typename T1, bool AF1, bool PF1, bool TF, typename T2, bool AF2, bool PF2 >
5019 struct MultTrait< CustomVector<T1,AF1,PF1,TF>, CustomVector<T2,AF2,PF2,TF> >
5020 {
5021  typedef DynamicVector< typename MultTrait<T1,T2>::Type, TF > Type;
5022 };
5023 
5024 template< typename T1, bool AF1, bool PF1, typename T2, bool AF2, bool PF2 >
5025 struct MultTrait< CustomVector<T1,AF1,PF1,false>, CustomVector<T2,AF2,PF2,true> >
5026 {
5027  typedef DynamicMatrix< typename MultTrait<T1,T2>::Type, false > Type;
5028 };
5029 
5030 template< typename T1, bool AF1, bool PF1, typename T2, bool AF2, bool PF2 >
5031 struct MultTrait< CustomVector<T1,AF1,PF1,true>, CustomVector<T2,AF2,PF2,false> >
5032 {
5033  typedef typename MultTrait<T1,T2>::Type Type;
5034 };
5036 //*************************************************************************************************
5037 
5038 
5039 
5040 
5041 //=================================================================================================
5042 //
5043 // CROSSTRAIT SPECIALIZATIONS
5044 //
5045 //=================================================================================================
5046 
5047 //*************************************************************************************************
5049 template< typename T1, bool AF, bool PF, typename T2 >
5050 struct CrossTrait< CustomVector<T1,AF,PF,false>, StaticVector<T2,3UL,false> >
5051 {
5052  private:
5053  typedef typename MultTrait<T1,T2>::Type T;
5054 
5055  public:
5056  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5057 };
5058 
5059 template< typename T1, typename T2, bool AF, bool PF >
5060 struct CrossTrait< StaticVector<T1,3UL,false>, CustomVector<T2,AF,PF,false> >
5061 {
5062  private:
5063  typedef typename MultTrait<T1,T2>::Type T;
5064 
5065  public:
5066  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5067 };
5068 
5069 template< typename T1, bool AF, bool PF, typename T2, size_t N >
5070 struct CrossTrait< CustomVector<T1,AF,PF,false>, HybridVector<T2,N,false> >
5071 {
5072  private:
5073  typedef typename MultTrait<T1,T2>::Type T;
5074 
5075  public:
5076  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5077 };
5078 
5079 template< typename T1, size_t N, typename T2, bool AF, bool PF >
5080 struct CrossTrait< HybridVector<T1,N,false>, CustomVector<T2,AF,PF,false> >
5081 {
5082  private:
5083  typedef typename MultTrait<T1,T2>::Type T;
5084 
5085  public:
5086  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5087 };
5088 
5089 template< typename T1, bool AF, bool PF, typename T2 >
5090 struct CrossTrait< CustomVector<T1,AF,PF,false>, DynamicVector<T2,false> >
5091 {
5092  private:
5093  typedef typename MultTrait<T1,T2>::Type T;
5094 
5095  public:
5096  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5097 };
5098 
5099 template< typename T1, typename T2, bool AF, bool PF >
5100 struct CrossTrait< DynamicVector<T1,false>, CustomVector<T2,AF,PF,false> >
5101 {
5102  private:
5103  typedef typename MultTrait<T1,T2>::Type T;
5104 
5105  public:
5106  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5107 };
5108 
5109 template< typename T1, bool AF1, bool PF1, typename T2, bool AF2, bool PF2 >
5110 struct CrossTrait< CustomVector<T1,AF1,PF1,false>, CustomVector<T2,AF2,PF2,false> >
5111 {
5112  private:
5113  typedef typename MultTrait<T1,T2>::Type T;
5114 
5115  public:
5116  typedef StaticVector< typename SubTrait<T,T>::Type, 3UL, false > Type;
5117 };
5119 //*************************************************************************************************
5120 
5121 
5122 
5123 
5124 //=================================================================================================
5125 //
5126 // DIVTRAIT SPECIALIZATIONS
5127 //
5128 //=================================================================================================
5129 
5130 //*************************************************************************************************
5132 template< typename T1, bool AF, bool PF, bool TF, typename T2 >
5133 struct DivTrait< CustomVector<T1,AF,PF,TF>, T2, typename EnableIf< IsNumeric<T2> >::Type >
5134 {
5135  typedef DynamicVector< typename DivTrait<T1,T2>::Type, TF > Type;
5136 };
5138 //*************************************************************************************************
5139 
5140 
5141 
5142 
5143 //=================================================================================================
5144 //
5145 // SUBVECTORTRAIT SPECIALIZATIONS
5146 //
5147 //=================================================================================================
5148 
5149 //*************************************************************************************************
5151 template< typename T1, bool AF, bool PF, bool TF >
5152 struct SubvectorTrait< CustomVector<T1,AF,PF,TF> >
5153 {
5154  typedef DynamicVector<T1,TF> Type;
5155 };
5157 //*************************************************************************************************
5158 
5159 } // namespace blaze
5160 
5161 #endif
Compile time check for vectorizable types.Depending on the available instruction set (SSE...
Definition: IsVectorizable.h:118
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
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
const bool defaultTransposeFlag
The default transpose flag for all vectors of the Blaze library.This value specifies the default tran...
Definition: TransposeFlag.h:56
IT::Type IntrinsicType
Intrinsic type of the vector elements.
Definition: CustomVector.h:429
#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 AlignmentOf type trait.
Header file for the alignment flag values.
Header file for the UNUSED_PARAMETER function template.
Header file for the subtraction trait.
CustomVector()
The default constructor for CustomVector.
Definition: CustomVector.h:705
BLAZE_ALWAYS_INLINE void store(size_t index, const IntrinsicType &value)
Store of an intrinsic element of the vector.
Definition: CustomVector.h:1917
Header file for basic type definitions.
No-delete policy class.
Definition: NoDelete.h:51
Header file for the SparseVector base class.
size_t size_
The size/dimension of the custom vector.
Definition: CustomVector.h:668
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
const Type & ReturnType
Return type for expression template evaluations.
Definition: CustomVector.h:430
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:250
const Type * ConstPointer
Pointer to a constant vector value.
Definition: CustomVector.h:436
const Type & ConstReference
Reference to a constant vector value.
Definition: CustomVector.h:434
const bool aligned
Alignment flag for aligned vectors and matrices.Via this flag it is possible to specify subvectors...
Definition: AlignmentFlag.h:85
Header file for the IsSame and IsStrictlySame type traits.
const bool useStreaming
Configuration of the streaming behavior.For large vectors and matrices non-temporal stores can provid...
Definition: Optimizations.h:68
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
DynamicVector< Type,!TF > TransposeType
Transpose type for expression template evaluations.
Definition: CustomVector.h:427
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:721
Efficient implementation of an arbitrary sized vector.The DynamicVector class template is the represe...
Definition: DynamicVector.h:168
void move(CustomMatrix< Type, AF, PF, SO > &dst, CustomMatrix< Type, AF, PF, SO > &src)
Moving the contents of one custom matrix to another.
Definition: CustomMatrix.h:6085
System settings for performance optimizations.
Header file for the implementation of an arbitrarily sized vector.
Header file for the NoDelete policy classes.
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
size_t capacity_
The current capacity of the pointer array.
Definition: CompressedMatrix.h:2751
Header file for the DisableIf class template.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loadu(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loadu.h:74
Pointer data()
Low-level data access to the vector elements.
Definition: CustomVector.h:997
Header file for the IsCustom type trait.
Header file for the multiplication trait.
Header file for the clear shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Header file for nested template disabiguation.
Compile time assertion.
Iterator begin()
Returns an iterator to the first element of the custom vector.
Definition: CustomVector.h:1031
void swap(CompressedMatrix< Type, SO > &a, CompressedMatrix< Type, SO > &b)
Swapping the contents of two compressed matrices.
Definition: CompressedMatrix.h:4998
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type storeu(T *address, const simd_int16_t &value)
Unaligned store of a vector of 2-byte integral values.
Definition: Storeu.h:75
Header file for all forward declarations of the math module.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
#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
Header file for the IsSMPAssignable type trait.
BLAZE_ALWAYS_INLINE IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the vector.
Definition: CustomVector.h:1885
const bool padded
Padding flag for padded vectors and matrices.Via this flag it is possible to specify custom vectors a...
Definition: PaddingFlag.h:86
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
Header file for the DenseIterator class template.
void clear()
Clearing the vector to its default state.
Definition: CustomVector.h:1509
Header file for the subvector trait.
DenseIterator< const Type, AF > ConstIterator
Iterator over constant elements.
Definition: CustomVector.h:439
Constraint on the data type.
boost::shared_array< Type > v_
The custom array of elements.
Definition: CustomVector.h:669
size_t capacity() const
Returns the maximum capacity of the vector.
Definition: CustomVector.h:1446
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
bool isAligned() const
Returns whether the vector is properly aligned in memory.
Definition: CustomVector.h:1777
Constraint on the data type.
Efficient implementation of a customizable vector.
Definition: CustomVector.h:416
ConstIterator cend() const
Returns an iterator just past the last element of the custom vector.
Definition: CustomVector.h:1111
void reset()
Reset to the default initial values.
Definition: CustomVector.h:1488
#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
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:187
Compile time check for data types.This type trait tests whether or not the given template parameter i...
Definition: IsSMPAssignable.h:120
size_t size() const
Returns the size/dimension of the vector.
Definition: CustomVector.h:1430
DenseIterator< Type, AF > Iterator
Iterator over non-constant elements.
Definition: CustomVector.h:438
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
size_t nonZeros() const
Returns the number of non-zero elements in the vector.
Definition: CustomVector.h:1465
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
ConstIterator cbegin() const
Returns an iterator to the first element of the custom vector.
Definition: CustomVector.h:1063
bool canAlias(const Other *alias) const
Returns whether the vector can alias with the given address alias.
Definition: CustomVector.h:1735
Header file for the IsPadded type trait.
DynamicVector< Type, TF > ResultType
Result type for expression template evaluations.
Definition: CustomVector.h:426
Header file for the serial shim.
Header file for the IsVectorizable type trait.
Header file for the IsNumeric type trait.
Header file for the HasConstDataAccess type trait.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > >, simd_int16_t >::Type loada(const T *address)
Loads a vector of 2-byte integral values.
Definition: Loada.h:77
EnableIf< IsDenseMatrix< MT1 > >::Type smpSubAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP subtraction assignment of a matrix to dense matrix.
Definition: DenseMatrix.h:160
Header file for the IsSparseVector type trait.
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:1232
Rebind mechanism to obtain a CustomVector with different data/element type.
Definition: CustomVector.h:446
Type * Pointer
Pointer to a non-constant vector value.
Definition: CustomVector.h:435
Reference operator[](size_t index)
Subscript operator for the direct access to the vector elements.
Definition: CustomVector.h:906
Header file for run time assertion macros.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:98
BLAZE_ALWAYS_INLINE IntrinsicType load(size_t index) const
Load of an intrinsic element of the vector.
Definition: CustomVector.h:1823
Base template for the MultTrait class.
Definition: MultTrait.h:138
BLAZE_ALWAYS_INLINE void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the dense vector.
Definition: CustomVector.h:1979
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
IntrinsicTrait< Type > IT
Intrinsic trait for the vector element type.
Definition: CustomVector.h:420
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 bool useOptimizedKernels
Configuration switch for optimized kernels.This configuration switch enables/disables all optimized c...
Definition: Optimizations.h:84
Header file for the cache size of the target architecture.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Iterator end()
Returns an iterator just past the last element of the custom vector.
Definition: CustomVector.h:1079
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Reference at(size_t index)
Checked access to the vector elements.
Definition: CustomVector.h:951
Header file for the isDefault shim.
Type & Reference
Reference to a non-constant vector value.
Definition: CustomVector.h:433
Constraint on the data type.
Header file for the HasMutableDataAccess type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:118
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b)
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:256
Header file for the padding flag values.
Implementation of a generic iterator for dense vectors and matrices.The DenseIterator represents a ge...
Definition: DenseIterator.h:59
Header file for all intrinsic functionality.
CustomVector< ET, AF, PF, TF > Other
The type of the other CustomVector.
Definition: CustomVector.h:447
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
bool canSMPAssign() const
Returns whether the vector can be used in SMP assignments.
Definition: CustomVector.h:1798
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
Header file for the default transpose flag for all vectors of the Blaze library.
EnableIf< IsDenseMatrix< MT1 > >::Type smpAddAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the SMP addition assignment of a matrix to a dense matrix.
Definition: DenseMatrix.h:129
Header file for the alignment check function.
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
BLAZE_ALWAYS_INLINE void storea(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the vector.
Definition: CustomVector.h:1945
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
Header file for the IsTrue value trait.
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type stream(T *address, const simd_int16_t &value)
Aligned, non-temporal store of a vector of 2-byte integral values.
Definition: Stream.h:74
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
BLAZE_ALWAYS_INLINE void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the dense vector.
Definition: CustomVector.h:2011
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Rebind mechanism to obtain a CompressedMatrix with different data/element type.
Definition: CompressedMatrix.h:2599
Header file for exception macros.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:143
BLAZE_ALWAYS_INLINE IntrinsicType loada(size_t index) const
Aligned load of an intrinsic element of the vector.
Definition: CustomVector.h:1851
Type ElementType
Type of the vector elements.
Definition: CustomVector.h:428
const size_t cacheSize
Cache size of the target architecture.This setting specifies the available cache size in Byte of the ...
Definition: CacheSize.h:48
CustomVector< Type, AF, PF, TF > This
Type of this CustomVector instance.
Definition: CustomVector.h:425
bool isAliased(const Other *alias) const
Returns whether the vector is aliased with the given address alias.
Definition: CustomVector.h:1757
System settings for the inline keywords.
const CustomVector & CompositeType
Data type for composite expression templates.
Definition: CustomVector.h:431
EnableIf< IsDenseVector< VT1 > >::Type smpMultAssign(Vector< VT1, TF1 > &lhs, const Vector< VT2, TF2 > &rhs)
Default implementation of the SMP multiplication assignment of a vector to a dense vector...
Definition: DenseVector.h:189
#define BLAZE_CONSTRAINT_MUST_BE_VECTOR_WITH_TRANSPOSE_FLAG(T, TF)
Constraint on the data type.In case the given data type T is not a dense or sparse vector type and in...
Definition: TransposeFlag.h:81
Header file for the thresholds for matrix/vector and matrix/matrix multiplications.
void swap(CustomVector &v)
Swapping the contents of two vectors.
Definition: CustomVector.h:1548
#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
BLAZE_ALWAYS_INLINE EnableIf< And< IsIntegral< T >, HasSize< T, 2UL > > >::Type storea(T *address, const simd_int16_t &value)
Aligned store of a vector of 2-byte integral values.
Definition: Storea.h:78
Header file for a safe C++ NULL pointer implementation.