All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
67 #include <blaze/util/Assert.h>
68 #include <blaze/util/EnableIf.h>
70 #include <blaze/util/mpl/If.h>
71 #include <blaze/util/mpl/Or.h>
72 #include <blaze/util/SelectType.h>
73 #include <blaze/util/Types.h>
77 
78 
79 namespace blaze {
80 
81 //=================================================================================================
82 //
83 // CLASS DEFINITION
84 //
85 //=================================================================================================
86 
87 //*************************************************************************************************
379 template< typename VT // Type of the sparse vector
380  , bool AF = unaligned // Alignment flag
381  , bool TF = IsRowVector<VT>::value > // Transpose flag
382 class SparseSubvector : public SparseVector< SparseSubvector<VT,AF,TF>, TF >
383  , private Subvector
384 {
385  private:
386  //**Type definitions****************************************************************************
388  typedef typename SelectType< IsExpression<VT>::value, VT, VT& >::Type Operand;
389  //**********************************************************************************************
390 
391  //**********************************************************************************************
393 
399  enum { useConst = IsConst<VT>::value };
400  //**********************************************************************************************
401 
402  public:
403  //**Type definitions****************************************************************************
407  typedef typename VT::ElementType ElementType;
408  typedef typename VT::ReturnType ReturnType;
410 
413 
416  //**********************************************************************************************
417 
418  //**SubvectorElement class definition***********************************************************
421  template< typename VectorType // Type of the sparse vector
422  , typename IteratorType > // Type of the sparse vector iterator
424  {
425  private:
426  //*******************************************************************************************
428 
433  enum { returnConst = IsConst<VectorType>::value };
434  //*******************************************************************************************
435 
436  public:
437  //**Type definitions*************************************************************************
440  //*******************************************************************************************
441 
442  //**Constructor******************************************************************************
448  inline SubvectorElement( IteratorType pos, size_t offset )
449  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
450  , offset_( offset ) // Offset within the according sparse vector
451  {}
452  //*******************************************************************************************
453 
454  //**Assignment operator**********************************************************************
460  template< typename T > inline SubvectorElement& operator=( const T& v ) {
461  *pos_ = v;
462  return *this;
463  }
464  //*******************************************************************************************
465 
466  //**Addition assignment operator*************************************************************
472  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
473  *pos_ += v;
474  return *this;
475  }
476  //*******************************************************************************************
477 
478  //**Subtraction assignment operator**********************************************************
484  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
485  *pos_ -= v;
486  return *this;
487  }
488  //*******************************************************************************************
489 
490  //**Multiplication assignment operator*******************************************************
496  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
497  *pos_ *= v;
498  return *this;
499  }
500  //*******************************************************************************************
501 
502  //**Division assignment operator*************************************************************
508  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
509  *pos_ /= v;
510  return *this;
511  }
512  //*******************************************************************************************
513 
514  //**Element access operator******************************************************************
519  inline const SubvectorElement* operator->() const {
520  return this;
521  }
522  //*******************************************************************************************
523 
524  //**Value function***************************************************************************
529  inline ReferenceType value() const {
530  return pos_->value();
531  }
532  //*******************************************************************************************
533 
534  //**Index function***************************************************************************
539  inline size_t index() const {
540  return pos_->index() - offset_;
541  }
542  //*******************************************************************************************
543 
544  private:
545  //**Member variables*************************************************************************
546  IteratorType pos_;
547  size_t offset_;
548  //*******************************************************************************************
549  };
550  //**********************************************************************************************
551 
552  //**SubvectorIterator class definition**********************************************************
555  template< typename VectorType // Type of the sparse vector
556  , typename IteratorType > // Type of the sparse vector iterator
558  {
559  public:
560  //**Type definitions*************************************************************************
561  typedef std::forward_iterator_tag IteratorCategory;
566 
567  // STL iterator requirements
573  //*******************************************************************************************
574 
575  //**Default constructor**********************************************************************
579  : pos_ () // Iterator to the current sparse element
580  , offset_() // The offset of the subvector within the sparse vector
581  {}
582  //*******************************************************************************************
583 
584  //**Constructor******************************************************************************
590  inline SubvectorIterator( IteratorType iterator, size_t index )
591  : pos_ ( iterator ) // Iterator to the current sparse element
592  , offset_( index ) // The offset of the subvector within the sparse vector
593  {}
594  //*******************************************************************************************
595 
596  //**Constructor******************************************************************************
601  template< typename VectorType2, typename IteratorType2 >
603  : pos_ ( it.base() ) // Iterator to the current sparse element.
604  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
605  {}
606  //*******************************************************************************************
607 
608  //**Prefix increment operator****************************************************************
614  ++pos_;
615  return *this;
616  }
617  //*******************************************************************************************
618 
619  //**Postfix increment operator***************************************************************
624  inline const SubvectorIterator operator++( int ) {
625  const SubvectorIterator tmp( *this );
626  ++(*this);
627  return tmp;
628  }
629  //*******************************************************************************************
630 
631  //**Element access operator******************************************************************
636  inline ReferenceType operator*() const {
637  return ReferenceType( pos_, offset_ );
638  }
639  //*******************************************************************************************
640 
641  //**Element access operator******************************************************************
646  inline PointerType operator->() const {
647  return PointerType( pos_, offset_ );
648  }
649  //*******************************************************************************************
650 
651  //**Equality operator************************************************************************
657  template< typename VectorType2, typename IteratorType2 >
659  return base() == rhs.base();
660  }
661  //*******************************************************************************************
662 
663  //**Inequality operator**********************************************************************
669  template< typename VectorType2, typename IteratorType2 >
671  return !( *this == rhs );
672  }
673  //*******************************************************************************************
674 
675  //**Subtraction operator*********************************************************************
681  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
682  return pos_ - rhs.pos_;
683  }
684  //*******************************************************************************************
685 
686  //**Base function****************************************************************************
691  inline IteratorType base() const {
692  return pos_;
693  }
694  //*******************************************************************************************
695 
696  //**Offset function**************************************************************************
701  inline size_t offset() const {
702  return offset_;
703  }
704  //*******************************************************************************************
705 
706  private:
707  //**Member variables*************************************************************************
708  IteratorType pos_;
709  size_t offset_;
710  //*******************************************************************************************
711  };
712  //**********************************************************************************************
713 
714  //**Type definitions****************************************************************************
717 
720  //**********************************************************************************************
721 
722  //**Compilation flags***************************************************************************
724  enum { smpAssignable = VT::smpAssignable };
725  //**********************************************************************************************
726 
727  //**Constructors********************************************************************************
730  explicit inline SparseSubvector( Operand vector, size_t index, size_t n );
731  // No explicitly declared copy constructor.
733  //**********************************************************************************************
734 
735  //**Destructor**********************************************************************************
736  // No explicitly declared destructor.
737  //**********************************************************************************************
738 
739  //**Data access functions***********************************************************************
742  inline Reference operator[]( size_t index );
743  inline ConstReference operator[]( size_t index ) const;
744  inline Iterator begin ();
745  inline ConstIterator begin () const;
746  inline ConstIterator cbegin() const;
747  inline Iterator end ();
748  inline ConstIterator end () const;
749  inline ConstIterator cend () const;
751  //**********************************************************************************************
752 
753  //**Assignment operators************************************************************************
756  inline SparseSubvector& operator= ( const SparseSubvector& rhs );
757  template< typename VT2 > inline SparseSubvector& operator= ( const DenseVector<VT2,TF>& rhs );
758  template< typename VT2 > inline SparseSubvector& operator= ( const SparseVector<VT2,TF>& rhs );
759  template< typename VT2 > inline SparseSubvector& operator+=( const Vector<VT2,TF>& rhs );
760  template< typename VT2 > inline SparseSubvector& operator-=( const Vector<VT2,TF>& rhs );
761  template< typename VT2 > inline SparseSubvector& operator*=( const Vector<VT2,TF>& rhs );
762 
763  template< typename Other >
764  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
765  operator*=( Other rhs );
766 
767  template< typename Other >
768  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
769  operator/=( Other rhs );
771  //**********************************************************************************************
772 
773  //**Utility functions***************************************************************************
776  inline size_t size() const;
777  inline size_t capacity() const;
778  inline size_t nonZeros() const;
779  inline void reset();
780  inline Iterator insert ( size_t index, const ElementType& value );
781  inline void erase ( size_t index );
782  inline Iterator erase ( Iterator pos );
783  inline Iterator erase ( Iterator first, Iterator last );
784  inline void reserve( size_t n );
785  template< typename Other > inline SparseSubvector& scale ( Other scalar );
787  //**********************************************************************************************
788 
789  //**Lookup functions****************************************************************************
792  inline Iterator find ( size_t index );
793  inline ConstIterator find ( size_t index ) const;
794  inline Iterator lowerBound( size_t index );
795  inline ConstIterator lowerBound( size_t index ) const;
796  inline Iterator upperBound( size_t index );
797  inline ConstIterator upperBound( size_t index ) const;
799  //**********************************************************************************************
800 
801  //**Low-level utility functions*****************************************************************
804  inline void append( size_t index, const ElementType& value, bool check=false );
806  //**********************************************************************************************
807 
808  //**Expression template evaluation functions****************************************************
811  template< typename Other > inline bool canAlias ( const Other* alias ) const;
812  template< typename Other > inline bool isAliased( const Other* alias ) const;
813 
814  inline bool canSMPAssign() const;
815 
816  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
817  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
818  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
819  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
820  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
821  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
823  //**********************************************************************************************
824 
825  private:
826  //**Member variables****************************************************************************
830  const size_t offset_;
831  const size_t size_;
832 
833  //**********************************************************************************************
834 
835  //**Friend declarations*************************************************************************
837  template< bool AF1, typename VT2, bool AF2, bool TF2 >
838  friend const SparseSubvector<VT2,AF1,TF2>
839  subvector( const SparseSubvector<VT2,AF2,TF2>& sv, size_t index, size_t size );
840 
841  template< typename VT2, bool AF2, bool TF2 >
842  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseVector<VT2,TF2>& b );
843 
844  template< typename VT2, bool AF2, bool TF2 >
845  friend bool isSame( const SparseVector<VT2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
846 
847  template< typename VT2, bool AF2, bool TF2 >
848  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
850  //**********************************************************************************************
851 
852  //**Compile time checks*************************************************************************
860  //**********************************************************************************************
861 };
862 //*************************************************************************************************
863 
864 
865 
866 
867 //=================================================================================================
868 //
869 // CONSTRUCTOR
870 //
871 //=================================================================================================
872 
873 //*************************************************************************************************
885 template< typename VT // Type of the sparse vector
886  , bool AF // Alignment flag
887  , bool TF > // Transpose flag
888 inline SparseSubvector<VT,AF,TF>::SparseSubvector( Operand vector, size_t index, size_t n )
889  : vector_( vector ) // The sparse vector containing the subvector
890  , offset_( index ) // The offset of the subvector within the sparse vector
891  , size_ ( n ) // The size of the subvector
892 {
893  if( index + n > vector.size() )
894  throw std::invalid_argument( "Invalid subvector specification" );
895 }
896 //*************************************************************************************************
897 
898 
899 
900 
901 //=================================================================================================
902 //
903 // DATA ACCESS FUNCTIONS
904 //
905 //=================================================================================================
906 
907 //*************************************************************************************************
913 template< typename VT // Type of the sparse vector
914  , bool AF // Alignment flag
915  , bool TF > // Transpose flag
918 {
919  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
920  return vector_[offset_+index];
921 }
922 //*************************************************************************************************
923 
924 
925 //*************************************************************************************************
931 template< typename VT // Type of the sparse vector
932  , bool AF // Alignment flag
933  , bool TF > // Transpose flag
936 {
937  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
938  return const_cast<const VT&>( vector_ )[offset_+index];
939 }
940 //*************************************************************************************************
941 
942 
943 //*************************************************************************************************
950 template< typename VT // Type of the sparse vector
951  , bool AF // Alignment flag
952  , bool TF > // Transpose flag
954 {
955  if( offset_ == 0UL )
956  return Iterator( vector_.begin(), offset_ );
957  else
958  return Iterator( vector_.lowerBound( offset_ ), offset_ );
959 }
960 //*************************************************************************************************
961 
962 
963 //*************************************************************************************************
970 template< typename VT // Type of the sparse vector
971  , bool AF // Alignment flag
972  , bool TF > // Transpose flag
974 {
975  if( offset_ == 0UL )
976  return ConstIterator( vector_.cbegin(), offset_ );
977  else
978  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
979 }
980 //*************************************************************************************************
981 
982 
983 //*************************************************************************************************
990 template< typename VT // Type of the sparse vector
991  , bool AF // Alignment flag
992  , bool TF > // Transpose flag
994 {
995  if( offset_ == 0UL )
996  return ConstIterator( vector_.cbegin(), offset_ );
997  else
998  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
999 }
1000 //*************************************************************************************************
1001 
1002 
1003 //*************************************************************************************************
1010 template< typename VT // Type of the sparse vector
1011  , bool AF // Alignment flag
1012  , bool TF > // Transpose flag
1014 {
1015  if( offset_ + size_ == vector_.size() )
1016  return Iterator( vector_.end(), offset_ );
1017  else
1018  return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1019 }
1020 //*************************************************************************************************
1021 
1022 
1023 //*************************************************************************************************
1030 template< typename VT // Type of the sparse vector
1031  , bool AF // Alignment flag
1032  , bool TF > // Transpose flag
1034 {
1035  if( offset_ + size_ == vector_.size() )
1036  return ConstIterator( vector_.cend(), offset_ );
1037  else
1038  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1039 }
1040 //*************************************************************************************************
1041 
1042 
1043 //*************************************************************************************************
1050 template< typename VT // Type of the sparse vector
1051  , bool AF // Alignment flag
1052  , bool TF > // Transpose flag
1054 {
1055  if( offset_ + size_ == vector_.size() )
1056  return ConstIterator( vector_.cend(), offset_ );
1057  else
1058  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1059 }
1060 //*************************************************************************************************
1061 
1062 
1063 
1064 
1065 //=================================================================================================
1066 //
1067 // ASSIGNMENT OPERATORS
1068 //
1069 //=================================================================================================
1070 
1071 //*************************************************************************************************
1081 template< typename VT // Type of the sparse vector
1082  , bool AF // Alignment flag
1083  , bool TF > // Transpose flag
1086 {
1087  using blaze::assign;
1088 
1091 
1092  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
1093  return *this;
1094 
1095  if( size() != rhs.size() )
1096  throw std::invalid_argument( "Vector sizes do not match" );
1097 
1098  if( rhs.canAlias( &vector_ ) ) {
1099  const ResultType tmp( rhs );
1100  reset();
1101  assign( *this, tmp );
1102  }
1103  else {
1104  reset();
1105  assign( *this, rhs );
1106  }
1107 
1108  return *this;
1109 }
1110 //*************************************************************************************************
1111 
1112 
1113 //*************************************************************************************************
1123 template< typename VT // Type of the sparse vector
1124  , bool AF // Alignment flag
1125  , bool TF > // Transpose flag
1126 template< typename VT2 > // Type of the right-hand side dense vector
1129 {
1130  using blaze::assign;
1131 
1135 
1136  if( size() != (~rhs).size() )
1137  throw std::invalid_argument( "Vector sizes do not match" );
1138 
1139  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1140  const typename VT2::ResultType tmp( ~rhs );
1141  reset();
1142  assign( *this, tmp );
1143  }
1144  else {
1145  reset();
1146  assign( *this, ~rhs );
1147  }
1148 
1149  return *this;
1150 }
1151 //*************************************************************************************************
1152 
1153 
1154 //*************************************************************************************************
1164 template< typename VT // Type of the sparse vector
1165  , bool AF // Alignment flag
1166  , bool TF > // Transpose flag
1167 template< typename VT2 > // Type of the right-hand side sparse vector
1170 {
1171  using blaze::assign;
1172 
1176 
1177  if( size() != (~rhs).size() )
1178  throw std::invalid_argument( "Vector sizes do not match" );
1179 
1180  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1181  const typename VT2::ResultType tmp( ~rhs );
1182  reset();
1183  assign( *this, tmp );
1184  }
1185  else {
1186  reset();
1187  assign( *this, ~rhs );
1188  }
1189 
1190  return *this;
1191 }
1192 //*************************************************************************************************
1193 
1194 
1195 //*************************************************************************************************
1205 template< typename VT // Type of the sparse vector
1206  , bool AF // Alignment flag
1207  , bool TF > // Transpose flag
1208 template< typename VT2 > // Type of the right-hand side vector
1211 {
1212  using blaze::addAssign;
1213 
1214  if( size() != (~rhs).size() )
1215  throw std::invalid_argument( "Vector sizes do not match" );
1216 
1217  addAssign( *this, ~rhs );
1218 
1219  return *this;
1220 }
1221 //*************************************************************************************************
1222 
1223 
1224 //*************************************************************************************************
1234 template< typename VT // Type of the sparse vector
1235  , bool AF // Alignment flag
1236  , bool TF > // Transpose flag
1237 template< typename VT2 > // Type of the right-hand side vector
1240 {
1241  using blaze::subAssign;
1242 
1243  if( size() != (~rhs).size() )
1244  throw std::invalid_argument( "Vector sizes do not match" );
1245 
1246  subAssign( *this, ~rhs );
1247 
1248  return *this;
1249 }
1250 //*************************************************************************************************
1251 
1252 
1253 //*************************************************************************************************
1264 template< typename VT // Type of the sparse vector
1265  , bool AF // Alignment flag
1266  , bool TF > // Transpose flag
1267 template< typename VT2 > // Type of the right-hand side vector
1270 {
1271  if( size() != (~rhs).size() )
1272  throw std::invalid_argument( "Vector sizes do not match" );
1273 
1274  typedef typename MultTrait<ResultType,typename VT2::ResultType>::Type MultType;
1275 
1279 
1280  const MultType tmp( *this * (~rhs) );
1281  reset();
1282  assign( tmp );
1283 
1284  return *this;
1285 }
1286 //*************************************************************************************************
1287 
1288 
1289 //*************************************************************************************************
1300 template< typename VT // Type of the sparse vector
1301  , bool AF // Alignment flag
1302  , bool TF > // Transpose flag
1303 template< typename Other > // Data type of the right-hand side scalar
1304 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1306 {
1307  const Iterator last( end() );
1308  for( Iterator element=begin(); element!=last; ++element )
1309  element->value() *= rhs;
1310  return *this;
1311 }
1312 //*************************************************************************************************
1313 
1314 
1315 //*************************************************************************************************
1327 template< typename VT // Type of the sparse vector
1328  , bool AF // Alignment flag
1329  , bool TF > // Transpose flag
1330 template< typename Other > // Data type of the right-hand side scalar
1331 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1333 {
1334  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1335 
1336  typedef typename DivTrait<ElementType,Other>::Type DT;
1337  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1338 
1339  const Iterator last( end() );
1340 
1341  // Depending on the two involved data types, an integer division is applied or a
1342  // floating point division is selected.
1344  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1345  for( Iterator element=begin(); element!=last; ++element )
1346  element->value() *= tmp;
1347  }
1348  else {
1349  for( Iterator element=begin(); element!=last; ++element )
1350  element->value() /= rhs;
1351  }
1352 
1353  return *this;
1354 }
1355 //*************************************************************************************************
1356 
1357 
1358 
1359 
1360 //=================================================================================================
1361 //
1362 // UTILITY FUNCTIONS
1363 //
1364 //=================================================================================================
1365 
1366 //*************************************************************************************************
1371 template< typename VT // Type of the sparse vector
1372  , bool AF // Alignment flag
1373  , bool TF > // Transpose flag
1374 inline size_t SparseSubvector<VT,AF,TF>::size() const
1375 {
1376  return size_;
1377 }
1378 //*************************************************************************************************
1379 
1380 
1381 //*************************************************************************************************
1386 template< typename VT // Type of the sparse vector
1387  , bool AF // Alignment flag
1388  , bool TF > // Transpose flag
1390 {
1391  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1392 }
1393 //*************************************************************************************************
1394 
1395 
1396 //*************************************************************************************************
1403 template< typename VT // Type of the sparse vector
1404  , bool AF // Alignment flag
1405  , bool TF > // Transpose flag
1407 {
1408  return end() - begin();
1409 }
1410 //*************************************************************************************************
1411 
1412 
1413 //*************************************************************************************************
1418 template< typename VT // Type of the sparse vector
1419  , bool AF // Alignment flag
1420  , bool TF > // Transpose flag
1422 {
1423  vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1424 }
1425 //*************************************************************************************************
1426 
1427 
1428 //*************************************************************************************************
1440 template< typename VT // Type of the sparse vector
1441  , bool AF // Alignment flag
1442  , bool TF > // Transpose flag
1444  SparseSubvector<VT,AF,TF>::insert( size_t index, const ElementType& value )
1445 {
1446  return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1447 }
1448 //*************************************************************************************************
1449 
1450 
1451 //*************************************************************************************************
1459 template< typename VT // Type of the sparse vector
1460  , bool AF // Alignment flag
1461  , bool TF > // Transpose flag
1462 inline void SparseSubvector<VT,AF,TF>::erase( size_t index )
1463 {
1464  vector_.erase( offset_ + index );
1465 }
1466 //*************************************************************************************************
1467 
1468 
1469 //*************************************************************************************************
1477 template< typename VT // Type of the sparse vector
1478  , bool AF // Alignment flag
1479  , bool TF > // Transpose flag
1481 {
1482  return Iterator( vector_.erase( pos.base() ), offset_ );
1483 }
1484 //*************************************************************************************************
1485 
1486 
1487 //*************************************************************************************************
1496 template< typename VT // Type of the sparse vector
1497  , bool AF // Alignment flag
1498  , bool TF > // Transpose flag
1501 {
1502  return Iterator( vector_.erase( first.base(), last.base() ), offset_ );
1503 }
1504 //*************************************************************************************************
1505 
1506 
1507 //*************************************************************************************************
1516 template< typename VT // Type of the sparse vector
1517  , bool AF // Alignment flag
1518  , bool TF > // Transpose flag
1520 {
1521  const size_t current( capacity() );
1522 
1523  if( n > current ) {
1524  vector_.reserve( vector_.capacity() + n - current );
1525  }
1526 }
1527 //*************************************************************************************************
1528 
1529 
1530 //*************************************************************************************************
1536 template< typename VT // Type of the sparse vector
1537  , bool AF // Alignment flag
1538  , bool TF > // Transpose flag
1539 template< typename Other > // Data type of the scalar value
1541 {
1542  for( Iterator element=begin(); element!=end(); ++element )
1543  element->value() *= scalar;
1544  return *this;
1545 }
1546 //*************************************************************************************************
1547 
1548 
1549 
1550 
1551 //=================================================================================================
1552 //
1553 // LOOKUP FUNCTIONS
1554 //
1555 //=================================================================================================
1556 
1557 //*************************************************************************************************
1570 template< typename VT // Type of the sparse vector
1571  , bool AF // Alignment flag
1572  , bool TF > // Transpose flag
1575 {
1576  const typename VT::Iterator pos( vector_.find( offset_ + index ) );
1577 
1578  if( pos != vector_.end() )
1579  return Iterator( pos, offset_ );
1580  else
1581  return end();
1582 }
1583 //*************************************************************************************************
1584 
1585 
1586 //*************************************************************************************************
1599 template< typename VT // Type of the sparse vector
1600  , bool AF // Alignment flag
1601  , bool TF > // Transpose flag
1603  SparseSubvector<VT,AF,TF>::find( size_t index ) const
1604 {
1605  const typename VT::ConstIterator pos( vector_.find( offset_ + index ) );
1606 
1607  if( pos != vector_.end() )
1608  return Iterator( pos, offset_ );
1609  else
1610  return end();
1611 }
1612 //*************************************************************************************************
1613 
1614 
1615 //*************************************************************************************************
1627 template< typename VT // Type of the sparse vector
1628  , bool AF // Alignment flag
1629  , bool TF > // Transpose flag
1632 {
1633  return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1634 }
1635 //*************************************************************************************************
1636 
1637 
1638 //*************************************************************************************************
1650 template< typename VT // Type of the sparse vector
1651  , bool AF // Alignment flag
1652  , bool TF > // Transpose flag
1655 {
1656  return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1657 }
1658 //*************************************************************************************************
1659 
1660 
1661 //*************************************************************************************************
1673 template< typename VT // Type of the sparse vector
1674  , bool AF // Alignment flag
1675  , bool TF > // Transpose flag
1678 {
1679  return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1680 }
1681 //*************************************************************************************************
1682 
1683 
1684 //*************************************************************************************************
1696 template< typename VT // Type of the sparse vector
1697  , bool AF // Alignment flag
1698  , bool TF > // Transpose flag
1701 {
1702  return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1703 }
1704 //*************************************************************************************************
1705 
1706 
1707 
1708 
1709 //=================================================================================================
1710 //
1711 // LOW-LEVEL UTILITY FUNCTIONS
1712 //
1713 //=================================================================================================
1714 
1715 //*************************************************************************************************
1739 template< typename VT // Type of the sparse vector
1740  , bool AF // Alignment flag
1741  , bool TF > // Transpose flag
1742 inline void SparseSubvector<VT,AF,TF>::append( size_t index, const ElementType& value, bool check )
1743 {
1744  if( offset_ + size_ == vector_.size() )
1745  vector_.append( offset_ + index, value, check );
1746  else if( !check || !isDefault( value ) )
1747  vector_.insert( offset_ + index, value );
1748 }
1749 //*************************************************************************************************
1750 
1751 
1752 
1753 
1754 //=================================================================================================
1755 //
1756 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1757 //
1758 //=================================================================================================
1759 
1760 //*************************************************************************************************
1770 template< typename VT // Type of the sparse vector
1771  , bool AF // Alignment flag
1772  , bool TF > // Transpose flag
1773 template< typename Other > // Data type of the foreign expression
1774 inline bool SparseSubvector<VT,AF,TF>::canAlias( const Other* alias ) const
1775 {
1776  return vector_.isAliased( alias );
1777 }
1778 //*************************************************************************************************
1779 
1780 
1781 //*************************************************************************************************
1791 template< typename VT // Type of the sparse vector
1792  , bool AF // Alignment flag
1793  , bool TF > // Transpose flag
1794 template< typename Other > // Data type of the foreign expression
1795 inline bool SparseSubvector<VT,AF,TF>::isAliased( const Other* alias ) const
1796 {
1797  return vector_.isAliased( alias );
1798 }
1799 //*************************************************************************************************
1800 
1801 
1802 //*************************************************************************************************
1812 template< typename VT // Type of the sparse vector
1813  , bool AF // Alignment flag
1814  , bool TF > // Transpose flag
1816 {
1817  return false;
1818 }
1819 //*************************************************************************************************
1820 
1821 
1822 //*************************************************************************************************
1833 template< typename VT // Type of the sparse vector
1834  , bool AF // Alignment flag
1835  , bool TF > // Transpose flag
1836 template< typename VT2 > // Type of the right-hand side dense vector
1838 {
1839  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1840  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1841 
1842  reserve( (~rhs).size() );
1843 
1844  for( size_t i=0UL; i<size(); ++i ) {
1845  append( i, (~rhs)[i], true );
1846  }
1847 }
1848 //*************************************************************************************************
1849 
1850 
1851 //*************************************************************************************************
1862 template< typename VT // Type of the sparse vector
1863  , bool AF // Alignment flag
1864  , bool TF > // Transpose flag
1865 template< typename VT2 > // Type of the right-hand side sparse vector
1867 {
1868  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1869  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1870 
1871  reserve( (~rhs).nonZeros() );
1872 
1873  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1874  append( element->index(), element->value(), true );
1875  }
1876 }
1877 //*************************************************************************************************
1878 
1879 
1880 //*************************************************************************************************
1891 template< typename VT // Type of the sparse vector
1892  , bool AF // Alignment flag
1893  , bool TF > // Transpose flag
1894 template< typename VT2 > // Type of the right-hand side dense vector
1896 {
1897  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1898 
1902 
1903  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1904 
1905  const AddType tmp( serial( *this + (~rhs) ) );
1906  reset();
1907  assign( tmp );
1908 }
1909 //*************************************************************************************************
1910 
1911 
1912 //*************************************************************************************************
1923 template< typename VT // Type of the sparse vector
1924  , bool AF // Alignment flag
1925  , bool TF > // Transpose flag
1926 template< typename VT2 > // Type of the right-hand side sparse vector
1928 {
1929  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1930 
1934 
1935  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1936 
1937  const AddType tmp( serial( *this + (~rhs) ) );
1938  reset();
1939  assign( tmp );
1940 }
1941 //*************************************************************************************************
1942 
1943 
1944 //*************************************************************************************************
1955 template< typename VT // Type of the sparse vector
1956  , bool AF // Alignment flag
1957  , bool TF > // Transpose flag
1958 template< typename VT2 > // Type of the right-hand side dense vector
1960 {
1961  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
1962 
1966 
1967  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1968 
1969  const SubType tmp( serial( *this - (~rhs) ) );
1970  reset();
1971  assign( tmp );
1972 }
1973 //*************************************************************************************************
1974 
1975 
1976 //*************************************************************************************************
1987 template< typename VT // Type of the sparse vector
1988  , bool AF // Alignment flag
1989  , bool TF > // Transpose flag
1990 template< typename VT2 > // Type of the right-hand side sparse vector
1992 {
1993  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
1994 
1998 
1999  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2000 
2001  const SubType tmp( serial( *this - (~rhs) ) );
2002  reset();
2003  assign( tmp );
2004 }
2005 //*************************************************************************************************
2006 
2007 
2008 
2009 
2010 
2011 
2012 
2013 
2014 //=================================================================================================
2015 //
2016 // SPARSESUBVECTOR OPERATORS
2017 //
2018 //=================================================================================================
2019 
2020 //*************************************************************************************************
2023 template< typename VT, bool AF, bool TF >
2024 inline void reset( SparseSubvector<VT,AF,TF>& sv );
2025 
2026 template< typename VT, bool AF, bool TF >
2027 inline void clear( SparseSubvector<VT,AF,TF>& sv );
2028 
2029 template< typename VT, bool AF, bool TF >
2030 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv );
2031 
2032 template< typename VT, bool AF, bool TF >
2033 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b );
2034 
2035 template< typename VT, bool AF, bool TF >
2036 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2037 
2038 template< typename VT, bool AF, bool TF >
2039 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2041 //*************************************************************************************************
2042 
2043 
2044 //*************************************************************************************************
2051 template< typename VT // Type of the sparse vector
2052  , bool AF // Alignment flag
2053  , bool TF > // Transpose flag
2055 {
2056  sv.reset();
2057 }
2058 //*************************************************************************************************
2059 
2060 
2061 //*************************************************************************************************
2070 template< typename VT // Type of the sparse vector
2071  , bool AF // Alignment flag
2072  , bool TF > // Transpose flag
2074 {
2075  sv.reset();
2076 }
2077 //*************************************************************************************************
2078 
2079 
2080 //*************************************************************************************************
2098 template< typename VT // Type of the sparse vector
2099  , bool AF // Alignment flag
2100  , bool TF > // Transpose flag
2101 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv )
2102 {
2104 
2105  const ConstIterator end( sv.end() );
2106  for( ConstIterator element=sv.begin(); element!=end; ++element )
2107  if( !isDefault( element->value() ) ) return false;
2108  return true;
2109 }
2110 //*************************************************************************************************
2111 
2112 
2113 //*************************************************************************************************
2125 template< typename VT, bool AF, bool TF >
2126 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b )
2127 {
2128  return ( isSame( a.vector_, ~b ) && ( a.size() == (~b).size() ) );
2129 }
2130 //*************************************************************************************************
2131 
2132 
2133 //*************************************************************************************************
2145 template< typename VT, bool AF, bool TF >
2146 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b )
2147 {
2148  return ( isSame( ~a, b.vector_ ) && ( (~a).size() == b.size() ) );
2149 }
2150 //*************************************************************************************************
2151 
2152 
2153 //*************************************************************************************************
2165 template< typename VT, bool AF, bool TF >
2167 {
2168  return ( isSame( a.vector_, b.vector_ ) && ( a.offset_ == b.offset_ ) && ( a.size_ == b.size_ ) );
2169 }
2170 //*************************************************************************************************
2171 
2172 
2173 
2174 
2175 //=================================================================================================
2176 //
2177 // GLOBAL RESTRUCTURING OPERATORS
2178 //
2179 //=================================================================================================
2180 
2181 //*************************************************************************************************
2194 template< bool AF1 // Required alignment flag
2195  , typename VT // Type of the sparse vector
2196  , bool AF2 // Present alignment flag
2197  , bool TF > // Transpose flag
2198 inline const SparseSubvector<VT,AF1,TF>
2199  subvector( const SparseSubvector<VT,AF2,TF>& sv, size_t index, size_t size )
2200 {
2202 
2203  if( index + size > sv.size() )
2204  throw std::invalid_argument( "Invalid subvector specification" );
2205 
2206  return SparseSubvector<VT,AF1,TF>( sv.vector_, sv.offset_ + index, size );
2207 }
2209 //*************************************************************************************************
2210 
2211 
2212 
2213 
2214 //=================================================================================================
2215 //
2216 // SUBVECTORTRAIT SPECIALIZATIONS
2217 //
2218 //=================================================================================================
2219 
2220 //*************************************************************************************************
2222 template< typename VT, bool AF, bool TF >
2223 struct SubvectorTrait< SparseSubvector<VT,AF,TF> >
2224 {
2226 };
2228 //*************************************************************************************************
2229 
2230 
2231 
2232 
2233 //=================================================================================================
2234 //
2235 // SUBVECTOREXPRTRAIT SPECIALIZATIONS
2236 //
2237 //=================================================================================================
2238 
2239 //*************************************************************************************************
2241 template< typename VT, bool AF1, bool TF, bool AF2 >
2242 struct SubvectorExprTrait< SparseSubvector<VT,AF1,TF>, AF2 >
2243 {
2244  typedef SparseSubvector<VT,AF2,TF> Type;
2245 };
2247 //*************************************************************************************************
2248 
2249 
2250 //*************************************************************************************************
2252 template< typename VT, bool AF1, bool TF, bool AF2 >
2253 struct SubvectorExprTrait< const SparseSubvector<VT,AF1,TF>, AF2 >
2254 {
2255  typedef SparseSubvector<VT,AF2,TF> Type;
2256 };
2258 //*************************************************************************************************
2259 
2260 
2261 //*************************************************************************************************
2263 template< typename VT, bool AF1, bool TF, bool AF2 >
2264 struct SubvectorExprTrait< volatile SparseSubvector<VT,AF1,TF>, AF2 >
2265 {
2266  typedef SparseSubvector<VT,AF2,TF> Type;
2267 };
2269 //*************************************************************************************************
2270 
2271 
2272 //*************************************************************************************************
2274 template< typename VT, bool AF1, bool TF, bool AF2 >
2275 struct SubvectorExprTrait< const volatile SparseSubvector<VT,AF1,TF>, AF2 >
2276 {
2277  typedef SparseSubvector<VT,AF2,TF> Type;
2278 };
2280 //*************************************************************************************************
2281 
2282 } // namespace blaze
2283 
2284 #endif
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
SparseSubvector< VT, AF, TF > This
Type of this SparseSubvector instance.
Definition: SparseSubvector.h:404
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
SelectType< IsExpression< VT >::value, VT, VT & >::Type Operand
Composite data type of the sparse vector expression.
Definition: SparseSubvector.h:388
size_t offset_
Offset within the according sparse vector.
Definition: SparseSubvector.h:547
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4599
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
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.
DifferenceType operator-(const SubvectorIterator &rhs) const
Calculating the number of elements between two subvector iterators.
Definition: SparseSubvector.h:681
ValueType PointerType
Pointer return type.
Definition: SparseSubvector.h:563
Header file for the SparseVector base class.
const size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:830
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubvector.h:408
IteratorType base() const
Access to the current position of the submatrix iterator.
Definition: SparseSubvector.h:691
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4642
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:199
bool operator==(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:658
#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
Iterator begin()
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:953
SubvectorElement< VectorType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubvector.h:562
ValueType value_type
Type of the underlying elements.
Definition: SparseSubvector.h:569
Header file for the IsRowVector type trait.
SparseSubvector(Operand vector, size_t index, size_t n)
The constructor for SparseSubvector.
Definition: SparseSubvector.h:888
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: SparseSubvector.h:412
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:690
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseSubvector.h:1631
#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.
bool operator!=(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Inequality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:670
size_t size() const
Returns the size/dimension of the sparse subvector.
Definition: SparseSubvector.h:1374
size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:709
SelectType< returnConst, const ElementType &, ElementType & >::Type ReferenceType
Return type of the value member function.
Definition: SparseSubvector.h:439
void reserve(size_t n)
Setting the minimum capacity of the sparse subvector.
Definition: SparseSubvector.h:1519
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubvector.h:568
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4615
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:409
PointerType operator->() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:646
SubvectorElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:496
SubvectorElement & operator/=(const T &v)
Division assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:508
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:122
Constraint on the data type.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubvector.h:406
SubvectorElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:484
Compile time check to query the requirement to evaluate an expression.Via this type trait it is possi...
Definition: RequiresEvaluation.h:90
ReferenceType operator*() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:636
SubvectorElement & operator+=(const T &v)
Addition assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:472
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1013
ReferenceType reference
Reference return type.
Definition: SparseSubvector.h:571
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
SelectType< useConst, ConstIterator, SubvectorIterator< VT, typename VT::Iterator > >::Type Iterator
Iterator over non-constant elements.
Definition: SparseSubvector.h:719
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubvector.h:561
SubvectorIterator< const VT, typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubvector.h:716
Header file for the multiplication trait.
void erase(size_t index)
Erasing an element from the sparse subvector.
Definition: SparseSubvector.h:1462
size_t capacity() const
Returns the maximum capacity of the sparse subvector.
Definition: SparseSubvector.h:1389
Header file for the If class template.
Header file for the Subvector base class.
Operand vector_
The sparse vector containing the subvector.
Definition: SparseSubvector.h:829
Header file for the IsFloatingPoint type trait.
bool canSMPAssign() const
Returns whether the subvector can be used in SMP assignments.
Definition: SparseSubvector.h:1815
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2412
SubvectorIterator & operator++()
Pre-increment operator.
Definition: SparseSubvector.h:613
Header file for the Or class template.
size_t nonZeros(const Matrix< MT, SO > &m)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:224
SubvectorIterator()
Default constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:578
void assign(const DenseVector< VT2, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseSubvector.h:1837
PointerType pointer
Pointer return type.
Definition: SparseSubvector.h:570
size_t index() const
Access to the current index of the sparse element.
Definition: SparseSubvector.h:539
Header file for the subvector trait.
const SubvectorElement * operator->() const
Direct access to the sparse subvector element at the current iterator position.
Definition: SparseSubvector.h:519
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:271
Access proxy for a specific element of the sparse subvector.
Definition: SparseSubvector.h:423
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse subvector.
Definition: SparseSubvector.h:1742
SubvectorIterator(IteratorType iterator, size_t index)
Constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:590
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#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
Constraint on the data type.
Header file for the SparseElement base class.
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:1959
Constraint on the data type.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubvector.h:565
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubvector.h:405
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
size_t offset() const
Access to the offset of the submatrix iterator.
Definition: SparseSubvector.h:701
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubvector.h:1677
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2406
Constraint on the data type.
Header file for the SelectType class template.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2410
Header file for the EnableIf class template.
VT::ElementType ElementType
Type of the subvector elements.
Definition: SparseSubvector.h:407
SubvectorElement & operator=(const T &v)
Assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:460
Header file for the serial shim.
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubvector.h:572
const bool unaligned
Alignment flag for unaligned subvectors and submatrices.
Definition: AlignmentFlag.h:63
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:917
SubvectorIterator(const SubvectorIterator< VectorType2, IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: SparseSubvector.h:602
ValueType ReferenceType
Reference return type.
Definition: SparseSubvector.h:564
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2407
Header file for the IsConst type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
Base template for the MultTrait class.
Definition: MultTrait.h:141
Header file for the addition trait.
Header file for the division trait.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:301
ReferenceType value() const
Access to the current value of the sparse subvector element.
Definition: SparseSubvector.h:529
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
const size_t size_
The size of the subvector.
Definition: SparseSubvector.h:831
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:135
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:331
bool canAlias(const Other *alias) const
Returns whether the sparse subvector can alias with the given address alias.
Definition: SparseSubvector.h:1774
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2411
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:1795
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
VT VectorType
Type of the vector.
Definition: Vector.h:73
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
Iterator find(size_t index)
Searches for a specific subvector element.
Definition: SparseSubvector.h:1574
Base template for the DivTrait class.
Definition: DivTrait.h:141
size_t nonZeros() const
Returns the number of non-zero elements in the subvector.
Definition: SparseSubvector.h:1406
#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
const SparseSubvector & CompositeType
Data type for composite expression templates.
Definition: SparseSubvector.h:409
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:993
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse subvector.
Definition: SparseSubvector.h:1444
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: SparseSubvector.h:624
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:151
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubvector.h:708
Iterator over the elements of the sparse subvector.
Definition: SparseSubvector.h:557
SubvectorElement(IteratorType pos, size_t offset)
Constructor for the SubvectorElement class.
Definition: SparseSubvector.h:448
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
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2403
Header file for basic type definitions.
void reset()
Reset to the default initial values.
Definition: SparseSubvector.h:1421
Header file for the SubvectorExprTrait class template.
SparseSubvector & operator=(const SparseSubvector &rhs)
Copy assignment operator for SparseSubvector.
Definition: SparseSubvector.h:1085
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1053
void addAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseSubvector.h:1895
Base template for the SubTrait class.
Definition: SubTrait.h:141
SelectType< useConst, ConstReference, typename VT::Reference >::Type Reference
Reference to a non-constant subvector value.
Definition: SparseSubvector.h:415
#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
#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
size_t capacity(const Matrix< MT, SO > &m)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:186
IteratorType pos_
Iterator to the current position within the sparse subvector.
Definition: SparseSubvector.h:546
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.