DenseSubvector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_DENSESUBVECTOR_H_
36 #define _BLAZE_MATH_VIEWS_DENSESUBVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
57 #include <blaze/math/Intrinsics.h>
58 #include <blaze/math/shims/Clear.h>
76 #include <blaze/system/CacheSize.h>
77 #include <blaze/system/Inline.h>
81 #include <blaze/util/Assert.h>
83 #include <blaze/util/DisableIf.h>
84 #include <blaze/util/EnableIf.h>
85 #include <blaze/util/Exception.h>
87 #include <blaze/util/mpl/If.h>
88 #include <blaze/util/mpl/Not.h>
89 #include <blaze/util/mpl/Or.h>
90 #include <blaze/util/Null.h>
91 #include <blaze/util/Template.h>
92 #include <blaze/util/Types.h>
98 
99 
100 namespace blaze {
101 
102 //=================================================================================================
103 //
104 // CLASS DEFINITION
105 //
106 //=================================================================================================
107 
108 //*************************************************************************************************
389 template< typename VT // Type of the dense vector
390  , bool AF = unaligned // Alignment flag
391  , bool TF = IsRowVector<VT>::value > // Transpose flag
392 class DenseSubvector : public DenseVector< DenseSubvector<VT,AF,TF>, TF >
393  , private Subvector
394 {
395  private:
396  //**Type definitions****************************************************************************
398  typedef typename If< IsExpression<VT>, VT, VT& >::Type Operand;
399 
402  //**********************************************************************************************
403 
404  public:
405  //**Type definitions****************************************************************************
409  typedef typename VT::ElementType ElementType;
410  typedef typename IT::Type IntrinsicType;
411  typedef typename VT::ReturnType ReturnType;
412  typedef const DenseSubvector& CompositeType;
413 
416 
418  typedef typename If< IsConst<VT>, ConstReference, typename VT::Reference >::Type Reference;
419 
421  typedef const ElementType* ConstPointer;
422 
425  , ConstPointer, ElementType* >::Type Pointer;
426  //**********************************************************************************************
427 
428  //**SubvectorIterator class definition**********************************************************
431  template< typename IteratorType > // Type of the dense vector iterator
433  {
434  public:
435  //**Type definitions*************************************************************************
437  typedef typename std::iterator_traits<IteratorType>::iterator_category IteratorCategory;
438 
440  typedef typename std::iterator_traits<IteratorType>::value_type ValueType;
441 
443  typedef typename std::iterator_traits<IteratorType>::pointer PointerType;
444 
446  typedef typename std::iterator_traits<IteratorType>::reference ReferenceType;
447 
449  typedef typename std::iterator_traits<IteratorType>::difference_type DifferenceType;
450 
451  // STL iterator requirements
452  typedef IteratorCategory iterator_category;
453  typedef ValueType value_type;
454  typedef PointerType pointer;
455  typedef ReferenceType reference;
456  typedef DifferenceType difference_type;
457  //*******************************************************************************************
458 
459  //**Constructor******************************************************************************
463  : iterator_ ( ) // Iterator to the current subvector element
464  , isAligned_( false ) // Memory alignment flag
465  {}
466  //*******************************************************************************************
467 
468  //**Constructor******************************************************************************
474  inline SubvectorIterator( IteratorType iterator, bool isMemoryAligned )
475  : iterator_ ( iterator ) // Iterator to the current subvector element
476  , isAligned_( isMemoryAligned ) // Memory alignment flag
477  {}
478  //*******************************************************************************************
479 
480  //**Constructor******************************************************************************
485  template< typename IteratorType2 >
487  : iterator_ ( it.base() ) // Iterator to the current subvector element
488  , isAligned_( it.isAligned() ) // Memory alignment flag
489  {}
490  //*******************************************************************************************
491 
492  //**Addition assignment operator*************************************************************
498  inline SubvectorIterator& operator+=( size_t inc ) {
499  iterator_ += inc;
500  return *this;
501  }
502  //*******************************************************************************************
503 
504  //**Subtraction assignment operator**********************************************************
510  inline SubvectorIterator& operator-=( size_t dec ) {
511  iterator_ -= dec;
512  return *this;
513  }
514  //*******************************************************************************************
515 
516  //**Prefix increment operator****************************************************************
522  ++iterator_;
523  return *this;
524  }
525  //*******************************************************************************************
526 
527  //**Postfix increment operator***************************************************************
532  inline const SubvectorIterator operator++( int ) {
534  }
535  //*******************************************************************************************
536 
537  //**Prefix decrement operator****************************************************************
543  --iterator_;
544  return *this;
545  }
546  //*******************************************************************************************
547 
548  //**Postfix decrement operator***************************************************************
553  inline const SubvectorIterator operator--( int ) {
555  }
556  //*******************************************************************************************
557 
558  //**Element access operator******************************************************************
563  inline ReferenceType operator*() const {
564  return *iterator_;
565  }
566  //*******************************************************************************************
567 
568  //**Load function****************************************************************************
578  inline IntrinsicType load() const {
579  return loadu();
580  }
581  //*******************************************************************************************
582 
583  //**Loada function***************************************************************************
593  inline IntrinsicType loada() const {
594  return iterator_.loada();
595  }
596  //*******************************************************************************************
597 
598  //**Loadu function***************************************************************************
608  inline IntrinsicType loadu() const {
609  if( isAligned_ ) {
610  return iterator_.loada();
611  }
612  else {
613  return iterator_.loadu();
614  }
615  }
616  //*******************************************************************************************
617 
618  //**Equality operator************************************************************************
624  inline bool operator==( const SubvectorIterator& rhs ) const {
625  return iterator_ == rhs.iterator_;
626  }
627  //*******************************************************************************************
628 
629  //**Inequality operator**********************************************************************
635  inline bool operator!=( const SubvectorIterator& rhs ) const {
636  return iterator_ != rhs.iterator_;
637  }
638  //*******************************************************************************************
639 
640  //**Less-than operator***********************************************************************
646  inline bool operator<( const SubvectorIterator& rhs ) const {
647  return iterator_ < rhs.iterator_;
648  }
649  //*******************************************************************************************
650 
651  //**Greater-than operator********************************************************************
657  inline bool operator>( const SubvectorIterator& rhs ) const {
658  return iterator_ > rhs.iterator_;
659  }
660  //*******************************************************************************************
661 
662  //**Less-or-equal-than operator**************************************************************
668  inline bool operator<=( const SubvectorIterator& rhs ) const {
669  return iterator_ <= rhs.iterator_;
670  }
671  //*******************************************************************************************
672 
673  //**Greater-or-equal-than operator***********************************************************
679  inline bool operator>=( const SubvectorIterator& rhs ) const {
680  return iterator_ >= rhs.iterator_;
681  }
682  //*******************************************************************************************
683 
684  //**Subtraction operator*********************************************************************
690  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
691  return iterator_ - rhs.iterator_;
692  }
693  //*******************************************************************************************
694 
695  //**Addition operator************************************************************************
702  friend inline const SubvectorIterator operator+( const SubvectorIterator& it, size_t inc ) {
703  return SubvectorIterator( it.iterator_ + inc, it.isAligned_ );
704  }
705  //*******************************************************************************************
706 
707  //**Addition operator************************************************************************
714  friend inline const SubvectorIterator operator+( size_t inc, const SubvectorIterator& it ) {
715  return SubvectorIterator( it.iterator_ + inc, it.isAligned_ );
716  }
717  //*******************************************************************************************
718 
719  //**Subtraction operator*********************************************************************
726  friend inline const SubvectorIterator operator-( const SubvectorIterator& it, size_t dec ) {
727  return SubvectorIterator( it.iterator_ - dec, it.isAligned_ );
728  }
729  //*******************************************************************************************
730 
731  //**Base function****************************************************************************
736  inline IteratorType base() const {
737  return iterator_;
738  }
739  //*******************************************************************************************
740 
741  //**IsAligned function***********************************************************************
746  inline bool isAligned() const {
747  return isAligned_;
748  }
749  //*******************************************************************************************
750 
751  private:
752  //**Member variables*************************************************************************
753  IteratorType iterator_;
754  bool isAligned_;
755  //*******************************************************************************************
756  };
757  //**********************************************************************************************
758 
759  //**Type definitions****************************************************************************
762 
764  typedef typename If< IsConst<VT>, ConstIterator, SubvectorIterator<typename VT::Iterator> >::Type Iterator;
765  //**********************************************************************************************
766 
767  //**Compilation flags***************************************************************************
769  enum { vectorizable = VT::vectorizable };
770 
772  enum { smpAssignable = VT::smpAssignable };
773  //**********************************************************************************************
774 
775  //**Constructors********************************************************************************
778  explicit inline DenseSubvector( Operand vector, size_t index, size_t n );
779  // No explicitly declared copy constructor.
781  //**********************************************************************************************
782 
783  //**Destructor**********************************************************************************
784  // No explicitly declared destructor.
785  //**********************************************************************************************
786 
787  //**Data access functions***********************************************************************
790  inline Reference operator[]( size_t index );
791  inline ConstReference operator[]( size_t index ) const;
792  inline Reference at( size_t index );
793  inline ConstReference at( size_t index ) const;
794  inline Pointer data ();
795  inline ConstPointer data () const;
796  inline Iterator begin ();
797  inline ConstIterator begin () const;
798  inline ConstIterator cbegin() const;
799  inline Iterator end ();
800  inline ConstIterator end () const;
801  inline ConstIterator cend () const;
803  //**********************************************************************************************
804 
805  //**Assignment operators************************************************************************
808  inline DenseSubvector& operator= ( const ElementType& rhs );
809  inline DenseSubvector& operator= ( const DenseSubvector& rhs );
810  template< typename VT2 > inline DenseSubvector& operator= ( const Vector<VT2,TF>& rhs );
811  template< typename VT2 > inline DenseSubvector& operator+=( const Vector<VT2,TF>& rhs );
812  template< typename VT2 > inline DenseSubvector& operator-=( const Vector<VT2,TF>& rhs );
813  template< typename VT2 > inline DenseSubvector& operator*=( const DenseVector<VT2,TF>& rhs );
814  template< typename VT2 > inline DenseSubvector& operator*=( const SparseVector<VT2,TF>& rhs );
815 
816  template< typename Other >
817  inline typename EnableIf< IsNumeric<Other>, DenseSubvector >::Type&
818  operator*=( Other rhs );
819 
820  template< typename Other >
821  inline typename EnableIf< IsNumeric<Other>, DenseSubvector >::Type&
822  operator/=( Other rhs );
824  //**********************************************************************************************
825 
826  //**Utility functions***************************************************************************
829  inline size_t size() const;
830  inline size_t capacity() const;
831  inline size_t nonZeros() const;
832  inline void reset();
833  template< typename Other > inline DenseSubvector& scale( const Other& scalar );
835  //**********************************************************************************************
836 
837  private:
838  //**********************************************************************************************
840  template< typename VT2 >
842  struct VectorizedAssign {
843  enum { value = useOptimizedKernels &&
844  vectorizable && VT2::vectorizable &&
845  IsSame<ElementType,typename VT2::ElementType>::value };
846  };
848  //**********************************************************************************************
849 
850  //**********************************************************************************************
852  template< typename VT2 >
854  struct VectorizedAddAssign {
855  enum { value = useOptimizedKernels &&
856  vectorizable && VT2::vectorizable &&
857  IsSame<ElementType,typename VT2::ElementType>::value &&
858  IntrinsicTrait<ElementType>::addition };
859  };
861  //**********************************************************************************************
862 
863  //**********************************************************************************************
865  template< typename VT2 >
867  struct VectorizedSubAssign {
868  enum { value = useOptimizedKernels &&
869  vectorizable && VT2::vectorizable &&
870  IsSame<ElementType,typename VT2::ElementType>::value &&
871  IntrinsicTrait<ElementType>::subtraction };
872  };
874  //**********************************************************************************************
875 
876  //**********************************************************************************************
878  template< typename VT2 >
880  struct VectorizedMultAssign {
881  enum { value = useOptimizedKernels &&
882  vectorizable && VT2::vectorizable &&
883  IsSame<ElementType,typename VT2::ElementType>::value &&
884  IntrinsicTrait<ElementType>::multiplication };
885  };
887  //**********************************************************************************************
888 
889  public:
890  //**Expression template evaluation functions****************************************************
893  template< typename Other >
894  inline bool canAlias( const Other* alias ) const;
895 
896  template< typename VT2, bool AF2, bool TF2 >
897  inline bool canAlias( const DenseSubvector<VT2,AF2,TF2>* alias ) const;
898 
899  template< typename Other >
900  inline bool isAliased( const Other* alias ) const;
901 
902  template< typename VT2, bool AF2, bool TF2 >
903  inline bool isAliased( const DenseSubvector<VT2,AF2,TF2>* alias ) const;
904 
905  inline bool isAligned () const;
906  inline bool canSMPAssign() const;
907 
908  inline IntrinsicType load ( size_t index ) const;
909  inline IntrinsicType loada( size_t index ) const;
910  inline IntrinsicType loadu( size_t index ) const;
911 
912  inline void store ( size_t index, const IntrinsicType& value );
913  inline void storea( size_t index, const IntrinsicType& value );
914  inline void storeu( size_t index, const IntrinsicType& value );
915  inline void stream( size_t index, const IntrinsicType& value );
916 
917  template< typename VT2 >
918  inline typename DisableIf< VectorizedAssign<VT2> >::Type
919  assign( const DenseVector <VT2,TF>& rhs );
920 
921  template< typename VT2 >
922  inline typename EnableIf< VectorizedAssign<VT2> >::Type
923  assign( const DenseVector <VT2,TF>& rhs );
924 
925  template< typename VT2 > inline void assign( const SparseVector<VT2,TF>& rhs );
926 
927  template< typename VT2 >
928  inline typename DisableIf< VectorizedAddAssign<VT2> >::Type
929  addAssign( const DenseVector <VT2,TF>& rhs );
930 
931  template< typename VT2 >
932  inline typename EnableIf< VectorizedAddAssign<VT2> >::Type
933  addAssign ( const DenseVector <VT2,TF>& rhs );
934 
935  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
936 
937  template< typename VT2 >
938  inline typename DisableIf< VectorizedSubAssign<VT2> >::Type
939  subAssign ( const DenseVector <VT2,TF>& rhs );
940 
941  template< typename VT2 >
942  inline typename EnableIf< VectorizedSubAssign<VT2> >::Type
943  subAssign( const DenseVector <VT2,TF>& rhs );
944 
945  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
946 
947  template< typename VT2 >
948  inline typename DisableIf< VectorizedMultAssign<VT2> >::Type
949  multAssign( const DenseVector <VT2,TF>& rhs );
950 
951  template< typename VT2 >
952  inline typename EnableIf< VectorizedMultAssign<VT2> >::Type
953  multAssign( const DenseVector <VT2,TF>& rhs );
954 
955  template< typename VT2 > inline void multAssign( const SparseVector<VT2,TF>& rhs );
957  //**********************************************************************************************
958 
959  private:
960  //**Member variables****************************************************************************
963  Operand vector_;
964  const size_t offset_;
965  const size_t size_;
966  const bool isAligned_;
967 
974  //**********************************************************************************************
975 
976  //**Friend declarations*************************************************************************
978  template< typename VT2, bool AF2, bool TF2 > friend class DenseSubvector;
979 
980  template< bool AF1, typename VT2, bool AF2, bool TF2 >
981  friend const DenseSubvector<VT2,AF1,TF2>
982  subvector( const DenseSubvector<VT2,AF2,TF2>& dv, size_t index, size_t size );
983 
984  template< typename VT2, bool AF2, bool TF2 >
985  friend bool isIntact( const DenseSubvector<VT2,AF2,TF2>& dv );
986 
987  template< typename VT2, bool AF2, bool TF2 >
988  friend bool isSame( const DenseSubvector<VT2,AF2,TF2>& a, const DenseVector<VT2,TF2>& b );
989 
990  template< typename VT2, bool AF2, bool TF2 >
991  friend bool isSame( const DenseVector<VT2,TF2>& a, const DenseSubvector<VT2,AF2,TF2>& b );
992 
993  template< typename VT2, bool AF2, bool TF2 >
994  friend bool isSame( const DenseSubvector<VT2,AF2,TF2>& a, const DenseSubvector<VT2,AF2,TF2>& b );
995 
996  template< typename VT2, bool AF2, bool TF2, typename VT3 >
997  friend bool tryAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
998 
999  template< typename VT2, bool AF2, bool TF2, typename VT3 >
1000  friend bool tryAddAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
1001 
1002  template< typename VT2, bool AF2, bool TF2, typename VT3 >
1003  friend bool trySubAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
1004 
1005  template< typename VT2, bool AF2, bool TF2, typename VT3 >
1006  friend bool tryMultAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
1007 
1008  template< typename VT2, bool AF2, bool TF2 >
1009  friend typename DerestrictTrait< DenseSubvector<VT2,AF2,TF2> >::Type
1010  derestrict( DenseSubvector<VT2,AF2,TF2>& dv );
1012  //**********************************************************************************************
1013 
1014  //**Compile time checks*************************************************************************
1022  //**********************************************************************************************
1023 };
1024 //*************************************************************************************************
1025 
1026 
1027 
1028 
1029 //=================================================================================================
1030 //
1031 // CONSTRUCTOR
1032 //
1033 //=================================================================================================
1034 
1035 //*************************************************************************************************
1047 template< typename VT // Type of the dense vector
1048  , bool AF // Alignment flag
1049  , bool TF > // Transpose flag
1050 inline DenseSubvector<VT,AF,TF>::DenseSubvector( Operand vector, size_t index, size_t n )
1051  : vector_ ( vector ) // The vector containing the subvector
1052  , offset_ ( index ) // The offset of the subvector within the dense vector
1053  , size_ ( n ) // The size of the subvector
1054  , isAligned_( vectorizable && vector.data() != NULL && checkAlignment( data() ) )
1055 {
1056  if( index + n > vector.size() ) {
1057  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
1058  }
1059 }
1060 //*************************************************************************************************
1061 
1062 
1063 
1064 
1065 //=================================================================================================
1066 //
1067 // DATA ACCESS FUNCTIONS
1068 //
1069 //=================================================================================================
1070 
1071 //*************************************************************************************************
1080 template< typename VT // Type of the dense vector
1081  , bool AF // Alignment flag
1082  , bool TF > // Transpose flag
1085 {
1086  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
1087  return vector_[offset_+index];
1088 }
1089 //*************************************************************************************************
1090 
1091 
1092 //*************************************************************************************************
1101 template< typename VT // Type of the dense vector
1102  , bool AF // Alignment flag
1103  , bool TF > // Transpose flag
1106 {
1107  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
1108  return const_cast<const VT&>( vector_ )[offset_+index];
1109 }
1110 //*************************************************************************************************
1111 
1112 
1113 //*************************************************************************************************
1123 template< typename VT // Type of the dense vector
1124  , bool AF // Alignment flag
1125  , bool TF > // Transpose flag
1128 {
1129  if( index >= size() ) {
1130  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
1131  }
1132  return (*this)[index];
1133 }
1134 //*************************************************************************************************
1135 
1136 
1137 //*************************************************************************************************
1147 template< typename VT // Type of the dense vector
1148  , bool AF // Alignment flag
1149  , bool TF > // Transpose flag
1151  DenseSubvector<VT,AF,TF>::at( size_t index ) const
1152 {
1153  if( index >= size() ) {
1154  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
1155  }
1156  return (*this)[index];
1157 }
1158 //*************************************************************************************************
1159 
1160 
1161 //*************************************************************************************************
1168 template< typename VT // Type of the dense vector
1169  , bool AF // Alignment flag
1170  , bool TF > // Transpose flag
1172 {
1173  return vector_.data() + offset_;
1174 }
1175 //*************************************************************************************************
1176 
1177 
1178 //*************************************************************************************************
1185 template< typename VT // Type of the dense vector
1186  , bool AF // Alignment flag
1187  , bool TF > // Transpose flag
1189 {
1190  return vector_.data() + offset_;
1191 }
1192 //*************************************************************************************************
1193 
1194 
1195 //*************************************************************************************************
1202 template< typename VT // Type of the dense vector
1203  , bool AF // Alignment flag
1204  , bool TF > // Transpose flag
1206 {
1207  return Iterator( vector_.begin() + offset_, isAligned_ );
1208 }
1209 //*************************************************************************************************
1210 
1211 
1212 //*************************************************************************************************
1219 template< typename VT // Type of the dense vector
1220  , bool AF // Alignment flag
1221  , bool TF > // Transpose flag
1223 {
1224  return ConstIterator( vector_.cbegin() + offset_, isAligned_ );
1225 }
1226 //*************************************************************************************************
1227 
1228 
1229 //*************************************************************************************************
1236 template< typename VT // Type of the dense vector
1237  , bool AF // Alignment flag
1238  , bool TF > // Transpose flag
1240 {
1241  return ConstIterator( vector_.cbegin() + offset_, isAligned_ );
1242 }
1243 //*************************************************************************************************
1244 
1245 
1246 //*************************************************************************************************
1253 template< typename VT // Type of the dense vector
1254  , bool AF // Alignment flag
1255  , bool TF > // Transpose flag
1257 {
1258  return Iterator( vector_.begin() + offset_ + size_, isAligned_ );
1259 }
1260 //*************************************************************************************************
1261 
1262 
1263 //*************************************************************************************************
1270 template< typename VT // Type of the dense vector
1271  , bool AF // Alignment flag
1272  , bool TF > // Transpose flag
1274 {
1275  return ConstIterator( vector_.cbegin() + offset_ + size_, isAligned_ );
1276 }
1277 //*************************************************************************************************
1278 
1279 
1280 //*************************************************************************************************
1287 template< typename VT // Type of the dense vector
1288  , bool AF // Alignment flag
1289  , bool TF > // Transpose flag
1291 {
1292  return ConstIterator( vector_.cbegin() + offset_ + size_, isAligned_ );
1293 }
1294 //*************************************************************************************************
1295 
1296 
1297 
1298 
1299 //=================================================================================================
1300 //
1301 // ASSIGNMENT OPERATORS
1302 //
1303 //=================================================================================================
1304 
1305 //*************************************************************************************************
1311 template< typename VT // Type of the dense vector
1312  , bool AF // Alignment flag
1313  , bool TF > // Transpose flag
1315 {
1316  const size_t iend( offset_ + size_ );
1317 
1318  for( size_t i=offset_; i<iend; ++i )
1319  vector_[i] = rhs;
1320 
1321  return *this;
1322 }
1323 //*************************************************************************************************
1324 
1325 
1326 //*************************************************************************************************
1337 template< typename VT // Type of the dense vector
1338  , bool AF // Alignment flag
1339  , bool TF > // Transpose flag
1341 {
1344 
1345  if( &rhs == this || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
1346  return *this;
1347 
1348  if( size() != rhs.size() ) {
1349  BLAZE_THROW_INVALID_ARGUMENT( "Subvector sizes do not match" );
1350  }
1351 
1352  if( !tryAssign( vector_, rhs, offset_ ) ) {
1353  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1354  }
1355 
1356  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1357 
1358  if( rhs.canAlias( &vector_ ) ) {
1359  const ResultType tmp( rhs );
1360  smpAssign( left, tmp );
1361  }
1362  else {
1363  smpAssign( left, rhs );
1364  }
1365 
1366  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1367 
1368  return *this;
1369 }
1370 //*************************************************************************************************
1371 
1372 
1373 //*************************************************************************************************
1384 template< typename VT // Type of the dense vector
1385  , bool AF // Alignment flag
1386  , bool TF > // Transpose flag
1387 template< typename VT2 > // Type of the right-hand side vector
1389 {
1392 
1393  if( size() != (~rhs).size() ) {
1394  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1395  }
1396 
1397  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
1398  Right right( ~rhs );
1399 
1400  if( !tryAssign( vector_, right, offset_ ) ) {
1401  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1402  }
1403 
1404  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1405 
1406  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1407  const typename VT2::ResultType tmp( right );
1408  smpAssign( left, tmp );
1409  }
1410  else {
1412  reset();
1413  smpAssign( left, right );
1414  }
1415 
1416  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1417 
1418  return *this;
1419 }
1420 //*************************************************************************************************
1421 
1422 
1423 //*************************************************************************************************
1434 template< typename VT // Type of the dense vector
1435  , bool AF // Alignment flag
1436  , bool TF > // Transpose flag
1437 template< typename VT2 > // Type of the right-hand side vector
1439 {
1442 
1443  if( size() != (~rhs).size() ) {
1444  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1445  }
1446 
1447  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
1448  Right right( ~rhs );
1449 
1450  if( !tryAddAssign( vector_, right, offset_ ) ) {
1451  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1452  }
1453 
1454  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1455 
1456  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1457  const typename VT2::ResultType tmp( right );
1458  smpAddAssign( left, tmp );
1459  }
1460  else {
1461  smpAddAssign( left, right );
1462  }
1463 
1464  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1465 
1466  return *this;
1467 }
1468 //*************************************************************************************************
1469 
1470 
1471 //*************************************************************************************************
1482 template< typename VT // Type of the dense vector
1483  , bool AF // Alignment flag
1484  , bool TF > // Transpose flag
1485 template< typename VT2 > // Type of the right-hand side vector
1487 {
1490 
1491  if( size() != (~rhs).size() ) {
1492  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1493  }
1494 
1495  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
1496  Right right( ~rhs );
1497 
1498  if( !trySubAssign( vector_, right, offset_ ) ) {
1499  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1500  }
1501 
1502  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1503 
1504  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1505  const typename VT2::ResultType tmp( right );
1506  smpSubAssign( left, tmp );
1507  }
1508  else {
1509  smpSubAssign( left, right );
1510  }
1511 
1512  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1513 
1514  return *this;
1515 }
1516 //*************************************************************************************************
1517 
1518 
1519 //*************************************************************************************************
1531 template< typename VT // Type of the dense vector
1532  , bool AF // Alignment flag
1533  , bool TF > // Transpose flag
1534 template< typename VT2 > // Type of the right-hand side dense vector
1537 {
1540 
1541  if( size() != (~rhs).size() ) {
1542  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1543  }
1544 
1545  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
1546  Right right( ~rhs );
1547 
1548  if( !tryMultAssign( vector_, right, offset_ ) ) {
1549  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1550  }
1551 
1552  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1553 
1554  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
1555  const typename VT2::ResultType tmp( right );
1556  smpMultAssign( left, tmp );
1557  }
1558  else {
1559  smpMultAssign( left, right );
1560  }
1561 
1562  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1563 
1564  return *this;
1565 }
1566 //*************************************************************************************************
1567 
1568 
1569 //*************************************************************************************************
1581 template< typename VT // Type of the dense vector
1582  , bool AF // Alignment flag
1583  , bool TF > // Transpose flag
1584 template< typename VT2 > // Type of the right-hand side sparse vector
1587 {
1590 
1591  if( size() != (~rhs).size() ) {
1592  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1593  }
1594 
1595  const ResultType tmp( *this * (~rhs) );
1596 
1597  if( !tryAssign( vector_, tmp, offset_ ) ) {
1598  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
1599  }
1600 
1601  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1602 
1603  smpAssign( left, tmp );
1604 
1605  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
1606 
1607  return *this;
1608 }
1609 //*************************************************************************************************
1610 
1611 
1612 //*************************************************************************************************
1619 template< typename VT // Type of the dense vector
1620  , bool AF // Alignment flag
1621  , bool TF > // Transpose flag
1622 template< typename Other > // Data type of the right-hand side scalar
1623 inline typename EnableIf< IsNumeric<Other>, DenseSubvector<VT,AF,TF> >::Type&
1625 {
1626  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1627  smpAssign( left, (*this) * rhs );
1628 
1629  return *this;
1630 }
1631 //*************************************************************************************************
1632 
1633 
1634 //*************************************************************************************************
1643 template< typename VT // Type of the dense vector
1644  , bool AF // Alignment flag
1645  , bool TF > // Transpose flag
1646 template< typename Other > // Data type of the right-hand side scalar
1647 inline typename EnableIf< IsNumeric<Other>, DenseSubvector<VT,AF,TF> >::Type&
1649 {
1650  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1651 
1652  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1653  smpAssign( left, (*this) / rhs );
1654 
1655  return *this;
1656 }
1657 //*************************************************************************************************
1658 
1659 
1660 
1661 
1662 //=================================================================================================
1663 //
1664 // UTILITY FUNCTIONS
1665 //
1666 //=================================================================================================
1667 
1668 //*************************************************************************************************
1673 template< typename VT // Type of the dense vector
1674  , bool AF // Alignment flag
1675  , bool TF > // Transpose flag
1676 inline size_t DenseSubvector<VT,AF,TF>::size() const
1677 {
1678  return size_;
1679 }
1680 //*************************************************************************************************
1681 
1682 
1683 //*************************************************************************************************
1688 template< typename VT // Type of the dense vector
1689  , bool AF // Alignment flag
1690  , bool TF > // Transpose flag
1692 {
1693  return vector_.capacity() - offset_;
1694 }
1695 //*************************************************************************************************
1696 
1697 
1698 //*************************************************************************************************
1706 template< typename VT // Type of the dense vector
1707  , bool AF // Alignment flag
1708  , bool TF > // Transpose flag
1710 {
1711  size_t nonzeros( 0 );
1712 
1713  const size_t iend( offset_ + size_ );
1714  for( size_t i=offset_; i<iend; ++i ) {
1715  if( !isDefault( vector_[i] ) )
1716  ++nonzeros;
1717  }
1718 
1719  return nonzeros;
1720 }
1721 //*************************************************************************************************
1722 
1723 
1724 //*************************************************************************************************
1729 template< typename VT // Type of the dense vector
1730  , bool AF // Alignment flag
1731  , bool TF > // Transpose flag
1733 {
1734  using blaze::clear;
1735 
1736  const size_t iend( offset_ + size_ );
1737  for( size_t i=offset_; i<iend; ++i )
1738  clear( vector_[i] );
1739 }
1740 //*************************************************************************************************
1741 
1742 
1743 //*************************************************************************************************
1749 template< typename VT // Type of the dense vector
1750  , bool AF // Alignment flag
1751  , bool TF > // Transpose flag
1752 template< typename Other > // Data type of the scalar value
1754 {
1755  const size_t iend( offset_ + size_ );
1756  for( size_t i=offset_; i<iend; ++i )
1757  vector_[i] *= scalar;
1758  return *this;
1759 }
1760 //*************************************************************************************************
1761 
1762 
1763 
1764 
1765 //=================================================================================================
1766 //
1767 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1768 //
1769 //=================================================================================================
1770 
1771 //*************************************************************************************************
1781 template< typename VT // Type of the dense vector
1782  , bool AF // Alignment flag
1783  , bool TF > // Transpose flag
1784 template< typename Other > // Data type of the foreign expression
1785 inline bool DenseSubvector<VT,AF,TF>::canAlias( const Other* alias ) const
1786 {
1787  return vector_.isAliased( alias );
1788 }
1789 //*************************************************************************************************
1790 
1791 
1792 //*************************************************************************************************
1802 template< typename VT // Type of the dense vector
1803  , bool AF // Alignment flag
1804  , bool TF > // Transpose flag
1805 template< typename VT2 // Data type of the foreign dense subvector
1806  , bool AF2 // Alignment flag of the foreign dense subvector
1807  , bool TF2 > // Transpose flag of the foreign dense subvector
1809 {
1810  return ( vector_.isAliased( &alias->vector_ ) &&
1811  ( offset_ + size_ > alias->offset_ ) && ( offset_ < alias->offset_ + alias->size_ ) );
1812 }
1813 //*************************************************************************************************
1814 
1815 
1816 //*************************************************************************************************
1826 template< typename VT // Type of the dense vector
1827  , bool AF // Alignment flag
1828  , bool TF > // Transpose flag
1829 template< typename Other > // Data type of the foreign expression
1830 inline bool DenseSubvector<VT,AF,TF>::isAliased( const Other* alias ) const
1831 {
1832  return vector_.isAliased( alias );
1833 }
1834 //*************************************************************************************************
1835 
1836 
1837 //*************************************************************************************************
1847 template< typename VT // Type of the dense vector
1848  , bool AF // Alignment flag
1849  , bool TF > // Transpose flag
1850 template< typename VT2 // Data type of the foreign dense subvector
1851  , bool AF2 // Alignment flag of the foreign dense subvector
1852  , bool TF2 > // Transpose flag of the foreign dense subvector
1854 {
1855  return ( vector_.isAliased( &alias->vector_ ) &&
1856  ( offset_ + size_ > alias->offset_ ) && ( offset_ < alias->offset_ + alias->size_ ) );
1857 }
1858 //*************************************************************************************************
1859 
1860 
1861 //*************************************************************************************************
1870 template< typename VT // Type of the dense vector
1871  , bool AF // Alignment flag
1872  , bool TF > // Transpose flag
1874 {
1875  return isAligned_;
1876 }
1877 //*************************************************************************************************
1878 
1879 
1880 //*************************************************************************************************
1890 template< typename VT // Type of the dense vector
1891  , bool AF // Alignment flag
1892  , bool TF > // Transpose flag
1894 {
1895  return ( size() > SMP_DVECASSIGN_THRESHOLD );
1896 }
1897 //*************************************************************************************************
1898 
1899 
1900 //*************************************************************************************************
1913 template< typename VT // Type of the dense vector
1914  , bool AF // Alignment flag
1915  , bool TF > // Transpose flag
1917  DenseSubvector<VT,AF,TF>::load( size_t index ) const
1918 {
1919  if( isAligned_ )
1920  return loada( index );
1921  else
1922  return loadu( index );
1923 }
1924 //*************************************************************************************************
1925 
1926 
1927 //*************************************************************************************************
1940 template< typename VT // Type of the dense vector
1941  , bool AF // Alignment flag
1942  , bool TF > // Transpose flag
1944  DenseSubvector<VT,AF,TF>::loada( size_t index ) const
1945 {
1947 
1948  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
1949  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
1950  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
1951 
1952  return vector_.loada( offset_+index );
1953 }
1954 //*************************************************************************************************
1955 
1956 
1957 //*************************************************************************************************
1970 template< typename VT // Type of the dense vector
1971  , bool AF // Alignment flag
1972  , bool TF > // Transpose flag
1974  DenseSubvector<VT,AF,TF>::loadu( size_t index ) const
1975 {
1977 
1978  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
1979  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
1980  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
1981 
1982  return vector_.loadu( offset_+index );
1983 }
1984 //*************************************************************************************************
1985 
1986 
1987 //*************************************************************************************************
2001 template< typename VT // Type of the dense vector
2002  , bool AF // Alignment flag
2003  , bool TF > // Transpose flag
2004 inline void DenseSubvector<VT,AF,TF>::store( size_t index, const IntrinsicType& value )
2005 {
2006  if( isAligned_ )
2007  storea( index, value );
2008  else
2009  storeu( index, value );
2010 }
2011 //*************************************************************************************************
2012 
2013 
2014 //*************************************************************************************************
2028 template< typename VT // Type of the dense vector
2029  , bool AF // Alignment flag
2030  , bool TF > // Transpose flag
2031 inline void DenseSubvector<VT,AF,TF>::storea( size_t index, const IntrinsicType& value )
2032 {
2034 
2035  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
2036  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
2037  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
2038 
2039  vector_.storea( offset_+index, value );
2040 }
2041 //*************************************************************************************************
2042 
2043 
2044 //*************************************************************************************************
2058 template< typename VT // Type of the dense vector
2059  , bool AF // Alignment flag
2060  , bool TF > // Transpose flag
2061 inline void DenseSubvector<VT,AF,TF>::storeu( size_t index, const IntrinsicType& value )
2062 {
2064 
2065  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
2066  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
2067  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
2068 
2069  vector_.storeu( offset_+index, value );
2070 }
2071 //*************************************************************************************************
2072 
2073 
2074 //*************************************************************************************************
2088 template< typename VT // Type of the dense vector
2089  , bool AF // Alignment flag
2090  , bool TF > // Transpose flag
2091 inline void DenseSubvector<VT,AF,TF>::stream( size_t index, const IntrinsicType& value )
2092 {
2094 
2095  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
2096  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
2097  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
2098 
2099  if( isAligned_ )
2100  vector_.stream( offset_+index, value );
2101  else
2102  vector_.storeu( offset_+index, value );
2103 }
2104 //*************************************************************************************************
2105 
2106 
2107 //*************************************************************************************************
2118 template< typename VT // Type of the dense vector
2119  , bool AF // Alignment flag
2120  , bool TF > // Transpose flag
2121 template< typename VT2 > // Type of the right-hand side dense vector
2122 inline typename DisableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedAssign<VT2> >::Type
2124 {
2125  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2126 
2127  const size_t ipos( size() & size_t(-2) );
2128  for( size_t i=0UL; i<ipos; i+=2UL ) {
2129  vector_[offset_+i ] = (~rhs)[i ];
2130  vector_[offset_+i+1UL] = (~rhs)[i+1UL];
2131  }
2132  if( ipos < size() ) {
2133  vector_[offset_+ipos] = (~rhs)[ipos];
2134  }
2135 }
2136 //*************************************************************************************************
2137 
2138 
2139 //*************************************************************************************************
2150 template< typename VT // Type of the dense vector
2151  , bool AF // Alignment flag
2152  , bool TF > // Transpose flag
2153 template< typename VT2 > // Type of the right-hand side dense vector
2154 inline typename EnableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedAssign<VT2> >::Type
2156 {
2158 
2159  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2160 
2161  const size_t ipos( size_ & size_t(-IT::size) );
2162  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
2163 
2164  if( useStreaming && isAligned_ &&
2165  ( size_ > ( cacheSize/( sizeof(ElementType) * 3UL ) ) ) &&
2166  !(~rhs).isAliased( &vector_ ) )
2167  {
2168  size_t i( 0UL );
2169 
2170  for( ; i<ipos; i+=IT::size ) {
2171  vector_.stream( offset_+i, (~rhs).load(i) );
2172  }
2173  for( ; i<size_; ++i ) {
2174  vector_[offset_+i] = (~rhs)[i];
2175  }
2176  }
2177  else
2178  {
2179  size_t i( 0UL );
2180  typename VT2::ConstIterator it( (~rhs).begin() );
2181 
2182  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
2183  store( i , it.load() ); it += IT::size;
2184  store( i+IT::size , it.load() ); it += IT::size;
2185  store( i+IT::size*2UL, it.load() ); it += IT::size;
2186  store( i+IT::size*3UL, it.load() ); it += IT::size;
2187  }
2188  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2189  store( i, it.load() );
2190  }
2191  for( ; i<size_; ++i, ++it ) {
2192  vector_[offset_+i] = *it;
2193  }
2194  }
2195 }
2196 //*************************************************************************************************
2197 
2198 
2199 //*************************************************************************************************
2210 template< typename VT // Type of the dense vector
2211  , bool AF // Alignment flag
2212  , bool TF > // Transpose flag
2213 template< typename VT2 > // Type of the right-hand side dense vector
2215 {
2216  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2217 
2218  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2219  vector_[offset_+element->index()] = element->value();
2220 }
2221 //*************************************************************************************************
2222 
2223 
2224 //*************************************************************************************************
2235 template< typename VT // Type of the dense vector
2236  , bool AF // Alignment flag
2237  , bool TF > // Transpose flag
2238 template< typename VT2 > // Type of the right-hand side dense vector
2239 inline typename DisableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT2> >::Type
2241 {
2242  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2243 
2244  const size_t ipos( size() & size_t(-2) );
2245  for( size_t i=0UL; i<ipos; i+=2UL ) {
2246  vector_[offset_+i ] += (~rhs)[i ];
2247  vector_[offset_+i+1UL] += (~rhs)[i+1UL];
2248  }
2249  if( ipos < size() ) {
2250  vector_[offset_+ipos] += (~rhs)[ipos];
2251  }
2252 }
2253 //*************************************************************************************************
2254 
2255 
2256 //*************************************************************************************************
2267 template< typename VT // Type of the dense vector
2268  , bool AF // Alignment flag
2269  , bool TF > // Transpose flag
2270 template< typename VT2 > // Type of the right-hand side dense vector
2271 inline typename EnableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT2> >::Type
2273 {
2275 
2276  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2277 
2278  const size_t ipos( size_ & size_t(-IT::size) );
2279  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
2280 
2281  size_t i( 0UL );
2282  typename VT2::ConstIterator it( (~rhs).begin() );
2283 
2284  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
2285  store( i , load(i ) + it.load() ); it += IT::size;
2286  store( i+IT::size , load(i+IT::size ) + it.load() ); it += IT::size;
2287  store( i+IT::size*2UL, load(i+IT::size*2UL) + it.load() ); it += IT::size;
2288  store( i+IT::size*3UL, load(i+IT::size*3UL) + it.load() ); it += IT::size;
2289  }
2290  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2291  store( i, load(i) + it.load() );
2292  }
2293  for( ; i<size_; ++i, ++it ) {
2294  vector_[offset_+i] += *it;
2295  }
2296 }
2297 //*************************************************************************************************
2298 
2299 
2300 //*************************************************************************************************
2311 template< typename VT // Type of the dense vector
2312  , bool AF // Alignment flag
2313  , bool TF > // Transpose flag
2314 template< typename VT2 > // Type of the right-hand side dense vector
2316 {
2317  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2318 
2319  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2320  vector_[offset_+element->index()] += element->value();
2321 }
2322 //*************************************************************************************************
2323 
2324 
2325 //*************************************************************************************************
2336 template< typename VT // Type of the dense vector
2337  , bool AF // Alignment flag
2338  , bool TF > // Transpose flag
2339 template< typename VT2 > // Type of the right-hand side dense vector
2340 inline typename DisableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT2> >::Type
2342 {
2343  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2344 
2345  const size_t ipos( size() & size_t(-2) );
2346  for( size_t i=0UL; i<ipos; i+=2UL ) {
2347  vector_[offset_+i ] -= (~rhs)[i ];
2348  vector_[offset_+i+1UL] -= (~rhs)[i+1UL];
2349  }
2350  if( ipos < size() ) {
2351  vector_[offset_+ipos] -= (~rhs)[ipos];
2352  }
2353 }
2354 //*************************************************************************************************
2355 
2356 
2357 //*************************************************************************************************
2368 template< typename VT // Type of the dense vector
2369  , bool AF // Alignment flag
2370  , bool TF > // Transpose flag
2371 template< typename VT2 > // Type of the right-hand side dense vector
2372 inline typename EnableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT2> >::Type
2374 {
2376 
2377  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2378 
2379  const size_t ipos( size_ & size_t(-IT::size) );
2380  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
2381 
2382  size_t i( 0UL );
2383  typename VT2::ConstIterator it( (~rhs).begin() );
2384 
2385  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
2386  store( i , load(i ) - it.load() ); it += IT::size;
2387  store( i+IT::size , load(i+IT::size ) - it.load() ); it += IT::size;
2388  store( i+IT::size*2UL, load(i+IT::size*2UL) - it.load() ); it += IT::size;
2389  store( i+IT::size*3UL, load(i+IT::size*3UL) - it.load() ); it += IT::size;
2390  }
2391  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2392  store( i, load(i) - it.load() );
2393  }
2394  for( ; i<size_; ++i, ++it ) {
2395  vector_[offset_+i] -= *it;
2396  }
2397 }
2398 //*************************************************************************************************
2399 
2400 
2401 //*************************************************************************************************
2412 template< typename VT // Type of the dense vector
2413  , bool AF // Alignment flag
2414  , bool TF > // Transpose flag
2415 template< typename VT2 > // Type of the right-hand side dense vector
2417 {
2418  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2419 
2420  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2421  vector_[offset_+element->index()] -= element->value();
2422 }
2423 //*************************************************************************************************
2424 
2425 
2426 //*************************************************************************************************
2437 template< typename VT // Type of the dense vector
2438  , bool AF // Alignment flag
2439  , bool TF > // Transpose flag
2440 template< typename VT2 > // Type of the right-hand side dense vector
2441 inline typename DisableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT2> >::Type
2443 {
2444  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2445 
2446  const size_t ipos( size() & size_t(-2) );
2447  for( size_t i=0UL; i<ipos; i+=2UL ) {
2448  vector_[offset_+i ] *= (~rhs)[i ];
2449  vector_[offset_+i+1UL] *= (~rhs)[i+1UL];
2450  }
2451  if( ipos < size() ) {
2452  vector_[offset_+ipos] *= (~rhs)[ipos];
2453  }
2454 }
2455 //*************************************************************************************************
2456 
2457 
2458 //*************************************************************************************************
2469 template< typename VT // Type of the dense vector
2470  , bool AF // Alignment flag
2471  , bool TF > // Transpose flag
2472 template< typename VT2 > // Type of the right-hand side dense vector
2473 inline typename EnableIf< typename DenseSubvector<VT,AF,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT2> >::Type
2475 {
2477 
2478  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2479 
2480  const size_t ipos( size_ & size_t(-IT::size) );
2481  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
2482 
2483  size_t i( 0UL );
2484  typename VT2::ConstIterator it( (~rhs).begin() );
2485 
2486  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
2487  store( i , load(i ) * it.load() ); it += IT::size;
2488  store( i+IT::size , load(i+IT::size ) * it.load() ); it += IT::size;
2489  store( i+IT::size*2UL, load(i+IT::size*2UL) * it.load() ); it += IT::size;
2490  store( i+IT::size*3UL, load(i+IT::size*3UL) * it.load() ); it += IT::size;
2491  }
2492  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
2493  store( i, load(i) * it.load() );
2494  }
2495  for( ; i<size_; ++i, ++it ) {
2496  vector_[offset_+i] *= *it;
2497  }
2498 }
2499 //*************************************************************************************************
2500 
2501 
2502 //*************************************************************************************************
2513 template< typename VT // Type of the dense vector
2514  , bool AF // Alignment flag
2515  , bool TF > // Transpose flag
2516 template< typename VT2 > // Type of the right-hand side dense vector
2518 {
2519  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2520 
2521  const ResultType tmp( serial( *this ) );
2522 
2523  reset();
2524 
2525  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
2526  vector_[offset_+element->index()] = tmp[element->index()] * element->value();
2527 }
2528 //*************************************************************************************************
2529 
2530 
2531 
2532 
2533 
2534 
2535 
2536 
2537 //=================================================================================================
2538 //
2539 // CLASS TEMPLATE SPECIALIZATION FOR ALIGNED SUBVECTORS
2540 //
2541 //=================================================================================================
2542 
2543 //*************************************************************************************************
2551 template< typename VT // Type of the dense vector
2552  , bool TF > // Transpose flag
2553 class DenseSubvector<VT,aligned,TF> : public DenseVector< DenseSubvector<VT,aligned,TF>, TF >
2554  , private Subvector
2555 {
2556  private:
2557  //**Type definitions****************************************************************************
2559  typedef typename If< IsExpression<VT>, VT, VT& >::Type Operand;
2560 
2563  //**********************************************************************************************
2564 
2565  public:
2566  //**Type definitions****************************************************************************
2568  typedef typename SubvectorTrait<VT>::Type ResultType;
2569  typedef typename ResultType::TransposeType TransposeType;
2570  typedef typename VT::ElementType ElementType;
2571  typedef typename IT::Type IntrinsicType;
2572  typedef typename VT::ReturnType ReturnType;
2573  typedef const DenseSubvector& CompositeType;
2574 
2576  typedef typename VT::ConstReference ConstReference;
2577 
2579  typedef typename If< IsConst<VT>, ConstReference, typename VT::Reference >::Type Reference;
2580 
2582  typedef const ElementType* ConstPointer;
2583 
2586  , ConstPointer, ElementType* >::Type Pointer;
2587 
2589  typedef typename VT::ConstIterator ConstIterator;
2590 
2592  typedef typename If< IsConst<VT>, ConstIterator, typename VT::Iterator >::Type Iterator;
2593  //**********************************************************************************************
2594 
2595  //**Compilation flags***************************************************************************
2597  enum { vectorizable = VT::vectorizable };
2598 
2600  enum { smpAssignable = VT::smpAssignable };
2601  //**********************************************************************************************
2602 
2603  //**Constructors********************************************************************************
2606  explicit inline DenseSubvector( Operand vector, size_t index, size_t n );
2607  // No explicitly declared copy constructor.
2609  //**********************************************************************************************
2610 
2611  //**Destructor**********************************************************************************
2612  // No explicitly declared destructor.
2613  //**********************************************************************************************
2614 
2615  //**Data access functions***********************************************************************
2618  inline Reference operator[]( size_t index );
2619  inline ConstReference operator[]( size_t index ) const;
2620  inline Reference at( size_t index );
2621  inline ConstReference at( size_t index ) const;
2622  inline Pointer data ();
2623  inline ConstPointer data () const;
2624  inline Iterator begin ();
2625  inline ConstIterator begin () const;
2626  inline ConstIterator cbegin() const;
2627  inline Iterator end ();
2628  inline ConstIterator end () const;
2629  inline ConstIterator cend () const;
2631  //**********************************************************************************************
2632 
2633  //**Assignment operators************************************************************************
2636  inline DenseSubvector& operator= ( const ElementType& rhs );
2637  inline DenseSubvector& operator= ( const DenseSubvector& rhs );
2638  template< typename VT2 > inline DenseSubvector& operator= ( const Vector<VT2,TF>& rhs );
2639  template< typename VT2 > inline DenseSubvector& operator+=( const Vector<VT2,TF>& rhs );
2640  template< typename VT2 > inline DenseSubvector& operator-=( const Vector<VT2,TF>& rhs );
2641  template< typename VT2 > inline DenseSubvector& operator*=( const DenseVector<VT2,TF>& rhs );
2642  template< typename VT2 > inline DenseSubvector& operator*=( const SparseVector<VT2,TF>& rhs );
2643 
2644  template< typename Other >
2645  inline typename EnableIf< IsNumeric<Other>, DenseSubvector >::Type&
2646  operator*=( Other rhs );
2647 
2648  template< typename Other >
2649  inline typename EnableIf< IsNumeric<Other>, DenseSubvector >::Type&
2650  operator/=( Other rhs );
2652  //**********************************************************************************************
2653 
2654  //**Utility functions***************************************************************************
2657  inline size_t size() const;
2658  inline size_t capacity() const;
2659  inline size_t nonZeros() const;
2660  inline void reset();
2661  template< typename Other > inline DenseSubvector& scale( const Other& scalar );
2663  //**********************************************************************************************
2664 
2665  private:
2666  //**********************************************************************************************
2668  template< typename VT2 >
2669  struct VectorizedAssign {
2670  enum { value = useOptimizedKernels &&
2671  vectorizable && VT2::vectorizable &&
2672  IsSame<ElementType,typename VT2::ElementType>::value };
2673  };
2674  //**********************************************************************************************
2675 
2676  //**********************************************************************************************
2678  template< typename VT2 >
2679  struct VectorizedAddAssign {
2680  enum { value = useOptimizedKernels &&
2681  vectorizable && VT2::vectorizable &&
2682  IsSame<ElementType,typename VT2::ElementType>::value &&
2683  IntrinsicTrait<ElementType>::addition };
2684  };
2685  //**********************************************************************************************
2686 
2687  //**********************************************************************************************
2689  template< typename VT2 >
2690  struct VectorizedSubAssign {
2691  enum { value = useOptimizedKernels &&
2692  vectorizable && VT2::vectorizable &&
2693  IsSame<ElementType,typename VT2::ElementType>::value &&
2694  IntrinsicTrait<ElementType>::subtraction };
2695  };
2696  //**********************************************************************************************
2697 
2698  //**********************************************************************************************
2700  template< typename VT2 >
2701  struct VectorizedMultAssign {
2702  enum { value = useOptimizedKernels &&
2703  vectorizable && VT2::vectorizable &&
2704  IsSame<ElementType,typename VT2::ElementType>::value &&
2705  IntrinsicTrait<ElementType>::multiplication };
2706  };
2707  //**********************************************************************************************
2708 
2709  public:
2710  //**Expression template evaluation functions****************************************************
2713  template< typename Other >
2714  inline bool canAlias( const Other* alias ) const;
2715 
2716  template< typename VT2, bool AF2, bool TF2 >
2717  inline bool canAlias( const DenseSubvector<VT2,AF2,TF2>* alias ) const;
2718 
2719  template< typename Other >
2720  inline bool isAliased( const Other* alias ) const;
2721 
2722  template< typename VT2, bool AF2, bool TF2 >
2723  inline bool isAliased( const DenseSubvector<VT2,AF2,TF2>* alias ) const;
2724 
2725  inline bool isAligned () const;
2726  inline bool canSMPAssign() const;
2727 
2728  inline IntrinsicType load ( size_t index ) const;
2729  inline IntrinsicType loada( size_t index ) const;
2730  inline IntrinsicType loadu( size_t index ) const;
2731 
2732  inline void store ( size_t index, const IntrinsicType& value );
2733  inline void storea( size_t index, const IntrinsicType& value );
2734  inline void storeu( size_t index, const IntrinsicType& value );
2735  inline void stream( size_t index, const IntrinsicType& value );
2736 
2737  template< typename VT2 >
2738  inline typename DisableIf< VectorizedAssign<VT2> >::Type
2739  assign( const DenseVector <VT2,TF>& rhs );
2740 
2741  template< typename VT2 >
2742  inline typename EnableIf< VectorizedAssign<VT2> >::Type
2743  assign( const DenseVector <VT2,TF>& rhs );
2744 
2745  template< typename VT2 > inline void assign( const SparseVector<VT2,TF>& rhs );
2746 
2747  template< typename VT2 >
2748  inline typename DisableIf< VectorizedAddAssign<VT2> >::Type
2749  addAssign( const DenseVector <VT2,TF>& rhs );
2750 
2751  template< typename VT2 >
2752  inline typename EnableIf< VectorizedAddAssign<VT2> >::Type
2753  addAssign ( const DenseVector <VT2,TF>& rhs );
2754 
2755  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
2756 
2757  template< typename VT2 >
2758  inline typename DisableIf< VectorizedSubAssign<VT2> >::Type
2759  subAssign ( const DenseVector <VT2,TF>& rhs );
2760 
2761  template< typename VT2 >
2762  inline typename EnableIf< VectorizedSubAssign<VT2> >::Type
2763  subAssign( const DenseVector <VT2,TF>& rhs );
2764 
2765  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
2766 
2767  template< typename VT2 >
2768  inline typename DisableIf< VectorizedMultAssign<VT2> >::Type
2769  multAssign( const DenseVector <VT2,TF>& rhs );
2770 
2771  template< typename VT2 >
2772  inline typename EnableIf< VectorizedMultAssign<VT2> >::Type
2773  multAssign( const DenseVector <VT2,TF>& rhs );
2774 
2775  template< typename VT2 > inline void multAssign( const SparseVector<VT2,TF>& rhs );
2777  //**********************************************************************************************
2778 
2779  private:
2780  //**Member variables****************************************************************************
2783  Operand vector_;
2784  const size_t offset_;
2785  const size_t size_;
2786 
2787  //**********************************************************************************************
2788 
2789  //**Friend declarations*************************************************************************
2790  template< typename VT2, bool AF2, bool TF2 > friend class DenseSubvector;
2791 
2792  template< bool AF1, typename VT2, bool AF2, bool TF2 >
2793  friend const DenseSubvector<VT2,AF1,TF2>
2794  subvector( const DenseSubvector<VT2,AF2,TF2>& dv, size_t index, size_t size );
2795 
2796  template< typename VT2, bool AF2, bool TF2 >
2797  friend bool isIntact( const DenseSubvector<VT2,AF2,TF2>& dv );
2798 
2799  template< typename VT2, bool AF2, bool TF2 >
2800  friend bool isSame( const DenseSubvector<VT2,AF2,TF2>& a, const DenseVector<VT2,TF2>& b );
2801 
2802  template< typename VT2, bool AF2, bool TF2 >
2803  friend bool isSame( const DenseVector<VT2,TF2>& a, const DenseSubvector<VT2,AF2,TF2>& b );
2804 
2805  template< typename VT2, bool AF2, bool TF2 >
2806  friend bool isSame( const DenseSubvector<VT2,AF2,TF2>& a, const DenseSubvector<VT2,AF2,TF2>& b );
2807 
2808  template< typename VT2, bool AF2, bool TF2, typename VT3 >
2809  friend bool tryAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
2810 
2811  template< typename VT2, bool AF2, bool TF2, typename VT3 >
2812  friend bool tryAddAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
2813 
2814  template< typename VT2, bool AF2, bool TF2, typename VT3 >
2815  friend bool trySubAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
2816 
2817  template< typename VT2, bool AF2, bool TF2, typename VT3 >
2818  friend bool tryMultAssign( const DenseSubvector<VT2,AF2,TF2>& lhs, const Vector<VT3,TF2>& rhs, size_t index );
2819 
2820  template< typename VT2, bool AF2, bool TF2 >
2821  friend typename DerestrictTrait< DenseSubvector<VT2,AF2,TF2> >::Type
2822  derestrict( DenseSubvector<VT2,AF2,TF2>& dv );
2823  //**********************************************************************************************
2824 
2825  //**Compile time checks*************************************************************************
2831  //**********************************************************************************************
2832 };
2834 //*************************************************************************************************
2835 
2836 
2837 
2838 
2839 //=================================================================================================
2840 //
2841 // CONSTRUCTOR
2842 //
2843 //=================================================================================================
2844 
2845 //*************************************************************************************************
2858 template< typename VT // Type of the dense vector
2859  , bool TF > // Transpose flag
2860 inline DenseSubvector<VT,aligned,TF>::DenseSubvector( Operand vector, size_t index, size_t n )
2861  : vector_( vector ) // The vector containing the subvector
2862  , offset_( index ) // The offset of the subvector within the dense vector
2863  , size_ ( n ) // The size of the subvector
2864 {
2865  if( index + n > vector.size() ) {
2866  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
2867  }
2868 
2869  if( vectorizable && vector_.data() != NULL && !checkAlignment( data() ) ) {
2870  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector alignment" );
2871  }
2872 }
2874 //*************************************************************************************************
2875 
2876 
2877 
2878 
2879 //=================================================================================================
2880 //
2881 // DATA ACCESS FUNCTIONS
2882 //
2883 //=================================================================================================
2884 
2885 //*************************************************************************************************
2892 template< typename VT // Type of the dense vector
2893  , bool TF > // Transpose flag
2896 {
2897  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
2898  return vector_[offset_+index];
2899 }
2901 //*************************************************************************************************
2902 
2903 
2904 //*************************************************************************************************
2911 template< typename VT // Type of the dense vector
2912  , bool TF > // Transpose flag
2914  DenseSubvector<VT,aligned,TF>::operator[]( size_t index ) const
2915 {
2916  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
2917  return const_cast<const VT&>( vector_ )[offset_+index];
2918 }
2920 //*************************************************************************************************
2921 
2922 
2923 //*************************************************************************************************
2934 template< typename VT // Type of the dense vector
2935  , bool TF > // Transpose flag
2937  DenseSubvector<VT,aligned,TF>::at( size_t index )
2938 {
2939  if( index >= size() ) {
2940  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
2941  }
2942  return (*this)[index];
2943 }
2945 //*************************************************************************************************
2946 
2947 
2948 //*************************************************************************************************
2959 template< typename VT // Type of the dense vector
2960  , bool TF > // Transpose flag
2962  DenseSubvector<VT,aligned,TF>::at( size_t index ) const
2963 {
2964  if( index >= size() ) {
2965  BLAZE_THROW_OUT_OF_RANGE( "Invalid subvector access index" );
2966  }
2967  return (*this)[index];
2968 }
2970 //*************************************************************************************************
2971 
2972 
2973 //*************************************************************************************************
2981 template< typename VT // Type of the dense vector
2982  , bool TF > // Transpose flag
2983 inline typename DenseSubvector<VT,aligned,TF>::Pointer DenseSubvector<VT,aligned,TF>::data()
2984 {
2985  return vector_.data() + offset_;
2986 }
2988 //*************************************************************************************************
2989 
2990 
2991 //*************************************************************************************************
2999 template< typename VT // Type of the dense vector
3000  , bool TF > // Transpose flag
3001 inline typename DenseSubvector<VT,aligned,TF>::ConstPointer DenseSubvector<VT,aligned,TF>::data() const
3002 {
3003  return vector_.data() + offset_;
3004 }
3006 //*************************************************************************************************
3007 
3008 
3009 //*************************************************************************************************
3017 template< typename VT // Type of the dense vector
3018  , bool TF > // Transpose flag
3020 {
3021  return ( vector_.begin() + offset_ );
3022 }
3024 //*************************************************************************************************
3025 
3026 
3027 //*************************************************************************************************
3035 template< typename VT // Type of the dense vector
3036  , bool TF > // Transpose flag
3039 {
3040  return ( vector_.cbegin() + offset_ );
3041 }
3043 //*************************************************************************************************
3044 
3045 
3046 //*************************************************************************************************
3054 template< typename VT // Type of the dense vector
3055  , bool TF > // Transpose flag
3058 {
3059  return ( vector_.cbegin() + offset_ );
3060 }
3062 //*************************************************************************************************
3063 
3064 
3065 //*************************************************************************************************
3073 template< typename VT // Type of the dense vector
3074  , bool TF > // Transpose flag
3076 {
3077  return ( vector_.begin() + offset_ + size_ );
3078 }
3080 //*************************************************************************************************
3081 
3082 
3083 //*************************************************************************************************
3091 template< typename VT // Type of the dense vector
3092  , bool TF > // Transpose flag
3095 {
3096  return ( vector_.cbegin() + offset_ + size_ );
3097 }
3099 //*************************************************************************************************
3100 
3101 
3102 //*************************************************************************************************
3110 template< typename VT // Type of the dense vector
3111  , bool TF > // Transpose flag
3114 {
3115  return ( vector_.cbegin() + offset_ + size_ );
3116 }
3118 //*************************************************************************************************
3119 
3120 
3121 
3122 
3123 //=================================================================================================
3124 //
3125 // ASSIGNMENT OPERATORS
3126 //
3127 //=================================================================================================
3128 
3129 //*************************************************************************************************
3136 template< typename VT // Type of the dense vector
3137  , bool TF > // Transpose flag
3138 inline DenseSubvector<VT,aligned,TF>&
3140 {
3141  const size_t iend( offset_ + size_ );
3142 
3143  for( size_t i=offset_; i<iend; ++i )
3144  vector_[i] = rhs;
3145 
3146  return *this;
3147 }
3149 //*************************************************************************************************
3150 
3151 
3152 //*************************************************************************************************
3164 template< typename VT // Type of the dense vector
3165  , bool TF > // Transpose flag
3166 inline DenseSubvector<VT,aligned,TF>&
3167  DenseSubvector<VT,aligned,TF>::operator=( const DenseSubvector& rhs )
3168 {
3171 
3172  if( &rhs == this || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
3173  return *this;
3174 
3175  if( size() != rhs.size() ) {
3176  BLAZE_THROW_INVALID_ARGUMENT( "Subvector sizes do not match" );
3177  }
3178 
3179  if( !tryAssign( vector_, rhs, offset_ ) ) {
3180  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3181  }
3182 
3183  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3184 
3185  if( rhs.canAlias( &vector_ ) ) {
3186  const ResultType tmp( ~rhs );
3187  smpAssign( left, tmp );
3188  }
3189  else {
3190  smpAssign( left, rhs );
3191  }
3192 
3193  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3194 
3195  return *this;
3196 }
3198 //*************************************************************************************************
3199 
3200 
3201 //*************************************************************************************************
3213 template< typename VT // Type of the dense vector
3214  , bool TF > // Transpose flag
3215 template< typename VT2 > // Type of the right-hand side vector
3216 inline DenseSubvector<VT,aligned,TF>&
3217  DenseSubvector<VT,aligned,TF>::operator=( const Vector<VT2,TF>& rhs )
3218 {
3221 
3222  if( size() != (~rhs).size() ) {
3223  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3224  }
3225 
3226  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
3227  Right right( ~rhs );
3228 
3229  if( !tryAssign( vector_, right, offset_ ) ) {
3230  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3231  }
3232 
3233  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3234 
3235  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
3236  const typename VT2::ResultType tmp( right );
3237  smpAssign( left, tmp );
3238  }
3239  else {
3240  if( IsSparseVector<VT2>::value )
3241  reset();
3242  smpAssign( left, right );
3243  }
3244 
3245  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3246 
3247  return *this;
3248 }
3250 //*************************************************************************************************
3251 
3252 
3253 //*************************************************************************************************
3265 template< typename VT // Type of the dense vector
3266  , bool TF > // Transpose flag
3267 template< typename VT2 > // Type of the right-hand side vector
3268 inline DenseSubvector<VT,aligned,TF>&
3269  DenseSubvector<VT,aligned,TF>::operator+=( const Vector<VT2,TF>& rhs )
3270 {
3273 
3274  if( size() != (~rhs).size() ) {
3275  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3276  }
3277 
3278  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
3279  Right right( ~rhs );
3280 
3281  if( !tryAddAssign( vector_, right, offset_ ) ) {
3282  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3283  }
3284 
3285  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3286 
3287  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
3288  const typename VT2::ResultType tmp( right );
3289  smpAddAssign( left, tmp );
3290  }
3291  else {
3292  smpAddAssign( left, right );
3293  }
3294 
3295  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3296 
3297  return *this;
3298 }
3300 //*************************************************************************************************
3301 
3302 
3303 //*************************************************************************************************
3315 template< typename VT // Type of the dense vector
3316  , bool TF > // Transpose flag
3317 template< typename VT2 > // Type of the right-hand side vector
3318 inline DenseSubvector<VT,aligned,TF>&
3319  DenseSubvector<VT,aligned,TF>::operator-=( const Vector<VT2,TF>& rhs )
3320 {
3323 
3324  if( size() != (~rhs).size() ) {
3325  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3326  }
3327 
3328  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
3329  Right right( ~rhs );
3330 
3331  if( !trySubAssign( vector_, right, offset_ ) ) {
3332  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3333  }
3334 
3335  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3336 
3337  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
3338  const typename VT2::ResultType tmp( right );
3339  smpSubAssign( left, tmp );
3340  }
3341  else {
3342  smpSubAssign( left, right );
3343  }
3344 
3345  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3346 
3347  return *this;
3348 }
3350 //*************************************************************************************************
3351 
3352 
3353 //*************************************************************************************************
3366 template< typename VT // Type of the dense vector
3367  , bool TF > // Transpose flag
3368 template< typename VT2 > // Type of the right-hand side dense vector
3369 inline DenseSubvector<VT,aligned,TF>&
3370  DenseSubvector<VT,aligned,TF>::operator*=( const DenseVector<VT2,TF>& rhs )
3371 {
3374 
3375  if( size() != (~rhs).size() ) {
3376  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3377  }
3378 
3379  typedef typename If< IsRestricted<VT>, typename VT2::CompositeType, const VT2& >::Type Right;
3380  Right right( ~rhs );
3381 
3382  if( !tryMultAssign( vector_, right, offset_ ) ) {
3383  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3384  }
3385 
3386  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3387 
3388  if( IsReference<Right>::value && right.canAlias( &vector_ ) ) {
3389  const typename VT2::ResultType tmp( right );
3390  smpMultAssign( left, tmp );
3391  }
3392  else {
3393  smpMultAssign( left, right );
3394  }
3395 
3396  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3397 
3398  return *this;
3399 }
3401 //*************************************************************************************************
3402 
3403 
3404 //*************************************************************************************************
3417 template< typename VT // Type of the dense vector
3418  , bool TF > // Transpose flag
3419 template< typename VT2 > // Type of the right-hand side sparse vector
3420 inline DenseSubvector<VT,aligned,TF>&
3421  DenseSubvector<VT,aligned,TF>::operator*=( const SparseVector<VT2,TF>& rhs )
3422 {
3425 
3426  if( size() != (~rhs).size() ) {
3427  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3428  }
3429 
3430  const ResultType tmp( *this * (~rhs) );
3431 
3432  if( !tryAssign( vector_, tmp, offset_ ) ) {
3433  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted vector" );
3434  }
3435 
3436  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3437 
3438  smpAssign( left, tmp );
3439 
3440  BLAZE_INTERNAL_ASSERT( isIntact( vector_ ), "Invariant violation detected" );
3441 
3442  return *this;
3443 }
3445 //*************************************************************************************************
3446 
3447 
3448 //*************************************************************************************************
3456 template< typename VT // Type of the dense vector
3457  , bool TF > // Transpose flag
3458 template< typename Other > // Data type of the right-hand side scalar
3459 inline typename EnableIf< IsNumeric<Other>, DenseSubvector<VT,aligned,TF> >::Type&
3460  DenseSubvector<VT,aligned,TF>::operator*=( Other rhs )
3461 {
3462  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3463  smpAssign( left, (*this) * rhs );
3464 
3465  return *this;
3466 }
3468 //*************************************************************************************************
3469 
3470 
3471 //*************************************************************************************************
3481 template< typename VT // Type of the dense vector
3482  , bool TF > // Transpose flag
3483 template< typename Other > // Data type of the right-hand side scalar
3484 inline typename EnableIf< IsNumeric<Other>, DenseSubvector<VT,aligned,TF> >::Type&
3485  DenseSubvector<VT,aligned,TF>::operator/=( Other rhs )
3486 {
3487  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3488 
3489  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3490  smpAssign( left, (*this) / rhs );
3491 
3492  return *this;
3493 }
3495 //*************************************************************************************************
3496 
3497 
3498 
3499 
3500 //=================================================================================================
3501 //
3502 // UTILITY FUNCTIONS
3503 //
3504 //=================================================================================================
3505 
3506 //*************************************************************************************************
3512 template< typename VT // Type of the dense vector
3513  , bool TF > // Transpose flag
3514 inline size_t DenseSubvector<VT,aligned,TF>::size() const
3515 {
3516  return size_;
3517 }
3519 //*************************************************************************************************
3520 
3521 
3522 //*************************************************************************************************
3528 template< typename VT // Type of the dense vector
3529  , bool TF > // Transpose flag
3530 inline size_t DenseSubvector<VT,aligned,TF>::capacity() const
3531 {
3532  return vector_.capacity() - offset_;
3533 }
3535 //*************************************************************************************************
3536 
3537 
3538 //*************************************************************************************************
3547 template< typename VT // Type of the dense vector
3548  , bool TF > // Transpose flag
3549 inline size_t DenseSubvector<VT,aligned,TF>::nonZeros() const
3550 {
3551  size_t nonzeros( 0 );
3552 
3553  const size_t iend( offset_ + size_ );
3554  for( size_t i=offset_; i<iend; ++i ) {
3555  if( !isDefault( vector_[i] ) )
3556  ++nonzeros;
3557  }
3558 
3559  return nonzeros;
3560 }
3562 //*************************************************************************************************
3563 
3564 
3565 //*************************************************************************************************
3571 template< typename VT // Type of the dense vector
3572  , bool TF > // Transpose flag
3574 {
3575  using blaze::clear;
3576 
3577  const size_t iend( offset_ + size_ );
3578  for( size_t i=offset_; i<iend; ++i )
3579  clear( vector_[i] );
3580 }
3582 //*************************************************************************************************
3583 
3584 
3585 //*************************************************************************************************
3592 template< typename VT // Type of the dense vector
3593  , bool TF > // Transpose flag
3594 template< typename Other > // Data type of the scalar value
3595 inline DenseSubvector<VT,aligned,TF>& DenseSubvector<VT,aligned,TF>::scale( const Other& scalar )
3596 {
3597  const size_t iend( offset_ + size_ );
3598  for( size_t i=offset_; i<iend; ++i )
3599  vector_[i] *= scalar;
3600  return *this;
3601 }
3603 //*************************************************************************************************
3604 
3605 
3606 
3607 
3608 //=================================================================================================
3609 //
3610 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3611 //
3612 //=================================================================================================
3613 
3614 //*************************************************************************************************
3625 template< typename VT // Type of the dense vector
3626  , bool TF > // Transpose flag
3627 template< typename Other > // Data type of the foreign expression
3628 inline bool DenseSubvector<VT,aligned,TF>::canAlias( const Other* alias ) const
3629 {
3630  return vector_.isAliased( alias );
3631 }
3633 //*************************************************************************************************
3634 
3635 
3636 //*************************************************************************************************
3647 template< typename VT // Type of the dense vector
3648  , bool TF > // Transpose flag
3649 template< typename VT2 // Data type of the foreign dense subvector
3650  , bool AF2 // Alignment flag of the foreign dense subvector
3651  , bool TF2 > // Transpose flag of the foreign dense subvector
3652 inline bool DenseSubvector<VT,aligned,TF>::canAlias( const DenseSubvector<VT2,AF2,TF2>* alias ) const
3653 {
3654  return ( vector_.isAliased( &alias->vector_ ) &&
3655  ( offset_ + size_ > alias->offset_ ) && ( offset_ < alias->offset_ + alias->size_ ) );
3656 }
3658 //*************************************************************************************************
3659 
3660 
3661 //*************************************************************************************************
3672 template< typename VT // Type of the dense vector
3673  , bool TF > // Transpose flag
3674 template< typename Other > // Data type of the foreign expression
3675 inline bool DenseSubvector<VT,aligned,TF>::isAliased( const Other* alias ) const
3676 {
3677  return vector_.isAliased( alias );
3678 }
3680 //*************************************************************************************************
3681 
3682 
3683 //*************************************************************************************************
3694 template< typename VT // Type of the dense vector
3695  , bool TF > // Transpose flag
3696 template< typename VT2 // Data type of the foreign dense subvector
3697  , bool AF2 // Alignment flag of the foreign dense subvector
3698  , bool TF2 > // Transpose flag of the foreign dense subvector
3699 inline bool DenseSubvector<VT,aligned,TF>::isAliased( const DenseSubvector<VT2,AF2,TF2>* alias ) const
3700 {
3701  return ( vector_.isAliased( &alias->vector_ ) &&
3702  ( offset_ + size_ > alias->offset_ ) && ( offset_ < alias->offset_ + alias->size_ ) );
3703 }
3705 //*************************************************************************************************
3706 
3707 
3708 //*************************************************************************************************
3718 template< typename VT // Type of the dense vector
3719  , bool TF > // Transpose flag
3720 inline bool DenseSubvector<VT,aligned,TF>::isAligned() const
3721 {
3722  return true;
3723 }
3725 //*************************************************************************************************
3726 
3727 
3728 //*************************************************************************************************
3739 template< typename VT // Type of the dense vector
3740  , bool TF > // Transpose flag
3742 {
3743  return ( size() > SMP_DVECASSIGN_THRESHOLD );
3744 }
3746 //*************************************************************************************************
3747 
3748 
3749 //*************************************************************************************************
3763 template< typename VT // Type of the dense vector
3764  , bool TF > // Transpose flag
3765 BLAZE_ALWAYS_INLINE typename DenseSubvector<VT,aligned,TF>::IntrinsicType
3766  DenseSubvector<VT,aligned,TF>::load( size_t index ) const
3767 {
3768  return loada( index );
3769 }
3771 //*************************************************************************************************
3772 
3773 
3774 //*************************************************************************************************
3788 template< typename VT // Type of the dense vector
3789  , bool TF > // Transpose flag
3790 BLAZE_ALWAYS_INLINE typename DenseSubvector<VT,aligned,TF>::IntrinsicType
3791  DenseSubvector<VT,aligned,TF>::loada( size_t index ) const
3792 {
3794 
3795  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
3796  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
3797  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
3798 
3799  return vector_.loada( offset_+index );
3800 }
3802 //*************************************************************************************************
3803 
3804 
3805 //*************************************************************************************************
3819 template< typename VT // Type of the dense vector
3820  , bool TF > // Transpose flag
3821 BLAZE_ALWAYS_INLINE typename DenseSubvector<VT,aligned,TF>::IntrinsicType
3822  DenseSubvector<VT,aligned,TF>::loadu( size_t index ) const
3823 {
3825 
3826  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
3827  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
3828  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
3829 
3830  return vector_.loadu( offset_+index );
3831 }
3833 //*************************************************************************************************
3834 
3835 
3836 //*************************************************************************************************
3851 template< typename VT // Type of the dense vector
3852  , bool TF > // Transpose flag
3854  DenseSubvector<VT,aligned,TF>::store( size_t index, const IntrinsicType& value )
3855 {
3856  storea( index, value );
3857 }
3859 //*************************************************************************************************
3860 
3861 
3862 //*************************************************************************************************
3877 template< typename VT // Type of the dense vector
3878  , bool TF > // Transpose flag
3880  DenseSubvector<VT,aligned,TF>::storea( size_t index, const IntrinsicType& value )
3881 {
3883 
3884  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
3885  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
3886  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
3887 
3888  vector_.storea( offset_+index, value );
3889 }
3891 //*************************************************************************************************
3892 
3893 
3894 //*************************************************************************************************
3909 template< typename VT // Type of the dense vector
3910  , bool TF > // Transpose flag
3912  DenseSubvector<VT,aligned,TF>::storeu( size_t index, const IntrinsicType& value )
3913 {
3915 
3916  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
3917  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
3918  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
3919 
3920  vector_.storeu( offset_+index, value );
3921 }
3923 //*************************************************************************************************
3924 
3925 
3926 //*************************************************************************************************
3941 template< typename VT // Type of the dense vector
3942  , bool TF > // Transpose flag
3944  DenseSubvector<VT,aligned,TF>::stream( size_t index, const IntrinsicType& value )
3945 {
3947 
3948  BLAZE_INTERNAL_ASSERT( index < size() , "Invalid subvector access index" );
3949  BLAZE_INTERNAL_ASSERT( index + IT::size <= size(), "Invalid subvector access index" );
3950  BLAZE_INTERNAL_ASSERT( index % IT::size == 0UL , "Invalid subvector access index" );
3951 
3952  vector_.stream( offset_+index, value );
3953 }
3955 //*************************************************************************************************
3956 
3957 
3958 //*************************************************************************************************
3970 template< typename VT // Type of the dense vector
3971  , bool TF > // Transpose flag
3972 template< typename VT2 > // Type of the right-hand side dense vector
3973 inline typename DisableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedAssign<VT2> >::Type
3974  DenseSubvector<VT,aligned,TF>::assign( const DenseVector<VT2,TF>& rhs )
3975 {
3976  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3977 
3978  const size_t ipos( size() & size_t(-2) );
3979  for( size_t i=0UL; i<ipos; i+=2UL ) {
3980  vector_[offset_+i ] = (~rhs)[i ];
3981  vector_[offset_+i+1UL] = (~rhs)[i+1UL];
3982  }
3983  if( ipos < size() ) {
3984  vector_[offset_+ipos] = (~rhs)[ipos];
3985  }
3986 }
3988 //*************************************************************************************************
3989 
3990 
3991 //*************************************************************************************************
4003 template< typename VT // Type of the dense vector
4004  , bool TF > // Transpose flag
4005 template< typename VT2 > // Type of the right-hand side dense vector
4006 inline typename EnableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedAssign<VT2> >::Type
4007  DenseSubvector<VT,aligned,TF>::assign( const DenseVector<VT2,TF>& rhs )
4008 {
4010 
4011  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4012 
4013  const size_t ipos( size_ & size_t(-IT::size) );
4014  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
4015 
4016  if( useStreaming && size_ > ( cacheSize/( sizeof(ElementType) * 3UL ) ) && !(~rhs).isAliased( &vector_ ) )
4017  {
4018  size_t i( 0UL );
4019 
4020  for( ; i<ipos; i+=IT::size ) {
4021  stream( i, (~rhs).load(i) );
4022  }
4023  for( ; i<size_; ++i ) {
4024  vector_[offset_+i] = (~rhs)[i];
4025  }
4026  }
4027  else
4028  {
4029  size_t i( 0UL );
4030  typename VT2::ConstIterator it( (~rhs).begin() );
4031 
4032  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
4033  store( i , it.load() ); it += IT::size;
4034  store( i+IT::size , it.load() ); it += IT::size;
4035  store( i+IT::size*2UL, it.load() ); it += IT::size;
4036  store( i+IT::size*3UL, it.load() ); it += IT::size;
4037  }
4038  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4039  store( i, it.load() );
4040  }
4041  for( ; i<size_; ++i, ++it ) {
4042  vector_[offset_+i] = *it;
4043  }
4044  }
4045 }
4047 //*************************************************************************************************
4048 
4049 
4050 //*************************************************************************************************
4062 template< typename VT // Type of the dense vector
4063  , bool TF > // Transpose flag
4064 template< typename VT2 > // Type of the right-hand side dense vector
4065 inline void DenseSubvector<VT,aligned,TF>::assign( const SparseVector<VT2,TF>& rhs )
4066 {
4067  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4068 
4069  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4070  vector_[offset_+element->index()] = element->value();
4071 }
4073 //*************************************************************************************************
4074 
4075 
4076 //*************************************************************************************************
4088 template< typename VT // Type of the dense vector
4089  , bool TF > // Transpose flag
4090 template< typename VT2 > // Type of the right-hand side dense vector
4091 inline typename DisableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT2> >::Type
4092  DenseSubvector<VT,aligned,TF>::addAssign( const DenseVector<VT2,TF>& rhs )
4093 {
4094  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4095 
4096  const size_t ipos( size() & size_t(-2) );
4097  for( size_t i=0UL; i<ipos; i+=2UL ) {
4098  vector_[offset_+i ] += (~rhs)[i ];
4099  vector_[offset_+i+1UL] += (~rhs)[i+1UL];
4100  }
4101  if( ipos < size() ) {
4102  vector_[offset_+ipos] += (~rhs)[ipos];
4103  }
4104 }
4106 //*************************************************************************************************
4107 
4108 
4109 //*************************************************************************************************
4121 template< typename VT // Type of the dense vector
4122  , bool TF > // Transpose flag
4123 template< typename VT2 > // Type of the right-hand side dense vector
4124 inline typename EnableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedAddAssign<VT2> >::Type
4125  DenseSubvector<VT,aligned,TF>::addAssign( const DenseVector<VT2,TF>& rhs )
4126 {
4128 
4129  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4130 
4131  const size_t ipos( size_ & size_t(-IT::size) );
4132  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
4133 
4134  size_t i( 0UL );
4135  typename VT2::ConstIterator it( (~rhs).begin() );
4136 
4137  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
4138  store( i , load(i ) + it.load() ); it += IT::size;
4139  store( i+IT::size , load(i+IT::size ) + it.load() ); it += IT::size;
4140  store( i+IT::size*2UL, load(i+IT::size*2UL) + it.load() ); it += IT::size;
4141  store( i+IT::size*3UL, load(i+IT::size*3UL) + it.load() ); it += IT::size;
4142  }
4143  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4144  store( i, load(i) + it.load() );
4145  }
4146  for( ; i<size_; ++i, ++it ) {
4147  vector_[offset_+i] += *it;
4148  }
4149 }
4151 //*************************************************************************************************
4152 
4153 
4154 //*************************************************************************************************
4166 template< typename VT // Type of the dense vector
4167  , bool TF > // Transpose flag
4168 template< typename VT2 > // Type of the right-hand side dense vector
4169 inline void DenseSubvector<VT,aligned,TF>::addAssign( const SparseVector<VT2,TF>& rhs )
4170 {
4171  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4172 
4173  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4174  vector_[offset_+element->index()] += element->value();
4175 }
4177 //*************************************************************************************************
4178 
4179 
4180 //*************************************************************************************************
4192 template< typename VT // Type of the dense vector
4193  , bool TF > // Transpose flag
4194 template< typename VT2 > // Type of the right-hand side dense vector
4195 inline typename DisableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT2> >::Type
4196  DenseSubvector<VT,aligned,TF>::subAssign( const DenseVector<VT2,TF>& rhs )
4197 {
4198  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4199 
4200  const size_t ipos( size() & size_t(-2) );
4201  for( size_t i=0UL; i<ipos; i+=2UL ) {
4202  vector_[offset_+i ] -= (~rhs)[i ];
4203  vector_[offset_+i+1UL] -= (~rhs)[i+1UL];
4204  }
4205  if( ipos < size() ) {
4206  vector_[offset_+ipos] -= (~rhs)[ipos];
4207  }
4208 }
4210 //*************************************************************************************************
4211 
4212 
4213 //*************************************************************************************************
4225 template< typename VT // Type of the dense vector
4226  , bool TF > // Transpose flag
4227 template< typename VT2 > // Type of the right-hand side dense vector
4228 inline typename EnableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedSubAssign<VT2> >::Type
4229  DenseSubvector<VT,aligned,TF>::subAssign( const DenseVector<VT2,TF>& rhs )
4230 {
4232 
4233  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4234 
4235  const size_t ipos( size_ & size_t(-IT::size) );
4236  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
4237 
4238  size_t i( 0UL );
4239  typename VT2::ConstIterator it( (~rhs).begin() );
4240 
4241  for( ; (i+IT::size*3UL) < ipos; 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( ; i<size_; ++i, ++it ) {
4251  vector_[offset_+i] -= *it;
4252  }
4253 }
4255 //*************************************************************************************************
4256 
4257 
4258 //*************************************************************************************************
4270 template< typename VT // Type of the dense vector
4271  , bool TF > // Transpose flag
4272 template< typename VT2 > // Type of the right-hand side dense vector
4273 inline void DenseSubvector<VT,aligned,TF>::subAssign( const SparseVector<VT2,TF>& rhs )
4274 {
4275  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4276 
4277  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4278  vector_[offset_+element->index()] -= element->value();
4279 }
4281 //*************************************************************************************************
4282 
4283 
4284 //*************************************************************************************************
4296 template< typename VT // Type of the dense vector
4297  , bool TF > // Transpose flag
4298 template< typename VT2 > // Type of the right-hand side dense vector
4299 inline typename DisableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT2> >::Type
4300  DenseSubvector<VT,aligned,TF>::multAssign( const DenseVector<VT2,TF>& rhs )
4301 {
4302  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4303 
4304  const size_t ipos( size() & size_t(-2) );
4305  for( size_t i=0UL; i<ipos; i+=2UL ) {
4306  vector_[offset_+i ] *= (~rhs)[i ];
4307  vector_[offset_+i+1UL] *= (~rhs)[i+1UL];
4308  }
4309  if( ipos < size() ) {
4310  vector_[offset_+ipos] *= (~rhs)[ipos];
4311  }
4312 }
4314 //*************************************************************************************************
4315 
4316 
4317 //*************************************************************************************************
4329 template< typename VT // Type of the dense vector
4330  , bool TF > // Transpose flag
4331 template< typename VT2 > // Type of the right-hand side dense vector
4332 inline typename EnableIf< typename DenseSubvector<VT,aligned,TF>::BLAZE_TEMPLATE VectorizedMultAssign<VT2> >::Type
4333  DenseSubvector<VT,aligned,TF>::multAssign( const DenseVector<VT2,TF>& rhs )
4334 {
4336 
4337  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4338 
4339  const size_t ipos( size_ & size_t(-IT::size) );
4340  BLAZE_INTERNAL_ASSERT( ( size_ - ( size_ % (IT::size) ) ) == ipos, "Invalid end calculation" );
4341 
4342  size_t i( 0UL );
4343  typename VT2::ConstIterator it( (~rhs).begin() );
4344 
4345  for( ; (i+IT::size*3UL) < ipos; i+=IT::size*4UL ) {
4346  store( i , load(i ) * it.load() ); it += IT::size;
4347  store( i+IT::size , load(i+IT::size ) * it.load() ); it += IT::size;
4348  store( i+IT::size*2UL, load(i+IT::size*2UL) * it.load() ); it += IT::size;
4349  store( i+IT::size*3UL, load(i+IT::size*3UL) * it.load() ); it += IT::size;
4350  }
4351  for( ; i<ipos; i+=IT::size, it+=IT::size ) {
4352  store( i, load(i) * it.load() );
4353  }
4354  for( ; i<size_; ++i, ++it ) {
4355  vector_[offset_+i] *= *it;
4356  }
4357 }
4359 //*************************************************************************************************
4360 
4361 
4362 //*************************************************************************************************
4374 template< typename VT // Type of the dense vector
4375  , bool TF > // Transpose flag
4376 template< typename VT2 > // Type of the right-hand side dense vector
4377 inline void DenseSubvector<VT,aligned,TF>::multAssign( const SparseVector<VT2,TF>& rhs )
4378 {
4379  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4380 
4381  const ResultType tmp( serial( *this ) );
4382 
4383  reset();
4384 
4385  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element )
4386  vector_[offset_+element->index()] = tmp[element->index()] * element->value();
4387 }
4389 //*************************************************************************************************
4390 
4391 
4392 
4393 
4394 
4395 
4396 
4397 
4398 //=================================================================================================
4399 //
4400 // CLASS TEMPLATE SPECIALIZATION FOR DVECDVECCROSSEXPR
4401 //
4402 //=================================================================================================
4403 
4404 //*************************************************************************************************
4412 template< typename VT1 // Type of the left-hand side dense vector
4413  , typename VT2 > // Type of the right-hand side dense vector
4414 class DenseSubvector< DVecDVecCrossExpr<VT1,VT2>, unaligned, false >
4415  : public DenseVector< DenseSubvector< DVecDVecCrossExpr<VT1,VT2>, unaligned, false >, false >
4416  , private Subvector
4417 {
4418  private:
4419  //**Type definitions****************************************************************************
4420  typedef DVecDVecCrossExpr<VT1,VT2> CPE;
4421  typedef typename CPE::ResultType RT;
4422  //**********************************************************************************************
4423 
4424  public:
4425  //**Type definitions****************************************************************************
4426  typedef DenseSubvector<CPE,unaligned,false> This;
4427  typedef typename SubvectorTrait<RT>::Type ResultType;
4428  typedef typename ResultType::TransposeType TransposeType;
4429  typedef typename CPE::ElementType ElementType;
4430  typedef typename CPE::ReturnType ReturnType;
4431  typedef const ResultType CompositeType;
4432  //**********************************************************************************************
4433 
4434  //**Compilation flags***************************************************************************
4436  enum { vectorizable = 0 };
4437 
4439  enum { smpAssignable = 0 };
4440  //**********************************************************************************************
4441 
4442  //**Constructor*********************************************************************************
4449  explicit inline DenseSubvector( const CPE& vector, size_t index, size_t n )
4450  : vector_( vector ) // The dense vector/dense vector cross product expression
4451  , offset_( index ) // The offset of the subvector within the cross product expression
4452  , size_ ( n ) // The size of the subvector
4453  {}
4454  //**********************************************************************************************
4455 
4456  //**Subscript operator**************************************************************************
4462  inline ReturnType operator[]( size_t index ) const {
4463  BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
4464  return vector_[offset_+index];
4465  }
4466  //**********************************************************************************************
4467 
4468  //**At function*********************************************************************************
4475  inline ReturnType at( size_t index ) const {
4476  if( index >= size() ) {
4477  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
4478  }
4479  return (*this)[index];
4480  }
4481  //**********************************************************************************************
4482 
4483  //**Size function*******************************************************************************
4488  inline size_t size() const {
4489  return size_;
4490  }
4491  //**********************************************************************************************
4492 
4493  //**********************************************************************************************
4499  template< typename T >
4500  inline bool canAlias( const T* alias ) const {
4501  return vector_.canAlias( alias );
4502  }
4503  //**********************************************************************************************
4504 
4505  //**********************************************************************************************
4511  template< typename T >
4512  inline bool isAliased( const T* alias ) const {
4513  return vector_.isAliased( alias );
4514  }
4515  //**********************************************************************************************
4516 
4517  private:
4518  //**Member variables****************************************************************************
4521  CPE vector_;
4522  const size_t offset_;
4523  const size_t size_;
4524 
4525  //**********************************************************************************************
4526 
4527  //**Friend declarations*************************************************************************
4528  template< bool AF1, typename VT, bool AF2, bool TF >
4529  friend const DenseSubvector<VT,AF1,TF>
4530  subvector( const DenseSubvector<VT,AF2,TF>& dv, size_t index, size_t size );
4531 
4532  template< typename VT3, bool AF, bool TF >
4533  friend bool isIntact( const DenseSubvector<VT3,AF,TF>& dv );
4534 
4535  template< typename VT3, bool AF, bool TF >
4536  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseVector<VT3,TF>& b );
4537 
4538  template< typename VT3, bool AF, bool TF >
4539  friend bool isSame( const DenseVector<VT3,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4540 
4541  template< typename VT3, bool AF, bool TF >
4542  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4543 
4544  template< typename VT3, bool AF, bool TF, typename VT4 >
4545  friend bool tryAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4546 
4547  template< typename VT3, bool AF, bool TF, typename VT4 >
4548  friend bool tryAddAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4549 
4550  template< typename VT3, bool AF, bool TF, typename VT4 >
4551  friend bool trySubAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4552 
4553  template< typename VT3, bool AF, bool TF, typename VT4 >
4554  friend bool tryMultAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4555  //**********************************************************************************************
4556 };
4558 //*************************************************************************************************
4559 
4560 
4561 
4562 
4563 
4564 
4565 
4566 
4567 //=================================================================================================
4568 //
4569 // CLASS TEMPLATE SPECIALIZATION FOR DVECSVECCROSSEXPR
4570 //
4571 //=================================================================================================
4572 
4573 //*************************************************************************************************
4581 template< typename VT1 // Type of the left-hand side dense vector
4582  , typename VT2 > // Type of the right-hand side sparse vector
4583 class DenseSubvector< DVecSVecCrossExpr<VT1,VT2>, unaligned, false >
4584  : public DenseVector< DenseSubvector< DVecSVecCrossExpr<VT1,VT2>, unaligned, false >, false >
4585  , private Subvector
4586 {
4587  private:
4588  //**Type definitions****************************************************************************
4589  typedef DVecSVecCrossExpr<VT1,VT2> CPE;
4590  typedef typename CPE::ResultType RT;
4591  //**********************************************************************************************
4592 
4593  public:
4594  //**Type definitions****************************************************************************
4595  typedef DenseSubvector<CPE,unaligned,false> This;
4596  typedef typename SubvectorTrait<RT>::Type ResultType;
4597  typedef typename ResultType::TransposeType TransposeType;
4598  typedef typename CPE::ElementType ElementType;
4599  typedef typename CPE::ReturnType ReturnType;
4600  typedef const ResultType CompositeType;
4601  //**********************************************************************************************
4602 
4603  //**Compilation flags***************************************************************************
4605  enum { vectorizable = 0 };
4606 
4608  enum { smpAssignable = 0 };
4609  //**********************************************************************************************
4610 
4611  //**Constructor*********************************************************************************
4618  explicit inline DenseSubvector( const CPE& vector, size_t index, size_t n )
4619  : vector_( vector ) // The dense vector/sparse vector cross product expression
4620  , offset_( index ) // The offset of the subvector within the cross product expression
4621  , size_ ( n ) // The size of the subvector
4622  {}
4623  //**********************************************************************************************
4624 
4625  //**Subscript operator**************************************************************************
4631  inline ReturnType operator[]( size_t index ) const {
4632  BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
4633  return vector_[offset_+index];
4634  }
4635  //**********************************************************************************************
4636 
4637  //**At function*********************************************************************************
4644  inline ReturnType at( size_t index ) const {
4645  if( index >= size() ) {
4646  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
4647  }
4648  return (*this)[index];
4649  }
4650  //**********************************************************************************************
4651 
4652  //**Size function*******************************************************************************
4657  inline size_t size() const {
4658  return size_;
4659  }
4660  //**********************************************************************************************
4661 
4662  //**********************************************************************************************
4668  template< typename T >
4669  inline bool canAlias( const T* alias ) const {
4670  return vector_.canAlias( alias );
4671  }
4672  //**********************************************************************************************
4673 
4674  //**********************************************************************************************
4680  template< typename T >
4681  inline bool isAliased( const T* alias ) const {
4682  return vector_.isAliased( alias );
4683  }
4684  //**********************************************************************************************
4685 
4686  private:
4687  //**Member variables****************************************************************************
4690  CPE vector_;
4691  const size_t offset_;
4692  const size_t size_;
4693 
4694  //**********************************************************************************************
4695 
4696  //**Friend declarations*************************************************************************
4697  template< bool AF1, typename VT, bool AF2, bool TF >
4698  friend const DenseSubvector<VT,AF1,TF>
4699  subvector( const DenseSubvector<VT,AF2,TF>& dv, size_t index, size_t size );
4700 
4701  template< typename VT3, bool AF, bool TF >
4702  friend bool isIntact( const DenseSubvector<VT3,AF,TF>& dv );
4703 
4704  template< typename VT3, bool AF, bool TF >
4705  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseVector<VT3,TF>& b );
4706 
4707  template< typename VT3, bool AF, bool TF >
4708  friend bool isSame( const DenseVector<VT3,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4709 
4710  template< typename VT3, bool AF, bool TF >
4711  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4712 
4713  template< typename VT3, bool AF, bool TF, typename VT4 >
4714  friend bool tryAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4715 
4716  template< typename VT3, bool AF, bool TF, typename VT4 >
4717  friend bool tryAddAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4718 
4719  template< typename VT3, bool AF, bool TF, typename VT4 >
4720  friend bool trySubAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4721 
4722  template< typename VT3, bool AF, bool TF, typename VT4 >
4723  friend bool tryMultAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4724  //**********************************************************************************************
4725 };
4727 //*************************************************************************************************
4728 
4729 
4730 
4731 
4732 
4733 
4734 
4735 
4736 //=================================================================================================
4737 //
4738 // CLASS TEMPLATE SPECIALIZATION FOR SVECDVECCROSSEXPR
4739 //
4740 //=================================================================================================
4741 
4742 //*************************************************************************************************
4750 template< typename VT1 // Type of the left-hand side sparse vector
4751  , typename VT2 > // Type of the right-hand side dense vector
4752 class DenseSubvector< SVecDVecCrossExpr<VT1,VT2>, unaligned, false >
4753  : public DenseVector< DenseSubvector< SVecDVecCrossExpr<VT1,VT2>, unaligned, false >, false >
4754  , private Subvector
4755 {
4756  private:
4757  //**Type definitions****************************************************************************
4758  typedef SVecDVecCrossExpr<VT1,VT2> CPE;
4759  typedef typename CPE::ResultType RT;
4760  //**********************************************************************************************
4761 
4762  public:
4763  //**Type definitions****************************************************************************
4764  typedef DenseSubvector<CPE,unaligned,false> This;
4765  typedef typename SubvectorTrait<RT>::Type ResultType;
4766  typedef typename ResultType::TransposeType TransposeType;
4767  typedef typename CPE::ElementType ElementType;
4768  typedef typename CPE::ReturnType ReturnType;
4769  typedef const ResultType CompositeType;
4770  //**********************************************************************************************
4771 
4772  //**Compilation flags***************************************************************************
4774  enum { vectorizable = 0 };
4775 
4777  enum { smpAssignable = 0 };
4778  //**********************************************************************************************
4779 
4780  //**Constructor*********************************************************************************
4787  explicit inline DenseSubvector( const CPE& vector, size_t index, size_t n )
4788  : vector_( vector ) // The sparse vector/dense vector cross product expression
4789  , offset_( index ) // The offset of the subvector within the cross product expression
4790  , size_ ( n ) // The size of the subvector
4791  {}
4792  //**********************************************************************************************
4793 
4794  //**Subscript operator**************************************************************************
4800  inline ReturnType operator[]( size_t index ) const {
4801  BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
4802  return vector_[offset_+index];
4803  }
4804  //**********************************************************************************************
4805 
4806  //**At function*********************************************************************************
4813  inline ReturnType at( size_t index ) const {
4814  if( index >= size() ) {
4815  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
4816  }
4817  return (*this)[index];
4818  }
4819  //**********************************************************************************************
4820 
4821  //**Size function*******************************************************************************
4826  inline size_t size() const {
4827  return size_;
4828  }
4829  //**********************************************************************************************
4830 
4831  //**********************************************************************************************
4837  template< typename T >
4838  inline bool canAlias( const T* alias ) const {
4839  return vector_.canAlias( alias );
4840  }
4841  //**********************************************************************************************
4842 
4843  //**********************************************************************************************
4849  template< typename T >
4850  inline bool isAliased( const T* alias ) const {
4851  return vector_.isAliased( alias );
4852  }
4853  //**********************************************************************************************
4854 
4855  private:
4856  //**Member variables****************************************************************************
4859  CPE vector_;
4860  const size_t offset_;
4861  const size_t size_;
4862 
4863  //**********************************************************************************************
4864 
4865  //**Friend declarations*************************************************************************
4866  template< bool AF1, typename VT, bool AF2, bool TF >
4867  friend const DenseSubvector<VT,AF1,TF>
4868  subvector( const DenseSubvector<VT,AF2,TF>& dv, size_t index, size_t size );
4869 
4870  template< typename VT3, bool AF, bool TF >
4871  friend bool isIntact( const DenseSubvector<VT3,AF,TF>& dv );
4872 
4873  template< typename VT3, bool AF, bool TF >
4874  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseVector<VT3,TF>& b );
4875 
4876  template< typename VT3, bool AF, bool TF >
4877  friend bool isSame( const DenseVector<VT3,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4878 
4879  template< typename VT3, bool AF, bool TF >
4880  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
4881 
4882  template< typename VT3, bool AF, bool TF, typename VT4 >
4883  friend bool tryAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4884 
4885  template< typename VT3, bool AF, bool TF, typename VT4 >
4886  friend bool tryAddAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4887 
4888  template< typename VT3, bool AF, bool TF, typename VT4 >
4889  friend bool trySubAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
4890 
4891  template< typename VT3, bool AF, bool TF, typename VT4 >
4892  friend bool tryMultAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
4893  //**********************************************************************************************
4894 };
4896 //*************************************************************************************************
4897 
4898 
4899 
4900 
4901 
4902 
4903 
4904 
4905 //=================================================================================================
4906 //
4907 // CLASS TEMPLATE SPECIALIZATION FOR SVECSVECCROSSEXPR
4908 //
4909 //=================================================================================================
4910 
4911 //*************************************************************************************************
4919 template< typename VT1 // Type of the left-hand side sparse vector
4920  , typename VT2 > // Type of the right-hand side sparse vector
4921 class DenseSubvector< SVecSVecCrossExpr<VT1,VT2>, unaligned, false >
4922  : public DenseVector< DenseSubvector< SVecSVecCrossExpr<VT1,VT2>, unaligned, false >, false >
4923  , private Subvector
4924 {
4925  private:
4926  //**Type definitions****************************************************************************
4927  typedef SVecSVecCrossExpr<VT1,VT2> CPE;
4928  typedef typename CPE::ResultType RT;
4929  //**********************************************************************************************
4930 
4931  public:
4932  //**Type definitions****************************************************************************
4933  typedef DenseSubvector<CPE,unaligned,false> This;
4934  typedef typename SubvectorTrait<RT>::Type ResultType;
4935  typedef typename ResultType::TransposeType TransposeType;
4936  typedef typename CPE::ElementType ElementType;
4937  typedef typename CPE::ReturnType ReturnType;
4938  typedef const ResultType CompositeType;
4939  //**********************************************************************************************
4940 
4941  //**Compilation flags***************************************************************************
4943  enum { vectorizable = 0 };
4944 
4946  enum { smpAssignable = 0 };
4947  //**********************************************************************************************
4948 
4949  //**Constructor*********************************************************************************
4956  explicit inline DenseSubvector( const CPE& vector, size_t index, size_t n )
4957  : vector_( vector ) // The sparse vector/sparse vector cross product expression
4958  , offset_( index ) // The offset of the subvector within the cross product expression
4959  , size_ ( n ) // The size of the subvector
4960  {}
4961  //**********************************************************************************************
4962 
4963  //**Subscript operator**************************************************************************
4969  inline ReturnType operator[]( size_t index ) const {
4970  BLAZE_INTERNAL_ASSERT( index < size(), "Invalid vector access index" );
4971  return vector_[offset_+index];
4972  }
4973  //**********************************************************************************************
4974 
4975  //**At function*********************************************************************************
4982  inline ReturnType at( size_t index ) const {
4983  if( index >= size() ) {
4984  BLAZE_THROW_OUT_OF_RANGE( "Invalid vector access index" );
4985  }
4986  return (*this)[index];
4987  }
4988  //**********************************************************************************************
4989 
4990  //**Size function*******************************************************************************
4995  inline size_t size() const {
4996  return size_;
4997  }
4998  //**********************************************************************************************
4999 
5000  //**********************************************************************************************
5006  template< typename T >
5007  inline bool canAlias( const T* alias ) const {
5008  return vector_.canAlias( alias );
5009  }
5010  //**********************************************************************************************
5011 
5012  //**********************************************************************************************
5018  template< typename T >
5019  inline bool isAliased( const T* alias ) const {
5020  return vector_.isAliased( alias );
5021  }
5022  //**********************************************************************************************
5023 
5024  private:
5025  //**Member variables****************************************************************************
5028  CPE vector_;
5029  const size_t offset_;
5030  const size_t size_;
5031 
5032  //**********************************************************************************************
5033 
5034  //**Friend declarations*************************************************************************
5035  template< bool AF1, typename VT, bool AF2, bool TF >
5036  friend const DenseSubvector<VT,AF1,TF>
5037  subvector( const DenseSubvector<VT,AF2,TF>& dv, size_t index, size_t size );
5038 
5039  template< typename VT3, bool AF, bool TF >
5040  friend bool isIntact( const DenseSubvector<VT3,AF,TF>& dv );
5041 
5042  template< typename VT3, bool AF, bool TF >
5043  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseVector<VT3,TF>& b );
5044 
5045  template< typename VT3, bool AF, bool TF >
5046  friend bool isSame( const DenseVector<VT3,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
5047 
5048  template< typename VT3, bool AF, bool TF >
5049  friend bool isSame( const DenseSubvector<VT3,AF,TF>& a, const DenseSubvector<VT3,AF,TF>& b );
5050 
5051  template< typename VT3, bool AF, bool TF, typename VT4 >
5052  friend bool tryAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
5053 
5054  template< typename VT3, bool AF, bool TF, typename VT4 >
5055  friend bool tryAddAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
5056 
5057  template< typename VT3, bool AF, bool TF, typename VT4 >
5058  friend bool trySubAssign( const DenseSubvector<VT2,AF,TF>& lhs, const Vector<VT3,TF>& rhs, size_t index );
5059 
5060  template< typename VT3, bool AF, bool TF, typename VT4 >
5061  friend bool tryMultAssign( const DenseSubvector<VT3,AF,TF>& lhs, const Vector<VT4,TF>& rhs, size_t index );
5062  //**********************************************************************************************
5063 };
5065 //*************************************************************************************************
5066 
5067 
5068 
5069 
5070 
5071 
5072 
5073 
5074 //=================================================================================================
5075 //
5076 // DENSESUBVECTOR OPERATORS
5077 //
5078 //=================================================================================================
5079 
5080 //*************************************************************************************************
5083 template< typename VT, bool AF, bool TF >
5084 inline void reset( DenseSubvector<VT,AF,TF>& dv );
5085 
5086 template< typename VT, bool AF, bool TF >
5087 inline void clear( DenseSubvector<VT,AF,TF>& dv );
5088 
5089 template< typename VT, bool AF, bool TF >
5090 inline bool isDefault( const DenseSubvector<VT,AF,TF>& dv );
5091 
5092 template< typename VT, bool AF, bool TF >
5093 inline bool isIntact( const DenseSubvector<VT,AF,TF>& dv );
5094 
5095 template< typename VT, bool AF, bool TF >
5096 inline bool isSame( const DenseSubvector<VT,AF,TF>& a, const DenseVector<VT,TF>& b );
5097 
5098 template< typename VT, bool AF, bool TF >
5099 inline bool isSame( const DenseVector<VT,TF>& a, const DenseSubvector<VT,AF,TF>& b );
5100 
5101 template< typename VT, bool AF, bool TF >
5102 inline bool isSame( const DenseSubvector<VT,AF,TF>& a, const DenseSubvector<VT,AF,TF>& b );
5104 //*************************************************************************************************
5105 
5106 
5107 //*************************************************************************************************
5114 template< typename VT // Type of the dense vector
5115  , bool AF // Alignment flag
5116  , bool TF > // Transpose flag
5118 {
5119  dv.reset();
5120 }
5121 //*************************************************************************************************
5122 
5123 
5124 //*************************************************************************************************
5131 template< typename VT // Type of the dense vector
5132  , bool AF // Alignment flag
5133  , bool TF > // Transpose flag
5135 {
5136  dv.reset();
5137 }
5138 //*************************************************************************************************
5139 
5140 
5141 //*************************************************************************************************
5160 template< typename VT // Type of the dense vector
5161  , bool AF // Alignment flag
5162  , bool TF > // Transpose flag
5163 inline bool isDefault( const DenseSubvector<VT,AF,TF>& dv )
5164 {
5165  for( size_t i=0UL; i<dv.size(); ++i )
5166  if( !isDefault( dv[i] ) ) return false;
5167  return true;
5168 }
5169 //*************************************************************************************************
5170 
5171 
5172 //*************************************************************************************************
5190 template< typename VT // Type of the dense vector
5191  , bool AF // Alignment flag
5192  , bool TF > // Transpose flag
5193 inline bool isIntact( const DenseSubvector<VT,AF,TF>& dv )
5194 {
5195  return ( dv.offset_ + dv.size_ <= dv.vector_.size() &&
5196  isIntact( dv.vector_ ) );
5197 }
5198 //*************************************************************************************************
5199 
5200 
5201 //*************************************************************************************************
5213 template< typename VT // Type of the dense vector
5214  , bool AF // Alignment flag
5215  , bool TF > // Transpose flag
5216 inline bool isSame( const DenseSubvector<VT,AF,TF>& a, const DenseVector<VT,TF>& b )
5217 {
5218  return ( isSame( a.vector_, ~b ) && ( a.size() == (~b).size() ) );
5219 }
5220 //*************************************************************************************************
5221 
5222 
5223 //*************************************************************************************************
5235 template< typename VT // Type of the dense vector
5236  , bool AF // Alignment flag
5237  , bool TF > // Transpose flag
5238 inline bool isSame( const DenseVector<VT,TF>& a, const DenseSubvector<VT,AF,TF>& b )
5239 {
5240  return ( isSame( ~a, b.vector_ ) && ( (~a).size() == b.size() ) );
5241 }
5242 //*************************************************************************************************
5243 
5244 
5245 //*************************************************************************************************
5257 template< typename VT // Type of the dense vector
5258  , bool AF // Alignment flag
5259  , bool TF > // Transpose flag
5261 {
5262  return ( isSame( a.vector_, b.vector_ ) && ( a.offset_ == b.offset_ ) && ( a.size_ == b.size_ ) );
5263 }
5264 //*************************************************************************************************
5265 
5266 
5267 //*************************************************************************************************
5282 template< typename VT1 // Type of the dense vector
5283  , bool AF // Alignment flag
5284  , bool TF // Transpose flag
5285  , typename VT2 > // Type of the right-hand side vector
5286 inline bool tryAssign( const DenseSubvector<VT1,AF,TF>& lhs, const Vector<VT2,TF>& rhs, size_t index )
5287 {
5288  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5289  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5290 
5291  return tryAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
5292 }
5294 //*************************************************************************************************
5295 
5296 
5297 //*************************************************************************************************
5312 template< typename VT1 // Type of the dense vector
5313  , bool AF // Alignment flag
5314  , bool TF // Transpose flag
5315  , typename VT2 > // Type of the right-hand side vector
5316 inline bool tryAddAssign( const DenseSubvector<VT1,AF,TF>& lhs, const Vector<VT2,TF>& rhs, size_t index )
5317 {
5318  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5319  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5320 
5321  return tryAddAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
5322 }
5324 //*************************************************************************************************
5325 
5326 
5327 //*************************************************************************************************
5343 template< typename VT1 // Type of the dense vector
5344  , bool AF // Alignment flag
5345  , bool TF // Transpose flag
5346  , typename VT2 > // Type of the right-hand side vector
5347 inline bool trySubAssign( const DenseSubvector<VT1,AF,TF>& lhs, const Vector<VT2,TF>& rhs, size_t index )
5348 {
5349  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5350  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5351 
5352  return trySubAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
5353 }
5355 //*************************************************************************************************
5356 
5357 
5358 //*************************************************************************************************
5374 template< typename VT1 // Type of the dense vector
5375  , bool AF // Alignment flag
5376  , bool TF // Transpose flag
5377  , typename VT2 > // Type of the right-hand side vector
5378 inline bool tryMultAssign( const DenseSubvector<VT1,AF,TF>& lhs, const Vector<VT2,TF>& rhs, size_t index )
5379 {
5380  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5381  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5382 
5383  return tryMultAssign( lhs.vector_, ~rhs, lhs.offset_ + index );
5384 }
5386 //*************************************************************************************************
5387 
5388 
5389 //*************************************************************************************************
5404 template< typename VT // Type of the dense vector
5405  , bool AF // Alignment flag
5406  , bool TF > // Transpose flag
5407 inline typename DerestrictTrait< DenseSubvector<VT,AF,TF> >::Type
5408  derestrict( DenseSubvector<VT,AF,TF>& dv )
5409 {
5410  typedef typename DerestrictTrait< DenseSubvector<VT,AF,TF> >::Type ReturnType;
5411  return ReturnType( derestrict( dv.vector_ ), dv.offset_, dv.size_ );
5412 }
5414 //*************************************************************************************************
5415 
5416 
5417 
5418 
5419 //=================================================================================================
5420 //
5421 // GLOBAL RESTRUCTURING OPERATORS
5422 //
5423 //=================================================================================================
5424 
5425 //*************************************************************************************************
5438 template< bool AF1 // Required alignment flag
5439  , typename VT // Type of the dense vector
5440  , bool AF2 // Present alignment flag
5441  , bool TF > // Transpose flag
5442 inline const DenseSubvector<VT,AF1,TF>
5443  subvector( const DenseSubvector<VT,AF2,TF>& dv, size_t index, size_t size )
5444 {
5446 
5447  if( index + size > dv.size() ) {
5448  BLAZE_THROW_INVALID_ARGUMENT( "Invalid subvector specification" );
5449  }
5450 
5451  return DenseSubvector<VT,AF1,TF>( dv.vector_, dv.offset_ + index, size );
5452 }
5454 //*************************************************************************************************
5455 
5456 
5457 
5458 
5459 //=================================================================================================
5460 //
5461 // ISRESTRICTED SPECIALIZATIONS
5462 //
5463 //=================================================================================================
5464 
5465 //*************************************************************************************************
5467 template< typename VT, bool AF, bool TF >
5468 struct IsRestricted< DenseSubvector<VT,AF,TF> > : public IsTrue< IsRestricted<VT>::value >
5469 {};
5471 //*************************************************************************************************
5472 
5473 
5474 
5475 
5476 //=================================================================================================
5477 //
5478 // DERESTRICTTRAIT SPECIALIZATIONS
5479 //
5480 //=================================================================================================
5481 
5482 //*************************************************************************************************
5484 template< typename VT, bool AF, bool TF >
5485 struct DerestrictTrait< DenseSubvector<VT,AF,TF> >
5486 {
5487  typedef DenseSubvector< typename RemoveReference< typename DerestrictTrait<VT>::Type >::Type, AF, TF > Type;
5488 };
5490 //*************************************************************************************************
5491 
5492 
5493 
5494 
5495 //=================================================================================================
5496 //
5497 // HASCONSTDATAACCESS SPECIALIZATIONS
5498 //
5499 //=================================================================================================
5500 
5501 //*************************************************************************************************
5503 template< typename VT, bool AF, bool TF >
5504 struct HasConstDataAccess< DenseSubvector<VT,AF,TF> >
5505  : public IsTrue< HasConstDataAccess<VT>::value >
5506 {};
5508 //*************************************************************************************************
5509 
5510 
5511 
5512 
5513 //=================================================================================================
5514 //
5515 // HASMUTABLEDATAACCESS SPECIALIZATIONS
5516 //
5517 //=================================================================================================
5518 
5519 //*************************************************************************************************
5521 template< typename VT, bool AF, bool TF >
5522 struct HasMutableDataAccess< DenseSubvector<VT,AF,TF> >
5523  : public IsTrue< HasMutableDataAccess<VT>::value >
5524 {};
5526 //*************************************************************************************************
5527 
5528 
5529 
5530 
5531 //=================================================================================================
5532 //
5533 // ISPADDED SPECIALIZATIONS
5534 //
5535 //=================================================================================================
5536 
5537 //*************************************************************************************************
5539 template< typename VT, bool TF >
5540 struct IsAligned< DenseSubvector<VT,aligned,TF> > : public IsTrue<true>
5541 {};
5543 //*************************************************************************************************
5544 
5545 
5546 
5547 
5548 //=================================================================================================
5549 //
5550 // ADDTRAIT SPECIALIZATIONS
5551 //
5552 //=================================================================================================
5553 
5554 //*************************************************************************************************
5556 template< typename VT, bool AF, bool TF, typename T >
5557 struct AddTrait< DenseSubvector<VT,AF,TF>, T >
5558 {
5559  typedef typename AddTrait< typename SubvectorTrait<VT>::Type, T >::Type Type;
5560 };
5561 
5562 template< typename T, typename VT, bool AF, bool TF >
5563 struct AddTrait< T, DenseSubvector<VT,AF,TF> >
5564 {
5565  typedef typename AddTrait< T, typename SubvectorTrait<VT>::Type >::Type Type;
5566 };
5568 //*************************************************************************************************
5569 
5570 
5571 
5572 
5573 //=================================================================================================
5574 //
5575 // SUBTRAIT SPECIALIZATIONS
5576 //
5577 //=================================================================================================
5578 
5579 //*************************************************************************************************
5581 template< typename VT, bool AF, bool TF, typename T >
5582 struct SubTrait< DenseSubvector<VT,AF,TF>, T >
5583 {
5584  typedef typename SubTrait< typename SubvectorTrait<VT>::Type, T >::Type Type;
5585 };
5586 
5587 template< typename T, typename VT, bool AF, bool TF >
5588 struct SubTrait< T, DenseSubvector<VT,AF,TF> >
5589 {
5590  typedef typename SubTrait< T, typename SubvectorTrait<VT>::Type >::Type Type;
5591 };
5593 //*************************************************************************************************
5594 
5595 
5596 
5597 
5598 //=================================================================================================
5599 //
5600 // MULTTRAIT SPECIALIZATIONS
5601 //
5602 //=================================================================================================
5603 
5604 //*************************************************************************************************
5606 template< typename VT, bool AF, bool TF, typename T >
5607 struct MultTrait< DenseSubvector<VT,AF,TF>, T >
5608 {
5609  typedef typename MultTrait< typename SubvectorTrait<VT>::Type, T >::Type Type;
5610 };
5611 
5612 template< typename T, typename VT, bool AF, bool TF >
5613 struct MultTrait< T, DenseSubvector<VT,AF,TF> >
5614 {
5615  typedef typename MultTrait< T, typename SubvectorTrait<VT>::Type >::Type Type;
5616 };
5618 //*************************************************************************************************
5619 
5620 
5621 
5622 
5623 //=================================================================================================
5624 //
5625 // CROSSTRAIT SPECIALIZATIONS
5626 //
5627 //=================================================================================================
5628 
5629 //*************************************************************************************************
5631 template< typename VT, bool AF, bool TF, typename T >
5632 struct CrossTrait< DenseSubvector<VT,AF,TF>, T >
5633 {
5634  typedef typename CrossTrait< typename SubvectorTrait<VT>::Type, T >::Type Type;
5635 };
5636 
5637 template< typename T, typename VT, bool AF, bool TF >
5638 struct CrossTrait< T, DenseSubvector<VT,AF,TF> >
5639 {
5640  typedef typename CrossTrait< T, typename SubvectorTrait<VT>::Type >::Type Type;
5641 };
5643 //*************************************************************************************************
5644 
5645 
5646 
5647 
5648 //=================================================================================================
5649 //
5650 // DIVTRAIT SPECIALIZATIONS
5651 //
5652 //=================================================================================================
5653 
5654 //*************************************************************************************************
5656 template< typename VT, bool AF, bool TF, typename T >
5657 struct DivTrait< DenseSubvector<VT,AF,TF>, T >
5658 {
5659  typedef typename DivTrait< typename SubvectorTrait<VT>::Type, T >::Type Type;
5660 };
5661 
5662 template< typename T, typename VT, bool AF, bool TF >
5663 struct DivTrait< T, DenseSubvector<VT,AF,TF> >
5664 {
5665  typedef typename DivTrait< T, typename SubvectorTrait<VT>::Type >::Type Type;
5666 };
5668 //*************************************************************************************************
5669 
5670 
5671 
5672 
5673 //=================================================================================================
5674 //
5675 // SUBVECTORTRAIT SPECIALIZATIONS
5676 //
5677 //=================================================================================================
5678 
5679 //*************************************************************************************************
5681 template< typename VT, bool AF, bool TF >
5682 struct SubvectorTrait< DenseSubvector<VT,AF,TF> >
5683 {
5685 };
5687 //*************************************************************************************************
5688 
5689 
5690 
5691 
5692 //=================================================================================================
5693 //
5694 // SUBVECTOREXPRTRAIT SPECIALIZATIONS
5695 //
5696 //=================================================================================================
5697 
5698 //*************************************************************************************************
5700 template< typename VT, bool AF1, bool TF, bool AF2 >
5701 struct SubvectorExprTrait< DenseSubvector<VT,AF1,TF>, AF2 >
5702 {
5703  typedef DenseSubvector<VT,AF2,TF> Type;
5704 };
5706 //*************************************************************************************************
5707 
5708 
5709 //*************************************************************************************************
5711 template< typename VT, bool AF1, bool TF, bool AF2 >
5712 struct SubvectorExprTrait< const DenseSubvector<VT,AF1,TF>, AF2 >
5713 {
5714  typedef DenseSubvector<VT,AF2,TF> Type;
5715 };
5717 //*************************************************************************************************
5718 
5719 
5720 //*************************************************************************************************
5722 template< typename VT, bool AF1, bool TF, bool AF2 >
5723 struct SubvectorExprTrait< volatile DenseSubvector<VT,AF1,TF>, AF2 >
5724 {
5725  typedef DenseSubvector<VT,AF2,TF> Type;
5726 };
5728 //*************************************************************************************************
5729 
5730 
5731 //*************************************************************************************************
5733 template< typename VT, bool AF1, bool TF, bool AF2 >
5734 struct SubvectorExprTrait< const volatile DenseSubvector<VT,AF1,TF>, AF2 >
5735 {
5736  typedef DenseSubvector<VT,AF2,TF> Type;
5737 };
5739 //*************************************************************************************************
5740 
5741 
5742 //*************************************************************************************************
5744 template< typename VT1, typename VT2, bool AF >
5745 struct SubvectorExprTrait< DVecDVecCrossExpr<VT1,VT2>, AF >
5746 {
5747  public:
5748  //**********************************************************************************************
5749  typedef DenseSubvector< DVecDVecCrossExpr<VT1,VT2>, unaligned, false > Type;
5750  //**********************************************************************************************
5751 };
5753 //*************************************************************************************************
5754 
5755 
5756 //*************************************************************************************************
5758 template< typename VT1, typename VT2, bool AF >
5759 struct SubvectorExprTrait< DVecSVecCrossExpr<VT1,VT2>, AF >
5760 {
5761  public:
5762  //**********************************************************************************************
5763  typedef DenseSubvector< DVecSVecCrossExpr<VT1,VT2>, unaligned, false > Type;
5764  //**********************************************************************************************
5765 };
5767 //*************************************************************************************************
5768 
5769 
5770 //*************************************************************************************************
5772 template< typename VT1, typename VT2, bool AF >
5773 struct SubvectorExprTrait< SVecDVecCrossExpr<VT1,VT2>, AF >
5774 {
5775  public:
5776  //**********************************************************************************************
5777  typedef DenseSubvector< SVecDVecCrossExpr<VT1,VT2>, unaligned, false > Type;
5778  //**********************************************************************************************
5779 };
5781 //*************************************************************************************************
5782 
5783 
5784 //*************************************************************************************************
5786 template< typename VT1, typename VT2, bool AF >
5787 struct SubvectorExprTrait< SVecSVecCrossExpr<VT1,VT2>, AF >
5788 {
5789  public:
5790  //**********************************************************************************************
5791  typedef DenseSubvector< SVecSVecCrossExpr<VT1,VT2>, unaligned, false > Type;
5792  //**********************************************************************************************
5793 };
5795 //*************************************************************************************************
5796 
5797 } // namespace blaze
5798 
5799 #endif
const ElementType * ConstPointer
Pointer to a constant subvector value.
Definition: DenseSubvector.h:421
Constraint on the data type.
#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
Constraint on the data type.
bool canAlias(const Other *alias) const
Returns whether the dense subvector can alias with the given address alias.
Definition: DenseSubvector.h:1785
#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 alignment flag values.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
Header file for the subtraction trait.
Header file for basic type definitions.
If< IsConst< VT >, ConstIterator, SubvectorIterator< typename VT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: DenseSubvector.h:764
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
SubvectorIterator()
Default constructor of the SubvectorIterator class.
Definition: DenseSubvector.h:462
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
IT::Type IntrinsicType
Intrinsic type of the subvector elements.
Definition: DenseSubvector.h:410
SubvectorIterator(IteratorType iterator, bool isMemoryAligned)
Constructor of the SubvectorIterator class.
Definition: DenseSubvector.h:474
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:647
ReferenceType reference
Reference return type.
Definition: DenseSubvector.h:455
const bool aligned
Alignment flag for aligned vectors and matrices.Via this flag it is possible to specify subvectors...
Definition: AlignmentFlag.h:85
If< Or< IsConst< VT >, Not< HasMutableDataAccess< VT > > >, ConstPointer, ElementType * >::Type Pointer
Pointer to a non-constant subvector value.
Definition: DenseSubvector.h:425
Header file for the IsSame and IsStrictlySame type traits.
size_t nonZeros() const
Returns the number of non-zero elements in the subvector.
Definition: DenseSubvector.h:1709
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
bool isAligned_
Memory alignment flag.
Definition: DenseSubvector.h:754
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
Header file for the IsRowVector type trait.
const DenseSubvector & CompositeType
Data type for composite expression templates.
Definition: DenseSubvector.h:412
Header file for the DenseVector base class.
IntrinsicType loada() const
Aligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:593
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
SubvectorIterator(const SubvectorIterator< IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: DenseSubvector.h:486
Header file for the Computation base class.
IntrinsicType loadu() const
Unaligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:608
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i...
Definition: TransExpr.h:118
bool operator==(const SubvectorIterator &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:624
DenseSubvector(Operand vector, size_t index, size_t n)
The constructor for DenseSubvector.
Definition: DenseSubvector.h:1050
System settings for performance optimizations.
IntrinsicTrait< typename VT::ElementType > IT
Intrinsic trait for the vector element type.
Definition: DenseSubvector.h:401
const size_t offset_
The offset of the subvector within the dense vector.
Definition: DenseSubvector.h:964
Reference at(size_t index)
Checked access to the subvector elements.
Definition: DenseSubvector.h:1127
size_t capacity() const
Returns the maximum capacity of the dense subvector.
Definition: DenseSubvector.h:1691
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Iterator begin()
Returns an iterator to the first element of the subvector.
Definition: DenseSubvector.h:1205
DenseSubvector & operator=(const ElementType &rhs)
Homogenous assignment to all subvector elements.
Definition: DenseSubvector.h:1314
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:123
void stream(size_t index, const IntrinsicType &value)
Aligned, non-temporal store of an intrinsic element of the subvector.
Definition: DenseSubvector.h:2091
Constraint on the data type.
void reset()
Reset to the default initial values.
Definition: DenseSubvector.h:1732
Pointer data()
Low-level data access to the subvector elements.
Definition: DenseSubvector.h:1171
DifferenceType difference_type
Difference between two iterators.
Definition: DenseSubvector.h:456
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: DenseSubvector.h:407
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
Header file for the multiplication trait.
void store(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the subvector.
Definition: DenseSubvector.h:2004
Operand vector_
The dense vector containing the subvector.
Definition: DenseSubvector.h:963
const SubvectorIterator operator--(int)
Post-decrement operator.
Definition: DenseSubvector.h:553
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.
Header file for the If class template.
Header file for the Subvector base class.
Reference operator[](size_t index)
Subscript operator for the direct access to the subvector elements.
Definition: DenseSubvector.h:1084
SubvectorIterator & operator++()
Pre-increment operator.
Definition: DenseSubvector.h:521
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
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
Header file for the Or class template.
friend const SubvectorIterator operator-(const SubvectorIterator &it, size_t dec)
Subtraction between a SubvectorIterator and an integral value.
Definition: DenseSubvector.h:726
#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
std::iterator_traits< IteratorType >::difference_type DifferenceType
Difference between two iterators.
Definition: DenseSubvector.h:449
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: DenseSubvector.h:1239
Header file for the Not class template.
DifferenceType operator-(const SubvectorIterator &rhs) const
Calculating the number of elements between two iterators.
Definition: DenseSubvector.h:690
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: DenseSubvector.h:411
Header file for the subvector trait.
DenseSubvector< VT, AF, TF > This
Type of this DenseSubvector instance.
Definition: DenseSubvector.h:406
friend const SubvectorIterator operator+(size_t inc, const SubvectorIterator &it)
Addition between an integral value and a SubvectorIterator.
Definition: DenseSubvector.h:714
bool operator!=(const SubvectorIterator &rhs) const
Inequality comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:635
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
SubvectorIterator & operator--()
Pre-decrement operator.
Definition: DenseSubvector.h:542
Header file for the IsAligned type trait.
IteratorType iterator_
Iterator to the current subvector element.
Definition: DenseSubvector.h:753
Constraint on the data type.
Constraint on the data type.
#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
IteratorType base() const
Access to the current position of the subvector iterator.
Definition: DenseSubvector.h:736
Constraint on the data type.
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
size_t size() const
Returns the current size/dimension of the dense subvector.
Definition: DenseSubvector.h:1676
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
const bool unaligned
Alignment flag for unaligned vectors and matrices.Via this flag it is possible to specify subvectors...
Definition: AlignmentFlag.h:64
Constraint on the data type.
Header file for all forward declarations for expression class templates.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: DenseSubvector.h:408
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the IsPadded type trait.
Header file for the DerestrictTrait class template.
std::iterator_traits< IteratorType >::iterator_category IteratorCategory
The iterator category.
Definition: DenseSubvector.h:437
Header file for the CrossExpr base class.
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.
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for the IsConst type trait.
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: DenseSubvector.h:1256
Intrinsic characteristics of data types.The IntrinsicTrait class template provides the intrinsic char...
Definition: IntrinsicTrait.h:1232
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
Header file for the addition trait.
Header file for the cross product trait.
Base class for all subvectors.The Subvector class serves as a tag for all subvectors (i...
Definition: Subvector.h:64
Header file for the division trait.
View on a specific subvector of a dense vector.The DenseSubvector template represents a view on a spe...
Definition: DenseSubvector.h:392
SubvectorIterator & operator+=(size_t inc)
Addition assignment operator.
Definition: DenseSubvector.h:498
bool operator>(const SubvectorIterator &rhs) const
Greater-than comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:657
bool isAligned() const
Returns whether the subvector is properly aligned in memory.
Definition: DenseSubvector.h:1873
std::iterator_traits< IteratorType >::pointer PointerType
Pointer return type.
Definition: DenseSubvector.h:443
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
SubvectorExprTrait< VT, unaligned >::Type subvector(Vector< VT, TF > &vector, size_t index, size_t size)
Creating a view on a specific subvector of the given vector.
Definition: Subvector.h:143
const bool useOptimizedKernels
Configuration switch for optimized kernels.This configuration switch enables/disables all optimized c...
Definition: Optimizations.h:84
ValueType value_type
Type of the underlying elements.
Definition: DenseSubvector.h:453
Header file for the cache size of the target architecture.
IntrinsicType loada(size_t index) const
Aligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:1944
bool canSMPAssign() const
Returns whether the subvector can be used in SMP assignments.
Definition: DenseSubvector.h:1893
Compile time type negation.The Not class template negates the given compile time condition. In case the given condition would evaluate to true, the nested member enumeration is set to false and vice versa:
Definition: Not.h:70
bool isAligned() const
Access to the iterator's memory alignment flag.
Definition: DenseSubvector.h:746
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the isDefault shim.
ReferenceType operator*() const
Direct access to the element at the current iterator position.
Definition: DenseSubvector.h:563
const size_t size_
The size of the subvector.
Definition: DenseSubvector.h:965
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
void storea(size_t index, const IntrinsicType &value)
Aligned store of an intrinsic element of the subvector.
Definition: DenseSubvector.h:2031
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
IntrinsicType load() const
Aligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:578
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: DenseSubvector.h:532
IteratorCategory iterator_category
The iterator category.
Definition: DenseSubvector.h:452
Header file for the RemoveReference type trait.
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: DenseSubvector.h:415
SubvectorIterator< typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: DenseSubvector.h:761
Header file for all intrinsic functionality.
IntrinsicType loadu(size_t index) const
Unaligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:1974
BLAZE_ALWAYS_INLINE bool checkAlignment(const T *address)
Checks the alignment of the given address.
Definition: AlignmentCheck.h:68
friend const SubvectorIterator operator+(const SubvectorIterator &it, size_t inc)
Addition between a SubvectorIterator and an integral value.
Definition: DenseSubvector.h:702
If< IsConst< VT >, ConstReference, typename VT::Reference >::Type Reference
Reference to a non-constant subvector value.
Definition: DenseSubvector.h:418
bool isAliased(const Other *alias) const
Returns whether the dense subvector is aliased with the given address alias.
Definition: DenseSubvector.h:1830
#define BLAZE_CONSTRAINT_MUST_BE_DENSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a dense, N-dimensional vector type...
Definition: DenseVector.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SUBVECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is a subvector type (i.e. a dense or sparse subvector), a compilation error is created.
Definition: Subvector.h:118
PointerType pointer
Pointer return type.
Definition: DenseSubvector.h:454
const bool isAligned_
Memory alignment flag.
Definition: DenseSubvector.h:966
If< IsExpression< VT >, VT, VT & >::Type Operand
Composite data type of the dense vector expression.
Definition: DenseSubvector.h:398
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
IntrinsicType load(size_t index) const
Aligned load of an intrinsic element of the dense subvector.
Definition: DenseSubvector.h:1917
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:258
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
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:157
bool operator>=(const SubvectorIterator &rhs) const
Greater-than comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:679
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
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: DenseSubvector.h:1290
Compile time type check.This class tests whether the given template parameter T is a reference type (...
Definition: IsReference.h:94
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
Header file for the SubvectorExprTrait class template.
SubvectorIterator & operator-=(size_t dec)
Subtraction assignment operator.
Definition: DenseSubvector.h:510
Iterator over the elements of the sparse subvector.
Definition: DenseSubvector.h:432
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Header file for exception macros.
std::iterator_traits< IteratorType >::value_type ValueType
Type of the underlying elements.
Definition: DenseSubvector.h:440
VT::ElementType ElementType
Type of the subvector elements.
Definition: DenseSubvector.h:409
void storeu(size_t index, const IntrinsicType &value)
Unaligned store of an intrinsic element of the subvector.
Definition: DenseSubvector.h:2061
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
bool operator<(const SubvectorIterator &rhs) const
Less-than comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:646
Header file for the IsRestricted type trait.
System settings for the inline keywords.
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
bool operator<=(const SubvectorIterator &rhs) const
Less-than comparison between two SubvectorIterator objects.
Definition: DenseSubvector.h:668
#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.
#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 the IsExpression type trait class.
Header file for the FunctionTrace class.
std::iterator_traits< IteratorType >::reference ReferenceType
Reference return type.
Definition: DenseSubvector.h:446
Header file for a safe C++ NULL pointer implementation.