All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
44 #include <stdexcept>
56 #include <blaze/math/Functions.h>
58 #include <blaze/math/shims/Reset.h>
70 #include <blaze/util/Assert.h>
71 #include <blaze/util/DisableIf.h>
72 #include <blaze/util/EnableIf.h>
74 #include <blaze/util/mpl/If.h>
75 #include <blaze/util/mpl/Or.h>
76 #include <blaze/util/Null.h>
77 #include <blaze/util/SelectType.h>
78 #include <blaze/util/Types.h>
82 #include <blaze/util/Unused.h>
83 
84 
85 namespace blaze {
86 
87 //=================================================================================================
88 //
89 // CLASS DEFINITION
90 //
91 //=================================================================================================
92 
93 //*************************************************************************************************
350 template< typename MT // Type of the sparse matrix
351  , bool SO = IsRowMajorMatrix<MT>::value // Storage order
352  , bool SF = IsSymmetric<MT>::value > // Symmetry flag
353 class SparseRow : public SparseVector< SparseRow<MT,SO,SF>, true >
354  , private Row
355 {
356  private:
357  //**Type definitions****************************************************************************
359  typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type Operand;
360  //**********************************************************************************************
361 
362  //**********************************************************************************************
364 
370  enum { useConst = IsConst<MT>::value };
371  //**********************************************************************************************
372 
373  public:
374  //**Type definitions****************************************************************************
376  typedef typename RowTrait<MT>::Type ResultType;
378  typedef typename MT::ElementType ElementType;
379  typedef typename MT::ReturnType ReturnType;
380  typedef const SparseRow& CompositeType;
381 
384 
387 
390 
393  //**********************************************************************************************
394 
395  //**Compilation flags***************************************************************************
397  enum { smpAssignable = 0 };
398  //**********************************************************************************************
399 
400  //**Constructors********************************************************************************
403  explicit inline SparseRow( MT& matrix, size_t index );
404  // No explicitly declared copy constructor.
406  //**********************************************************************************************
407 
408  //**Destructor**********************************************************************************
409  // No explicitly declared destructor.
410  //**********************************************************************************************
411 
412  //**Data access functions***********************************************************************
415  inline Reference operator[]( size_t index );
416  inline ConstReference operator[]( size_t index ) const;
417  inline Iterator begin ();
418  inline ConstIterator begin () const;
419  inline ConstIterator cbegin() const;
420  inline Iterator end ();
421  inline ConstIterator end () const;
422  inline ConstIterator cend () const;
424  //**********************************************************************************************
425 
426  //**Assignment operators************************************************************************
429  inline SparseRow& operator= ( const SparseRow& rhs );
430  template< typename VT > inline SparseRow& operator= ( const DenseVector <VT,true>& rhs );
431  template< typename VT > inline SparseRow& operator= ( const SparseVector<VT,true>& rhs );
432  template< typename VT > inline SparseRow& operator+=( const Vector<VT,true>& rhs );
433  template< typename VT > inline SparseRow& operator-=( const Vector<VT,true>& rhs );
434  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
435 
436  template< typename Other >
437  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
438  operator*=( Other rhs );
439 
440  template< typename Other >
441  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
442  operator/=( Other rhs );
444  //**********************************************************************************************
445 
446  //**Utility functions***************************************************************************
449  inline size_t size() const;
450  inline size_t capacity() const;
451  inline size_t nonZeros() const;
452  inline void reset();
453  inline Iterator set ( size_t index, const ElementType& value );
454  inline Iterator insert ( size_t index, const ElementType& value );
455  inline void erase ( size_t index );
456  inline Iterator erase ( Iterator pos );
457  inline Iterator erase ( Iterator first, Iterator last );
458  inline void reserve( size_t n );
459  template< typename Other > inline SparseRow& scale ( const Other& scalar );
461  //**********************************************************************************************
462 
463  //**Lookup functions****************************************************************************
466  inline Iterator find ( size_t index );
467  inline ConstIterator find ( size_t index ) const;
468  inline Iterator lowerBound( size_t index );
469  inline ConstIterator lowerBound( size_t index ) const;
470  inline Iterator upperBound( size_t index );
471  inline ConstIterator upperBound( size_t index ) const;
473  //**********************************************************************************************
474 
475  //**Low-level utility functions*****************************************************************
478  inline void append( size_t index, const ElementType& value, bool check=false );
480  //**********************************************************************************************
481 
482  //**Expression template evaluation functions****************************************************
485  template< typename Other > inline bool canAlias ( const Other* alias ) const;
486  template< typename Other > inline bool isAliased( const Other* alias ) const;
487 
488  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
489  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
490  template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
491  template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
492  template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
493  template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
495  //**********************************************************************************************
496 
497  private:
498  //**Utility functions***************************************************************************
501  inline size_t extendCapacity() const;
503  //**********************************************************************************************
504 
505  //**Member variables****************************************************************************
509  const size_t row_;
510 
511  //**********************************************************************************************
512 
513  //**Friend declarations*************************************************************************
515  template< typename MT2, bool SO2, bool SF2 >
516  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
518  //**********************************************************************************************
519 
520  //**Compile time checks*************************************************************************
527  //**********************************************************************************************
528 };
529 //*************************************************************************************************
530 
531 
532 
533 
534 //=================================================================================================
535 //
536 // CONSTRUCTOR
537 //
538 //=================================================================================================
539 
540 //*************************************************************************************************
547 template< typename MT // Type of the sparse matrix
548  , bool SO // Storage order
549  , bool SF > // Symmetry flag
550 inline SparseRow<MT,SO,SF>::SparseRow( MT& matrix, size_t index )
551  : matrix_( matrix ) // The sparse matrix containing the row
552  , row_ ( index ) // The index of the row in the matrix
553 {
554  if( matrix_.rows() <= index )
555  throw std::invalid_argument( "Invalid row access index" );
556 }
557 //*************************************************************************************************
558 
559 
560 
561 
562 //=================================================================================================
563 //
564 // DATA ACCESS FUNCTIONS
565 //
566 //=================================================================================================
567 
568 //*************************************************************************************************
574 template< typename MT // Type of the sparse matrix
575  , bool SO // Storage order
576  , bool SF > // Symmetry flag
578 {
579  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
580  return matrix_(row_,index);
581 }
582 //*************************************************************************************************
583 
584 
585 //*************************************************************************************************
591 template< typename MT // Type of the sparse matrix
592  , bool SO // Storage order
593  , bool SF > // Symmetry flag
595  SparseRow<MT,SO,SF>::operator[]( size_t index ) const
596 {
597  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
598  return const_cast<const MT&>( matrix_ )(row_,index);
599 }
600 //*************************************************************************************************
601 
602 
603 //*************************************************************************************************
610 template< typename MT // Type of the sparse matrix
611  , bool SO // Storage order
612  , bool SF > // Symmetry flag
614 {
615  return matrix_.begin( row_ );
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
627 template< typename MT // Type of the sparse matrix
628  , bool SO // Storage order
629  , bool SF > // Symmetry flag
631 {
632  return matrix_.cbegin( row_ );
633 }
634 //*************************************************************************************************
635 
636 
637 //*************************************************************************************************
644 template< typename MT // Type of the sparse matrix
645  , bool SO // Storage order
646  , bool SF > // Symmetry flag
648 {
649  return matrix_.cbegin( row_ );
650 }
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
661 template< typename MT // Type of the sparse matrix
662  , bool SO // Storage order
663  , bool SF > // Symmetry flag
665 {
666  return matrix_.end( row_ );
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
678 template< typename MT // Type of the sparse matrix
679  , bool SO // Storage order
680  , bool SF > // Symmetry flag
682 {
683  return matrix_.cend( row_ );
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_.cend( row_ );
701 }
702 //*************************************************************************************************
703 
704 
705 
706 
707 //=================================================================================================
708 //
709 // ASSIGNMENT OPERATORS
710 //
711 //=================================================================================================
712 
713 //*************************************************************************************************
723 template< typename MT // Type of the sparse matrix
724  , bool SO // Storage order
725  , bool SF > // Symmetry flag
727 {
728  using blaze::assign;
729 
733 
734  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
735  return *this;
736 
737  if( size() != rhs.size() )
738  throw std::invalid_argument( "Row sizes do not match" );
739 
740  if( rhs.canAlias( &matrix_ ) ) {
741  const ResultType tmp( rhs );
742  matrix_.reset ( row_ );
743  matrix_.reserve( row_, tmp.nonZeros() );
744  assign( *this, tmp );
745  }
746  else {
747  matrix_.reset ( row_ );
748  matrix_.reserve( row_, rhs.nonZeros() );
749  assign( *this, rhs );
750  }
751 
752  return *this;
753 }
754 //*************************************************************************************************
755 
756 
757 //*************************************************************************************************
767 template< typename MT // Type of the sparse matrix
768  , bool SO // Storage order
769  , bool SF > // Symmetry flag
770 template< typename VT > // Type of the right-hand side dense vector
772 {
773  using blaze::assign;
774 
778 
779  if( size() != (~rhs).size() )
780  throw std::invalid_argument( "Vector sizes do not match" );
781 
782  if( (~rhs).canAlias( &matrix_ ) ) {
783  const typename VT::ResultType tmp( ~rhs );
784  matrix_.reset( row_ );
785  assign( *this, tmp );
786  }
787  else {
788  matrix_.reset( row_ );
789  assign( *this, ~rhs );
790  }
791 
792  return *this;
793 }
794 //*************************************************************************************************
795 
796 
797 //*************************************************************************************************
807 template< typename MT // Type of the sparse matrix
808  , bool SO // Storage order
809  , bool SF > // Symmetry flag
810 template< typename VT > // Type of the right-hand side sparse vector
812 {
813  using blaze::assign;
814 
818 
819  if( size() != (~rhs).size() )
820  throw std::invalid_argument( "Vector sizes do not match" );
821 
822  if( (~rhs).canAlias( &matrix_ ) ) {
823  const typename VT::ResultType tmp( ~rhs );
824  matrix_.reset ( row_ );
825  matrix_.reserve( row_, tmp.nonZeros() );
826  assign( *this, tmp );
827  }
828  else {
829  matrix_.reset ( row_ );
830  matrix_.reserve( row_, (~rhs).nonZeros() );
831  assign( *this, ~rhs );
832  }
833 
834  return *this;
835 }
836 //*************************************************************************************************
837 
838 
839 //*************************************************************************************************
849 template< typename MT // Type of the sparse matrix
850  , bool SO // Storage order
851  , bool SF > // Symmetry flag
852 template< typename VT > // Type of the right-hand side vector
854 {
855  using blaze::addAssign;
856 
857  if( size() != (~rhs).size() )
858  throw std::invalid_argument( "Vector sizes do not match" );
859 
860  addAssign( *this, ~rhs );
861 
862  return *this;
863 }
864 //*************************************************************************************************
865 
866 
867 //*************************************************************************************************
877 template< typename MT // Type of the sparse matrix
878  , bool SO // Storage order
879  , bool SF > // Symmetry flag
880 template< typename VT > // Type of the right-hand side vector
882 {
883  using blaze::subAssign;
884 
885  if( size() != (~rhs).size() )
886  throw std::invalid_argument( "Vector sizes do not match" );
887 
888  subAssign( *this, ~rhs );
889 
890  return *this;
891 }
892 //*************************************************************************************************
893 
894 
895 //*************************************************************************************************
906 template< typename MT // Type of the sparse matrix
907  , bool SO // Storage order
908  , bool SF > // Symmetry flag
909 template< typename VT > // Type of the right-hand side vector
911 {
912  if( size() != (~rhs).size() )
913  throw std::invalid_argument( "Vector sizes do not match" );
914 
915  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
916 
919 
920  const MultType tmp( *this * (~rhs) );
921  matrix_.reset( row_ );
922  assign( tmp );
923 
924  return *this;
925 }
926 //*************************************************************************************************
927 
928 
929 //*************************************************************************************************
940 template< typename MT // Type of the sparse matrix
941  , bool SO // Storage order
942  , bool SF > // Symmetry flag
943 template< typename Other > // Data type of the right-hand side scalar
944 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,SO,SF> >::Type&
946 {
947  for( Iterator element=begin(); element!=end(); ++element )
948  element->value() *= rhs;
949  return *this;
950 }
951 //*************************************************************************************************
952 
953 
954 //*************************************************************************************************
966 template< typename MT // Type of the sparse matrix
967  , bool SO // Storage order
968  , bool SF > // Symmetry flag
969 template< typename Other > // Data type of the right-hand side scalar
970 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,SO,SF> >::Type&
972 {
973  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
974 
975  typedef typename DivTrait<ElementType,Other>::Type DT;
976  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
977 
978  // Depending on the two involved data types, an integer division is applied or a
979  // floating point division is selected.
981  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
982  for( Iterator element=begin(); element!=end(); ++element )
983  element->value() *= tmp;
984  }
985  else {
986  for( Iterator element=begin(); element!=end(); ++element )
987  element->value() /= rhs;
988  }
989 
990  return *this;
991 }
992 //*************************************************************************************************
993 
994 
995 
996 
997 //=================================================================================================
998 //
999 // UTILITY FUNCTIONS
1000 //
1001 //=================================================================================================
1002 
1003 //*************************************************************************************************
1008 template< typename MT // Type of the sparse matrix
1009  , bool SO // Storage order
1010  , bool SF > // Symmetry flag
1011 inline size_t SparseRow<MT,SO,SF>::size() const
1012 {
1013  return matrix_.columns();
1014 }
1015 //*************************************************************************************************
1016 
1017 
1018 //*************************************************************************************************
1023 template< typename MT // Type of the sparse matrix
1024  , bool SO // Storage order
1025  , bool SF > // Symmetry flag
1026 inline size_t SparseRow<MT,SO,SF>::capacity() const
1027 {
1028  return matrix_.capacity( row_ );
1029 }
1030 //*************************************************************************************************
1031 
1032 
1033 //*************************************************************************************************
1041 template< typename MT // Type of the sparse matrix
1042  , bool SO // Storage order
1043  , bool SF > // Symmetry flag
1044 inline size_t SparseRow<MT,SO,SF>::nonZeros() const
1045 {
1046  return matrix_.nonZeros( row_ );
1047 }
1048 //*************************************************************************************************
1049 
1050 
1051 //*************************************************************************************************
1056 template< typename MT // Type of the sparse matrix
1057  , bool SO // Storage order
1058  , bool SF > // Symmetry flag
1060 {
1061  matrix_.reset( row_ );
1062 }
1063 //*************************************************************************************************
1064 
1065 
1066 //*************************************************************************************************
1077 template< typename MT // Type of the sparse matrix
1078  , bool SO // Storage order
1079  , bool SF > // Symmetry flag
1080 inline typename SparseRow<MT,SO,SF>::Iterator
1081  SparseRow<MT,SO,SF>::set( size_t index, const ElementType& value )
1082 {
1083  return matrix_.set( row_, index, value );
1084 }
1085 //*************************************************************************************************
1086 
1087 
1088 //*************************************************************************************************
1100 template< typename MT // Type of the sparse matrix
1101  , bool SO // Storage order
1102  , bool SF > // Symmetry flag
1103 inline typename SparseRow<MT,SO,SF>::Iterator
1104  SparseRow<MT,SO,SF>::insert( size_t index, const ElementType& value )
1105 {
1106  return matrix_.insert( row_, index, value );
1107 }
1108 //*************************************************************************************************
1109 
1110 
1111 //*************************************************************************************************
1119 template< typename MT // Type of the sparse matrix
1120  , bool SO // Storage order
1121  , bool SF > // Symmetry flag
1122 inline void SparseRow<MT,SO,SF>::erase( size_t index )
1123 {
1124  matrix_.erase( row_, index );
1125 }
1126 //*************************************************************************************************
1127 
1128 
1129 //*************************************************************************************************
1137 template< typename MT // Type of the sparse matrix
1138  , bool SO // Storage order
1139  , bool SF > // Symmetry flag
1141 {
1142  return matrix_.erase( row_, pos );
1143 }
1144 //*************************************************************************************************
1145 
1146 
1147 //*************************************************************************************************
1156 template< typename MT // Type of the sparse matrix
1157  , bool SO // Storage order
1158  , bool SF > // Symmetry flag
1159 inline typename SparseRow<MT,SO,SF>::Iterator
1161 {
1162  return matrix_.erase( row_, first, last );
1163 }
1164 //*************************************************************************************************
1165 
1166 
1167 //*************************************************************************************************
1176 template< typename MT // Type of the sparse matrix
1177  , bool SO // Storage order
1178  , bool SF > // Symmetry flag
1180 {
1181  matrix_.reserve( row_, n );
1182 }
1183 //*************************************************************************************************
1184 
1185 
1186 //*************************************************************************************************
1192 template< typename MT // Type of the sparse matrix
1193  , bool SO // Storage order
1194  , bool SF > // Symmetry flag
1195 template< typename Other > // Data type of the scalar value
1196 inline SparseRow<MT,SO,SF>& SparseRow<MT,SO,SF>::scale( const Other& scalar )
1197 {
1198  for( Iterator element=begin(); element!=end(); ++element )
1199  element->value() *= scalar;
1200  return *this;
1201 }
1202 //*************************************************************************************************
1203 
1204 
1205 //*************************************************************************************************
1213 template< typename MT // Type of the sparse matrix
1214  , bool SO // Storage order
1215  , bool SF > // Symmetry flag
1217 {
1218  using blaze::max;
1219  using blaze::min;
1220 
1221  size_t nonzeros( 2UL*capacity()+1UL );
1222  nonzeros = max( nonzeros, 7UL );
1223  nonzeros = min( nonzeros, size() );
1224 
1225  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1226 
1227  return nonzeros;
1228 }
1229 //*************************************************************************************************
1230 
1231 
1232 
1233 
1234 //=================================================================================================
1235 //
1236 // LOOKUP FUNCTIONS
1237 //
1238 //=================================================================================================
1239 
1240 //*************************************************************************************************
1253 template< typename MT // Type of the sparse matrix
1254  , bool SO // Storage order
1255  , bool SF > // Symmetry flag
1257 {
1258  return matrix_.find( row_, index );
1259 }
1260 //*************************************************************************************************
1261 
1262 
1263 //*************************************************************************************************
1276 template< typename MT // Type of the sparse matrix
1277  , bool SO // Storage order
1278  , bool SF > // Symmetry flag
1280 {
1281  return matrix_.find( row_, index );
1282 }
1283 //*************************************************************************************************
1284 
1285 
1286 //*************************************************************************************************
1298 template< typename MT // Type of the sparse matrix
1299  , bool SO // Storage order
1300  , bool SF > // Symmetry flag
1302 {
1303  return matrix_.lowerBound( row_, index );
1304 }
1305 //*************************************************************************************************
1306 
1307 
1308 //*************************************************************************************************
1320 template< typename MT // Type of the sparse matrix
1321  , bool SO // Storage order
1322  , bool SF > // Symmetry flag
1324 {
1325  return matrix_.lowerBound( row_, index );
1326 }
1327 //*************************************************************************************************
1328 
1329 
1330 //*************************************************************************************************
1342 template< typename MT // Type of the sparse matrix
1343  , bool SO // Storage order
1344  , bool SF > // Symmetry flag
1346 {
1347  return matrix_.upperBound( row_, index );
1348 }
1349 //*************************************************************************************************
1350 
1351 
1352 //*************************************************************************************************
1364 template< typename MT // Type of the sparse matrix
1365  , bool SO // Storage order
1366  , bool SF > // Symmetry flag
1368 {
1369  return matrix_.upperBound( row_, index );
1370 }
1371 //*************************************************************************************************
1372 
1373 
1374 
1375 
1376 //=================================================================================================
1377 //
1378 // LOW-LEVEL UTILITY FUNCTIONS
1379 //
1380 //=================================================================================================
1381 
1382 //*************************************************************************************************
1406 template< typename MT // Type of the sparse matrix
1407  , bool SO // Storage order
1408  , bool SF > // Symmetry flag
1409 inline void SparseRow<MT,SO,SF>::append( size_t index, const ElementType& value, bool check )
1410 {
1411  matrix_.append( row_, index, value, check );
1412 }
1413 //*************************************************************************************************
1414 
1415 
1416 
1417 
1418 //=================================================================================================
1419 //
1420 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1421 //
1422 //=================================================================================================
1423 
1424 //*************************************************************************************************
1434 template< typename MT // Type of the sparse matrix
1435  , bool SO // Storage order
1436  , bool SF > // Symmetry flag
1437 template< typename Other > // Data type of the foreign expression
1438 inline bool SparseRow<MT,SO,SF>::canAlias( const Other* alias ) const
1439 {
1440  return matrix_.isAliased( alias );
1441 }
1442 //*************************************************************************************************
1443 
1444 
1445 //*************************************************************************************************
1455 template< typename MT // Type of the sparse matrix
1456  , bool SO // Storage order
1457  , bool SF > // Symmetry flag
1458 template< typename Other > // Data type of the foreign expression
1459 inline bool SparseRow<MT,SO,SF>::isAliased( const Other* alias ) const
1460 {
1461  return matrix_.isAliased( alias );
1462 }
1463 //*************************************************************************************************
1464 
1465 
1466 //*************************************************************************************************
1477 template< typename MT // Type of the sparse matrix
1478  , bool SO // Storage order
1479  , bool SF > // Symmetry flag
1480 template< typename VT > // Type of the right-hand side dense vector
1482 {
1483  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1484  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1485 
1486  for( size_t j=0UL; j<size(); ++j )
1487  {
1488  if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
1489  matrix_.reserve( row_, extendCapacity() );
1490 
1491  matrix_.append( row_, j, (~rhs)[j], true );
1492  }
1493 }
1494 //*************************************************************************************************
1495 
1496 
1497 //*************************************************************************************************
1508 template< typename MT // Type of the sparse matrix
1509  , bool SO // Storage order
1510  , bool SF > // Symmetry flag
1511 template< typename VT > // Type of the right-hand side sparse vector
1513 {
1514  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1515  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1516 
1517  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1518  matrix_.append( row_, element->index(), element->value() );
1519  }
1520 }
1521 //*************************************************************************************************
1522 
1523 
1524 //*************************************************************************************************
1535 template< typename MT // Type of the sparse matrix
1536  , bool SO // Storage order
1537  , bool SF > // Symmetry flag
1538 template< typename VT > // Type of the right-hand side dense vector
1540 {
1541  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1542 
1546 
1547  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1548 
1549  const AddType tmp( serial( *this + (~rhs) ) );
1550  matrix_.reset( row_ );
1551  assign( tmp );
1552 }
1553 //*************************************************************************************************
1554 
1555 
1556 //*************************************************************************************************
1567 template< typename MT // Type of the sparse matrix
1568  , bool SO // Storage order
1569  , bool SF > // Symmetry flag
1570 template< typename VT > // Type of the right-hand side sparse vector
1572 {
1573  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1574 
1578 
1579  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1580 
1581  const AddType tmp( serial( *this + (~rhs) ) );
1582  matrix_.reset ( row_ );
1583  matrix_.reserve( row_, tmp.nonZeros() );
1584  assign( tmp );
1585 }
1586 //*************************************************************************************************
1587 
1588 
1589 //*************************************************************************************************
1600 template< typename MT // Type of the sparse matrix
1601  , bool SO // Storage order
1602  , bool SF > // Symmetry flag
1603 template< typename VT > // Type of the right-hand side dense vector
1605 {
1606  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1607 
1611 
1612  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1613 
1614  const SubType tmp( serial( *this - (~rhs) ) );
1615  matrix_.reset ( row_ );
1616  assign( tmp );
1617 }
1618 //*************************************************************************************************
1619 
1620 
1621 //*************************************************************************************************
1632 template< typename MT // Type of the sparse matrix
1633  , bool SO // Storage order
1634  , bool SF > // Symmetry flag
1635 template< typename VT > // Type of the right-hand side sparse vector
1637 {
1638  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1639 
1643 
1644  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1645 
1646  const SubType tmp( serial( *this - (~rhs) ) );
1647  matrix_.reset ( row_ );
1648  matrix_.reserve( row_, tmp.nonZeros() );
1649  assign( tmp );
1650 }
1651 //*************************************************************************************************
1652 
1653 
1654 
1655 
1656 
1657 
1658 
1659 
1660 //=================================================================================================
1661 //
1662 // CLASS TEMPLATE SPECIALIZATION FOR GENERAL COLUMN-MAJOR MATRICES
1663 //
1664 //=================================================================================================
1665 
1666 //*************************************************************************************************
1674 template< typename MT > // Type of the sparse matrix
1675 class SparseRow<MT,false,false> : public SparseVector< SparseRow<MT,false,false>, true >
1676  , private Row
1677 {
1678  private:
1679  //**Type definitions****************************************************************************
1681  typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type Operand;
1682  //**********************************************************************************************
1683 
1684  //**********************************************************************************************
1686 
1692  enum { useConst = IsConst<MT>::value };
1693  //**********************************************************************************************
1694 
1695  public:
1696  //**Type definitions****************************************************************************
1697  typedef SparseRow<MT,false,false> This;
1698  typedef typename RowTrait<MT>::Type ResultType;
1699  typedef typename ResultType::TransposeType TransposeType;
1700  typedef typename MT::ElementType ElementType;
1701  typedef typename MT::ReturnType ReturnType;
1702  typedef const ResultType CompositeType;
1703 
1705  typedef typename MT::ConstReference ConstReference;
1706 
1708  typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference;
1709  //**********************************************************************************************
1710 
1711  //**RowElement class definition*****************************************************************
1714  template< typename MatrixType // Type of the sparse matrix
1715  , typename IteratorType > // Type of the sparse matrix iterator
1716  class RowElement : private SparseElement
1717  {
1718  private:
1719  //*******************************************************************************************
1721 
1726  enum { returnConst = IsConst<MatrixType>::value };
1727  //*******************************************************************************************
1728 
1729  //**Type definitions*************************************************************************
1731  typedef typename std::iterator_traits<IteratorType>::value_type SET;
1732 
1733  typedef typename SET::Reference RT;
1734  typedef typename SET::ConstReference CRT;
1735  //*******************************************************************************************
1736 
1737  public:
1738  //**Type definitions*************************************************************************
1739  typedef typename SET::ValueType ValueType;
1740  typedef size_t IndexType;
1741  typedef typename SelectType<returnConst,CRT,RT>::Type Reference;
1742  typedef CRT ConstReference;
1743  //*******************************************************************************************
1744 
1745  //**Constructor******************************************************************************
1751  inline RowElement( IteratorType pos, size_t column )
1752  : pos_ ( pos ) // Iterator to the current position within the sparse row
1753  , column_( column ) // Index of the according column
1754  {}
1755  //*******************************************************************************************
1756 
1757  //**Assignment operator**********************************************************************
1763  template< typename T > inline RowElement& operator=( const T& v ) {
1764  *pos_ = v;
1765  return *this;
1766  }
1767  //*******************************************************************************************
1768 
1769  //**Addition assignment operator*************************************************************
1775  template< typename T > inline RowElement& operator+=( const T& v ) {
1776  *pos_ += v;
1777  return *this;
1778  }
1779  //*******************************************************************************************
1780 
1781  //**Subtraction assignment operator**********************************************************
1787  template< typename T > inline RowElement& operator-=( const T& v ) {
1788  *pos_ -= v;
1789  return *this;
1790  }
1791  //*******************************************************************************************
1792 
1793  //**Multiplication assignment operator*******************************************************
1799  template< typename T > inline RowElement& operator*=( const T& v ) {
1800  *pos_ *= v;
1801  return *this;
1802  }
1803  //*******************************************************************************************
1804 
1805  //**Division assignment operator*************************************************************
1811  template< typename T > inline RowElement& operator/=( const T& v ) {
1812  *pos_ /= v;
1813  return *this;
1814  }
1815  //*******************************************************************************************
1816 
1817  //**Element access operator******************************************************************
1822  inline const RowElement* operator->() const {
1823  return this;
1824  }
1825  //*******************************************************************************************
1826 
1827  //**Value function***************************************************************************
1832  inline Reference value() const {
1833  return pos_->value();
1834  }
1835  //*******************************************************************************************
1836 
1837  //**Index function***************************************************************************
1842  inline IndexType index() const {
1843  return column_;
1844  }
1845  //*******************************************************************************************
1846 
1847  private:
1848  //**Member variables*************************************************************************
1849  IteratorType pos_;
1850  size_t column_;
1851  //*******************************************************************************************
1852  };
1853  //**********************************************************************************************
1854 
1855  //**RowIterator class definition****************************************************************
1858  template< typename MatrixType // Type of the sparse matrix
1859  , typename IteratorType > // Type of the sparse matrix iterator
1860  class RowIterator
1861  {
1862  public:
1863  //**Type definitions*************************************************************************
1864  typedef std::forward_iterator_tag IteratorCategory;
1865  typedef RowElement<MatrixType,IteratorType> ValueType;
1866  typedef ValueType PointerType;
1867  typedef ValueType ReferenceType;
1868  typedef ptrdiff_t DifferenceType;
1869 
1870  // STL iterator requirements
1871  typedef IteratorCategory iterator_category;
1872  typedef ValueType value_type;
1873  typedef PointerType pointer;
1874  typedef ReferenceType reference;
1875  typedef DifferenceType difference_type;
1876  //*******************************************************************************************
1877 
1878  //**Constructor******************************************************************************
1881  inline RowIterator()
1882  : matrix_( NULL ) // The sparse matrix containing the row.
1883  , row_ ( 0UL ) // The current row index.
1884  , column_( 0UL ) // The current column index.
1885  , pos_ () // Iterator to the current sparse element.
1886  {}
1887  //*******************************************************************************************
1888 
1889  //**Constructor******************************************************************************
1896  inline RowIterator( MatrixType& matrix, size_t row, size_t column )
1897  : matrix_( &matrix ) // The sparse matrix containing the row.
1898  , row_ ( row ) // The current row index.
1899  , column_( column ) // The current column index.
1900  , pos_ () // Iterator to the current sparse element.
1901  {
1902  for( ; column_<matrix_->columns(); ++column_ ) {
1903  pos_ = matrix_->find( row_, column_ );
1904  if( pos_ != matrix_->end( column_ ) ) break;
1905  }
1906  }
1907  //*******************************************************************************************
1908 
1909  //**Constructor******************************************************************************
1917  inline RowIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
1918  : matrix_( &matrix ) // The sparse matrix containing the row.
1919  , row_ ( row ) // The current row index.
1920  , column_( column ) // The current column index.
1921  , pos_ ( pos ) // Iterator to the current sparse element.
1922  {
1923  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
1924  }
1925  //*******************************************************************************************
1926 
1927  //**Constructor******************************************************************************
1932  template< typename MatrixType2, typename IteratorType2 >
1933  inline RowIterator( const RowIterator<MatrixType2,IteratorType2>& it )
1934  : matrix_( it.matrix_ ) // The sparse matrix containing the row.
1935  , row_ ( it.row_ ) // The current row index.
1936  , column_( it.column_ ) // The current column index.
1937  , pos_ ( it.pos_ ) // Iterator to the current sparse element.
1938  {}
1939  //*******************************************************************************************
1940 
1941  //**Prefix increment operator****************************************************************
1946  inline RowIterator& operator++() {
1947  ++column_;
1948  for( ; column_<matrix_->columns(); ++column_ ) {
1949  pos_ = matrix_->find( row_, column_ );
1950  if( pos_ != matrix_->end( column_ ) ) break;
1951  }
1952 
1953  return *this;
1954  }
1955  //*******************************************************************************************
1956 
1957  //**Postfix increment operator***************************************************************
1962  inline const RowIterator operator++( int ) {
1963  const RowIterator tmp( *this );
1964  ++(*this);
1965  return tmp;
1966  }
1967  //*******************************************************************************************
1968 
1969  //**Element access operator******************************************************************
1974  inline ReferenceType operator*() const {
1975  return ReferenceType( pos_, column_ );
1976  }
1977  //*******************************************************************************************
1978 
1979  //**Element access operator******************************************************************
1984  inline PointerType operator->() const {
1985  return PointerType( pos_, column_ );
1986  }
1987  //*******************************************************************************************
1988 
1989  //**Equality operator************************************************************************
1995  template< typename MatrixType2, typename IteratorType2 >
1996  inline bool operator==( const RowIterator<MatrixType2,IteratorType2>& rhs ) const {
1997  return ( matrix_ == rhs.matrix_ ) && ( row_ == rhs.row_ ) && ( column_ == rhs.column_ );
1998  }
1999  //*******************************************************************************************
2000 
2001  //**Inequality operator**********************************************************************
2007  template< typename MatrixType2, typename IteratorType2 >
2008  inline bool operator!=( const RowIterator<MatrixType2,IteratorType2>& rhs ) const {
2009  return !( *this == rhs );
2010  }
2011  //*******************************************************************************************
2012 
2013  //**Subtraction operator*********************************************************************
2019  inline DifferenceType operator-( const RowIterator& rhs ) const {
2020  size_t counter( 0UL );
2021  for( size_t j=rhs.column_; j<column_; ++j ) {
2022  if( matrix_->find( row_, j ) != matrix_->end( j ) )
2023  ++counter;
2024  }
2025  return counter;
2026  }
2027  //*******************************************************************************************
2028 
2029  private:
2030  //**Member variables*************************************************************************
2031  MatrixType* matrix_;
2032  size_t row_;
2033  size_t column_;
2034  IteratorType pos_;
2035  //*******************************************************************************************
2036 
2037  //**Friend declarations**********************************************************************
2038  template< typename MatrixType2, typename IteratorType2 > friend class RowIterator;
2039  template< typename MT2, bool SO2, bool SF2 > friend class SparseRow;
2040  //*******************************************************************************************
2041  };
2042  //**********************************************************************************************
2043 
2044  //**Type definitions****************************************************************************
2046  typedef RowIterator<const MT,typename MT::ConstIterator> ConstIterator;
2047 
2049  typedef typename SelectType< useConst, ConstIterator, RowIterator<MT,typename MT::Iterator> >::Type Iterator;
2050  //**********************************************************************************************
2051 
2052  //**Compilation flags***************************************************************************
2054  enum { smpAssignable = 0 };
2055  //**********************************************************************************************
2056 
2057  //**Constructors********************************************************************************
2060  explicit inline SparseRow( MT& matrix, size_t index );
2061  // No explicitly declared copy constructor.
2063  //**********************************************************************************************
2064 
2065  //**Destructor**********************************************************************************
2066  // No explicitly declared destructor.
2067  //**********************************************************************************************
2068 
2069  //**Data access functions***********************************************************************
2072  inline Reference operator[]( size_t index );
2073  inline ConstReference operator[]( size_t index ) const;
2074  inline Iterator begin ();
2075  inline ConstIterator begin () const;
2076  inline ConstIterator cbegin() const;
2077  inline Iterator end ();
2078  inline ConstIterator end () const;
2079  inline ConstIterator cend () const;
2081  //**********************************************************************************************
2082 
2083  //**Assignment operators************************************************************************
2086  inline SparseRow& operator= ( const SparseRow& rhs );
2087  template< typename VT > inline SparseRow& operator= ( const Vector<VT,true>& rhs );
2088  template< typename VT > inline SparseRow& operator+=( const Vector<VT,true>& rhs );
2089  template< typename VT > inline SparseRow& operator-=( const Vector<VT,true>& rhs );
2090  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
2091 
2092  template< typename Other >
2093  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
2094  operator*=( Other rhs );
2095 
2096  template< typename Other >
2097  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
2098  operator/=( Other rhs );
2100  //**********************************************************************************************
2101 
2102  //**Utility functions***************************************************************************
2105  inline size_t size() const;
2106  inline size_t capacity() const;
2107  inline size_t nonZeros() const;
2108  inline void reset();
2109  inline Iterator set ( size_t index, const ElementType& value );
2110  inline Iterator insert ( size_t index, const ElementType& value );
2111  inline void erase ( size_t index );
2112  inline Iterator erase ( Iterator pos );
2113  inline Iterator erase ( Iterator first, Iterator last );
2114  inline void reserve( size_t n );
2115  template< typename Other > inline SparseRow& scale ( const Other& scalar );
2117  //**********************************************************************************************
2118 
2119  //**Lookup functions****************************************************************************
2122  inline Iterator find ( size_t index );
2123  inline ConstIterator find ( size_t index ) const;
2124  inline Iterator lowerBound( size_t index );
2125  inline ConstIterator lowerBound( size_t index ) const;
2126  inline Iterator upperBound( size_t index );
2127  inline ConstIterator upperBound( size_t index ) const;
2129  //**********************************************************************************************
2130 
2131  //**Low-level utility functions*****************************************************************
2134  inline void append( size_t index, const ElementType& value, bool check=false );
2136  //**********************************************************************************************
2137 
2138  //**Expression template evaluation functions****************************************************
2141  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2142  template< typename Other > inline bool isAliased( const Other* alias ) const;
2143 
2144  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
2145  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
2146  template< typename VT > inline void addAssign( const Vector<VT,true>& rhs );
2147  template< typename VT > inline void subAssign( const Vector<VT,true>& rhs );
2149  //**********************************************************************************************
2150 
2151  private:
2152  //**Member variables****************************************************************************
2155  Operand matrix_;
2156  const size_t row_;
2157 
2158  //**********************************************************************************************
2159 
2160  //**Friend declarations*************************************************************************
2161  template< typename MT2, bool SO2, bool SF2 >
2162  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
2163  //**********************************************************************************************
2164 
2165  //**Compile time checks*************************************************************************
2171  //**********************************************************************************************
2172 };
2174 //*************************************************************************************************
2175 
2176 
2177 
2178 
2179 //=================================================================================================
2180 //
2181 // CONSTRUCTOR
2182 //
2183 //=================================================================================================
2184 
2185 //*************************************************************************************************
2193 template< typename MT > // Type of the sparse matrix
2194 inline SparseRow<MT,false,false>::SparseRow( MT& matrix, size_t index )
2195  : matrix_( matrix ) // The sparse matrix containing the row
2196  , row_ ( index ) // The index of the row in the matrix
2197 {
2198  if( matrix_.rows() <= index )
2199  throw std::invalid_argument( "Invalid row access index" );
2200 }
2202 //*************************************************************************************************
2203 
2204 
2205 
2206 
2207 //=================================================================================================
2208 //
2209 // DATA ACCESS FUNCTIONS
2210 //
2211 //=================================================================================================
2212 
2213 //*************************************************************************************************
2220 template< typename MT > // Type of the sparse matrix
2223 {
2224  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2225  return matrix_(row_,index);
2226 }
2228 //*************************************************************************************************
2229 
2230 
2231 //*************************************************************************************************
2238 template< typename MT > // Type of the sparse matrix
2240  SparseRow<MT,false,false>::operator[]( size_t index ) const
2241 {
2242  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
2243  return const_cast<const MT&>( matrix_ )(row_,index);
2244 }
2246 //*************************************************************************************************
2247 
2248 
2249 //*************************************************************************************************
2257 template< typename MT > // Type of the sparse matrix
2259 {
2260  return Iterator( matrix_, row_, 0UL );
2261 }
2263 //*************************************************************************************************
2264 
2265 
2266 //*************************************************************************************************
2274 template< typename MT > // Type of the sparse matrix
2276 {
2277  return ConstIterator( matrix_, row_, 0UL );
2278 }
2280 //*************************************************************************************************
2281 
2282 
2283 //*************************************************************************************************
2291 template< typename MT > // Type of the sparse matrix
2293 {
2294  return ConstIterator( matrix_, row_, 0UL );
2295 }
2297 //*************************************************************************************************
2298 
2299 
2300 //*************************************************************************************************
2308 template< typename MT > // Type of the sparse matrix
2310 {
2311  return Iterator( matrix_, row_, size() );
2312 }
2314 //*************************************************************************************************
2315 
2316 
2317 //*************************************************************************************************
2325 template< typename MT > // Type of the sparse matrix
2327 {
2328  return ConstIterator( matrix_, row_, size() );
2329 }
2331 //*************************************************************************************************
2332 
2333 
2334 //*************************************************************************************************
2342 template< typename MT > // Type of the sparse matrix
2344 {
2345  return ConstIterator( matrix_, row_, size() );
2346 }
2348 //*************************************************************************************************
2349 
2350 
2351 
2352 
2353 //=================================================================================================
2354 //
2355 // ASSIGNMENT OPERATORS
2356 //
2357 //=================================================================================================
2358 
2359 //*************************************************************************************************
2370 template< typename MT > // Type of the sparse matrix
2371 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator=( const SparseRow& rhs )
2372 {
2373  using blaze::assign;
2374 
2378 
2379  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
2380  return *this;
2381 
2382  if( size() != rhs.size() )
2383  throw std::invalid_argument( "Row sizes do not match" );
2384 
2385  if( rhs.canAlias( &matrix_ ) ) {
2386  const ResultType tmp( rhs );
2387  assign( *this, tmp );
2388  }
2389  else {
2390  assign( *this, rhs );
2391  }
2392 
2393  return *this;
2394 }
2396 //*************************************************************************************************
2397 
2398 
2399 //*************************************************************************************************
2410 template< typename MT > // Type of the sparse matrix
2411 template< typename VT > // Type of the right-hand side vector
2412 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator=( const Vector<VT,true>& rhs )
2413 {
2414  using blaze::assign;
2415 
2416  if( size() != (~rhs).size() )
2417  throw std::invalid_argument( "Vector sizes do not match" );
2418 
2419  const typename VT::CompositeType tmp( ~rhs );
2420  assign( *this, tmp );
2421 
2422  return *this;
2423 }
2425 //*************************************************************************************************
2426 
2427 
2428 //*************************************************************************************************
2439 template< typename MT > // Type of the sparse matrix
2440 template< typename VT > // Type of the right-hand side vector
2441 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator+=( const Vector<VT,true>& rhs )
2442 {
2443  using blaze::addAssign;
2444 
2445  if( size() != (~rhs).size() )
2446  throw std::invalid_argument( "Vector sizes do not match" );
2447 
2448  addAssign( *this, ~rhs );
2449 
2450  return *this;
2451 }
2453 //*************************************************************************************************
2454 
2455 
2456 //*************************************************************************************************
2467 template< typename MT > // Type of the sparse matrix
2468 template< typename VT > // Type of the right-hand side vector
2469 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator-=( const Vector<VT,true>& rhs )
2470 {
2471  using blaze::subAssign;
2472 
2473  if( size() != (~rhs).size() )
2474  throw std::invalid_argument( "Vector sizes do not match" );
2475 
2476  subAssign( *this, ~rhs );
2477 
2478  return *this;
2479 }
2481 //*************************************************************************************************
2482 
2483 
2484 //*************************************************************************************************
2496 template< typename MT > // Type of the sparse matrix
2497 template< typename VT > // Type of the right-hand side vector
2498 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::operator*=( const Vector<VT,true>& rhs )
2499 {
2500  if( size() != (~rhs).size() )
2501  throw std::invalid_argument( "Vector sizes do not match" );
2502 
2503  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
2504 
2507 
2508  const MultType tmp( *this * (~rhs) );
2509  assign( tmp );
2510 
2511  return *this;
2512 }
2514 //*************************************************************************************************
2515 
2516 
2517 //*************************************************************************************************
2529 template< typename MT > // Type of the sparse matrix
2530 template< typename Other > // Data type of the right-hand side scalar
2531 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
2532  SparseRow<MT,false,false>::operator*=( Other rhs )
2533 {
2534  for( Iterator element=begin(); element!=end(); ++element )
2535  element->value() *= rhs;
2536  return *this;
2537 }
2539 //*************************************************************************************************
2540 
2541 
2542 //*************************************************************************************************
2555 template< typename MT > // Type of the sparse matrix
2556 template< typename Other > // Data type of the right-hand side scalar
2557 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,false> >::Type&
2558  SparseRow<MT,false,false>::operator/=( Other rhs )
2559 {
2560  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
2561 
2562  typedef typename DivTrait<ElementType,Other>::Type DT;
2563  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
2564 
2565  // Depending on the two involved data types, an integer division is applied or a
2566  // floating point division is selected.
2567  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
2568  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
2569  for( Iterator element=begin(); element!=end(); ++element )
2570  element->value() *= tmp;
2571  }
2572  else {
2573  for( Iterator element=begin(); element!=end(); ++element )
2574  element->value() /= rhs;
2575  }
2576 
2577  return *this;
2578 }
2580 //*************************************************************************************************
2581 
2582 
2583 
2584 
2585 //=================================================================================================
2586 //
2587 // UTILITY FUNCTIONS
2588 //
2589 //=================================================================================================
2590 
2591 //*************************************************************************************************
2597 template< typename MT > // Type of the sparse matrix
2598 inline size_t SparseRow<MT,false,false>::size() const
2599 {
2600  return matrix_.columns();
2601 }
2603 //*************************************************************************************************
2604 
2605 
2606 //*************************************************************************************************
2612 template< typename MT > // Type of the sparse matrix
2613 inline size_t SparseRow<MT,false,false>::capacity() const
2614 {
2615  return matrix_.columns();
2616 }
2618 //*************************************************************************************************
2619 
2620 
2621 //*************************************************************************************************
2630 template< typename MT > // Type of the sparse matrix
2631 inline size_t SparseRow<MT,false,false>::nonZeros() const
2632 {
2633  size_t counter( 0UL );
2634  for( ConstIterator element=begin(); element!=end(); ++element ) {
2635  ++counter;
2636  }
2637  return counter;
2638 }
2640 //*************************************************************************************************
2641 
2642 
2643 //*************************************************************************************************
2649 template< typename MT > // Type of the sparse matrix
2651 {
2652  for( size_t j=0UL; j<size(); ++j ) {
2653  matrix_.erase( row_, j );
2654  }
2655 }
2657 //*************************************************************************************************
2658 
2659 
2660 //*************************************************************************************************
2673 template< typename MT > // Type of the sparse matrix
2675  SparseRow<MT,false,false>::insert( size_t index, const ElementType& value )
2676 {
2677  return Iterator( matrix_, row_, index, matrix_.insert( row_, index, value ) );
2678 }
2680 //*************************************************************************************************
2681 
2682 
2683 //*************************************************************************************************
2695 template< typename MT > // Type of the sparse matrix
2697  SparseRow<MT,false,false>::set( size_t index, const ElementType& value )
2698 {
2699  return Iterator( matrix_, row_, index, matrix_.set( row_, index, value ) );
2700 }
2702 //*************************************************************************************************
2703 
2704 
2705 //*************************************************************************************************
2714 template< typename MT > // Type of the sparse matrix
2715 inline void SparseRow<MT,false,false>::erase( size_t index )
2716 {
2717  matrix_.erase( row_, index );
2718 }
2720 //*************************************************************************************************
2721 
2722 
2723 //*************************************************************************************************
2732 template< typename MT > // Type of the sparse matrix
2734 {
2735  const size_t column( pos.column_ );
2736 
2737  if( column == size() )
2738  return pos;
2739 
2740  matrix_.erase( column, pos.pos_ );
2741  return Iterator( matrix_, row_, column+1UL );
2742 }
2744 //*************************************************************************************************
2745 
2746 
2747 //*************************************************************************************************
2757 template< typename MT > // Type of the sparse matrix
2760 {
2761  for( ; first!=last; ++first ) {
2762  matrix_.erase( first.column_, first.pos_ );
2763  }
2764  return last;
2765 }
2767 //*************************************************************************************************
2768 
2769 
2770 //*************************************************************************************************
2780 template< typename MT > // Type of the sparse matrix
2781 void SparseRow<MT,false,false>::reserve( size_t n )
2782 {
2783  UNUSED_PARAMETER( n );
2784  return;
2785 }
2787 //*************************************************************************************************
2788 
2789 
2790 //*************************************************************************************************
2797 template< typename MT > // Type of the sparse matrix
2798 template< typename Other > // Data type of the scalar value
2799 inline SparseRow<MT,false,false>& SparseRow<MT,false,false>::scale( const Other& scalar )
2800 {
2801  for( Iterator element=begin(); element!=end(); ++element )
2802  element->value() *= scalar;
2803  return *this;
2804 }
2806 //*************************************************************************************************
2807 
2808 
2809 
2810 
2811 //=================================================================================================
2812 //
2813 // LOOKUP FUNCTIONS
2814 //
2815 //=================================================================================================
2816 
2817 //*************************************************************************************************
2831 template< typename MT > // Type of the sparse matrix
2833 {
2834  const typename MT::Iterator pos( matrix_.find( row_, index ) );
2835 
2836  if( pos != matrix_.end( index ) )
2837  return Iterator( matrix_, row_, index, pos );
2838  else
2839  return end();
2840 }
2842 //*************************************************************************************************
2843 
2844 
2845 //*************************************************************************************************
2859 template< typename MT > // Type of the sparse matrix
2861  SparseRow<MT,false,false>::find( size_t index ) const
2862 {
2863  const typename MT::ConstIterator pos( matrix_.find( row_, index ) );
2864 
2865  if( pos != matrix_.end( index ) )
2866  return ConstIterator( matrix_, row_, index, pos );
2867  else
2868  return end();
2869 }
2871 //*************************************************************************************************
2872 
2873 
2874 //*************************************************************************************************
2887 template< typename MT > // Type of the sparse matrix
2890 {
2891  for( size_t i=index; i<size(); ++i )
2892  {
2893  const typename MT::Iterator pos( matrix_.find( row_, i ) );
2894 
2895  if( pos != matrix_.end( i ) )
2896  return Iterator( matrix_, row_, i, pos );
2897  }
2898 
2899  return end();
2900 }
2902 //*************************************************************************************************
2903 
2904 
2905 //*************************************************************************************************
2918 template< typename MT > // Type of the sparse matrix
2920  SparseRow<MT,false,false>::lowerBound( size_t index ) const
2921 {
2922  for( size_t i=index; i<size(); ++i )
2923  {
2924  const typename MT::ConstIterator pos( matrix_.find( row_, i ) );
2925 
2926  if( pos != matrix_.end( i ) )
2927  return ConstIterator( matrix_, row_, i, pos );
2928  }
2929 
2930  return end();
2931 }
2933 //*************************************************************************************************
2934 
2935 
2936 //*************************************************************************************************
2949 template< typename MT > // Type of the sparse matrix
2952 {
2953  for( size_t i=index+1UL; i<size(); ++i )
2954  {
2955  const typename MT::Iterator pos( matrix_.find( row_, i ) );
2956 
2957  if( pos != matrix_.end( i ) )
2958  return Iterator( matrix_, row_, i, pos );
2959  }
2960 
2961  return end();
2962 }
2964 //*************************************************************************************************
2965 
2966 
2967 //*************************************************************************************************
2980 template< typename MT > // Type of the sparse matrix
2982  SparseRow<MT,false,false>::upperBound( size_t index ) const
2983 {
2984  for( size_t i=index+1UL; i<size(); ++i )
2985  {
2986  const typename MT::ConstIterator pos( matrix_.find( row_, i ) );
2987 
2988  if( pos != matrix_.end( i ) )
2989  return ConstIterator( matrix_, row_, i, pos );
2990  }
2991 
2992  return end();
2993 }
2995 //*************************************************************************************************
2996 
2997 
2998 
2999 
3000 //=================================================================================================
3001 //
3002 // LOW-LEVEL UTILITY FUNCTIONS
3003 //
3004 //=================================================================================================
3005 
3006 //*************************************************************************************************
3031 template< typename MT > // Type of the sparse matrix
3032 inline void SparseRow<MT,false,false>::append( size_t index, const ElementType& value, bool check )
3033 {
3034  if( !check || !isDefault( value ) )
3035  matrix_.insert( row_, index, value );
3036 }
3038 //*************************************************************************************************
3039 
3040 
3041 
3042 
3043 //=================================================================================================
3044 //
3045 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3046 //
3047 //=================================================================================================
3048 
3049 //*************************************************************************************************
3060 template< typename MT > // Type of the sparse matrix
3061 template< typename Other > // Data type of the foreign expression
3062 inline bool SparseRow<MT,false,false>::canAlias( const Other* alias ) const
3063 {
3064  return matrix_.isAliased( alias );
3065 }
3067 //*************************************************************************************************
3068 
3069 
3070 //*************************************************************************************************
3077 template< typename MT > // Type of the sparse matrix
3078 template< typename Other > // Data type of the foreign expression
3079 inline bool SparseRow<MT,false,false>::isAliased( const Other* alias ) const
3080 {
3081  return matrix_.isAliased( alias );
3082 }
3084 //*************************************************************************************************
3085 
3086 
3087 //*************************************************************************************************
3099 template< typename MT > // Type of the sparse matrix
3100 template< typename VT > // Type of the right-hand side dense vector
3101 inline void SparseRow<MT,false,false>::assign( const DenseVector<VT,true>& rhs )
3102 {
3103  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3104 
3105  for( size_t j=0UL; j<(~rhs).size(); ++j ) {
3106  matrix_(row_,j) = (~rhs)[j];
3107  }
3108 }
3110 //*************************************************************************************************
3111 
3112 
3113 //*************************************************************************************************
3125 template< typename MT > // Type of the sparse matrix
3126 template< typename VT > // Type of the right-hand side sparse vector
3127 inline void SparseRow<MT,false,false>::assign( const SparseVector<VT,true>& rhs )
3128 {
3129  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3130 
3131  size_t j( 0UL );
3132 
3133  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
3134  for( ; j<element->index(); ++j )
3135  matrix_.erase( row_, j );
3136  matrix_(row_,j++) = element->value();
3137  }
3138  for( ; j<size(); ++j ) {
3139  matrix_.erase( row_, j );
3140  }
3141 }
3143 //*************************************************************************************************
3144 
3145 
3146 //*************************************************************************************************
3158 template< typename MT > // Type of the sparse matrix
3159 template< typename VT > // Type of the right-hand side vector
3160 inline void SparseRow<MT,false,false>::addAssign( const Vector<VT,true>& rhs )
3161 {
3162  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3163 
3166 
3167  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3168 
3169  const AddType tmp( serial( *this + (~rhs) ) );
3170  assign( tmp );
3171 }
3173 //*************************************************************************************************
3174 
3175 
3176 //*************************************************************************************************
3188 template< typename MT > // Type of the sparse matrix
3189 template< typename VT > // Type of the right-hand side vector
3190 inline void SparseRow<MT,false,false>::subAssign( const Vector<VT,true>& rhs )
3191 {
3192  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3193 
3196 
3197  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3198 
3199  const SubType tmp( serial( *this - (~rhs) ) );
3200  assign( tmp );
3201 }
3203 //*************************************************************************************************
3204 
3205 
3206 
3207 
3208 
3209 
3210 
3211 
3212 //=================================================================================================
3213 //
3214 // CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC COLUMN-MAJOR MATRICES
3215 //
3216 //=================================================================================================
3217 
3218 //*************************************************************************************************
3226 template< typename MT > // Type of the sparse matrix
3227 class SparseRow<MT,false,true> : public SparseVector< SparseRow<MT,false,true>, true >
3228  , private Row
3229 {
3230  private:
3231  //**Type definitions****************************************************************************
3233  typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type Operand;
3234  //**********************************************************************************************
3235 
3236  //**********************************************************************************************
3238 
3244  enum { useConst = IsConst<MT>::value };
3245  //**********************************************************************************************
3246 
3247  public:
3248  //**Type definitions****************************************************************************
3249  typedef SparseRow<MT,false,true> This;
3250  typedef typename RowTrait<MT>::Type ResultType;
3251  typedef typename ResultType::TransposeType TransposeType;
3252  typedef typename MT::ElementType ElementType;
3253  typedef typename MT::ReturnType ReturnType;
3254  typedef const SparseRow& CompositeType;
3255 
3257  typedef typename MT::ConstReference ConstReference;
3258 
3260  typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference;
3261 
3263  typedef typename MT::ConstIterator ConstIterator;
3264 
3266  typedef typename SelectType< useConst, ConstIterator, typename MT::Iterator >::Type Iterator;
3267  //**********************************************************************************************
3268 
3269  //**Compilation flags***************************************************************************
3271  enum { smpAssignable = 0 };
3272  //**********************************************************************************************
3273 
3274  //**Constructors********************************************************************************
3277  explicit inline SparseRow( MT& matrix, size_t index );
3278  // No explicitly declared copy constructor.
3280  //**********************************************************************************************
3281 
3282  //**Destructor**********************************************************************************
3283  // No explicitly declared destructor.
3284  //**********************************************************************************************
3285 
3286  //**Data access functions***********************************************************************
3289  inline Reference operator[]( size_t index );
3290  inline ConstReference operator[]( size_t index ) const;
3291  inline Iterator begin ();
3292  inline ConstIterator begin () const;
3293  inline ConstIterator cbegin() const;
3294  inline Iterator end ();
3295  inline ConstIterator end () const;
3296  inline ConstIterator cend () const;
3298  //**********************************************************************************************
3299 
3300  //**Assignment operators************************************************************************
3303  inline SparseRow& operator= ( const SparseRow& rhs );
3304  template< typename VT > inline SparseRow& operator= ( const DenseVector <VT,true>& rhs );
3305  template< typename VT > inline SparseRow& operator= ( const SparseVector<VT,true>& rhs );
3306  template< typename VT > inline SparseRow& operator+=( const Vector<VT,true>& rhs );
3307  template< typename VT > inline SparseRow& operator-=( const Vector<VT,true>& rhs );
3308  template< typename VT > inline SparseRow& operator*=( const Vector<VT,true>& rhs );
3309 
3310  template< typename Other >
3311  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
3312  operator*=( Other rhs );
3313 
3314  template< typename Other >
3315  inline typename EnableIf< IsNumeric<Other>, SparseRow >::Type&
3316  operator/=( Other rhs );
3318  //**********************************************************************************************
3319 
3320  //**Utility functions***************************************************************************
3323  inline size_t size() const;
3324  inline size_t capacity() const;
3325  inline size_t nonZeros() const;
3326  inline void reset();
3327  inline Iterator set ( size_t index, const ElementType& value );
3328  inline Iterator insert ( size_t index, const ElementType& value );
3329  inline void erase ( size_t index );
3330  inline Iterator erase ( Iterator pos );
3331  inline Iterator erase ( Iterator first, Iterator last );
3332  inline void reserve( size_t n );
3333  template< typename Other > inline SparseRow& scale ( const Other& scalar );
3335  //**********************************************************************************************
3336 
3337  //**Lookup functions****************************************************************************
3340  inline Iterator find ( size_t index );
3341  inline ConstIterator find ( size_t index ) const;
3342  inline Iterator lowerBound( size_t index );
3343  inline ConstIterator lowerBound( size_t index ) const;
3344  inline Iterator upperBound( size_t index );
3345  inline ConstIterator upperBound( size_t index ) const;
3347  //**********************************************************************************************
3348 
3349  //**Low-level utility functions*****************************************************************
3352  inline void append( size_t index, const ElementType& value, bool check=false );
3354  //**********************************************************************************************
3355 
3356  //**Expression template evaluation functions****************************************************
3359  template< typename Other > inline bool canAlias ( const Other* alias ) const;
3360  template< typename Other > inline bool isAliased( const Other* alias ) const;
3361 
3362  template< typename VT > inline void assign ( const DenseVector <VT,true>& rhs );
3363  template< typename VT > inline void assign ( const SparseVector<VT,true>& rhs );
3364  template< typename VT > inline void addAssign( const DenseVector <VT,true>& rhs );
3365  template< typename VT > inline void addAssign( const SparseVector<VT,true>& rhs );
3366  template< typename VT > inline void subAssign( const DenseVector <VT,true>& rhs );
3367  template< typename VT > inline void subAssign( const SparseVector<VT,true>& rhs );
3369  //**********************************************************************************************
3370 
3371  private:
3372  //**Utility functions***************************************************************************
3375  inline size_t extendCapacity() const;
3377  //**********************************************************************************************
3378 
3379  //**Member variables****************************************************************************
3382  Operand matrix_;
3383  const size_t row_;
3384 
3385  //**********************************************************************************************
3386 
3387  //**Friend declarations*************************************************************************
3388  template< typename MT2, bool SO2, bool SF2 >
3389  friend bool isSame( const SparseRow<MT2,SO2,SF2>& a, const SparseRow<MT2,SO2,SF2>& b );
3390  //**********************************************************************************************
3391 
3392  //**Compile time checks*************************************************************************
3398  //**********************************************************************************************
3399 };
3401 //*************************************************************************************************
3402 
3403 
3404 
3405 
3406 //=================================================================================================
3407 //
3408 // CONSTRUCTOR
3409 //
3410 //=================================================================================================
3411 
3412 //*************************************************************************************************
3420 template< typename MT > // Type of the sparse matrix
3421 inline SparseRow<MT,false,true>::SparseRow( MT& matrix, size_t index )
3422  : matrix_( matrix ) // The sparse matrix containing the row
3423  , row_ ( index ) // The index of the row in the matrix
3424 {
3425  if( matrix_.rows() <= index )
3426  throw std::invalid_argument( "Invalid row access index" );
3427 }
3429 //*************************************************************************************************
3430 
3431 
3432 
3433 
3434 //=================================================================================================
3435 //
3436 // DATA ACCESS FUNCTIONS
3437 //
3438 //=================================================================================================
3439 
3440 //*************************************************************************************************
3447 template< typename MT > // Type of the sparse matrix
3449  SparseRow<MT,false,true>::operator[]( size_t index )
3450 {
3451  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
3452  return matrix_(index,row_);
3453 }
3455 //*************************************************************************************************
3456 
3457 
3458 //*************************************************************************************************
3465 template< typename MT > // Type of the sparse matrix
3467  SparseRow<MT,false,true>::operator[]( size_t index ) const
3468 {
3469  BLAZE_USER_ASSERT( index < size(), "Invalid row access index" );
3470  return const_cast<const MT&>( matrix_ )(index,row_);
3471 }
3473 //*************************************************************************************************
3474 
3475 
3476 //*************************************************************************************************
3484 template< typename MT > // Type of the sparse matrix
3486 {
3487  return matrix_.begin( row_ );
3488 }
3490 //*************************************************************************************************
3491 
3492 
3493 //*************************************************************************************************
3501 template< typename MT > // Type of the sparse matrix
3503 {
3504  return matrix_.cbegin( row_ );
3505 }
3507 //*************************************************************************************************
3508 
3509 
3510 //*************************************************************************************************
3518 template< typename MT > // Type of the sparse matrix
3520 {
3521  return matrix_.cbegin( row_ );
3522 }
3524 //*************************************************************************************************
3525 
3526 
3527 //*************************************************************************************************
3535 template< typename MT > // Type of the sparse matrix
3537 {
3538  return matrix_.end( row_ );
3539 }
3541 //*************************************************************************************************
3542 
3543 
3544 //*************************************************************************************************
3552 template< typename MT > // Type of the sparse matrix
3554 {
3555  return matrix_.cend( row_ );
3556 }
3558 //*************************************************************************************************
3559 
3560 
3561 //*************************************************************************************************
3569 template< typename MT > // Type of the sparse matrix
3571 {
3572  return matrix_.cend( row_ );
3573 }
3575 //*************************************************************************************************
3576 
3577 
3578 
3579 
3580 //=================================================================================================
3581 //
3582 // ASSIGNMENT OPERATORS
3583 //
3584 //=================================================================================================
3585 
3586 //*************************************************************************************************
3597 template< typename MT > // Type of the sparse matrix
3598 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::operator=( const SparseRow& rhs )
3599 {
3600  using blaze::assign;
3601 
3605 
3606  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && row_ == rhs.row_ ) )
3607  return *this;
3608 
3609  if( size() != rhs.size() )
3610  throw std::invalid_argument( "Row sizes do not match" );
3611 
3612  if( rhs.canAlias( &matrix_ ) ) {
3613  const ResultType tmp( rhs );
3614  matrix_.reset ( row_ );
3615  matrix_.reserve( row_, tmp.nonZeros() );
3616  assign( *this, tmp );
3617  }
3618  else {
3619  matrix_.reset ( row_ );
3620  matrix_.reserve( row_, rhs.nonZeros() );
3621  assign( *this, rhs );
3622  }
3623 
3624  return *this;
3625 }
3627 //*************************************************************************************************
3628 
3629 
3630 //*************************************************************************************************
3641 template< typename MT > // Type of the sparse matrix
3642 template< typename VT > // Type of the right-hand side dense vector
3643 inline SparseRow<MT,false,true>&
3644  SparseRow<MT,false,true>::operator=( const DenseVector<VT,true>& rhs )
3645 {
3646  using blaze::assign;
3647 
3651 
3652  if( size() != (~rhs).size() )
3653  throw std::invalid_argument( "Vector sizes do not match" );
3654 
3655  if( (~rhs).canAlias( &matrix_ ) ) {
3656  const typename VT::ResultType tmp( ~rhs );
3657  matrix_.reset( row_ );
3658  assign( *this, tmp );
3659  }
3660  else {
3661  matrix_.reset( row_ );
3662  assign( *this, ~rhs );
3663  }
3664 
3665  return *this;
3666 }
3668 //*************************************************************************************************
3669 
3670 
3671 //*************************************************************************************************
3682 template< typename MT > // Type of the sparse matrix
3683 template< typename VT > // Type of the right-hand side sparse vector
3684 inline SparseRow<MT,false,true>&
3685  SparseRow<MT,false,true>::operator=( const SparseVector<VT,true>& rhs )
3686 {
3687  using blaze::assign;
3688 
3692 
3693  if( size() != (~rhs).size() )
3694  throw std::invalid_argument( "Vector sizes do not match" );
3695 
3696  if( (~rhs).canAlias( &matrix_ ) ) {
3697  const typename VT::ResultType tmp( ~rhs );
3698  matrix_.reset ( row_ );
3699  matrix_.reserve( row_, tmp.nonZeros() );
3700  assign( *this, tmp );
3701  }
3702  else {
3703  matrix_.reset ( row_ );
3704  matrix_.reserve( row_, (~rhs).nonZeros() );
3705  assign( *this, ~rhs );
3706  }
3707 
3708  return *this;
3709 }
3711 //*************************************************************************************************
3712 
3713 
3714 //*************************************************************************************************
3725 template< typename MT > // Type of the sparse matrix
3726 template< typename VT > // Type of the right-hand side vector
3727 inline SparseRow<MT,false,true>&
3728  SparseRow<MT,false,true>::operator+=( const Vector<VT,true>& rhs )
3729 {
3730  using blaze::addAssign;
3731 
3732  if( size() != (~rhs).size() )
3733  throw std::invalid_argument( "Vector sizes do not match" );
3734 
3735  addAssign( *this, ~rhs );
3736 
3737  return *this;
3738 }
3740 //*************************************************************************************************
3741 
3742 
3743 //*************************************************************************************************
3754 template< typename MT > // Type of the sparse matrix
3755 template< typename VT > // Type of the right-hand side vector
3756 inline SparseRow<MT,false,true>&
3757  SparseRow<MT,false,true>::operator-=( const Vector<VT,true>& rhs )
3758 {
3759  using blaze::subAssign;
3760 
3761  if( size() != (~rhs).size() )
3762  throw std::invalid_argument( "Vector sizes do not match" );
3763 
3764  subAssign( *this, ~rhs );
3765 
3766  return *this;
3767 }
3769 //*************************************************************************************************
3770 
3771 
3772 //*************************************************************************************************
3784 template< typename MT > // Type of the sparse matrix
3785 template< typename VT > // Type of the right-hand side vector
3786 inline SparseRow<MT,false,true>&
3787  SparseRow<MT,false,true>::operator*=( const Vector<VT,true>& rhs )
3788 {
3789  if( size() != (~rhs).size() )
3790  throw std::invalid_argument( "Vector sizes do not match" );
3791 
3792  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
3793 
3796 
3797  const MultType tmp( *this * (~rhs) );
3798  matrix_.reset( row_ );
3799  assign( tmp );
3800 
3801  return *this;
3802 }
3804 //*************************************************************************************************
3805 
3806 
3807 //*************************************************************************************************
3819 template< typename MT > // Type of the sparse matrix
3820 template< typename Other > // Data type of the right-hand side scalar
3821 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
3822  SparseRow<MT,false,true>::operator*=( Other rhs )
3823 {
3824  for( Iterator element=begin(); element!=end(); ++element )
3825  element->value() *= rhs;
3826  return *this;
3827 }
3829 //*************************************************************************************************
3830 
3831 
3832 //*************************************************************************************************
3845 template< typename MT > // Type of the sparse matrix
3846 template< typename Other > // Data type of the right-hand side scalar
3847 inline typename EnableIf< IsNumeric<Other>, SparseRow<MT,false,true> >::Type&
3848  SparseRow<MT,false,true>::operator/=( Other rhs )
3849 {
3850  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3851 
3852  typedef typename DivTrait<ElementType,Other>::Type DT;
3853  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3854 
3855  // Depending on the two involved data types, an integer division is applied or a
3856  // floating point division is selected.
3857  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3858  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3859  for( Iterator element=begin(); element!=end(); ++element )
3860  element->value() *= tmp;
3861  }
3862  else {
3863  for( Iterator element=begin(); element!=end(); ++element )
3864  element->value() /= rhs;
3865  }
3866 
3867  return *this;
3868 }
3870 //*************************************************************************************************
3871 
3872 
3873 
3874 
3875 //=================================================================================================
3876 //
3877 // UTILITY FUNCTIONS
3878 //
3879 //=================================================================================================
3880 
3881 //*************************************************************************************************
3887 template< typename MT > // Type of the sparse matrix
3888 inline size_t SparseRow<MT,false,true>::size() const
3889 {
3890  return matrix_.columns();
3891 }
3893 //*************************************************************************************************
3894 
3895 
3896 //*************************************************************************************************
3902 template< typename MT > // Type of the sparse matrix
3903 inline size_t SparseRow<MT,false,true>::capacity() const
3904 {
3905  return matrix_.capacity( row_ );
3906 }
3908 //*************************************************************************************************
3909 
3910 
3911 //*************************************************************************************************
3920 template< typename MT > // Type of the sparse matrix
3921 inline size_t SparseRow<MT,false,true>::nonZeros() const
3922 {
3923  return matrix_.nonZeros( row_ );
3924 }
3926 //*************************************************************************************************
3927 
3928 
3929 //*************************************************************************************************
3935 template< typename MT > // Type of the sparse matrix
3936 inline void SparseRow<MT,false,true>::reset()
3937 {
3938  matrix_.reset( row_ );
3939 }
3941 //*************************************************************************************************
3942 
3943 
3944 //*************************************************************************************************
3956 template< typename MT > // Type of the sparse matrix
3957 inline typename SparseRow<MT,false,true>::Iterator
3958  SparseRow<MT,false,true>::set( size_t index, const ElementType& value )
3959 {
3960  return matrix_.set( index, row_, value );
3961 }
3963 //*************************************************************************************************
3964 
3965 
3966 //*************************************************************************************************
3979 template< typename MT > // Type of the sparse matrix
3980 inline typename SparseRow<MT,false,true>::Iterator
3981  SparseRow<MT,false,true>::insert( size_t index, const ElementType& value )
3982 {
3983  return matrix_.insert( index, row_, value );
3984 }
3986 //*************************************************************************************************
3987 
3988 
3989 //*************************************************************************************************
3998 template< typename MT > // Type of the sparse matrix
3999 inline void SparseRow<MT,false,true>::erase( size_t index )
4000 {
4001  matrix_.erase( index, row_ );
4002 }
4004 //*************************************************************************************************
4005 
4006 
4007 //*************************************************************************************************
4016 template< typename MT > // Type of the sparse matrix
4017 inline typename SparseRow<MT,false,true>::Iterator
4019 {
4020  return matrix_.erase( row_, pos );
4021 }
4023 //*************************************************************************************************
4024 
4025 
4026 //*************************************************************************************************
4036 template< typename MT > // Type of the sparse matrix
4037 inline typename SparseRow<MT,false,true>::Iterator
4039 {
4040  return matrix_.erase( row_, first, last );
4041 }
4043 //*************************************************************************************************
4044 
4045 
4046 //*************************************************************************************************
4056 template< typename MT > // Type of the sparse matrix
4057 void SparseRow<MT,false,true>::reserve( size_t n )
4058 {
4059  matrix_.reserve( row_, n );
4060 }
4062 //*************************************************************************************************
4063 
4064 
4065 //*************************************************************************************************
4072 template< typename MT > // Type of the sparse matrix
4073 template< typename Other > // Data type of the scalar value
4074 inline SparseRow<MT,false,true>& SparseRow<MT,false,true>::scale( const Other& scalar )
4075 {
4076  for( Iterator element=begin(); element!=end(); ++element )
4077  element->value() *= scalar;
4078  return *this;
4079 }
4081 //*************************************************************************************************
4082 
4083 
4084 //*************************************************************************************************
4093 template< typename MT > // Type of the sparse matrix
4094 inline size_t SparseRow<MT,false,true>::extendCapacity() const
4095 {
4096  using blaze::max;
4097  using blaze::min;
4098 
4099  size_t nonzeros( 2UL*capacity()+1UL );
4100  nonzeros = max( nonzeros, 7UL );
4101  nonzeros = min( nonzeros, size() );
4102 
4103  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
4104 
4105  return nonzeros;
4106 }
4108 //*************************************************************************************************
4109 
4110 
4111 
4112 
4113 //=================================================================================================
4114 //
4115 // LOOKUP FUNCTIONS
4116 //
4117 //=================================================================================================
4118 
4119 //*************************************************************************************************
4133 template< typename MT > // Type of the sparse matrix
4134 inline typename SparseRow<MT,false,true>::Iterator
4135  SparseRow<MT,false,true>::find( size_t index )
4136 {
4137  return matrix_.find( index, row_ );
4138 }
4140 //*************************************************************************************************
4141 
4142 
4143 //*************************************************************************************************
4157 template< typename MT > // Type of the sparse matrix
4159  SparseRow<MT,false,true>::find( size_t index ) const
4160 {
4161  return matrix_.find( index, row_ );
4162 }
4164 //*************************************************************************************************
4165 
4166 
4167 //*************************************************************************************************
4180 template< typename MT > // Type of the sparse matrix
4181 inline typename SparseRow<MT,false,true>::Iterator
4182  SparseRow<MT,false,true>::lowerBound( size_t index )
4183 {
4184  return matrix_.lowerBound( index, row_ );
4185 }
4187 //*************************************************************************************************
4188 
4189 
4190 //*************************************************************************************************
4203 template< typename MT > // Type of the sparse matrix
4205  SparseRow<MT,false,true>::lowerBound( size_t index ) const
4206 {
4207  return matrix_.lowerBound( index, row_ );
4208 }
4210 //*************************************************************************************************
4211 
4212 
4213 //*************************************************************************************************
4226 template< typename MT > // Type of the sparse matrix
4227 inline typename SparseRow<MT,false,true>::Iterator
4228  SparseRow<MT,false,true>::upperBound( size_t index )
4229 {
4230  return matrix_.upperBound( index, row_ );
4231 }
4233 //*************************************************************************************************
4234 
4235 
4236 //*************************************************************************************************
4249 template< typename MT > // Type of the sparse matrix
4251  SparseRow<MT,false,true>::upperBound( size_t index ) const
4252 {
4253  return matrix_.upperBound( index, row_ );
4254 }
4256 //*************************************************************************************************
4257 
4258 
4259 
4260 
4261 //=================================================================================================
4262 //
4263 // LOW-LEVEL UTILITY FUNCTIONS
4264 //
4265 //=================================================================================================
4266 
4267 //*************************************************************************************************
4292 template< typename MT > // Type of the sparse matrix
4293 inline void SparseRow<MT,false,true>::append( size_t index, const ElementType& value, bool check )
4294 {
4295  matrix_.append( index, row_, value, check );
4296 }
4298 //*************************************************************************************************
4299 
4300 
4301 
4302 
4303 //=================================================================================================
4304 //
4305 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
4306 //
4307 //=================================================================================================
4308 
4309 //*************************************************************************************************
4320 template< typename MT > // Type of the sparse matrix
4321 template< typename Other > // Data type of the foreign expression
4322 inline bool SparseRow<MT,false,true>::canAlias( const Other* alias ) const
4323 {
4324  return matrix_.isAliased( alias );
4325 }
4327 //*************************************************************************************************
4328 
4329 
4330 //*************************************************************************************************
4341 template< typename MT > // Type of the sparse matrix
4342 template< typename Other > // Data type of the foreign expression
4343 inline bool SparseRow<MT,false,true>::isAliased( const Other* alias ) const
4344 {
4345  return matrix_.isAliased( alias );
4346 }
4348 //*************************************************************************************************
4349 
4350 
4351 //*************************************************************************************************
4363 template< typename MT > // Type of the sparse matrix
4364 template< typename VT > // Type of the right-hand side dense vector
4365 inline void SparseRow<MT,false,true>::assign( const DenseVector<VT,true>& rhs )
4366 {
4367  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4368  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4369 
4370  for( size_t i=0UL; i<size(); ++i )
4371  {
4372  if( matrix_.nonZeros( row_ ) == matrix_.capacity( row_ ) )
4373  matrix_.reserve( row_, extendCapacity() );
4374 
4375  matrix_.append( i, row_, (~rhs)[i], true );
4376  }
4377 }
4379 //*************************************************************************************************
4380 
4381 
4382 //*************************************************************************************************
4394 template< typename MT > // Type of the sparse matrix
4395 template< typename VT > // Type of the right-hand side sparse vector
4396 inline void SparseRow<MT,false,true>::assign( const SparseVector<VT,true>& rhs )
4397 {
4398  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4399  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
4400 
4401  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
4402  matrix_.append( element->index(), row_, element->value() );
4403  }
4404 }
4406 //*************************************************************************************************
4407 
4408 
4409 //*************************************************************************************************
4421 template< typename MT > // Type of the sparse matrix
4422 template< typename VT > // Type of the right-hand side dense vector
4423 inline void SparseRow<MT,false,true>::addAssign( const DenseVector<VT,true>& rhs )
4424 {
4425  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4426 
4430 
4431  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4432 
4433  const AddType tmp( serial( *this + (~rhs) ) );
4434  matrix_.reset( row_ );
4435  assign( tmp );
4436 }
4438 //*************************************************************************************************
4439 
4440 
4441 //*************************************************************************************************
4453 template< typename MT > // Type of the sparse matrix
4454 template< typename VT > // Type of the right-hand side sparse vector
4455 inline void SparseRow<MT,false,true>::addAssign( const SparseVector<VT,true>& rhs )
4456 {
4457  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4458 
4462 
4463  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4464 
4465  const AddType tmp( serial( *this + (~rhs) ) );
4466  matrix_.reset ( row_ );
4467  matrix_.reserve( row_, tmp.nonZeros() );
4468  assign( tmp );
4469 }
4471 //*************************************************************************************************
4472 
4473 
4474 //*************************************************************************************************
4486 template< typename MT > // Type of the sparse matrix
4487 template< typename VT > // Type of the right-hand side dense vector
4488 inline void SparseRow<MT,false,true>::subAssign( const DenseVector<VT,true>& rhs )
4489 {
4490  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4491 
4495 
4496  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4497 
4498  const SubType tmp( serial( *this - (~rhs) ) );
4499  matrix_.reset ( row_ );
4500  assign( tmp );
4501 }
4503 //*************************************************************************************************
4504 
4505 
4506 //*************************************************************************************************
4518 template< typename MT > // Type of the sparse matrix
4519 template< typename VT > // Type of the right-hand side sparse vector
4520 inline void SparseRow<MT,false,true>::subAssign( const SparseVector<VT,true>& rhs )
4521 {
4522  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4523 
4527 
4528  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
4529 
4530  const SubType tmp( serial( *this - (~rhs) ) );
4531  matrix_.reset ( row_ );
4532  matrix_.reserve( row_, tmp.nonZeros() );
4533  assign( tmp );
4534 }
4536 //*************************************************************************************************
4537 
4538 
4539 
4540 
4541 
4542 
4543 
4544 
4545 //=================================================================================================
4546 //
4547 // SPARSEROW OPERATORS
4548 //
4549 //=================================================================================================
4550 
4551 //*************************************************************************************************
4554 template< typename MT, bool SO, bool SF >
4555 inline void reset( SparseRow<MT,SO,SF>& row );
4556 
4557 template< typename MT, bool SO, bool SF >
4558 inline void clear( SparseRow<MT,SO,SF>& row );
4559 
4560 template< typename MT, bool SO, bool SF >
4561 inline bool isDefault( const SparseRow<MT,SO,SF>& row );
4562 
4563 template< typename MT, bool SO, bool SF >
4564 inline bool isSame( const SparseRow<MT,SO,SF>& a, const SparseRow<MT,SO,SF>& b );
4566 //*************************************************************************************************
4567 
4568 
4569 //*************************************************************************************************
4576 template< typename MT // Type of the sparse matrix
4577  , bool SO // Storage order
4578  , bool SF > // Symmetry flag
4579 inline void reset( SparseRow<MT,SO,SF>& row )
4580 {
4581  row.reset();
4582 }
4583 //*************************************************************************************************
4584 
4585 
4586 //*************************************************************************************************
4595 template< typename MT // Type of the sparse matrix
4596  , bool SO // Storage order
4597  , bool SF > // Symmetry flag
4598 inline void clear( SparseRow<MT,SO,SF>& row )
4599 {
4600  row.reset();
4601 }
4602 //*************************************************************************************************
4603 
4604 
4605 //*************************************************************************************************
4623 template< typename MT // Type of the sparse matrix
4624  , bool SO // Storage order
4625  , bool SF > // Symmetry flag
4626 inline bool isDefault( const SparseRow<MT,SO,SF>& row )
4627 {
4629 
4630  const ConstIterator end( row.end() );
4631  for( ConstIterator element=row.begin(); element!=end; ++element )
4632  if( !isDefault( element->value() ) ) return false;
4633  return true;
4634 }
4635 //*************************************************************************************************
4636 
4637 
4638 //*************************************************************************************************
4650 template< typename MT // Type of the sparse matrix
4651  , bool SO // Storage order
4652  , bool SF > // Symmetry flag
4653 inline bool isSame( const SparseRow<MT,SO,SF>& a, const SparseRow<MT,SO,SF>& b )
4654 {
4655  return ( isSame( a.matrix_, b.matrix_ ) && ( a.row_ == b.row_ ) );
4656 }
4657 //*************************************************************************************************
4658 
4659 
4660 
4661 
4662 //=================================================================================================
4663 //
4664 // SUBVECTORTRAIT SPECIALIZATIONS
4665 //
4666 //=================================================================================================
4667 
4668 //*************************************************************************************************
4670 template< typename MT, bool SO, bool SF >
4671 struct SubvectorTrait< SparseRow<MT,SO,SF> >
4672 {
4673  typedef typename SubvectorTrait< typename SparseRow<MT,SO,SF>::ResultType >::Type Type;
4674 };
4676 //*************************************************************************************************
4677 
4678 } // namespace blaze
4679 
4680 #endif
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:994
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.
MT::ConstReference ConstReference
Reference to a constant row value.
Definition: SparseRow.h:383
#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.
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:4838
Header file for the subtraction trait.
Header file for the SparseVector base class.
SparseRow & operator=(const SparseRow &rhs)
Copy assignment operator for SparseRow.
Definition: SparseRow.h:726
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:258
Header file for the row trait.
SparseRow< MT, SO, SF > This
Type of this SparseRow instance.
Definition: SparseRow.h:375
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:258
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse row.
Definition: SparseRow.h:1409
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:205
Header file for the row base class.
#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:1011
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:946
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2478
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:348
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:103
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
bool canAlias(const Other *alias) const
Returns whether the sparse row can alias with the given address alias.
Definition: SparseRow.h:1438
size_t nonZeros() const
Returns the number of non-zero elements in the row.
Definition: SparseRow.h:1044
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseRow.h:379
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:695
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:386
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:95
#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
#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
size_t extendCapacity() const
Calculating a new sparse row capacity.
Definition: SparseRow.h:1216
RowTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseRow.h:376
void subAssign(const DenseVector< VT, true > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseRow.h:1604
Constraint on the data type.
const size_t row_
The index of the row in the matrix.
Definition: SparseRow.h:509
Base template for the RowTrait class.
Definition: RowTrait.h:115
SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant row value.
Definition: SparseRow.h:386
ConstIterator cbegin() const
Returns an iterator to the first element of the row.
Definition: SparseRow.h:647
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsSymmetric type trait.
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
void erase(size_t index)
Erasing an element from the sparse row.
Definition: SparseRow.h:1122
#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: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2482
Header file for the Or class template.
void reset()
Reset to the default initial values.
Definition: SparseRow.h:1059
void reserve(size_t n)
Setting the minimum capacity of the sparse row.
Definition: SparseRow.h:1179
size_t capacity() const
Returns the maximum capacity of the sparse row.
Definition: SparseRow.h:1026
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:947
BLAZE_ALWAYS_INLINE void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:635
BLAZE_ALWAYS_INLINE void clear(const NonNumericProxy< MT > &proxy)
Clearing the represented element.
Definition: NonNumericProxy.h:854
Header file for the subvector trait.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
Header file for the SparseElement base class.
Constraint on the data type.
void addAssign(const DenseVector< VT, true > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseRow.h:1539
Operand matrix_
The sparse matrix containing the row.
Definition: SparseRow.h:508
Constraints on the storage order of matrix types.
Constraint on the data type.
Reference operator[](size_t index)
Subscript operator for the direct access to the row elements.
Definition: SparseRow.h:577
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:195
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
MT::ElementType ElementType
Type of the row elements.
Definition: SparseRow.h:378
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseRow.h:389
SparseRow(MT &matrix, size_t index)
The constructor for SparseRow.
Definition: SparseRow.h:550
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2476
Constraint on the data type.
Header file for the SelectType class template.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2480
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse row.
Definition: SparseRow.h:1104
Header file for the EnableIf class template.
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse row.
Definition: SparseRow.h:1081
Header file for the serial shim.
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:103
#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: StorageOrder.h:81
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2477
Header file for the IsConst type trait.
Iterator end()
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:664
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:142
Base template for the MultTrait class.
Definition: MultTrait.h:142
Header file for the addition trait.
BLAZE_ALWAYS_INLINE void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:742
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.
SelectType< useConst, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseRow.h:392
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
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.
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2481
Header file for the isDefault shim.
const SparseRow & CompositeType
Data type for composite expression templates.
Definition: SparseRow.h:380
BLAZE_ALWAYS_INLINE bool isDefault(const NonNumericProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: NonNumericProxy.h:874
Constraint on the data type.
BLAZE_ALWAYS_INLINE void reset(const NonNumericProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: NonNumericProxy.h:833
#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
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:142
Iterator find(size_t index)
Searches for a specific row element.
Definition: SparseRow.h:1256
bool isAliased(const Other *alias) const
Returns whether the sparse row is aliased with the given address alias.
Definition: SparseRow.h:1459
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseRow.h:1301
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseRow.h:377
#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:151
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:256
SelectType< IsExpression< MT >::value, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseRow.h:359
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:108
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:2473
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
#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: TransposeFlag.h:81
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2479
Base template for the SubTrait class.
Definition: SubTrait.h:142
ConstIterator cend() const
Returns an iterator just past the last element of the row.
Definition: SparseRow.h:698
Iterator begin()
Returns an iterator to the first element of the row.
Definition: SparseRow.h:613
#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:1345
#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
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
BLAZE_ALWAYS_INLINE void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:849
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:1481