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 //*************************************************************************************************
384 template< typename VT // Type of the sparse vector
385  , bool AF = unaligned // Alignment flag
386  , bool TF = IsRowVector<VT>::value > // Transpose flag
387 class SparseSubvector : public SparseVector< SparseSubvector<VT,AF,TF>, TF >
388  , private Subvector
389 {
390  private:
391  //**Type definitions****************************************************************************
393  typedef typename SelectType< IsExpression<VT>::value, VT, VT& >::Type Operand;
394  //**********************************************************************************************
395 
396  //**********************************************************************************************
398 
404  enum { useConst = IsConst<VT>::value };
405  //**********************************************************************************************
406 
407  public:
408  //**Type definitions****************************************************************************
412  typedef typename VT::ElementType ElementType;
413  typedef typename VT::ReturnType ReturnType;
415 
418 
421  //**********************************************************************************************
422 
423  //**SubvectorElement class definition***********************************************************
426  template< typename VectorType // Type of the sparse vector
427  , typename IteratorType > // Type of the sparse vector iterator
429  {
430  private:
431  //*******************************************************************************************
433 
438  enum { returnConst = IsConst<VectorType>::value };
439  //*******************************************************************************************
440 
441  //**Type definitions*************************************************************************
443  typedef typename std::iterator_traits<IteratorType>::value_type SET;
444 
445  typedef typename SET::Reference RT;
446  typedef typename SET::ConstReference CRT;
447  //*******************************************************************************************
448 
449  public:
450  //**Type definitions*************************************************************************
451  typedef typename SET::ValueType ValueType;
452  typedef size_t IndexType;
454  typedef CRT ConstReference;
455  //*******************************************************************************************
456 
457  //**Constructor******************************************************************************
463  inline SubvectorElement( IteratorType pos, size_t offset )
464  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
465  , offset_( offset ) // Offset within the according sparse vector
466  {}
467  //*******************************************************************************************
468 
469  //**Assignment operator**********************************************************************
475  template< typename T > inline SubvectorElement& operator=( const T& v ) {
476  *pos_ = v;
477  return *this;
478  }
479  //*******************************************************************************************
480 
481  //**Addition assignment operator*************************************************************
487  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
488  *pos_ += v;
489  return *this;
490  }
491  //*******************************************************************************************
492 
493  //**Subtraction assignment operator**********************************************************
499  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
500  *pos_ -= v;
501  return *this;
502  }
503  //*******************************************************************************************
504 
505  //**Multiplication assignment operator*******************************************************
511  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
512  *pos_ *= v;
513  return *this;
514  }
515  //*******************************************************************************************
516 
517  //**Division assignment operator*************************************************************
523  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
524  *pos_ /= v;
525  return *this;
526  }
527  //*******************************************************************************************
528 
529  //**Element access operator******************************************************************
534  inline const SubvectorElement* operator->() const {
535  return this;
536  }
537  //*******************************************************************************************
538 
539  //**Value function***************************************************************************
544  inline Reference value() const {
545  return pos_->value();
546  }
547  //*******************************************************************************************
548 
549  //**Index function***************************************************************************
554  inline IndexType index() const {
555  return pos_->index() - offset_;
556  }
557  //*******************************************************************************************
558 
559  private:
560  //**Member variables*************************************************************************
561  IteratorType pos_;
562  size_t offset_;
563  //*******************************************************************************************
564  };
565  //**********************************************************************************************
566 
567  //**SubvectorIterator class definition**********************************************************
570  template< typename VectorType // Type of the sparse vector
571  , typename IteratorType > // Type of the sparse vector iterator
573  {
574  public:
575  //**Type definitions*************************************************************************
576  typedef std::forward_iterator_tag IteratorCategory;
581 
582  // STL iterator requirements
588  //*******************************************************************************************
589 
590  //**Default constructor**********************************************************************
594  : pos_ () // Iterator to the current sparse element
595  , offset_() // The offset of the subvector within the sparse vector
596  {}
597  //*******************************************************************************************
598 
599  //**Constructor******************************************************************************
605  inline SubvectorIterator( IteratorType iterator, size_t index )
606  : pos_ ( iterator ) // Iterator to the current sparse element
607  , offset_( index ) // The offset of the subvector within the sparse vector
608  {}
609  //*******************************************************************************************
610 
611  //**Constructor******************************************************************************
616  template< typename VectorType2, typename IteratorType2 >
618  : pos_ ( it.base() ) // Iterator to the current sparse element.
619  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
620  {}
621  //*******************************************************************************************
622 
623  //**Prefix increment operator****************************************************************
629  ++pos_;
630  return *this;
631  }
632  //*******************************************************************************************
633 
634  //**Postfix increment operator***************************************************************
639  inline const SubvectorIterator operator++( int ) {
640  const SubvectorIterator tmp( *this );
641  ++(*this);
642  return tmp;
643  }
644  //*******************************************************************************************
645 
646  //**Element access operator******************************************************************
651  inline ReferenceType operator*() const {
652  return ReferenceType( pos_, offset_ );
653  }
654  //*******************************************************************************************
655 
656  //**Element access operator******************************************************************
661  inline PointerType operator->() const {
662  return PointerType( pos_, offset_ );
663  }
664  //*******************************************************************************************
665 
666  //**Equality operator************************************************************************
672  template< typename VectorType2, typename IteratorType2 >
674  return base() == rhs.base();
675  }
676  //*******************************************************************************************
677 
678  //**Inequality operator**********************************************************************
684  template< typename VectorType2, typename IteratorType2 >
686  return !( *this == rhs );
687  }
688  //*******************************************************************************************
689 
690  //**Subtraction operator*********************************************************************
696  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
697  return pos_ - rhs.pos_;
698  }
699  //*******************************************************************************************
700 
701  //**Base function****************************************************************************
706  inline IteratorType base() const {
707  return pos_;
708  }
709  //*******************************************************************************************
710 
711  //**Offset function**************************************************************************
716  inline size_t offset() const {
717  return offset_;
718  }
719  //*******************************************************************************************
720 
721  private:
722  //**Member variables*************************************************************************
723  IteratorType pos_;
724  size_t offset_;
725  //*******************************************************************************************
726  };
727  //**********************************************************************************************
728 
729  //**Type definitions****************************************************************************
732 
735  //**********************************************************************************************
736 
737  //**Compilation flags***************************************************************************
739  enum { smpAssignable = VT::smpAssignable };
740  //**********************************************************************************************
741 
742  //**Constructors********************************************************************************
745  explicit inline SparseSubvector( Operand vector, size_t index, size_t n );
746  // No explicitly declared copy constructor.
748  //**********************************************************************************************
749 
750  //**Destructor**********************************************************************************
751  // No explicitly declared destructor.
752  //**********************************************************************************************
753 
754  //**Data access functions***********************************************************************
757  inline Reference operator[]( size_t index );
758  inline ConstReference operator[]( size_t index ) const;
759  inline Iterator begin ();
760  inline ConstIterator begin () const;
761  inline ConstIterator cbegin() const;
762  inline Iterator end ();
763  inline ConstIterator end () const;
764  inline ConstIterator cend () const;
766  //**********************************************************************************************
767 
768  //**Assignment operators************************************************************************
771  inline SparseSubvector& operator= ( const SparseSubvector& rhs );
772  template< typename VT2 > inline SparseSubvector& operator= ( const DenseVector<VT2,TF>& rhs );
773  template< typename VT2 > inline SparseSubvector& operator= ( const SparseVector<VT2,TF>& rhs );
774  template< typename VT2 > inline SparseSubvector& operator+=( const Vector<VT2,TF>& rhs );
775  template< typename VT2 > inline SparseSubvector& operator-=( const Vector<VT2,TF>& rhs );
776  template< typename VT2 > inline SparseSubvector& operator*=( const Vector<VT2,TF>& rhs );
777 
778  template< typename Other >
779  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
780  operator*=( Other rhs );
781 
782  template< typename Other >
783  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
784  operator/=( Other rhs );
786  //**********************************************************************************************
787 
788  //**Utility functions***************************************************************************
791  inline size_t size() const;
792  inline size_t capacity() const;
793  inline size_t nonZeros() const;
794  inline void reset();
795  inline Iterator set ( size_t index, const ElementType& value );
796  inline Iterator insert ( size_t index, const ElementType& value );
797  inline void erase ( size_t index );
798  inline Iterator erase ( Iterator pos );
799  inline Iterator erase ( Iterator first, Iterator last );
800  inline void reserve( size_t n );
801  template< typename Other > inline SparseSubvector& scale ( const Other& scalar );
803  //**********************************************************************************************
804 
805  //**Lookup functions****************************************************************************
808  inline Iterator find ( size_t index );
809  inline ConstIterator find ( size_t index ) const;
810  inline Iterator lowerBound( size_t index );
811  inline ConstIterator lowerBound( size_t index ) const;
812  inline Iterator upperBound( size_t index );
813  inline ConstIterator upperBound( size_t index ) const;
815  //**********************************************************************************************
816 
817  //**Low-level utility functions*****************************************************************
820  inline void append( size_t index, const ElementType& value, bool check=false );
822  //**********************************************************************************************
823 
824  //**Expression template evaluation functions****************************************************
827  template< typename Other > inline bool canAlias ( const Other* alias ) const;
828  template< typename Other > inline bool isAliased( const Other* alias ) const;
829 
830  inline bool canSMPAssign() const;
831 
832  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
833  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
834  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
835  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
836  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
837  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
839  //**********************************************************************************************
840 
841  private:
842  //**Member variables****************************************************************************
846  const size_t offset_;
847  const size_t size_;
848 
849  //**********************************************************************************************
850 
851  //**Friend declarations*************************************************************************
853  template< bool AF1, typename VT2, bool AF2, bool TF2 >
854  friend const SparseSubvector<VT2,AF1,TF2>
855  subvector( const SparseSubvector<VT2,AF2,TF2>& sv, size_t index, size_t size );
856 
857  template< typename VT2, bool AF2, bool TF2 >
858  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseVector<VT2,TF2>& b );
859 
860  template< typename VT2, bool AF2, bool TF2 >
861  friend bool isSame( const SparseVector<VT2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
862 
863  template< typename VT2, bool AF2, bool TF2 >
864  friend bool isSame( const SparseSubvector<VT2,AF2,TF2>& a, const SparseSubvector<VT2,AF2,TF2>& b );
866  //**********************************************************************************************
867 
868  //**Compile time checks*************************************************************************
876  //**********************************************************************************************
877 };
878 //*************************************************************************************************
879 
880 
881 
882 
883 //=================================================================================================
884 //
885 // CONSTRUCTOR
886 //
887 //=================================================================================================
888 
889 //*************************************************************************************************
901 template< typename VT // Type of the sparse vector
902  , bool AF // Alignment flag
903  , bool TF > // Transpose flag
904 inline SparseSubvector<VT,AF,TF>::SparseSubvector( Operand vector, size_t index, size_t n )
905  : vector_( vector ) // The sparse vector containing the subvector
906  , offset_( index ) // The offset of the subvector within the sparse vector
907  , size_ ( n ) // The size of the subvector
908 {
909  if( index + n > vector.size() )
910  throw std::invalid_argument( "Invalid subvector specification" );
911 }
912 //*************************************************************************************************
913 
914 
915 
916 
917 //=================================================================================================
918 //
919 // DATA ACCESS FUNCTIONS
920 //
921 //=================================================================================================
922 
923 //*************************************************************************************************
929 template< typename VT // Type of the sparse vector
930  , bool AF // Alignment flag
931  , bool TF > // Transpose flag
934 {
935  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
936  return vector_[offset_+index];
937 }
938 //*************************************************************************************************
939 
940 
941 //*************************************************************************************************
947 template< typename VT // Type of the sparse vector
948  , bool AF // Alignment flag
949  , bool TF > // Transpose flag
952 {
953  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
954  return const_cast<const VT&>( vector_ )[offset_+index];
955 }
956 //*************************************************************************************************
957 
958 
959 //*************************************************************************************************
966 template< typename VT // Type of the sparse vector
967  , bool AF // Alignment flag
968  , bool TF > // Transpose flag
970 {
971  if( offset_ == 0UL )
972  return Iterator( vector_.begin(), offset_ );
973  else
974  return Iterator( vector_.lowerBound( offset_ ), offset_ );
975 }
976 //*************************************************************************************************
977 
978 
979 //*************************************************************************************************
986 template< typename VT // Type of the sparse vector
987  , bool AF // Alignment flag
988  , bool TF > // Transpose flag
990 {
991  if( offset_ == 0UL )
992  return ConstIterator( vector_.cbegin(), offset_ );
993  else
994  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
995 }
996 //*************************************************************************************************
997 
998 
999 //*************************************************************************************************
1006 template< typename VT // Type of the sparse vector
1007  , bool AF // Alignment flag
1008  , bool TF > // Transpose flag
1010 {
1011  if( offset_ == 0UL )
1012  return ConstIterator( vector_.cbegin(), offset_ );
1013  else
1014  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
1015 }
1016 //*************************************************************************************************
1017 
1018 
1019 //*************************************************************************************************
1026 template< typename VT // Type of the sparse vector
1027  , bool AF // Alignment flag
1028  , bool TF > // Transpose flag
1030 {
1031  if( offset_ + size_ == vector_.size() )
1032  return Iterator( vector_.end(), offset_ );
1033  else
1034  return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1035 }
1036 //*************************************************************************************************
1037 
1038 
1039 //*************************************************************************************************
1046 template< typename VT // Type of the sparse vector
1047  , bool AF // Alignment flag
1048  , bool TF > // Transpose flag
1050 {
1051  if( offset_ + size_ == vector_.size() )
1052  return ConstIterator( vector_.cend(), offset_ );
1053  else
1054  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1055 }
1056 //*************************************************************************************************
1057 
1058 
1059 //*************************************************************************************************
1066 template< typename VT // Type of the sparse vector
1067  , bool AF // Alignment flag
1068  , bool TF > // Transpose flag
1070 {
1071  if( offset_ + size_ == vector_.size() )
1072  return ConstIterator( vector_.cend(), offset_ );
1073  else
1074  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1075 }
1076 //*************************************************************************************************
1077 
1078 
1079 
1080 
1081 //=================================================================================================
1082 //
1083 // ASSIGNMENT OPERATORS
1084 //
1085 //=================================================================================================
1086 
1087 //*************************************************************************************************
1097 template< typename VT // Type of the sparse vector
1098  , bool AF // Alignment flag
1099  , bool TF > // Transpose flag
1102 {
1103  using blaze::assign;
1104 
1107 
1108  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
1109  return *this;
1110 
1111  if( size() != rhs.size() )
1112  throw std::invalid_argument( "Vector sizes do not match" );
1113 
1114  if( rhs.canAlias( &vector_ ) ) {
1115  const ResultType tmp( rhs );
1116  reset();
1117  assign( *this, tmp );
1118  }
1119  else {
1120  reset();
1121  assign( *this, rhs );
1122  }
1123 
1124  return *this;
1125 }
1126 //*************************************************************************************************
1127 
1128 
1129 //*************************************************************************************************
1139 template< typename VT // Type of the sparse vector
1140  , bool AF // Alignment flag
1141  , bool TF > // Transpose flag
1142 template< typename VT2 > // Type of the right-hand side dense vector
1145 {
1146  using blaze::assign;
1147 
1151 
1152  if( size() != (~rhs).size() )
1153  throw std::invalid_argument( "Vector sizes do not match" );
1154 
1155  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1156  const typename VT2::ResultType tmp( ~rhs );
1157  reset();
1158  assign( *this, tmp );
1159  }
1160  else {
1161  reset();
1162  assign( *this, ~rhs );
1163  }
1164 
1165  return *this;
1166 }
1167 //*************************************************************************************************
1168 
1169 
1170 //*************************************************************************************************
1180 template< typename VT // Type of the sparse vector
1181  , bool AF // Alignment flag
1182  , bool TF > // Transpose flag
1183 template< typename VT2 > // Type of the right-hand side sparse vector
1186 {
1187  using blaze::assign;
1188 
1192 
1193  if( size() != (~rhs).size() )
1194  throw std::invalid_argument( "Vector sizes do not match" );
1195 
1196  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1197  const typename VT2::ResultType tmp( ~rhs );
1198  reset();
1199  assign( *this, tmp );
1200  }
1201  else {
1202  reset();
1203  assign( *this, ~rhs );
1204  }
1205 
1206  return *this;
1207 }
1208 //*************************************************************************************************
1209 
1210 
1211 //*************************************************************************************************
1221 template< typename VT // Type of the sparse vector
1222  , bool AF // Alignment flag
1223  , bool TF > // Transpose flag
1224 template< typename VT2 > // Type of the right-hand side vector
1227 {
1228  using blaze::addAssign;
1229 
1230  if( size() != (~rhs).size() )
1231  throw std::invalid_argument( "Vector sizes do not match" );
1232 
1233  addAssign( *this, ~rhs );
1234 
1235  return *this;
1236 }
1237 //*************************************************************************************************
1238 
1239 
1240 //*************************************************************************************************
1250 template< typename VT // Type of the sparse vector
1251  , bool AF // Alignment flag
1252  , bool TF > // Transpose flag
1253 template< typename VT2 > // Type of the right-hand side vector
1256 {
1257  using blaze::subAssign;
1258 
1259  if( size() != (~rhs).size() )
1260  throw std::invalid_argument( "Vector sizes do not match" );
1261 
1262  subAssign( *this, ~rhs );
1263 
1264  return *this;
1265 }
1266 //*************************************************************************************************
1267 
1268 
1269 //*************************************************************************************************
1280 template< typename VT // Type of the sparse vector
1281  , bool AF // Alignment flag
1282  , bool TF > // Transpose flag
1283 template< typename VT2 > // Type of the right-hand side vector
1286 {
1287  if( size() != (~rhs).size() )
1288  throw std::invalid_argument( "Vector sizes do not match" );
1289 
1290  typedef typename MultTrait<ResultType,typename VT2::ResultType>::Type MultType;
1291 
1295 
1296  const MultType tmp( *this * (~rhs) );
1297  reset();
1298  assign( tmp );
1299 
1300  return *this;
1301 }
1302 //*************************************************************************************************
1303 
1304 
1305 //*************************************************************************************************
1316 template< typename VT // Type of the sparse vector
1317  , bool AF // Alignment flag
1318  , bool TF > // Transpose flag
1319 template< typename Other > // Data type of the right-hand side scalar
1320 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1322 {
1323  const Iterator last( end() );
1324  for( Iterator element=begin(); element!=last; ++element )
1325  element->value() *= rhs;
1326  return *this;
1327 }
1328 //*************************************************************************************************
1329 
1330 
1331 //*************************************************************************************************
1343 template< typename VT // Type of the sparse vector
1344  , bool AF // Alignment flag
1345  , bool TF > // Transpose flag
1346 template< typename Other > // Data type of the right-hand side scalar
1347 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1349 {
1350  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1351 
1352  typedef typename DivTrait<ElementType,Other>::Type DT;
1353  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1354 
1355  const Iterator last( end() );
1356 
1357  // Depending on the two involved data types, an integer division is applied or a
1358  // floating point division is selected.
1360  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1361  for( Iterator element=begin(); element!=last; ++element )
1362  element->value() *= tmp;
1363  }
1364  else {
1365  for( Iterator element=begin(); element!=last; ++element )
1366  element->value() /= rhs;
1367  }
1368 
1369  return *this;
1370 }
1371 //*************************************************************************************************
1372 
1373 
1374 
1375 
1376 //=================================================================================================
1377 //
1378 // UTILITY FUNCTIONS
1379 //
1380 //=================================================================================================
1381 
1382 //*************************************************************************************************
1387 template< typename VT // Type of the sparse vector
1388  , bool AF // Alignment flag
1389  , bool TF > // Transpose flag
1390 inline size_t SparseSubvector<VT,AF,TF>::size() const
1391 {
1392  return size_;
1393 }
1394 //*************************************************************************************************
1395 
1396 
1397 //*************************************************************************************************
1402 template< typename VT // Type of the sparse vector
1403  , bool AF // Alignment flag
1404  , bool TF > // Transpose flag
1406 {
1407  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1408 }
1409 //*************************************************************************************************
1410 
1411 
1412 //*************************************************************************************************
1419 template< typename VT // Type of the sparse vector
1420  , bool AF // Alignment flag
1421  , bool TF > // Transpose flag
1423 {
1424  return end() - begin();
1425 }
1426 //*************************************************************************************************
1427 
1428 
1429 //*************************************************************************************************
1434 template< typename VT // Type of the sparse vector
1435  , bool AF // Alignment flag
1436  , bool TF > // Transpose flag
1438 {
1439  vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1440 }
1441 //*************************************************************************************************
1442 
1443 
1444 //*************************************************************************************************
1455 template< typename VT // Type of the sparse vector
1456  , bool AF // Alignment flag
1457  , bool TF > // Transpose flag
1459  SparseSubvector<VT,AF,TF>::set( size_t index, const ElementType& value )
1460 {
1461  return Iterator( vector_.set( offset_ + index, value ), offset_ );
1462 }
1463 //*************************************************************************************************
1464 
1465 
1466 //*************************************************************************************************
1478 template< typename VT // Type of the sparse vector
1479  , bool AF // Alignment flag
1480  , bool TF > // Transpose flag
1482  SparseSubvector<VT,AF,TF>::insert( size_t index, const ElementType& value )
1483 {
1484  return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1485 }
1486 //*************************************************************************************************
1487 
1488 
1489 //*************************************************************************************************
1497 template< typename VT // Type of the sparse vector
1498  , bool AF // Alignment flag
1499  , bool TF > // Transpose flag
1500 inline void SparseSubvector<VT,AF,TF>::erase( size_t index )
1501 {
1502  vector_.erase( offset_ + index );
1503 }
1504 //*************************************************************************************************
1505 
1506 
1507 //*************************************************************************************************
1515 template< typename VT // Type of the sparse vector
1516  , bool AF // Alignment flag
1517  , bool TF > // Transpose flag
1519 {
1520  return Iterator( vector_.erase( pos.base() ), offset_ );
1521 }
1522 //*************************************************************************************************
1523 
1524 
1525 //*************************************************************************************************
1534 template< typename VT // Type of the sparse vector
1535  , bool AF // Alignment flag
1536  , bool TF > // Transpose flag
1539 {
1540  return Iterator( vector_.erase( first.base(), last.base() ), offset_ );
1541 }
1542 //*************************************************************************************************
1543 
1544 
1545 //*************************************************************************************************
1554 template< typename VT // Type of the sparse vector
1555  , bool AF // Alignment flag
1556  , bool TF > // Transpose flag
1558 {
1559  const size_t current( capacity() );
1560 
1561  if( n > current ) {
1562  vector_.reserve( vector_.capacity() + n - current );
1563  }
1564 }
1565 //*************************************************************************************************
1566 
1567 
1568 //*************************************************************************************************
1574 template< typename VT // Type of the sparse vector
1575  , bool AF // Alignment flag
1576  , bool TF > // Transpose flag
1577 template< typename Other > // Data type of the scalar value
1579 {
1580  for( Iterator element=begin(); element!=end(); ++element )
1581  element->value() *= scalar;
1582  return *this;
1583 }
1584 //*************************************************************************************************
1585 
1586 
1587 
1588 
1589 //=================================================================================================
1590 //
1591 // LOOKUP FUNCTIONS
1592 //
1593 //=================================================================================================
1594 
1595 //*************************************************************************************************
1608 template< typename VT // Type of the sparse vector
1609  , bool AF // Alignment flag
1610  , bool TF > // Transpose flag
1613 {
1614  const typename VT::Iterator pos( vector_.find( offset_ + index ) );
1615 
1616  if( pos != vector_.end() )
1617  return Iterator( pos, offset_ );
1618  else
1619  return end();
1620 }
1621 //*************************************************************************************************
1622 
1623 
1624 //*************************************************************************************************
1637 template< typename VT // Type of the sparse vector
1638  , bool AF // Alignment flag
1639  , bool TF > // Transpose flag
1641  SparseSubvector<VT,AF,TF>::find( size_t index ) const
1642 {
1643  const typename VT::ConstIterator pos( vector_.find( offset_ + index ) );
1644 
1645  if( pos != vector_.end() )
1646  return Iterator( pos, offset_ );
1647  else
1648  return end();
1649 }
1650 //*************************************************************************************************
1651 
1652 
1653 //*************************************************************************************************
1665 template< typename VT // Type of the sparse vector
1666  , bool AF // Alignment flag
1667  , bool TF > // Transpose flag
1670 {
1671  return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1672 }
1673 //*************************************************************************************************
1674 
1675 
1676 //*************************************************************************************************
1688 template< typename VT // Type of the sparse vector
1689  , bool AF // Alignment flag
1690  , bool TF > // Transpose flag
1693 {
1694  return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1695 }
1696 //*************************************************************************************************
1697 
1698 
1699 //*************************************************************************************************
1711 template< typename VT // Type of the sparse vector
1712  , bool AF // Alignment flag
1713  , bool TF > // Transpose flag
1716 {
1717  return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1718 }
1719 //*************************************************************************************************
1720 
1721 
1722 //*************************************************************************************************
1734 template< typename VT // Type of the sparse vector
1735  , bool AF // Alignment flag
1736  , bool TF > // Transpose flag
1739 {
1740  return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1741 }
1742 //*************************************************************************************************
1743 
1744 
1745 
1746 
1747 //=================================================================================================
1748 //
1749 // LOW-LEVEL UTILITY FUNCTIONS
1750 //
1751 //=================================================================================================
1752 
1753 //*************************************************************************************************
1777 template< typename VT // Type of the sparse vector
1778  , bool AF // Alignment flag
1779  , bool TF > // Transpose flag
1780 inline void SparseSubvector<VT,AF,TF>::append( size_t index, const ElementType& value, bool check )
1781 {
1782  if( offset_ + size_ == vector_.size() )
1783  vector_.append( offset_ + index, value, check );
1784  else if( !check || !isDefault( value ) )
1785  vector_.insert( offset_ + index, value );
1786 }
1787 //*************************************************************************************************
1788 
1789 
1790 
1791 
1792 //=================================================================================================
1793 //
1794 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1795 //
1796 //=================================================================================================
1797 
1798 //*************************************************************************************************
1808 template< typename VT // Type of the sparse vector
1809  , bool AF // Alignment flag
1810  , bool TF > // Transpose flag
1811 template< typename Other > // Data type of the foreign expression
1812 inline bool SparseSubvector<VT,AF,TF>::canAlias( const Other* alias ) const
1813 {
1814  return vector_.isAliased( alias );
1815 }
1816 //*************************************************************************************************
1817 
1818 
1819 //*************************************************************************************************
1829 template< typename VT // Type of the sparse vector
1830  , bool AF // Alignment flag
1831  , bool TF > // Transpose flag
1832 template< typename Other > // Data type of the foreign expression
1833 inline bool SparseSubvector<VT,AF,TF>::isAliased( const Other* alias ) const
1834 {
1835  return vector_.isAliased( alias );
1836 }
1837 //*************************************************************************************************
1838 
1839 
1840 //*************************************************************************************************
1850 template< typename VT // Type of the sparse vector
1851  , bool AF // Alignment flag
1852  , bool TF > // Transpose flag
1854 {
1855  return false;
1856 }
1857 //*************************************************************************************************
1858 
1859 
1860 //*************************************************************************************************
1871 template< typename VT // Type of the sparse vector
1872  , bool AF // Alignment flag
1873  , bool TF > // Transpose flag
1874 template< typename VT2 > // Type of the right-hand side dense vector
1876 {
1877  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1878  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1879 
1880  reserve( (~rhs).size() );
1881 
1882  for( size_t i=0UL; i<size(); ++i ) {
1883  append( i, (~rhs)[i], true );
1884  }
1885 }
1886 //*************************************************************************************************
1887 
1888 
1889 //*************************************************************************************************
1900 template< typename VT // Type of the sparse vector
1901  , bool AF // Alignment flag
1902  , bool TF > // Transpose flag
1903 template< typename VT2 > // Type of the right-hand side sparse vector
1905 {
1906  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1907  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1908 
1909  reserve( (~rhs).nonZeros() );
1910 
1911  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1912  append( element->index(), element->value(), true );
1913  }
1914 }
1915 //*************************************************************************************************
1916 
1917 
1918 //*************************************************************************************************
1929 template< typename VT // Type of the sparse vector
1930  , bool AF // Alignment flag
1931  , bool TF > // Transpose flag
1932 template< typename VT2 > // Type of the right-hand side dense vector
1934 {
1935  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1936 
1940 
1941  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1942 
1943  const AddType tmp( serial( *this + (~rhs) ) );
1944  reset();
1945  assign( tmp );
1946 }
1947 //*************************************************************************************************
1948 
1949 
1950 //*************************************************************************************************
1961 template< typename VT // Type of the sparse vector
1962  , bool AF // Alignment flag
1963  , bool TF > // Transpose flag
1964 template< typename VT2 > // Type of the right-hand side sparse vector
1966 {
1967  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1968 
1972 
1973  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1974 
1975  const AddType tmp( serial( *this + (~rhs) ) );
1976  reset();
1977  assign( tmp );
1978 }
1979 //*************************************************************************************************
1980 
1981 
1982 //*************************************************************************************************
1993 template< typename VT // Type of the sparse vector
1994  , bool AF // Alignment flag
1995  , bool TF > // Transpose flag
1996 template< typename VT2 > // Type of the right-hand side dense vector
1998 {
1999  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
2000 
2004 
2005  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2006 
2007  const SubType tmp( serial( *this - (~rhs) ) );
2008  reset();
2009  assign( tmp );
2010 }
2011 //*************************************************************************************************
2012 
2013 
2014 //*************************************************************************************************
2025 template< typename VT // Type of the sparse vector
2026  , bool AF // Alignment flag
2027  , bool TF > // Transpose flag
2028 template< typename VT2 > // Type of the right-hand side sparse vector
2030 {
2031  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
2032 
2036 
2037  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2038 
2039  const SubType tmp( serial( *this - (~rhs) ) );
2040  reset();
2041  assign( tmp );
2042 }
2043 //*************************************************************************************************
2044 
2045 
2046 
2047 
2048 
2049 
2050 
2051 
2052 //=================================================================================================
2053 //
2054 // SPARSESUBVECTOR OPERATORS
2055 //
2056 //=================================================================================================
2057 
2058 //*************************************************************************************************
2061 template< typename VT, bool AF, bool TF >
2062 inline void reset( SparseSubvector<VT,AF,TF>& sv );
2063 
2064 template< typename VT, bool AF, bool TF >
2065 inline void clear( SparseSubvector<VT,AF,TF>& sv );
2066 
2067 template< typename VT, bool AF, bool TF >
2068 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv );
2069 
2070 template< typename VT, bool AF, bool TF >
2071 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b );
2072 
2073 template< typename VT, bool AF, bool TF >
2074 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2075 
2076 template< typename VT, bool AF, bool TF >
2077 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseSubvector<VT,AF,TF>& b );
2079 //*************************************************************************************************
2080 
2081 
2082 //*************************************************************************************************
2089 template< typename VT // Type of the sparse vector
2090  , bool AF // Alignment flag
2091  , bool TF > // Transpose flag
2093 {
2094  sv.reset();
2095 }
2096 //*************************************************************************************************
2097 
2098 
2099 //*************************************************************************************************
2108 template< typename VT // Type of the sparse vector
2109  , bool AF // Alignment flag
2110  , bool TF > // Transpose flag
2112 {
2113  sv.reset();
2114 }
2115 //*************************************************************************************************
2116 
2117 
2118 //*************************************************************************************************
2136 template< typename VT // Type of the sparse vector
2137  , bool AF // Alignment flag
2138  , bool TF > // Transpose flag
2139 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv )
2140 {
2142 
2143  const ConstIterator end( sv.end() );
2144  for( ConstIterator element=sv.begin(); element!=end; ++element )
2145  if( !isDefault( element->value() ) ) return false;
2146  return true;
2147 }
2148 //*************************************************************************************************
2149 
2150 
2151 //*************************************************************************************************
2163 template< typename VT, bool AF, bool TF >
2164 inline bool isSame( const SparseSubvector<VT,AF,TF>& a, const SparseVector<VT,TF>& b )
2165 {
2166  return ( isSame( a.vector_, ~b ) && ( a.size() == (~b).size() ) );
2167 }
2168 //*************************************************************************************************
2169 
2170 
2171 //*************************************************************************************************
2183 template< typename VT, bool AF, bool TF >
2184 inline bool isSame( const SparseVector<VT,TF>& a, const SparseSubvector<VT,AF,TF>& b )
2185 {
2186  return ( isSame( ~a, b.vector_ ) && ( (~a).size() == b.size() ) );
2187 }
2188 //*************************************************************************************************
2189 
2190 
2191 //*************************************************************************************************
2203 template< typename VT, bool AF, bool TF >
2205 {
2206  return ( isSame( a.vector_, b.vector_ ) && ( a.offset_ == b.offset_ ) && ( a.size_ == b.size_ ) );
2207 }
2208 //*************************************************************************************************
2209 
2210 
2211 
2212 
2213 //=================================================================================================
2214 //
2215 // GLOBAL RESTRUCTURING OPERATORS
2216 //
2217 //=================================================================================================
2218 
2219 //*************************************************************************************************
2232 template< bool AF1 // Required alignment flag
2233  , typename VT // Type of the sparse vector
2234  , bool AF2 // Present alignment flag
2235  , bool TF > // Transpose flag
2236 inline const SparseSubvector<VT,AF1,TF>
2237  subvector( const SparseSubvector<VT,AF2,TF>& sv, size_t index, size_t size )
2238 {
2240 
2241  if( index + size > sv.size() )
2242  throw std::invalid_argument( "Invalid subvector specification" );
2243 
2244  return SparseSubvector<VT,AF1,TF>( sv.vector_, sv.offset_ + index, size );
2245 }
2247 //*************************************************************************************************
2248 
2249 
2250 
2251 
2252 //=================================================================================================
2253 //
2254 // SUBVECTORTRAIT SPECIALIZATIONS
2255 //
2256 //=================================================================================================
2257 
2258 //*************************************************************************************************
2260 template< typename VT, bool AF, bool TF >
2261 struct SubvectorTrait< SparseSubvector<VT,AF,TF> >
2262 {
2264 };
2266 //*************************************************************************************************
2267 
2268 
2269 
2270 
2271 //=================================================================================================
2272 //
2273 // SUBVECTOREXPRTRAIT SPECIALIZATIONS
2274 //
2275 //=================================================================================================
2276 
2277 //*************************************************************************************************
2279 template< typename VT, bool AF1, bool TF, bool AF2 >
2280 struct SubvectorExprTrait< SparseSubvector<VT,AF1,TF>, AF2 >
2281 {
2282  typedef SparseSubvector<VT,AF2,TF> Type;
2283 };
2285 //*************************************************************************************************
2286 
2287 
2288 //*************************************************************************************************
2290 template< typename VT, bool AF1, bool TF, bool AF2 >
2291 struct SubvectorExprTrait< const SparseSubvector<VT,AF1,TF>, AF2 >
2292 {
2293  typedef SparseSubvector<VT,AF2,TF> Type;
2294 };
2296 //*************************************************************************************************
2297 
2298 
2299 //*************************************************************************************************
2301 template< typename VT, bool AF1, bool TF, bool AF2 >
2302 struct SubvectorExprTrait< volatile SparseSubvector<VT,AF1,TF>, AF2 >
2303 {
2304  typedef SparseSubvector<VT,AF2,TF> Type;
2305 };
2307 //*************************************************************************************************
2308 
2309 
2310 //*************************************************************************************************
2312 template< typename VT, bool AF1, bool TF, bool AF2 >
2313 struct SubvectorExprTrait< const volatile SparseSubvector<VT,AF1,TF>, AF2 >
2314 {
2315  typedef SparseSubvector<VT,AF2,TF> Type;
2316 };
2318 //*************************************************************************************************
2319 
2320 } // namespace blaze
2321 
2322 #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:409
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:393
size_t offset_
Offset within the according sparse vector.
Definition: SparseSubvector.h:562
#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:696
ValueType PointerType
Pointer return type.
Definition: SparseSubvector.h:578
Header file for the SparseVector base class.
const size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:846
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
std::iterator_traits< IteratorType >::value_type SET
Type of the underlying sparse elements.
Definition: SparseSubvector.h:443
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubvector.h:413
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
IteratorType base() const
Access to the current position of the subvector iterator.
Definition: SparseSubvector.h:706
Reference value() const
Access to the current value of the sparse subvector element.
Definition: SparseSubvector.h:544
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
bool operator==(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:673
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:946
Iterator begin()
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:969
SubvectorElement< VectorType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubvector.h:577
ValueType value_type
Type of the underlying elements.
Definition: SparseSubvector.h:584
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:904
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: SparseSubvector.h:417
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
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
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:95
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseSubvector.h:1669
#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:685
size_t size() const
Returns the size/dimension of the sparse subvector.
Definition: SparseSubvector.h:1390
size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:724
void reserve(size_t n)
Setting the minimum capacity of the sparse subvector.
Definition: SparseSubvector.h:1557
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubvector.h:583
PointerType operator->() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:661
SubvectorElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:511
SubvectorElement & operator/=(const T &v)
Division assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:523
Base template for the SubvectorTrait class.
Definition: SubvectorTrait.h:123
Constraint on the data type.
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseSubvector.h:411
SubvectorElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:499
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:651
SubvectorElement & operator+=(const T &v)
Addition assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:487
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1029
ReferenceType reference
Reference return type.
Definition: SparseSubvector.h:586
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:734
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubvector.h:576
SubvectorIterator< const VT, typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubvector.h:731
Header file for the multiplication trait.
void erase(size_t index)
Erasing an element from the sparse subvector.
Definition: SparseSubvector.h:1500
size_t capacity() const
Returns the maximum capacity of the sparse subvector.
Definition: SparseSubvector.h:1405
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:845
Header file for the IsFloatingPoint type trait.
bool canSMPAssign() const
Returns whether the subvector can be used in SMP assignments.
Definition: SparseSubvector.h:1853
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
SubvectorIterator & operator++()
Pre-increment operator.
Definition: SparseSubvector.h:628
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
SubvectorIterator()
Default constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:593
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
void assign(const DenseVector< VT2, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseSubvector.h:1875
PointerType pointer
Pointer return type.
Definition: SparseSubvector.h:585
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:534
Access proxy for a specific element of the sparse subvector.
Definition: SparseSubvector.h:428
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse subvector.
Definition: SparseSubvector.h:1780
SubvectorIterator(IteratorType iterator, size_t index)
Constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:605
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
SET::ConstReference CRT
Reference-to-const type of the underlying sparse element.
Definition: SparseSubvector.h:446
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:1997
Constraint on the data type.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubvector.h:580
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubvector.h:410
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
size_t offset() const
Access to the offset of the subvector iterator.
Definition: SparseSubvector.h:716
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubvector.h:1715
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
IndexType index() const
Access to the current index of the sparse element.
Definition: SparseSubvector.h:554
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:2480
CRT ConstReference
Reference-to-const return type.
Definition: SparseSubvector.h:454
Header file for the EnableIf class template.
VT::ElementType ElementType
Type of the subvector elements.
Definition: SparseSubvector.h:412
SubvectorElement & operator=(const T &v)
Assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:475
Header file for the serial shim.
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubvector.h:587
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:933
SubvectorIterator(const SubvectorIterator< VectorType2, IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: SparseSubvector.h:617
ValueType ReferenceType
Reference return type.
Definition: SparseSubvector.h:579
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Header file for the IsConst type trait.
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:142
Base template for the MultTrait class.
Definition: MultTrait.h:142
Header file for the addition trait.
SET::ValueType ValueType
The value type of the row element.
Definition: SparseSubvector.h:451
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
const size_t size_
The size of the subvector.
Definition: SparseSubvector.h:847
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
bool canAlias(const Other *alias) const
Returns whether the sparse subvector can alias with the given address alias.
Definition: SparseSubvector.h:1812
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the isDefault shim.
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
bool isAliased(const Other *alias) const
Returns whether the sparse subvector is aliased with the given address alias.
Definition: SparseSubvector.h:1833
size_t IndexType
The index type of the row element.
Definition: SparseSubvector.h:452
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse subvector.
Definition: SparseSubvector.h:1459
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
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:80
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:1612
Base template for the DivTrait class.
Definition: DivTrait.h:142
size_t nonZeros() const
Returns the number of non-zero elements in the subvector.
Definition: SparseSubvector.h:1422
#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:414
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:1009
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse subvector.
Definition: SparseSubvector.h:1482
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: SparseSubvector.h:639
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:723
Iterator over the elements of the sparse subvector.
Definition: SparseSubvector.h:572
SubvectorElement(IteratorType pos, size_t offset)
Constructor for the SubvectorElement class.
Definition: SparseSubvector.h:463
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:2473
Header file for basic type definitions.
void reset()
Reset to the default initial values.
Definition: SparseSubvector.h:1437
Header file for the SubvectorExprTrait class template.
SparseSubvector & operator=(const SparseSubvector &rhs)
Copy assignment operator for SparseSubvector.
Definition: SparseSubvector.h:1101
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1069
void addAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseSubvector.h:1933
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Base template for the SubTrait class.
Definition: SubTrait.h:142
SelectType< useConst, ConstReference, typename VT::Reference >::Type Reference
Reference to a non-constant subvector value.
Definition: SparseSubvector.h:420
SelectType< returnConst, CRT, RT >::Type Reference
Reference return type.
Definition: SparseSubvector.h:453
Size type of the Blaze library.
#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
IteratorType pos_
Iterator to the current position within the sparse subvector.
Definition: SparseSubvector.h:561
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
SET::Reference RT
Reference type of the underlying sparse element.
Definition: SparseSubvector.h:445