SparseRow.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SPARSEROW_H_
36 #define _BLAZE_MATH_VIEWS_SPARSEROW_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
57 #include <blaze/math/Functions.h>
59 #include <blaze/math/shims/Reset.h>
81 #include <blaze/util/Assert.h>
84 #include <blaze/util/DisableIf.h>
85 #include <blaze/util/EnableIf.h>
86 #include <blaze/util/Exception.h>
88 #include <blaze/util/mpl/And.h>
89 #include <blaze/util/mpl/If.h>
90 #include <blaze/util/mpl/Or.h>
91 #include <blaze/util/Null.h>
92 #include <blaze/util/Types.h>
98 #include <blaze/util/Unused.h>
100 
101 
102 namespace blaze {
103 
104 //=================================================================================================
105 //
106 // CLASS DEFINITION
107 //
108 //=================================================================================================
109 
110 //*************************************************************************************************
367 template< typename MT // Type of the sparse matrix
368  , bool SO = IsRowMajorMatrix<MT>::value // Storage order
369  , bool SF = IsSymmetric<MT>::value > // Symmetry flag
370 class SparseRow : public SparseVector< SparseRow<MT,SO,SF>, true >
371  , private Row
372 {
373  private:
374  //**Type definitions****************************************************************************
376  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
377  //**********************************************************************************************
378 
379  public:
380  //**Type definitions****************************************************************************
382  typedef typename RowTrait<MT>::Type ResultType;
384  typedef typename MT::ElementType ElementType;
385  typedef typename MT::ReturnType ReturnType;
386  typedef const SparseRow& CompositeType;
387 
390 
392  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
393 
396 
398  typedef typename If< IsConst<MT>, ConstIterator, typename MT::Iterator >::Type Iterator;
399  //**********************************************************************************************
400 
401  //**Compilation flags***************************************************************************
403  enum { smpAssignable = 0 };
404  //**********************************************************************************************
405 
406  //**Constructors********************************************************************************
409  explicit inline SparseRow( MT& matrix, size_t index );
410  // No explicitly declared copy constructor.
412  //**********************************************************************************************
413 
414  //**Destructor**********************************************************************************
415  // No explicitly declared destructor.
416  //**********************************************************************************************
417 
418  //**Data access functions***********************************************************************
421  inline Reference operator[]( size_t index );
422  inline ConstReference operator[]( size_t index ) const;
423  inline Reference at( size_t index );
424  inline ConstReference at( size_t index ) const;
425  inline Iterator begin ();
426  inline ConstIterator begin () const;
427  inline ConstIterator cbegin() const;
428  inline Iterator end ();
429  inline ConstIterator end () const;
430  inline ConstIterator cend () const;
432  //**********************************************************************************************
433 
434  //**Assignment operators************************************************************************
437  inline SparseRow& operator=( const SparseRow& rhs );
438 
439  template< typename VT > inline SparseRow& operator= ( const DenseVector<VT,true>& rhs );
440  template< typename VT > inline SparseRow& operator= ( const SparseVector<VT,true>& rhs );
441  template< typename VT > inline SparseRow& operator+=( const DenseVector<VT,true>& rhs );
442  template< typename VT > inline SparseRow& operator+=( const SparseVector<VT,true>& rhs );
443  template< typename VT > inline SparseRow& operator-=( const DenseVector<VT,true>& rhs );
444  template< typename VT > inline SparseRow& operator-=( const SparseVector<VT,true>& rhs );
445  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
446 
447  template< typename Other >
448  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
449  operator*=( Other rhs );
450 
451  template< typename Other >
452  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
453  operator/=( Other rhs );
455  //**********************************************************************************************
456 
457  //**Utility functions***************************************************************************
460  inline size_t size() const;
461  inline size_t capacity() const;
462  inline size_t nonZeros() const;
463  inline void reset();
464  inline Iterator set ( size_t index, const ElementType& value );
465  inline Iterator insert ( size_t index, const ElementType& value );
466  inline void erase ( size_t index );
467  inline Iterator erase ( Iterator pos );
468  inline Iterator erase ( Iterator first, Iterator last );
469  inline void reserve( size_t n );
470  template< typename Other > inline SparseRow& scale ( const Other& scalar );
472  //**********************************************************************************************
473 
474  //**Lookup functions****************************************************************************
477  inline Iterator find ( size_t index );
478  inline ConstIterator find ( size_t index ) const;
479  inline Iterator lowerBound( size_t index );
480  inline ConstIterator lowerBound( size_t index ) const;
481  inline Iterator upperBound( size_t index );
482  inline ConstIterator upperBound( size_t index ) const;
484  //**********************************************************************************************
485 
486  //**Low-level utility functions*****************************************************************
489  inline void append( size_t index, const ElementType& value, bool check=false );
491  //**********************************************************************************************
492 
493  //**Expression template evaluation functions****************************************************
496  template< typename Other > inline bool canAlias ( const Other* alias ) const;
497  template< typename Other > inline bool isAliased( const Other* alias ) const;
498 
499  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
500  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
501  template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
502  template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
503  template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
504  template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
506  //**********************************************************************************************
507 
508  private:
509  //**Utility functions***************************************************************************
512  inline size_t extendCapacity() const;
514  //**********************************************************************************************
515 
516  //**Member variables****************************************************************************
519  Operand matrix_;
520  const size_t row_;
521 
522  //**********************************************************************************************
523 
524  //**Friend declarations*************************************************************************
526  template< typename MT2, bool SO2, bool SF2 >
527  friend bool isIntact( const SparseRow<MT2,SO2,SF2>& row );
528 
529  template< typename MT2, bool SO2, bool SF2 >
530  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
531 
532  template< typename MT2, bool SO2, bool SF2, typename VT >
533  friend bool tryAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
534 
535  template< typename MT2, bool SO2, bool SF2, typename VT >
536  friend bool tryAddAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
537 
538  template< typename MT2, bool SO2, bool SF2, typename VT >
539  friend bool trySubAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
540 
541  template< typename MT2, bool SO2, bool SF2, typename VT >
542  friend bool tryMultAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
543 
544  template< typename MT2, bool SO2, bool SF2 >
545  friend typename DerestrictTrait< SparseRow<MT2,SO2,SF2> >::Type
546  derestrict( SparseRow<MT2,SO2,SF2>& dm );
548  //**********************************************************************************************
549 
550  //**Compile time checks*************************************************************************
559  //**********************************************************************************************
560 };
561 //*************************************************************************************************
562 
563 
564 
565 
566 //=================================================================================================
567 //
568 // CONSTRUCTOR
569 //
570 //=================================================================================================
571 
572 //*************************************************************************************************
579 template< typename MT // Type of the sparse matrix
580  , bool SO // Storage order
581  , bool SF > // Symmetry flag
582 inline SparseRow<MT,SO,SF>::SparseRow( MT& matrix, size_t index )
583  : matrix_( matrix ) // The sparse matrix containing the row
584  , row_ ( index ) // The index of the row in the matrix
585 {
586  if( matrix_.rows() <= index ) {
587  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
588  }
589 }
590 //*************************************************************************************************
591 
592 
593 
594 
595 //=================================================================================================
596 //
597 // DATA ACCESS FUNCTIONS
598 //
599 //=================================================================================================
600 
601 //*************************************************************************************************
610 template< typename MT // Type of the sparse matrix
611  , bool SO // Storage order
612  , bool SF > // Symmetry flag
614 {
615  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
616  return matrix_(row_,index);
617 }
618 //*************************************************************************************************
619 
620 
621 //*************************************************************************************************
630 template< typename MT // Type of the sparse matrix
631  , bool SO // Storage order
632  , bool SF > // Symmetry flag
634  SparseRow<MT,SO,SF>::operator[]( size_t index ) const
635 {
636  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
637  return const_cast<const MT&>( matrix_ )(row_,index);
638 }
639 //*************************************************************************************************
640 
641 
642 //*************************************************************************************************
652 template< typename MT // Type of the sparse matrix
653  , bool SO // Storage order
654  , bool SF > // Symmetry flag
656 {
657  if( index >= size() ) {
658  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
659  }
660  return (*this)[index];
661 }
662 //*************************************************************************************************
663 
664 
665 //*************************************************************************************************
675 template< typename MT // Type of the sparse matrix
676  , bool SO // Storage order
677  , bool SF > // Symmetry flag
679 {
680  if( index >= size() ) {
681  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
682  }
683  return (*this)[index];
684 }
685 //*************************************************************************************************
686 
687 
688 //*************************************************************************************************
695 template< typename MT // Type of the sparse matrix
696  , bool SO // Storage order
697  , bool SF > // Symmetry flag
699 {
700  return matrix_.begin( row_ );
701 }
702 //*************************************************************************************************
703 
704 
705 //*************************************************************************************************
712 template< typename MT // Type of the sparse matrix
713  , bool SO // Storage order
714  , bool SF > // Symmetry flag
716 {
717  return matrix_.cbegin( row_ );
718 }
719 //*************************************************************************************************
720 
721 
722 //*************************************************************************************************
729 template< typename MT // Type of the sparse matrix
730  , bool SO // Storage order
731  , bool SF > // Symmetry flag
733 {
734  return matrix_.cbegin( row_ );
735 }
736 //*************************************************************************************************
737 
738 
739 //*************************************************************************************************
746 template< typename MT // Type of the sparse matrix
747  , bool SO // Storage order
748  , bool SF > // Symmetry flag
750 {
751  return matrix_.end( row_ );
752 }
753 //*************************************************************************************************
754 
755 
756 //*************************************************************************************************
763 template< typename MT // Type of the sparse matrix
764  , bool SO // Storage order
765  , bool SF > // Symmetry flag
767 {
768  return matrix_.cend( row_ );
769 }
770 //*************************************************************************************************
771 
772 
773 //*************************************************************************************************
780 template< typename MT // Type of the sparse matrix
781  , bool SO // Storage order
782  , bool SF > // Symmetry flag
784 {
785  return matrix_.cend( row_ );
786 }
787 //*************************************************************************************************
788 
789 
790 
791 
792 //=================================================================================================
793 //
794 // ASSIGNMENT OPERATORS
795 //
796 //=================================================================================================
797 
798 //*************************************************************************************************
811 template< typename MT // Type of the sparse matrix
812  , bool SO // Storage order
813  , bool SF > // Symmetry flag
815 {
816  using blaze::assign;
817 
821 
822  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
823  return *this;
824 
825  if( size() != rhs.size() ) {
826  BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
827  }
828 
829  if( !tryAssign( matrix_, rhs, row_, 0UL ) ) {
830  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
831  }
832 
833  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
834 
835  if( rhs.canAlias( &matrix_ ) ) {
836  const ResultType tmp( rhs );
837  left.reset();
838  left.reserve( tmp.nonZeros() );
839  assign( left, tmp );
840  }
841  else {
842  left.reset();
843  left.reserve( rhs.nonZeros() );
844  assign( left, rhs );
845  }
846 
847  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
848 
849  return *this;
850 }
851 //*************************************************************************************************
852 
853 
854 //*************************************************************************************************
867 template< typename MT // Type of the sparse matrix
868  , bool SO // Storage order
869  , bool SF > // Symmetry flag
870 template< typename VT > // Type of the right-hand side dense vector
872 {
873  using blaze::assign;
874 
878 
879  if( size() != (~rhs).size() ) {
880  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
881  }
882 
883  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
884  Right right( ~rhs );
885 
886  if( !tryAssign( matrix_, right, row_, 0UL ) ) {
887  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
888  }
889 
890  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
891 
892  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
893  const typename VT::ResultType tmp( right );
894  left.reset();
895  assign( left, tmp );
896  }
897  else {
898  left.reset();
899  assign( left, right );
900  }
901 
902  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
903 
904  return *this;
905 }
906 //*************************************************************************************************
907 
908 
909 //*************************************************************************************************
922 template< typename MT // Type of the sparse matrix
923  , bool SO // Storage order
924  , bool SF > // Symmetry flag
925 template< typename VT > // Type of the right-hand side sparse vector
927 {
928  using blaze::assign;
929 
933 
934  if( size() != (~rhs).size() ) {
935  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
936  }
937 
938  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
939  Right right( ~rhs );
940 
941  if( !tryAssign( matrix_, right, row_, 0UL ) ) {
942  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
943  }
944 
945  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
946 
947  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
948  const typename VT::ResultType tmp( right );
949  left.reset();
950  left.reserve( tmp.nonZeros() );
951  assign( left, tmp );
952  }
953  else {
954  left.reset();
955  left.reserve( right.nonZeros() );
956  assign( left, right );
957  }
958 
959  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
960 
961  return *this;
962 }
963 //*************************************************************************************************
964 
965 
966 //*************************************************************************************************
979 template< typename MT // Type of the sparse matrix
980  , bool SO // Storage order
981  , bool SF > // Symmetry flag
982 template< typename VT > // Type of the right-hand side dense vector
984 {
985  using blaze::assign;
986 
993 
995 
999 
1000  if( size() != (~rhs).size() ) {
1001  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1002  }
1003 
1004  const AddType tmp( *this + (~rhs) );
1005 
1006  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
1007  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1008  }
1009 
1010  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1011 
1012  left.reset();
1013  assign( left, tmp );
1014 
1015  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1016 
1017  return *this;
1018 }
1019 //*************************************************************************************************
1020 
1021 
1022 //*************************************************************************************************
1035 template< typename MT // Type of the sparse matrix
1036  , bool SO // Storage order
1037  , bool SF > // Symmetry flag
1038 template< typename VT > // Type of the right-hand side sparse vector
1040 {
1041  using blaze::assign;
1042 
1049 
1050  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1051 
1055 
1056  if( size() != (~rhs).size() ) {
1057  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1058  }
1059 
1060  const AddType tmp( *this + (~rhs) );
1061 
1062  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
1063  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1064  }
1065 
1066  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1067 
1068  left.reset();
1069  left.reserve( tmp.nonZeros() );
1070  assign( left, tmp );
1071 
1072  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1073 
1074  return *this;
1075 }
1076 //*************************************************************************************************
1077 
1078 
1079 //*************************************************************************************************
1093 template< typename MT // Type of the sparse matrix
1094  , bool SO // Storage order
1095  , bool SF > // Symmetry flag
1096 template< typename VT > // Type of the right-hand side dense vector
1098 {
1099  using blaze::assign;
1100 
1107 
1108  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1109 
1113 
1114  if( size() != (~rhs).size() ) {
1115  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1116  }
1117 
1118  const SubType tmp( *this - (~rhs) );
1119 
1120  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
1121  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1122  }
1123 
1124  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1125 
1126  left.reset();
1127  assign( left, tmp );
1128 
1129  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1130 
1131  return *this;
1132 }
1133 //*************************************************************************************************
1134 
1135 
1136 //*************************************************************************************************
1150 template< typename MT // Type of the sparse matrix
1151  , bool SO // Storage order
1152  , bool SF > // Symmetry flag
1153 template< typename VT > // Type of the right-hand side sparse vector
1155 {
1156  using blaze::assign;
1157 
1164 
1165  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1166 
1170 
1171  if( size() != (~rhs).size() ) {
1172  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1173  }
1174 
1175  const SubType tmp( *this - (~rhs) );
1176 
1177  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
1178  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1179  }
1180 
1181  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1182 
1183  left.reset();
1184  left.reserve( tmp.nonZeros() );
1185  assign( left, tmp );
1186 
1187  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1188 
1189  return *this;
1190 }
1191 //*************************************************************************************************
1192 
1193 
1194 //*************************************************************************************************
1206 template< typename MT // Type of the sparse matrix
1207  , bool SO // Storage order
1208  , bool SF > // Symmetry flag
1209 template< typename VT > // Type of the right-hand side vector
1211 {
1212  using blaze::assign;
1213 
1219 
1220  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
1221 
1224 
1225  if( size() != (~rhs).size() ) {
1226  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1227  }
1228 
1229  const MultType tmp( *this * (~rhs) );
1230 
1231  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
1232  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1233  }
1234 
1235  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1236 
1237  left.reset();
1238  assign( left, tmp );
1239 
1240  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1241 
1242  return *this;
1243 }
1244 //*************************************************************************************************
1245 
1246 
1247 //*************************************************************************************************
1261 template< typename MT // Type of the sparse matrix
1262  , bool SO // Storage order
1263  , bool SF > // Symmetry flag
1264 template< typename Other > // Data type of the right-hand side scalar
1265 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,SO,SF> >::Type&
1267 {
1269 
1270  for( Iterator element=begin(); element!=end(); ++element )
1271  element->value() *= rhs;
1272  return *this;
1273 }
1274 //*************************************************************************************************
1275 
1276 
1277 //*************************************************************************************************
1294 template< typename MT // Type of the sparse matrix
1295  , bool SO // Storage order
1296  , bool SF > // Symmetry flag
1297 template< typename Other > // Data type of the right-hand side scalar
1298 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,SO,SF> >::Type&
1300 {
1302 
1303  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1304 
1305  typedef typename DivTrait<ElementType,Other>::Type DT;
1306  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1307 
1308  // Depending on the two involved data types, an integer division is applied or a
1309  // floating point division is selected.
1311  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1312  for( Iterator element=begin(); element!=end(); ++element )
1313  element->value() *= tmp;
1314  }
1315  else {
1316  for( Iterator element=begin(); element!=end(); ++element )
1317  element->value() /= rhs;
1318  }
1319 
1320  return *this;
1321 }
1322 //*************************************************************************************************
1323 
1324 
1325 
1326 
1327 //=================================================================================================
1328 //
1329 // UTILITY FUNCTIONS
1330 //
1331 //=================================================================================================
1332 
1333 //*************************************************************************************************
1338 template< typename MT // Type of the sparse matrix
1339  , bool SO // Storage order
1340  , bool SF > // Symmetry flag
1341 inline size_t SparseRow<MT,SO,SF>::size() const
1342 {
1343  return matrix_.columns();
1344 }
1345 //*************************************************************************************************
1346 
1347 
1348 //*************************************************************************************************
1353 template< typename MT // Type of the sparse matrix
1354  , bool SO // Storage order
1355  , bool SF > // Symmetry flag
1356 inline size_t SparseRow<MT,SO,SF>::capacity() const
1357 {
1358  return matrix_.capacity( row_ );
1359 }
1360 //*************************************************************************************************
1361 
1362 
1363 //*************************************************************************************************
1371 template< typename MT // Type of the sparse matrix
1372  , bool SO // Storage order
1373  , bool SF > // Symmetry flag
1374 inline size_t SparseRow<MT,SO,SF>::nonZeros() const
1375 {
1376  return matrix_.nonZeros( row_ );
1377 }
1378 //*************************************************************************************************
1379 
1380 
1381 //*************************************************************************************************
1386 template< typename MT // Type of the sparse matrix
1387  , bool SO // Storage order
1388  , bool SF > // Symmetry flag
1390 {
1391  matrix_.reset( row_ );
1392 }
1393 //*************************************************************************************************
1394 
1395 
1396 //*************************************************************************************************
1407 template< typename MT // Type of the sparse matrix
1408  , bool SO // Storage order
1409  , bool SF > // Symmetry flag
1410 inline typename SparseRow<MT,SO,SF>::Iterator
1411  SparseRow<MT,SO,SF>::set( size_t index, const ElementType& value )
1412 {
1413  return matrix_.set( row_, index, value );
1414 }
1415 //*************************************************************************************************
1416 
1417 
1418 //*************************************************************************************************
1430 template< typename MT // Type of the sparse matrix
1431  , bool SO // Storage order
1432  , bool SF > // Symmetry flag
1433 inline typename SparseRow<MT,SO,SF>::Iterator
1434  SparseRow<MT,SO,SF>::insert( size_t index, const ElementType& value )
1435 {
1436  return matrix_.insert( row_, index, value );
1437 }
1438 //*************************************************************************************************
1439 
1440 
1441 //*************************************************************************************************
1449 template< typename MT // Type of the sparse matrix
1450  , bool SO // Storage order
1451  , bool SF > // Symmetry flag
1452 inline void SparseRow<MT,SO,SF>::erase( size_t index )
1453 {
1454  matrix_.erase( row_, index );
1455 }
1456 //*************************************************************************************************
1457 
1458 
1459 //*************************************************************************************************
1467 template< typename MT // Type of the sparse matrix
1468  , bool SO // Storage order
1469  , bool SF > // Symmetry flag
1471 {
1472  return matrix_.erase( row_, pos );
1473 }
1474 //*************************************************************************************************
1475 
1476 
1477 //*************************************************************************************************
1486 template< typename MT // Type of the sparse matrix
1487  , bool SO // Storage order
1488  , bool SF > // Symmetry flag
1489 inline typename SparseRow<MT,SO,SF>::Iterator
1491 {
1492  return matrix_.erase( row_, first, last );
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1506 template< typename MT // Type of the sparse matrix
1507  , bool SO // Storage order
1508  , bool SF > // Symmetry flag
1510 {
1511  matrix_.reserve( row_, n );
1512 }
1513 //*************************************************************************************************
1514 
1515 
1516 //*************************************************************************************************
1526 template< typename MT // Type of the sparse matrix
1527  , bool SO // Storage order
1528  , bool SF > // Symmetry flag
1529 template< typename Other > // Data type of the scalar value
1530 inline SparseRow<MT,SO,SF>& SparseRow<MT,SO,SF>::scale( const Other& scalar )
1531 {
1533 
1534  for( Iterator element=begin(); element!=end(); ++element )
1535  element->value() *= scalar;
1536  return *this;
1537 }
1538 //*************************************************************************************************
1539 
1540 
1541 //*************************************************************************************************
1549 template< typename MT // Type of the sparse matrix
1550  , bool SO // Storage order
1551  , bool SF > // Symmetry flag
1553 {
1554  using blaze::max;
1555  using blaze::min;
1556 
1557  size_t nonzeros( 2UL*capacity()+1UL );
1558  nonzeros = max( nonzeros, 7UL );
1559  nonzeros = min( nonzeros, size() );
1560 
1561  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1562 
1563  return nonzeros;
1564 }
1565 //*************************************************************************************************
1566 
1567 
1568 
1569 
1570 //=================================================================================================
1571 //
1572 // LOOKUP FUNCTIONS
1573 //
1574 //=================================================================================================
1575 
1576 //*************************************************************************************************
1589 template< typename MT // Type of the sparse matrix
1590  , bool SO // Storage order
1591  , bool SF > // Symmetry flag
1593 {
1594  return matrix_.find( row_, index );
1595 }
1596 //*************************************************************************************************
1597 
1598 
1599 //*************************************************************************************************
1612 template< typename MT // Type of the sparse matrix
1613  , bool SO // Storage order
1614  , bool SF > // Symmetry flag
1616 {
1617  return matrix_.find( row_, index );
1618 }
1619 //*************************************************************************************************
1620 
1621 
1622 //*************************************************************************************************
1634 template< typename MT // Type of the sparse matrix
1635  , bool SO // Storage order
1636  , bool SF > // Symmetry flag
1638 {
1639  return matrix_.lowerBound( row_, index );
1640 }
1641 //*************************************************************************************************
1642 
1643 
1644 //*************************************************************************************************
1656 template< typename MT // Type of the sparse matrix
1657  , bool SO // Storage order
1658  , bool SF > // Symmetry flag
1660 {
1661  return matrix_.lowerBound( row_, index );
1662 }
1663 //*************************************************************************************************
1664 
1665 
1666 //*************************************************************************************************
1678 template< typename MT // Type of the sparse matrix
1679  , bool SO // Storage order
1680  , bool SF > // Symmetry flag
1682 {
1683  return matrix_.upperBound( row_, index );
1684 }
1685 //*************************************************************************************************
1686 
1687 
1688 //*************************************************************************************************
1700 template< typename MT // Type of the sparse matrix
1701  , bool SO // Storage order
1702  , bool SF > // Symmetry flag
1704 {
1705  return matrix_.upperBound( row_, index );
1706 }
1707 //*************************************************************************************************
1708 
1709 
1710 
1711 
1712 //=================================================================================================
1713 //
1714 // LOW-LEVEL UTILITY FUNCTIONS
1715 //
1716 //=================================================================================================
1717 
1718 //*************************************************************************************************
1742 template< typename MT // Type of the sparse matrix
1743  , bool SO // Storage order
1744  , bool SF > // Symmetry flag
1745 inline void SparseRow<MT,SO,SF>::append( size_t index, const ElementType& value, bool check )
1746 {
1747  matrix_.append( row_, index, value, check );
1748 }
1749 //*************************************************************************************************
1750 
1751 
1752 
1753 
1754 //=================================================================================================
1755 //
1756 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1757 //
1758 //=================================================================================================
1759 
1760 //*************************************************************************************************
1770 template< typename MT // Type of the sparse matrix
1771  , bool SO // Storage order
1772  , bool SF > // Symmetry flag
1773 template< typename Other > // Data type of the foreign expression
1774 inline bool SparseRow<MT,SO,SF>::canAlias( const Other* alias ) const
1775 {
1776  return matrix_.isAliased( alias );
1777 }
1778 //*************************************************************************************************
1779 
1780 
1781 //*************************************************************************************************
1791 template< typename MT // Type of the sparse matrix
1792  , bool SO // Storage order
1793  , bool SF > // Symmetry flag
1794 template< typename Other > // Data type of the foreign expression
1795 inline bool SparseRow<MT,SO,SF>::isAliased( const Other* alias ) const
1796 {
1797  return matrix_.isAliased( alias );
1798 }
1799 //*************************************************************************************************
1800 
1801 
1802 //*************************************************************************************************
1813 template< typename MT // Type of the sparse matrix
1814  , bool SO // Storage order
1815  , bool SF > // Symmetry flag
1816 template< typename VT > // Type of the right-hand side dense vector
1818 {
1819  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1820  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1821 
1822  for( size_t j=0UL; j<size(); ++j )
1823  {
1824  if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
1825  matrix_.reserve( row_, extendCapacity() );
1826 
1827  matrix_.append( row_, j, (~rhs)[j], true );
1828  }
1829 }
1830 //*************************************************************************************************
1831 
1832 
1833 //*************************************************************************************************
1844 template< typename MT // Type of the sparse matrix
1845  , bool SO // Storage order
1846  , bool SF > // Symmetry flag
1847 template< typename VT > // Type of the right-hand side sparse vector
1849 {
1850  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1851  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1852 
1853  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1854  matrix_.append( row_, element->index(), element->value(), true );
1855  }
1856 }
1857 //*************************************************************************************************
1858 
1859 
1860 //*************************************************************************************************
1871 template< typename MT // Type of the sparse matrix
1872  , bool SO // Storage order
1873  , bool SF > // Symmetry flag
1874 template< typename VT > // Type of the right-hand side dense vector
1876 {
1877  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1878 
1882 
1883  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1884 
1885  const AddType tmp( serial( *this + (~rhs) ) );
1886  matrix_.reset( row_ );
1887  assign( tmp );
1888 }
1889 //*************************************************************************************************
1890 
1891 
1892 //*************************************************************************************************
1903 template< typename MT // Type of the sparse matrix
1904  , bool SO // Storage order
1905  , bool SF > // Symmetry flag
1906 template< typename VT > // Type of the right-hand side sparse vector
1908 {
1909  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1910 
1914 
1915  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1916 
1917  const AddType tmp( serial( *this + (~rhs) ) );
1918  matrix_.reset( row_ );
1919  matrix_.reserve( row_, tmp.nonZeros() );
1920  assign( tmp );
1921 }
1922 //*************************************************************************************************
1923 
1924 
1925 //*************************************************************************************************
1936 template< typename MT // Type of the sparse matrix
1937  , bool SO // Storage order
1938  , bool SF > // Symmetry flag
1939 template< typename VT > // Type of the right-hand side dense vector
1941 {
1942  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1943 
1947 
1948  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1949 
1950  const SubType tmp( serial( *this - (~rhs) ) );
1951  matrix_.reset( row_ );
1952  assign( tmp );
1953 }
1954 //*************************************************************************************************
1955 
1956 
1957 //*************************************************************************************************
1968 template< typename MT // Type of the sparse matrix
1969  , bool SO // Storage order
1970  , bool SF > // Symmetry flag
1971 template< typename VT > // Type of the right-hand side sparse vector
1973 {
1974  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1975 
1979 
1980  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1981 
1982  const SubType tmp( serial( *this - (~rhs) ) );
1983  matrix_.reset( row_ );
1984  matrix_.reserve( row_, tmp.nonZeros() );
1985  assign( tmp );
1986 }
1987 //*************************************************************************************************
1988 
1989 
1990 
1991 
1992 
1993 
1994 
1995 
1996 //=================================================================================================
1997 //
1998 // CLASS TEMPLATE SPECIALIZATION FOR GENERAL COLUMN-MAJOR MATRICES
1999 //
2000 //=================================================================================================
2001 
2002 //*************************************************************************************************
2010 template< typename MT > // Type of the sparse matrix
2011 class SparseRow<MT,false,false> : public SparseVector< SparseRow<MT,false,false>, true >
2012  , private Row
2013 {
2014  private:
2015  //**Type definitions****************************************************************************
2017  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
2018  //**********************************************************************************************
2019 
2020  public:
2021  //**Type definitions****************************************************************************
2023  typedef typename RowTrait<MT>::Type ResultType;
2024  typedef typename ResultType::TransposeType TransposeType;
2025  typedef typename MT::ElementType ElementType;
2026  typedef typename MT::ReturnType ReturnType;
2027  typedef const SparseRow& CompositeType;
2028 
2030  typedef typename MT::ConstReference ConstReference;
2031 
2033  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
2034  //**********************************************************************************************
2035 
2036  //**RowElement class definition*****************************************************************
2039  template< typename MatrixType // Type of the sparse matrix
2040  , typename IteratorType > // Type of the sparse matrix iterator
2041  class RowElement : private SparseElement
2042  {
2043  private:
2044  //*******************************************************************************************
2046 
2051  enum { returnConst = IsConst<MatrixType>::value };
2052  //*******************************************************************************************
2053 
2054  //**Type definitions*************************************************************************
2056  typedef typename std::iterator_traits<IteratorType>::value_type SET;
2057 
2058  typedef typename SET::Reference RT;
2059  typedef typename SET::ConstReference CRT;
2060  //*******************************************************************************************
2061 
2062  public:
2063  //**Type definitions*************************************************************************
2064  typedef typename SET::ValueType ValueType;
2065  typedef size_t IndexType;
2066  typedef typename IfTrue<returnConst,CRT,RT>::Type Reference;
2067  typedef CRT ConstReference;
2068  //*******************************************************************************************
2069 
2070  //**Constructor******************************************************************************
2076  inline RowElement( IteratorType pos, size_t column )
2077  : pos_ ( pos ) // Iterator to the current position within the sparse row
2078  , column_( column ) // Index of the according column
2079  {}
2080  //*******************************************************************************************
2081 
2082  //**Assignment operator**********************************************************************
2088  template< typename T > inline RowElement& operator=( const T& v ) {
2089  *pos_ = v;
2090  return *this;
2091  }
2092  //*******************************************************************************************
2093 
2094  //**Addition assignment operator*************************************************************
2100  template< typename T > inline RowElement& operator+=( const T& v ) {
2101  *pos_ += v;
2102  return *this;
2103  }
2104  //*******************************************************************************************
2105 
2106  //**Subtraction assignment operator**********************************************************
2112  template< typename T > inline RowElement& operator-=( const T& v ) {
2113  *pos_ -= v;
2114  return *this;
2115  }
2116  //*******************************************************************************************
2117 
2118  //**Multiplication assignment operator*******************************************************
2124  template< typename T > inline RowElement& operator*=( const T& v ) {
2125  *pos_ *= v;
2126  return *this;
2127  }
2128  //*******************************************************************************************
2129 
2130  //**Division assignment operator*************************************************************
2136  template< typename T > inline RowElement& operator/=( const T& v ) {
2137  *pos_ /= v;
2138  return *this;
2139  }
2140  //*******************************************************************************************
2141 
2142  //**Element access operator******************************************************************
2147  inline const RowElement* operator->() const {
2148  return this;
2149  }
2150  //*******************************************************************************************
2151 
2152  //**Value function***************************************************************************
2157  inline Reference value() const {
2158  return pos_->value();
2159  }
2160  //*******************************************************************************************
2161 
2162  //**Index function***************************************************************************
2167  inline IndexType index() const {
2168  return column_;
2169  }
2170  //*******************************************************************************************
2171 
2172  private:
2173  //**Member variables*************************************************************************
2174  IteratorType pos_;
2175  size_t column_;
2176  //*******************************************************************************************
2177  };
2178  //**********************************************************************************************
2179 
2180  //**RowIterator class definition****************************************************************
2183  template< typename MatrixType // Type of the sparse matrix
2184  , typename IteratorType > // Type of the sparse matrix iterator
2185  class RowIterator
2186  {
2187  public:
2188  //**Type definitions*************************************************************************
2189  typedef std::forward_iterator_tag IteratorCategory;
2190  typedef RowElement<MatrixType,IteratorType> ValueType;
2191  typedef ValueType PointerType;
2192  typedef ValueType ReferenceType;
2193  typedef ptrdiff_t DifferenceType;
2194 
2195  // STL iterator requirements
2196  typedef IteratorCategory iterator_category;
2197  typedef ValueType value_type;
2198  typedef PointerType pointer;
2199  typedef ReferenceType reference;
2200  typedef DifferenceType difference_type;
2201  //*******************************************************************************************
2202 
2203  //**Constructor******************************************************************************
2206  inline RowIterator()
2207  : matrix_( NULL ) // The sparse matrix containing the row.
2208  , row_ ( 0UL ) // The current row index.
2209  , column_( 0UL ) // The current column index.
2210  , pos_ () // Iterator to the current sparse element.
2211  {}
2212  //*******************************************************************************************
2213 
2214  //**Constructor******************************************************************************
2221  inline RowIterator( MatrixType& matrix, size_t row, size_t column )
2222  : matrix_( &matrix ) // The sparse matrix containing the row.
2223  , row_ ( row ) // The current row index.
2224  , column_( column ) // The current column index.
2225  , pos_ () // Iterator to the current sparse element.
2226  {
2227  for( ; column_<matrix_->columns(); ++column_ ) {
2228  pos_ = matrix_->find( row_, column_ );
2229  if( pos_ != matrix_->end( column_ ) ) break;
2230  }
2231  }
2232  //*******************************************************************************************
2233 
2234  //**Constructor******************************************************************************
2242  inline RowIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2243  : matrix_( &matrix ) // The sparse matrix containing the row.
2244  , row_ ( row ) // The current row index.
2245  , column_( column ) // The current column index.
2246  , pos_ ( pos ) // Iterator to the current sparse element.
2247  {
2248  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
2249  }
2250  //*******************************************************************************************
2251 
2252  //**Constructor******************************************************************************
2257  template< typename MatrixType2, typename IteratorType2 >
2258  inline RowIterator( const RowIterator<MatrixType2,IteratorType2>& it )
2259  : matrix_( it.matrix_ ) // The sparse matrix containing the row.
2260  , row_ ( it.row_ ) // The current row index.
2261  , column_( it.column_ ) // The current column index.
2262  , pos_ ( it.pos_ ) // Iterator to the current sparse element.
2263  {}
2264  //*******************************************************************************************
2265 
2266  //**Prefix increment operator****************************************************************
2271  inline RowIterator& operator++() {
2272  ++column_;
2273  for( ; column_<matrix_->columns(); ++column_ ) {
2274  pos_ = matrix_->find( row_, column_ );
2275  if( pos_ != matrix_->end( column_ ) ) break;
2276  }
2277 
2278  return *this;
2279  }
2280  //*******************************************************************************************
2281 
2282  //**Postfix increment operator***************************************************************
2287  inline const RowIterator operator++( int ) {
2288  const RowIterator tmp( *this );
2289  ++(*this);
2290  return tmp;
2291  }
2292  //*******************************************************************************************
2293 
2294  //**Element access operator******************************************************************
2299  inline ReferenceType operator*() const {
2300  return ReferenceType( pos_, column_ );
2301  }
2302  //*******************************************************************************************
2303 
2304  //**Element access operator******************************************************************
2309  inline PointerType operator->() const {
2310  return PointerType( pos_, column_ );
2311  }
2312  //*******************************************************************************************
2313 
2314  //**Equality operator************************************************************************
2320  template< typename MatrixType2, typename IteratorType2 >
2321  inline bool operator==( const RowIterator<MatrixType2,IteratorType2>& rhs ) const {
2322  return ( matrix_ == rhs.matrix_ ) && ( row_ == rhs.row_ ) && ( column_ == rhs.column_ );
2323  }
2324  //*******************************************************************************************
2325 
2326  //**Inequality operator**********************************************************************
2332  template< typename MatrixType2, typename IteratorType2 >
2333  inline bool operator!=( const RowIterator<MatrixType2,IteratorType2>& rhs ) const {
2334  return !( *this == rhs );
2335  }
2336  //*******************************************************************************************
2337 
2338  //**Subtraction operator*********************************************************************
2344  inline DifferenceType operator-( const RowIterator& rhs ) const {
2345  size_t counter( 0UL );
2346  for( size_t j=rhs.column_; j<column_; ++j ) {
2347  if( matrix_->find( row_, j ) != matrix_->end( j ) )
2348  ++counter;
2349  }
2350  return counter;
2351  }
2352  //*******************************************************************************************
2353 
2354  private:
2355  //**Member variables*************************************************************************
2356  MatrixType* matrix_;
2357  size_t row_;
2358  size_t column_;
2359  IteratorType pos_;
2360  //*******************************************************************************************
2361 
2362  //**Friend declarations**********************************************************************
2363  template< typename MatrixType2, typename IteratorType2 > friend class RowIterator;
2364  template< typename MT2, bool SO2, bool SF2 > friend class SparseRow;
2365  //*******************************************************************************************
2366  };
2367  //**********************************************************************************************
2368 
2369  //**Type definitions****************************************************************************
2371  typedef RowIterator<const MT,typename MT::ConstIterator> ConstIterator;
2372 
2374  typedef typename If< IsConst<MT>, ConstIterator, RowIterator<MT,typename MT::Iterator> >::Type Iterator;
2375  //**********************************************************************************************
2376 
2377  //**Compilation flags***************************************************************************
2379  enum { smpAssignable = 0 };
2380  //**********************************************************************************************
2381 
2382  //**Constructors********************************************************************************
2385  explicit inline SparseRow( MT& matrix, size_t index );
2386  // No explicitly declared copy constructor.
2388  //**********************************************************************************************
2389 
2390  //**Destructor**********************************************************************************
2391  // No explicitly declared destructor.
2392  //**********************************************************************************************
2393 
2394  //**Data access functions***********************************************************************
2397  inline Reference operator[]( size_t index );
2398  inline ConstReference operator[]( size_t index ) const;
2399  inline Reference at( size_t index );
2400  inline ConstReference at( size_t index ) const;
2401  inline Iterator begin ();
2402  inline ConstIterator begin () const;
2403  inline ConstIterator cbegin() const;
2404  inline Iterator end ();
2405  inline ConstIterator end () const;
2406  inline ConstIterator cend () const;
2408  //**********************************************************************************************
2409 
2410  //**Assignment operators************************************************************************
2413  inline SparseRow& operator= ( const SparseRow& rhs );
2414  template< typename VT > inline SparseRow& operator= ( const Vector<VT,true>& rhs );
2415  template< typename VT > inline SparseRow& operator+=( const Vector<VT,true>& rhs );
2416  template< typename VT > inline SparseRow& operator-=( const Vector<VT,true>& rhs );
2417  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
2418 
2419  template< typename Other >
2420  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
2421  operator*=( Other rhs );
2422 
2423  template< typename Other >
2424  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
2425  operator/=( Other rhs );
2427  //**********************************************************************************************
2428 
2429  //**Utility functions***************************************************************************
2432  inline size_t size() const;
2433  inline size_t capacity() const;
2434  inline size_t nonZeros() const;
2435  inline void reset();
2436  inline Iterator set ( size_t index, const ElementType& value );
2437  inline Iterator insert ( size_t index, const ElementType& value );
2438  inline void erase ( size_t index );
2439  inline Iterator erase ( Iterator pos );
2440  inline Iterator erase ( Iterator first, Iterator last );
2441  inline void reserve( size_t n );
2442  template< typename Other > inline SparseRow& scale ( const Other& scalar );
2444  //**********************************************************************************************
2445 
2446  //**Lookup functions****************************************************************************
2449  inline Iterator find ( size_t index );
2450  inline ConstIterator find ( size_t index ) const;
2451  inline Iterator lowerBound( size_t index );
2452  inline ConstIterator lowerBound( size_t index ) const;
2453  inline Iterator upperBound( size_t index );
2454  inline ConstIterator upperBound( size_t index ) const;
2456  //**********************************************************************************************
2457 
2458  //**Low-level utility functions*****************************************************************
2461  inline void append( size_t index, const ElementType& value, bool check=false );
2463  //**********************************************************************************************
2464 
2465  //**Expression template evaluation functions****************************************************
2468  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2469  template< typename Other > inline bool isAliased( const Other* alias ) const;
2470 
2471  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
2472  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
2473  template< typename VT > inline void addAssign( const Vector<VT,true>& rhs );
2474  template< typename VT > inline void subAssign( const Vector<VT,true>& rhs );
2476  //**********************************************************************************************
2477 
2478  private:
2479  //**Member variables****************************************************************************
2482  Operand matrix_;
2483  const size_t row_;
2484 
2485  //**********************************************************************************************
2486 
2487  //**Friend declarations*************************************************************************
2488  template< typename MT2, bool SO2, bool SF2 >
2489  friend bool isIntact( const SparseRow<MT2,SO2,SF2>& row );
2490 
2491  template< typename MT2, bool SO2, bool SF2 >
2492  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
2493 
2494  template< typename MT2, bool SO2, bool SF2, typename VT >
2495  friend bool tryAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
2496 
2497  template< typename MT2, bool SO2, bool SF2, typename VT >
2498  friend bool tryAddAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
2499 
2500  template< typename MT2, bool SO2, bool SF2, typename VT >
2501  friend bool trySubAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
2502 
2503  template< typename MT2, bool SO2, bool SF2, typename VT >
2504  friend bool tryMultAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
2505 
2506  template< typename MT2, bool SO2, bool SF2 >
2507  friend typename DerestrictTrait< SparseRow<MT2,SO2,SF2> >::Type
2508  derestrict( SparseRow<MT2,SO2,SF2>& dm );
2509  //**********************************************************************************************
2510 
2511  //**Compile time checks*************************************************************************
2519  //**********************************************************************************************
2520 };
2522 //*************************************************************************************************
2523 
2524 
2525 
2526 
2527 //=================================================================================================
2528 //
2529 // CONSTRUCTOR
2530 //
2531 //=================================================================================================
2532 
2533 //*************************************************************************************************
2541 template< typename MT > // Type of the sparse matrix
2542 inline SparseRow<MT,false,false>::SparseRow( MT& matrix, size_t index )
2543  : matrix_( matrix ) // The sparse matrix containing the row
2544  , row_ ( index ) // The index of the row in the matrix
2545 {
2546  if( matrix_.rows() <= index ) {
2547  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
2548  }
2549 }
2551 //*************************************************************************************************
2552 
2553 
2554 
2555 
2556 //=================================================================================================
2557 //
2558 // DATA ACCESS FUNCTIONS
2559 //
2560 //=================================================================================================
2561 
2562 //*************************************************************************************************
2572 template< typename MT > // Type of the sparse matrix
2575 {
2576  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2577  return matrix_(row_,index);
2578 }
2580 //*************************************************************************************************
2581 
2582 
2583 //*************************************************************************************************
2593 template< typename MT > // Type of the sparse matrix
2595  SparseRow<MT,false,false>::operator[]( size_t index ) const
2596 {
2597  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2598  return const_cast<const MT&>( matrix_ )(row_,index);
2599 }
2601 //*************************************************************************************************
2602 
2603 
2604 //*************************************************************************************************
2615 template< typename MT > // Type of the sparse matrix
2617  SparseRow<MT,false,false>::at( size_t index )
2618 {
2619  if( index >= size() ) {
2620  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2621  }
2622  return (*this)[index];
2623 }
2625 //*************************************************************************************************
2626 
2627 
2628 //*************************************************************************************************
2639 template< typename MT > // Type of the sparse matrix
2641  SparseRow<MT,false,false>::at( size_t index ) const
2642 {
2643  if( index >= size() ) {
2644  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
2645  }
2646  return (*this)[index];
2647 }
2649 //*************************************************************************************************
2650 
2651 
2652 //*************************************************************************************************
2660 template< typename MT > // Type of the sparse matrix
2662 {
2663  return Iterator( matrix_, row_, 0UL );
2664 }
2666 //*************************************************************************************************
2667 
2668 
2669 //*************************************************************************************************
2677 template< typename MT > // Type of the sparse matrix
2679 {
2680  return ConstIterator( matrix_, row_, 0UL );
2681 }
2683 //*************************************************************************************************
2684 
2685 
2686 //*************************************************************************************************
2694 template< typename MT > // Type of the sparse matrix
2696 {
2697  return ConstIterator( matrix_, row_, 0UL );
2698 }
2700 //*************************************************************************************************
2701 
2702 
2703 //*************************************************************************************************
2711 template< typename MT > // Type of the sparse matrix
2713 {
2714  return Iterator( matrix_, row_, size() );
2715 }
2717 //*************************************************************************************************
2718 
2719 
2720 //*************************************************************************************************
2728 template< typename MT > // Type of the sparse matrix
2730 {
2731  return ConstIterator( matrix_, row_, size() );
2732 }
2734 //*************************************************************************************************
2735 
2736 
2737 //*************************************************************************************************
2745 template< typename MT > // Type of the sparse matrix
2747 {
2748  return ConstIterator( matrix_, row_, size() );
2749 }
2751 //*************************************************************************************************
2752 
2753 
2754 
2755 
2756 //=================================================================================================
2757 //
2758 // ASSIGNMENT OPERATORS
2759 //
2760 //=================================================================================================
2761 
2762 //*************************************************************************************************
2776 template< typename MT > // Type of the sparse matrix
2777 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator=( const SparseRow& rhs )
2778 {
2779  using blaze::assign;
2780 
2784 
2785  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
2786  return *this;
2787 
2788  if( size() != rhs.size() ) {
2789  BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
2790  }
2791 
2792  if( !tryAssign( matrix_, rhs, row_, 0UL ) ) {
2793  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2794  }
2795 
2796  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2797 
2798  if( rhs.canAlias( &matrix_ ) ) {
2799  const ResultType tmp( rhs );
2800  assign( left, tmp );
2801  }
2802  else {
2803  assign( left, rhs );
2804  }
2805 
2806  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2807 
2808  return *this;
2809 }
2811 //*************************************************************************************************
2812 
2813 
2814 //*************************************************************************************************
2828 template< typename MT > // Type of the sparse matrix
2829 template< typename VT > // Type of the right-hand side vector
2830 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator=( const Vector<VT,true>& rhs )
2831 {
2832  using blaze::assign;
2833 
2834  if( size() != (~rhs).size() ) {
2835  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2836  }
2837 
2838  const typename VT::CompositeType tmp( ~rhs );
2839 
2840  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
2841  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2842  }
2843 
2844  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2845 
2846  assign( left, tmp );
2847 
2848  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2849 
2850  return *this;
2851 }
2853 //*************************************************************************************************
2854 
2855 
2856 //*************************************************************************************************
2870 template< typename MT > // Type of the sparse matrix
2871 template< typename VT > // Type of the right-hand side vector
2872 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator+=( const Vector<VT,true>& rhs )
2873 {
2874  using blaze::assign;
2875 
2881 
2882  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
2883 
2886 
2887  if( size() != (~rhs).size() ) {
2888  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2889  }
2890 
2891  const AddType tmp( *this + (~rhs) );
2892 
2893  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
2894  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2895  }
2896 
2897  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2898 
2899  assign( left, tmp );
2900 
2901  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2902 
2903  return *this;
2904 }
2906 //*************************************************************************************************
2907 
2908 
2909 //*************************************************************************************************
2923 template< typename MT > // Type of the sparse matrix
2924 template< typename VT > // Type of the right-hand side vector
2925 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator-=( const Vector<VT,true>& rhs )
2926 {
2927  using blaze::assign;
2928 
2934 
2935  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
2936 
2939 
2940  if( size() != (~rhs).size() ) {
2941  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2942  }
2943 
2944  const SubType tmp( *this - (~rhs) );
2945 
2946  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
2947  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2948  }
2949 
2950  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2951 
2952  assign( left, tmp );
2953 
2954  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2955 
2956  return *this;
2957 }
2959 //*************************************************************************************************
2960 
2961 
2962 //*************************************************************************************************
2975 template< typename MT > // Type of the sparse matrix
2976 template< typename VT > // Type of the right-hand side vector
2977 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator*=( const Vector<VT,true>& rhs )
2978 {
2979  using blaze::assign;
2980 
2986 
2987  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
2988 
2991 
2992  if( size() != (~rhs).size() ) {
2993  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2994  }
2995 
2996  const MultType tmp( *this * (~rhs) );
2997 
2998  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
2999  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3000  }
3001 
3002  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3003 
3004  assign( left, tmp );
3005 
3006  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3007 
3008  return *this;
3009 }
3011 //*************************************************************************************************
3012 
3013 
3014 //*************************************************************************************************
3029 template< typename MT > // Type of the sparse matrix
3030 template< typename Other > // Data type of the right-hand side scalar
3031 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
3032  SparseRow<MT,false,false>::operator*=( Other rhs )
3033 {
3035 
3036  for( Iterator element=begin(); element!=end(); ++element )
3037  element->value() *= rhs;
3038  return *this;
3039 }
3041 //*************************************************************************************************
3042 
3043 
3044 //*************************************************************************************************
3062 template< typename MT > // Type of the sparse matrix
3063 template< typename Other > // Data type of the right-hand side scalar
3064 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
3065  SparseRow<MT,false,false>::operator/=( Other rhs )
3066 {
3068 
3069  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3070 
3071  typedef typename DivTrait<ElementType,Other>::Type DT;
3072  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3073 
3074  // Depending on the two involved data types, an integer division is applied or a
3075  // floating point division is selected.
3076  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3077  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3078  for( Iterator element=begin(); element!=end(); ++element )
3079  element->value() *= tmp;
3080  }
3081  else {
3082  for( Iterator element=begin(); element!=end(); ++element )
3083  element->value() /= rhs;
3084  }
3085 
3086  return *this;
3087 }
3089 //*************************************************************************************************
3090 
3091 
3092 
3093 
3094 //=================================================================================================
3095 //
3096 // UTILITY FUNCTIONS
3097 //
3098 //=================================================================================================
3099 
3100 //*************************************************************************************************
3106 template< typename MT > // Type of the sparse matrix
3107 inline size_t SparseRow<MT,false,false>::size() const
3108 {
3109  return matrix_.columns();
3110 }
3112 //*************************************************************************************************
3113 
3114 
3115 //*************************************************************************************************
3121 template< typename MT > // Type of the sparse matrix
3122 inline size_t SparseRow<MT,false,false>::capacity() const
3123 {
3124  return matrix_.columns();
3125 }
3127 //*************************************************************************************************
3128 
3129 
3130 //*************************************************************************************************
3139 template< typename MT > // Type of the sparse matrix
3140 inline size_t SparseRow<MT,false,false>::nonZeros() const
3141 {
3142  size_t counter( 0UL );
3143  for( ConstIterator element=begin(); element!=end(); ++element ) {
3144  ++counter;
3145  }
3146  return counter;
3147 }
3149 //*************************************************************************************************
3150 
3151 
3152 //*************************************************************************************************
3158 template< typename MT > // Type of the sparse matrix
3160 {
3161  const size_t jbegin( ( IsUpper<MT>::value )
3162  ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
3163  ?( row_+1UL )
3164  :( row_ ) )
3165  :( 0UL ) );
3166  const size_t jend ( ( IsLower<MT>::value )
3167  ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
3168  ?( row_ )
3169  :( row_+1UL ) )
3170  :( size() ) );
3171 
3172  for( size_t j=jbegin; j<jend; ++j ) {
3173  matrix_.erase( row_, j );
3174  }
3175 }
3177 //*************************************************************************************************
3178 
3179 
3180 //*************************************************************************************************
3193 template< typename MT > // Type of the sparse matrix
3195  SparseRow<MT,false,false>::insert( size_t index, const ElementType& value )
3196 {
3197  return Iterator( matrix_, row_, index, matrix_.insert( row_, index, value ) );
3198 }
3200 //*************************************************************************************************
3201 
3202 
3203 //*************************************************************************************************
3215 template< typename MT > // Type of the sparse matrix
3217  SparseRow<MT,false,false>::set( size_t index, const ElementType& value )
3218 {
3219  return Iterator( matrix_, row_, index, matrix_.set( row_, index, value ) );
3220 }
3222 //*************************************************************************************************
3223 
3224 
3225 //*************************************************************************************************
3234 template< typename MT > // Type of the sparse matrix
3235 inline void SparseRow<MT,false,false>::erase( size_t index )
3236 {
3237  matrix_.erase( row_, index );
3238 }
3240 //*************************************************************************************************
3241 
3242 
3243 //*************************************************************************************************
3252 template< typename MT > // Type of the sparse matrix
3254 {
3255  const size_t column( pos.column_ );
3256 
3257  if( column == size() )
3258  return pos;
3259 
3260  matrix_.erase( column, pos.pos_ );
3261  return Iterator( matrix_, row_, column+1UL );
3262 }
3264 //*************************************************************************************************
3265 
3266 
3267 //*************************************************************************************************
3277 template< typename MT > // Type of the sparse matrix
3280 {
3281  for( ; first!=last; ++first ) {
3282  matrix_.erase( first.column_, first.pos_ );
3283  }
3284  return last;
3285 }
3287 //*************************************************************************************************
3288 
3289 
3290 //*************************************************************************************************
3300 template< typename MT > // Type of the sparse matrix
3301 void SparseRow<MT,false,false>::reserve( size_t n )
3302 {
3303  UNUSED_PARAMETER( n );
3304 
3305  return;
3306 }
3308 //*************************************************************************************************
3309 
3310 
3311 //*************************************************************************************************
3322 template< typename MT > // Type of the sparse matrix
3323 template< typename Other > // Data type of the scalar value
3324 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::scale( const Other& scalar )
3325 {
3327 
3328  for( Iterator element=begin(); element!=end(); ++element )
3329  element->value() *= scalar;
3330  return *this;
3331 }
3333 //*************************************************************************************************
3334 
3335 
3336 
3337 
3338 //=================================================================================================
3339 //
3340 // LOOKUP FUNCTIONS
3341 //
3342 //=================================================================================================
3343 
3344 //*************************************************************************************************
3358 template< typename MT > // Type of the sparse matrix
3360 {
3361  const typename MT::Iterator pos( matrix_.find( row_, index ) );
3362 
3363  if( pos != matrix_.end( index ) )
3364  return Iterator( matrix_, row_, index, pos );
3365  else
3366  return end();
3367 }
3369 //*************************************************************************************************
3370 
3371 
3372 //*************************************************************************************************
3386 template< typename MT > // Type of the sparse matrix
3388  SparseRow<MT,false,false>::find( size_t index ) const
3389 {
3390  const typename MT::ConstIterator pos( matrix_.find( row_, index ) );
3391 
3392  if( pos != matrix_.end( index ) )
3393  return ConstIterator( matrix_, row_, index, pos );
3394  else
3395  return end();
3396 }
3398 //*************************************************************************************************
3399 
3400 
3401 //*************************************************************************************************
3414 template< typename MT > // Type of the sparse matrix
3417 {
3418  for( size_t i=index; i<size(); ++i )
3419  {
3420  const typename MT::Iterator pos( matrix_.find( row_, i ) );
3421 
3422  if( pos != matrix_.end( i ) )
3423  return Iterator( matrix_, row_, i, pos );
3424  }
3425 
3426  return end();
3427 }
3429 //*************************************************************************************************
3430 
3431 
3432 //*************************************************************************************************
3445 template< typename MT > // Type of the sparse matrix
3447  SparseRow<MT,false,false>::lowerBound( size_t index ) const
3448 {
3449  for( size_t i=index; i<size(); ++i )
3450  {
3451  const typename MT::ConstIterator pos( matrix_.find( row_, i ) );
3452 
3453  if( pos != matrix_.end( i ) )
3454  return ConstIterator( matrix_, row_, i, pos );
3455  }
3456 
3457  return end();
3458 }
3460 //*************************************************************************************************
3461 
3462 
3463 //*************************************************************************************************
3476 template< typename MT > // Type of the sparse matrix
3479 {
3480  for( size_t i=index+1UL; i<size(); ++i )
3481  {
3482  const typename MT::Iterator pos( matrix_.find( row_, i ) );
3483 
3484  if( pos != matrix_.end( i ) )
3485  return Iterator( matrix_, row_, i, pos );
3486  }
3487 
3488  return end();
3489 }
3491 //*************************************************************************************************
3492 
3493 
3494 //*************************************************************************************************
3507 template< typename MT > // Type of the sparse matrix
3509  SparseRow<MT,false,false>::upperBound( size_t index ) const
3510 {
3511  for( size_t i=index+1UL; i<size(); ++i )
3512  {
3513  const typename MT::ConstIterator pos( matrix_.find( row_, i ) );
3514 
3515  if( pos != matrix_.end( i ) )
3516  return ConstIterator( matrix_, row_, i, pos );
3517  }
3518 
3519  return end();
3520 }
3522 //*************************************************************************************************
3523 
3524 
3525 
3526 
3527 //=================================================================================================
3528 //
3529 // LOW-LEVEL UTILITY FUNCTIONS
3530 //
3531 //=================================================================================================
3532 
3533 //*************************************************************************************************
3558 template< typename MT > // Type of the sparse matrix
3559 inline void SparseRow<MT,false,false>::append( size_t index, const ElementType& value, bool check )
3560 {
3561  if( !check || !isDefault( value ) )
3562  matrix_.insert( row_, index, value );
3563 }
3565 //*************************************************************************************************
3566 
3567 
3568 
3569 
3570 //=================================================================================================
3571 //
3572 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3573 //
3574 //=================================================================================================
3575 
3576 //*************************************************************************************************
3587 template< typename MT > // Type of the sparse matrix
3588 template< typename Other > // Data type of the foreign expression
3589 inline bool SparseRow<MT,false,false>::canAlias( const Other* alias ) const
3590 {
3591  return matrix_.isAliased( alias );
3592 }
3594 //*************************************************************************************************
3595 
3596 
3597 //*************************************************************************************************
3604 template< typename MT > // Type of the sparse matrix
3605 template< typename Other > // Data type of the foreign expression
3606 inline bool SparseRow<MT,false,false>::isAliased( const Other* alias ) const
3607 {
3608  return matrix_.isAliased( alias );
3609 }
3611 //*************************************************************************************************
3612 
3613 
3614 //*************************************************************************************************
3626 template< typename MT > // Type of the sparse matrix
3627 template< typename VT > // Type of the right-hand side dense vector
3628 inline void SparseRow<MT,false,false>::assign( const DenseVector<VT,true>& rhs )
3629 {
3630  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3631 
3632  for( size_t j=0UL; j<(~rhs).size(); ++j ) {
3633  matrix_(row_,j) = (~rhs)[j];
3634  }
3635 }
3637 //*************************************************************************************************
3638 
3639 
3640 //*************************************************************************************************
3652 template< typename MT > // Type of the sparse matrix
3653 template< typename VT > // Type of the right-hand side sparse vector
3654 inline void SparseRow<MT,false,false>::assign( const SparseVector<VT,true>& rhs )
3655 {
3656  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3657 
3658  size_t j( 0UL );
3659 
3660  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
3661  for( ; j<element->index(); ++j )
3662  matrix_.erase( row_, j );
3663  matrix_(row_,j++) = element->value();
3664  }
3665  for( ; j<size(); ++j ) {
3666  matrix_.erase( row_, j );
3667  }
3668 }
3670 //*************************************************************************************************
3671 
3672 
3673 //*************************************************************************************************
3685 template< typename MT > // Type of the sparse matrix
3686 template< typename VT > // Type of the right-hand side vector
3687 inline void SparseRow<MT,false,false>::addAssign( const Vector<VT,true>& rhs )
3688 {
3689  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3690 
3693 
3694  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3695 
3696  const AddType tmp( serial( *this + (~rhs) ) );
3697  assign( tmp );
3698 }
3700 //*************************************************************************************************
3701 
3702 
3703 //*************************************************************************************************
3715 template< typename MT > // Type of the sparse matrix
3716 template< typename VT > // Type of the right-hand side vector
3717 inline void SparseRow<MT,false,false>::subAssign( const Vector<VT,true>& rhs )
3718 {
3719  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3720 
3723 
3724  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3725 
3726  const SubType tmp( serial( *this - (~rhs) ) );
3727  assign( tmp );
3728 }
3730 //*************************************************************************************************
3731 
3732 
3733 
3734 
3735 
3736 
3737 
3738 
3739 //=================================================================================================
3740 //
3741 // CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC COLUMN-MAJOR MATRICES
3742 //
3743 //=================================================================================================
3744 
3745 //*************************************************************************************************
3753 template< typename MT > // Type of the sparse matrix
3754 class SparseRow<MT,false,true> : public SparseVector< SparseRow<MT,false,true>, true >
3755  , private Row
3756 {
3757  private:
3758  //**Type definitions****************************************************************************
3760  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
3761  //**********************************************************************************************
3762 
3763  public:
3764  //**Type definitions****************************************************************************
3765  typedef SparseRow<MT,false,true> This;
3766  typedef typename RowTrait<MT>::Type ResultType;
3767  typedef typename ResultType::TransposeType TransposeType;
3768  typedef typename MT::ElementType ElementType;
3769  typedef typename MT::ReturnType ReturnType;
3770  typedef const SparseRow& CompositeType;
3771 
3773  typedef typename MT::ConstReference ConstReference;
3774 
3776  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
3777 
3779  typedef typename MT::ConstIterator ConstIterator;
3780 
3782  typedef typename If< IsConst<MT>, ConstIterator, typename MT::Iterator >::Type Iterator;
3783  //**********************************************************************************************
3784 
3785  //**Compilation flags***************************************************************************
3787  enum { smpAssignable = 0 };
3788  //**********************************************************************************************
3789 
3790  //**Constructors********************************************************************************
3793  explicit inline SparseRow( MT& matrix, size_t index );
3794  // No explicitly declared copy constructor.
3796  //**********************************************************************************************
3797 
3798  //**Destructor**********************************************************************************
3799  // No explicitly declared destructor.
3800  //**********************************************************************************************
3801 
3802  //**Data access functions***********************************************************************
3805  inline Reference operator[]( size_t index );
3806  inline ConstReference operator[]( size_t index ) const;
3807  inline Reference at( size_t index );
3808  inline ConstReference at( size_t index ) const;
3809  inline Iterator begin ();
3810  inline ConstIterator begin () const;
3811  inline ConstIterator cbegin() const;
3812  inline Iterator end ();
3813  inline ConstIterator end () const;
3814  inline ConstIterator cend () const;
3816  //**********************************************************************************************
3817 
3818  //**Assignment operators************************************************************************
3821  inline SparseRow& operator=( const SparseRow& rhs );
3822 
3823  template< typename VT > inline SparseRow& operator= ( const DenseVector<VT,true>& rhs );
3824  template< typename VT > inline SparseRow& operator= ( const SparseVector<VT,true>& rhs );
3825  template< typename VT > inline SparseRow& operator+=( const DenseVector<VT,true>& rhs );
3826  template< typename VT > inline SparseRow& operator+=( const SparseVector<VT,true>& rhs );
3827  template< typename VT > inline SparseRow& operator-=( const DenseVector<VT,true>& rhs );
3828  template< typename VT > inline SparseRow& operator-=( const SparseVector<VT,true>& rhs );
3829  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
3830 
3831  template< typename Other >
3832  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
3833  operator*=( Other rhs );
3834 
3835  template< typename Other >
3836  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
3837  operator/=( Other rhs );
3839  //**********************************************************************************************
3840 
3841  //**Utility functions***************************************************************************
3844  inline size_t size() const;
3845  inline size_t capacity() const;
3846  inline size_t nonZeros() const;
3847  inline void reset();
3848  inline Iterator set ( size_t index, const ElementType& value );
3849  inline Iterator insert ( size_t index, const ElementType& value );
3850  inline void erase ( size_t index );
3851  inline Iterator erase ( Iterator pos );
3852  inline Iterator erase ( Iterator first, Iterator last );
3853  inline void reserve( size_t n );
3854  template< typename Other > inline SparseRow& scale ( const Other& scalar );
3856  //**********************************************************************************************
3857 
3858  //**Lookup functions****************************************************************************
3861  inline Iterator find ( size_t index );
3862  inline ConstIterator find ( size_t index ) const;
3863  inline Iterator lowerBound( size_t index );
3864  inline ConstIterator lowerBound( size_t index ) const;
3865  inline Iterator upperBound( size_t index );
3866  inline ConstIterator upperBound( size_t index ) const;
3868  //**********************************************************************************************
3869 
3870  //**Low-level utility functions*****************************************************************
3873  inline void append( size_t index, const ElementType& value, bool check=false );
3875  //**********************************************************************************************
3876 
3877  //**Expression template evaluation functions****************************************************
3880  template< typename Other > inline bool canAlias ( const Other* alias ) const;
3881  template< typename Other > inline bool isAliased( const Other* alias ) const;
3882 
3883  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
3884  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
3885  template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
3886  template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
3887  template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
3888  template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
3890  //**********************************************************************************************
3891 
3892  private:
3893  //**Utility functions***************************************************************************
3896  inline size_t extendCapacity() const;
3898  //**********************************************************************************************
3899 
3900  //**Member variables****************************************************************************
3903  Operand matrix_;
3904  const size_t row_;
3905 
3906  //**********************************************************************************************
3907 
3908  //**Friend declarations*************************************************************************
3909  template< typename MT2, bool SO2, bool SF2 >
3910  friend bool isIntact( const SparseRow<MT2,SO2,SF2>& row );
3911 
3912  template< typename MT2, bool SO2, bool SF2 >
3913  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
3914 
3915  template< typename MT2, bool SO2, bool SF2, typename VT >
3916  friend bool tryAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
3917 
3918  template< typename MT2, bool SO2, bool SF2, typename VT >
3919  friend bool tryAddAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
3920 
3921  template< typename MT2, bool SO2, bool SF2, typename VT >
3922  friend bool trySubAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
3923 
3924  template< typename MT2, bool SO2, bool SF2, typename VT >
3925  friend bool tryMultAssign( const SparseRow<MT2,SO2,SF2>& lhs, const Vector<VT,true>& rhs, size_t index );
3926 
3927  template< typename MT2, bool SO2, bool SF2 >
3928  friend typename DerestrictTrait< SparseRow<MT2,SO2,SF2> >::Type
3929  derestrict( SparseRow<MT2,SO2,SF2>& dm );
3930  //**********************************************************************************************
3931 
3932  //**Compile time checks*************************************************************************
3940  //**********************************************************************************************
3941 };
3943 //*************************************************************************************************
3944 
3945 
3946 
3947 
3948 //=================================================================================================
3949 //
3950 // CONSTRUCTOR
3951 //
3952 //=================================================================================================
3953 
3954 //*************************************************************************************************
3962 template< typename MT > // Type of the sparse matrix
3963 inline SparseRow<MT,false,true>::SparseRow( MT& matrix, size_t index )
3964  : matrix_( matrix ) // The sparse matrix containing the row
3965  , row_ ( index ) // The index of the row in the matrix
3966 {
3967  if( matrix_.rows() <= index ) {
3968  BLAZE_THROW_INVALID_ARGUMENT( "Invalid row access index" );
3969  }
3970 }
3972 //*************************************************************************************************
3973 
3974 
3975 
3976 
3977 //=================================================================================================
3978 //
3979 // DATA ACCESS FUNCTIONS
3980 //
3981 //=================================================================================================
3982 
3983 //*************************************************************************************************
3993 template< typename MT > // Type of the sparse matrix
3995  SparseRow<MT,false,true>::operator[]( size_t index )
3996 {
3997  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
3998  return matrix_(index,row_);
3999 }
4001 //*************************************************************************************************
4002 
4003 
4004 //*************************************************************************************************
4014 template< typename MT > // Type of the sparse matrix
4016  SparseRow<MT,false,true>::operator[]( size_t index ) const
4017 {
4018  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
4019  return const_cast<const MT&>( matrix_ )(index,row_);
4020 }
4022 //*************************************************************************************************
4023 
4024 
4025 //*************************************************************************************************
4036 template< typename MT > // Type of the sparse matrix
4038  SparseRow<MT,false,true>::at( size_t index )
4039 {
4040  if( index >= size() ) {
4041  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4042  }
4043  return (*this)[index];
4044 }
4046 //*************************************************************************************************
4047 
4048 
4049 //*************************************************************************************************
4060 template< typename MT > // Type of the sparse matrix
4062  SparseRow<MT,false,true>::at( size_t index ) const
4063 {
4064  if( index >= size() ) {
4065  BLAZE_THROW_OUT_OF_RANGE( "Invalid row access index" );
4066  }
4067  return (*this)[index];
4068 }
4070 //*************************************************************************************************
4071 
4072 
4073 //*************************************************************************************************
4081 template< typename MT > // Type of the sparse matrix
4083 {
4084  return matrix_.begin( row_ );
4085 }
4087 //*************************************************************************************************
4088 
4089 
4090 //*************************************************************************************************
4098 template< typename MT > // Type of the sparse matrix
4100 {
4101  return matrix_.cbegin( row_ );
4102 }
4104 //*************************************************************************************************
4105 
4106 
4107 //*************************************************************************************************
4115 template< typename MT > // Type of the sparse matrix
4117 {
4118  return matrix_.cbegin( row_ );
4119 }
4121 //*************************************************************************************************
4122 
4123 
4124 //*************************************************************************************************
4132 template< typename MT > // Type of the sparse matrix
4134 {
4135  return matrix_.end( row_ );
4136 }
4138 //*************************************************************************************************
4139 
4140 
4141 //*************************************************************************************************
4149 template< typename MT > // Type of the sparse matrix
4151 {
4152  return matrix_.cend( row_ );
4153 }
4155 //*************************************************************************************************
4156 
4157 
4158 //*************************************************************************************************
4166 template< typename MT > // Type of the sparse matrix
4168 {
4169  return matrix_.cend( row_ );
4170 }
4172 //*************************************************************************************************
4173 
4174 
4175 
4176 
4177 //=================================================================================================
4178 //
4179 // ASSIGNMENT OPERATORS
4180 //
4181 //=================================================================================================
4182 
4183 //*************************************************************************************************
4197 template< typename MT > // Type of the sparse matrix
4198 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::operator=( const SparseRow& rhs )
4199 {
4200  using blaze::assign;
4201 
4205 
4206  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
4207  return *this;
4208 
4209  if( size() != rhs.size() ) {
4210  BLAZE_THROW_INVALID_ARGUMENT( "Row sizes do not match" );
4211  }
4212 
4213  if( !tryAssign( matrix_, rhs, row_, 0UL ) ) {
4214  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4215  }
4216 
4217  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4218 
4219  if( rhs.canAlias( &matrix_ ) ) {
4220  const ResultType tmp( rhs );
4221  left.reset();
4222  left.reserve( tmp.nonZeros() );
4223  assign( left, tmp );
4224  }
4225  else {
4226  left.reset();
4227  left.reserve( rhs.nonZeros() );
4228  assign( left, rhs );
4229  }
4230 
4231  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4232 
4233  return *this;
4234 }
4236 //*************************************************************************************************
4237 
4238 
4239 //*************************************************************************************************
4253 template< typename MT > // Type of the sparse matrix
4254 template< typename VT > // Type of the right-hand side dense vector
4255 inline SparseRow<MT,false,true>&
4256  SparseRow<MT,false,true>::operator=( const DenseVector<VT,true>& rhs )
4257 {
4258  using blaze::assign;
4259 
4263 
4264  if( size() != (~rhs).size() ) {
4265  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4266  }
4267 
4268  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
4269  Right right( ~rhs );
4270 
4271  if( !tryAssign( matrix_, right, row_, 0UL ) ) {
4272  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4273  }
4274 
4275  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4276 
4277  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4278  const typename VT::ResultType tmp( right );
4279  left.reset();
4280  assign( left, tmp );
4281  }
4282  else {
4283  left.reset();
4284  assign( left, right );
4285  }
4286 
4287  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4288 
4289  return *this;
4290 }
4292 //*************************************************************************************************
4293 
4294 
4295 //*************************************************************************************************
4309 template< typename MT > // Type of the sparse matrix
4310 template< typename VT > // Type of the right-hand side sparse vector
4311 inline SparseRow<MT,false,true>&
4312  SparseRow<MT,false,true>::operator=( const SparseVector<VT,true>& rhs )
4313 {
4314  using blaze::assign;
4315 
4319 
4320  if( size() != (~rhs).size() ) {
4321  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4322  }
4323 
4324  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
4325  Right right( ~rhs );
4326 
4327  if( !tryAssign( matrix_, right, row_, 0UL ) ) {
4328  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4329  }
4330 
4331  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4332 
4333  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4334  const typename VT::ResultType tmp( right );
4335  left.reset();
4336  left.reserve( tmp.nonZeros() );
4337  assign( left, tmp );
4338  }
4339  else {
4340  left.reset();
4341  left.reserve( right.nonZeros() );
4342  assign( left, right );
4343  }
4344 
4345  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4346 
4347  return *this;
4348 }
4350 //*************************************************************************************************
4351 
4352 
4353 //*************************************************************************************************
4367 template< typename MT > // Type of the sparse matrix
4368 template< typename VT > // Type of the right-hand side dense vector
4369 inline SparseRow<MT,false,true>&
4370  SparseRow<MT,false,true>::operator+=( const DenseVector<VT,true>& rhs )
4371 {
4372  using blaze::assign;
4373 
4380 
4381  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4382 
4386 
4387  if( size() != (~rhs).size() ) {
4388  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4389  }
4390 
4391  const AddType tmp( *this + (~rhs) );
4392 
4393  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
4394  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4395  }
4396 
4397  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4398 
4399  left.reset();
4400  assign( left, tmp );
4401 
4402  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4403 
4404  return *this;
4405 }
4407 //*************************************************************************************************
4408 
4409 
4410 //*************************************************************************************************
4424 template< typename MT > // Type of the sparse matrix
4425 template< typename VT > // Type of the right-hand side sparse vector
4426 inline SparseRow<MT,false,true>&
4427  SparseRow<MT,false,true>::operator+=( const SparseVector<VT,true>& rhs )
4428 {
4429  using blaze::assign;
4430 
4437 
4438  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4439 
4443 
4444  if( size() != (~rhs).size() ) {
4445  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4446  }
4447 
4448  const AddType tmp( *this + (~rhs) );
4449 
4450  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
4451  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4452  }
4453 
4454  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4455 
4456  left.reset();
4457  left.reserve( tmp.nonZeros() );
4458  assign( left, tmp );
4459 
4460  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4461 
4462  return *this;
4463 }
4465 //*************************************************************************************************
4466 
4467 
4468 //*************************************************************************************************
4483 template< typename MT > // Type of the sparse matrix
4484 template< typename VT > // Type of the right-hand side dense vector
4485 inline SparseRow<MT,false,true>&
4486  SparseRow<MT,false,true>::operator-=( const DenseVector<VT,true>& rhs )
4487 {
4488  using blaze::assign;
4489 
4496 
4497  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4498 
4502 
4503  if( size() != (~rhs).size() ) {
4504  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4505  }
4506 
4507  const SubType tmp( *this - (~rhs) );
4508 
4509  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
4510  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4511  }
4512 
4513  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4514 
4515  left.reset();
4516  assign( left, tmp );
4517 
4518  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4519 
4520  return *this;
4521 }
4523 //*************************************************************************************************
4524 
4525 
4526 //*************************************************************************************************
4541 template< typename MT > // Type of the sparse matrix
4542 template< typename VT > // Type of the right-hand side sparse vector
4543 inline SparseRow<MT,false,true>&
4544  SparseRow<MT,false,true>::operator-=( const SparseVector<VT,true>& rhs )
4545 {
4546  using blaze::assign;
4547 
4554 
4555  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4556 
4560 
4561  if( size() != (~rhs).size() ) {
4562  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4563  }
4564 
4565  const SubType tmp( *this - (~rhs) );
4566 
4567  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
4568  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4569  }
4570 
4571  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4572 
4573  left.reset();
4574  left.reserve( tmp.nonZeros() );
4575  assign( left, tmp );
4576 
4577  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4578 
4579  return *this;
4580 }
4582 //*************************************************************************************************
4583 
4584 
4585 //*************************************************************************************************
4598 template< typename MT > // Type of the sparse matrix
4599 template< typename VT > // Type of the right-hand side vector
4600 inline SparseRow<MT,false,true>&
4601  SparseRow<MT,false,true>::operator*=( const Vector<VT,true>& rhs )
4602 {
4603  using blaze::assign;
4604 
4610 
4611  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
4612 
4615 
4616  if( size() != (~rhs).size() ) {
4617  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4618  }
4619 
4620  const MultType tmp( *this * (~rhs) );
4621 
4622  if( !tryAssign( matrix_, tmp, row_, 0UL ) ) {
4623  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4624  }
4625 
4626  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4627 
4628  left.reset();
4629  assign( left, tmp );
4630 
4631  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4632 
4633  return *this;
4634 }
4636 //*************************************************************************************************
4637 
4638 
4639 //*************************************************************************************************
4654 template< typename MT > // Type of the sparse matrix
4655 template< typename Other > // Data type of the right-hand side scalar
4656 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
4657  SparseRow<MT,false,true>::operator*=( Other rhs )
4658 {
4660 
4661  for( Iterator element=begin(); element!=end(); ++element )
4662  element->value() *= rhs;
4663  return *this;
4664 }
4666 //*************************************************************************************************
4667 
4668 
4669 //*************************************************************************************************
4687 template< typename MT > // Type of the sparse matrix
4688 template< typename Other > // Data type of the right-hand side scalar
4689 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
4690  SparseRow<MT,false,true>::operator/=( Other rhs )
4691 {
4693 
4694  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
4695 
4696  typedef typename DivTrait<ElementType,Other>::Type DT;
4697  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
4698 
4699  // Depending on the two involved data types, an integer division is applied or a
4700  // floating point division is selected.
4701  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
4702  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
4703  for( Iterator element=begin(); element!=end(); ++element )
4704  element->value() *= tmp;
4705  }
4706  else {
4707  for( Iterator element=begin(); element!=end(); ++element )
4708  element->value() /= rhs;
4709  }
4710 
4711  return *this;
4712 }
4714 //*************************************************************************************************
4715 
4716 
4717 
4718 
4719 //=================================================================================================
4720 //
4721 // UTILITY FUNCTIONS
4722 //
4723 //=================================================================================================
4724 
4725 //*************************************************************************************************
4731 template< typename MT > // Type of the sparse matrix
4732 inline size_t SparseRow<MT,false,true>::size() const
4733 {
4734  return matrix_.columns();
4735 }
4737 //*************************************************************************************************
4738 
4739 
4740 //*************************************************************************************************
4746 template< typename MT > // Type of the sparse matrix
4747 inline size_t SparseRow<MT,false,true>::capacity() const
4748 {
4749  return matrix_.capacity( row_ );
4750 }
4752 //*************************************************************************************************
4753 
4754 
4755 //*************************************************************************************************
4764 template< typename MT > // Type of the sparse matrix
4765 inline size_t SparseRow<MT,false,true>::nonZeros() const
4766 {
4767  return matrix_.nonZeros( row_ );
4768 }
4770 //*************************************************************************************************
4771 
4772 
4773 //*************************************************************************************************
4779 template< typename MT > // Type of the sparse matrix
4780 inline void SparseRow<MT,false,true>::reset()
4781 {
4782  matrix_.reset( row_ );
4783 }
4785 //*************************************************************************************************
4786 
4787 
4788 //*************************************************************************************************
4800 template< typename MT > // Type of the sparse matrix
4801 inline typename SparseRow<MT,false,true>::Iterator
4802  SparseRow<MT,false,true>::set( size_t index, const ElementType& value )
4803 {
4804  return matrix_.set( index, row_, value );
4805 }
4807 //*************************************************************************************************
4808 
4809 
4810 //*************************************************************************************************
4823 template< typename MT > // Type of the sparse matrix
4824 inline typename SparseRow<MT,false,true>::Iterator
4825  SparseRow<MT,false,true>::insert( size_t index, const ElementType& value )
4826 {
4827  return matrix_.insert( index, row_, value );
4828 }
4830 //*************************************************************************************************
4831 
4832 
4833 //*************************************************************************************************
4842 template< typename MT > // Type of the sparse matrix
4843 inline void SparseRow<MT,false,true>::erase( size_t index )
4844 {
4845  matrix_.erase( index, row_ );
4846 }
4848 //*************************************************************************************************
4849 
4850 
4851 //*************************************************************************************************
4860 template< typename MT > // Type of the sparse matrix
4861 inline typename SparseRow<MT,false,true>::Iterator
4863 {
4864  return matrix_.erase( row_, pos );
4865 }
4867 //*************************************************************************************************
4868 
4869 
4870 //*************************************************************************************************
4880 template< typename MT > // Type of the sparse matrix
4881 inline typename SparseRow<MT,false,true>::Iterator
4883 {
4884  return matrix_.erase( row_, first, last );
4885 }
4887 //*************************************************************************************************
4888 
4889 
4890 //*************************************************************************************************
4900 template< typename MT > // Type of the sparse matrix
4901 void SparseRow<MT,false,true>::reserve( size_t n )
4902 {
4903  matrix_.reserve( row_, n );
4904 }
4906 //*************************************************************************************************
4907 
4908 
4909 //*************************************************************************************************
4920 template< typename MT > // Type of the sparse matrix
4921 template< typename Other > // Data type of the scalar value
4922 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::scale( const Other& scalar )
4923 {
4925 
4926  for( Iterator element=begin(); element!=end(); ++element )
4927  element->value() *= scalar;
4928  return *this;
4929 }
4931 //*************************************************************************************************
4932 
4933 
4934 //*************************************************************************************************
4943 template< typename MT > // Type of the sparse matrix
4944 inline size_t SparseRow<MT,false,true>::extendCapacity() const
4945 {
4946  using blaze::max;
4947  using blaze::min;
4948 
4949  size_t nonzeros( 2UL*capacity()+1UL );
4950  nonzeros = max( nonzeros, 7UL );
4951  nonzeros = min( nonzeros, size() );
4952 
4953  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
4954 
4955  return nonzeros;
4956 }
4958 //*************************************************************************************************
4959 
4960 
4961 
4962 
4963 //=================================================================================================
4964 //
4965 // LOOKUP FUNCTIONS
4966 //
4967 //=================================================================================================
4968 
4969 //*************************************************************************************************
4983 template< typename MT > // Type of the sparse matrix
4984 inline typename SparseRow<MT,false,true>::Iterator
4985  SparseRow<MT,false,true>::find( size_t index )
4986 {
4987  return matrix_.find( index, row_ );
4988 }
4990 //*************************************************************************************************
4991 
4992 
4993 //*************************************************************************************************
5007 template< typename MT > // Type of the sparse matrix
5009  SparseRow<MT,false,true>::find( size_t index ) const
5010 {
5011  return matrix_.find( index, row_ );
5012 }
5014 //*************************************************************************************************
5015 
5016 
5017 //*************************************************************************************************
5030 template< typename MT > // Type of the sparse matrix
5031 inline typename SparseRow<MT,false,true>::Iterator
5032  SparseRow<MT,false,true>::lowerBound( size_t index )
5033 {
5034  return matrix_.lowerBound( index, row_ );
5035 }
5037 //*************************************************************************************************
5038 
5039 
5040 //*************************************************************************************************
5053 template< typename MT > // Type of the sparse matrix
5055  SparseRow<MT,false,true>::lowerBound( size_t index ) const
5056 {
5057  return matrix_.lowerBound( index, row_ );
5058 }
5060 //*************************************************************************************************
5061 
5062 
5063 //*************************************************************************************************
5076 template< typename MT > // Type of the sparse matrix
5077 inline typename SparseRow<MT,false,true>::Iterator
5078  SparseRow<MT,false,true>::upperBound( size_t index )
5079 {
5080  return matrix_.upperBound( index, row_ );
5081 }
5083 //*************************************************************************************************
5084 
5085 
5086 //*************************************************************************************************
5099 template< typename MT > // Type of the sparse matrix
5101  SparseRow<MT,false,true>::upperBound( size_t index ) const
5102 {
5103  return matrix_.upperBound( index, row_ );
5104 }
5106 //*************************************************************************************************
5107 
5108 
5109 
5110 
5111 //=================================================================================================
5112 //
5113 // LOW-LEVEL UTILITY FUNCTIONS
5114 //
5115 //=================================================================================================
5116 
5117 //*************************************************************************************************
5142 template< typename MT > // Type of the sparse matrix
5143 inline void SparseRow<MT,false,true>::append( size_t index, const ElementType& value, bool check )
5144 {
5145  matrix_.append( index, row_, value, check );
5146 }
5148 //*************************************************************************************************
5149 
5150 
5151 
5152 
5153 //=================================================================================================
5154 //
5155 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5156 //
5157 //=================================================================================================
5158 
5159 //*************************************************************************************************
5170 template< typename MT > // Type of the sparse matrix
5171 template< typename Other > // Data type of the foreign expression
5172 inline bool SparseRow<MT,false,true>::canAlias( const Other* alias ) const
5173 {
5174  return matrix_.isAliased( alias );
5175 }
5177 //*************************************************************************************************
5178 
5179 
5180 //*************************************************************************************************
5191 template< typename MT > // Type of the sparse matrix
5192 template< typename Other > // Data type of the foreign expression
5193 inline bool SparseRow<MT,false,true>::isAliased( const Other* alias ) const
5194 {
5195  return matrix_.isAliased( alias );
5196 }
5198 //*************************************************************************************************
5199 
5200 
5201 //*************************************************************************************************
5213 template< typename MT > // Type of the sparse matrix
5214 template< typename VT > // Type of the right-hand side dense vector
5215 inline void SparseRow<MT,false,true>::assign( const DenseVector<VT,true>& rhs )
5216 {
5217  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5218  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5219 
5220  for( size_t i=0UL; i<size(); ++i )
5221  {
5222  if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
5223  matrix_.reserve( row_, extendCapacity() );
5224 
5225  matrix_.append( i, row_, (~rhs)[i], true );
5226  }
5227 }
5229 //*************************************************************************************************
5230 
5231 
5232 //*************************************************************************************************
5244 template< typename MT > // Type of the sparse matrix
5245 template< typename VT > // Type of the right-hand side sparse vector
5246 inline void SparseRow<MT,false,true>::assign( const SparseVector<VT,true>& rhs )
5247 {
5248  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5249  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5250 
5251  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
5252  matrix_.append( element->index(), row_, element->value(), true );
5253  }
5254 }
5256 //*************************************************************************************************
5257 
5258 
5259 //*************************************************************************************************
5271 template< typename MT > // Type of the sparse matrix
5272 template< typename VT > // Type of the right-hand side dense vector
5273 inline void SparseRow<MT,false,true>::addAssign( const DenseVector<VT,true>& rhs )
5274 {
5275  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
5276 
5280 
5281  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5282 
5283  const AddType tmp( serial( *this + (~rhs) ) );
5284  matrix_.reset( row_ );
5285  assign( tmp );
5286 }
5288 //*************************************************************************************************
5289 
5290 
5291 //*************************************************************************************************
5303 template< typename MT > // Type of the sparse matrix
5304 template< typename VT > // Type of the right-hand side sparse vector
5305 inline void SparseRow<MT,false,true>::addAssign( const SparseVector<VT,true>& rhs )
5306 {
5307  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
5308 
5312 
5313  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5314 
5315  const AddType tmp( serial( *this + (~rhs) ) );
5316  matrix_.reset( row_ );
5317  matrix_.reserve( row_, tmp.nonZeros() );
5318  assign( tmp );
5319 }
5321 //*************************************************************************************************
5322 
5323 
5324 //*************************************************************************************************
5336 template< typename MT > // Type of the sparse matrix
5337 template< typename VT > // Type of the right-hand side dense vector
5338 inline void SparseRow<MT,false,true>::subAssign( const DenseVector<VT,true>& rhs )
5339 {
5340  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
5341 
5345 
5346  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5347 
5348  const SubType tmp( serial( *this - (~rhs) ) );
5349  matrix_.reset( row_ );
5350  assign( tmp );
5351 }
5353 //*************************************************************************************************
5354 
5355 
5356 //*************************************************************************************************
5368 template< typename MT > // Type of the sparse matrix
5369 template< typename VT > // Type of the right-hand side sparse vector
5370 inline void SparseRow<MT,false,true>::subAssign( const SparseVector<VT,true>& rhs )
5371 {
5372  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
5373 
5377 
5378  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5379 
5380  const SubType tmp( serial( *this - (~rhs) ) );
5381  matrix_.reset( row_ );
5382  matrix_.reserve( row_, tmp.nonZeros() );
5383  assign( tmp );
5384 }
5386 //*************************************************************************************************
5387 
5388 
5389 
5390 
5391 
5392 
5393 
5394 
5395 //=================================================================================================
5396 //
5397 // SPARSEROW OPERATORS
5398 //
5399 //=================================================================================================
5400 
5401 //*************************************************************************************************
5404 template< typename MT, bool SO, bool SF >
5405 inline void reset( SparseRow<MT,SO,SF>& row );
5406 
5407 template< typename MT, bool SO, bool SF >
5408 inline void clear( SparseRow<MT,SO,SF>& row );
5409 
5410 template< typename MT, bool SO, bool SF >
5411 inline bool isDefault( const SparseRow<MT,SO,SF>& row );
5412 
5413 template< typename MT, bool SO, bool SF >
5414 inline bool isIntact( const SparseRow<MT,SO,SF>& row );
5415 
5416 template< typename MT, bool SO, bool SF >
5417 inline bool isSame( const SparseRow<MT,SO,SF>& a, const SparseRow<MT,SO,SF>& b );
5419 //*************************************************************************************************
5420 
5421 
5422 //*************************************************************************************************
5429 template< typename MT // Type of the sparse matrix
5430  , bool SO // Storage order
5431  , bool SF > // Symmetry flag
5432 inline void reset( SparseRow<MT,SO,SF>& row )
5433 {
5434  row.reset();
5435 }
5436 //*************************************************************************************************
5437 
5438 
5439 //*************************************************************************************************
5448 template< typename MT // Type of the sparse matrix
5449  , bool SO // Storage order
5450  , bool SF > // Symmetry flag
5451 inline void clear( SparseRow<MT,SO,SF>& row )
5452 {
5453  row.reset();
5454 }
5455 //*************************************************************************************************
5456 
5457 
5458 //*************************************************************************************************
5476 template< typename MT // Type of the sparse matrix
5477  , bool SO // Storage order
5478  , bool SF > // Symmetry flag
5479 inline bool isDefault( const SparseRow<MT,SO,SF>& row )
5480 {
5482 
5483  const ConstIterator end( row.end() );
5484  for( ConstIterator element=row.begin(); element!=end; ++element )
5485  if( !isDefault( element->value() ) ) return false;
5486  return true;
5487 }
5488 //*************************************************************************************************
5489 
5490 
5491 //*************************************************************************************************
5508 template< typename MT // Type of the sparse matrix
5509  , bool SO // Storage order
5510  , bool SF > // Symmetry flag
5511 inline bool isIntact( const SparseRow<MT,SO,SF>& row )
5512 {
5513  return ( row.row_ <= row.matrix_.rows() &&
5514  isIntact( row.matrix_ ) );
5515 }
5516 //*************************************************************************************************
5517 
5518 
5519 //*************************************************************************************************
5531 template< typename MT // Type of the sparse matrix
5532  , bool SO // Storage order
5533  , bool SF > // Symmetry flag
5534 inline bool isSame( const SparseRow<MT,SO,SF>& a, const SparseRow<MT,SO,SF>& b )
5535 {
5536  return ( isSame( a.matrix_, b.matrix_ ) && ( a.row_ == b.row_ ) );
5537 }
5538 //*************************************************************************************************
5539 
5540 
5541 //*************************************************************************************************
5556 template< typename MT // Type of the sparse matrix
5557  , bool SO // Storage order
5558  , bool SF // Symmetry flag
5559  , typename VT > // Type of the right-hand side vector
5560 inline bool tryAssign( const SparseRow<MT,SO,SF>& lhs, const Vector<VT,true>& rhs, size_t index )
5561 {
5562  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5563  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5564 
5565  return tryAssign( lhs.matrix_, ~rhs, lhs.row_, index );
5566 }
5568 //*************************************************************************************************
5569 
5570 
5571 //*************************************************************************************************
5586 template< typename MT // Type of the sparse matrix
5587  , bool SO // Storage order
5588  , bool SF // Symmetry flag
5589  , typename VT > // Type of the right-hand side vector
5590 inline bool tryAddAssign( const SparseRow<MT,SO,SF>& lhs, const Vector<VT,true>& rhs, size_t index )
5591 {
5592  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5593  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5594 
5595  return tryAddAssign( lhs.matrix_, ~rhs, lhs.row_, index );
5596 }
5598 //*************************************************************************************************
5599 
5600 
5601 //*************************************************************************************************
5616 template< typename MT // Type of the sparse matrix
5617  , bool SO // Storage order
5618  , bool SF // Symmetry flag
5619  , typename VT > // Type of the right-hand side vector
5620 inline bool trySubAssign( const SparseRow<MT,SO,SF>& lhs, const Vector<VT,true>& rhs, size_t index )
5621 {
5622  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5623  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5624 
5625  return trySubAssign( lhs.matrix_, ~rhs, lhs.row_, index );
5626 }
5628 //*************************************************************************************************
5629 
5630 
5631 //*************************************************************************************************
5646 template< typename MT // Type of the sparse matrix
5647  , bool SO // Storage order
5648  , bool SF // Symmetry flag
5649  , typename VT > // Type of the right-hand side vector
5650 inline bool tryMultAssign( const SparseRow<MT,SO,SF>& lhs, const Vector<VT,true>& rhs, size_t index )
5651 {
5652  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5653  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5654 
5655  return tryMultAssign( lhs.matrix_, ~rhs, lhs.row_, index );
5656 }
5658 //*************************************************************************************************
5659 
5660 
5661 //*************************************************************************************************
5676 template< typename MT // Type of the sparse matrix
5677  , bool SO // Storage order
5678  , bool SF > // Symmetry flag
5679 inline typename DerestrictTrait< SparseRow<MT,SO,SF> >::Type
5680  derestrict( SparseRow<MT,SO,SF>& row )
5681 {
5682  typedef typename DerestrictTrait< SparseRow<MT,SO,SF> >::Type ReturnType;
5683  return ReturnType( derestrict( row.matrix_ ), row.row_ );
5684 }
5686 //*************************************************************************************************
5687 
5688 
5689 
5690 
5691 //=================================================================================================
5692 //
5693 // ISRESTRICTED SPECIALIZATIONS
5694 //
5695 //=================================================================================================
5696 
5697 //*************************************************************************************************
5699 template< typename MT, bool SO, bool SF >
5700 struct IsRestricted< SparseRow<MT,SO,SF> > : public IsTrue< IsRestricted<MT>::value >
5701 {};
5703 //*************************************************************************************************
5704 
5705 
5706 
5707 
5708 //=================================================================================================
5709 //
5710 // DERESTRICTTRAIT SPECIALIZATIONS
5711 //
5712 //=================================================================================================
5713 
5714 //*************************************************************************************************
5716 template< typename MT, bool SO, bool SF >
5717 struct DerestrictTrait< SparseRow<MT,SO,SF> >
5718 {
5719  typedef SparseRow< typename RemoveReference< typename DerestrictTrait<MT>::Type >::Type > Type;
5720 };
5722 //*************************************************************************************************
5723 
5724 
5725 
5726 
5727 //=================================================================================================
5728 //
5729 // ADDTRAIT SPECIALIZATIONS
5730 //
5731 //=================================================================================================
5732 
5733 //*************************************************************************************************
5735 template< typename MT, bool SO, bool SF, typename T >
5736 struct AddTrait< SparseRow<MT,SO,SF>, T >
5737 {
5738  typedef typename AddTrait< typename RowTrait<MT>::Type, T >::Type Type;
5739 };
5740 
5741 template< typename T, typename MT, bool SO, bool SF >
5742 struct AddTrait< T, SparseRow<MT,SO,SF> >
5743 {
5744  typedef typename AddTrait< T, typename RowTrait<MT>::Type >::Type Type;
5745 };
5747 //*************************************************************************************************
5748 
5749 
5750 
5751 
5752 //=================================================================================================
5753 //
5754 // SUBTRAIT SPECIALIZATIONS
5755 //
5756 //=================================================================================================
5757 
5758 //*************************************************************************************************
5760 template< typename MT, bool SO, bool SF, typename T >
5761 struct SubTrait< SparseRow<MT,SO,SF>, T >
5762 {
5763  typedef typename SubTrait< typename RowTrait<MT>::Type, T >::Type Type;
5764 };
5765 
5766 template< typename T, typename MT, bool SO, bool SF >
5767 struct SubTrait< T, SparseRow<MT,SO,SF> >
5768 {
5769  typedef typename SubTrait< T, typename RowTrait<MT>::Type >::Type Type;
5770 };
5772 //*************************************************************************************************
5773 
5774 
5775 
5776 
5777 //=================================================================================================
5778 //
5779 // MULTTRAIT SPECIALIZATIONS
5780 //
5781 //=================================================================================================
5782 
5783 //*************************************************************************************************
5785 template< typename MT, bool SO, bool SF, typename T >
5786 struct MultTrait< SparseRow<MT,SO,SF>, T >
5787 {
5788  typedef typename MultTrait< typename RowTrait<MT>::Type, T >::Type Type;
5789 };
5790 
5791 template< typename T, typename MT, bool SO, bool SF >
5792 struct MultTrait< T, SparseRow<MT,SO,SF> >
5793 {
5794  typedef typename MultTrait< T, typename RowTrait<MT>::Type >::Type Type;
5795 };
5797 //*************************************************************************************************
5798 
5799 
5800 
5801 
5802 //=================================================================================================
5803 //
5804 // CROSSTRAIT SPECIALIZATIONS
5805 //
5806 //=================================================================================================
5807 
5808 //*************************************************************************************************
5810 template< typename MT, bool SO, bool SF, typename T >
5811 struct CrossTrait< SparseRow<MT,SO,SF>, T >
5812 {
5813  typedef typename CrossTrait< typename RowTrait<MT>::Type, T >::Type Type;
5814 };
5815 
5816 template< typename T, typename MT, bool SO, bool SF >
5817 struct CrossTrait< T, SparseRow<MT,SO,SF> >
5818 {
5819  typedef typename CrossTrait< T, typename RowTrait<MT>::Type >::Type Type;
5820 };
5822 //*************************************************************************************************
5823 
5824 
5825 
5826 
5827 //=================================================================================================
5828 //
5829 // DIVTRAIT SPECIALIZATIONS
5830 //
5831 //=================================================================================================
5832 
5833 //*************************************************************************************************
5835 template< typename MT, bool SO, bool SF, typename T >
5836 struct DivTrait< SparseRow<MT,SO,SF>, T >
5837 {
5838  typedef typename DivTrait< typename RowTrait<MT>::Type, T >::Type Type;
5839 };
5840 
5841 template< typename T, typename MT, bool SO, bool SF >
5842 struct DivTrait< T, SparseRow<MT,SO,SF> >
5843 {
5844  typedef typename DivTrait< T, typename RowTrait<MT>::Type >::Type Type;
5845 };
5847 //*************************************************************************************************
5848 
5849 
5850 
5851 
5852 //=================================================================================================
5853 //
5854 // SUBVECTORTRAIT SPECIALIZATIONS
5855 //
5856 //=================================================================================================
5857 
5858 //*************************************************************************************************
5860 template< typename MT, bool SO, bool SF >
5861 struct SubvectorTrait< SparseRow<MT,SO,SF> >
5862 {
5863  typedef typename SubvectorTrait< typename SparseRow<MT,SO,SF>::ResultType >::Type Type;
5864 };
5866 //*************************************************************************************************
5867 
5868 } // namespace blaze
5869 
5870 #endif
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Constraint on the data type.
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
#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 UNUSED_PARAMETER function template.
Header file for the IsUniUpper type trait.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7820
Header file for the subtraction trait.
SparseRow< MT, SO, SF > This
Type of this SparseRow instance.
Definition: SparseRow.h:381
Header file for basic type definitions.
Header file for the SparseVector base class.
SparseRow & operator=(const SparseRow &rhs)
Copy assignment operator for SparseRow.
Definition: SparseRow.h:814
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
Header file for the row trait.
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:250
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse row.
Definition: SparseRow.h:1745
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
Header file for the row base class.
Header file for the IsDiagonal type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
size_t size() const
Returns the current size/dimension of the sparse row.
Definition: SparseRow.h:1341
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:647
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:340
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the And class template.
bool canAlias(const Other *alias) const
Returns whether the sparse row can alias with the given address alias.
Definition: SparseRow.h:1774
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:118
size_t nonZeros() const
Returns the number of non-zero elements in the row.
Definition: SparseRow.h:1374
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
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:378
#define BLAZE_CONSTRAINT_MUST_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a symmetric matrix type...
Definition: Symmetric.h:78
Constraints on the storage order of matrix types.
#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 IsUniLower type trait.
size_t extendCapacity() const
Calculating a new sparse row capacity.
Definition: SparseRow.h:1552
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
void subAssign(const DenseVector< VT, true > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseRow.h:1940
Constraint on the data type.
Base template for the RowTrait class.
Definition: RowTrait.h:115
If< IsConst< MT >, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseRow.h:398
ConstIterator cbegin() const
Returns an iterator to the first element of the row.
Definition: SparseRow.h:732
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Reference at(size_t index)
Checked access to the row elements.
Definition: SparseRow.h:655
Header file for the IsFloatingPoint type trait.
void erase(size_t index)
Erasing an element from the sparse row.
Definition: SparseRow.h:1452
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:79
const SparseRow & CompositeType
Data type for composite expression templates.
Definition: SparseRow.h:386
Operand matrix_
The sparse matrix containing the row.
Definition: SparseRow.h:519
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Header file for the Or class template.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseRow.h:385
void reset()
Reset to the default initial values.
Definition: SparseRow.h:1389
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
void reserve(size_t n)
Setting the minimum capacity of the sparse row.
Definition: SparseRow.h:1509
size_t capacity() const
Returns the maximum capacity of the sparse row.
Definition: SparseRow.h:1356
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
Header file for the subvector trait.
RowTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseRow.h:382
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseRow.h:395
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
Header file for the IsLower type trait.
#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
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:642
MT::ConstReference ConstReference
Reference to a constant row value.
Definition: SparseRow.h:389
Header file for the SparseElement base class.
Constraint on the data type.
MT::ElementType ElementType
Type of the row elements.
Definition: SparseRow.h:384
void addAssign(const DenseVector< VT, true > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseRow.h:1875
Constraint on the data type.
Reference operator[](size_t index)
Subscript operator for the direct access to the row elements.
Definition: SparseRow.h:613
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:187
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
SparseRow(MT &matrix, size_t index)
The constructor for SparseRow.
Definition: SparseRow.h:582
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
Constraint on the data type.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse row.
Definition: SparseRow.h:1434
If< IsExpression< MT >, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseRow.h:376
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse row.
Definition: SparseRow.h:1411
Header file for the serial shim.
Header file for the DerestrictTrait class template.
Constraint on the data type.
Header file for the IsNumeric type trait.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:79
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for the IsConst type trait.
Iterator end()
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:749
Base class for all rows.The Row class serves as a tag for all rows (i.e. dense and sparse rows)...
Definition: Row.h:63
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:138
Base template for the MultTrait class.
Definition: MultTrait.h:138
Header file for the addition trait.
Header file for the cross product trait.
Reference to a specific row of a sparse matrix.The SparseRow template represents a reference to a spe...
Definition: Forward.h:52
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
Header file for the reset shim.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the isDefault shim.
Constraint on the data type.
Constraint on the data type.
Constraints on the storage order of matrix types.
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:118
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
Header file for the IsReference type trait.
Header file for the RemoveReference type trait.
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
Base template for the DivTrait class.
Definition: DivTrait.h:138
Iterator find(size_t index)
Searches for a specific row element.
Definition: SparseRow.h:1592
bool isAliased(const Other *alias) const
Returns whether the sparse row is aliased with the given address alias.
Definition: SparseRow.h:1795
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseRow.h:1637
#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
Header file for the IsRowMajorMatrix type trait.
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:258
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
Header file for the IsTrue value trait.
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Compile time type check.This class tests whether the given template parameter T is a reference type (...
Definition: IsReference.h:94
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
#define BLAZE_CONSTRAINT_MUST_BE_ROW_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a row dense or sparse vector type (i...
Definition: RowVector.h:79
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseRow.h:383
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Base template for the SubTrait class.
Definition: SubTrait.h:138
Header file for the IsUpper type trait.
Header file for exception macros.
ConstIterator cend() const
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:783
Header file for the IsRestricted type trait.
If< IsConst< MT >, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant row value.
Definition: SparseRow.h:392
Iterator begin()
Returns an iterator to the first element of the row.
Definition: SparseRow.h:698
#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
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseRow.h:1681
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional matrix type...
Definition: SparseMatrix.h:79
const size_t row_
The index of the row in the matrix.
Definition: SparseRow.h:520
Constraint on the transpose flag of vector types.
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
Header file for a safe C++ NULL pointer implementation.
void assign(const DenseVector< VT, true > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseRow.h:1817