SparseColumn.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_SPARSECOLUMN_H_
36 #define _BLAZE_MATH_VIEWS_SPARSECOLUMN_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
57 #include <blaze/math/Functions.h>
59 #include <blaze/math/shims/Reset.h>
82 #include <blaze/util/Assert.h>
85 #include <blaze/util/DisableIf.h>
86 #include <blaze/util/EnableIf.h>
87 #include <blaze/util/Exception.h>
89 #include <blaze/util/mpl/And.h>
90 #include <blaze/util/mpl/If.h>
91 #include <blaze/util/mpl/Or.h>
92 #include <blaze/util/Null.h>
93 #include <blaze/util/Types.h>
99 #include <blaze/util/Unused.h>
101 
102 
103 namespace blaze {
104 
105 //=================================================================================================
106 //
107 // CLASS DEFINITION
108 //
109 //=================================================================================================
110 
111 //*************************************************************************************************
369 template< typename MT // Type of the sparse matrix
370  , bool SO = IsColumnMajorMatrix<MT>::value // Storage order
371  , bool SF = IsSymmetric<MT>::value > // Symmetry flag
372 class SparseColumn : public SparseVector< SparseColumn<MT,SO,SF>, false >
373  , private Column
374 {
375  private:
376  //**Type definitions****************************************************************************
378  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
379  //**********************************************************************************************
380 
381  public:
382  //**Type definitions****************************************************************************
386  typedef typename MT::ElementType ElementType;
387  typedef typename MT::ReturnType ReturnType;
388  typedef const SparseColumn& CompositeType;
389 
392 
394  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
395 
398 
400  typedef typename If< IsConst<MT>, ConstIterator, typename MT::Iterator >::Type Iterator;
401  //**********************************************************************************************
402 
403  //**Compilation flags***************************************************************************
405  enum { smpAssignable = 0 };
406  //**********************************************************************************************
407 
408  //**Constructors********************************************************************************
411  explicit inline SparseColumn( MT& matrix, size_t index );
412  // No explicitly declared copy constructor.
414  //**********************************************************************************************
415 
416  //**Destructor**********************************************************************************
417  // No explicitly declared destructor.
418  //**********************************************************************************************
419 
420  //**Data access functions***********************************************************************
423  inline Reference operator[]( size_t index );
424  inline ConstReference operator[]( size_t index ) const;
425  inline Reference at( size_t index );
426  inline ConstReference at( size_t index ) const;
427  inline Iterator begin ();
428  inline ConstIterator begin () const;
429  inline ConstIterator cbegin() const;
430  inline Iterator end ();
431  inline ConstIterator end () const;
432  inline ConstIterator cend () const;
434  //**********************************************************************************************
435 
436  //**Assignment operators************************************************************************
439  inline SparseColumn& operator=( const SparseColumn& rhs );
440 
441  template< typename VT > inline SparseColumn& operator= ( const DenseVector<VT,false>& rhs );
442  template< typename VT > inline SparseColumn& operator= ( const SparseVector<VT,false>& rhs );
443  template< typename VT > inline SparseColumn& operator+=( const DenseVector<VT,false>& rhs );
444  template< typename VT > inline SparseColumn& operator+=( const SparseVector<VT,false>& rhs );
445  template< typename VT > inline SparseColumn& operator-=( const DenseVector<VT,false>& rhs );
446  template< typename VT > inline SparseColumn& operator-=( const SparseVector<VT,false>& rhs );
447  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
448 
449  template< typename Other >
450  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
451  operator*=( Other rhs );
452 
453  template< typename Other >
454  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
455  operator/=( Other rhs );
457  //**********************************************************************************************
458 
459  //**Utility functions***************************************************************************
462  inline size_t size() const;
463  inline size_t capacity() const;
464  inline size_t nonZeros() const;
465  inline void reset();
466  inline Iterator set ( size_t index, const ElementType& value );
467  inline Iterator insert ( size_t index, const ElementType& value );
468  inline void erase ( size_t index );
469  inline Iterator erase ( Iterator pos );
470  inline Iterator erase ( Iterator first, Iterator last );
471  inline void reserve( size_t n );
472  template< typename Other > inline SparseColumn& scale ( const Other& scalar );
474  //**********************************************************************************************
475 
476  //**Lookup functions****************************************************************************
479  inline Iterator find ( size_t index );
480  inline ConstIterator find ( size_t index ) const;
481  inline Iterator lowerBound( size_t index );
482  inline ConstIterator lowerBound( size_t index ) const;
483  inline Iterator upperBound( size_t index );
484  inline ConstIterator upperBound( size_t index ) const;
486  //**********************************************************************************************
487 
488  //**Low-level utility functions*****************************************************************
491  inline void append( size_t index, const ElementType& value, bool check=false );
493  //**********************************************************************************************
494 
495  //**Expression template evaluation functions****************************************************
498  template< typename Other > inline bool canAlias ( const Other* alias ) const;
499  template< typename Other > inline bool isAliased( const Other* alias ) const;
500 
501  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
502  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
503  template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
504  template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
505  template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
506  template< typename VT > inline void subAssign( const SparseVector<VT,false>& rhs );
508  //**********************************************************************************************
509 
510  private:
511  //**Utility functions***************************************************************************
514  inline size_t extendCapacity() const;
516  //**********************************************************************************************
517 
518  //**Member variables****************************************************************************
521  Operand matrix_;
522  const size_t col_;
523 
524  //**********************************************************************************************
525 
526  //**Friend declarations*************************************************************************
528  template< typename MT2, bool SO2, bool SF2 >
529  friend bool isIntact( const SparseColumn<MT2,SO2,SF2>& column );
530 
531  template< typename MT2, bool SO2, bool SF2 >
532  friend bool isSame( const SparseColumn<MT2,SO2,SF2>& a, const SparseColumn<MT2,SO2,SF2>& b );
533 
534  template< typename MT2, bool SO2, bool SF2, typename VT >
535  friend bool tryAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
536 
537  template< typename MT2, bool SO2, bool SF2, typename VT >
538  friend bool tryAddAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
539 
540  template< typename MT2, bool SO2, bool SF2, typename VT >
541  friend bool trySubAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
542 
543  template< typename MT2, bool SO2, bool SF2, typename VT >
544  friend bool tryMultAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
545 
546  template< typename MT2, bool SO2, bool SF2 >
547  friend typename DerestrictTrait< SparseColumn<MT2,SO2,SF2> >::Type
548  derestrict( SparseColumn<MT2,SO2,SF2>& dm );
550  //**********************************************************************************************
551 
552  //**Compile time checks*************************************************************************
561  //**********************************************************************************************
562 };
563 //*************************************************************************************************
564 
565 
566 
567 
568 //=================================================================================================
569 //
570 // CONSTRUCTOR
571 //
572 //=================================================================================================
573 
574 //*************************************************************************************************
581 template< typename MT // Type of the sparse matrix
582  , bool SO // Storage order
583  , bool SF > // Symmetry flag
584 inline SparseColumn<MT,SO,SF>::SparseColumn( MT& matrix, size_t index )
585  : matrix_( matrix ) // The sparse matrix containing the column
586  , col_ ( index ) // The index of the column in the matrix
587 {
588  if( matrix_.columns() <= index ) {
589  BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
590  }
591 }
592 //*************************************************************************************************
593 
594 
595 
596 
597 //=================================================================================================
598 //
599 // DATA ACCESS FUNCTIONS
600 //
601 //=================================================================================================
602 
603 //*************************************************************************************************
612 template< typename MT // Type of the sparse matrix
613  , bool SO // Storage order
614  , bool SF > // Symmetry flag
615 inline typename SparseColumn<MT,SO,SF>::Reference
617 {
618  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
619  return matrix_(index,col_);
620 }
621 //*************************************************************************************************
622 
623 
624 //*************************************************************************************************
633 template< typename MT // Type of the sparse matrix
634  , bool SO // Storage order
635  , bool SF > // Symmetry flag
638 {
639  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
640  return const_cast<const MT&>( matrix_ )(index,col_);
641 }
642 //*************************************************************************************************
643 
644 
645 //*************************************************************************************************
655 template< typename MT // Type of the sparse matrix
656  , bool SO // Storage order
657  , bool SF > // Symmetry flag
658 inline typename SparseColumn<MT,SO,SF>::Reference
660 {
661  if( index >= size() ) {
662  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
663  }
664  return (*this)[index];
665 }
666 //*************************************************************************************************
667 
668 
669 //*************************************************************************************************
679 template< typename MT // Type of the sparse matrix
680  , bool SO // Storage order
681  , bool SF > // Symmetry flag
683  SparseColumn<MT,SO,SF>::at( size_t index ) const
684 {
685  if( index >= size() ) {
686  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
687  }
688  return (*this)[index];
689 }
690 //*************************************************************************************************
691 
692 
693 //*************************************************************************************************
700 template< typename MT // Type of the sparse matrix
701  , bool SO // Storage order
702  , bool SF > // Symmetry flag
704 {
705  return matrix_.begin( col_ );
706 }
707 //*************************************************************************************************
708 
709 
710 //*************************************************************************************************
717 template< typename MT // Type of the sparse matrix
718  , bool SO // Storage order
719  , bool SF > // Symmetry flag
721 {
722  return matrix_.cbegin( col_ );
723 }
724 //*************************************************************************************************
725 
726 
727 //*************************************************************************************************
734 template< typename MT // Type of the sparse matrix
735  , bool SO // Storage order
736  , bool SF > // Symmetry flag
738 {
739  return matrix_.cbegin( col_ );
740 }
741 //*************************************************************************************************
742 
743 
744 //*************************************************************************************************
751 template< typename MT // Type of the sparse matrix
752  , bool SO // Storage order
753  , bool SF > // Symmetry flag
755 {
756  return matrix_.end( col_ );
757 }
758 //*************************************************************************************************
759 
760 
761 //*************************************************************************************************
768 template< typename MT // Type of the sparse matrix
769  , bool SO // Storage order
770  , bool SF > // Symmetry flag
772 {
773  return matrix_.cend( col_ );
774 }
775 //*************************************************************************************************
776 
777 
778 //*************************************************************************************************
785 template< typename MT // Type of the sparse matrix
786  , bool SO // Storage order
787  , bool SF > // Symmetry flag
789 {
790  return matrix_.cend( col_ );
791 }
792 //*************************************************************************************************
793 
794 
795 
796 
797 //=================================================================================================
798 //
799 // ASSIGNMENT OPERATORS
800 //
801 //=================================================================================================
802 
803 //*************************************************************************************************
816 template< typename MT // Type of the sparse matrix
817  , bool SO // Storage order
818  , bool SF > // Symmetry flag
820 {
821  using blaze::assign;
822 
826 
827  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
828  return *this;
829 
830  if( size() != rhs.size() ) {
831  BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
832  }
833 
834  if( !tryAssign( matrix_, rhs, 0UL, col_ ) ) {
835  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
836  }
837 
838  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
839 
840  if( rhs.canAlias( &matrix_ ) ) {
841  const ResultType tmp( rhs );
842  left.reset();
843  left.reserve( tmp.nonZeros() );
844  assign( left, tmp );
845  }
846  else {
847  left.reset();
848  left.reserve( rhs.nonZeros() );
849  assign( left, rhs );
850  }
851 
852  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
853 
854  return *this;
855 }
856 //*************************************************************************************************
857 
858 
859 //*************************************************************************************************
872 template< typename MT // Type of the sparse matrix
873  , bool SO // Storage order
874  , bool SF > // Symmetry flag
875 template< typename VT > // Type of the right-hand side dense vector
877 {
878  using blaze::assign;
879 
883 
884  if( size() != (~rhs).size() ) {
885  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
886  }
887 
888  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
889  Right right( ~rhs );
890 
891  if( !tryAssign( matrix_, right, 0UL, col_ ) ) {
892  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
893  }
894 
895  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
896 
897  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
898  const typename VT::ResultType tmp( right );
899  left.reset();
900  assign( left, tmp );
901  }
902  else {
903  left.reset();
904  assign( left, right );
905  }
906 
907  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
908 
909  return *this;
910 }
911 //*************************************************************************************************
912 
913 
914 //*************************************************************************************************
927 template< typename MT // Type of the sparse matrix
928  , bool SO // Storage order
929  , bool SF > // Symmetry flag
930 template< typename VT > // Type of the right-hand side sparse vector
932 {
933  using blaze::assign;
934 
938 
939  if( size() != (~rhs).size() ) {
940  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
941  }
942 
943  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
944  Right right( ~rhs );
945 
946  if( !tryAssign( matrix_, right, 0UL, col_ ) ) {
947  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
948  }
949 
950  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
951 
952  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
953  const typename VT::ResultType tmp( right );
954  left.reset();
955  left.reserve( tmp.nonZeros() );
956  assign( left, tmp );
957  }
958  else {
959  left.reset();
960  left.reserve( right.nonZeros() );
961  assign( left, right );
962  }
963 
964  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
965 
966  return *this;
967 }
968 //*************************************************************************************************
969 
970 
971 //*************************************************************************************************
984 template< typename MT // Type of the sparse matrix
985  , bool SO // Storage order
986  , bool SF > // Symmetry flag
987 template< typename VT > // Type of the right-hand side dense vector
989 {
990  using blaze::assign;
991 
998 
1000 
1004 
1005  if( size() != (~rhs).size() ) {
1006  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1007  }
1008 
1009  const AddType tmp( *this + (~rhs) );
1010 
1011  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
1012  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1013  }
1014 
1015  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1016 
1017  left.reset();
1018  assign( left, tmp );
1019 
1020  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1021 
1022  return *this;
1023 }
1024 //*************************************************************************************************
1025 
1026 
1027 //*************************************************************************************************
1040 template< typename MT // Type of the sparse matrix
1041  , bool SO // Storage order
1042  , bool SF > // Symmetry flag
1043 template< typename VT > // Type of the right-hand side sparse vector
1045 {
1046  using blaze::assign;
1047 
1054 
1055  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1056 
1060 
1061  if( size() != (~rhs).size() ) {
1062  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1063  }
1064 
1065  const AddType tmp( *this + (~rhs) );
1066 
1067  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
1068  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1069  }
1070 
1071  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1072 
1073  left.reset();
1074  left.reserve( tmp.nonZeros() );
1075  assign( left, tmp );
1076 
1077  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1078 
1079  return *this;
1080 }
1081 //*************************************************************************************************
1082 
1083 
1084 //*************************************************************************************************
1098 template< typename MT // Type of the sparse matrix
1099  , bool SO // Storage order
1100  , bool SF > // Symmetry flag
1101 template< typename VT > // Type of the right-hand side dense vector
1103 {
1104  using blaze::assign;
1105 
1112 
1113  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1114 
1118 
1119  if( size() != (~rhs).size() ) {
1120  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1121  }
1122 
1123  const SubType tmp( *this - (~rhs) );
1124 
1125  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
1126  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1127  }
1128 
1129  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1130 
1131  left.reset();
1132  assign( left, tmp );
1133 
1134  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1135 
1136  return *this;
1137 }
1138 //*************************************************************************************************
1139 
1140 
1141 //*************************************************************************************************
1155 template< typename MT // Type of the sparse matrix
1156  , bool SO // Storage order
1157  , bool SF > // Symmetry flag
1158 template< typename VT > // Type of the right-hand side sparse vector
1160 {
1161  using blaze::assign;
1162 
1169 
1170  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1171 
1175 
1176  if( size() != (~rhs).size() ) {
1177  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1178  }
1179 
1180  const SubType tmp( *this - (~rhs) );
1181 
1182  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
1183  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1184  }
1185 
1186  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1187 
1188  left.reset();
1189  left.reserve( tmp.nonZeros() );
1190  assign( left, tmp );
1191 
1192  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1193 
1194  return *this;
1195 }
1196 //*************************************************************************************************
1197 
1198 
1199 //*************************************************************************************************
1211 template< typename MT // Type of the sparse matrix
1212  , bool SO // Storage order
1213  , bool SF > // Symmetry flag
1214 template< typename VT > // Type of the right-hand side vector
1216 {
1217  using blaze::assign;
1218 
1224 
1225  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
1226 
1229 
1230  if( size() != (~rhs).size() ) {
1231  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
1232  }
1233 
1234  const MultType tmp( *this * (~rhs) );
1235 
1236  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
1237  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
1238  }
1239 
1240  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
1241 
1242  left.reset();
1243  assign( left, tmp );
1244 
1245  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
1246 
1247  return *this;
1248 }
1249 //*************************************************************************************************
1250 
1251 
1252 //*************************************************************************************************
1266 template< typename MT // Type of the sparse matrix
1267  , bool SO // Storage order
1268  , bool SF > // Symmetry flag
1269 template< typename Other > // Data type of the right-hand side scalar
1270 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO,SF> >::Type&
1272 {
1274 
1275  for( Iterator element=begin(); element!=end(); ++element )
1276  element->value() *= rhs;
1277  return *this;
1278 }
1279 //*************************************************************************************************
1280 
1281 
1282 //*************************************************************************************************
1299 template< typename MT // Type of the sparse matrix
1300  , bool SO // Storage order
1301  , bool SF > // Symmetry flag
1302 template< typename Other > // Data type of the right-hand side scalar
1303 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO,SF> >::Type&
1305 {
1307 
1308  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
1309 
1310  typedef typename DivTrait<ElementType,Other>::Type DT;
1311  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
1312 
1313  // Depending on the two involved data types, an integer division is applied or a
1314  // floating point division is selected.
1316  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
1317  for( Iterator element=begin(); element!=end(); ++element )
1318  element->value() *= tmp;
1319  }
1320  else {
1321  for( Iterator element=begin(); element!=end(); ++element )
1322  element->value() /= rhs;
1323  }
1324 
1325  return *this;
1326 }
1327 //*************************************************************************************************
1328 
1329 
1330 
1331 
1332 //=================================================================================================
1333 //
1334 // UTILITY FUNCTIONS
1335 //
1336 //=================================================================================================
1337 
1338 //*************************************************************************************************
1343 template< typename MT // Type of the sparse matrix
1344  , bool SO // Storage order
1345  , bool SF > // Symmetry flag
1346 inline size_t SparseColumn<MT,SO,SF>::size() const
1347 {
1348  return matrix_.rows();
1349 }
1350 //*************************************************************************************************
1351 
1352 
1353 //*************************************************************************************************
1358 template< typename MT // Type of the sparse matrix
1359  , bool SO // Storage order
1360  , bool SF > // Symmetry flag
1362 {
1363  return matrix_.capacity( col_ );
1364 }
1365 //*************************************************************************************************
1366 
1367 
1368 //*************************************************************************************************
1376 template< typename MT // Type of the sparse matrix
1377  , bool SO // Storage order
1378  , bool SF > // Symmetry flag
1380 {
1381  return matrix_.nonZeros( col_ );
1382 }
1383 //*************************************************************************************************
1384 
1385 
1386 //*************************************************************************************************
1391 template< typename MT // Type of the sparse matrix
1392  , bool SO // Storage order
1393  , bool SF > // Symmetry flag
1395 {
1396  matrix_.reset( col_ );
1397 }
1398 //*************************************************************************************************
1399 
1400 
1401 //*************************************************************************************************
1412 template< typename MT // Type of the sparse matrix
1413  , bool SO // Storage order
1414  , bool SF > // Symmetry flag
1415 inline typename SparseColumn<MT,SO,SF>::Iterator
1416  SparseColumn<MT,SO,SF>::set( size_t index, const ElementType& value )
1417 {
1418  return matrix_.set( index, col_, value );
1419 }
1420 //*************************************************************************************************
1421 
1422 
1423 //*************************************************************************************************
1435 template< typename MT // Type of the sparse matrix
1436  , bool SO // Storage order
1437  , bool SF > // Symmetry flag
1438 inline typename SparseColumn<MT,SO,SF>::Iterator
1439  SparseColumn<MT,SO,SF>::insert( size_t index, const ElementType& value )
1440 {
1441  return matrix_.insert( index, col_, value );
1442 }
1443 //*************************************************************************************************
1444 
1445 
1446 //*************************************************************************************************
1454 template< typename MT // Type of the sparse matrix
1455  , bool SO // Storage order
1456  , bool SF > // Symmetry flag
1457 inline void SparseColumn<MT,SO,SF>::erase( size_t index )
1458 {
1459  matrix_.erase( index, col_ );
1460 }
1461 //*************************************************************************************************
1462 
1463 
1464 //*************************************************************************************************
1472 template< typename MT // Type of the sparse matrix
1473  , bool SO // Storage order
1474  , bool SF > // Symmetry flag
1476 {
1477  return matrix_.erase( col_, pos );
1478 }
1479 //*************************************************************************************************
1480 
1481 
1482 //*************************************************************************************************
1491 template< typename MT // Type of the sparse matrix
1492  , bool SO // Storage order
1493  , bool SF > // Symmetry flag
1494 inline typename SparseColumn<MT,SO,SF>::Iterator
1496 {
1497  return matrix_.erase( col_, first, last );
1498 }
1499 //*************************************************************************************************
1500 
1501 
1502 //*************************************************************************************************
1511 template< typename MT // Type of the sparse matrix
1512  , bool SO // Storage order
1513  , bool SF > // Symmetry flag
1515 {
1516  matrix_.reserve( col_, n );
1517 }
1518 //*************************************************************************************************
1519 
1520 
1521 //*************************************************************************************************
1531 template< typename MT // Type of the sparse matrix
1532  , bool SO // Storage order
1533  , bool SF > // Symmetry flag
1534 template< typename Other > // Data type of the scalar value
1536 {
1538 
1539  for( Iterator element=begin(); element!=end(); ++element )
1540  element->value() *= scalar;
1541  return *this;
1542 }
1543 //*************************************************************************************************
1544 
1545 
1546 //*************************************************************************************************
1554 template< typename MT // Type of the sparse matrix
1555  , bool SO // Storage order
1556  , bool SF > // Symmetry flag
1558 {
1559  using blaze::max;
1560  using blaze::min;
1561 
1562  size_t nonzeros( 2UL*capacity()+1UL );
1563  nonzeros = max( nonzeros, 7UL );
1564  nonzeros = min( nonzeros, size() );
1565 
1566  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1567 
1568  return nonzeros;
1569 }
1570 //*************************************************************************************************
1571 
1572 
1573 
1574 
1575 //=================================================================================================
1576 //
1577 // LOOKUP FUNCTIONS
1578 //
1579 //=================================================================================================
1580 
1581 //*************************************************************************************************
1594 template< typename MT // Type of the sparse matrix
1595  , bool SO // Storage order
1596  , bool SF > // Symmetry flag
1598 {
1599  return matrix_.find( index, col_ );
1600 }
1601 //*************************************************************************************************
1602 
1603 
1604 //*************************************************************************************************
1617 template< typename MT // Type of the sparse matrix
1618  , bool SO // Storage order
1619  , bool SF > // Symmetry flag
1621  SparseColumn<MT,SO,SF>::find( size_t index ) const
1622 {
1623  return matrix_.find( index, col_ );
1624 }
1625 //*************************************************************************************************
1626 
1627 
1628 //*************************************************************************************************
1640 template< typename MT // Type of the sparse matrix
1641  , bool SO // Storage order
1642  , bool SF > // Symmetry flag
1644 {
1645  return matrix_.lowerBound( index, col_ );
1646 }
1647 //*************************************************************************************************
1648 
1649 
1650 //*************************************************************************************************
1662 template< typename MT // Type of the sparse matrix
1663  , bool SO // Storage order
1664  , bool SF > // Symmetry flag
1667 {
1668  return matrix_.lowerBound( index, col_ );
1669 }
1670 //*************************************************************************************************
1671 
1672 
1673 //*************************************************************************************************
1685 template< typename MT // Type of the sparse matrix
1686  , bool SO // Storage order
1687  , bool SF > // Symmetry flag
1689 {
1690  return matrix_.upperBound( index, col_ );
1691 }
1692 //*************************************************************************************************
1693 
1694 
1695 //*************************************************************************************************
1707 template< typename MT // Type of the sparse matrix
1708  , bool SO // Storage order
1709  , bool SF > // Symmetry flag
1712 {
1713  return matrix_.upperBound( index, col_ );
1714 }
1715 //*************************************************************************************************
1716 
1717 
1718 
1719 
1720 //=================================================================================================
1721 //
1722 // LOW-LEVEL UTILITY FUNCTIONS
1723 //
1724 //=================================================================================================
1725 
1726 //*************************************************************************************************
1750 template< typename MT // Type of the sparse matrix
1751  , bool SO // Storage order
1752  , bool SF > // Symmetry flag
1753 inline void SparseColumn<MT,SO,SF>::append( size_t index, const ElementType& value, bool check )
1754 {
1755  matrix_.append( index, col_, value, check );
1756 }
1757 //*************************************************************************************************
1758 
1759 
1760 
1761 
1762 //=================================================================================================
1763 //
1764 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1765 //
1766 //=================================================================================================
1767 
1768 //*************************************************************************************************
1778 template< typename MT // Type of the sparse matrix
1779  , bool SO // Storage order
1780  , bool SF > // Symmetry flag
1781 template< typename Other > // Data type of the foreign expression
1782 inline bool SparseColumn<MT,SO,SF>::canAlias( const Other* alias ) const
1783 {
1784  return matrix_.isAliased( alias );
1785 }
1786 //*************************************************************************************************
1787 
1788 
1789 //*************************************************************************************************
1799 template< typename MT // Type of the sparse matrix
1800  , bool SO // Storage order
1801  , bool SF > // Symmetry flag
1802 template< typename Other > // Data type of the foreign expression
1803 inline bool SparseColumn<MT,SO,SF>::isAliased( const Other* alias ) const
1804 {
1805  return matrix_.isAliased( alias );
1806 }
1807 //*************************************************************************************************
1808 
1809 
1810 //*************************************************************************************************
1821 template< typename MT // Type of the sparse matrix
1822  , bool SO // Storage order
1823  , bool SF > // Symmetry flag
1824 template< typename VT > // Type of the right-hand side dense vector
1826 {
1827  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1828  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1829 
1830  for( size_t i=0UL; i<size(); ++i )
1831  {
1832  if( matrix_.nonZeros( col_ ) == matrix_.capacity( col_ ) )
1833  matrix_.reserve( col_, extendCapacity() );
1834 
1835  matrix_.append( i, col_, (~rhs)[i], true );
1836  }
1837 }
1838 //*************************************************************************************************
1839 
1840 
1841 //*************************************************************************************************
1852 template< typename MT // Type of the sparse matrix
1853  , bool SO // Storage order
1854  , bool SF > // Symmetry flag
1855 template< typename VT > // Type of the right-hand side sparse vector
1857 {
1858  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1859  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1860 
1861  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1862  matrix_.append( element->index(), col_, element->value(), true );
1863  }
1864 }
1865 //*************************************************************************************************
1866 
1867 
1868 //*************************************************************************************************
1879 template< typename MT // Type of the sparse matrix
1880  , bool SO // Storage order
1881  , bool SF > // Symmetry flag
1882 template< typename VT > // Type of the right-hand side dense vector
1884 {
1885  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1886 
1890 
1891  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1892 
1893  const AddType tmp( serial( *this + (~rhs) ) );
1894  matrix_.reset( col_ );
1895  assign( tmp );
1896 }
1897 //*************************************************************************************************
1898 
1899 
1900 //*************************************************************************************************
1911 template< typename MT // Type of the sparse matrix
1912  , bool SO // Storage order
1913  , bool SF > // Symmetry flag
1914 template< typename VT > // Type of the right-hand side sparse vector
1916 {
1917  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1918 
1922 
1923  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1924 
1925  const AddType tmp( serial( *this + (~rhs) ) );
1926  matrix_.reset( col_ );
1927  matrix_.reserve( col_, tmp.nonZeros() );
1928  assign( tmp );
1929 }
1930 //*************************************************************************************************
1931 
1932 
1933 //*************************************************************************************************
1944 template< typename MT // Type of the sparse matrix
1945  , bool SO // Storage order
1946  , bool SF > // Symmetry flag
1947 template< typename VT > // Type of the right-hand side dense vector
1949 {
1950  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1951 
1955 
1956  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1957 
1958  const SubType tmp( serial( *this - (~rhs) ) );
1959  matrix_.reset( col_ );
1960  assign( tmp );
1961 }
1962 //*************************************************************************************************
1963 
1964 
1965 //*************************************************************************************************
1976 template< typename MT // Type of the sparse matrix
1977  , bool SO // Storage order
1978  , bool SF > // Symmetry flag
1979 template< typename VT > // Type of the right-hand side sparse vector
1981 {
1982  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1983 
1987 
1988  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1989 
1990  const SubType tmp( serial( *this - (~rhs) ) );
1991  matrix_.reset( col_ );
1992  matrix_.reserve( col_, tmp.nonZeros() );
1993  assign( tmp );
1994 }
1995 //*************************************************************************************************
1996 
1997 
1998 
1999 
2000 
2001 
2002 
2003 
2004 //=================================================================================================
2005 //
2006 // CLASS TEMPLATE SPECIALIZATION FOR GENERAL ROW-MAJOR MATRICES
2007 //
2008 //=================================================================================================
2009 
2010 //*************************************************************************************************
2018 template< typename MT > // Type of the sparse matrix
2019 class SparseColumn<MT,false,false> : public SparseVector< SparseColumn<MT,false,false>, false >
2020  , private Column
2021 {
2022  private:
2023  //**Type definitions****************************************************************************
2025  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
2026  //**********************************************************************************************
2027 
2028  public:
2029  //**Type definitions****************************************************************************
2031  typedef typename ColumnTrait<MT>::Type ResultType;
2032  typedef typename ResultType::TransposeType TransposeType;
2033  typedef typename MT::ElementType ElementType;
2034  typedef typename MT::ReturnType ReturnType;
2035  typedef const SparseColumn& CompositeType;
2036 
2038  typedef typename MT::ConstReference ConstReference;
2039 
2041  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
2042  //**********************************************************************************************
2043 
2044  //**ColumnElement class definition**************************************************************
2047  template< typename MatrixType // Type of the sparse matrix
2048  , typename IteratorType > // Type of the sparse matrix iterator
2049  class ColumnElement : private SparseElement
2050  {
2051  private:
2052  //*******************************************************************************************
2054 
2059  enum { returnConst = IsConst<MatrixType>::value };
2060  //*******************************************************************************************
2061 
2062  //**Type definitions*************************************************************************
2064  typedef typename std::iterator_traits<IteratorType>::value_type SET;
2065 
2066  typedef typename SET::Reference RT;
2067  typedef typename SET::ConstReference CRT;
2068  //*******************************************************************************************
2069 
2070  public:
2071  //**Type definitions*************************************************************************
2072  typedef typename SET::ValueType ValueType;
2073  typedef size_t IndexType;
2074  typedef typename IfTrue<returnConst,CRT,RT>::Type Reference;
2075  typedef CRT ConstReference;
2076  //*******************************************************************************************
2077 
2078  //**Constructor******************************************************************************
2084  inline ColumnElement( IteratorType pos, size_t row )
2085  : pos_( pos ) // Iterator to the current position within the sparse column
2086  , row_( row ) // Index of the according row
2087  {}
2088  //*******************************************************************************************
2089 
2090  //**Assignment operator**********************************************************************
2096  template< typename T > inline ColumnElement& operator=( const T& v ) {
2097  *pos_ = v;
2098  return *this;
2099  }
2100  //*******************************************************************************************
2101 
2102  //**Addition assignment operator*************************************************************
2108  template< typename T > inline ColumnElement& operator+=( const T& v ) {
2109  *pos_ += v;
2110  return *this;
2111  }
2112  //*******************************************************************************************
2113 
2114  //**Subtraction assignment operator**********************************************************
2120  template< typename T > inline ColumnElement& operator-=( const T& v ) {
2121  *pos_ -= v;
2122  return *this;
2123  }
2124  //*******************************************************************************************
2125 
2126  //**Multiplication assignment operator*******************************************************
2132  template< typename T > inline ColumnElement& operator*=( const T& v ) {
2133  *pos_ *= v;
2134  return *this;
2135  }
2136  //*******************************************************************************************
2137 
2138  //**Division assignment operator*************************************************************
2144  template< typename T > inline ColumnElement& operator/=( const T& v ) {
2145  *pos_ /= v;
2146  return *this;
2147  }
2148  //*******************************************************************************************
2149 
2150  //**Element access operator******************************************************************
2155  inline const ColumnElement* operator->() const {
2156  return this;
2157  }
2158  //*******************************************************************************************
2159 
2160  //**Value function***************************************************************************
2165  inline Reference value() const {
2166  return pos_->value();
2167  }
2168  //*******************************************************************************************
2169 
2170  //**Index function***************************************************************************
2175  inline IndexType index() const {
2176  return row_;
2177  }
2178  //*******************************************************************************************
2179 
2180  private:
2181  //**Member variables*************************************************************************
2182  IteratorType pos_;
2183  size_t row_;
2184  //*******************************************************************************************
2185  };
2186  //**********************************************************************************************
2187 
2188  //**ColumnIterator class definition*************************************************************
2191  template< typename MatrixType // Type of the sparse matrix
2192  , typename IteratorType > // Type of the sparse matrix iterator
2193  class ColumnIterator
2194  {
2195  public:
2196  //**Type definitions*************************************************************************
2197  typedef std::forward_iterator_tag IteratorCategory;
2198  typedef ColumnElement<MatrixType,IteratorType> ValueType;
2199  typedef ValueType PointerType;
2200  typedef ValueType ReferenceType;
2201  typedef ptrdiff_t DifferenceType;
2202 
2203  // STL iterator requirements
2204  typedef IteratorCategory iterator_category;
2205  typedef ValueType value_type;
2206  typedef PointerType pointer;
2207  typedef ReferenceType reference;
2208  typedef DifferenceType difference_type;
2209  //*******************************************************************************************
2210 
2211  //**Constructor******************************************************************************
2214  inline ColumnIterator()
2215  : matrix_( NULL ) // The sparse matrix containing the column.
2216  , row_ ( 0UL ) // The current row index.
2217  , column_( 0UL ) // The current column index.
2218  , pos_ () // Iterator to the current sparse element.
2219  {}
2220  //*******************************************************************************************
2221 
2222  //**Constructor******************************************************************************
2229  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column )
2230  : matrix_( &matrix ) // The sparse matrix containing the column.
2231  , row_ ( row ) // The current row index.
2232  , column_( column ) // The current column index.
2233  , pos_ () // Iterator to the current sparse element.
2234  {
2235  for( ; row_<matrix_->rows(); ++row_ ) {
2236  pos_ = matrix_->find( row_, column_ );
2237  if( pos_ != matrix_->end( row_ ) ) break;
2238  }
2239  }
2240  //*******************************************************************************************
2241 
2242  //**Constructor******************************************************************************
2250  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
2251  : matrix_( &matrix ) // The sparse matrix containing the column.
2252  , row_ ( row ) // The current row index.
2253  , column_( column ) // The current column index.
2254  , pos_ ( pos ) // Iterator to the current sparse element.
2255  {
2256  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
2257  }
2258  //*******************************************************************************************
2259 
2260  //**Constructor******************************************************************************
2265  template< typename MatrixType2, typename IteratorType2 >
2266  inline ColumnIterator( const ColumnIterator<MatrixType2,IteratorType2>& it )
2267  : matrix_( it.matrix_ ) // The sparse matrix containing the column.
2268  , row_ ( it.row_ ) // The current row index.
2269  , column_( it.column_ ) // The current column index.
2270  , pos_ ( it.pos_ ) // Iterator to the current sparse element.
2271  {}
2272  //*******************************************************************************************
2273 
2274  //**Prefix increment operator****************************************************************
2279  inline ColumnIterator& operator++() {
2280  ++row_;
2281  for( ; row_<matrix_->rows(); ++row_ ) {
2282  pos_ = matrix_->find( row_, column_ );
2283  if( pos_ != matrix_->end( row_ ) ) break;
2284  }
2285 
2286  return *this;
2287  }
2288  //*******************************************************************************************
2289 
2290  //**Postfix increment operator***************************************************************
2295  inline const ColumnIterator operator++( int ) {
2296  const ColumnIterator tmp( *this );
2297  ++(*this);
2298  return tmp;
2299  }
2300  //*******************************************************************************************
2301 
2302  //**Element access operator******************************************************************
2307  inline ReferenceType operator*() const {
2308  return ReferenceType( pos_, row_ );
2309  }
2310  //*******************************************************************************************
2311 
2312  //**Element access operator******************************************************************
2317  inline PointerType operator->() const {
2318  return PointerType( pos_, row_ );
2319  }
2320  //*******************************************************************************************
2321 
2322  //**Equality operator************************************************************************
2328  template< typename MatrixType2, typename IteratorType2 >
2329  inline bool operator==( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
2330  return ( matrix_ == rhs.matrix_ ) && ( row_ == rhs.row_ ) && ( column_ == rhs.column_ );
2331  }
2332  //*******************************************************************************************
2333 
2334  //**Inequality operator**********************************************************************
2340  template< typename MatrixType2, typename IteratorType2 >
2341  inline bool operator!=( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
2342  return !( *this == rhs );
2343  }
2344  //*******************************************************************************************
2345 
2346  //**Subtraction operator*********************************************************************
2352  inline DifferenceType operator-( const ColumnIterator& rhs ) const {
2353  size_t counter( 0UL );
2354  for( size_t i=rhs.row_; i<row_; ++i ) {
2355  if( matrix_->find( i, column_ ) != matrix_->end( i ) )
2356  ++counter;
2357  }
2358  return counter;
2359  }
2360  //*******************************************************************************************
2361 
2362  private:
2363  //**Member variables*************************************************************************
2364  MatrixType* matrix_;
2365  size_t row_;
2366  size_t column_;
2367  IteratorType pos_;
2368  //*******************************************************************************************
2369 
2370  //**Friend declarations**********************************************************************
2371  template< typename MatrixType2, typename IteratorType2 > friend class ColumnIterator;
2372  template< typename MT2, bool SO2, bool SF2 > friend class SparseColumn;
2373  //*******************************************************************************************
2374  };
2375  //**********************************************************************************************
2376 
2377  //**Type definitions****************************************************************************
2379  typedef ColumnIterator<const MT,typename MT::ConstIterator> ConstIterator;
2380 
2382  typedef typename If< IsConst<MT>, ConstIterator, ColumnIterator<MT,typename MT::Iterator> >::Type Iterator;
2383  //**********************************************************************************************
2384 
2385  //**Compilation flags***************************************************************************
2387  enum { smpAssignable = 0 };
2388  //**********************************************************************************************
2389 
2390  //**Constructors********************************************************************************
2393  explicit inline SparseColumn( MT& matrix, size_t index );
2394  // No explicitly declared copy constructor.
2396  //**********************************************************************************************
2397 
2398  //**Destructor**********************************************************************************
2399  // No explicitly declared destructor.
2400  //**********************************************************************************************
2401 
2402  //**Data access functions***********************************************************************
2405  inline Reference operator[]( size_t index );
2406  inline ConstReference operator[]( size_t index ) const;
2407  inline Reference at( size_t index );
2408  inline ConstReference at( size_t index ) const;
2409  inline Iterator begin ();
2410  inline ConstIterator begin () const;
2411  inline ConstIterator cbegin() const;
2412  inline Iterator end ();
2413  inline ConstIterator end () const;
2414  inline ConstIterator cend () const;
2416  //**********************************************************************************************
2417 
2418  //**Assignment operators************************************************************************
2421  inline SparseColumn& operator= ( const SparseColumn& rhs );
2422  template< typename VT > inline SparseColumn& operator= ( const Vector<VT,false>& rhs );
2423  template< typename VT > inline SparseColumn& operator+=( const Vector<VT,false>& rhs );
2424  template< typename VT > inline SparseColumn& operator-=( const Vector<VT,false>& rhs );
2425  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
2426 
2427  template< typename Other >
2428  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
2429  operator*=( Other rhs );
2430 
2431  template< typename Other >
2432  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
2433  operator/=( Other rhs );
2435  //**********************************************************************************************
2436 
2437  //**Utility functions***************************************************************************
2440  inline size_t size() const;
2441  inline size_t capacity() const;
2442  inline size_t nonZeros() const;
2443  inline void reset();
2444  inline Iterator set ( size_t index, const ElementType& value );
2445  inline Iterator insert ( size_t index, const ElementType& value );
2446  inline void erase ( size_t index );
2447  inline Iterator erase ( Iterator pos );
2448  inline Iterator erase ( Iterator first, Iterator last );
2449  inline void reserve( size_t n );
2450  template< typename Other > inline SparseColumn& scale ( const Other& scalar );
2452  //**********************************************************************************************
2453 
2454  //**Lookup functions****************************************************************************
2457  inline Iterator find ( size_t index );
2458  inline ConstIterator find ( size_t index ) const;
2459  inline Iterator lowerBound( size_t index );
2460  inline ConstIterator lowerBound( size_t index ) const;
2461  inline Iterator upperBound( size_t index );
2462  inline ConstIterator upperBound( size_t index ) const;
2464  //**********************************************************************************************
2465 
2466  //**Low-level utility functions*****************************************************************
2469  inline void append( size_t index, const ElementType& value, bool check=false );
2471  //**********************************************************************************************
2472 
2473  //**Expression template evaluation functions****************************************************
2476  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2477  template< typename Other > inline bool isAliased( const Other* alias ) const;
2478 
2479  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
2480  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
2481  template< typename VT > inline void addAssign( const Vector<VT,false>& rhs );
2482  template< typename VT > inline void subAssign( const Vector<VT,false>& rhs );
2484  //**********************************************************************************************
2485 
2486  private:
2487  //**Member variables****************************************************************************
2490  Operand matrix_;
2491  const size_t col_;
2492 
2493  //**********************************************************************************************
2494 
2495  //**Friend declarations*************************************************************************
2496  template< typename MT2, bool SO2, bool SF2 >
2497  friend bool isIntact( const SparseColumn<MT2,SO2,SF2>& column );
2498 
2499  template< typename MT2, bool SO2, bool SF2 >
2500  friend bool isSame( const SparseColumn<MT2,SO2,SF2>& a, const SparseColumn<MT2,SO2,SF2>& b );
2501 
2502  template< typename MT2, bool SO2, bool SF2, typename VT >
2503  friend bool tryAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
2504 
2505  template< typename MT2, bool SO2, bool SF2, typename VT >
2506  friend bool tryAddAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
2507 
2508  template< typename MT2, bool SO2, bool SF2, typename VT >
2509  friend bool trySubAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
2510 
2511  template< typename MT2, bool SO2, bool SF2, typename VT >
2512  friend bool tryMultAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
2513 
2514  template< typename MT2, bool SO2, bool SF2 >
2515  friend typename DerestrictTrait< SparseColumn<MT2,SO2,SF2> >::Type
2516  derestrict( SparseColumn<MT2,SO2,SF2>& dm );
2517  //**********************************************************************************************
2518 
2519  //**Compile time checks*************************************************************************
2527  //**********************************************************************************************
2528 };
2530 //*************************************************************************************************
2531 
2532 
2533 
2534 
2535 //=================================================================================================
2536 //
2537 // CONSTRUCTOR
2538 //
2539 //=================================================================================================
2540 
2541 //*************************************************************************************************
2549 template< typename MT > // Type of the sparse matrix
2550 inline SparseColumn<MT,false,false>::SparseColumn( MT& matrix, size_t index )
2551  : matrix_( matrix ) // The sparse matrix containing the column
2552  , col_ ( index ) // The index of the column in the matrix
2553 {
2554  if( matrix_.columns() <= index ) {
2555  BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
2556  }
2557 }
2559 //*************************************************************************************************
2560 
2561 
2562 
2563 
2564 //=================================================================================================
2565 //
2566 // DATA ACCESS FUNCTIONS
2567 //
2568 //=================================================================================================
2569 
2570 //*************************************************************************************************
2580 template< typename MT > // Type of the sparse matrix
2583 {
2584  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2585  return matrix_(index,col_);
2586 }
2588 //*************************************************************************************************
2589 
2590 
2591 //*************************************************************************************************
2601 template< typename MT > // Type of the sparse matrix
2603  SparseColumn<MT,false,false>::operator[]( size_t index ) const
2604 {
2605  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2606  return const_cast<const MT&>( matrix_ )(index,col_);
2607 }
2609 //*************************************************************************************************
2610 
2611 
2612 //*************************************************************************************************
2623 template< typename MT > // Type of the sparse matrix
2625  SparseColumn<MT,false,false>::at( size_t index )
2626 {
2627  if( index >= size() ) {
2628  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2629  }
2630  return (*this)[index];
2631 }
2633 //*************************************************************************************************
2634 
2635 
2636 //*************************************************************************************************
2647 template< typename MT > // Type of the sparse matrix
2649  SparseColumn<MT,false,false>::at( size_t index ) const
2650 {
2651  if( index >= size() ) {
2652  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
2653  }
2654  return (*this)[index];
2655 }
2657 //*************************************************************************************************
2658 
2659 
2660 //*************************************************************************************************
2668 template< typename MT > // Type of the sparse matrix
2670 {
2671  return Iterator( matrix_, 0UL, col_ );
2672 }
2674 //*************************************************************************************************
2675 
2676 
2677 //*************************************************************************************************
2685 template< typename MT > // Type of the sparse matrix
2688 {
2689  return ConstIterator( matrix_, 0UL, col_ );
2690 }
2692 //*************************************************************************************************
2693 
2694 
2695 //*************************************************************************************************
2703 template< typename MT > // Type of the sparse matrix
2706 {
2707  return ConstIterator( matrix_, 0UL, col_ );
2708 }
2710 //*************************************************************************************************
2711 
2712 
2713 //*************************************************************************************************
2721 template< typename MT > // Type of the sparse matrix
2723 {
2724  return Iterator( matrix_, size(), col_ );
2725 }
2727 //*************************************************************************************************
2728 
2729 
2730 //*************************************************************************************************
2738 template< typename MT > // Type of the sparse matrix
2741 {
2742  return ConstIterator( matrix_, size(), col_ );
2743 }
2745 //*************************************************************************************************
2746 
2747 
2748 //*************************************************************************************************
2756 template< typename MT > // Type of the sparse matrix
2759 {
2760  return ConstIterator( matrix_, size(), col_ );
2761 }
2763 //*************************************************************************************************
2764 
2765 
2766 
2767 
2768 //=================================================================================================
2769 //
2770 // ASSIGNMENT OPERATORS
2771 //
2772 //=================================================================================================
2773 
2774 //*************************************************************************************************
2788 template< typename MT > // Type of the sparse matrix
2789 inline SparseColumn<MT,false,false>&
2790  SparseColumn<MT,false,false>::operator=( const SparseColumn& rhs )
2791 {
2792  using blaze::assign;
2793 
2797 
2798  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
2799  return *this;
2800 
2801  if( size() != rhs.size() ) {
2802  BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
2803  }
2804 
2805  if( !tryAssign( matrix_, rhs, 0UL, col_ ) ) {
2806  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2807  }
2808 
2809  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2810 
2811  if( rhs.canAlias( &matrix_ ) ) {
2812  const ResultType tmp( rhs );
2813  assign( left, tmp );
2814  }
2815  else {
2816  assign( left, rhs );
2817  }
2818 
2819  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2820 
2821  return *this;
2822 }
2824 //*************************************************************************************************
2825 
2826 
2827 //*************************************************************************************************
2841 template< typename MT > // Type of the sparse matrix
2842 template< typename VT > // Type of the right-hand side vector
2843 inline SparseColumn<MT,false,false>&
2844  SparseColumn<MT,false,false>::operator=( const Vector<VT,false>& rhs )
2845 {
2846  using blaze::assign;
2847 
2848  if( size() != (~rhs).size() ) {
2849  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2850  }
2851 
2852  const typename VT::CompositeType tmp( ~rhs );
2853 
2854  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
2855  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2856  }
2857 
2858  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2859 
2860  assign( left, tmp );
2861 
2862  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2863 
2864  return *this;
2865 }
2867 //*************************************************************************************************
2868 
2869 
2870 //*************************************************************************************************
2884 template< typename MT > // Type of the sparse matrix
2885 template< typename VT > // Type of the right-hand side vector
2886 inline SparseColumn<MT,false,false>&
2887  SparseColumn<MT,false,false>::operator+=( const Vector<VT,false>& rhs )
2888 {
2889  using blaze::assign;
2890 
2896 
2897  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
2898 
2901 
2902  if( size() != (~rhs).size() ) {
2903  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2904  }
2905 
2906  const AddType tmp( *this + (~rhs) );
2907 
2908  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
2909  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2910  }
2911 
2912  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2913 
2914  assign( left, tmp );
2915 
2916  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2917 
2918  return *this;
2919 }
2921 //*************************************************************************************************
2922 
2923 
2924 //*************************************************************************************************
2938 template< typename MT > // Type of the sparse matrix
2939 template< typename VT > // Type of the right-hand side vector
2940 inline SparseColumn<MT,false,false>&
2941  SparseColumn<MT,false,false>::operator-=( const Vector<VT,false>& rhs )
2942 {
2943  using blaze::assign;
2944 
2950 
2951  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
2952 
2955 
2956  if( size() != (~rhs).size() ) {
2957  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
2958  }
2959 
2960  const SubType tmp( *this - (~rhs) );
2961 
2962  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
2963  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
2964  }
2965 
2966  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
2967 
2968  assign( left, tmp );
2969 
2970  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
2971 
2972  return *this;
2973 }
2975 //*************************************************************************************************
2976 
2977 
2978 //*************************************************************************************************
2991 template< typename MT > // Type of the sparse matrix
2992 template< typename VT > // Type of the right-hand side vector
2993 inline SparseColumn<MT,false,false>&
2994  SparseColumn<MT,false,false>::operator*=( const Vector<VT,false>& rhs )
2995 {
2996  using blaze::assign;
2997 
3003 
3004  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
3005 
3008 
3009  if( size() != (~rhs).size() ) {
3010  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
3011  }
3012 
3013  const MultType tmp( *this * (~rhs) );
3014 
3015  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
3016  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
3017  }
3018 
3019  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
3020 
3021  assign( left, tmp );
3022 
3023  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
3024 
3025  return *this;
3026 }
3028 //*************************************************************************************************
3029 
3030 
3031 //*************************************************************************************************
3046 template< typename MT > // Type of the sparse matrix
3047 template< typename Other > // Data type of the right-hand side scalar
3048 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false,false> >::Type&
3049  SparseColumn<MT,false,false>::operator*=( Other rhs )
3050 {
3052 
3053  for( Iterator element=begin(); element!=end(); ++element )
3054  element->value() *= rhs;
3055  return *this;
3056 }
3058 //*************************************************************************************************
3059 
3060 
3061 //*************************************************************************************************
3079 template< typename MT > // Type of the sparse matrix
3080 template< typename Other > // Data type of the right-hand side scalar
3081 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false,false> >::Type&
3082  SparseColumn<MT,false,false>::operator/=( Other rhs )
3083 {
3085 
3086  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
3087 
3088  typedef typename DivTrait<ElementType,Other>::Type DT;
3089  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
3090 
3091  // Depending on the two involved data types, an integer division is applied or a
3092  // floating point division is selected.
3093  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
3094  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
3095  for( Iterator element=begin(); element!=end(); ++element )
3096  element->value() *= tmp;
3097  }
3098  else {
3099  for( Iterator element=begin(); element!=end(); ++element )
3100  element->value() /= rhs;
3101  }
3102 
3103  return *this;
3104 }
3106 //*************************************************************************************************
3107 
3108 
3109 
3110 
3111 //=================================================================================================
3112 //
3113 // UTILITY FUNCTIONS
3114 //
3115 //=================================================================================================
3116 
3117 //*************************************************************************************************
3123 template< typename MT > // Type of the sparse matrix
3124 inline size_t SparseColumn<MT,false,false>::size() const
3125 {
3126  return matrix_.rows();
3127 }
3129 //*************************************************************************************************
3130 
3131 
3132 //*************************************************************************************************
3138 template< typename MT > // Type of the sparse matrix
3139 inline size_t SparseColumn<MT,false,false>::capacity() const
3140 {
3141  return matrix_.rows();
3142 }
3144 //*************************************************************************************************
3145 
3146 
3147 //*************************************************************************************************
3156 template< typename MT > // Type of the sparse matrix
3157 inline size_t SparseColumn<MT,false,false>::nonZeros() const
3158 {
3159  size_t counter( 0UL );
3160  for( ConstIterator element=begin(); element!=end(); ++element ) {
3161  ++counter;
3162  }
3163  return counter;
3164 }
3166 //*************************************************************************************************
3167 
3168 
3169 //*************************************************************************************************
3175 template< typename MT > // Type of the sparse matrix
3177 {
3178  const size_t ibegin( ( IsLower<MT>::value )
3179  ?( ( IsUniLower<MT>::value || IsStrictlyLower<MT>::value )
3180  ?( col_+1UL )
3181  :( col_ ) )
3182  :( 0UL ) );
3183  const size_t iend ( ( IsUpper<MT>::value )
3184  ?( ( IsUniUpper<MT>::value || IsStrictlyUpper<MT>::value )
3185  ?( col_ )
3186  :( col_+1UL ) )
3187  :( size() ) );
3188 
3189  for( size_t i=ibegin; i<iend; ++i ) {
3190  matrix_.erase( i, col_ );
3191  }
3192 }
3194 //*************************************************************************************************
3195 
3196 
3197 //*************************************************************************************************
3209 template< typename MT > // Type of the sparse matrix
3211  SparseColumn<MT,false,false>::set( size_t index, const ElementType& value )
3212 {
3213  return Iterator( matrix_, index, col_, matrix_.set( index, col_, value ) );
3214 }
3216 //*************************************************************************************************
3217 
3218 
3219 //*************************************************************************************************
3232 template< typename MT > // Type of the sparse matrix
3234  SparseColumn<MT,false,false>::insert( size_t index, const ElementType& value )
3235 {
3236  return Iterator( matrix_, index, col_, matrix_.insert( index, col_, value ) );
3237 }
3239 //*************************************************************************************************
3240 
3241 
3242 //*************************************************************************************************
3251 template< typename MT > // Type of the sparse matrix
3252 inline void SparseColumn<MT,false,false>::erase( size_t index )
3253 {
3254  matrix_.erase( index, col_ );
3255 }
3257 //*************************************************************************************************
3258 
3259 
3260 //*************************************************************************************************
3269 template< typename MT > // Type of the sparse matrix
3272 {
3273  const size_t row( pos.row_ );
3274 
3275  if( row == size() )
3276  return pos;
3277 
3278  matrix_.erase( row, pos.pos_ );
3279  return Iterator( matrix_, row+1UL, col_ );
3280 }
3282 //*************************************************************************************************
3283 
3284 
3285 //*************************************************************************************************
3295 template< typename MT > // Type of the sparse matrix
3298 {
3299  for( ; first!=last; ++first ) {
3300  matrix_.erase( first.row_, first.pos_ );
3301  }
3302  return last;
3303 }
3305 //*************************************************************************************************
3306 
3307 
3308 //*************************************************************************************************
3318 template< typename MT > // Type of the sparse matrix
3320 {
3321  UNUSED_PARAMETER( n );
3322 
3323  return;
3324 }
3326 //*************************************************************************************************
3327 
3328 
3329 //*************************************************************************************************
3340 template< typename MT > // Type of the sparse matrix
3341 template< typename Other > // Data type of the scalar value
3342 inline SparseColumn<MT,false,false>& SparseColumn<MT,false,false>::scale( const Other& scalar )
3343 {
3345 
3346  for( Iterator element=begin(); element!=end(); ++element )
3347  element->value() *= scalar;
3348  return *this;
3349 }
3351 //*************************************************************************************************
3352 
3353 
3354 
3355 
3356 //=================================================================================================
3357 //
3358 // LOOKUP FUNCTIONS
3359 //
3360 //=================================================================================================
3361 
3362 //*************************************************************************************************
3376 template< typename MT > // Type of the sparse matrix
3378  SparseColumn<MT,false,false>::find( size_t index )
3379 {
3380  const typename MT::Iterator pos( matrix_.find( index, col_ ) );
3381 
3382  if( pos != matrix_.end( index ) )
3383  return Iterator( matrix_, index, col_, pos );
3384  else
3385  return end();
3386 }
3388 //*************************************************************************************************
3389 
3390 
3391 //*************************************************************************************************
3405 template< typename MT > // Type of the sparse matrix
3407  SparseColumn<MT,false,false>::find( size_t index ) const
3408 {
3409  const typename MT::ConstIterator pos( matrix_.find( index, col_ ) );
3410 
3411  if( pos != matrix_.end( index ) )
3412  return ConstIterator( matrix_, index, col_, pos );
3413  else
3414  return end();
3415 }
3417 //*************************************************************************************************
3418 
3419 
3420 //*************************************************************************************************
3433 template< typename MT > // Type of the sparse matrix
3436 {
3437  for( size_t i=index; i<size(); ++i )
3438  {
3439  const typename MT::Iterator pos( matrix_.find( i, col_ ) );
3440 
3441  if( pos != matrix_.end( i ) )
3442  return Iterator( matrix_, i, col_, pos );
3443  }
3444 
3445  return end();
3446 }
3448 //*************************************************************************************************
3449 
3450 
3451 //*************************************************************************************************
3464 template< typename MT > // Type of the sparse matrix
3466  SparseColumn<MT,false,false>::lowerBound( size_t index ) const
3467 {
3468  for( size_t i=index; i<size(); ++i )
3469  {
3470  const typename MT::ConstIterator pos( matrix_.find( i, col_ ) );
3471 
3472  if( pos != matrix_.end( i ) )
3473  return ConstIterator( matrix_, i, col_, pos );
3474  }
3475 
3476  return end();
3477 }
3479 //*************************************************************************************************
3480 
3481 
3482 //*************************************************************************************************
3495 template< typename MT > // Type of the sparse matrix
3498 {
3499  for( size_t i=index+1UL; i<size(); ++i )
3500  {
3501  const typename MT::Iterator pos( matrix_.find( i, col_ ) );
3502 
3503  if( pos != matrix_.end( i ) )
3504  return Iterator( matrix_, i, col_, pos );
3505  }
3506 
3507  return end();
3508 }
3510 //*************************************************************************************************
3511 
3512 
3513 //*************************************************************************************************
3526 template< typename MT > // Type of the sparse matrix
3528  SparseColumn<MT,false,false>::upperBound( size_t index ) const
3529 {
3530  for( size_t i=index+1UL; i<size(); ++i )
3531  {
3532  const typename MT::ConstIterator pos( matrix_.find( i, col_ ) );
3533 
3534  if( pos != matrix_.end( i ) )
3535  return ConstIterator( matrix_, i, col_, pos );
3536  }
3537 
3538  return end();
3539 }
3541 //*************************************************************************************************
3542 
3543 
3544 
3545 
3546 //=================================================================================================
3547 //
3548 // LOW-LEVEL UTILITY FUNCTIONS
3549 //
3550 //=================================================================================================
3551 
3552 //*************************************************************************************************
3577 template< typename MT > // Type of the sparse matrix
3578 inline void SparseColumn<MT,false,false>::append( size_t index, const ElementType& value, bool check )
3579 {
3580  if( !check || !isDefault( value ) )
3581  matrix_.insert( index, col_, value );
3582 }
3584 //*************************************************************************************************
3585 
3586 
3587 
3588 
3589 //=================================================================================================
3590 //
3591 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
3592 //
3593 //=================================================================================================
3594 
3595 //*************************************************************************************************
3606 template< typename MT > // Type of the sparse matrix
3607 template< typename Other > // Data type of the foreign expression
3608 inline bool SparseColumn<MT,false,false>::canAlias( const Other* alias ) const
3609 {
3610  return matrix_.isAliased( alias );
3611 }
3613 //*************************************************************************************************
3614 
3615 
3616 //*************************************************************************************************
3623 template< typename MT > // Type of the sparse matrix
3624 template< typename Other > // Data type of the foreign expression
3625 inline bool SparseColumn<MT,false,false>::isAliased( const Other* alias ) const
3626 {
3627  return matrix_.isAliased( alias );
3628 }
3630 //*************************************************************************************************
3631 
3632 
3633 //*************************************************************************************************
3645 template< typename MT > // Type of the sparse matrix
3646 template< typename VT > // Type of the right-hand side dense vector
3647 inline void SparseColumn<MT,false,false>::assign( const DenseVector<VT,false>& rhs )
3648 {
3649  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3650 
3651  for( size_t i=0UL; i<(~rhs).size(); ++i ) {
3652  matrix_(i,col_) = (~rhs)[i];
3653  }
3654 }
3656 //*************************************************************************************************
3657 
3658 
3659 //*************************************************************************************************
3671 template< typename MT > // Type of the sparse matrix
3672 template< typename VT > // Type of the right-hand side sparse vector
3673 inline void SparseColumn<MT,false,false>::assign( const SparseVector<VT,false>& rhs )
3674 {
3675  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3676 
3677  size_t i( 0UL );
3678 
3679  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
3680  for( ; i<element->index(); ++i )
3681  matrix_.erase( i, col_ );
3682  matrix_(i++,col_) = element->value();
3683  }
3684  for( ; i<size(); ++i ) {
3685  matrix_.erase( i, col_ );
3686  }
3687 }
3689 //*************************************************************************************************
3690 
3691 
3692 //*************************************************************************************************
3704 template< typename MT > // Type of the sparse matrix
3705 template< typename VT > // Type of the right-hand side vector
3706 inline void SparseColumn<MT,false,false>::addAssign( const Vector<VT,false>& rhs )
3707 {
3708  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3709 
3712 
3713  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3714 
3715  const AddType tmp( serial( *this + (~rhs) ) );
3716  assign( tmp );
3717 }
3719 //*************************************************************************************************
3720 
3721 
3722 //*************************************************************************************************
3734 template< typename MT > // Type of the sparse matrix
3735 template< typename VT > // Type of the right-hand side vector
3736 inline void SparseColumn<MT,false,false>::subAssign( const Vector<VT,false>& rhs )
3737 {
3738  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3739 
3742 
3743  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3744 
3745  const SubType tmp( serial( *this - (~rhs) ) );
3746  assign( tmp );
3747 }
3749 //*************************************************************************************************
3750 
3751 
3752 
3753 
3754 
3755 
3756 
3757 
3758 //=================================================================================================
3759 //
3760 // CLASS TEMPLATE SPECIALIZATION FOR SYMMETRIC ROW-MAJOR MATRICES
3761 //
3762 //=================================================================================================
3763 
3764 //*************************************************************************************************
3772 template< typename MT > // Type of the sparse matrix
3773 class SparseColumn<MT,false,true> : public SparseVector< SparseColumn<MT,false,true>, false >
3774  , private Column
3775 {
3776  private:
3777  //**Type definitions****************************************************************************
3779  typedef typename If< IsExpression<MT>, MT, MT& >::Type Operand;
3780  //**********************************************************************************************
3781 
3782  public:
3783  //**Type definitions****************************************************************************
3784  typedef SparseColumn<MT,false,true> This;
3785  typedef typename ColumnTrait<MT>::Type ResultType;
3786  typedef typename ResultType::TransposeType TransposeType;
3787  typedef typename MT::ElementType ElementType;
3788  typedef typename MT::ReturnType ReturnType;
3789  typedef const SparseColumn& CompositeType;
3790 
3792  typedef typename MT::ConstReference ConstReference;
3793 
3795  typedef typename If< IsConst<MT>, ConstReference, typename MT::Reference >::Type Reference;
3796 
3798  typedef typename MT::ConstIterator ConstIterator;
3799 
3801  typedef typename If< IsConst<MT>, ConstIterator, typename MT::Iterator >::Type Iterator;
3802  //**********************************************************************************************
3803 
3804  //**Compilation flags***************************************************************************
3806  enum { smpAssignable = 0 };
3807  //**********************************************************************************************
3808 
3809  //**Constructors********************************************************************************
3812  explicit inline SparseColumn( MT& matrix, size_t index );
3813  // No explicitly declared copy constructor.
3815  //**********************************************************************************************
3816 
3817  //**Destructor**********************************************************************************
3818  // No explicitly declared destructor.
3819  //**********************************************************************************************
3820 
3821  //**Data access functions***********************************************************************
3824  inline Reference operator[]( size_t index );
3825  inline ConstReference operator[]( size_t index ) const;
3826  inline Reference at( size_t index );
3827  inline ConstReference at( size_t index ) const;
3828  inline Iterator begin ();
3829  inline ConstIterator begin () const;
3830  inline ConstIterator cbegin() const;
3831  inline Iterator end ();
3832  inline ConstIterator end () const;
3833  inline ConstIterator cend () const;
3835  //**********************************************************************************************
3836 
3837  //**Assignment operators************************************************************************
3840  inline SparseColumn& operator=( const SparseColumn& rhs );
3841 
3842  template< typename VT > inline SparseColumn& operator= ( const DenseVector<VT,false>& rhs );
3843  template< typename VT > inline SparseColumn& operator= ( const SparseVector<VT,false>& rhs );
3844  template< typename VT > inline SparseColumn& operator+=( const DenseVector<VT,false>& rhs );
3845  template< typename VT > inline SparseColumn& operator+=( const SparseVector<VT,false>& rhs );
3846  template< typename VT > inline SparseColumn& operator-=( const DenseVector<VT,false>& rhs );
3847  template< typename VT > inline SparseColumn& operator-=( const SparseVector<VT,false>& rhs );
3848  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
3849 
3850  template< typename Other >
3851  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
3852  operator*=( Other rhs );
3853 
3854  template< typename Other >
3855  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
3856  operator/=( Other rhs );
3858  //**********************************************************************************************
3859 
3860  //**Utility functions***************************************************************************
3863  inline size_t size() const;
3864  inline size_t capacity() const;
3865  inline size_t nonZeros() const;
3866  inline void reset();
3867  inline Iterator set ( size_t index, const ElementType& value );
3868  inline Iterator insert ( size_t index, const ElementType& value );
3869  inline void erase ( size_t index );
3870  inline Iterator erase ( Iterator pos );
3871  inline Iterator erase ( Iterator first, Iterator last );
3872  inline void reserve( size_t n );
3873  template< typename Other > inline SparseColumn& scale ( const Other& scalar );
3875  //**********************************************************************************************
3876 
3877  //**Lookup functions****************************************************************************
3880  inline Iterator find ( size_t index );
3881  inline ConstIterator find ( size_t index ) const;
3882  inline Iterator lowerBound( size_t index );
3883  inline ConstIterator lowerBound( size_t index ) const;
3884  inline Iterator upperBound( size_t index );
3885  inline ConstIterator upperBound( size_t index ) const;
3887  //**********************************************************************************************
3888 
3889  //**Low-level utility functions*****************************************************************
3892  inline void append( size_t index, const ElementType& value, bool check=false );
3894  //**********************************************************************************************
3895 
3896  //**Expression template evaluation functions****************************************************
3899  template< typename Other > inline bool canAlias ( const Other* alias ) const;
3900  template< typename Other > inline bool isAliased( const Other* alias ) const;
3901 
3902  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
3903  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
3904  template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
3905  template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
3906  template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
3907  template< typename VT > inline void subAssign( const SparseVector<VT,false>& rhs );
3909  //**********************************************************************************************
3910 
3911  private:
3912  //**Utility functions***************************************************************************
3915  inline size_t extendCapacity() const;
3917  //**********************************************************************************************
3918 
3919  //**Member variables****************************************************************************
3922  Operand matrix_;
3923  const size_t col_;
3924 
3925  //**********************************************************************************************
3926 
3927  //**Friend declarations*************************************************************************
3928  template< typename MT2, bool SO2, bool SF2 >
3929  friend bool isIntact( const SparseColumn<MT2,SO2,SF2>& column );
3930 
3931  template< typename MT2, bool SO2, bool SF2 >
3932  friend bool isSame( const SparseColumn<MT2,SO2,SF2>& a, const SparseColumn<MT2,SO2,SF2>& b );
3933 
3934  template< typename MT2, bool SO2, bool SF2, typename VT >
3935  friend bool tryAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
3936 
3937  template< typename MT2, bool SO2, bool SF2, typename VT >
3938  friend bool tryAddAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
3939 
3940  template< typename MT2, bool SO2, bool SF2, typename VT >
3941  friend bool trySubAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
3942 
3943  template< typename MT2, bool SO2, bool SF2, typename VT >
3944  friend bool tryMultAssign( const SparseColumn<MT2,SO2,SF2>& lhs, const Vector<VT,false>& rhs, size_t index );
3945 
3946  template< typename MT2, bool SO2, bool SF2 >
3947  friend typename DerestrictTrait< SparseColumn<MT2,SO2,SF2> >::Type
3948  derestrict( SparseColumn<MT2,SO2,SF2>& dm );
3949  //**********************************************************************************************
3950 
3951  //**Compile time checks*************************************************************************
3959  //**********************************************************************************************
3960 };
3962 //*************************************************************************************************
3963 
3964 
3965 
3966 
3967 //=================================================================================================
3968 //
3969 // CONSTRUCTOR
3970 //
3971 //=================================================================================================
3972 
3973 //*************************************************************************************************
3981 template< typename MT > // Type of the sparse matrix
3982 inline SparseColumn<MT,false,true>::SparseColumn( MT& matrix, size_t index )
3983  : matrix_( matrix ) // The sparse matrix containing the column
3984  , col_ ( index ) // The index of the column in the matrix
3985 {
3986  if( matrix_.columns() <= index ) {
3987  BLAZE_THROW_INVALID_ARGUMENT( "Invalid column access index" );
3988  }
3989 }
3991 //*************************************************************************************************
3992 
3993 
3994 
3995 
3996 //=================================================================================================
3997 //
3998 // DATA ACCESS FUNCTIONS
3999 //
4000 //=================================================================================================
4001 
4002 //*************************************************************************************************
4012 template< typename MT > // Type of the sparse matrix
4015 {
4016  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
4017  return matrix_(col_,index);
4018 }
4020 //*************************************************************************************************
4021 
4022 
4023 //*************************************************************************************************
4033 template< typename MT > // Type of the sparse matrix
4035  SparseColumn<MT,false,true>::operator[]( size_t index ) const
4036 {
4037  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
4038  return const_cast<const MT&>( matrix_ )(col_,index);
4039 }
4041 //*************************************************************************************************
4042 
4043 
4044 //*************************************************************************************************
4055 template< typename MT > // Type of the sparse matrix
4057  SparseColumn<MT,false,true>::at( size_t index )
4058 {
4059  if( index >= size() ) {
4060  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4061  }
4062  return (*this)[index];
4063 }
4065 //*************************************************************************************************
4066 
4067 
4068 //*************************************************************************************************
4079 template< typename MT > // Type of the sparse matrix
4081  SparseColumn<MT,false,true>::at( size_t index ) const
4082 {
4083  if( index >= size() ) {
4084  BLAZE_THROW_OUT_OF_RANGE( "Invalid column access index" );
4085  }
4086  return (*this)[index];
4087 }
4089 //*************************************************************************************************
4090 
4091 
4092 //*************************************************************************************************
4100 template< typename MT > // Type of the sparse matrix
4102 {
4103  return matrix_.begin( col_ );
4104 }
4106 //*************************************************************************************************
4107 
4108 
4109 //*************************************************************************************************
4117 template< typename MT > // Type of the sparse matrix
4120 {
4121  return matrix_.cbegin( col_ );
4122 }
4124 //*************************************************************************************************
4125 
4126 
4127 //*************************************************************************************************
4135 template< typename MT > // Type of the sparse matrix
4138 {
4139  return matrix_.cbegin( col_ );
4140 }
4142 //*************************************************************************************************
4143 
4144 
4145 //*************************************************************************************************
4153 template< typename MT > // Type of the sparse matrix
4155 {
4156  return matrix_.end( col_ );
4157 }
4159 //*************************************************************************************************
4160 
4161 
4162 //*************************************************************************************************
4170 template< typename MT > // Type of the sparse matrix
4173 {
4174  return matrix_.cend( col_ );
4175 }
4177 //*************************************************************************************************
4178 
4179 
4180 //*************************************************************************************************
4188 template< typename MT > // Type of the sparse matrix
4191 {
4192  return matrix_.cend( col_ );
4193 }
4195 //*************************************************************************************************
4196 
4197 
4198 
4199 
4200 //=================================================================================================
4201 //
4202 // ASSIGNMENT OPERATORS
4203 //
4204 //=================================================================================================
4205 
4206 //*************************************************************************************************
4220 template< typename MT > // Type of the sparse matrix
4221 inline SparseColumn<MT,false,true>& SparseColumn<MT,false,true>::operator=( const SparseColumn& rhs )
4222 {
4223  using blaze::assign;
4224 
4228 
4229  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
4230  return *this;
4231 
4232  if( size() != rhs.size() ) {
4233  BLAZE_THROW_INVALID_ARGUMENT( "Column sizes do not match" );
4234  }
4235 
4236  if( !tryAssign( matrix_, rhs, 0UL, col_ ) ) {
4237  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4238  }
4239 
4240  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4241 
4242  if( rhs.canAlias( &matrix_ ) ) {
4243  const ResultType tmp( rhs );
4244  left.reset();
4245  left.reserve( tmp.nonZeros() );
4246  assign( left, tmp );
4247  }
4248  else {
4249  left.reset();
4250  left.reserve( rhs.nonZeros() );
4251  assign( left, rhs );
4252  }
4253 
4254  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4255 
4256  return *this;
4257 }
4259 //*************************************************************************************************
4260 
4261 
4262 //*************************************************************************************************
4276 template< typename MT > // Type of the sparse matrix
4277 template< typename VT > // Type of the right-hand side dense vector
4278 inline SparseColumn<MT,false,true>&
4279  SparseColumn<MT,false,true>::operator=( const DenseVector<VT,false>& rhs )
4280 {
4281  using blaze::assign;
4282 
4286 
4287  if( size() != (~rhs).size() ) {
4288  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4289  }
4290 
4291  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
4292  Right right( ~rhs );
4293 
4294  if( !tryAssign( matrix_, right, 0UL, col_ ) ) {
4295  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4296  }
4297 
4298  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4299 
4300  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4301  const typename VT::ResultType tmp( right );
4302  left.reset();
4303  assign( left, tmp );
4304  }
4305  else {
4306  left.reset();
4307  assign( left, right );
4308  }
4309 
4310  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4311 
4312  return *this;
4313 }
4315 //*************************************************************************************************
4316 
4317 
4318 //*************************************************************************************************
4332 template< typename MT > // Type of the sparse matrix
4333 template< typename VT > // Type of the right-hand side sparse vector
4334 inline SparseColumn<MT,false,true>&
4335  SparseColumn<MT,false,true>::operator=( const SparseVector<VT,false>& rhs )
4336 {
4337  using blaze::assign;
4338 
4342 
4343  if( size() != (~rhs).size() ) {
4344  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4345  }
4346 
4347  typedef typename If< IsRestricted<MT>, typename VT::CompositeType, const VT& >::Type Right;
4348  Right right( ~rhs );
4349 
4350  if( !tryAssign( matrix_, right, 0UL, col_ ) ) {
4351  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4352  }
4353 
4354  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4355 
4356  if( IsReference<Right>::value && right.canAlias( &matrix_ ) ) {
4357  const typename VT::ResultType tmp( right);
4358  left.reset();
4359  left.reserve( tmp.nonZeros() );
4360  assign( left, tmp );
4361  }
4362  else {
4363  left.reset();
4364  left.reserve( right.nonZeros() );
4365  assign( left, right );
4366  }
4367 
4368  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4369 
4370  return *this;
4371 }
4373 //*************************************************************************************************
4374 
4375 
4376 //*************************************************************************************************
4390 template< typename MT > // Type of the sparse matrix
4391 template< typename VT > // Type of the right-hand side dense vector
4392 inline SparseColumn<MT,false,true>&
4393  SparseColumn<MT,false,true>::operator+=( const DenseVector<VT,false>& rhs )
4394 {
4395  using blaze::assign;
4396 
4403 
4404  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4405 
4409 
4410  if( size() != (~rhs).size() ) {
4411  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4412  }
4413 
4414  const AddType tmp( *this + (~rhs) );
4415 
4416  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
4417  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4418  }
4419 
4420  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4421 
4422  left.reset();
4423  assign( left, tmp );
4424 
4425  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4426 
4427  return *this;
4428 }
4430 //*************************************************************************************************
4431 
4432 
4433 //*************************************************************************************************
4447 template< typename MT > // Type of the sparse matrix
4448 template< typename VT > // Type of the right-hand side sparse vector
4449 inline SparseColumn<MT,false,true>&
4450  SparseColumn<MT,false,true>::operator+=( const SparseVector<VT,false>& rhs )
4451 {
4452  using blaze::assign;
4453 
4460 
4461  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
4462 
4466 
4467  if( size() != (~rhs).size() ) {
4468  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4469  }
4470 
4471  const AddType tmp( *this + (~rhs) );
4472 
4473  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
4474  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4475  }
4476 
4477  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4478 
4479  left.reset();
4480  left.reserve( tmp.nonZeros() );
4481  assign( left, tmp );
4482 
4483  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4484 
4485  return *this;
4486 }
4488 //*************************************************************************************************
4489 
4490 
4491 //*************************************************************************************************
4506 template< typename MT > // Type of the sparse matrix
4507 template< typename VT > // Type of the right-hand side dense vector
4508 inline SparseColumn<MT,false,true>&
4509  SparseColumn<MT,false,true>::operator-=( const DenseVector<VT,false>& rhs )
4510 {
4511  using blaze::assign;
4512 
4519 
4520  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4521 
4525 
4526  if( size() != (~rhs).size() ) {
4527  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4528  }
4529 
4530  const SubType tmp( *this - (~rhs) );
4531 
4532  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
4533  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4534  }
4535 
4536  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4537 
4538  left.reset();
4539  assign( left, tmp );
4540 
4541  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4542 
4543  return *this;
4544 }
4546 //*************************************************************************************************
4547 
4548 
4549 //*************************************************************************************************
4564 template< typename MT > // Type of the sparse matrix
4565 template< typename VT > // Type of the right-hand side sparse vector
4566 inline SparseColumn<MT,false,true>&
4567  SparseColumn<MT,false,true>::operator-=( const SparseVector<VT,false>& rhs )
4568 {
4569  using blaze::assign;
4570 
4577 
4578  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
4579 
4583 
4584  if( size() != (~rhs).size() ) {
4585  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4586  }
4587 
4588  const SubType tmp( *this - (~rhs) );
4589 
4590  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
4591  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4592  }
4593 
4594  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4595 
4596  left.reset();
4597  left.reserve( tmp.nonZeros() );
4598  assign( left, tmp );
4599 
4600  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4601 
4602  return *this;
4603 }
4605 //*************************************************************************************************
4606 
4607 
4608 //*************************************************************************************************
4621 template< typename MT > // Type of the sparse matrix
4622 template< typename VT > // Type of the right-hand side vector
4623 inline SparseColumn<MT,false,true>&
4624  SparseColumn<MT,false,true>::operator*=( const Vector<VT,false>& rhs )
4625 {
4626  using blaze::assign;
4627 
4633 
4634  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
4635 
4638 
4639  if( size() != (~rhs).size() ) {
4640  BLAZE_THROW_INVALID_ARGUMENT( "Vector sizes do not match" );
4641  }
4642 
4643  const MultType tmp( *this * (~rhs) );
4644 
4645  if( !tryAssign( matrix_, tmp, 0UL, col_ ) ) {
4646  BLAZE_THROW_INVALID_ARGUMENT( "Invalid assignment to restricted matrix" );
4647  }
4648 
4649  typename DerestrictTrait<This>::Type left( derestrict( *this ) );
4650 
4651  left.reset();
4652  assign( left, tmp );
4653 
4654  BLAZE_INTERNAL_ASSERT( isIntact( matrix_ ), "Invariant violation detected" );
4655 
4656  return *this;
4657 }
4659 //*************************************************************************************************
4660 
4661 
4662 //*************************************************************************************************
4677 template< typename MT > // Type of the sparse matrix
4678 template< typename Other > // Data type of the right-hand side scalar
4679 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false,true> >::Type&
4680  SparseColumn<MT,false,true>::operator*=( Other rhs )
4681 {
4683 
4684  for( Iterator element=begin(); element!=end(); ++element )
4685  element->value() *= rhs;
4686  return *this;
4687 }
4689 //*************************************************************************************************
4690 
4691 
4692 //*************************************************************************************************
4710 template< typename MT > // Type of the sparse matrix
4711 template< typename Other > // Data type of the right-hand side scalar
4712 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false,true> >::Type&
4713  SparseColumn<MT,false,true>::operator/=( Other rhs )
4714 {
4716 
4717  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
4718 
4719  typedef typename DivTrait<ElementType,Other>::Type DT;
4720  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
4721 
4722  // Depending on the two involved data types, an integer division is applied or a
4723  // floating point division is selected.
4724  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
4725  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
4726  for( Iterator element=begin(); element!=end(); ++element )
4727  element->value() *= tmp;
4728  }
4729  else {
4730  for( Iterator element=begin(); element!=end(); ++element )
4731  element->value() /= rhs;
4732  }
4733 
4734  return *this;
4735 }
4737 //*************************************************************************************************
4738 
4739 
4740 
4741 
4742 //=================================================================================================
4743 //
4744 // UTILITY FUNCTIONS
4745 //
4746 //=================================================================================================
4747 
4748 //*************************************************************************************************
4754 template< typename MT > // Type of the sparse matrix
4755 inline size_t SparseColumn<MT,false,true>::size() const
4756 {
4757  return matrix_.rows();
4758 }
4760 //*************************************************************************************************
4761 
4762 
4763 //*************************************************************************************************
4769 template< typename MT > // Type of the sparse matrix
4770 inline size_t SparseColumn<MT,false,true>::capacity() const
4771 {
4772  return matrix_.capacity( col_ );
4773 }
4775 //*************************************************************************************************
4776 
4777 
4778 //*************************************************************************************************
4787 template< typename MT > // Type of the sparse matrix
4788 inline size_t SparseColumn<MT,false,true>::nonZeros() const
4789 {
4790  return matrix_.nonZeros( col_ );
4791 }
4793 //*************************************************************************************************
4794 
4795 
4796 //*************************************************************************************************
4802 template< typename MT > // Type of the sparse matrix
4804 {
4805  matrix_.reset( col_ );
4806 }
4808 //*************************************************************************************************
4809 
4810 
4811 //*************************************************************************************************
4823 template< typename MT > // Type of the sparse matrix
4825  SparseColumn<MT,false,true>::set( size_t index, const ElementType& value )
4826 {
4827  return matrix_.set( col_, index, value );
4828 }
4830 //*************************************************************************************************
4831 
4832 
4833 //*************************************************************************************************
4846 template< typename MT > // Type of the sparse matrix
4848  SparseColumn<MT,false,true>::insert( size_t index, const ElementType& value )
4849 {
4850  return matrix_.insert( col_, index, value );
4851 }
4853 //*************************************************************************************************
4854 
4855 
4856 //*************************************************************************************************
4865 template< typename MT > // Type of the sparse matrix
4866 inline void SparseColumn<MT,false,true>::erase( size_t index )
4867 {
4868  matrix_.erase( col_, index );
4869 }
4871 //*************************************************************************************************
4872 
4873 
4874 //*************************************************************************************************
4883 template< typename MT > // Type of the sparse matrix
4886 {
4887  return matrix_.erase( col_, pos );
4888 }
4890 //*************************************************************************************************
4891 
4892 
4893 //*************************************************************************************************
4903 template< typename MT > // Type of the sparse matrix
4906 {
4907  return matrix_.erase( col_, first, last );
4908 }
4910 //*************************************************************************************************
4911 
4912 
4913 //*************************************************************************************************
4923 template< typename MT > // Type of the sparse matrix
4924 void SparseColumn<MT,false,true>::reserve( size_t n )
4925 {
4926  matrix_.reserve( col_, n );
4927 }
4929 //*************************************************************************************************
4930 
4931 
4932 //*************************************************************************************************
4943 template< typename MT > // Type of the sparse matrix
4944 template< typename Other > // Data type of the scalar value
4945 inline SparseColumn<MT,false,true>& SparseColumn<MT,false,true>::scale( const Other& scalar )
4946 {
4948 
4949  for( Iterator element=begin(); element!=end(); ++element )
4950  element->value() *= scalar;
4951  return *this;
4952 }
4954 //*************************************************************************************************
4955 
4956 
4957 //*************************************************************************************************
4966 template< typename MT > // Type of the sparse matrix
4967 inline size_t SparseColumn<MT,false,true>::extendCapacity() const
4968 {
4969  using blaze::max;
4970  using blaze::min;
4971 
4972  size_t nonzeros( 2UL*capacity()+1UL );
4973  nonzeros = max( nonzeros, 7UL );
4974  nonzeros = min( nonzeros, size() );
4975 
4976  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
4977 
4978  return nonzeros;
4979 }
4981 //*************************************************************************************************
4982 
4983 
4984 
4985 
4986 //=================================================================================================
4987 //
4988 // LOOKUP FUNCTIONS
4989 //
4990 //=================================================================================================
4991 
4992 //*************************************************************************************************
5006 template< typename MT > // Type of the sparse matrix
5008  SparseColumn<MT,false,true>::find( size_t index )
5009 {
5010  return matrix_.find( col_, index );
5011 }
5013 //*************************************************************************************************
5014 
5015 
5016 //*************************************************************************************************
5030 template< typename MT > // Type of the sparse matrix
5032  SparseColumn<MT,false,true>::find( size_t index ) const
5033 {
5034  return matrix_.find( col_, index );
5035 }
5037 //*************************************************************************************************
5038 
5039 
5040 //*************************************************************************************************
5053 template< typename MT > // Type of the sparse matrix
5056 {
5057  return matrix_.lowerBound( col_, index );
5058 }
5060 //*************************************************************************************************
5061 
5062 
5063 //*************************************************************************************************
5076 template< typename MT > // Type of the sparse matrix
5078  SparseColumn<MT,false,true>::lowerBound( size_t index ) const
5079 {
5080  return matrix_.lowerBound( col_, index );
5081 }
5083 //*************************************************************************************************
5084 
5085 
5086 //*************************************************************************************************
5099 template< typename MT > // Type of the sparse matrix
5102 {
5103  return matrix_.upperBound( col_, index );
5104 }
5106 //*************************************************************************************************
5107 
5108 
5109 //*************************************************************************************************
5122 template< typename MT > // Type of the sparse matrix
5124  SparseColumn<MT,false,true>::upperBound( size_t index ) const
5125 {
5126  return matrix_.upperBound( col_, index );
5127 }
5129 //*************************************************************************************************
5130 
5131 
5132 
5133 
5134 //=================================================================================================
5135 //
5136 // LOW-LEVEL UTILITY FUNCTIONS
5137 //
5138 //=================================================================================================
5139 
5140 //*************************************************************************************************
5165 template< typename MT > // Type of the sparse matrix
5166 inline void SparseColumn<MT,false,true>::append( size_t index, const ElementType& value, bool check )
5167 {
5168  matrix_.append( col_, index, value, check );
5169 }
5171 //*************************************************************************************************
5172 
5173 
5174 
5175 
5176 //=================================================================================================
5177 //
5178 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
5179 //
5180 //=================================================================================================
5181 
5182 //*************************************************************************************************
5193 template< typename MT > // Type of the sparse matrix
5194 template< typename Other > // Data type of the foreign expression
5195 inline bool SparseColumn<MT,false,true>::canAlias( const Other* alias ) const
5196 {
5197  return matrix_.isAliased( alias );
5198 }
5200 //*************************************************************************************************
5201 
5202 
5203 //*************************************************************************************************
5214 template< typename MT > // Type of the sparse matrix
5215 template< typename Other > // Data type of the foreign expression
5216 inline bool SparseColumn<MT,false,true>::isAliased( const Other* alias ) const
5217 {
5218  return matrix_.isAliased( alias );
5219 }
5221 //*************************************************************************************************
5222 
5223 
5224 //*************************************************************************************************
5236 template< typename MT > // Type of the sparse matrix
5237 template< typename VT > // Type of the right-hand side dense vector
5238 inline void SparseColumn<MT,false,true>::assign( const DenseVector<VT,false>& rhs )
5239 {
5240  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5241  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5242 
5243  for( size_t i=0UL; i<size(); ++i )
5244  {
5245  if( matrix_.nonZeros( col_ ) == matrix_.capacity( col_ ) )
5246  matrix_.reserve( col_, extendCapacity() );
5247 
5248  matrix_.append( col_, i, (~rhs)[i], true );
5249  }
5250 }
5252 //*************************************************************************************************
5253 
5254 
5255 //*************************************************************************************************
5267 template< typename MT > // Type of the sparse matrix
5268 template< typename VT > // Type of the right-hand side sparse vector
5269 inline void SparseColumn<MT,false,true>::assign( const SparseVector<VT,false>& rhs )
5270 {
5271  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5272  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
5273 
5274  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
5275  matrix_.append( col_, element->index(), element->value(), true );
5276  }
5277 }
5279 //*************************************************************************************************
5280 
5281 
5282 //*************************************************************************************************
5294 template< typename MT > // Type of the sparse matrix
5295 template< typename VT > // Type of the right-hand side dense vector
5296 inline void SparseColumn<MT,false,true>::addAssign( const DenseVector<VT,false>& rhs )
5297 {
5298  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
5299 
5303 
5304  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5305 
5306  const AddType tmp( serial( *this + (~rhs) ) );
5307  matrix_.reset( col_ );
5308  assign( tmp );
5309 }
5311 //*************************************************************************************************
5312 
5313 
5314 //*************************************************************************************************
5326 template< typename MT > // Type of the sparse matrix
5327 template< typename VT > // Type of the right-hand side sparse vector
5328 inline void SparseColumn<MT,false,true>::addAssign( const SparseVector<VT,false>& rhs )
5329 {
5330  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
5331 
5335 
5336  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5337 
5338  const AddType tmp( serial( *this + (~rhs) ) );
5339  matrix_.reset( col_ );
5340  matrix_.reserve( col_, tmp.nonZeros() );
5341  assign( tmp );
5342 }
5344 //*************************************************************************************************
5345 
5346 
5347 //*************************************************************************************************
5359 template< typename MT > // Type of the sparse matrix
5360 template< typename VT > // Type of the right-hand side dense vector
5361 inline void SparseColumn<MT,false,true>::subAssign( const DenseVector<VT,false>& rhs )
5362 {
5363  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
5364 
5368 
5369  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5370 
5371  const SubType tmp( serial( *this - (~rhs) ) );
5372  matrix_.reset( col_ );
5373  assign( tmp );
5374 }
5376 //*************************************************************************************************
5377 
5378 
5379 //*************************************************************************************************
5391 template< typename MT > // Type of the sparse matrix
5392 template< typename VT > // Type of the right-hand side sparse vector
5393 inline void SparseColumn<MT,false,true>::subAssign( const SparseVector<VT,false>& rhs )
5394 {
5395  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
5396 
5400 
5401  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
5402 
5403  const SubType tmp( serial( *this - (~rhs) ) );
5404  matrix_.reset( col_ );
5405  matrix_.reserve( col_, tmp.nonZeros() );
5406  assign( tmp );
5407 }
5409 //*************************************************************************************************
5410 
5411 
5412 
5413 
5414 
5415 
5416 
5417 
5418 //=================================================================================================
5419 //
5420 // SPARSECOLUMN OPERATORS
5421 //
5422 //=================================================================================================
5423 
5424 //*************************************************************************************************
5427 template< typename MT, bool SO, bool SF >
5428 inline void reset( SparseColumn<MT,SO,SF>& column );
5429 
5430 template< typename MT, bool SO, bool SF >
5431 inline void clear( SparseColumn<MT,SO,SF>& column );
5432 
5433 template< typename MT, bool SO, bool SF >
5434 inline bool isDefault( const SparseColumn<MT,SO,SF>& column );
5435 
5436 template< typename MT, bool SO, bool SF >
5437 inline bool isIntact( const SparseColumn<MT,SO,SF>& column );
5438 
5439 template< typename MT, bool SO, bool SF >
5440 inline bool isSame( const SparseColumn<MT,SO,SF>& a, const SparseColumn<MT,SO,SF>& b );
5442 //*************************************************************************************************
5443 
5444 
5445 //*************************************************************************************************
5452 template< typename MT // Type of the sparse matrix
5453  , bool SO // Storage order
5454  , bool SF > // Symmetry flag
5455 inline void reset( SparseColumn<MT,SO,SF>& column )
5456 {
5457  column.reset();
5458 }
5459 //*************************************************************************************************
5460 
5461 
5462 //*************************************************************************************************
5471 template< typename MT // Type of the sparse matrix
5472  , bool SO // Storage order
5473  , bool SF > // Symmetry flag
5474 inline void clear( SparseColumn<MT,SO,SF>& column )
5475 {
5476  column.reset();
5477 }
5478 //*************************************************************************************************
5479 
5480 
5481 //*************************************************************************************************
5499 template< typename MT // Type of the sparse matrix
5500  , bool SO // Storage order
5501  , bool SF > // Symmetry flag
5502 inline bool isDefault( const SparseColumn<MT,SO,SF>& column )
5503 {
5505 
5506  const ConstIterator end( column.end() );
5507  for( ConstIterator element=column.begin(); element!=end; ++element )
5508  if( !isDefault( element->value() ) ) return false;
5509  return true;
5510 }
5511 //*************************************************************************************************
5512 
5513 
5514 //*************************************************************************************************
5532 template< typename MT // Type of the sparse matrix
5533  , bool SO // Storage order
5534  , bool SF > // Symmetry flag
5535 inline bool isIntact( const SparseColumn<MT,SO,SF>& column )
5536 {
5537  return ( column.col_ <= column.matrix_.columns() &&
5538  isIntact( column.matrix_ ) );
5539 }
5540 //*************************************************************************************************
5541 
5542 
5543 //*************************************************************************************************
5555 template< typename MT // Type of the sparse matrix
5556  , bool SO // Storage order
5557  , bool SF > // Symmetry flag
5558 inline bool isSame( const SparseColumn<MT,SO,SF>& a, const SparseColumn<MT,SO,SF>& b )
5559 {
5560  return ( isSame( a.matrix_, b.matrix_ ) && ( a.col_ == b.col_ ) );
5561 }
5562 //*************************************************************************************************
5563 
5564 
5565 //*************************************************************************************************
5580 template< typename MT // Type of the sparse matrix
5581  , bool SO // Storage order
5582  , bool SF // Symmetry flag
5583  , typename VT > // Type of the right-hand side vector
5584 inline bool tryAssign( const SparseColumn<MT,SO,SF>& lhs, const Vector<VT,false>& rhs, size_t index )
5585 {
5586  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5587  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5588 
5589  return tryAssign( lhs.matrix_, ~rhs, index, lhs.col_ );
5590 }
5592 //*************************************************************************************************
5593 
5594 
5595 //*************************************************************************************************
5610 template< typename MT // Type of the sparse matrix
5611  , bool SO // Storage order
5612  , bool SF // Symmetry flag
5613  , typename VT > // Type of the right-hand side vector
5614 inline bool tryAddAssign( const SparseColumn<MT,SO,SF>& lhs, const Vector<VT,false>& rhs, size_t index )
5615 {
5616  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5617  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5618 
5619  return tryAddAssign( lhs.matrix_, ~rhs, index, lhs.col_ );
5620 }
5622 //*************************************************************************************************
5623 
5624 
5625 //*************************************************************************************************
5640 template< typename MT // Type of the sparse matrix
5641  , bool SO // Storage order
5642  , bool SF // Symmetry flag
5643  , typename VT > // Type of the right-hand side vector
5644 inline bool trySubAssign( const SparseColumn<MT,SO,SF>& lhs, const Vector<VT,false>& rhs, size_t index )
5645 {
5646  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5647  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5648 
5649  return trySubAssign( lhs.matrix_, ~rhs, index, lhs.col_ );
5650 }
5652 //*************************************************************************************************
5653 
5654 
5655 //*************************************************************************************************
5670 template< typename MT // Type of the sparse matrix
5671  , bool SO // Storage order
5672  , bool SF // Symmetry flag
5673  , typename VT > // Type of the right-hand side vector
5674 inline bool tryMultAssign( const SparseColumn<MT,SO,SF>& lhs, const Vector<VT,false>& rhs, size_t index )
5675 {
5676  BLAZE_INTERNAL_ASSERT( index <= lhs.size(), "Invalid vector access index" );
5677  BLAZE_INTERNAL_ASSERT( (~rhs).size() <= lhs.size() - index, "Invalid vector size" );
5678 
5679  return tryMultAssign( lhs.matrix_, ~rhs, index, lhs.col_ );
5680 }
5682 //*************************************************************************************************
5683 
5684 
5685 //*************************************************************************************************
5700 template< typename MT // Type of the sparse matrix
5701  , bool SO // Storage order
5702  , bool SF > // Symmetry flag
5703 inline typename DerestrictTrait< SparseColumn<MT,SO,SF> >::Type
5704  derestrict( SparseColumn<MT,SO,SF>& column )
5705 {
5706  typedef typename DerestrictTrait< SparseColumn<MT,SO,SF> >::Type ReturnType;
5707  return ReturnType( derestrict( column.matrix_ ), column.col_ );
5708 }
5710 //*************************************************************************************************
5711 
5712 
5713 
5714 
5715 //=================================================================================================
5716 //
5717 // ISRESTRICTED SPECIALIZATIONS
5718 //
5719 //=================================================================================================
5720 
5721 //*************************************************************************************************
5723 template< typename MT, bool SO, bool SF >
5724 struct IsRestricted< SparseColumn<MT,SO,SF> > : public IsTrue< IsRestricted<MT>::value >
5725 {};
5727 //*************************************************************************************************
5728 
5729 
5730 
5731 
5732 //=================================================================================================
5733 //
5734 // DERESTRICTTRAIT SPECIALIZATIONS
5735 //
5736 //=================================================================================================
5737 
5738 //*************************************************************************************************
5740 template< typename MT, bool SO, bool SF >
5741 struct DerestrictTrait< SparseColumn<MT,SO,SF> >
5742 {
5743  typedef SparseColumn< typename RemoveReference< typename DerestrictTrait<MT>::Type >::Type > Type;
5744 };
5746 //*************************************************************************************************
5747 
5748 
5749 
5750 
5751 //=================================================================================================
5752 //
5753 // ADDTRAIT SPECIALIZATIONS
5754 //
5755 //=================================================================================================
5756 
5757 //*************************************************************************************************
5759 template< typename MT, bool SO, bool SF, typename T >
5760 struct AddTrait< SparseColumn<MT,SO,SF>, T >
5761 {
5762  typedef typename AddTrait< typename ColumnTrait<MT>::Type, T >::Type Type;
5763 };
5764 
5765 template< typename T, typename MT, bool SO, bool SF >
5766 struct AddTrait< T, SparseColumn<MT,SO,SF> >
5767 {
5768  typedef typename AddTrait< T, typename ColumnTrait<MT>::Type >::Type Type;
5769 };
5771 //*************************************************************************************************
5772 
5773 
5774 
5775 
5776 //=================================================================================================
5777 //
5778 // SUBTRAIT SPECIALIZATIONS
5779 //
5780 //=================================================================================================
5781 
5782 //*************************************************************************************************
5784 template< typename MT, bool SO, bool SF, typename T >
5785 struct SubTrait< SparseColumn<MT,SO,SF>, T >
5786 {
5787  typedef typename SubTrait< typename ColumnTrait<MT>::Type, T >::Type Type;
5788 };
5789 
5790 template< typename T, typename MT, bool SO, bool SF >
5791 struct SubTrait< T, SparseColumn<MT,SO,SF> >
5792 {
5793  typedef typename SubTrait< T, typename ColumnTrait<MT>::Type >::Type Type;
5794 };
5796 //*************************************************************************************************
5797 
5798 
5799 
5800 
5801 //=================================================================================================
5802 //
5803 // MULTTRAIT SPECIALIZATIONS
5804 //
5805 //=================================================================================================
5806 
5807 //*************************************************************************************************
5809 template< typename MT, bool SO, bool SF, typename T >
5810 struct MultTrait< SparseColumn<MT,SO,SF>, T >
5811 {
5812  typedef typename MultTrait< typename ColumnTrait<MT>::Type, T >::Type Type;
5813 };
5814 
5815 template< typename T, typename MT, bool SO, bool SF >
5816 struct MultTrait< T, SparseColumn<MT,SO,SF> >
5817 {
5818  typedef typename MultTrait< T, typename ColumnTrait<MT>::Type >::Type Type;
5819 };
5821 //*************************************************************************************************
5822 
5823 
5824 
5825 
5826 //=================================================================================================
5827 //
5828 // CROSSTRAIT SPECIALIZATIONS
5829 //
5830 //=================================================================================================
5831 
5832 //*************************************************************************************************
5834 template< typename MT, bool SO, bool SF, typename T >
5835 struct CrossTrait< SparseColumn<MT,SO,SF>, T >
5836 {
5837  typedef typename CrossTrait< typename ColumnTrait<MT>::Type, T >::Type Type;
5838 };
5839 
5840 template< typename T, typename MT, bool SO, bool SF >
5841 struct CrossTrait< T, SparseColumn<MT,SO,SF> >
5842 {
5843  typedef typename CrossTrait< T, typename ColumnTrait<MT>::Type >::Type Type;
5844 };
5846 //*************************************************************************************************
5847 
5848 
5849 
5850 
5851 //=================================================================================================
5852 //
5853 // DIVTRAIT SPECIALIZATIONS
5854 //
5855 //=================================================================================================
5856 
5857 //*************************************************************************************************
5859 template< typename MT, bool SO, bool SF, typename T >
5860 struct DivTrait< SparseColumn<MT,SO,SF>, T >
5861 {
5862  typedef typename DivTrait< typename ColumnTrait<MT>::Type, T >::Type Type;
5863 };
5864 
5865 template< typename T, typename MT, bool SO, bool SF >
5866 struct DivTrait< T, SparseColumn<MT,SO,SF> >
5867 {
5868  typedef typename DivTrait< T, typename ColumnTrait<MT>::Type >::Type Type;
5869 };
5871 //*************************************************************************************************
5872 
5873 
5874 
5875 
5876 //=================================================================================================
5877 //
5878 // SUBVECTORTRAIT SPECIALIZATIONS
5879 //
5880 //=================================================================================================
5881 
5882 //*************************************************************************************************
5884 template< typename MT, bool SO, bool SF >
5885 struct SubvectorTrait< SparseColumn<MT,SO,SF> >
5886 {
5888 };
5890 //*************************************************************************************************
5891 
5892 } // namespace blaze
5893 
5894 #endif
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseColumn.h:1688
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exceptionThis macro encapsulates the default way of...
Definition: Exception.h:187
Constraint on the data type.
bool canAlias(const Other *alias) const
Returns whether the sparse column can alias with the given address alias.
Definition: SparseColumn.h:1782
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Compile time check for numeric types.This type trait tests whether or not the given template paramete...
Definition: IsNumeric.h:98
Header file for mathematical functions.
ConstIterator cbegin() const
Returns an iterator to the first element of the column.
Definition: SparseColumn.h:737
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the UNUSED_PARAMETER function template.
Header file for the IsUniUpper type trait.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:7820
Header file for the subtraction trait.
Header file for basic type definitions.
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse column.
Definition: SparseColumn.h:1439
Iterator find(size_t index)
Searches for a specific column element.
Definition: SparseColumn.h:1597
Header file for the SparseVector base class.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
void subAssign(const DenseVector< VT, false > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseColumn.h:1948
BLAZE_ALWAYS_INLINE MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:250
Base template for the ColumnTrait class.
Definition: ColumnTrait.h:115
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a column dense or sparse vector type...
Definition: ColumnVector.h:79
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:207
Header file for the IsDiagonal type trait.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_COMPUTATION_TYPE(T)
Constraint on the data type.In case the given data type T is a computational expression (i...
Definition: Computation.h:118
BLAZE_ALWAYS_INLINE bool isSame(const Matrix< MT1, SO1 > &a, const Matrix< MT2, SO2 > &b)
Returns whether the two given matrices represent the same observable state.
Definition: Matrix.h:647
void reserve(size_t n)
Setting the minimum capacity of the sparse column.
Definition: SparseColumn.h:1514
size_t capacity() const
Returns the maximum capacity of the sparse column.
Definition: SparseColumn.h:1361
Header file for the IsColumnMajorMatrix type trait.
void reset(const DiagonalProxy< MT > &proxy)
Resetting the represented element to the default initial values.
Definition: DiagonalProxy.h:507
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2588
BLAZE_ALWAYS_INLINE size_t capacity(const Matrix< MT, SO > &matrix)
Returns the maximum capacity of the matrix.
Definition: Matrix.h:340
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:107
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:81
Header file for the And class template.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_UNITRIANGULAR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a lower or upper unitriangular matrix ty...
Definition: UniTriangular.h:118
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseColumn.h:397
const DMatSerialExpr< MT, SO > serial(const DenseMatrix< MT, SO > &dm)
Forces the serial evaluation of the given dense matrix expression dm.
Definition: DMatSerialExpr.h:721
BLAZE_ALWAYS_INLINE size_t nonZeros(const Matrix< MT, SO > &matrix)
Returns the total number of non-zero elements in the matrix.
Definition: Matrix.h:378
#define BLAZE_CONSTRAINT_MUST_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a symmetric matrix type...
Definition: Symmetric.h:78
Constraints on the storage order of matrix types.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_TRANSEXPR_TYPE(T)
Constraint on the data type.In case the given data type T is a transposition expression (i...
Definition: TransExpr.h:118
Header file for the IsUniLower type trait.
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse column.
Definition: SparseColumn.h:1753
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:547
Constraint on the data type.
If< IsConst< MT >, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant column value.
Definition: SparseColumn.h:394
Header file for the column base class.
Constraint on the transpose flag of vector types.
const size_t col_
The index of the column in the matrix.
Definition: SparseColumn.h:522
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseColumn.h:385
Constraint on the data type.
ConstIterator cend() const
Returns an iterator just past the last element of the column.
Definition: SparseColumn.h:788
Header file for the DisableIf class template.
Header file for the multiplication trait.
Header file for the IsStrictlyUpper type trait.
Header file for the IsSymmetric type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
#define BLAZE_CONSTRAINT_MUST_BE_COLUMN_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a column-major dense or sparse matri...
Definition: ColumnMajorMatrix.h:79
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseColumn.h:1643
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2592
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Header file for the Or class template.
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exceptionThis macro encapsulates the default way of Bla...
Definition: Exception.h:331
const MT::ElementType min(const DenseMatrix< MT, SO > &dm)
Returns the smallest element of the dense matrix.
Definition: DenseMatrix.h:1682
Iterator set(size_t index, const ElementType &value)
Setting an element of the sparse column.
Definition: SparseColumn.h:1416
Base class for all columns.The Column class serves as a tag for all columns (i.e. dense and sparse co...
Definition: Column.h:64
ColumnTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseColumn.h:384
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
Header file for the IsLower type trait.
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:642
Header file for the SparseElement base class.
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseColumn.h:387
Constraint on the data type.
void reset()
Reset to the default initial values.
Definition: SparseColumn.h:1394
void erase(size_t index)
Erasing an element from the sparse column.
Definition: SparseColumn.h:1457
Constraint on the data type.
If< IsConst< MT >, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseColumn.h:400
void assign(const DenseVector< VT, false > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseColumn.h:1825
BLAZE_ALWAYS_INLINE MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:187
Compile time check for floating point data types.This type trait tests whether or not the given templ...
Definition: IsFloatingPoint.h:94
Type ElementType
Type of the sparse matrix elements.
Definition: CompressedMatrix.h:2586
size_t nonZeros() const
Returns the number of non-zero elements in the column.
Definition: SparseColumn.h:1379
Constraint on the data type.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2590
const SparseColumn & CompositeType
Data type for composite expression templates.
Definition: SparseColumn.h:388
Header file for the EnableIf class template.
Header file for the IsStrictlyLower type trait.
void clear(const DiagonalProxy< MT > &proxy)
Clearing the represented element.
Definition: DiagonalProxy.h:527
Header file for the serial shim.
bool isAliased(const Other *alias) const
Returns whether the sparse column is aliased with the given address alias.
Definition: SparseColumn.h:1803
Header file for the DerestrictTrait class template.
Constraint on the data type.
Header file for the IsNumeric type trait.
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:107
#define BLAZE_CONSTRAINT_MUST_NOT_BE_SYMMETRIC_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is a symmetric matrix type, a compilation error is created.
Definition: Symmetric.h:116
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: RowMajorMatrix.h:79
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2587
Header file for the IsConst type trait.
MT::ElementType ElementType
Type of the column elements.
Definition: SparseColumn.h:386
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:138
Base template for the MultTrait class.
Definition: MultTrait.h:138
Header file for the addition trait.
Header file for the cross product trait.
Header file for the division trait.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the reset shim.
SparseColumn & operator=(const SparseColumn &rhs)
Copy assignment operator for SparseColumn.
Definition: SparseColumn.h:819
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2591
Header file for the column trait.
Header file for the isDefault shim.
Constraint on the data type.
Reference at(size_t index)
Checked access to the column elements.
Definition: SparseColumn.h:659
Constraint on the data type.
Constraints on the storage order of matrix types.
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
#define BLAZE_CONSTRAINT_MUST_NOT_REQUIRE_EVALUATION(T)
Constraint on the data type.In case the given data type T requires an intermediate evaluation within ...
Definition: RequiresEvaluation.h:118
Evaluation of the return type of the derestrict function.Via this type trait it is possible to evalua...
Definition: DerestrictTrait.h:74
Header file for the IsReference type trait.
Header file for the RemoveReference type trait.
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
Base template for the DivTrait class.
Definition: DivTrait.h:138
#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
void addAssign(const DenseVector< VT, false > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseColumn.h:1883
Iterator end()
Returns an iterator just past the last element of the column.
Definition: SparseColumn.h:754
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:164
Iterator begin()
Returns an iterator to the first element of the column.
Definition: SparseColumn.h:703
Reference operator[](size_t index)
Subscript operator for the direct access to the column elements.
Definition: SparseColumn.h:616
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:258
If< IsExpression< MT >, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseColumn.h:378
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:118
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
This ResultType
Result type for expression template evaluations.
Definition: CompressedMatrix.h:2583
Header file for the IsTrue value trait.
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
size_t extendCapacity() const
Calculating a new sparse column capacity.
Definition: SparseColumn.h:1557
Compile time type check.This class tests whether the given template parameter T is a reference type (...
Definition: IsReference.h:94
bool isIntact(const DiagonalMatrix< MT, SO, DF > &m)
Returns whether the invariants of the given diagonal matrix are intact.
Definition: DiagonalMatrix.h:237
SparseColumn< MT, SO, SF > This
Type of this SparseColumn instance.
Definition: SparseColumn.h:383
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2589
Base template for the SubTrait class.
Definition: SubTrait.h:138
Header file for the IsUpper type trait.
Header file for exception macros.
Header file for the IsRestricted type trait.
#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
#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
Reference to a specific column of a sparse matrix.The SparseColumn template represents a reference to...
Definition: Forward.h:51
MT::ConstReference ConstReference
Reference to a constant column value.
Definition: SparseColumn.h:391
Operand matrix_
The sparse matrix containing the column.
Definition: SparseColumn.h:521
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.
size_t size() const
Returns the current size/dimension of the sparse column.
Definition: SparseColumn.h:1346
SparseColumn(MT &matrix, size_t index)
The constructor for SparseColumn.
Definition: SparseColumn.h:584
Header file for a safe C++ NULL pointer implementation.