SparseSubvector.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SPARSESUBVECTOR_H_
36 #define _BLAZE_MATH_VIEWS_SPARSESUBVECTOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 #include <stdexcept>
69 #include <blaze/util/Assert.h>
70 #include <blaze/util/EnableIf.h>
72 #include <blaze/util/mpl/If.h>
73 #include <blaze/util/mpl/Or.h>
74 #include <blaze/util/Types.h>
79 
80 
81 namespace blaze {
82 
83 //=================================================================================================
84 //
85 // CLASS DEFINITION
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
386 template< typename VT // Type of the sparse vector
387  , bool AF = unaligned // Alignment flag
388  , bool TF = IsRowVector<VT>::value > // Transpose flag
389 class SparseSubvector : public SparseVector< SparseSubvector<VT,AF,TF>, TF >
390  , private Subvector
391 {
392  private:
393  //**Type definitions****************************************************************************
395  typedef typename If< IsExpression<VT>, VT, VT& >::Type Operand;
396  //**********************************************************************************************
397 
398  //**********************************************************************************************
400 
406  enum { useConst = IsConst<VT>::value };
407  //**********************************************************************************************
408 
409  public:
410  //**Type definitions****************************************************************************
414  typedef typename VT::ElementType ElementType;
415  typedef typename VT::ReturnType ReturnType;
417 
420 
423  //**********************************************************************************************
424 
425  //**SubvectorElement class definition***********************************************************
428  template< typename VectorType // Type of the sparse vector
429  , typename IteratorType > // Type of the sparse vector iterator
431  {
432  private:
433  //*******************************************************************************************
435 
440  enum { returnConst = IsConst<VectorType>::value };
441  //*******************************************************************************************
442 
443  //**Type definitions*************************************************************************
445  typedef typename std::iterator_traits<IteratorType>::value_type SET;
446 
447  typedef typename SET::Reference RT;
448  typedef typename SET::ConstReference CRT;
449  //*******************************************************************************************
450 
451  public:
452  //**Type definitions*************************************************************************
453  typedef typename SET::ValueType ValueType;
454  typedef size_t IndexType;
456  typedef CRT ConstReference;
457  //*******************************************************************************************
458 
459  //**Constructor******************************************************************************
465  inline SubvectorElement( IteratorType pos, size_t offset )
466  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
467  , offset_( offset ) // Offset within the according sparse vector
468  {}
469  //*******************************************************************************************
470 
471  //**Assignment operator**********************************************************************
477  template< typename T > inline SubvectorElement& operator=( const T& v ) {
478  *pos_ = v;
479  return *this;
480  }
481  //*******************************************************************************************
482 
483  //**Addition assignment operator*************************************************************
489  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
490  *pos_ += v;
491  return *this;
492  }
493  //*******************************************************************************************
494 
495  //**Subtraction assignment operator**********************************************************
501  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
502  *pos_ -= v;
503  return *this;
504  }
505  //*******************************************************************************************
506 
507  //**Multiplication assignment operator*******************************************************
513  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
514  *pos_ *= v;
515  return *this;
516  }
517  //*******************************************************************************************
518 
519  //**Division assignment operator*************************************************************
525  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
526  *pos_ /= v;
527  return *this;
528  }
529  //*******************************************************************************************
530 
531  //**Element access operator******************************************************************
536  inline const SubvectorElement* operator->() const {
537  return this;
538  }
539  //*******************************************************************************************
540 
541  //**Value function***************************************************************************
546  inline Reference value() const {
547  return pos_->value();
548  }
549  //*******************************************************************************************
550 
551  //**Index function***************************************************************************
556  inline IndexType index() const {
557  return pos_->index() - offset_;
558  }
559  //*******************************************************************************************
560 
561  private:
562  //**Member variables*************************************************************************
563  IteratorType pos_;
564  size_t offset_;
565  //*******************************************************************************************
566  };
567  //**********************************************************************************************
568 
569  //**SubvectorIterator class definition**********************************************************
572  template< typename VectorType // Type of the sparse vector
573  , typename IteratorType > // Type of the sparse vector iterator
575  {
576  public:
577  //**Type definitions*************************************************************************
578  typedef std::forward_iterator_tag IteratorCategory;
580  typedef ValueType PointerType;
581  typedef ValueType ReferenceType;
583 
584  // STL iterator requirements
585  typedef IteratorCategory iterator_category;
586  typedef ValueType value_type;
587  typedef PointerType pointer;
588  typedef ReferenceType reference;
589  typedef DifferenceType difference_type;
590  //*******************************************************************************************
591 
592  //**Default constructor**********************************************************************
596  : pos_ () // Iterator to the current sparse element
597  , offset_() // The offset of the subvector within the sparse vector
598  {}
599  //*******************************************************************************************
600 
601  //**Constructor******************************************************************************
607  inline SubvectorIterator( IteratorType iterator, size_t index )
608  : pos_ ( iterator ) // Iterator to the current sparse element
609  , offset_( index ) // The offset of the subvector within the sparse vector
610  {}
611  //*******************************************************************************************
612 
613  //**Constructor******************************************************************************
618  template< typename VectorType2, typename IteratorType2 >
620  : pos_ ( it.base() ) // Iterator to the current sparse element.
621  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
622  {}
623  //*******************************************************************************************
624 
625  //**Prefix increment operator****************************************************************
631  ++pos_;
632  return *this;
633  }
634  //*******************************************************************************************
635 
636  //**Postfix increment operator***************************************************************
641  inline const SubvectorIterator operator++( int ) {
642  const SubvectorIterator tmp( *this );
643  ++(*this);
644  return tmp;
645  }
646  //*******************************************************************************************
647 
648  //**Element access operator******************************************************************
653  inline ReferenceType operator*() const {
654  return ReferenceType( pos_, offset_ );
655  }
656  //*******************************************************************************************
657 
658  //**Element access operator******************************************************************
663  inline PointerType operator->() const {
664  return PointerType( pos_, offset_ );
665  }
666  //*******************************************************************************************
667 
668  //**Equality operator************************************************************************
674  template< typename VectorType2, typename IteratorType2 >
676  return base() == rhs.base();
677  }
678  //*******************************************************************************************
679 
680  //**Inequality operator**********************************************************************
686  template< typename VectorType2, typename IteratorType2 >
688  return !( *this == rhs );
689  }
690  //*******************************************************************************************
691 
692  //**Subtraction operator*********************************************************************
698  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
699  return pos_ - rhs.pos_;
700  }
701  //*******************************************************************************************
702 
703  //**Base function****************************************************************************
708  inline IteratorType base() const {
709  return pos_;
710  }
711  //*******************************************************************************************
712 
713  //**Offset function**************************************************************************
718  inline size_t offset() const {
719  return offset_;
720  }
721  //*******************************************************************************************
722 
723  private:
724  //**Member variables*************************************************************************
725  IteratorType pos_;
726  size_t offset_;
727  //*******************************************************************************************
728  };
729  //**********************************************************************************************
730 
731  //**Type definitions****************************************************************************
734 
737  //**********************************************************************************************
738 
739  //**Compilation flags***************************************************************************
741  enum { smpAssignable = VT::smpAssignable };
742  //**********************************************************************************************
743 
744  //**Constructors********************************************************************************
747  explicit inline SparseSubvector( Operand vector, size_t index, size_t n );
748  // No explicitly declared copy constructor.
750  //**********************************************************************************************
751 
752  //**Destructor**********************************************************************************
753  // No explicitly declared destructor.
754  //**********************************************************************************************
755 
756  //**Data access functions***********************************************************************
759  inline Reference operator[]( size_t index );
760  inline ConstReference operator[]( size_t index ) const;
761  inline Iterator begin ();
762  inline ConstIterator begin () const;
763  inline ConstIterator cbegin() const;
764  inline Iterator end ();
765  inline ConstIterator end () const;
766  inline ConstIterator cend () const;
768  //**********************************************************************************************
769 
770  //**Assignment operators************************************************************************
773  inline SparseSubvector& operator= ( const SparseSubvector& rhs );
774  template< typename VT2 > inline SparseSubvector& operator= ( const DenseVector<VT2,TF>& rhs );
775  template< typename VT2 > inline SparseSubvector& operator= ( const SparseVector<VT2,TF>& rhs );
776  template< typename VT2 > inline SparseSubvector& operator+=( const Vector<VT2,TF>& rhs );
777  template< typename VT2 > inline SparseSubvector& operator-=( const Vector<VT2,TF>& rhs );
778  template< typename VT2 > inline SparseSubvector& operator*=( const Vector<VT2,TF>& rhs );
779 
780  template< typename Other >
781  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
782  operator*=( Other rhs );
783 
784  template< typename Other >
785  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
786  operator/=( Other rhs );
788  //**********************************************************************************************
789 
790  //**Utility functions***************************************************************************
793  inline size_t size() const;
794  inline size_t capacity() const;
795  inline size_t nonZeros() const;
796  inline void reset();
797  inline Iterator set ( size_t index, const ElementType& value );
798  inline Iterator insert ( size_t index, const ElementType& value );
799  inline void erase ( size_t index );
800  inline Iterator erase ( Iterator pos );
801  inline Iterator erase ( Iterator first, Iterator last );
802  inline void reserve( size_t n );
803  template< typename Other > inline SparseSubvector& scale ( const Other& scalar );
805  //**********************************************************************************************
806 
807  //**Lookup functions****************************************************************************
810  inline Iterator find ( size_t index );
811  inline ConstIterator find ( size_t index ) const;
812  inline Iterator lowerBound( size_t index );
813  inline ConstIterator lowerBound( size_t index ) const;
814  inline Iterator upperBound( size_t index );
815  inline ConstIterator upperBound( size_t index ) const;
817  //**********************************************************************************************
818 
819  //**Low-level utility functions*****************************************************************
822  inline void append( size_t index, const ElementType& value, bool check=false );
824  //**********************************************************************************************
825 
826  //**Expression template evaluation functions****************************************************
829  template< typename Other > inline bool canAlias ( const Other* alias ) const;
830  template< typename Other > inline bool isAliased( const Other* alias ) const;
831 
832  inline bool canSMPAssign() const;
833 
834  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
835  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
836  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
837  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
838  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
839  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
841  //**********************************************************************************************
842 
843  private:
844  //**Member variables****************************************************************************
847  Operand vector_;
848  const size_t offset_;
849  const size_t size_;
850 
851  //**********************************************************************************************
852 
853  //**Friend declarations*************************************************************************
855  template< bool AF1, typename VT2, bool AF2, bool TF2 >
856  friend const SparseSubvector<VT2,AF1,TF2>
857  subvector( const SparseSubvector<VT2,AF2,TF2>& sv, size_t index, size_t size );
858 
859  template< typename VT2, bool AF2, bool TF2 >
860  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseVector<VT2,TF2>& b );
861 
862  template< typename VT2, bool AF2, bool TF2 >
863  friend bool isSame( const SparseVector<VT2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
864 
865  template< typename VT2, bool AF2, bool TF2 >
866  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
867 
868  template< typename VT2, bool AF2, bool TF2 >
869  friend typename DerestrictTrait< SparseSubvector<VT2,AF2,TF2> >::Type
870  derestrict( SparseSubvector<VT2,AF2,TF2>& sv );
872  //**********************************************************************************************
873 
874  //**Compile time checks*************************************************************************
882  //**********************************************************************************************
883 };
884 //*************************************************************************************************
885 
886 
887 
888 
889 //=================================================================================================
890 //
891 // CONSTRUCTOR
892 //
893 //=================================================================================================
894 
895 //*************************************************************************************************
907 template< typename VT // Type of the sparse vector
908  , bool AF // Alignment flag
909  , bool TF > // Transpose flag
910 inline SparseSubvector<VT,AF,TF>::SparseSubvector( Operand vector, size_t index, size_t n )
911  : vector_( vector ) // The sparse vector containing the subvector
912  , offset_( index ) // The offset of the subvector within the sparse vector
913  , size_ ( n ) // The size of the subvector
914 {
915  if( index + n > vector.size() )
916  throw std::invalid_argument( "Invalid subvector specification" );
917 }
918 //*************************************************************************************************
919 
920 
921 
922 
923 //=================================================================================================
924 //
925 // DATA ACCESS FUNCTIONS
926 //
927 //=================================================================================================
928 
929 //*************************************************************************************************
935 template< typename VT // Type of the sparse vector
936  , bool AF // Alignment flag
937  , bool TF > // Transpose flag
940 {
941  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
942  return vector_[offset_+index];
943 }
944 //*************************************************************************************************
945 
946 
947 //*************************************************************************************************
953 template< typename VT // Type of the sparse vector
954  , bool AF // Alignment flag
955  , bool TF > // Transpose flag
958 {
959  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
960  return const_cast<const VT&>( vector_ )[offset_+index];
961 }
962 //*************************************************************************************************
963 
964 
965 //*************************************************************************************************
972 template< typename VT // Type of the sparse vector
973  , bool AF // Alignment flag
974  , bool TF > // Transpose flag
976 {
977  if( offset_ == 0UL )
978  return Iterator( vector_.begin(), offset_ );
979  else
980  return Iterator( vector_.lowerBound( offset_ ), offset_ );
981 }
982 //*************************************************************************************************
983 
984 
985 //*************************************************************************************************
992 template< typename VT // Type of the sparse vector
993  , bool AF // Alignment flag
994  , bool TF > // Transpose flag
996 {
997  if( offset_ == 0UL )
998  return ConstIterator( vector_.cbegin(), offset_ );
999  else
1000  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
1001 }
1002 //*************************************************************************************************
1003 
1004 
1005 //*************************************************************************************************
1012 template< typename VT // Type of the sparse vector
1013  , bool AF // Alignment flag
1014  , bool TF > // Transpose flag
1016 {
1017  if( offset_ == 0UL )
1018  return ConstIterator( vector_.cbegin(), offset_ );
1019  else
1020  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
1021 }
1022 //*************************************************************************************************
1023 
1024 
1025 //*************************************************************************************************
1032 template< typename VT // Type of the sparse vector
1033  , bool AF // Alignment flag
1034  , bool TF > // Transpose flag
1036 {
1037  if( offset_ + size_ == vector_.size() )
1038  return Iterator( vector_.end(), offset_ );
1039  else
1040  return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1041 }
1042 //*************************************************************************************************
1043 
1044 
1045 //*************************************************************************************************
1052 template< typename VT // Type of the sparse vector
1053  , bool AF // Alignment flag
1054  , bool TF > // Transpose flag
1056 {
1057  if( offset_ + size_ == vector_.size() )
1058  return ConstIterator( vector_.cend(), offset_ );
1059  else
1060  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1061 }
1062 //*************************************************************************************************
1063 
1064 
1065 //*************************************************************************************************
1072 template< typename VT // Type of the sparse vector
1073  , bool AF // Alignment flag
1074  , bool TF > // Transpose flag
1076 {
1077  if( offset_ + size_ == vector_.size() )
1078  return ConstIterator( vector_.cend(), offset_ );
1079  else
1080  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1081 }
1082 //*************************************************************************************************
1083 
1084 
1085 
1086 
1087 //=================================================================================================
1088 //
1089 // ASSIGNMENT OPERATORS
1090 //
1091 //=================================================================================================
1092 
1093 //*************************************************************************************************
1103 template< typename VT // Type of the sparse vector
1104  , bool AF // Alignment flag
1105  , bool TF > // Transpose flag
1108 {
1109  using blaze::assign;
1110 
1113 
1114  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
1115  return *this;
1116 
1117  if( size() != rhs.size() )
1118  throw std::invalid_argument( "Vector sizes do not match" );
1119 
1120  if( rhs.canAlias( &vector_ ) ) {
1121  const ResultType tmp( rhs );
1122  reset();
1123  assign( *this, tmp );
1124  }
1125  else {
1126  reset();
1127  assign( *this, rhs );
1128  }
1129 
1130  return *this;
1131 }
1132 //*************************************************************************************************
1133 
1134 
1135 //*************************************************************************************************
1145 template< typename VT // Type of the sparse vector
1146  , bool AF // Alignment flag
1147  , bool TF > // Transpose flag
1148 template< typename VT2 > // Type of the right-hand side dense vector
1151 {
1152  using blaze::assign;
1153 
1157 
1158  if( size() != (~rhs).size() )
1159  throw std::invalid_argument( "Vector sizes do not match" );
1160 
1161  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1162  const typename VT2::ResultType tmp( ~rhs );
1163  reset();
1164  assign( *this, tmp );
1165  }
1166  else {
1167  reset();
1168  assign( *this, ~rhs );
1169  }
1170 
1171  return *this;
1172 }
1173 //*************************************************************************************************
1174 
1175 
1176 //*************************************************************************************************
1186 template< typename VT // Type of the sparse vector
1187  , bool AF // Alignment flag
1188  , bool TF > // Transpose flag
1189 template< typename VT2 > // Type of the right-hand side sparse vector
1192 {
1193  using blaze::assign;
1194 
1198 
1199  if( size() != (~rhs).size() )
1200  throw std::invalid_argument( "Vector sizes do not match" );
1201 
1202  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1203  const typename VT2::ResultType tmp( ~rhs );
1204  reset();
1205  assign( *this, tmp );
1206  }
1207  else {
1208  reset();
1209  assign( *this, ~rhs );
1210  }
1211 
1212  return *this;
1213 }
1214 //*************************************************************************************************
1215 
1216 
1217 //*************************************************************************************************
1227 template< typename VT // Type of the sparse vector
1228  , bool AF // Alignment flag
1229  , bool TF > // Transpose flag
1230 template< typename VT2 > // Type of the right-hand side vector
1233 {
1234  using blaze::addAssign;
1235 
1236  if( size() != (~rhs).size() )
1237  throw std::invalid_argument( "Vector sizes do not match" );
1238 
1239  addAssign( *this, ~rhs );
1240 
1241  return *this;
1242 }
1243 //*************************************************************************************************
1244 
1245 
1246 //*************************************************************************************************
1256 template< typename VT // Type of the sparse vector
1257  , bool AF // Alignment flag
1258  , bool TF > // Transpose flag
1259 template< typename VT2 > // Type of the right-hand side vector
1262 {
1263  using blaze::subAssign;
1264 
1265  if( size() != (~rhs).size() )
1266  throw std::invalid_argument( "Vector sizes do not match" );
1267 
1268  subAssign( *this, ~rhs );
1269 
1270  return *this;
1271 }
1272 //*************************************************************************************************
1273 
1274 
1275 //*************************************************************************************************
1286 template< typename VT // Type of the sparse vector
1287  , bool AF // Alignment flag
1288  , bool TF > // Transpose flag
1289 template< typename VT2 > // Type of the right-hand side vector
1292 {
1293  if( size() != (~rhs).size() )
1294  throw std::invalid_argument( "Vector sizes do not match" );
1295 
1296  typedef typename MultTrait<ResultType,typename VT2::ResultType>::Type MultType;
1297 
1301 
1302  const MultType tmp( *this * (~rhs) );
1303  reset();
1304  assign( tmp );
1305 
1306  return *this;
1307 }
1308 //*************************************************************************************************
1309 
1310 
1311 //*************************************************************************************************
1322 template< typename VT // Type of the sparse vector
1323  , bool AF // Alignment flag
1324  , bool TF > // Transpose flag
1325 template< typename Other > // Data type of the right-hand side scalar
1326 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1328 {
1329  const Iterator last( end() );
1330  for( Iterator element=begin(); element!=last; ++element )
1331  element->value() *= rhs;
1332  return *this;
1333 }
1334 //*************************************************************************************************
1335 
1336 
1337 //*************************************************************************************************
1349 template< typename VT // Type of the sparse vector
1350  , bool AF // Alignment flag
1351  , bool TF > // Transpose flag
1352 template< typename Other > // Data type of the right-hand side scalar
1353 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1355 {
1356  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1357 
1358  typedef typename DivTrait<ElementType,Other>::Type DT;
1359  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1360 
1361  const Iterator last( end() );
1362 
1363  // Depending on the two involved data types, an integer division is applied or a
1364  // floating point division is selected.
1366  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1367  for( Iterator element=begin(); element!=last; ++element )
1368  element->value() *= tmp;
1369  }
1370  else {
1371  for( Iterator element=begin(); element!=last; ++element )
1372  element->value() /= rhs;
1373  }
1374 
1375  return *this;
1376 }
1377 //*************************************************************************************************
1378 
1379 
1380 
1381 
1382 //=================================================================================================
1383 //
1384 // UTILITY FUNCTIONS
1385 //
1386 //=================================================================================================
1387 
1388 //*************************************************************************************************
1393 template< typename VT // Type of the sparse vector
1394  , bool AF // Alignment flag
1395  , bool TF > // Transpose flag
1396 inline size_t SparseSubvector<VT,AF,TF>::size() const
1397 {
1398  return size_;
1399 }
1400 //*************************************************************************************************
1401 
1402 
1403 //*************************************************************************************************
1408 template< typename VT // Type of the sparse vector
1409  , bool AF // Alignment flag
1410  , bool TF > // Transpose flag
1412 {
1413  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1414 }
1415 //*************************************************************************************************
1416 
1417 
1418 //*************************************************************************************************
1425 template< typename VT // Type of the sparse vector
1426  , bool AF // Alignment flag
1427  , bool TF > // Transpose flag
1429 {
1430  return end() - begin();
1431 }
1432 //*************************************************************************************************
1433 
1434 
1435 //*************************************************************************************************
1440 template< typename VT // Type of the sparse vector
1441  , bool AF // Alignment flag
1442  , bool TF > // Transpose flag
1444 {
1445  vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1446 }
1447 //*************************************************************************************************
1448 
1449 
1450 //*************************************************************************************************
1461 template< typename VT // Type of the sparse vector
1462  , bool AF // Alignment flag
1463  , bool TF > // Transpose flag
1465  SparseSubvector<VT,AF,TF>::set( size_t index, const ElementType& value )
1466 {
1467  return Iterator( vector_.set( offset_ + index, value ), offset_ );
1468 }
1469 //*************************************************************************************************
1470 
1471 
1472 //*************************************************************************************************
1484 template< typename VT // Type of the sparse vector
1485  , bool AF // Alignment flag
1486  , bool TF > // Transpose flag
1488  SparseSubvector<VT,AF,TF>::insert( size_t index, const ElementType& value )
1489 {
1490  return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1491 }
1492 //*************************************************************************************************
1493 
1494 
1495 //*************************************************************************************************
1503 template< typename VT // Type of the sparse vector
1504  , bool AF // Alignment flag
1505  , bool TF > // Transpose flag
1506 inline void SparseSubvector<VT,AF,TF>::erase( size_t index )
1507 {
1508  vector_.erase( offset_ + index );
1509 }
1510 //*************************************************************************************************
1511 
1512 
1513 //*************************************************************************************************
1521 template< typename VT // Type of the sparse vector
1522  , bool AF // Alignment flag
1523  , bool TF > // Transpose flag
1525 {
1526  return Iterator( vector_.erase( pos.base() ), offset_ );
1527 }
1528 //*************************************************************************************************
1529 
1530 
1531 //*************************************************************************************************
1540 template< typename VT // Type of the sparse vector
1541  , bool AF // Alignment flag
1542  , bool TF > // Transpose flag
1545 {
1546  return Iterator( vector_.erase( first.base(), last.base() ), offset_ );
1547 }
1548 //*************************************************************************************************
1549 
1550 
1551 //*************************************************************************************************
1560 template< typename VT // Type of the sparse vector
1561  , bool AF // Alignment flag
1562  , bool TF > // Transpose flag
1564 {
1565  const size_t current( capacity() );
1566 
1567  if( n > current ) {
1568  vector_.reserve( vector_.capacity() + n - current );
1569  }
1570 }
1571 //*************************************************************************************************
1572 
1573 
1574 //*************************************************************************************************
1580 template< typename VT // Type of the sparse vector
1581  , bool AF // Alignment flag
1582  , bool TF > // Transpose flag
1583 template< typename Other > // Data type of the scalar value
1585 {
1586  for( Iterator element=begin(); element!=end(); ++element )
1587  element->value() *= scalar;
1588  return *this;
1589 }
1590 //*************************************************************************************************
1591 
1592 
1593 
1594 
1595 //=================================================================================================
1596 //
1597 // LOOKUP FUNCTIONS
1598 //
1599 //=================================================================================================
1600 
1601 //*************************************************************************************************
1614 template< typename VT // Type of the sparse vector
1615  , bool AF // Alignment flag
1616  , bool TF > // Transpose flag
1619 {
1620  const typename VT::Iterator pos( vector_.find( offset_ + index ) );
1621 
1622  if( pos != vector_.end() )
1623  return Iterator( pos, offset_ );
1624  else
1625  return end();
1626 }
1627 //*************************************************************************************************
1628 
1629 
1630 //*************************************************************************************************
1643 template< typename VT // Type of the sparse vector
1644  , bool AF // Alignment flag
1645  , bool TF > // Transpose flag
1647  SparseSubvector<VT,AF,TF>::find( size_t index ) const
1648 {
1649  const typename VT::ConstIterator pos( vector_.find( offset_ + index ) );
1650 
1651  if( pos != vector_.end() )
1652  return Iterator( pos, offset_ );
1653  else
1654  return end();
1655 }
1656 //*************************************************************************************************
1657 
1658 
1659 //*************************************************************************************************
1671 template< typename VT // Type of the sparse vector
1672  , bool AF // Alignment flag
1673  , bool TF > // Transpose flag
1676 {
1677  return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1678 }
1679 //*************************************************************************************************
1680 
1681 
1682 //*************************************************************************************************
1694 template< typename VT // Type of the sparse vector
1695  , bool AF // Alignment flag
1696  , bool TF > // Transpose flag
1699 {
1700  return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1701 }
1702 //*************************************************************************************************
1703 
1704 
1705 //*************************************************************************************************
1717 template< typename VT // Type of the sparse vector
1718  , bool AF // Alignment flag
1719  , bool TF > // Transpose flag
1722 {
1723  return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1724 }
1725 //*************************************************************************************************
1726 
1727 
1728 //*************************************************************************************************
1740 template< typename VT // Type of the sparse vector
1741  , bool AF // Alignment flag
1742  , bool TF > // Transpose flag
1745 {
1746  return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1747 }
1748 //*************************************************************************************************
1749 
1750 
1751 
1752 
1753 //=================================================================================================
1754 //
1755 // LOW-LEVEL UTILITY FUNCTIONS
1756 //
1757 //=================================================================================================
1758 
1759 //*************************************************************************************************
1783 template< typename VT // Type of the sparse vector
1784  , bool AF // Alignment flag
1785  , bool TF > // Transpose flag
1786 inline void SparseSubvector<VT,AF,TF>::append( size_t index, const ElementType& value, bool check )
1787 {
1788  if( offset_ + size_ == vector_.size() )
1789  vector_.append( offset_ + index, value, check );
1790  else if( !check || !isDefault( value ) )
1791  vector_.insert( offset_ + index, value );
1792 }
1793 //*************************************************************************************************
1794 
1795 
1796 
1797 
1798 //=================================================================================================
1799 //
1800 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1801 //
1802 //=================================================================================================
1803 
1804 //*************************************************************************************************
1814 template< typename VT // Type of the sparse vector
1815  , bool AF // Alignment flag
1816  , bool TF > // Transpose flag
1817 template< typename Other > // Data type of the foreign expression
1818 inline bool SparseSubvector<VT,AF,TF>::canAlias( const Other* alias ) const
1819 {
1820  return vector_.isAliased( alias );
1821 }
1822 //*************************************************************************************************
1823 
1824 
1825 //*************************************************************************************************
1835 template< typename VT // Type of the sparse vector
1836  , bool AF // Alignment flag
1837  , bool TF > // Transpose flag
1838 template< typename Other > // Data type of the foreign expression
1839 inline bool SparseSubvector<VT,AF,TF>::isAliased( const Other* alias ) const
1840 {
1841  return vector_.isAliased( alias );
1842 }
1843 //*************************************************************************************************
1844 
1845 
1846 //*************************************************************************************************
1856 template< typename VT // Type of the sparse vector
1857  , bool AF // Alignment flag
1858  , bool TF > // Transpose flag
1860 {
1861  return false;
1862 }
1863 //*************************************************************************************************
1864 
1865 
1866 //*************************************************************************************************
1877 template< typename VT // Type of the sparse vector
1878  , bool AF // Alignment flag
1879  , bool TF > // Transpose flag
1880 template< typename VT2 > // Type of the right-hand side dense vector
1882 {
1883  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1884  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1885 
1886  reserve( (~rhs).size() );
1887 
1888  for( size_t i=0UL; i<size(); ++i ) {
1889  append( i, (~rhs)[i], true );
1890  }
1891 }
1892 //*************************************************************************************************
1893 
1894 
1895 //*************************************************************************************************
1906 template< typename VT // Type of the sparse vector
1907  , bool AF // Alignment flag
1908  , bool TF > // Transpose flag
1909 template< typename VT2 > // Type of the right-hand side sparse vector
1911 {
1912  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1913  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1914 
1915  reserve( (~rhs).nonZeros() );
1916 
1917  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1918  append( element->index(), element->value(), true );
1919  }
1920 }
1921 //*************************************************************************************************
1922 
1923 
1924 //*************************************************************************************************
1935 template< typename VT // Type of the sparse vector
1936  , bool AF // Alignment flag
1937  , bool TF > // Transpose flag
1938 template< typename VT2 > // Type of the right-hand side dense vector
1940 {
1941  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1942 
1946 
1947  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1948 
1949  const AddType tmp( serial( *this + (~rhs) ) );
1950  reset();
1951  assign( tmp );
1952 }
1953 //*************************************************************************************************
1954 
1955 
1956 //*************************************************************************************************
1967 template< typename VT // Type of the sparse vector
1968  , bool AF // Alignment flag
1969  , bool TF > // Transpose flag
1970 template< typename VT2 > // Type of the right-hand side sparse vector
1972 {
1973  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1974 
1978 
1979  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1980 
1981  const AddType tmp( serial( *this + (~rhs) ) );
1982  reset();
1983  assign( tmp );
1984 }
1985 //*************************************************************************************************
1986 
1987 
1988 //*************************************************************************************************
1999 template< typename VT // Type of the sparse vector
2000  , bool AF // Alignment flag
2001  , bool TF > // Transpose flag
2002 template< typename VT2 > // Type of the right-hand side dense vector
2004 {
2005  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
2006 
2010 
2011  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2012 
2013  const SubType tmp( serial( *this - (~rhs) ) );
2014  reset();
2015  assign( tmp );
2016 }
2017 //*************************************************************************************************
2018 
2019 
2020 //*************************************************************************************************
2031 template< typename VT // Type of the sparse vector
2032  , bool AF // Alignment flag
2033  , bool TF > // Transpose flag
2034 template< typename VT2 > // Type of the right-hand side sparse vector
2036 {
2037  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
2038 
2042 
2043  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2044 
2045  const SubType tmp( serial( *this - (~rhs) ) );
2046  reset();
2047  assign( tmp );
2048 }
2049 //*************************************************************************************************
2050 
2051 
2052 
2053 
2054 
2055 
2056 
2057 
2058 //=================================================================================================
2059 //
2060 // SPARSESUBVECTOR OPERATORS
2061 //
2062 //=================================================================================================
2063 
2064 //*************************************************************************************************
2067 template< typename VT, bool AF, bool TF >
2068 inline void reset( SparseSubvector<VT,AF,TF>& sv );
2069 
2070 template< typename VT, bool AF, bool TF >
2071 inline void clear( SparseSubvector<VT,AF,TF>& sv );
2072 
2073 template< typename VT, bool AF, bool TF >
2074 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv );
2075 
2076 template< typename VT, bool AF, bool TF >
2077 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b );
2078 
2079 template< typename VT, bool AF, bool TF >
2080 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2081 
2082 template< typename VT, bool AF, bool TF >
2083 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2085 //*************************************************************************************************
2086 
2087 
2088 //*************************************************************************************************
2095 template< typename VT // Type of the sparse vector
2096  , bool AF // Alignment flag
2097  , bool TF > // Transpose flag
2099 {
2100  sv.reset();
2101 }
2102 //*************************************************************************************************
2103 
2104 
2105 //*************************************************************************************************
2114 template< typename VT // Type of the sparse vector
2115  , bool AF // Alignment flag
2116  , bool TF > // Transpose flag
2118 {
2119  sv.reset();
2120 }
2121 //*************************************************************************************************
2122 
2123 
2124 //*************************************************************************************************
2142 template< typename VT // Type of the sparse vector
2143  , bool AF // Alignment flag
2144  , bool TF > // Transpose flag
2145 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv )
2146 {
2148 
2149  const ConstIterator end( sv.end() );
2150  for( ConstIterator element=sv.begin(); element!=end; ++element )
2151  if( !isDefault( element->value() ) ) return false;
2152  return true;
2153 }
2154 //*************************************************************************************************
2155 
2156 
2157 //*************************************************************************************************
2169 template< typename VT // Type of the sparse vector
2170  , bool AF // Alignment flag
2171  , bool TF > // Transpose flag
2172 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b )
2173 {
2174  return ( isSame( a.vector_, ~b ) && ( a.size() == (~b).size() ) );
2175 }
2176 //*************************************************************************************************
2177 
2178 
2179 //*************************************************************************************************
2191 template< typename VT // Type of the sparse vector
2192  , bool AF // Alignment flag
2193  , bool TF > // Transpose flag
2194 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b )
2195 {
2196  return ( isSame( ~a, b.vector_ ) && ( (~a).size() == b.size() ) );
2197 }
2198 //*************************************************************************************************
2199 
2200 
2201 //*************************************************************************************************
2213 template< typename VT // Type of the sparse vector
2214  , bool AF // Alignment flag
2215  , bool TF > // Transpose flag
2217 {
2218  return ( isSame( a.vector_, b.vector_ ) && ( a.offset_ == b.offset_ ) && ( a.size_ == b.size_ ) );
2219 }
2220 //*************************************************************************************************
2221 
2222 
2223 //*************************************************************************************************
2238 template< typename VT // Type of the sparse vector
2239  , bool AF // Alignment flag
2240  , bool TF > // Transpose flag
2241 inline typename DerestrictTrait< SparseSubvector<VT,AF,TF> >::Type
2242  derestrict( SparseSubvector<VT,AF,TF>& sv )
2243 {
2244  typedef typename DerestrictTrait< SparseSubvector<VT,AF,TF> >::Type ReturnType;
2245  return ReturnType( derestrict( sv.vector_ ), sv.offset_, sv.size_ );
2246 }
2248 //*************************************************************************************************
2249 
2250 
2251 
2252 
2253 //=================================================================================================
2254 //
2255 // GLOBAL RESTRUCTURING OPERATORS
2256 //
2257 //=================================================================================================
2258 
2259 //*************************************************************************************************
2272 template< bool AF1 // Required alignment flag
2273  , typename VT // Type of the sparse vector
2274  , bool AF2 // Present alignment flag
2275  , bool TF > // Transpose flag
2276 inline const SparseSubvector<VT,AF1,TF>
2277  subvector( const SparseSubvector<VT,AF2,TF>& sv, size_t index, size_t size )
2278 {
2280 
2281  if( index + size > sv.size() )
2282  throw std::invalid_argument( "Invalid subvector specification" );
2283 
2284  return SparseSubvector<VT,AF1,TF>( sv.vector_, sv.offset_ + index, size );
2285 }
2287 //*************************************************************************************************
2288 
2289 
2290 
2291 
2292 //=================================================================================================
2293 //
2294 // ISRESTRICTED SPECIALIZATIONS
2295 //
2296 //=================================================================================================
2297 
2298 //*************************************************************************************************
2300 template< typename VT, bool AF, bool TF >
2301 struct IsRestricted< SparseSubvector<VT,AF,TF> > : public If< IsRestricted<VT>, TrueType, FalseType >::Type
2302 {
2303  enum { value = IsRestricted<VT>::value };
2304  typedef typename If< IsRestricted<VT>, TrueType, FalseType >::Type Type;
2305 };
2307 //*************************************************************************************************
2308 
2309 
2310 
2311 
2312 //=================================================================================================
2313 //
2314 // DERESTRICTTRAIT SPECIALIZATIONS
2315 //
2316 //=================================================================================================
2317 
2318 //*************************************************************************************************
2320 template< typename VT, bool AF, bool TF >
2321 struct DerestrictTrait< SparseSubvector<VT,AF,TF> >
2322 {
2323  typedef SparseSubvector< typename RemoveReference< typename DerestrictTrait<VT>::Type >::Type, AF, TF > Type;
2324 };
2326 //*************************************************************************************************
2327 
2328 
2329 
2330 
2331 //=================================================================================================
2332 //
2333 // SUBVECTORTRAIT SPECIALIZATIONS
2334 //
2335 //=================================================================================================
2336 
2337 //*************************************************************************************************
2339 template< typename VT, bool AF, bool TF >
2340 struct SubvectorTrait< SparseSubvector<VT,AF,TF> >
2341 {
2343 };
2345 //*************************************************************************************************
2346 
2347 
2348 
2349 
2350 //=================================================================================================
2351 //
2352 // SUBVECTOREXPRTRAIT SPECIALIZATIONS
2353 //
2354 //=================================================================================================
2355 
2356 //*************************************************************************************************
2358 template< typename VT, bool AF1, bool TF, bool AF2 >
2359 struct SubvectorExprTrait< SparseSubvector<VT,AF1,TF>, AF2 >
2360 {
2361  typedef SparseSubvector<VT,AF2,TF> Type;
2362 };
2364 //*************************************************************************************************
2365 
2366 
2367 //*************************************************************************************************
2369 template< typename VT, bool AF1, bool TF, bool AF2 >
2370 struct SubvectorExprTrait< const SparseSubvector<VT,AF1,TF>, AF2 >
2371 {
2372  typedef SparseSubvector<VT,AF2,TF> Type;
2373 };
2375 //*************************************************************************************************
2376 
2377 
2378 //*************************************************************************************************
2380 template< typename VT, bool AF1, bool TF, bool AF2 >
2381 struct SubvectorExprTrait< volatile SparseSubvector<VT,AF1,TF>, AF2 >
2382 {
2383  typedef SparseSubvector<VT,AF2,TF> Type;
2384 };
2386 //*************************************************************************************************
2387 
2388 
2389 //*************************************************************************************************
2391 template< typename VT, bool AF1, bool TF, bool AF2 >
2392 struct SubvectorExprTrait< const volatile SparseSubvector<VT,AF1,TF>, AF2 >
2393 {
2394  typedef SparseSubvector<VT,AF2,TF> Type;
2395 };
2397 //*************************************************************************************************
2398 
2399 } // namespace blaze
2400 
2401 #endif
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubvector.h:578
Constraint on the data type.
Pointer difference type of the Blaze library.
View on a specific subvector of a sparse vector.The SparseSubvector template represents a view on a s...
Definition: Forward.h:54
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
ValueType value_type
Type of the underlying elements.
Definition: SparseSubvector.h:586
#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 subvector/submatrix 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.
Header file for the SparseVector base class.
const SubvectorElement * operator->() const
Direct access to the sparse subvector element at the current iterator position.
Definition: SparseSubvector.h:536
const SparseSubvector & CompositeType
Data type for composite expression templates.
Definition: SparseSubvector.h:416
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:264
IndexType index() const
Access to the current index of the sparse element.
Definition: SparseSubvector.h:556
size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:726
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
PointerType pointer
Pointer return type.
Definition: SparseSubvector.h:587
IfTrue< useConst, ConstReference, typename VT::Reference >::Type Reference
Reference to a non-constant subvector value.
Definition: SparseSubvector.h:422
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:209
#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
size_t IndexType
The index type of the row element.
Definition: SparseSubvector.h:454
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:946
ReferenceType reference
Reference return type.
Definition: SparseSubvector.h:588
Iterator begin()
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:975
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:821
CRT ConstReference
Reference-to-const return type.
Definition: SparseSubvector.h:456
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
Header file for the IsRowVector type trait.
SparseSubvector(Operand vector, size_t index, size_t n)
The constructor for SparseSubvector.
Definition: SparseSubvector.h:910
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:699
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseSubvector.h:1675
size_t offset_
Offset within the according sparse vector.
Definition: SparseSubvector.h:564
IfTrue< returnConst, CRT, RT >::Type Reference
Reference return type.
Definition: SparseSubvector.h:455
#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
Header file for the RequiresEvaluation type trait.
IfTrue< useConst, ConstIterator, SubvectorIterator< VT, typename VT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: SparseSubvector.h:736
size_t size() const
Returns the size/dimension of the sparse subvector.
Definition: SparseSubvector.h:1396
void reserve(size_t n)
Setting the minimum capacity of the sparse subvector.
Definition: SparseSubvector.h:1563
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubvector.h:582
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
DifferenceType operator-(const SubvectorIterator &rhs) const
Calculating the number of elements between two subvector iterators.
Definition: SparseSubvector.h:698
VT::ElementType ElementType
Type of the subvector elements.
Definition: SparseSubvector.h:414
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:123
Constraint on the data type.
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: SparseSubvector.h:641
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1035
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubvector.h:585
Header file for the multiplication trait.
void erase(size_t index)
Erasing an element from the sparse subvector.
Definition: SparseSubvector.h:1506
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
size_t capacity() const
Returns the maximum capacity of the sparse subvector.
Definition: SparseSubvector.h:1411
Header file for the If class template.
Header file for the Subvector base class.
SubvectorIterator< const VT, typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubvector.h:733
SET::ValueType ValueType
The value type of the row element.
Definition: SparseSubvector.h:453
Header file for the IsFloatingPoint type trait.
bool canSMPAssign() const
Returns whether the subvector can be used in SMP assignments.
Definition: SparseSubvector.h:1859
SubvectorElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:501
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2511
Header file for the Or class template.
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
void assign(const DenseVector< VT2, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseSubvector.h:1881
SubvectorIterator(const SubvectorIterator< VectorType2, IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: SparseSubvector.h:619
Header file for the subvector trait.
Access proxy for a specific element of the sparse subvector.
Definition: SparseSubvector.h:430
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse subvector.
Definition: SparseSubvector.h:1786
bool operator==(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:675
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubvector.h:413
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubvector.h:412
Operand vector_
The sparse vector containing the subvector.
Definition: SparseSubvector.h:847
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
If< IsExpression< VT >, VT, VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SparseSubvector.h:395
SparseSubvector< VT, AF, TF > This
Type of this SparseSubvector instance.
Definition: SparseSubvector.h:411
SubvectorIterator & operator++()
Pre-increment operator.
Definition: SparseSubvector.h:630
const size_t size_
The size of the subvector.
Definition: SparseSubvector.h:849
Constraint on the data type.
Header file for the SparseElement base class.
Reference value() const
Access to the current value of the sparse subvector element.
Definition: SparseSubvector.h:546
Constraint on the data type.
void subAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseSubvector.h:2003
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:195
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubvector.h:1721
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2505
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubvector.h:725
size_t offset() const
Access to the offset of the subvector iterator.
Definition: SparseSubvector.h:718
Constraint on the data type.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2509
Header file for the EnableIf class template.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:841
Header file for the serial shim.
Header file for the DerestrictTrait class template.
const bool unaligned
Alignment flag for unaligned subvectors and submatrices.
Definition: AlignmentFlag.h:63
SET::Reference RT
Reference type of the underlying sparse element.
Definition: SparseSubvector.h:447
Header file for the IsNumeric type trait.
Reference operator[](size_t index)
Subscript operator for the direct access to the subvector elements.
Definition: SparseSubvector.h:939
SubvectorElement & operator=(const T &v)
Assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:477
SET::ConstReference CRT
Reference-to-const type of the underlying sparse element.
Definition: SparseSubvector.h:448
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2506
Header file for the IsConst type trait.
ValueType ReferenceType
Reference return type.
Definition: SparseSubvector.h:581
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:150
Base template for the MultTrait class.
Definition: MultTrait.h:150
Header file for the addition trait.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
Header file for the division trait.
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:140
SubvectorIterator()
Default constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:595
bool canAlias(const Other *alias) const
Returns whether the sparse subvector can alias with the given address alias.
Definition: SparseSubvector.h:1818
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2510
Header file for the isDefault shim.
bool isAliased(const Other *alias) const
Returns whether the sparse subvector is aliased with the given address alias.
Definition: SparseSubvector.h:1839
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse subvector.
Definition: SparseSubvector.h:1465
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
#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
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
Header file for the RemoveReference type trait.
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
SubvectorElement & operator+=(const T &v)
Addition assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:489
Iterator find(size_t index)
Searches for a specific subvector element.
Definition: SparseSubvector.h:1618
Base template for the DivTrait class.
Definition: DivTrait.h:150
size_t nonZeros() const
Returns the number of non-zero elements in the subvector.
Definition: SparseSubvector.h:1428
IteratorType base() const
Access to the current position of the subvector iterator.
Definition: SparseSubvector.h:708
ReferenceType operator*() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:653
#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
ValueType PointerType
Pointer return type.
Definition: SparseSubvector.h:580
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:1015
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse subvector.
Definition: SparseSubvector.h:1488
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:151
boost::false_type FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
PointerType operator->() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:663
Iterator over the elements of the sparse subvector.
Definition: SparseSubvector.h:574
std::iterator_traits< IteratorType >::value_type SET
Type of the underlying sparse elements.
Definition: SparseSubvector.h:445
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
#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
const size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:848
SubvectorElement & operator/=(const T &v)
Division assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:525
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2502
SubvectorIterator(IteratorType iterator, size_t index)
Constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:607
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: SparseSubvector.h:419
void reset()
Reset to the default initial values.
Definition: SparseSubvector.h:1443
Header file for the SubvectorExprTrait class template.
IteratorType pos_
Iterator to the current position within the sparse subvector.
Definition: SparseSubvector.h:563
SparseSubvector & operator=(const SparseSubvector &rhs)
Copy assignment operator for SparseSubvector.
Definition: SparseSubvector.h:1107
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1075
void addAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseSubvector.h:1939
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2508
Base template for the SubTrait class.
Definition: SubTrait.h:150
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubvector.h:589
boost::true_type TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
SubvectorElement< VectorType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubvector.h:579
SubvectorElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:513
Header file for the IsRestricted type trait.
#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:238
bool operator!=(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Inequality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:687
#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
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubvector.h:415
SubvectorElement(IteratorType pos, size_t offset)
Constructor for the SubvectorElement class.
Definition: SparseSubvector.h:465
Compile time type selection.The IfTrue class template selects one of the two given types T1 and T2 de...
Definition: If.h:59
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849