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>
66 #include <blaze/util/Assert.h>
67 #include <blaze/util/EnableIf.h>
69 #include <blaze/util/mpl/If.h>
70 #include <blaze/util/mpl/Or.h>
71 #include <blaze/util/SelectType.h>
72 #include <blaze/util/Types.h>
76 
77 
78 namespace blaze {
79 
80 //=================================================================================================
81 //
82 // CLASS DEFINITION
83 //
84 //=================================================================================================
85 
86 //*************************************************************************************************
378 template< typename VT // Type of the sparse vector
379  , bool AF = unaligned // Alignment flag
380  , bool TF = IsRowVector<VT>::value > // Transpose flag
381 class SparseSubvector : public SparseVector< SparseSubvector<VT,AF,TF>, TF >
382  , private Subvector
383 {
384  private:
385  //**Type definitions****************************************************************************
387  typedef typename SelectType< IsExpression<VT>::value, VT, VT& >::Type Operand;
388  //**********************************************************************************************
389 
390  //**********************************************************************************************
392 
398  enum { useConst = IsConst<VT>::value };
399  //**********************************************************************************************
400 
401  public:
402  //**Type definitions****************************************************************************
406  typedef typename VT::ElementType ElementType;
407  typedef typename VT::ReturnType ReturnType;
409 
412 
415  //**********************************************************************************************
416 
417  //**SubvectorElement class definition***********************************************************
420  template< typename VectorType // Type of the sparse vector
421  , typename IteratorType > // Type of the sparse vector iterator
423  {
424  private:
425  //*******************************************************************************************
427 
432  enum { returnConst = IsConst<VectorType>::value };
433  //*******************************************************************************************
434 
435  public:
436  //**Type definitions*************************************************************************
439  //*******************************************************************************************
440 
441  //**Constructor******************************************************************************
447  inline SubvectorElement( IteratorType pos, size_t offset )
448  : pos_ ( pos ) // Iterator to the current position within the sparse subvector
449  , offset_( offset ) // Offset within the according sparse vector
450  {}
451  //*******************************************************************************************
452 
453  //**Assignment operator**********************************************************************
459  template< typename T > inline SubvectorElement& operator=( const T& v ) {
460  *pos_ = v;
461  return *this;
462  }
463  //*******************************************************************************************
464 
465  //**Addition assignment operator*************************************************************
471  template< typename T > inline SubvectorElement& operator+=( const T& v ) {
472  *pos_ += v;
473  return *this;
474  }
475  //*******************************************************************************************
476 
477  //**Subtraction assignment operator**********************************************************
483  template< typename T > inline SubvectorElement& operator-=( const T& v ) {
484  *pos_ -= v;
485  return *this;
486  }
487  //*******************************************************************************************
488 
489  //**Multiplication assignment operator*******************************************************
495  template< typename T > inline SubvectorElement& operator*=( const T& v ) {
496  *pos_ *= v;
497  return *this;
498  }
499  //*******************************************************************************************
500 
501  //**Division assignment operator*************************************************************
507  template< typename T > inline SubvectorElement& operator/=( const T& v ) {
508  *pos_ /= v;
509  return *this;
510  }
511  //*******************************************************************************************
512 
513  //**Element access operator******************************************************************
518  inline const SubvectorElement* operator->() const {
519  return this;
520  }
521  //*******************************************************************************************
522 
523  //**Value function***************************************************************************
528  inline ReferenceType value() const {
529  return pos_->value();
530  }
531  //*******************************************************************************************
532 
533  //**Index function***************************************************************************
538  inline size_t index() const {
539  return pos_->index() - offset_;
540  }
541  //*******************************************************************************************
542 
543  private:
544  //**Member variables*************************************************************************
545  IteratorType pos_;
546  size_t offset_;
547  //*******************************************************************************************
548  };
549  //**********************************************************************************************
550 
551  //**SubvectorIterator class definition**********************************************************
554  template< typename VectorType // Type of the sparse vector
555  , typename IteratorType > // Type of the sparse vector iterator
557  {
558  public:
559  //**Type definitions*************************************************************************
560  typedef std::forward_iterator_tag IteratorCategory;
565 
566  // STL iterator requirements
572  //*******************************************************************************************
573 
574  //**Default constructor**********************************************************************
578  : pos_ () // Iterator to the current sparse element
579  , offset_() // The offset of the subvector within the sparse vector
580  {}
581  //*******************************************************************************************
582 
583  //**Constructor******************************************************************************
589  inline SubvectorIterator( IteratorType iterator, size_t index )
590  : pos_ ( iterator ) // Iterator to the current sparse element
591  , offset_( index ) // The offset of the subvector within the sparse vector
592  {}
593  //*******************************************************************************************
594 
595  //**Constructor******************************************************************************
600  template< typename VectorType2, typename IteratorType2 >
602  : pos_ ( it.base() ) // Iterator to the current sparse element.
603  , offset_( it.offset() ) // The offset of the subvector within the sparse vector
604  {}
605  //*******************************************************************************************
606 
607  //**Prefix increment operator****************************************************************
613  ++pos_;
614  return *this;
615  }
616  //*******************************************************************************************
617 
618  //**Postfix increment operator***************************************************************
623  inline const SubvectorIterator operator++( int ) {
624  const SubvectorIterator tmp( *this );
625  ++(*this);
626  return tmp;
627  }
628  //*******************************************************************************************
629 
630  //**Element access operator******************************************************************
635  inline ReferenceType operator*() const {
636  return ReferenceType( pos_, offset_ );
637  }
638  //*******************************************************************************************
639 
640  //**Element access operator******************************************************************
645  inline PointerType operator->() const {
646  return PointerType( pos_, offset_ );
647  }
648  //*******************************************************************************************
649 
650  //**Equality operator************************************************************************
656  template< typename VectorType2, typename IteratorType2 >
658  return base() == rhs.base();
659  }
660  //*******************************************************************************************
661 
662  //**Inequality operator**********************************************************************
668  template< typename VectorType2, typename IteratorType2 >
670  return !( *this == rhs );
671  }
672  //*******************************************************************************************
673 
674  //**Subtraction operator*********************************************************************
680  inline DifferenceType operator-( const SubvectorIterator& rhs ) const {
681  return pos_ - rhs.pos_;
682  }
683  //*******************************************************************************************
684 
685  //**Base function****************************************************************************
690  inline IteratorType base() const {
691  return pos_;
692  }
693  //*******************************************************************************************
694 
695  //**Offset function**************************************************************************
700  inline size_t offset() const {
701  return offset_;
702  }
703  //*******************************************************************************************
704 
705  private:
706  //**Member variables*************************************************************************
707  IteratorType pos_;
708  size_t offset_;
709  //*******************************************************************************************
710  };
711  //**********************************************************************************************
712 
713  //**Type definitions****************************************************************************
716 
719  //**********************************************************************************************
720 
721  //**Compilation flags***************************************************************************
723  enum { smpAssignable = 0 };
724  //**********************************************************************************************
725 
726  //**Constructors********************************************************************************
729  explicit inline SparseSubvector( Operand vector, size_t index, size_t n );
730  // No explicitly declared copy constructor.
732  //**********************************************************************************************
733 
734  //**Destructor**********************************************************************************
735  // No explicitly declared destructor.
736  //**********************************************************************************************
737 
738  //**Data access functions***********************************************************************
741  inline Reference operator[]( size_t index );
742  inline ConstReference operator[]( size_t index ) const;
743  inline Iterator begin ();
744  inline ConstIterator begin () const;
745  inline ConstIterator cbegin() const;
746  inline Iterator end ();
747  inline ConstIterator end () const;
748  inline ConstIterator cend () const;
750  //**********************************************************************************************
751 
752  //**Assignment operators************************************************************************
755  inline SparseSubvector& operator= ( const SparseSubvector& rhs );
756  template< typename VT2 > inline SparseSubvector& operator= ( const DenseVector<VT2,TF>& rhs );
757  template< typename VT2 > inline SparseSubvector& operator= ( const SparseVector<VT2,TF>& rhs );
758  template< typename VT2 > inline SparseSubvector& operator+=( const Vector<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 
762  template< typename Other >
763  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
764  operator*=( Other rhs );
765 
766  template< typename Other >
767  inline typename EnableIf< IsNumeric<Other>, SparseSubvector >::Type&
768  operator/=( Other rhs );
770  //**********************************************************************************************
771 
772  //**Utility functions***************************************************************************
775  inline size_t size() const;
776  inline size_t capacity() const;
777  inline size_t nonZeros() const;
778  inline void reset();
779  inline Iterator insert ( size_t index, const ElementType& value );
780  inline void erase ( size_t index );
781  inline Iterator erase ( Iterator pos );
782  inline Iterator erase ( Iterator first, Iterator last );
783  inline void reserve( size_t n );
784  template< typename Other > inline SparseSubvector& scale ( Other scalar );
786  //**********************************************************************************************
787 
788  //**Lookup functions****************************************************************************
791  inline Iterator find ( size_t index );
792  inline ConstIterator find ( size_t index ) const;
793  inline Iterator lowerBound( size_t index );
794  inline ConstIterator lowerBound( size_t index ) const;
795  inline Iterator upperBound( size_t index );
796  inline ConstIterator upperBound( size_t index ) const;
798  //**********************************************************************************************
799 
800  //**Low-level utility functions*****************************************************************
803  inline void append( size_t index, const ElementType& value, bool check=false );
805  //**********************************************************************************************
806 
807  //**Expression template evaluation functions****************************************************
810  template< typename Other > inline bool canAlias ( const Other* alias ) const;
811  template< typename Other > inline bool isAliased( const Other* alias ) const;
812  template< typename VT2 > inline void assign ( const DenseVector <VT2,TF>& rhs );
813  template< typename VT2 > inline void assign ( const SparseVector<VT2,TF>& rhs );
814  template< typename VT2 > inline void addAssign( const DenseVector <VT2,TF>& rhs );
815  template< typename VT2 > inline void addAssign( const SparseVector<VT2,TF>& rhs );
816  template< typename VT2 > inline void subAssign( const DenseVector <VT2,TF>& rhs );
817  template< typename VT2 > inline void subAssign( const SparseVector<VT2,TF>& rhs );
819  //**********************************************************************************************
820 
821  private:
822  //**Member variables****************************************************************************
826  const size_t offset_;
827  const size_t size_;
828 
829  //**********************************************************************************************
830 
831  //**Friend declarations*************************************************************************
833  template< bool AF1, typename VT2, bool AF2, bool TF2 >
834  friend const SparseSubvector<VT2,AF1,TF2>
835  subvector( const SparseSubvector<VT2,AF2,TF2>& sv, size_t index, size_t size );
837  //**********************************************************************************************
838 
839  //**Compile time checks*************************************************************************
847  //**********************************************************************************************
848 };
849 //*************************************************************************************************
850 
851 
852 
853 
854 //=================================================================================================
855 //
856 // CONSTRUCTOR
857 //
858 //=================================================================================================
859 
860 //*************************************************************************************************
872 template< typename VT // Type of the sparse vector
873  , bool AF // Alignment flag
874  , bool TF > // Transpose flag
875 inline SparseSubvector<VT,AF,TF>::SparseSubvector( Operand vector, size_t index, size_t n )
876  : vector_( vector ) // The sparse vector containing the subvector
877  , offset_( index ) // The offset of the subvector within the sparse vector
878  , size_ ( n ) // The size of the subvector
879 {
880  if( index + n > vector.size() )
881  throw std::invalid_argument( "Invalid subvector specification" );
882 }
883 //*************************************************************************************************
884 
885 
886 
887 
888 //=================================================================================================
889 //
890 // DATA ACCESS FUNCTIONS
891 //
892 //=================================================================================================
893 
894 //*************************************************************************************************
900 template< typename VT // Type of the sparse vector
901  , bool AF // Alignment flag
902  , bool TF > // Transpose flag
905 {
906  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
907  return vector_[offset_+index];
908 }
909 //*************************************************************************************************
910 
911 
912 //*************************************************************************************************
918 template< typename VT // Type of the sparse vector
919  , bool AF // Alignment flag
920  , bool TF > // Transpose flag
923 {
924  BLAZE_USER_ASSERT( index < size(), "Invalid subvector access index" );
925  return const_cast<const VT&>( vector_ )[offset_+index];
926 }
927 //*************************************************************************************************
928 
929 
930 //*************************************************************************************************
937 template< typename VT // Type of the sparse vector
938  , bool AF // Alignment flag
939  , bool TF > // Transpose flag
941 {
942  if( offset_ == 0UL )
943  return Iterator( vector_.begin(), offset_ );
944  else
945  return Iterator( vector_.lowerBound( offset_ ), offset_ );
946 }
947 //*************************************************************************************************
948 
949 
950 //*************************************************************************************************
957 template< typename VT // Type of the sparse vector
958  , bool AF // Alignment flag
959  , bool TF > // Transpose flag
961 {
962  if( offset_ == 0UL )
963  return ConstIterator( vector_.cbegin(), offset_ );
964  else
965  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
966 }
967 //*************************************************************************************************
968 
969 
970 //*************************************************************************************************
977 template< typename VT // Type of the sparse vector
978  , bool AF // Alignment flag
979  , bool TF > // Transpose flag
981 {
982  if( offset_ == 0UL )
983  return ConstIterator( vector_.cbegin(), offset_ );
984  else
985  return ConstIterator( vector_.lowerBound( offset_ ), offset_ );
986 }
987 //*************************************************************************************************
988 
989 
990 //*************************************************************************************************
997 template< typename VT // Type of the sparse vector
998  , bool AF // Alignment flag
999  , bool TF > // Transpose flag
1001 {
1002  if( offset_ + size_ == vector_.size() )
1003  return Iterator( vector_.end(), offset_ );
1004  else
1005  return Iterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1006 }
1007 //*************************************************************************************************
1008 
1009 
1010 //*************************************************************************************************
1017 template< typename VT // Type of the sparse vector
1018  , bool AF // Alignment flag
1019  , bool TF > // Transpose flag
1021 {
1022  if( offset_ + size_ == vector_.size() )
1023  return ConstIterator( vector_.cend(), offset_ );
1024  else
1025  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1026 }
1027 //*************************************************************************************************
1028 
1029 
1030 //*************************************************************************************************
1037 template< typename VT // Type of the sparse vector
1038  , bool AF // Alignment flag
1039  , bool TF > // Transpose flag
1041 {
1042  if( offset_ + size_ == vector_.size() )
1043  return ConstIterator( vector_.cend(), offset_ );
1044  else
1045  return ConstIterator( vector_.lowerBound( offset_ + size_ ), offset_ );
1046 }
1047 //*************************************************************************************************
1048 
1049 
1050 
1051 
1052 //=================================================================================================
1053 //
1054 // ASSIGNMENT OPERATORS
1055 //
1056 //=================================================================================================
1057 
1058 //*************************************************************************************************
1068 template< typename VT // Type of the sparse vector
1069  , bool AF // Alignment flag
1070  , bool TF > // Transpose flag
1073 {
1074  using blaze::assign;
1075 
1078 
1079  if( this == &rhs || ( &vector_ == &rhs.vector_ && offset_ == rhs.offset_ ) )
1080  return *this;
1081 
1082  if( size() != rhs.size() )
1083  throw std::invalid_argument( "Vector sizes do not match" );
1084 
1085  if( rhs.canAlias( &vector_ ) ) {
1086  const ResultType tmp( rhs );
1087  reset();
1088  assign( *this, tmp );
1089  }
1090  else {
1091  reset();
1092  assign( *this, rhs );
1093  }
1094 
1095  return *this;
1096 }
1097 //*************************************************************************************************
1098 
1099 
1100 //*************************************************************************************************
1110 template< typename VT // Type of the sparse vector
1111  , bool AF // Alignment flag
1112  , bool TF > // Transpose flag
1113 template< typename VT2 > // Type of the right-hand side dense vector
1116 {
1117  using blaze::assign;
1118 
1122 
1123  if( size() != (~rhs).size() )
1124  throw std::invalid_argument( "Vector sizes do not match" );
1125 
1126  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1127  const typename VT2::ResultType tmp( ~rhs );
1128  reset();
1129  assign( *this, tmp );
1130  }
1131  else {
1132  reset();
1133  assign( *this, ~rhs );
1134  }
1135 
1136  return *this;
1137 }
1138 //*************************************************************************************************
1139 
1140 
1141 //*************************************************************************************************
1151 template< typename VT // Type of the sparse vector
1152  , bool AF // Alignment flag
1153  , bool TF > // Transpose flag
1154 template< typename VT2 > // Type of the right-hand side sparse vector
1157 {
1158  using blaze::assign;
1159 
1163 
1164  if( size() != (~rhs).size() )
1165  throw std::invalid_argument( "Vector sizes do not match" );
1166 
1167  if( RequiresEvaluation<VT2>::value || (~rhs).canAlias( &vector_ ) ) {
1168  const typename VT2::ResultType tmp( ~rhs );
1169  reset();
1170  assign( *this, tmp );
1171  }
1172  else {
1173  reset();
1174  assign( *this, ~rhs );
1175  }
1176 
1177  return *this;
1178 }
1179 //*************************************************************************************************
1180 
1181 
1182 //*************************************************************************************************
1192 template< typename VT // Type of the sparse vector
1193  , bool AF // Alignment flag
1194  , bool TF > // Transpose flag
1195 template< typename VT2 > // Type of the right-hand side vector
1198 {
1199  using blaze::addAssign;
1200 
1201  if( size() != (~rhs).size() )
1202  throw std::invalid_argument( "Vector sizes do not match" );
1203 
1204  addAssign( *this, ~rhs );
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::subAssign;
1229 
1230  if( size() != (~rhs).size() )
1231  throw std::invalid_argument( "Vector sizes do not match" );
1232 
1233  subAssign( *this, ~rhs );
1234 
1235  return *this;
1236 }
1237 //*************************************************************************************************
1238 
1239 
1240 //*************************************************************************************************
1251 template< typename VT // Type of the sparse vector
1252  , bool AF // Alignment flag
1253  , bool TF > // Transpose flag
1254 template< typename VT2 > // Type of the right-hand side vector
1257 {
1258  if( size() != (~rhs).size() )
1259  throw std::invalid_argument( "Vector sizes do not match" );
1260 
1261  typedef typename MultTrait<ResultType,typename VT2::ResultType>::Type MultType;
1262 
1266 
1267  const MultType tmp( *this * (~rhs) );
1268  reset();
1269  assign( tmp );
1270 
1271  return *this;
1272 }
1273 //*************************************************************************************************
1274 
1275 
1276 //*************************************************************************************************
1287 template< typename VT // Type of the sparse vector
1288  , bool AF // Alignment flag
1289  , bool TF > // Transpose flag
1290 template< typename Other > // Data type of the right-hand side scalar
1291 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1293 {
1294  const Iterator last( end() );
1295  for( Iterator element=begin(); element!=last; ++element )
1296  element->value() *= rhs;
1297  return *this;
1298 }
1299 //*************************************************************************************************
1300 
1301 
1302 //*************************************************************************************************
1314 template< typename VT // Type of the sparse vector
1315  , bool AF // Alignment flag
1316  , bool TF > // Transpose flag
1317 template< typename Other > // Data type of the right-hand side scalar
1318 inline typename EnableIf< IsNumeric<Other>, SparseSubvector<VT,AF,TF> >::Type&
1320 {
1321  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1322 
1323  typedef typename DivTrait<ElementType,Other>::Type DT;
1324  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1325 
1326  const Iterator last( end() );
1327 
1328  // Depending on the two involved data types, an integer division is applied or a
1329  // floating point division is selected.
1331  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1332  for( Iterator element=begin(); element!=last; ++element )
1333  element->value() *= tmp;
1334  }
1335  else {
1336  for( Iterator element=begin(); element!=last; ++element )
1337  element->value() /= rhs;
1338  }
1339 
1340  return *this;
1341 }
1342 //*************************************************************************************************
1343 
1344 
1345 
1346 
1347 //=================================================================================================
1348 //
1349 // UTILITY FUNCTIONS
1350 //
1351 //=================================================================================================
1352 
1353 //*************************************************************************************************
1358 template< typename VT // Type of the sparse vector
1359  , bool AF // Alignment flag
1360  , bool TF > // Transpose flag
1361 inline size_t SparseSubvector<VT,AF,TF>::size() const
1362 {
1363  return size_;
1364 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1373 template< typename VT // Type of the sparse vector
1374  , bool AF // Alignment flag
1375  , bool TF > // Transpose flag
1377 {
1378  return nonZeros() + vector_.capacity() - vector_.nonZeros();
1379 }
1380 //*************************************************************************************************
1381 
1382 
1383 //*************************************************************************************************
1390 template< typename VT // Type of the sparse vector
1391  , bool AF // Alignment flag
1392  , bool TF > // Transpose flag
1394 {
1395  return end() - begin();
1396 }
1397 //*************************************************************************************************
1398 
1399 
1400 //*************************************************************************************************
1405 template< typename VT // Type of the sparse vector
1406  , bool AF // Alignment flag
1407  , bool TF > // Transpose flag
1409 {
1410  vector_.erase( vector_.lowerBound( offset_ ), vector_.lowerBound( offset_ + size_ ) );
1411 }
1412 //*************************************************************************************************
1413 
1414 
1415 //*************************************************************************************************
1427 template< typename VT // Type of the sparse vector
1428  , bool AF // Alignment flag
1429  , bool TF > // Transpose flag
1431  SparseSubvector<VT,AF,TF>::insert( size_t index, const ElementType& value )
1432 {
1433  return Iterator( vector_.insert( offset_ + index, value ), offset_ );
1434 }
1435 //*************************************************************************************************
1436 
1437 
1438 //*************************************************************************************************
1446 template< typename VT // Type of the sparse vector
1447  , bool AF // Alignment flag
1448  , bool TF > // Transpose flag
1449 inline void SparseSubvector<VT,AF,TF>::erase( size_t index )
1450 {
1451  vector_.erase( offset_ + index );
1452 }
1453 //*************************************************************************************************
1454 
1455 
1456 //*************************************************************************************************
1464 template< typename VT // Type of the sparse vector
1465  , bool AF // Alignment flag
1466  , bool TF > // Transpose flag
1468 {
1469  return Iterator( vector_.erase( pos.base() ), offset_ );
1470 }
1471 //*************************************************************************************************
1472 
1473 
1474 //*************************************************************************************************
1483 template< typename VT // Type of the sparse vector
1484  , bool AF // Alignment flag
1485  , bool TF > // Transpose flag
1488 {
1489  return Iterator( vector_.erase( first.base(), last.base() ), offset_ );
1490 }
1491 //*************************************************************************************************
1492 
1493 
1494 //*************************************************************************************************
1503 template< typename VT // Type of the sparse vector
1504  , bool AF // Alignment flag
1505  , bool TF > // Transpose flag
1507 {
1508  const size_t current( capacity() );
1509 
1510  if( n > current ) {
1511  vector_.reserve( vector_.capacity() + n - current );
1512  }
1513 }
1514 //*************************************************************************************************
1515 
1516 
1517 //*************************************************************************************************
1523 template< typename VT // Type of the sparse vector
1524  , bool AF // Alignment flag
1525  , bool TF > // Transpose flag
1526 template< typename Other > // Data type of the scalar value
1528 {
1529  for( Iterator element=begin(); element!=end(); ++element )
1530  element->value() *= scalar;
1531  return *this;
1532 }
1533 //*************************************************************************************************
1534 
1535 
1536 
1537 
1538 //=================================================================================================
1539 //
1540 // LOOKUP FUNCTIONS
1541 //
1542 //=================================================================================================
1543 
1544 //*************************************************************************************************
1557 template< typename VT // Type of the sparse vector
1558  , bool AF // Alignment flag
1559  , bool TF > // Transpose flag
1562 {
1563  const typename VT::Iterator pos( vector_.find( offset_ + index ) );
1564 
1565  if( pos != vector_.end() )
1566  return Iterator( pos, offset_ );
1567  else
1568  return end();
1569 }
1570 //*************************************************************************************************
1571 
1572 
1573 //*************************************************************************************************
1586 template< typename VT // Type of the sparse vector
1587  , bool AF // Alignment flag
1588  , bool TF > // Transpose flag
1590  SparseSubvector<VT,AF,TF>::find( size_t index ) const
1591 {
1592  const typename VT::ConstIterator pos( vector_.find( offset_ + index ) );
1593 
1594  if( pos != vector_.end() )
1595  return Iterator( pos, offset_ );
1596  else
1597  return end();
1598 }
1599 //*************************************************************************************************
1600 
1601 
1602 //*************************************************************************************************
1614 template< typename VT // Type of the sparse vector
1615  , bool AF // Alignment flag
1616  , bool TF > // Transpose flag
1619 {
1620  return Iterator( vector_.lowerBound( offset_ + index ), offset_ );
1621 }
1622 //*************************************************************************************************
1623 
1624 
1625 //*************************************************************************************************
1637 template< typename VT // Type of the sparse vector
1638  , bool AF // Alignment flag
1639  , bool TF > // Transpose flag
1642 {
1643  return ConstIterator( vector_.lowerBound( offset_ + index ), offset_ );
1644 }
1645 //*************************************************************************************************
1646 
1647 
1648 //*************************************************************************************************
1660 template< typename VT // Type of the sparse vector
1661  , bool AF // Alignment flag
1662  , bool TF > // Transpose flag
1665 {
1666  return Iterator( vector_.upperBound( offset_ + index ), offset_ );
1667 }
1668 //*************************************************************************************************
1669 
1670 
1671 //*************************************************************************************************
1683 template< typename VT // Type of the sparse vector
1684  , bool AF // Alignment flag
1685  , bool TF > // Transpose flag
1688 {
1689  return ConstIterator( vector_.upperBound( offset_ + index ), offset_ );
1690 }
1691 //*************************************************************************************************
1692 
1693 
1694 
1695 
1696 //=================================================================================================
1697 //
1698 // LOW-LEVEL UTILITY FUNCTIONS
1699 //
1700 //=================================================================================================
1701 
1702 //*************************************************************************************************
1726 template< typename VT // Type of the sparse vector
1727  , bool AF // Alignment flag
1728  , bool TF > // Transpose flag
1729 inline void SparseSubvector<VT,AF,TF>::append( size_t index, const ElementType& value, bool check )
1730 {
1731  if( offset_ + size_ == vector_.size() )
1732  vector_.append( offset_ + index, value, check );
1733  else if( !check || !isDefault( value ) )
1734  vector_.insert( offset_ + index, value );
1735 }
1736 //*************************************************************************************************
1737 
1738 
1739 
1740 
1741 //=================================================================================================
1742 //
1743 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1744 //
1745 //=================================================================================================
1746 
1747 //*************************************************************************************************
1757 template< typename VT // Type of the sparse vector
1758  , bool AF // Alignment flag
1759  , bool TF > // Transpose flag
1760 template< typename Other > // Data type of the foreign expression
1761 inline bool SparseSubvector<VT,AF,TF>::canAlias( const Other* alias ) const
1762 {
1763  return static_cast<const void*>( &vector_ ) == static_cast<const void*>( alias );
1764 }
1765 //*************************************************************************************************
1766 
1767 
1768 //*************************************************************************************************
1778 template< typename VT // Type of the sparse vector
1779  , bool AF // Alignment flag
1780  , bool TF > // Transpose flag
1781 template< typename Other > // Data type of the foreign expression
1782 inline bool SparseSubvector<VT,AF,TF>::isAliased( const Other* alias ) const
1783 {
1784  return static_cast<const void*>( &vector_ ) == static_cast<const void*>( alias );
1785 }
1786 //*************************************************************************************************
1787 
1788 
1789 //*************************************************************************************************
1800 template< typename VT // Type of the sparse vector
1801  , bool AF // Alignment flag
1802  , bool TF > // Transpose flag
1803 template< typename VT2 > // Type of the right-hand side dense vector
1805 {
1806  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1807  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1808 
1809  reserve( (~rhs).size() );
1810 
1811  for( size_t i=0UL; i<size(); ++i ) {
1812  append( i, (~rhs)[i], true );
1813  }
1814 }
1815 //*************************************************************************************************
1816 
1817 
1818 //*************************************************************************************************
1829 template< typename VT // Type of the sparse vector
1830  , bool AF // Alignment flag
1831  , bool TF > // Transpose flag
1832 template< typename VT2 > // Type of the right-hand side sparse vector
1834 {
1835  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1836  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1837 
1838  reserve( (~rhs).nonZeros() );
1839 
1840  for( typename VT2::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1841  append( element->index(), element->value(), true );
1842  }
1843 }
1844 //*************************************************************************************************
1845 
1846 
1847 //*************************************************************************************************
1858 template< typename VT // Type of the sparse vector
1859  , bool AF // Alignment flag
1860  , bool TF > // Transpose flag
1861 template< typename VT2 > // Type of the right-hand side dense vector
1863 {
1864  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1865 
1869 
1870  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1871 
1872  const AddType tmp( *this + (~rhs) );
1873  reset();
1874  assign( tmp );
1875 }
1876 //*************************************************************************************************
1877 
1878 
1879 //*************************************************************************************************
1890 template< typename VT // Type of the sparse vector
1891  , bool AF // Alignment flag
1892  , bool TF > // Transpose flag
1893 template< typename VT2 > // Type of the right-hand side sparse vector
1895 {
1896  typedef typename AddTrait<ResultType,typename VT2::ResultType>::Type AddType;
1897 
1901 
1902  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1903 
1904  const AddType tmp( *this + (~rhs) );
1905  reset();
1906  assign( tmp );
1907 }
1908 //*************************************************************************************************
1909 
1910 
1911 //*************************************************************************************************
1922 template< typename VT // Type of the sparse vector
1923  , bool AF // Alignment flag
1924  , bool TF > // Transpose flag
1925 template< typename VT2 > // Type of the right-hand side dense vector
1927 {
1928  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
1929 
1933 
1934  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1935 
1936  const SubType tmp( *this - (~rhs) );
1937  reset();
1938  assign( tmp );
1939 }
1940 //*************************************************************************************************
1941 
1942 
1943 //*************************************************************************************************
1954 template< typename VT // Type of the sparse vector
1955  , bool AF // Alignment flag
1956  , bool TF > // Transpose flag
1957 template< typename VT2 > // Type of the right-hand side sparse vector
1959 {
1960  typedef typename SubTrait<ResultType,typename VT2::ResultType>::Type SubType;
1961 
1965 
1966  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1967 
1968  const SubType tmp( *this - (~rhs) );
1969  reset();
1970  assign( tmp );
1971 }
1972 //*************************************************************************************************
1973 
1974 
1975 
1976 
1977 
1978 
1979 
1980 
1981 //=================================================================================================
1982 //
1983 // SPARSESUBVECTOR OPERATORS
1984 //
1985 //=================================================================================================
1986 
1987 //*************************************************************************************************
1990 template< typename VT, bool AF, bool TF >
1991 inline void reset( SparseSubvector<VT,AF,TF>& sv );
1992 
1993 template< typename VT, bool AF, bool TF >
1994 inline void clear( SparseSubvector<VT,AF,TF>& sv );
1995 
1996 template< typename VT, bool AF, bool TF >
1997 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv );
1999 //*************************************************************************************************
2000 
2001 
2002 //*************************************************************************************************
2009 template< typename VT // Type of the sparse vector
2010  , bool AF // Alignment flag
2011  , bool TF > // Transpose flag
2013 {
2014  sv.reset();
2015 }
2016 //*************************************************************************************************
2017 
2018 
2019 //*************************************************************************************************
2028 template< typename VT // Type of the sparse vector
2029  , bool AF // Alignment flag
2030  , bool TF > // Transpose flag
2032 {
2033  sv.reset();
2034 }
2035 //*************************************************************************************************
2036 
2037 
2038 //*************************************************************************************************
2056 template< typename VT // Type of the sparse vector
2057  , bool AF // Alignment flag
2058  , bool TF > // Transpose flag
2059 inline bool isDefault( const SparseSubvector<VT,AF,TF>& sv )
2060 {
2062 
2063  const ConstIterator end( sv.end() );
2064  for( ConstIterator element=sv.begin(); element!=end; ++element )
2065  if( !isDefault( element->value() ) ) return false;
2066  return true;
2067 }
2068 //*************************************************************************************************
2069 
2070 
2071 
2072 
2073 //=================================================================================================
2074 //
2075 // GLOBAL RESTRUCTURING OPERATORS
2076 //
2077 //=================================================================================================
2078 
2079 //*************************************************************************************************
2092 template< bool AF1 // Required alignment flag
2093  , typename VT // Type of the sparse vector
2094  , bool AF2 // Present alignment flag
2095  , bool TF > // Transpose flag
2096 inline const SparseSubvector<VT,AF1,TF>
2097  subvector( const SparseSubvector<VT,AF2,TF>& sv, size_t index, size_t size )
2098 {
2100 
2101  if( index + size > sv.size() )
2102  throw std::invalid_argument( "Invalid subvector specification" );
2103 
2104  return SparseSubvector<VT,AF1,TF>( sv.vector_, sv.offset_ + index, size );
2105 }
2107 //*************************************************************************************************
2108 
2109 
2110 
2111 
2112 //=================================================================================================
2113 //
2114 // SUBVECTORTRAIT SPECIALIZATIONS
2115 //
2116 //=================================================================================================
2117 
2118 //*************************************************************************************************
2120 template< typename VT, bool AF, bool TF >
2121 struct SubvectorTrait< SparseSubvector<VT,AF,TF> >
2122 {
2124 };
2126 //*************************************************************************************************
2127 
2128 
2129 
2130 
2131 //=================================================================================================
2132 //
2133 // SUBVECTOREXPRTRAIT SPECIALIZATIONS
2134 //
2135 //=================================================================================================
2136 
2137 //*************************************************************************************************
2139 template< typename VT, bool AF1, bool TF, bool AF2 >
2140 struct SubvectorExprTrait< SparseSubvector<VT,AF1,TF>, AF2 >
2141 {
2142  typedef SparseSubvector<VT,AF2,TF> Type;
2143 };
2145 //*************************************************************************************************
2146 
2147 
2148 //*************************************************************************************************
2150 template< typename VT, bool AF1, bool TF, bool AF2 >
2151 struct SubvectorExprTrait< const SparseSubvector<VT,AF1,TF>, AF2 >
2152 {
2153  typedef SparseSubvector<VT,AF2,TF> Type;
2154 };
2156 //*************************************************************************************************
2157 
2158 
2159 //*************************************************************************************************
2161 template< typename VT, bool AF1, bool TF, bool AF2 >
2162 struct SubvectorExprTrait< volatile SparseSubvector<VT,AF1,TF>, AF2 >
2163 {
2164  typedef SparseSubvector<VT,AF2,TF> Type;
2165 };
2167 //*************************************************************************************************
2168 
2169 
2170 //*************************************************************************************************
2172 template< typename VT, bool AF1, bool TF, bool AF2 >
2173 struct SubvectorExprTrait< const volatile SparseSubvector<VT,AF1,TF>, AF2 >
2174 {
2175  typedef SparseSubvector<VT,AF2,TF> Type;
2176 };
2178 //*************************************************************************************************
2179 
2180 } // namespace blaze
2181 
2182 #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:403
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:387
size_t offset_
Offset within the according sparse vector.
Definition: SparseSubvector.h:546
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#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:680
ValueType PointerType
Pointer return type.
Definition: SparseSubvector.h:562
Header file for the SparseVector base class.
const size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:826
VT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseSubvector.h:407
IteratorType base() const
Access to the current position of the submatrix iterator.
Definition: SparseSubvector.h:690
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
bool operator==(const SubvectorIterator< VectorType2, IteratorType2 > &rhs) const
Equality comparison between two SubvectorIterator objects.
Definition: SparseSubvector.h:657
#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:940
SubvectorElement< VectorType, IteratorType > ValueType
Type of the underlying elements.
Definition: SparseSubvector.h:561
ValueType value_type
Type of the underlying elements.
Definition: SparseSubvector.h:568
Header file for the IsRowVector type trait.
SparseSubvector(Operand vector, size_t index, size_t n)
The constructor for SparseSubvector.
Definition: SparseSubvector.h:875
VT::ConstReference ConstReference
Reference to a constant subvector value.
Definition: SparseSubvector.h:411
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:1618
#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:669
size_t size() const
Returns the size/dimension of the sparse subvector.
Definition: SparseSubvector.h:1361
size_t offset_
The offset of the subvector within the sparse vector.
Definition: SparseSubvector.h:708
SelectType< returnConst, const ElementType &, ElementType & >::Type ReferenceType
Return type of the value member function.
Definition: SparseSubvector.h:438
void reserve(size_t n)
Setting the minimum capacity of the sparse subvector.
Definition: SparseSubvector.h:1506
IteratorCategory iterator_category
The iterator category.
Definition: SparseSubvector.h:567
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
PointerType operator->() const
Direct access to the current sparse subvector element.
Definition: SparseSubvector.h:645
SubvectorElement & operator*=(const T &v)
Multiplication assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:495
SubvectorElement & operator/=(const T &v)
Division assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:507
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:405
SubvectorElement & operator-=(const T &v)
Subtraction assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:483
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:635
SubvectorElement & operator+=(const T &v)
Addition assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:471
Iterator end()
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1000
ReferenceType reference
Reference return type.
Definition: SparseSubvector.h:570
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:718
std::forward_iterator_tag IteratorCategory
The iterator category.
Definition: SparseSubvector.h:560
SubvectorIterator< const VT, typename VT::ConstIterator > ConstIterator
Iterator over constant elements.
Definition: SparseSubvector.h:715
Header file for the multiplication trait.
void erase(size_t index)
Erasing an element from the sparse subvector.
Definition: SparseSubvector.h:1449
size_t capacity() const
Returns the maximum capacity of the sparse subvector.
Definition: SparseSubvector.h:1376
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:825
Header file for the IsFloatingPoint type trait.
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
SubvectorIterator & operator++()
Pre-increment operator.
Definition: SparseSubvector.h:612
Header file for the Or class template.
SubvectorIterator()
Default constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:577
void assign(const DenseVector< VT2, TF > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseSubvector.h:1804
PointerType pointer
Pointer return type.
Definition: SparseSubvector.h:569
size_t index() const
Access to the current index of the sparse element.
Definition: SparseSubvector.h:538
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:518
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:179
Access proxy for a specific element of the sparse subvector.
Definition: SparseSubvector.h:422
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse subvector.
Definition: SparseSubvector.h:1729
SubvectorIterator(IteratorType iterator, size_t index)
Constructor for the SubvectorIterator class.
Definition: SparseSubvector.h:589
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:1926
Constraint on the data type.
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: SparseSubvector.h:564
SubvectorTrait< VT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseSubvector.h:404
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:700
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseSubvector.h:1664
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2382
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:2386
Header file for the EnableIf class template.
VT::ElementType ElementType
Type of the subvector elements.
Definition: SparseSubvector.h:406
SubvectorElement & operator=(const T &v)
Assignment to the accessed sparse subvector element.
Definition: SparseSubvector.h:459
DifferenceType difference_type
Difference between two iterators.
Definition: SparseSubvector.h:571
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:904
SubvectorIterator(const SubvectorIterator< VectorType2, IteratorType2 > &it)
Conversion constructor from different SubvectorIterator instances.
Definition: SparseSubvector.h:601
ValueType ReferenceType
Reference return type.
Definition: SparseSubvector.h:563
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
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:209
ReferenceType value() const
Access to the current value of the sparse subvector element.
Definition: SparseSubvector.h:528
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:827
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:133
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:239
bool canAlias(const Other *alias) const
Returns whether the sparse subvector can alias with the given address alias.
Definition: SparseSubvector.h:1761
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2387
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:1782
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:72
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:1561
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:1393
#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:408
ConstIterator cbegin() const
Returns an iterator to the first element of the subvector.
Definition: SparseSubvector.h:980
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse subvector.
Definition: SparseSubvector.h:1431
const SubvectorIterator operator++(int)
Post-increment operator.
Definition: SparseSubvector.h:623
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:147
IteratorType pos_
Iterator to the current sparse element.
Definition: SparseSubvector.h:707
Iterator over the elements of the sparse subvector.
Definition: SparseSubvector.h:556
SubvectorElement(IteratorType pos, size_t offset)
Constructor for the SubvectorElement class.
Definition: SparseSubvector.h:447
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
#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:2379
Header file for basic type definitions.
void reset()
Reset to the default initial values.
Definition: SparseSubvector.h:1408
Header file for the SubvectorExprTrait class template.
SparseSubvector & operator=(const SparseSubvector &rhs)
Copy assignment operator for SparseSubvector.
Definition: SparseSubvector.h:1072
ConstIterator cend() const
Returns an iterator just past the last element of the subvector.
Definition: SparseSubvector.h:1040
void addAssign(const DenseVector< VT2, TF > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseSubvector.h:1862
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:414
#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:545
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.