All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
44 #include <stdexcept>
55 #include <blaze/math/Functions.h>
57 #include <blaze/math/shims/Reset.h>
66 #include <blaze/util/Assert.h>
67 #include <blaze/util/DisableIf.h>
68 #include <blaze/util/EnableIf.h>
70 #include <blaze/util/mpl/If.h>
71 #include <blaze/util/mpl/Or.h>
72 #include <blaze/util/SelectType.h>
73 #include <blaze/util/Types.h>
77 #include <blaze/util/Unused.h>
78 
79 
80 namespace blaze {
81 
82 //=================================================================================================
83 //
84 // CLASS DEFINITION
85 //
86 //=================================================================================================
87 
88 //*************************************************************************************************
338 template< typename MT // Type of the sparse matrix
339  , bool SO = IsColumnMajorMatrix<MT>::value > // Storage order
340 class SparseColumn : public SparseVector< SparseColumn<MT,SO>, false >
341  , private Column
342 {
343  private:
344  //**Type definitions****************************************************************************
346  typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type Operand;
347  //**********************************************************************************************
348 
349  //**********************************************************************************************
351 
357  enum { useConst = IsConst<MT>::value };
358  //**********************************************************************************************
359 
360  public:
361  //**Type definitions****************************************************************************
365  typedef typename MT::ElementType ElementType;
366  typedef typename MT::ReturnType ReturnType;
367  typedef const SparseColumn& CompositeType;
368 
371 
374 
377 
380  //**********************************************************************************************
381 
382  //**Compilation flags***************************************************************************
384  enum { smpAssignable = 0 };
385  //**********************************************************************************************
386 
387  //**Constructors********************************************************************************
390  explicit inline SparseColumn( MT& matrix, size_t index );
391  // No explicitly declared copy constructor.
393  //**********************************************************************************************
394 
395  //**Destructor**********************************************************************************
396  // No explicitly declared destructor.
397  //**********************************************************************************************
398 
399  //**Data access functions***********************************************************************
402  inline Reference operator[]( size_t index );
403  inline ConstReference operator[]( size_t index ) const;
404  inline Iterator begin ();
405  inline ConstIterator begin () const;
406  inline ConstIterator cbegin() const;
407  inline Iterator end ();
408  inline ConstIterator end () const;
409  inline ConstIterator cend () const;
411  //**********************************************************************************************
412 
413  //**Assignment operators************************************************************************
416  inline SparseColumn& operator= ( const SparseColumn& rhs );
417  template< typename VT > inline SparseColumn& operator= ( const DenseVector <VT,false>& rhs );
418  template< typename VT > inline SparseColumn& operator= ( const SparseVector<VT,false>& rhs );
419  template< typename VT > inline SparseColumn& operator+=( const Vector<VT,false>& rhs );
420  template< typename VT > inline SparseColumn& operator-=( const Vector<VT,false>& rhs );
421  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
422 
423  template< typename Other >
424  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
425  operator*=( Other rhs );
426 
427  template< typename Other >
428  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
429  operator/=( Other rhs );
431  //**********************************************************************************************
432 
433  //**Utility functions***************************************************************************
436  inline size_t size() const;
437  inline size_t capacity() const;
438  inline size_t nonZeros() const;
439  inline void reset();
440  inline Iterator insert ( size_t index, const ElementType& value );
441  inline void erase ( size_t index );
442  inline Iterator erase ( Iterator pos );
443  inline Iterator erase ( Iterator first, Iterator last );
444  inline void reserve( size_t n );
445  template< typename Other > inline SparseColumn& scale ( Other scalar );
447  //**********************************************************************************************
448 
449  //**Lookup functions****************************************************************************
452  inline Iterator find ( size_t index );
453  inline ConstIterator find ( size_t index ) const;
454  inline Iterator lowerBound( size_t index );
455  inline ConstIterator lowerBound( size_t index ) const;
456  inline Iterator upperBound( size_t index );
457  inline ConstIterator upperBound( size_t index ) const;
459  //**********************************************************************************************
460 
461  //**Low-level utility functions*****************************************************************
464  inline void append( size_t index, const ElementType& value, bool check=false );
466  //**********************************************************************************************
467 
468  //**Expression template evaluation functions****************************************************
471  template< typename Other > inline bool canAlias ( const Other* alias ) const;
472  template< typename Other > inline bool isAliased( const Other* alias ) const;
473  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
474  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
475  template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
476  template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
477  template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
478  template< typename VT > inline void subAssign( const SparseVector<VT,false>& rhs );
480  //**********************************************************************************************
481 
482  private:
483  //**Utility functions***************************************************************************
486  inline size_t extendCapacity() const;
488  //**********************************************************************************************
489 
490  //**Member variables****************************************************************************
494  const size_t col_;
495 
496  //**********************************************************************************************
497 
498  //**Compile time checks*************************************************************************
505  //**********************************************************************************************
506 };
507 //*************************************************************************************************
508 
509 
510 
511 
512 //=================================================================================================
513 //
514 // CONSTRUCTOR
515 //
516 //=================================================================================================
517 
518 //*************************************************************************************************
525 template< typename MT // Type of the sparse matrix
526  , bool SO > // Storage order
527 inline SparseColumn<MT,SO>::SparseColumn( MT& matrix, size_t index )
528  : matrix_( matrix ) // The sparse matrix containing the column
529  , col_ ( index ) // The index of the column in the matrix
530 {
531  if( matrix_.columns() <= index )
532  throw std::invalid_argument( "Invalid column access index" );
533 }
534 //*************************************************************************************************
535 
536 
537 
538 
539 //=================================================================================================
540 //
541 // DATA ACCESS FUNCTIONS
542 //
543 //=================================================================================================
544 
545 //*************************************************************************************************
551 template< typename MT // Type of the sparse matrix
552  , bool SO > // Storage order
554 {
555  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
556  return matrix_(index,col_);
557 }
558 //*************************************************************************************************
559 
560 
561 //*************************************************************************************************
567 template< typename MT // Type of the sparse matrix
568  , bool SO > // Storage order
570 {
571  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
572  return const_cast<const MT&>( matrix_ )(index,col_);
573 }
574 //*************************************************************************************************
575 
576 
577 //*************************************************************************************************
584 template< typename MT // Type of the sparse matrix
585  , bool SO > // Storage order
587 {
588  return matrix_.begin( col_ );
589 }
590 //*************************************************************************************************
591 
592 
593 //*************************************************************************************************
600 template< typename MT // Type of the sparse matrix
601  , bool SO > // Storage order
603 {
604  return matrix_.cbegin( col_ );
605 }
606 //*************************************************************************************************
607 
608 
609 //*************************************************************************************************
616 template< typename MT // Type of the sparse matrix
617  , bool SO > // Storage order
619 {
620  return matrix_.cbegin( col_ );
621 }
622 //*************************************************************************************************
623 
624 
625 //*************************************************************************************************
632 template< typename MT // Type of the sparse matrix
633  , bool SO > // Storage order
635 {
636  return matrix_.end( col_ );
637 }
638 //*************************************************************************************************
639 
640 
641 //*************************************************************************************************
648 template< typename MT // Type of the sparse matrix
649  , bool SO > // Storage order
651 {
652  return matrix_.cend( col_ );
653 }
654 //*************************************************************************************************
655 
656 
657 //*************************************************************************************************
664 template< typename MT // Type of the sparse matrix
665  , bool SO > // Storage order
667 {
668  return matrix_.cend( col_ );
669 }
670 //*************************************************************************************************
671 
672 
673 
674 
675 //=================================================================================================
676 //
677 // ASSIGNMENT OPERATORS
678 //
679 //=================================================================================================
680 
681 //*************************************************************************************************
691 template< typename MT // Type of the sparse matrix
692  , bool SO > // Storage order
694 {
695  using blaze::assign;
696 
700 
701  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
702  return *this;
703 
704  if( size() != rhs.size() )
705  throw std::invalid_argument( "Column sizes do not match" );
706 
707  if( rhs.canAlias( &matrix_ ) ) {
708  const ResultType tmp( rhs );
709  matrix_.reset ( col_ );
710  matrix_.reserve( col_, tmp.nonZeros() );
711  assign( *this, tmp );
712  }
713  else {
714  matrix_.reset ( col_ );
715  matrix_.reserve( col_, rhs.nonZeros() );
716  assign( *this, rhs );
717  }
718 
719  return *this;
720 }
721 //*************************************************************************************************
722 
723 
724 //*************************************************************************************************
734 template< typename MT // Type of the sparse matrix
735  , bool SO > // Storage order
736 template< typename VT > // Type of the right-hand side dense vector
738 {
739  using blaze::assign;
740 
744 
745  if( size() != (~rhs).size() )
746  throw std::invalid_argument( "Vector sizes do not match" );
747 
748  if( (~rhs).canAlias( &matrix_ ) ) {
749  const typename VT::ResultType tmp( ~rhs );
750  matrix_.reset( col_ );
751  assign( *this, tmp );
752  }
753  else {
754  matrix_.reset( col_ );
755  assign( *this, ~rhs );
756  }
757 
758  return *this;
759 }
760 //*************************************************************************************************
761 
762 
763 //*************************************************************************************************
773 template< typename MT // Type of the sparse matrix
774  , bool SO > // Storage order
775 template< typename VT > // Type of the right-hand side sparse vector
777 {
778  using blaze::assign;
779 
780  if( size() != (~rhs).size() )
781  throw std::invalid_argument( "Vector sizes do not match" );
782 
786 
787  if( (~rhs).canAlias( &matrix_ ) ) {
788  const typename VT::ResultType tmp( ~rhs );
789  matrix_.reset ( col_ );
790  matrix_.reserve( col_, tmp.nonZeros() );
791  assign( *this, tmp );
792  }
793  else {
794  matrix_.reset ( col_ );
795  matrix_.reserve( col_, (~rhs).nonZeros() );
796  assign( *this, ~rhs );
797  }
798 
799  return *this;
800 }
801 //*************************************************************************************************
802 
803 
804 //*************************************************************************************************
814 template< typename MT // Type of the sparse matrix
815  , bool SO > // Storage order
816 template< typename VT > // Type of the right-hand side vector
818 {
819  using blaze::addAssign;
820 
821  if( size() != (~rhs).size() )
822  throw std::invalid_argument( "Vector sizes do not match" );
823 
824  addAssign( *this, ~rhs );
825 
826  return *this;
827 }
828 //*************************************************************************************************
829 
830 
831 //*************************************************************************************************
841 template< typename MT // Type of the sparse matrix
842  , bool SO > // Storage order
843 template< typename VT > // Type of the right-hand side vector
845 {
846  using blaze::subAssign;
847 
848  if( size() != (~rhs).size() )
849  throw std::invalid_argument( "Vector sizes do not match" );
850 
851  subAssign( *this, ~rhs );
852 
853  return *this;
854 }
855 //*************************************************************************************************
856 
857 
858 //*************************************************************************************************
869 template< typename MT // Type of the sparse matrix
870  , bool SO > // Storage order
871 template< typename VT > // Type of the right-hand side vector
873 {
874  if( size() != (~rhs).size() )
875  throw std::invalid_argument( "Vector sizes do not match" );
876 
877  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
878 
881 
882  const MultType tmp( *this * (~rhs) );
883  matrix_.reset( col_ );
884  assign( tmp );
885 
886  return *this;
887 }
888 //*************************************************************************************************
889 
890 
891 //*************************************************************************************************
902 template< typename MT // Type of the sparse matrix
903  , bool SO > // Storage order
904 template< typename Other > // Data type of the right-hand side scalar
905 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO> >::Type&
907 {
908  for( Iterator element=begin(); element!=end(); ++element )
909  element->value() *= rhs;
910  return *this;
911 }
912 //*************************************************************************************************
913 
914 
915 //*************************************************************************************************
927 template< typename MT // Type of the sparse matrix
928  , bool SO > // Storage order
929 template< typename Other > // Data type of the right-hand side scalar
930 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO> >::Type&
932 {
933  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
934 
935  typedef typename DivTrait<ElementType,Other>::Type DT;
936  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
937 
938  // Depending on the two involved data types, an integer division is applied or a
939  // floating point division is selected.
941  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
942  for( Iterator element=begin(); element!=end(); ++element )
943  element->value() *= tmp;
944  }
945  else {
946  for( Iterator element=begin(); element!=end(); ++element )
947  element->value() /= rhs;
948  }
949 
950  return *this;
951 }
952 //*************************************************************************************************
953 
954 
955 
956 
957 //=================================================================================================
958 //
959 // UTILITY FUNCTIONS
960 //
961 //=================================================================================================
962 
963 //*************************************************************************************************
968 template< typename MT // Type of the sparse matrix
969  , bool SO > // Storage order
970 inline size_t SparseColumn<MT,SO>::size() const
971 {
972  return matrix_.rows();
973 }
974 //*************************************************************************************************
975 
976 
977 //*************************************************************************************************
982 template< typename MT // Type of the sparse matrix
983  , bool SO > // Storage order
984 inline size_t SparseColumn<MT,SO>::capacity() const
985 {
986  return matrix_.capacity( col_ );
987 }
988 //*************************************************************************************************
989 
990 
991 //*************************************************************************************************
999 template< typename MT // Type of the sparse matrix
1000  , bool SO > // Storage order
1001 inline size_t SparseColumn<MT,SO>::nonZeros() const
1002 {
1003  return matrix_.nonZeros( col_ );
1004 }
1005 //*************************************************************************************************
1006 
1007 
1008 //*************************************************************************************************
1013 template< typename MT // Type of the sparse matrix
1014  , bool SO > // Storage order
1016 {
1017  matrix_.reset( col_ );
1018 }
1019 //*************************************************************************************************
1020 
1021 
1022 //*************************************************************************************************
1034 template< typename MT // Type of the sparse matrix
1035  , bool SO > // Storage order
1036 inline typename SparseColumn<MT,SO>::Iterator
1037  SparseColumn<MT,SO>::insert( size_t index, const ElementType& value )
1038 {
1039  return matrix_.insert( index, col_, value );
1040 }
1041 //*************************************************************************************************
1042 
1043 
1044 //*************************************************************************************************
1052 template< typename MT // Type of the sparse matrix
1053  , bool SO > // Storage order
1054 inline void SparseColumn<MT,SO>::erase( size_t index )
1055 {
1056  matrix_.erase( index, col_ );
1057 }
1058 //*************************************************************************************************
1059 
1060 
1061 //*************************************************************************************************
1069 template< typename MT // Type of the sparse matrix
1070  , bool SO > // Storage order
1072 {
1073  return matrix_.erase( col_, pos );
1074 }
1075 //*************************************************************************************************
1076 
1077 
1078 //*************************************************************************************************
1087 template< typename MT // Type of the sparse matrix
1088  , bool SO > // Storage order
1090 {
1091  return matrix_.erase( col_, first, last );
1092 }
1093 //*************************************************************************************************
1094 
1095 
1096 //*************************************************************************************************
1105 template< typename MT // Type of the sparse matrix
1106  , bool SO > // Storage order
1108 {
1109  matrix_.reserve( col_, n );
1110 }
1111 //*************************************************************************************************
1112 
1113 
1114 //*************************************************************************************************
1120 template< typename MT // Type of the sparse matrix
1121  , bool SO > // Storage order
1122 template< typename Other > // Data type of the scalar value
1124 {
1125  for( Iterator element=begin(); element!=end(); ++element )
1126  element->value() *= scalar;
1127  return *this;
1128 }
1129 //*************************************************************************************************
1130 
1131 
1132 //*************************************************************************************************
1140 template< typename MT // Type of the sparse matrix
1141  , bool SO > // Storage order
1143 {
1144  using blaze::max;
1145  using blaze::min;
1146 
1147  size_t nonzeros( 2UL*capacity()+1UL );
1148  nonzeros = max( nonzeros, 7UL );
1149  nonzeros = min( nonzeros, size() );
1150 
1151  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1152 
1153  return nonzeros;
1154 }
1155 //*************************************************************************************************
1156 
1157 
1158 
1159 
1160 //=================================================================================================
1161 //
1162 // LOOKUP FUNCTIONS
1163 //
1164 //=================================================================================================
1165 
1166 //*************************************************************************************************
1179 template< typename MT // Type of the sparse matrix
1180  , bool SO > // Storage order
1182 {
1183  return matrix_.find( index, col_ );
1184 }
1185 //*************************************************************************************************
1186 
1187 
1188 //*************************************************************************************************
1201 template< typename MT // Type of the sparse matrix
1202  , bool SO > // Storage order
1204 {
1205  return matrix_.find( index, col_ );
1206 }
1207 //*************************************************************************************************
1208 
1209 
1210 //*************************************************************************************************
1222 template< typename MT // Type of the sparse matrix
1223  , bool SO > // Storage order
1225 {
1226  return matrix_.lowerBound( index, col_ );
1227 }
1228 //*************************************************************************************************
1229 
1230 
1231 //*************************************************************************************************
1243 template< typename MT // Type of the sparse matrix
1244  , bool SO > // Storage order
1246 {
1247  return matrix_.lowerBound( index, col_ );
1248 }
1249 //*************************************************************************************************
1250 
1251 
1252 //*************************************************************************************************
1264 template< typename MT // Type of the sparse matrix
1265  , bool SO > // Storage order
1267 {
1268  return matrix_.upperBound( index, col_ );
1269 }
1270 //*************************************************************************************************
1271 
1272 
1273 //*************************************************************************************************
1285 template< typename MT // Type of the sparse matrix
1286  , bool SO > // Storage order
1288 {
1289  return matrix_.upperBound( index, col_ );
1290 }
1291 //*************************************************************************************************
1292 
1293 
1294 
1295 
1296 //=================================================================================================
1297 //
1298 // LOW-LEVEL UTILITY FUNCTIONS
1299 //
1300 //=================================================================================================
1301 
1302 //*************************************************************************************************
1326 template< typename MT // Type of the sparse matrix
1327  , bool SO > // Storage order
1328 inline void SparseColumn<MT,SO>::append( size_t index, const ElementType& value, bool check )
1329 {
1330  matrix_.append( index, col_, value, check );
1331 }
1332 //*************************************************************************************************
1333 
1334 
1335 
1336 
1337 //=================================================================================================
1338 //
1339 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1340 //
1341 //=================================================================================================
1342 
1343 //*************************************************************************************************
1353 template< typename MT // Type of the sparse matrix
1354  , bool SO > // Storage order
1355 template< typename Other > // Data type of the foreign expression
1356 inline bool SparseColumn<MT,SO>::canAlias( const Other* alias ) const
1357 {
1358  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
1359 }
1360 //*************************************************************************************************
1361 
1362 
1363 //*************************************************************************************************
1373 template< typename MT // Type of the sparse matrix
1374  , bool SO > // Storage order
1375 template< typename Other > // Data type of the foreign expression
1376 inline bool SparseColumn<MT,SO>::isAliased( const Other* alias ) const
1377 {
1378  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
1379 }
1380 //*************************************************************************************************
1381 
1382 
1383 //*************************************************************************************************
1394 template< typename MT // Type of the sparse matrix
1395  , bool SO > // Storage order
1396 template< typename VT > // Type of the right-hand side dense vector
1398 {
1399  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1400  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1401 
1402  for( size_t i=0UL; i<size(); ++i )
1403  {
1404  if( matrix_.nonZeros( col_ ) == matrix_.capacity( col_ ) )
1405  matrix_.reserve( col_, extendCapacity() );
1406 
1407  matrix_.append( i, col_, (~rhs)[i], true );
1408  }
1409 }
1410 //*************************************************************************************************
1411 
1412 
1413 //*************************************************************************************************
1424 template< typename MT // Type of the sparse matrix
1425  , bool SO > // Storage order
1426 template< typename VT > // Type of the right-hand side sparse vector
1428 {
1429  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1430  BLAZE_INTERNAL_ASSERT( nonZeros() == 0UL, "Invalid non-zero elements detected" );
1431 
1432  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1433  matrix_.append( element->index(), col_, element->value() );
1434  }
1435 }
1436 //*************************************************************************************************
1437 
1438 
1439 //*************************************************************************************************
1450 template< typename MT // Type of the sparse matrix
1451  , bool SO > // Storage order
1452 template< typename VT > // Type of the right-hand side dense vector
1454 {
1455  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1456 
1460 
1461  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1462 
1463  const AddType tmp( *this + (~rhs) );
1464  matrix_.reset( col_ );
1465  assign( tmp );
1466 }
1467 //*************************************************************************************************
1468 
1469 
1470 //*************************************************************************************************
1481 template< typename MT // Type of the sparse matrix
1482  , bool SO > // Storage order
1483 template< typename VT > // Type of the right-hand side sparse vector
1485 {
1486  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
1487 
1491 
1492  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1493 
1494  const AddType tmp( *this + (~rhs) );
1495  matrix_.reset ( col_ );
1496  matrix_.reserve( col_, tmp.nonZeros() );
1497  assign( tmp );
1498 }
1499 //*************************************************************************************************
1500 
1501 
1502 //*************************************************************************************************
1513 template< typename MT // Type of the sparse matrix
1514  , bool SO > // Storage order
1515 template< typename VT > // Type of the right-hand side dense vector
1517 {
1518  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1519 
1523 
1524  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1525 
1526  const SubType tmp( *this - (~rhs) );
1527  matrix_.reset( col_ );
1528  assign( tmp );
1529 }
1530 //*************************************************************************************************
1531 
1532 
1533 //*************************************************************************************************
1544 template< typename MT // Type of the sparse matrix
1545  , bool SO > // Storage order
1546 template< typename VT > // Type of the right-hand side sparse vector
1548 {
1549  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
1550 
1554 
1555  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1556 
1557  const SubType tmp( *this - (~rhs) );
1558  matrix_.reset ( col_ );
1559  matrix_.reserve( col_, tmp.nonZeros() );
1560  assign( tmp );
1561 }
1562 //*************************************************************************************************
1563 
1564 
1565 
1566 
1567 
1568 
1569 
1570 
1571 //=================================================================================================
1572 //
1573 // CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR MATRICES
1574 //
1575 //=================================================================================================
1576 
1577 //*************************************************************************************************
1585 template< typename MT > // Type of the sparse matrix
1586 class SparseColumn<MT,false> : public SparseVector< SparseColumn<MT,false>, false >
1587  , private Column
1588 {
1589  private:
1590  //**Type definitions****************************************************************************
1592  typedef typename SelectType< IsExpression<MT>::value, MT, MT& >::Type Operand;
1593  //**********************************************************************************************
1594 
1595  //**********************************************************************************************
1597 
1603  enum { useConst = IsConst<MT>::value };
1604  //**********************************************************************************************
1605 
1606  public:
1607  //**Type definitions****************************************************************************
1608  typedef SparseColumn<MT,false> This;
1609  typedef typename ColumnTrait<MT>::Type ResultType;
1610  typedef typename ResultType::TransposeType TransposeType;
1611  typedef typename MT::ElementType ElementType;
1612  typedef typename MT::ReturnType ReturnType;
1613  typedef const ResultType CompositeType;
1614 
1616  typedef typename MT::ConstReference ConstReference;
1617 
1619  typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference;
1620  //**********************************************************************************************
1621 
1622  //**ColumnElement class definition**************************************************************
1625  template< typename MatrixType // Type of the sparse matrix
1626  , typename IteratorType > // Type of the sparse matrix iterator
1627  class ColumnElement
1628  {
1629  private:
1630  //*******************************************************************************************
1632 
1637  enum { returnConst = IsConst<MatrixType>::value };
1638  //*******************************************************************************************
1639 
1640  public:
1641  //**Type definitions*************************************************************************
1642  typedef typename SelectType< returnConst, const ElementType&, ElementType& >::Type ReferenceType;
1643  //*******************************************************************************************
1644 
1645  //**Constructor******************************************************************************
1651  inline ColumnElement( IteratorType pos, size_t row )
1652  : pos_( pos ) // Iterator to the current position within the sparse column
1653  , row_( row ) // Index of the according row
1654  {}
1655  //*******************************************************************************************
1656 
1657  //**Assignment operator**********************************************************************
1663  template< typename T > inline ColumnElement& operator=( const T& v ) {
1664  *pos_ = v;
1665  return *this;
1666  }
1667  //*******************************************************************************************
1668 
1669  //**Addition assignment operator*************************************************************
1675  template< typename T > inline ColumnElement& operator+=( const T& v ) {
1676  *pos_ += v;
1677  return *this;
1678  }
1679  //*******************************************************************************************
1680 
1681  //**Subtraction assignment operator**********************************************************
1687  template< typename T > inline ColumnElement& operator-=( const T& v ) {
1688  *pos_ -= v;
1689  return *this;
1690  }
1691  //*******************************************************************************************
1692 
1693  //**Multiplication assignment operator*******************************************************
1699  template< typename T > inline ColumnElement& operator*=( const T& v ) {
1700  *pos_ *= v;
1701  return *this;
1702  }
1703  //*******************************************************************************************
1704 
1705  //**Division assignment operator*************************************************************
1711  template< typename T > inline ColumnElement& operator/=( const T& v ) {
1712  *pos_ /= v;
1713  return *this;
1714  }
1715  //*******************************************************************************************
1716 
1717  //**Element access operator******************************************************************
1722  inline const ColumnElement* operator->() const {
1723  return this;
1724  }
1725  //*******************************************************************************************
1726 
1727  //**Value function***************************************************************************
1732  inline ReferenceType value() const {
1733  return pos_->value();
1734  }
1735  //*******************************************************************************************
1736 
1737  //**Index function***************************************************************************
1742  inline size_t index() const {
1743  return row_;
1744  }
1745  //*******************************************************************************************
1746 
1747  private:
1748  //**Member variables*************************************************************************
1749  IteratorType pos_;
1750  size_t row_;
1751  //*******************************************************************************************
1752  };
1753  //**********************************************************************************************
1754 
1755  //**ColumnIterator class definition*************************************************************
1758  template< typename MatrixType // Type of the sparse matrix
1759  , typename IteratorType > // Type of the sparse matrix iterator
1760  class ColumnIterator
1761  {
1762  public:
1763  //**Type definitions*************************************************************************
1764  typedef std::forward_iterator_tag IteratorCategory;
1765  typedef ColumnElement<MatrixType,IteratorType> ValueType;
1766  typedef ValueType PointerType;
1767  typedef ValueType ReferenceType;
1768  typedef ptrdiff_t DifferenceType;
1769 
1770  // STL iterator requirements
1771  typedef IteratorCategory iterator_category;
1772  typedef ValueType value_type;
1773  typedef PointerType pointer;
1774  typedef ReferenceType reference;
1775  typedef DifferenceType difference_type;
1776  //*******************************************************************************************
1777 
1778  //**Constructor******************************************************************************
1785  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column )
1786  : matrix_( matrix ) // The sparse matrix containing the column.
1787  , row_ ( row ) // The current row index.
1788  , column_( column ) // The current column index.
1789  , pos_ () // Iterator to the current sparse element.
1790  {
1791  for( ; row_<matrix_.rows(); ++row_ ) {
1792  pos_ = matrix_.find( row_, column_ );
1793  if( pos_ != matrix_.end( row_ ) ) break;
1794  }
1795  }
1796  //*******************************************************************************************
1797 
1798  //**Constructor******************************************************************************
1806  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
1807  : matrix_( matrix ) // The sparse matrix containing the column.
1808  , row_ ( row ) // The current row index.
1809  , column_( column ) // The current column index.
1810  , pos_ ( pos ) // Iterator to the current sparse element.
1811  {
1812  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
1813  }
1814  //*******************************************************************************************
1815 
1816  //**Constructor******************************************************************************
1821  template< typename MatrixType2, typename IteratorType2 >
1822  inline ColumnIterator( const ColumnIterator<MatrixType2,IteratorType2>& it )
1823  : matrix_( it.matrix_ ) // The sparse matrix containing the column.
1824  , row_ ( it.row_ ) // The current row index.
1825  , column_( it.column_ ) // The current column index.
1826  , pos_ ( it.pos_ ) // Iterator to the current sparse element.
1827  {}
1828  //*******************************************************************************************
1829 
1830  //**Prefix increment operator****************************************************************
1835  inline ColumnIterator& operator++() {
1836  ++row_;
1837  for( ; row_<matrix_.rows(); ++row_ ) {
1838  pos_ = matrix_.find( row_, column_ );
1839  if( pos_ != matrix_.end( row_ ) ) break;
1840  }
1841 
1842  return *this;
1843  }
1844  //*******************************************************************************************
1845 
1846  //**Postfix increment operator***************************************************************
1851  inline const ColumnIterator operator++( int ) {
1852  const ColumnIterator tmp( *this );
1853  ++(*this);
1854  return tmp;
1855  }
1856  //*******************************************************************************************
1857 
1858  //**Element access operator******************************************************************
1863  inline ReferenceType operator*() const {
1864  return ReferenceType( pos_, row_ );
1865  }
1866  //*******************************************************************************************
1867 
1868  //**Element access operator******************************************************************
1873  inline PointerType operator->() const {
1874  return PointerType( pos_, row_ );
1875  }
1876  //*******************************************************************************************
1877 
1878  //**Equality operator************************************************************************
1884  template< typename MatrixType2, typename IteratorType2 >
1885  inline bool operator==( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
1886  return ( &matrix_ == &rhs.matrix_ ) && ( row_ == rhs.row_ ) && ( column_ == rhs.column_ );
1887  }
1888  //*******************************************************************************************
1889 
1890  //**Inequality operator**********************************************************************
1896  template< typename MatrixType2, typename IteratorType2 >
1897  inline bool operator!=( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
1898  return !( *this == rhs );
1899  }
1900  //*******************************************************************************************
1901 
1902  //**Subtraction operator*********************************************************************
1908  inline DifferenceType operator-( const ColumnIterator& rhs ) const {
1909  size_t counter( 0UL );
1910  for( size_t i=rhs.row_; i<row_; ++i ) {
1911  if( matrix_.find( i, column_ ) != matrix_.end( i ) )
1912  ++counter;
1913  }
1914  return counter;
1915  }
1916  //*******************************************************************************************
1917 
1918  private:
1919  //**Member variables*************************************************************************
1920  MatrixType& matrix_;
1921  size_t row_;
1922  size_t column_;
1923  IteratorType pos_;
1924  //*******************************************************************************************
1925 
1926  //**Friend declarations**********************************************************************
1927  template< typename MatrixType2, typename IteratorType2 > friend class ColumnIterator;
1928  template< typename MT2, bool SO2 > friend class SparseColumn;
1929  //*******************************************************************************************
1930  };
1931  //**********************************************************************************************
1932 
1933  //**Type definitions****************************************************************************
1935  typedef ColumnIterator<const MT,typename MT::ConstIterator> ConstIterator;
1936 
1938  typedef typename SelectType< useConst, ConstIterator, ColumnIterator<MT,typename MT::Iterator> >::Type Iterator;
1939  //**********************************************************************************************
1940 
1941  //**Compilation flags***************************************************************************
1943  enum { smpAssignable = 0 };
1944  //**********************************************************************************************
1945 
1946  //**Constructors********************************************************************************
1949  explicit inline SparseColumn( MT& matrix, size_t index );
1950  // No explicitly declared copy constructor.
1952  //**********************************************************************************************
1953 
1954  //**Destructor**********************************************************************************
1955  // No explicitly declared destructor.
1956  //**********************************************************************************************
1957 
1958  //**Data access functions***********************************************************************
1961  inline Reference operator[]( size_t index );
1962  inline ConstReference operator[]( size_t index ) const;
1963  inline Iterator begin ();
1964  inline ConstIterator begin () const;
1965  inline ConstIterator cbegin() const;
1966  inline Iterator end ();
1967  inline ConstIterator end () const;
1968  inline ConstIterator cend () const;
1970  //**********************************************************************************************
1971 
1972  //**Assignment operators************************************************************************
1975  inline SparseColumn& operator= ( const SparseColumn& rhs );
1976  template< typename VT > inline SparseColumn& operator= ( const Vector<VT,false>& rhs );
1977  template< typename VT > inline SparseColumn& operator+=( const Vector<VT,false>& rhs );
1978  template< typename VT > inline SparseColumn& operator-=( const Vector<VT,false>& rhs );
1979  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
1980 
1981  template< typename Other >
1982  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
1983  operator*=( Other rhs );
1984 
1985  template< typename Other >
1986  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
1987  operator/=( Other rhs );
1989  //**********************************************************************************************
1990 
1991  //**Utility functions***************************************************************************
1994  inline size_t size() const;
1995  inline size_t capacity() const;
1996  inline size_t nonZeros() const;
1997  inline void reset();
1998  inline Iterator insert ( size_t index, const ElementType& value );
1999  inline void erase ( size_t index );
2000  inline Iterator erase ( Iterator pos );
2001  inline Iterator erase ( Iterator first, Iterator last );
2002  inline void reserve( size_t n );
2003  template< typename Other > inline SparseColumn& scale ( Other scalar );
2005  //**********************************************************************************************
2006 
2007  //**Lookup functions****************************************************************************
2010  inline Iterator find ( size_t index );
2011  inline ConstIterator find ( size_t index ) const;
2012  inline Iterator lowerBound( size_t index );
2013  inline ConstIterator lowerBound( size_t index ) const;
2014  inline Iterator upperBound( size_t index );
2015  inline ConstIterator upperBound( size_t index ) const;
2017  //**********************************************************************************************
2018 
2019  //**Low-level utility functions*****************************************************************
2022  inline void append( size_t index, const ElementType& value, bool check=false );
2024  //**********************************************************************************************
2025 
2026  //**Expression template evaluation functions****************************************************
2029  template< typename Other > inline bool canAlias ( const Other* alias ) const;
2030  template< typename Other > inline bool isAliased( const Other* alias ) const;
2031  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
2032  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
2033  template< typename VT > inline void addAssign( const Vector<VT,false>& rhs );
2034  template< typename VT > inline void subAssign( const Vector<VT,false>& rhs );
2036  //**********************************************************************************************
2037 
2038  private:
2039  //**Member variables****************************************************************************
2042  Operand matrix_;
2043  const size_t col_;
2044 
2045  //**********************************************************************************************
2046 
2047  //**Compile time checks*************************************************************************
2052  //**********************************************************************************************
2053 };
2055 //*************************************************************************************************
2056 
2057 
2058 
2059 
2060 //=================================================================================================
2061 //
2062 // CONSTRUCTOR
2063 //
2064 //=================================================================================================
2065 
2066 //*************************************************************************************************
2074 template< typename MT > // Type of the sparse matrix
2075 inline SparseColumn<MT,false>::SparseColumn( MT& matrix, size_t index )
2076  : matrix_( matrix ) // The sparse matrix containing the column
2077  , col_ ( index ) // The index of the column in the matrix
2078 {
2079  if( matrix_.columns() <= index )
2080  throw std::invalid_argument( "Invalid column access index" );
2081 }
2083 //*************************************************************************************************
2084 
2085 
2086 
2087 
2088 //=================================================================================================
2089 //
2090 // DATA ACCESS FUNCTIONS
2091 //
2092 //=================================================================================================
2093 
2094 //*************************************************************************************************
2101 template< typename MT > // Type of the sparse matrix
2103 {
2104  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2105  return matrix_(index,col_);
2106 }
2108 //*************************************************************************************************
2109 
2110 
2111 //*************************************************************************************************
2118 template< typename MT > // Type of the sparse matrix
2120 {
2121  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
2122  return const_cast<const MT&>( matrix_ )(index,col_);
2123 }
2125 //*************************************************************************************************
2126 
2127 
2128 //*************************************************************************************************
2136 template< typename MT > // Type of the sparse matrix
2138 {
2139  return Iterator( matrix_, 0UL, col_ );
2140 }
2142 //*************************************************************************************************
2143 
2144 
2145 //*************************************************************************************************
2153 template< typename MT > // Type of the sparse matrix
2155 {
2156  return ConstIterator( matrix_, 0UL, col_ );
2157 }
2159 //*************************************************************************************************
2160 
2161 
2162 //*************************************************************************************************
2170 template< typename MT > // Type of the sparse matrix
2172 {
2173  return ConstIterator( matrix_, 0UL, col_ );
2174 }
2176 //*************************************************************************************************
2177 
2178 
2179 //*************************************************************************************************
2187 template< typename MT > // Type of the sparse matrix
2189 {
2190  return Iterator( matrix_, size(), col_ );
2191 }
2193 //*************************************************************************************************
2194 
2195 
2196 //*************************************************************************************************
2204 template< typename MT > // Type of the sparse matrix
2206 {
2207  return ConstIterator( matrix_, size(), col_ );
2208 }
2210 //*************************************************************************************************
2211 
2212 
2213 //*************************************************************************************************
2221 template< typename MT > // Type of the sparse matrix
2223 {
2224  return ConstIterator( matrix_, size(), col_ );
2225 }
2227 //*************************************************************************************************
2228 
2229 
2230 
2231 
2232 //=================================================================================================
2233 //
2234 // ASSIGNMENT OPERATORS
2235 //
2236 //=================================================================================================
2237 
2238 //*************************************************************************************************
2249 template< typename MT > // Type of the sparse matrix
2250 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator=( const SparseColumn& rhs )
2251 {
2252  using blaze::assign;
2253 
2257 
2258  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
2259  return *this;
2260 
2261  if( size() != rhs.size() )
2262  throw std::invalid_argument( "Column sizes do not match" );
2263 
2264  if( rhs.canAlias( &matrix_ ) ) {
2265  const ResultType tmp( rhs );
2266  assign( *this, tmp );
2267  }
2268  else {
2269  assign( *this, rhs );
2270  }
2271 
2272  return *this;
2273 }
2275 //*************************************************************************************************
2276 
2277 
2278 //*************************************************************************************************
2289 template< typename MT > // Type of the sparse matrix
2290 template< typename VT > // Type of the right-hand side vector
2291 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator=( const Vector<VT,false>& rhs )
2292 {
2293  using blaze::assign;
2294 
2295  if( size() != (~rhs).size() )
2296  throw std::invalid_argument( "Vector sizes do not match" );
2297 
2298  const typename VT::CompositeType tmp( ~rhs );
2299  assign( *this, tmp );
2300 
2301  return *this;
2302 }
2304 //*************************************************************************************************
2305 
2306 
2307 //*************************************************************************************************
2318 template< typename MT > // Type of the sparse matrix
2319 template< typename VT > // Type of the right-hand side vector
2320 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator+=( const Vector<VT,false>& rhs )
2321 {
2322  using blaze::addAssign;
2323 
2324  if( size() != (~rhs).size() )
2325  throw std::invalid_argument( "Vector sizes do not match" );
2326 
2327  addAssign( *this, ~rhs );
2328 
2329  return *this;
2330 }
2332 //*************************************************************************************************
2333 
2334 
2335 //*************************************************************************************************
2346 template< typename MT > // Type of the sparse matrix
2347 template< typename VT > // Type of the right-hand side vector
2348 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator-=( const Vector<VT,false>& rhs )
2349 {
2350  using blaze::subAssign;
2351 
2352  if( size() != (~rhs).size() )
2353  throw std::invalid_argument( "Vector sizes do not match" );
2354 
2355  subAssign( *this, ~rhs );
2356 
2357  return *this;
2358 }
2360 //*************************************************************************************************
2361 
2362 
2363 //*************************************************************************************************
2375 template< typename MT > // Type of the sparse matrix
2376 template< typename VT > // Type of the right-hand side vector
2377 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator*=( const Vector<VT,false>& rhs )
2378 {
2379  if( size() != (~rhs).size() )
2380  throw std::invalid_argument( "Vector sizes do not match" );
2381 
2382  typedef typename MultTrait<ResultType,typename VT::ResultType>::Type MultType;
2383 
2386 
2387  const MultType tmp( *this * (~rhs) );
2388  assign( tmp );
2389 
2390  return *this;
2391 }
2393 //*************************************************************************************************
2394 
2395 
2396 //*************************************************************************************************
2408 template< typename MT > // Type of the sparse matrix
2409 template< typename Other > // Data type of the right-hand side scalar
2410 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false> >::Type&
2411  SparseColumn<MT,false>::operator*=( Other rhs )
2412 {
2413  for( Iterator element=begin(); element!=end(); ++element )
2414  element->value() *= rhs;
2415  return *this;
2416 }
2418 //*************************************************************************************************
2419 
2420 
2421 //*************************************************************************************************
2434 template< typename MT > // Type of the sparse matrix
2435 template< typename Other > // Data type of the right-hand side scalar
2436 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false> >::Type&
2437  SparseColumn<MT,false>::operator/=( Other rhs )
2438 {
2439  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
2440 
2441  typedef typename DivTrait<ElementType,Other>::Type DT;
2442  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
2443 
2444  // Depending on the two involved data types, an integer division is applied or a
2445  // floating point division is selected.
2446  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
2447  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
2448  for( Iterator element=begin(); element!=end(); ++element )
2449  element->value() *= tmp;
2450  }
2451  else {
2452  for( Iterator element=begin(); element!=end(); ++element )
2453  element->value() /= rhs;
2454  }
2455 
2456  return *this;
2457 }
2459 //*************************************************************************************************
2460 
2461 
2462 
2463 
2464 //=================================================================================================
2465 //
2466 // UTILITY FUNCTIONS
2467 //
2468 //=================================================================================================
2469 
2470 //*************************************************************************************************
2476 template< typename MT > // Type of the sparse matrix
2477 inline size_t SparseColumn<MT,false>::size() const
2478 {
2479  return matrix_.rows();
2480 }
2482 //*************************************************************************************************
2483 
2484 
2485 //*************************************************************************************************
2491 template< typename MT > // Type of the sparse matrix
2492 inline size_t SparseColumn<MT,false>::capacity() const
2493 {
2494  return matrix_.rows();
2495 }
2497 //*************************************************************************************************
2498 
2499 
2500 //*************************************************************************************************
2509 template< typename MT > // Type of the sparse matrix
2510 inline size_t SparseColumn<MT,false>::nonZeros() const
2511 {
2512  size_t counter( 0UL );
2513  for( ConstIterator element=begin(); element!=end(); ++element ) {
2514  ++counter;
2515  }
2516  return counter;
2517 }
2519 //*************************************************************************************************
2520 
2521 
2522 //*************************************************************************************************
2528 template< typename MT > // Type of the sparse matrix
2529 inline void SparseColumn<MT,false>::reset()
2530 {
2531  for( size_t i=0UL; i<size(); ++i ) {
2532  matrix_.erase( i, col_ );
2533  }
2534 }
2536 //*************************************************************************************************
2537 
2538 
2539 //*************************************************************************************************
2552 template< typename MT > // Type of the sparse matrix
2553 inline typename SparseColumn<MT,false>::Iterator
2554  SparseColumn<MT,false>::insert( size_t index, const ElementType& value )
2555 {
2556  return Iterator( matrix_, index, col_, matrix_.insert( index, col_, value ) );
2557 }
2559 //*************************************************************************************************
2560 
2561 
2562 //*************************************************************************************************
2571 template< typename MT > // Type of the sparse matrix
2572 inline void SparseColumn<MT,false>::erase( size_t index )
2573 {
2574  matrix_.erase( index, col_ );
2575 }
2577 //*************************************************************************************************
2578 
2579 
2580 //*************************************************************************************************
2589 template< typename MT > // Type of the sparse matrix
2591 {
2592  const size_t row( pos.row_ );
2593 
2594  if( row == size() )
2595  return pos;
2596 
2597  matrix_.erase( row, pos.pos_ );
2598  return Iterator( matrix_, row+1UL, col_ );
2599 }
2601 //*************************************************************************************************
2602 
2603 
2604 //*************************************************************************************************
2614 template< typename MT > // Type of the sparse matrix
2616 {
2617  for( ; first!=last; ++first ) {
2618  matrix_.erase( first.row_, first.pos_ );
2619  }
2620  return last;
2621 }
2623 //*************************************************************************************************
2624 
2625 
2626 //*************************************************************************************************
2636 template< typename MT > // Type of the sparse matrix
2637 void SparseColumn<MT,false>::reserve( size_t n )
2638 {
2639  UNUSED_PARAMETER( n );
2640  return;
2641 }
2643 //*************************************************************************************************
2644 
2645 
2646 //*************************************************************************************************
2653 template< typename MT > // Type of the sparse matrix
2654 template< typename Other > // Data type of the scalar value
2655 inline SparseColumn<MT,false>& SparseColumn<MT,false>::scale( Other scalar )
2656 {
2657  for( Iterator element=begin(); element!=end(); ++element )
2658  element->value() *= scalar;
2659  return *this;
2660 }
2662 //*************************************************************************************************
2663 
2664 
2665 
2666 
2667 //=================================================================================================
2668 //
2669 // LOOKUP FUNCTIONS
2670 //
2671 //=================================================================================================
2672 
2673 //*************************************************************************************************
2687 template< typename MT > // Type of the sparse matrix
2688 inline typename SparseColumn<MT,false>::Iterator SparseColumn<MT,false>::find( size_t index )
2689 {
2690  const typename MT::Iterator pos( matrix_.find( index, col_ ) );
2691 
2692  if( pos != matrix_.end( index ) )
2693  return Iterator( matrix_, index, col_, pos );
2694  else
2695  return end();
2696 }
2698 //*************************************************************************************************
2699 
2700 
2701 //*************************************************************************************************
2715 template< typename MT > // Type of the sparse matrix
2716 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::find( size_t index ) const
2717 {
2718  const typename MT::ConstIterator pos( matrix_.find( index, col_ ) );
2719 
2720  if( pos != matrix_.end( index ) )
2721  return ConstIterator( matrix_, index, col_, pos );
2722  else
2723  return end();
2724 }
2726 //*************************************************************************************************
2727 
2728 
2729 //*************************************************************************************************
2742 template< typename MT > // Type of the sparse matrix
2744 {
2745  for( size_t i=index; i<size(); ++i )
2746  {
2747  const typename MT::Iterator pos( matrix_.find( i, col_ ) );
2748 
2749  if( pos != matrix_.end( i ) )
2750  return Iterator( matrix_, i, col_, pos );
2751  }
2752 
2753  return end();
2754 }
2756 //*************************************************************************************************
2757 
2758 
2759 //*************************************************************************************************
2772 template< typename MT > // Type of the sparse matrix
2774 {
2775  for( size_t i=index; i<size(); ++i )
2776  {
2777  const typename MT::ConstIterator pos( matrix_.find( i, col_ ) );
2778 
2779  if( pos != matrix_.end( i ) )
2780  return ConstIterator( matrix_, i, col_, pos );
2781  }
2782 
2783  return end();
2784 }
2786 //*************************************************************************************************
2787 
2788 
2789 //*************************************************************************************************
2802 template< typename MT > // Type of the sparse matrix
2804 {
2805  for( size_t i=index+1UL; i<size(); ++i )
2806  {
2807  const typename MT::Iterator pos( matrix_.find( i, col_ ) );
2808 
2809  if( pos != matrix_.end( i ) )
2810  return Iterator( matrix_, i, col_, pos );
2811  }
2812 
2813  return end();
2814 }
2816 //*************************************************************************************************
2817 
2818 
2819 //*************************************************************************************************
2832 template< typename MT > // Type of the sparse matrix
2834 {
2835  for( size_t i=index+1UL; i<size(); ++i )
2836  {
2837  const typename MT::ConstIterator pos( matrix_.find( i, col_ ) );
2838 
2839  if( pos != matrix_.end( i ) )
2840  return ConstIterator( matrix_, i, col_, pos );
2841  }
2842 
2843  return end();
2844 }
2846 //*************************************************************************************************
2847 
2848 
2849 
2850 
2851 //=================================================================================================
2852 //
2853 // LOW-LEVEL UTILITY FUNCTIONS
2854 //
2855 //=================================================================================================
2856 
2857 //*************************************************************************************************
2882 template< typename MT > // Type of the sparse matrix
2883 inline void SparseColumn<MT,false>::append( size_t index, const ElementType& value, bool check )
2884 {
2885  if( !check || !isDefault( value ) )
2886  matrix_.insert( index, col_, value );
2887 }
2889 //*************************************************************************************************
2890 
2891 
2892 
2893 
2894 //=================================================================================================
2895 //
2896 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2897 //
2898 //=================================================================================================
2899 
2900 //*************************************************************************************************
2911 template< typename MT > // Type of the sparse matrix
2912 template< typename Other > // Data type of the foreign expression
2913 inline bool SparseColumn<MT,false>::canAlias( const Other* alias ) const
2914 {
2915  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
2916 }
2918 //*************************************************************************************************
2919 
2920 
2921 //*************************************************************************************************
2928 template< typename MT > // Type of the sparse matrix
2929 template< typename Other > // Data type of the foreign expression
2930 inline bool SparseColumn<MT,false>::isAliased( const Other* alias ) const
2931 {
2932  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
2933 }
2935 //*************************************************************************************************
2936 
2937 
2938 //*************************************************************************************************
2950 template< typename MT > // Type of the sparse matrix
2951 template< typename VT > // Type of the right-hand side dense vector
2952 inline void SparseColumn<MT,false>::assign( const DenseVector<VT,false>& rhs )
2953 {
2954  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2955 
2956  for( size_t i=0UL; i<(~rhs).size(); ++i ) {
2957  matrix_(i,col_) = (~rhs)[i];
2958  }
2959 }
2961 //*************************************************************************************************
2962 
2963 
2964 //*************************************************************************************************
2976 template< typename MT > // Type of the sparse matrix
2977 template< typename VT > // Type of the right-hand side sparse vector
2978 inline void SparseColumn<MT,false>::assign( const SparseVector<VT,false>& rhs )
2979 {
2980  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2981 
2982  size_t i( 0UL );
2983 
2984  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2985  for( ; i<element->index(); ++i )
2986  matrix_.erase( i, col_ );
2987  matrix_(i++,col_) = element->value();
2988  }
2989  for( ; i<size(); ++i ) {
2990  matrix_.erase( i, col_ );
2991  }
2992 }
2994 //*************************************************************************************************
2995 
2996 
2997 //*************************************************************************************************
3009 template< typename MT > // Type of the sparse matrix
3010 template< typename VT > // Type of the right-hand side vector
3011 inline void SparseColumn<MT,false>::addAssign( const Vector<VT,false>& rhs )
3012 {
3013  typedef typename AddTrait<ResultType,typename VT::ResultType>::Type AddType;
3014 
3017 
3018  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3019 
3020  const AddType tmp( *this + (~rhs) );
3021  assign( tmp );
3022 }
3024 //*************************************************************************************************
3025 
3026 
3027 //*************************************************************************************************
3039 template< typename MT > // Type of the sparse matrix
3040 template< typename VT > // Type of the right-hand side vector
3041 inline void SparseColumn<MT,false>::subAssign( const Vector<VT,false>& rhs )
3042 {
3043  typedef typename SubTrait<ResultType,typename VT::ResultType>::Type SubType;
3044 
3047 
3048  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
3049 
3050  const SubType tmp( *this - (~rhs) );
3051  assign( tmp );
3052 }
3054 //*************************************************************************************************
3055 
3056 
3057 
3058 
3059 
3060 
3061 
3062 
3063 //=================================================================================================
3064 //
3065 // SPARSECOLUMN OPERATORS
3066 //
3067 //=================================================================================================
3068 
3069 //*************************************************************************************************
3072 template< typename MT, bool SO >
3073 inline void reset( SparseColumn<MT,SO>& column );
3074 
3075 template< typename MT, bool SO >
3076 inline void clear( SparseColumn<MT,SO>& column );
3077 
3078 template< typename MT, bool SO >
3079 inline bool isDefault( const SparseColumn<MT,SO>& column );
3081 //*************************************************************************************************
3082 
3083 
3084 //*************************************************************************************************
3091 template< typename MT // Type of the sparse matrix
3092  , bool SO > // Storage order
3093 inline void reset( SparseColumn<MT,SO>& column )
3094 {
3095  column.reset();
3096 }
3097 //*************************************************************************************************
3098 
3099 
3100 //*************************************************************************************************
3109 template< typename MT // Type of the sparse matrix
3110  , bool SO > // Storage order
3111 inline void clear( SparseColumn<MT,SO>& column )
3112 {
3113  column.reset();
3114 }
3115 //*************************************************************************************************
3116 
3117 
3118 //*************************************************************************************************
3136 template< typename MT // Type of the sparse matrix
3137  , bool SO > // Storage order
3138 inline bool isDefault( const SparseColumn<MT,SO>& column )
3139 {
3141 
3142  const ConstIterator end( column.end() );
3143  for( ConstIterator element=column.begin(); element!=end; ++element )
3144  if( !isDefault( element->value() ) ) return false;
3145  return true;
3146 }
3147 //*************************************************************************************************
3148 
3149 
3150 
3151 
3152 //=================================================================================================
3153 //
3154 // SUBVECTORTRAIT SPECIALIZATIONS
3155 //
3156 //=================================================================================================
3157 
3158 //*************************************************************************************************
3160 template< typename MT, bool SO >
3161 struct SubvectorTrait< SparseColumn<MT,SO> >
3162 {
3163  typedef typename SubvectorTrait< typename SparseColumn<MT,SO>::ResultType >::Type Type;
3164 };
3166 //*************************************************************************************************
3167 
3168 } // namespace blaze
3169 
3170 #endif
Constraint on the data type.
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.
void subAssign(const DenseVector< VT, false > &rhs)
Default implementation of the subtraction assignment of a dense vector.
Definition: SparseColumn.h:1516
void reset(DynamicMatrix< Type, SO > &m)
Resetting the given dense matrix.
Definition: DynamicMatrix.h:4579
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Operand matrix_
The sparse matrix containing the column.
Definition: SparseColumn.h:493
Header file for the UNUSED_PARAMETER function template.
Compile time type selection.The If class template selects one of the two given types T2 and T3 depend...
Definition: If.h:112
const DMatDMatMultExpr< T1, T2 > operator*(const DenseMatrix< T1, false > &lhs, const DenseMatrix< T2, false > &rhs)
Multiplication operator for the multiplication of two row-major dense matrices ( ).
Definition: DMatDMatMultExpr.h:4075
Header file for the subtraction trait.
Iterator end()
Returns an iterator just past the last element of the column.
Definition: SparseColumn.h:634
Header file for the SparseVector base class.
ConstIterator cend() const
Returns an iterator just past the last element of the column.
Definition: SparseColumn.h:666
Base template for the ColumnTrait class.
Definition: ColumnTrait.h:114
#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: TransposeFlag.h:159
bool isDefault(const DynamicMatrix< Type, SO > &m)
Returns whether the given dense matrix is in default state.
Definition: DynamicMatrix.h:4622
Efficient implementation of a compressed matrix.The CompressedMatrix class template is the represent...
Definition: CompressedMatrix.h:197
#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
Header file for the IsColumnMajorMatrix type trait.
void assign(const DenseVector< VT, false > &rhs)
Default implementation of the assignment of a dense vector.
Definition: SparseColumn.h:1397
const This & CompositeType
Data type for composite expression templates.
Definition: CompressedMatrix.h:2384
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename ColumnExprTrait< MT >::Type >::Type column(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific column of the given matrix.
Definition: Column.h:103
void UNUSED_PARAMETER(const T1 &)
Suppression of unused parameter warnings.
Definition: Unused.h:84
Iterator find(size_t index)
Searches for a specific column element.
Definition: SparseColumn.h:1181
Access proxy for sparse, matrices.The MatrixAccessProxy provides safe access to the elements of a no...
Definition: MatrixAccessProxy.h:86
ResultType::TransposeType TransposeType
Transpose type for expression template evaluations.
Definition: SparseColumn.h:364
#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
void clear(DynamicMatrix< Type, SO > &m)
Clearing the given dense matrix.
Definition: DynamicMatrix.h:4595
Header file for the column base class.
Constraint on the data type.
MT::ConstIterator ConstIterator
Iterator over constant elements.
Definition: SparseColumn.h:376
SelectType< useConst, ConstIterator, typename MT::Iterator >::Type Iterator
Iterator over non-constant elements.
Definition: SparseColumn.h:379
Compile time type selection.The SelectType class template selects one of the two given types T1 and T...
Definition: SelectType.h:59
Header file for the DisableIf class template.
Header file for the multiplication trait.
MT::ElementType ElementType
Type of the column elements.
Definition: SparseColumn.h:365
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: StorageOrder.h:161
const Element * ConstIterator
Iterator over constant elements.
Definition: CompressedMatrix.h:2388
Header file for the Or class template.
Iterator begin()
Returns an iterator to the first element of the column.
Definition: SparseColumn.h:586
void addAssign(const DenseVector< VT, false > &rhs)
Default implementation of the addition assignment of a dense vector.
Definition: SparseColumn.h:1453
size_t size() const
Returns the current size/dimension of the sparse column.
Definition: SparseColumn.h:970
MT::ConstReference ConstReference
Reference to a constant column value.
Definition: SparseColumn.h:370
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
Header file for the subvector trait.
Iterator lowerBound(size_t index)
Returns an iterator to the first index not less then the given index.
Definition: SparseColumn.h:1224
void assign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the assignment of a matrix to a matrix.
Definition: Matrix.h:179
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:70
#define BLAZE_CONSTRAINT_MUST_BE_SPARSE_VECTOR_TYPE(T)
Constraint on the data type.In case the given data type T is not a sparse, N-dimensional vector type...
Definition: SparseVector.h:79
Constraint on the data type.
Iterator upperBound(size_t index)
Returns an iterator to the first index greater then the given index.
Definition: SparseColumn.h:1266
Constraint on the data type.
size_t nonZeros() const
Returns the number of non-zero elements in the column.
Definition: SparseColumn.h:1001
Constraints on the storage order of matrix types.
Constraint on the data type.
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:2382
Constraint on the data type.
Header file for the SelectType class template.
Constraint on the data type.
const Type & ConstReference
Reference to a constant matrix value.
Definition: CompressedMatrix.h:2386
Header file for the EnableIf class template.
Header file for the IsNumeric type trait.
const size_t col_
The index of the column in the matrix.
Definition: SparseColumn.h:494
DisableIf< Or< IsComputation< MT >, IsTransExpr< MT > >, typename RowExprTrait< MT >::Type >::Type row(Matrix< MT, SO > &matrix, size_t index)
Creating a view on a specific row of the given matrix.
Definition: Row.h:103
#define BLAZE_CONSTRAINT_MUST_BE_ROW_MAJOR_MATRIX_TYPE(T)
Constraint on the data type.In case the given data type T is not a row-major dense or sparse matrix t...
Definition: StorageOrder.h:81
const Type & ReturnType
Return type for expression template evaluations.
Definition: CompressedMatrix.h:2383
Header file for the IsConst type trait.
void erase(size_t index)
Erasing an element from the sparse column.
Definition: SparseColumn.h:1054
SparseColumn< MT, SO > This
Type of this SparseColumn instance.
Definition: SparseColumn.h:362
Header file for run time assertion macros.
Base template for the AddTrait class.
Definition: AddTrait.h:141
Base template for the MultTrait class.
Definition: MultTrait.h:141
SelectType< IsExpression< MT >::value, MT, MT & >::Type Operand
Composite data type of the dense matrix expression.
Definition: SparseColumn.h:346
Header file for the addition trait.
ColumnTrait< MT >::Type ResultType
Result type for expression template evaluations.
Definition: SparseColumn.h:363
Header file for the division trait.
void addAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the addition assignment of a matrix to a matrix.
Definition: Matrix.h:209
void reserve(size_t n)
Setting the minimum capacity of the sparse column.
Definition: SparseColumn.h:1107
const DenseIterator< Type > operator-(const DenseIterator< Type > &it, ptrdiff_t inc)
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:585
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
Header file for the reset shim.
void subAssign(Matrix< MT1, SO1 > &lhs, const Matrix< MT2, SO2 > &rhs)
Default implementation of the subtraction assignment of a matrix to matrix.
Definition: Matrix.h:239
const VT::ElementType max(const SparseVector< VT, TF > &sv)
Returns the largest element of the sparse vector.
Definition: SparseVector.h:405
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:2387
Header file for the column trait.
Header file for the isDefault shim.
Iterator insert(size_t index, const ElementType &value)
Inserting an element into the sparse column.
Definition: SparseColumn.h:1037
size_t capacity() const
Returns the maximum capacity of the sparse column.
Definition: SparseColumn.h:984
#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
ConstIterator cbegin() const
Returns an iterator to the first element of the column.
Definition: SparseColumn.h:618
Compile time check for constant data types.The IsConst type trait tests whether or not the given temp...
Definition: IsConst.h:94
const SparseColumn & CompositeType
Data type for composite expression templates.
Definition: SparseColumn.h:367
Base template for the DivTrait class.
Definition: DivTrait.h:141
MT::ReturnType ReturnType
Return type for expression template evaluations.
Definition: SparseColumn.h:366
#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
Base class for N-dimensional vectors.The Vector class is a base class for all arbitrarily sized (N-di...
Definition: Forward.h:147
CompressedMatrix< Type,!SO > TransposeType
Transpose type for expression template evaluations.
Definition: CompressedMatrix.h:248
SparseColumn(MT &matrix, size_t index)
The constructor for SparseColumn.
Definition: SparseColumn.h:527
SparseColumn & operator=(const SparseColumn &rhs)
Copy assignment operator for SparseColumn.
Definition: SparseColumn.h:693
Base class for sparse vectors.The SparseVector class is a base class for all arbitrarily sized (N-dim...
Definition: Forward.h:105
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:2379
void reset()
Reset to the default initial values.
Definition: SparseColumn.h:1015
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
Header file for basic type definitions.
Reference operator[](size_t index)
Subscript operator for the direct access to the column elements.
Definition: SparseColumn.h:553
SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference
Reference to a non-constant column value.
Definition: SparseColumn.h:373
MatrixAccessProxy< This > Reference
Reference to a non-constant matrix value.
Definition: CompressedMatrix.h:2385
Base template for the SubTrait class.
Definition: SubTrait.h:141
const VT::ElementType min(const SparseVector< VT, TF > &sv)
Returns the smallest element of the sparse vector.
Definition: SparseVector.h:348
bool canAlias(const Other *alias) const
Returns whether the sparse column can alias with the given address alias.
Definition: SparseColumn.h:1356
void append(size_t index, const ElementType &value, bool check=false)
Appending an element to the sparse column.
Definition: SparseColumn.h:1328
bool isAliased(const Other *alias) const
Returns whether the sparse column is aliased with the given address alias.
Definition: SparseColumn.h:1376
size_t extendCapacity() const
Calculating a new sparse column capacity.
Definition: SparseColumn.h:1142
#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
Header file for the IsExpression type trait class.
Header file for the FunctionTrace class.