All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SparseColumn.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_VIEWS_SPARSECOLUMN_H_
23 #define _BLAZE_MATH_VIEWS_SPARSECOLUMN_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <iterator>
31 #include <stdexcept>
39 #include <blaze/math/Forward.h>
40 #include <blaze/math/Functions.h>
42 #include <blaze/math/shims/Reset.h>
51 #include <blaze/util/Assert.h>
52 #include <blaze/util/DisableIf.h>
53 #include <blaze/util/EnableIf.h>
55 #include <blaze/util/mpl/If.h>
56 #include <blaze/util/SelectType.h>
57 #include <blaze/util/Types.h>
61 
62 
63 namespace blaze {
64 
65 //=================================================================================================
66 //
67 // CLASS DEFINITION
68 //
69 //=================================================================================================
70 
71 //*************************************************************************************************
323 template< typename MT // Type of the sparse matrix
324  , bool SO = IsColumnMajorMatrix<MT>::value > // Storage order
325 class SparseColumn : public SparseVector< SparseColumn<MT,SO>, false >
326  , private Expression
327 {
328  private:
329  //**********************************************************************************************
331 
337  enum { useConst = IsConst<MT>::value };
338  //**********************************************************************************************
339 
340  public:
341  //**Type definitions****************************************************************************
344  typedef typename ResultType::TransposeType TransposeType;
345  typedef typename MT::ElementType ElementType;
346  typedef typename MT::ReturnType ReturnType;
347  typedef const SparseColumn& CompositeType;
348 
350  typedef typename MT::ConstReference ConstReference;
351 
354 
356  typedef typename MT::ConstIterator ConstIterator;
357 
360  //**********************************************************************************************
361 
362  //**Constructors********************************************************************************
365  explicit inline SparseColumn( MT& matrix, size_t index );
366  // No explicitly declared copy constructor.
368  //**********************************************************************************************
369 
370  //**Destructor**********************************************************************************
371  // No explicitly declared destructor.
372  //**********************************************************************************************
373 
374  //**Data access functions***********************************************************************
377  inline Reference operator[]( size_t index );
378  inline ConstReference operator[]( size_t index ) const;
379  inline Iterator begin ();
380  inline ConstIterator begin () const;
381  inline ConstIterator cbegin() const;
382  inline Iterator end ();
383  inline ConstIterator end () const;
384  inline ConstIterator cend () const;
386  //**********************************************************************************************
387 
388  //**Assignment operators************************************************************************
391  inline SparseColumn& operator= ( const SparseColumn& rhs );
392  template< typename VT > inline SparseColumn& operator= ( const DenseVector <VT,false>& rhs );
393  template< typename VT > inline SparseColumn& operator= ( const SparseVector<VT,false>& rhs );
394  template< typename VT > inline SparseColumn& operator+=( const Vector<VT,false>& rhs );
395  template< typename VT > inline SparseColumn& operator-=( const Vector<VT,false>& rhs );
396  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
397 
398  template< typename Other >
399  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
400  operator*=( Other rhs );
401 
402  template< typename Other >
403  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
404  operator/=( Other rhs );
406  //**********************************************************************************************
407 
408  //**Utility functions***************************************************************************
411  inline size_t size() const;
412  inline size_t capacity() const;
413  inline size_t nonZeros() const;
414  inline void reset();
415  inline ElementType& insert ( size_t index, const ElementType& value );
416  inline void erase ( size_t index );
417  inline Iterator erase ( Iterator pos );
418  inline Iterator find ( size_t index );
419  inline ConstIterator find ( size_t index ) const;
420  inline void reserve( size_t n );
421  template< typename Other > inline SparseColumn& scale ( Other scalar );
423  //**********************************************************************************************
424 
425  //**Low-level utility functions*****************************************************************
428  inline void append( size_t index, const ElementType& value, bool check=false );
430  //**********************************************************************************************
431 
432  //**Expression template evaluation functions****************************************************
435  template< typename Other > inline bool canAlias ( const Other* alias ) const;
436  template< typename Other > inline bool isAliased( const Other* alias ) const;
437  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
438  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
439  template< typename VT > inline void addAssign( const DenseVector <VT,false>& rhs );
440  template< typename VT > inline void addAssign( const SparseVector<VT,false>& rhs );
441  template< typename VT > inline void subAssign( const DenseVector <VT,false>& rhs );
442  template< typename VT > inline void subAssign( const SparseVector<VT,false>& rhs );
444  //**********************************************************************************************
445 
446  private:
447  //**Utility functions***************************************************************************
450  inline size_t extendCapacity() const;
452  //**********************************************************************************************
453 
454  //**Member variables****************************************************************************
457  MT& matrix_;
458  const size_t col_;
459 
460  //**********************************************************************************************
461 
462  //**Compile time checks*************************************************************************
468  //**********************************************************************************************
469 };
470 //*************************************************************************************************
471 
472 
473 
474 
475 //=================================================================================================
476 //
477 // CONSTRUCTOR
478 //
479 //=================================================================================================
480 
481 //*************************************************************************************************
488 template< typename MT // Type of the sparse matrix
489  , bool SO > // Storage order
490 inline SparseColumn<MT,SO>::SparseColumn( MT& matrix, size_t index )
491  : matrix_( matrix ) // The sparse matrix containing the column
492  , col_ ( index ) // The index of the column in the matrix
493 {
494  if( matrix_.columns() <= index )
495  throw std::invalid_argument( "Invalid column access index" );
496 }
497 //*************************************************************************************************
498 
499 
500 
501 
502 //=================================================================================================
503 //
504 // DATA ACCESS FUNCTIONS
505 //
506 //=================================================================================================
507 
508 //*************************************************************************************************
514 template< typename MT // Type of the sparse matrix
515  , bool SO > // Storage order
517 {
518  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
519  return matrix_(index,col_);
520 }
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
530 template< typename MT // Type of the sparse matrix
531  , bool SO > // Storage order
533 {
534  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
535  return const_cast<const MT&>( matrix_ )(index,col_);
536 }
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
547 template< typename MT // Type of the sparse matrix
548  , bool SO > // Storage order
550 {
551  return matrix_.begin( col_ );
552 }
553 //*************************************************************************************************
554 
555 
556 //*************************************************************************************************
563 template< typename MT // Type of the sparse matrix
564  , bool SO > // Storage order
566 {
567  return matrix_.begin( col_ );
568 }
569 //*************************************************************************************************
570 
571 
572 //*************************************************************************************************
579 template< typename MT // Type of the sparse matrix
580  , bool SO > // Storage order
582 {
583  return matrix_.begin( col_ );
584 }
585 //*************************************************************************************************
586 
587 
588 //*************************************************************************************************
595 template< typename MT // Type of the sparse matrix
596  , bool SO > // Storage order
598 {
599  return matrix_.end( col_ );
600 }
601 //*************************************************************************************************
602 
603 
604 //*************************************************************************************************
611 template< typename MT // Type of the sparse matrix
612  , bool SO > // Storage order
614 {
615  return matrix_.end( col_ );
616 }
617 //*************************************************************************************************
618 
619 
620 //*************************************************************************************************
627 template< typename MT // Type of the sparse matrix
628  , bool SO > // Storage order
630 {
631  return matrix_.end( col_ );
632 }
633 //*************************************************************************************************
634 
635 
636 
637 
638 //=================================================================================================
639 //
640 // ASSIGNMENT OPERATORS
641 //
642 //=================================================================================================
643 
644 //*************************************************************************************************
654 template< typename MT // Type of the sparse matrix
655  , bool SO > // Storage order
657 {
658  using blaze::assign;
659 
660  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
661  return *this;
662 
663  if( size() != rhs.size() )
664  throw std::invalid_argument( "Column sizes do not match" );
665 
666  if( rhs.canAlias( &matrix_ ) ) {
667  const ResultType tmp( rhs );
668  matrix_.reset ( col_ );
669  matrix_.reserve( col_, tmp.nonZeros() );
670  assign( *this, tmp );
671  }
672  else {
673  matrix_.reset ( col_ );
674  matrix_.reserve( col_, rhs.nonZeros() );
675  assign( *this, rhs );
676  }
677 
678  return *this;
679 }
680 //*************************************************************************************************
681 
682 
683 //*************************************************************************************************
693 template< typename MT // Type of the sparse matrix
694  , bool SO > // Storage order
695 template< typename VT > // Type of the right-hand side dense vector
697 {
698  using blaze::assign;
699 
700  if( size() != (~rhs).size() )
701  throw std::invalid_argument( "Vector sizes do not match" );
702 
703  if( (~rhs).canAlias( &matrix_ ) ) {
704  const typename VT::ResultType tmp( ~rhs );
705  matrix_.reset( col_ );
706  assign( *this, tmp );
707  }
708  else {
709  matrix_.reset( col_ );
710  assign( *this, ~rhs );
711  }
712 
713  return *this;
714 }
715 //*************************************************************************************************
716 
717 
718 //*************************************************************************************************
728 template< typename MT // Type of the sparse matrix
729  , bool SO > // Storage order
730 template< typename VT > // Type of the right-hand side sparse vector
732 {
733  using blaze::assign;
734 
735  if( size() != (~rhs).size() )
736  throw std::invalid_argument( "Vector sizes do not match" );
737 
738  if( (~rhs).canAlias( &matrix_ ) ) {
739  const typename VT::ResultType tmp( ~rhs );
740  matrix_.reset ( col_ );
741  matrix_.reserve( col_, tmp.nonZeros() );
742  assign( *this, tmp );
743  }
744  else {
745  matrix_.reset ( col_ );
746  matrix_.reserve( col_, (~rhs).nonZeros() );
747  assign( *this, ~rhs );
748  }
749 
750  return *this;
751 }
752 //*************************************************************************************************
753 
754 
755 //*************************************************************************************************
765 template< typename MT // Type of the sparse matrix
766  , bool SO > // Storage order
767 template< typename VT > // Type of the right-hand side vector
769 {
770  using blaze::addAssign;
771 
772  if( (~rhs).size() != size() )
773  throw std::invalid_argument( "Vector sizes do not match" );
774 
775  addAssign( *this, ~rhs );
776 
777  return *this;
778 }
779 //*************************************************************************************************
780 
781 
782 //*************************************************************************************************
792 template< typename MT // Type of the sparse matrix
793  , bool SO > // Storage order
794 template< typename VT > // Type of the right-hand side vector
796 {
797  using blaze::subAssign;
798 
799  if( (~rhs).size() != size() )
800  throw std::invalid_argument( "Vector sizes do not match" );
801 
802  subAssign( *this, ~rhs );
803 
804  return *this;
805 }
806 //*************************************************************************************************
807 
808 
809 //*************************************************************************************************
820 template< typename MT // Type of the sparse matrix
821  , bool SO > // Storage order
822 template< typename VT > // Type of the right-hand side vector
824 {
825  if( (~rhs).size() != size() )
826  throw std::invalid_argument( "Vector sizes do not match" );
827 
828  typedef typename MultTrait<This,typename VT::ResultType>::Type MultType;
829 
832 
833  const MultType tmp( *this * (~rhs) );
834  matrix_.reset( col_ );
835  assign( tmp );
836 
837  return *this;
838 }
839 //*************************************************************************************************
840 
841 
842 //*************************************************************************************************
853 template< typename MT // Type of the sparse matrix
854  , bool SO > // Storage order
855 template< typename Other > // Data type of the right-hand side scalar
856 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO> >::Type&
858 {
859  for( Iterator element=begin(); element!=end(); ++element )
860  element->value() *= rhs;
861  return *this;
862 }
863 //*************************************************************************************************
864 
865 
866 //*************************************************************************************************
878 template< typename MT // Type of the sparse matrix
879  , bool SO > // Storage order
880 template< typename Other > // Data type of the right-hand side scalar
881 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,SO> >::Type&
883 {
884  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
885 
886  typedef typename DivTrait<ElementType,Other>::Type DT;
887  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
888 
889  // Depending on the two involved data types, an integer division is applied or a
890  // floating point division is selected.
892  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
893  for( Iterator element=begin(); element!=end(); ++element )
894  element->value() *= tmp;
895  }
896  else {
897  for( Iterator element=begin(); element!=end(); ++element )
898  element->value() /= rhs;
899  }
900 
901  return *this;
902 }
903 //*************************************************************************************************
904 
905 
906 
907 
908 //=================================================================================================
909 //
910 // UTILITY FUNCTIONS
911 //
912 //=================================================================================================
913 
914 //*************************************************************************************************
919 template< typename MT // Type of the sparse matrix
920  , bool SO > // Storage order
921 inline size_t SparseColumn<MT,SO>::size() const
922 {
923  return matrix_.rows();
924 }
925 //*************************************************************************************************
926 
927 
928 //*************************************************************************************************
933 template< typename MT // Type of the sparse matrix
934  , bool SO > // Storage order
935 inline size_t SparseColumn<MT,SO>::capacity() const
936 {
937  return matrix_.capacity( col_ );
938 }
939 //*************************************************************************************************
940 
941 
942 //*************************************************************************************************
950 template< typename MT // Type of the sparse matrix
951  , bool SO > // Storage order
952 inline size_t SparseColumn<MT,SO>::nonZeros() const
953 {
954  return matrix_.nonZeros( col_ );
955 }
956 //*************************************************************************************************
957 
958 
959 //*************************************************************************************************
964 template< typename MT // Type of the sparse matrix
965  , bool SO > // Storage order
967 {
968  matrix_.reset( col_ );
969 }
970 //*************************************************************************************************
971 
972 
973 //*************************************************************************************************
985 template< typename MT // Type of the sparse matrix
986  , bool SO > // Storage order
987 inline typename SparseColumn<MT,SO>::ElementType&
988  SparseColumn<MT,SO>::insert( size_t index, const ElementType& value )
989 {
990  return matrix_.insert( index, col_, value )->value();
991 }
992 //*************************************************************************************************
993 
994 
995 //*************************************************************************************************
1003 template< typename MT // Type of the sparse matrix
1004  , bool SO > // Storage order
1005 inline void SparseColumn<MT,SO>::erase( size_t index )
1006 {
1007  matrix_.erase( index, col_ );
1008 }
1009 //*************************************************************************************************
1010 
1011 
1012 //*************************************************************************************************
1020 template< typename MT // Type of the sparse matrix
1021  , bool SO > // Storage order
1023 {
1024  return matrix_.erase( col_, pos );
1025 }
1026 //*************************************************************************************************
1027 
1028 
1029 //*************************************************************************************************
1042 template< typename MT // Type of the sparse matrix
1043  , bool SO > // Storage order
1045 {
1046  return matrix_.find( index, col_ );
1047 }
1048 //*************************************************************************************************
1049 
1050 
1051 //*************************************************************************************************
1064 template< typename MT // Type of the sparse matrix
1065  , bool SO > // Storage order
1067 {
1068  return matrix_.find( index, col_ );
1069 }
1070 //*************************************************************************************************
1071 
1072 
1073 //*************************************************************************************************
1082 template< typename MT // Type of the sparse matrix
1083  , bool SO > // Storage order
1085 {
1086  matrix_.reserve( col_, n );
1087 }
1088 //*************************************************************************************************
1089 
1090 
1091 //*************************************************************************************************
1097 template< typename MT // Type of the sparse matrix
1098  , bool SO > // Storage order
1099 template< typename Other > // Data type of the scalar value
1101 {
1102  for( Iterator element=begin(); element!=end(); ++element )
1103  element->value() *= scalar;
1104  return *this;
1105 }
1106 //*************************************************************************************************
1107 
1108 
1109 //*************************************************************************************************
1117 template< typename MT // Type of the sparse matrix
1118  , bool SO > // Storage order
1120 {
1121  using blaze::max;
1122  using blaze::min;
1123 
1124  size_t nonzeros( 2UL*capacity()+1UL );
1125  nonzeros = max( nonzeros, 7UL );
1126  nonzeros = min( nonzeros, size() );
1127 
1128  BLAZE_INTERNAL_ASSERT( nonzeros > capacity(), "Invalid capacity value" );
1129 
1130  return nonzeros;
1131 }
1132 //*************************************************************************************************
1133 
1134 
1135 
1136 
1137 //=================================================================================================
1138 //
1139 // LOW-LEVEL UTILITY FUNCTIONS
1140 //
1141 //=================================================================================================
1142 
1143 //*************************************************************************************************
1167 template< typename MT // Type of the sparse matrix
1168  , bool SO > // Storage order
1169 inline void SparseColumn<MT,SO>::append( size_t index, const ElementType& value, bool check )
1170 {
1171  matrix_.append( index, col_, value, check );
1172 }
1173 //*************************************************************************************************
1174 
1175 
1176 
1177 
1178 //=================================================================================================
1179 //
1180 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
1181 //
1182 //=================================================================================================
1183 
1184 //*************************************************************************************************
1194 template< typename MT // Type of the sparse matrix
1195  , bool SO > // Storage order
1196 template< typename Other > // Data type of the foreign expression
1197 inline bool SparseColumn<MT,SO>::canAlias( const Other* alias ) const
1198 {
1199  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
1200 }
1201 //*************************************************************************************************
1202 
1203 
1204 //*************************************************************************************************
1214 template< typename MT // Type of the sparse matrix
1215  , bool SO > // Storage order
1216 template< typename Other > // Data type of the foreign expression
1217 inline bool SparseColumn<MT,SO>::isAliased( const Other* alias ) const
1218 {
1219  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
1220 }
1221 //*************************************************************************************************
1222 
1223 
1224 //*************************************************************************************************
1235 template< typename MT // Type of the sparse matrix
1236  , bool SO > // Storage order
1237 template< typename VT > // Type of the right-hand side dense vector
1239 {
1240  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1241 
1242  size_t nonzeros( 0UL );
1243 
1244  for( size_t i=0UL; i<size(); ++i )
1245  {
1246  if( matrix_.nonZeros( col_ ) == matrix_.capacity( col_ ) )
1247  matrix_.reserve( col_, extendCapacity() );
1248 
1249  matrix_.append( i, col_, (~rhs)[i], true );
1250  }
1251 }
1252 //*************************************************************************************************
1253 
1254 
1255 //*************************************************************************************************
1266 template< typename MT // Type of the sparse matrix
1267  , bool SO > // Storage order
1268 template< typename VT > // Type of the right-hand side sparse vector
1270 {
1271  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1272 
1273  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
1274  matrix_.append( element->index(), col_, element->value() );
1275  }
1276 }
1277 //*************************************************************************************************
1278 
1279 
1280 //*************************************************************************************************
1291 template< typename MT // Type of the sparse matrix
1292  , bool SO > // Storage order
1293 template< typename VT > // Type of the right-hand side dense vector
1295 {
1296  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1297 
1301 
1302  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1303 
1304  const AddType tmp( *this + (~rhs) );
1305  matrix_.reset( col_ );
1306  assign( tmp );
1307 }
1308 //*************************************************************************************************
1309 
1310 
1311 //*************************************************************************************************
1322 template< typename MT // Type of the sparse matrix
1323  , bool SO > // Storage order
1324 template< typename VT > // Type of the right-hand side sparse vector
1326 {
1327  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
1328 
1332 
1333  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1334 
1335  const AddType tmp( *this + (~rhs) );
1336  matrix_.reset ( col_ );
1337  matrix_.reserve( col_, tmp.nonZeros() );
1338  assign( tmp );
1339 }
1340 //*************************************************************************************************
1341 
1342 
1343 //*************************************************************************************************
1354 template< typename MT // Type of the sparse matrix
1355  , bool SO > // Storage order
1356 template< typename VT > // Type of the right-hand side dense vector
1358 {
1359  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1360 
1364 
1365  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1366 
1367  const SubType tmp( *this - (~rhs) );
1368  matrix_.reset( col_ );
1369  assign( tmp );
1370 }
1371 //*************************************************************************************************
1372 
1373 
1374 //*************************************************************************************************
1385 template< typename MT // Type of the sparse matrix
1386  , bool SO > // Storage order
1387 template< typename VT > // Type of the right-hand side sparse vector
1389 {
1390  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
1391 
1395 
1396  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
1397 
1398  const SubType tmp( *this - (~rhs) );
1399  matrix_.reset ( col_ );
1400  matrix_.reserve( col_, tmp.nonZeros() );
1401  assign( tmp );
1402 }
1403 //*************************************************************************************************
1404 
1405 
1406 
1407 
1408 
1409 
1410 
1411 
1412 //=================================================================================================
1413 //
1414 // CLASS TEMPLATE SPECIALIZATION FOR ROW-MAJOR MATRICES
1415 //
1416 //=================================================================================================
1417 
1418 //*************************************************************************************************
1426 template< typename MT > // Type of the sparse matrix
1427 class SparseColumn<MT,false> : public SparseVector< SparseColumn<MT,false>, false >
1428  , private Expression
1429 {
1430  private:
1431  //**********************************************************************************************
1433 
1439  enum { useConst = IsConst<MT>::value };
1440  //**********************************************************************************************
1441 
1442  public:
1443  //**Type definitions****************************************************************************
1444  typedef SparseColumn<MT,false> This;
1445  typedef typename ColumnTrait<MT>::Type ResultType;
1446  typedef typename ResultType::TransposeType TransposeType;
1447  typedef typename MT::ElementType ElementType;
1448  typedef typename MT::ReturnType ReturnType;
1449  typedef const ResultType CompositeType;
1450 
1452  typedef typename MT::ConstReference ConstReference;
1453 
1455  typedef typename SelectType< useConst, ConstReference, typename MT::Reference >::Type Reference;
1456  //**********************************************************************************************
1457 
1458  //**ColumnElement class definition**************************************************************
1461  template< typename MatrixType // Type of the sparse matrix
1462  , typename IteratorType > // Type of the sparse matrix iterator
1463  class ColumnElement
1464  {
1465  private:
1466  //*******************************************************************************************
1468 
1473  enum { returnConst = IsConst<MatrixType>::value };
1474  //*******************************************************************************************
1475 
1476  public:
1477  //**Type definitions*************************************************************************
1478  typedef typename SelectType< returnConst, const ElementType&, ElementType& >::Type ReferenceType;
1479  //*******************************************************************************************
1480 
1481  //**Constructor******************************************************************************
1487  inline ColumnElement( IteratorType pos, size_t row )
1488  : pos_( pos ) // Iterator to the current position within the sparse column
1489  , row_( row ) // Index of the according row
1490  {}
1491  //*******************************************************************************************
1492 
1493  //**Assignment operator**********************************************************************
1499  template< typename T > inline ColumnElement& operator=( const T& v ) {
1500  *pos_ = v;
1501  return *this;
1502  }
1503  //*******************************************************************************************
1504 
1505  //**Addition assignment operator*************************************************************
1511  template< typename T > inline ColumnElement& operator+=( const T& v ) {
1512  *pos_ += v;
1513  return *this;
1514  }
1515  //*******************************************************************************************
1516 
1517  //**Subtraction assignment operator**********************************************************
1523  template< typename T > inline ColumnElement& operator-=( const T& v ) {
1524  *pos_ -= v;
1525  return *this;
1526  }
1527  //*******************************************************************************************
1528 
1529  //**Multiplication assignment operator*******************************************************
1535  template< typename T > inline ColumnElement& operator*=( const T& v ) {
1536  *pos_ *= v;
1537  return *this;
1538  }
1539  //*******************************************************************************************
1540 
1541  //**Division assignment operator*************************************************************
1547  template< typename T > inline ColumnElement& operator/=( const T& v ) {
1548  *pos_ /= v;
1549  return *this;
1550  }
1551  //*******************************************************************************************
1552 
1553  //**Element access operator******************************************************************
1558  inline const ColumnElement* operator->() const {
1559  return this;
1560  }
1561  //*******************************************************************************************
1562 
1563  //**Value function***************************************************************************
1568  inline ReferenceType value() const {
1569  return pos_->value();
1570  }
1571  //*******************************************************************************************
1572 
1573  //**Index function***************************************************************************
1578  inline size_t index() const {
1579  return row_;
1580  }
1581  //*******************************************************************************************
1582 
1583  private:
1584  //**Member variables*************************************************************************
1585  IteratorType pos_;
1586  size_t row_;
1587  //*******************************************************************************************
1588  };
1589  //**********************************************************************************************
1590 
1591  //**ColumnIterator class definition*************************************************************
1594  template< typename MatrixType // Type of the sparse matrix
1595  , typename IteratorType > // Type of the sparse matrix iterator
1596  class ColumnIterator
1597  {
1598  private:
1599  //*******************************************************************************************
1601 
1606  enum { returnConst = IsConst<MatrixType>::value };
1607  //*******************************************************************************************
1608 
1609  public:
1610  //**Type definitions*************************************************************************
1611  typedef std::forward_iterator_tag IteratorCategory;
1612  typedef ColumnElement<MatrixType,IteratorType> ValueType;
1613  typedef ValueType PointerType;
1614  typedef ValueType ReferenceType;
1615  typedef ptrdiff_t DifferenceType;
1616 
1617  // STL iterator requirements
1618  typedef IteratorCategory iterator_category;
1619  typedef ValueType value_type;
1620  typedef PointerType pointer;
1621  typedef ReferenceType reference;
1622  typedef DifferenceType difference_type;
1623 
1625  typedef typename SelectType< returnConst, ReturnType, ElementType& >::Type Value;
1626  //*******************************************************************************************
1627 
1628  //**Constructor******************************************************************************
1635  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column )
1636  : matrix_( matrix ) // The sparse matrix containing the column.
1637  , row_ ( row ) // The current row index.
1638  , column_( column ) // The current column index.
1639  , pos_ () // Iterator to the current sparse element.
1640  {
1641  for( ; row_<matrix_.rows(); ++row_ ) {
1642  pos_ = matrix_.find( row_, column_ );
1643  if( pos_ != matrix_.end( row_ ) ) break;
1644  }
1645  }
1646  //*******************************************************************************************
1647 
1648  //**Constructor******************************************************************************
1656  inline ColumnIterator( MatrixType& matrix, size_t row, size_t column, IteratorType pos )
1657  : matrix_( matrix ) // The sparse matrix containing the column.
1658  , row_ ( row ) // The current row index.
1659  , column_( column ) // The current column index.
1660  , pos_ ( pos ) // Iterator to the current sparse element.
1661  {
1662  BLAZE_INTERNAL_ASSERT( matrix.find( row, column ) == pos, "Invalid initial iterator position" );
1663  }
1664  //*******************************************************************************************
1665 
1666  //**Constructor******************************************************************************
1671  template< typename MatrixType2, typename IteratorType2 >
1672  inline ColumnIterator( const ColumnIterator<MatrixType2,IteratorType2>& it )
1673  : matrix_( it.matrix_ ) // The sparse matrix containing the column.
1674  , row_ ( it.row_ ) // The current row index.
1675  , column_( it.column_ ) // The current column index.
1676  , pos_ ( it.pos_ ) // Iterator to the current sparse element.
1677  {}
1678  //*******************************************************************************************
1679 
1680  //**Prefix increment operator****************************************************************
1685  inline ColumnIterator& operator++() {
1686  ++row_;
1687  for( ; row_<matrix_.rows(); ++row_ ) {
1688  pos_ = matrix_.find( row_, column_ );
1689  if( pos_ != matrix_.end( row_ ) ) break;
1690  }
1691 
1692  return *this;
1693  }
1694  //*******************************************************************************************
1695 
1696  //**Postfix increment operator***************************************************************
1701  inline const ColumnIterator operator++( int ) {
1702  const ColumnIterator tmp( *this );
1703  ++(*this);
1704  return tmp;
1705  }
1706  //*******************************************************************************************
1707 
1708  //**Element access operator******************************************************************
1713  inline ReferenceType operator*() const {
1714  return ReferenceType( pos_, row_ );
1715  }
1716  //*******************************************************************************************
1717 
1718  //**Element access operator******************************************************************
1723  inline PointerType operator->() const {
1724  return PointerType( pos_, row_ );
1725  }
1726  //*******************************************************************************************
1727 
1728  //**Equality operator************************************************************************
1734  template< typename MatrixType2, typename IteratorType2 >
1735  inline bool operator==( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
1736  return ( &matrix_ == &rhs.matrix_ ) && ( row_ == rhs.row_ ) && ( column_ == rhs.column_ );
1737  }
1738  //*******************************************************************************************
1739 
1740  //**Inequality operator**********************************************************************
1746  template< typename MatrixType2, typename IteratorType2 >
1747  inline bool operator!=( const ColumnIterator<MatrixType2,IteratorType2>& rhs ) const {
1748  return !( *this == rhs );
1749  }
1750  //*******************************************************************************************
1751 
1752  //**Subtraction operator*********************************************************************
1758  inline DifferenceType operator-( const ColumnIterator& rhs ) const {
1759  size_t counter( 0UL );
1760  for( size_t i=rhs.row_; i<row_; ++i ) {
1761  if( matrix_.find( i, column_ ) != matrix_.end( i ) )
1762  ++counter;
1763  }
1764  return counter;
1765  }
1766  //*******************************************************************************************
1767 
1768  private:
1769  //**Member variables*************************************************************************
1770  MatrixType& matrix_;
1771  size_t row_;
1772  size_t column_;
1773  IteratorType pos_;
1774  //*******************************************************************************************
1775 
1776  //**Friend declarations**********************************************************************
1778  template< typename MatrixType2, typename IteratorType2 > friend class ColumnIterator;
1779  template< typename MT2, bool SO2 > friend class SparseColumn;
1781  //*******************************************************************************************
1782  };
1783  //**********************************************************************************************
1784 
1785  //**Type definitions****************************************************************************
1787  typedef ColumnIterator<const MT,typename MT::ConstIterator> ConstIterator;
1788 
1790  typedef typename SelectType< useConst, ConstIterator, ColumnIterator<MT,typename MT::Iterator> >::Type Iterator;
1791  //**********************************************************************************************
1792 
1793  //**Constructors********************************************************************************
1796  explicit inline SparseColumn( MT& matrix, size_t index );
1797  // No explicitly declared copy constructor.
1799  //**********************************************************************************************
1800 
1801  //**Destructor**********************************************************************************
1802  // No explicitly declared destructor.
1803  //**********************************************************************************************
1804 
1805  //**Data access functions***********************************************************************
1808  inline Reference operator[]( size_t index );
1809  inline ConstReference operator[]( size_t index ) const;
1810  inline Iterator begin ();
1811  inline ConstIterator begin () const;
1812  inline ConstIterator cbegin() const;
1813  inline Iterator end ();
1814  inline ConstIterator end () const;
1815  inline ConstIterator cend () const;
1817  //**********************************************************************************************
1818 
1819  //**Assignment operators************************************************************************
1822  inline SparseColumn& operator= ( const SparseColumn& rhs );
1823  template< typename VT > inline SparseColumn& operator= ( const Vector<VT,false>& rhs );
1824  template< typename VT > inline SparseColumn& operator+=( const Vector<VT,false>& rhs );
1825  template< typename VT > inline SparseColumn& operator-=( const Vector<VT,false>& rhs );
1826  template< typename VT > inline SparseColumn& operator*=( const Vector<VT,false>& rhs );
1827 
1828  template< typename Other >
1829  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
1830  operator*=( Other rhs );
1831 
1832  template< typename Other >
1833  inline typename EnableIf< IsNumeric<Other>, SparseColumn >::Type&
1834  operator/=( Other rhs );
1836  //**********************************************************************************************
1837 
1838  //**Utility functions***************************************************************************
1841  inline size_t size() const;
1842  inline size_t capacity() const;
1843  inline size_t nonZeros() const;
1844  inline void reset();
1845  inline ElementType& insert ( size_t index, const ElementType& value );
1846  inline void erase ( size_t index );
1847  inline Iterator erase ( Iterator pos );
1848  inline Iterator find ( size_t index );
1849  inline ConstIterator find ( size_t index ) const;
1850  inline void reserve( size_t n );
1851  template< typename Other > inline SparseColumn& scale ( Other scalar );
1853  //**********************************************************************************************
1854 
1855  //**Low-level utility functions*****************************************************************
1858  inline void append( size_t index, const ElementType& value, bool check=false );
1860  //**********************************************************************************************
1861 
1862  //**Expression template evaluation functions****************************************************
1865  template< typename Other > inline bool canAlias ( const Other* alias ) const;
1866  template< typename Other > inline bool isAliased( const Other* alias ) const;
1867  template< typename VT > inline void assign ( const DenseVector <VT,false>& rhs );
1868  template< typename VT > inline void assign ( const SparseVector<VT,false>& rhs );
1869  template< typename VT > inline void addAssign( const Vector<VT,false>& rhs );
1870  template< typename VT > inline void subAssign( const Vector<VT,false>& rhs );
1872  //**********************************************************************************************
1873 
1874  private:
1875  //**Member variables****************************************************************************
1878  MT& matrix_;
1879  const size_t col_;
1880 
1881  //**********************************************************************************************
1882 
1883  //**Compile time checks*************************************************************************
1889  //**********************************************************************************************
1890 };
1892 //*************************************************************************************************
1893 
1894 
1895 
1896 
1897 //=================================================================================================
1898 //
1899 // CONSTRUCTOR
1900 //
1901 //=================================================================================================
1902 
1903 //*************************************************************************************************
1911 template< typename MT > // Type of the sparse matrix
1912 inline SparseColumn<MT,false>::SparseColumn( MT& matrix, size_t index )
1913  : matrix_( matrix ) // The sparse matrix containing the column
1914  , col_ ( index ) // The index of the column in the matrix
1915 {
1916  if( matrix_.columns() <= index )
1917  throw std::invalid_argument( "Invalid column access index" );
1918 }
1920 //*************************************************************************************************
1921 
1922 
1923 
1924 
1925 //=================================================================================================
1926 //
1927 // DATA ACCESS FUNCTIONS
1928 //
1929 //=================================================================================================
1930 
1931 //*************************************************************************************************
1938 template< typename MT > // Type of the sparse matrix
1939 inline typename SparseColumn<MT,false>::Reference SparseColumn<MT,false>::operator[]( size_t index )
1940 {
1941  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
1942  return matrix_(index,col_);
1943 }
1945 //*************************************************************************************************
1946 
1947 
1948 //*************************************************************************************************
1955 template< typename MT > // Type of the sparse matrix
1956 inline typename SparseColumn<MT,false>::ConstReference SparseColumn<MT,false>::operator[]( size_t index ) const
1957 {
1958  BLAZE_USER_ASSERT( index < size(), "Invalid column access index" );
1959  return const_cast<const MT&>( matrix_ )(index,col_);
1960 }
1962 //*************************************************************************************************
1963 
1964 
1965 //*************************************************************************************************
1973 template< typename MT > // Type of the sparse matrix
1974 inline typename SparseColumn<MT,false>::Iterator SparseColumn<MT,false>::begin()
1975 {
1976  return Iterator( matrix_, 0UL, col_ );
1977 }
1979 //*************************************************************************************************
1980 
1981 
1982 //*************************************************************************************************
1990 template< typename MT > // Type of the sparse matrix
1991 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::begin() const
1992 {
1993  return ConstIterator( matrix_, 0UL, col_ );
1994 }
1996 //*************************************************************************************************
1997 
1998 
1999 //*************************************************************************************************
2007 template< typename MT > // Type of the sparse matrix
2008 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::cbegin() const
2009 {
2010  return ConstIterator( matrix_, 0UL, col_ );
2011 }
2013 //*************************************************************************************************
2014 
2015 
2016 //*************************************************************************************************
2024 template< typename MT > // Type of the sparse matrix
2025 inline typename SparseColumn<MT,false>::Iterator SparseColumn<MT,false>::end()
2026 {
2027  return Iterator( matrix_, size(), col_ );
2028 }
2030 //*************************************************************************************************
2031 
2032 
2033 //*************************************************************************************************
2041 template< typename MT > // Type of the sparse matrix
2042 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::end() const
2043 {
2044  return ConstIterator( matrix_, size(), col_ );
2045 }
2047 //*************************************************************************************************
2048 
2049 
2050 //*************************************************************************************************
2058 template< typename MT > // Type of the sparse matrix
2059 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::cend() const
2060 {
2061  return ConstIterator( matrix_, size(), col_ );
2062 }
2064 //*************************************************************************************************
2065 
2066 
2067 
2068 
2069 //=================================================================================================
2070 //
2071 // ASSIGNMENT OPERATORS
2072 //
2073 //=================================================================================================
2074 
2075 //*************************************************************************************************
2086 template< typename MT > // Type of the sparse matrix
2087 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator=( const SparseColumn& rhs )
2088 {
2089  using blaze::assign;
2090 
2091  if( this == &rhs || ( &matrix_ == &rhs.matrix_ && col_ == rhs.col_ ) )
2092  return *this;
2093 
2094  if( size() != rhs.size() )
2095  throw std::invalid_argument( "Column sizes do not match" );
2096 
2097  if( rhs.canAlias( &matrix_ ) ) {
2098  const ResultType tmp( rhs );
2099  assign( *this, tmp );
2100  }
2101  else {
2102  assign( *this, rhs );
2103  }
2104 
2105  return *this;
2106 }
2108 //*************************************************************************************************
2109 
2110 
2111 //*************************************************************************************************
2122 template< typename MT > // Type of the sparse matrix
2123 template< typename VT > // Type of the right-hand side vector
2124 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator=( const Vector<VT,false>& rhs )
2125 {
2126  using blaze::assign;
2127 
2128  if( size() != (~rhs).size() )
2129  throw std::invalid_argument( "Vector sizes do not match" );
2130 
2131  const typename VT::CompositeType tmp( ~rhs );
2132  assign( *this, tmp );
2133 
2134  return *this;
2135 }
2137 //*************************************************************************************************
2138 
2139 
2140 //*************************************************************************************************
2151 template< typename MT > // Type of the sparse matrix
2152 template< typename VT > // Type of the right-hand side vector
2153 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator+=( const Vector<VT,false>& rhs )
2154 {
2155  using blaze::addAssign;
2156 
2157  if( (~rhs).size() != size() )
2158  throw std::invalid_argument( "Vector sizes do not match" );
2159 
2160  addAssign( *this, ~rhs );
2161 
2162  return *this;
2163 }
2165 //*************************************************************************************************
2166 
2167 
2168 //*************************************************************************************************
2179 template< typename MT > // Type of the sparse matrix
2180 template< typename VT > // Type of the right-hand side vector
2181 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator-=( const Vector<VT,false>& rhs )
2182 {
2183  using blaze::subAssign;
2184 
2185  if( (~rhs).size() != size() )
2186  throw std::invalid_argument( "Vector sizes do not match" );
2187 
2188  subAssign( *this, ~rhs );
2189 
2190  return *this;
2191 }
2193 //*************************************************************************************************
2194 
2195 
2196 //*************************************************************************************************
2208 template< typename MT > // Type of the sparse matrix
2209 template< typename VT > // Type of the right-hand side vector
2210 inline SparseColumn<MT,false>& SparseColumn<MT,false>::operator*=( const Vector<VT,false>& rhs )
2211 {
2212  if( (~rhs).size() != size() )
2213  throw std::invalid_argument( "Vector sizes do not match" );
2214 
2215  typedef typename MultTrait<This,typename VT::ResultType>::Type MultType;
2216 
2219 
2220  const MultType tmp( *this * (~rhs) );
2221  assign( tmp );
2222 
2223  return *this;
2224 }
2226 //*************************************************************************************************
2227 
2228 
2229 //*************************************************************************************************
2241 template< typename MT > // Type of the sparse matrix
2242 template< typename Other > // Data type of the right-hand side scalar
2243 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false> >::Type&
2244  SparseColumn<MT,false>::operator*=( Other rhs )
2245 {
2246  for( Iterator element=begin(); element!=end(); ++element )
2247  element->value() *= rhs;
2248  return *this;
2249 }
2251 //*************************************************************************************************
2252 
2253 
2254 //*************************************************************************************************
2267 template< typename MT > // Type of the sparse matrix
2268 template< typename Other > // Data type of the right-hand side scalar
2269 inline typename EnableIf< IsNumeric<Other>, SparseColumn<MT,false> >::Type&
2270  SparseColumn<MT,false>::operator/=( Other rhs )
2271 {
2272  BLAZE_USER_ASSERT( rhs != Other(0), "Division by zero detected" );
2273 
2274  typedef typename DivTrait<ElementType,Other>::Type DT;
2275  typedef typename If< IsNumeric<DT>, DT, Other >::Type Tmp;
2276 
2277  // Depending on the two involved data types, an integer division is applied or a
2278  // floating point division is selected.
2279  if( IsNumeric<DT>::value && IsFloatingPoint<DT>::value ) {
2280  const Tmp tmp( Tmp(1)/static_cast<Tmp>( rhs ) );
2281  for( Iterator element=begin(); element!=end(); ++element )
2282  element->value() *= tmp;
2283  }
2284  else {
2285  for( Iterator element=begin(); element!=end(); ++element )
2286  element->value() /= rhs;
2287  }
2288 
2289  return *this;
2290 }
2292 //*************************************************************************************************
2293 
2294 
2295 
2296 
2297 //=================================================================================================
2298 //
2299 // UTILITY FUNCTIONS
2300 //
2301 //=================================================================================================
2302 
2303 //*************************************************************************************************
2309 template< typename MT > // Type of the sparse matrix
2310 inline size_t SparseColumn<MT,false>::size() const
2311 {
2312  return matrix_.rows();
2313 }
2315 //*************************************************************************************************
2316 
2317 
2318 //*************************************************************************************************
2324 template< typename MT > // Type of the sparse matrix
2325 inline size_t SparseColumn<MT,false>::capacity() const
2326 {
2327  return matrix_.rows();
2328 }
2330 //*************************************************************************************************
2331 
2332 
2333 //*************************************************************************************************
2342 template< typename MT > // Type of the sparse matrix
2343 inline size_t SparseColumn<MT,false>::nonZeros() const
2344 {
2345  size_t counter( 0UL );
2346  for( ConstIterator element=begin(); element!=end(); ++element ) {
2347  ++counter;
2348  }
2349  return counter;
2350 }
2352 //*************************************************************************************************
2353 
2354 
2355 //*************************************************************************************************
2361 template< typename MT > // Type of the sparse matrix
2362 inline void SparseColumn<MT,false>::reset()
2363 {
2364  for( size_t i=0UL; i<size(); ++i ) {
2365  matrix_.erase( i, col_ );
2366  }
2367 }
2369 //*************************************************************************************************
2370 
2371 
2372 //*************************************************************************************************
2385 template< typename MT > // Type of the sparse matrix
2386 inline typename SparseColumn<MT,false>::ElementType&
2387  SparseColumn<MT,false>::insert( size_t index, const ElementType& value )
2388 {
2389  return matrix_.insert( index, col_, value )->value();
2390 }
2392 //*************************************************************************************************
2393 
2394 
2395 //*************************************************************************************************
2404 template< typename MT > // Type of the sparse matrix
2405 inline void SparseColumn<MT,false>::erase( size_t index )
2406 {
2407  matrix_.erase( index, col_ );
2408 }
2410 //*************************************************************************************************
2411 
2412 
2413 //*************************************************************************************************
2422 template< typename MT > // Type of the sparse matrix
2423 inline typename SparseColumn<MT,false>::Iterator SparseColumn<MT,false>::erase( Iterator pos )
2424 {
2425  const size_t row( pos.row_ );
2426 
2427  if( row == size() )
2428  return pos;
2429 
2430  matrix_.erase( row, pos.pos_ );
2431  return Iterator( matrix_, row+1UL, col_ );
2432 }
2434 //*************************************************************************************************
2435 
2436 
2437 //*************************************************************************************************
2451 template< typename MT > // Type of the sparse matrix
2452 inline typename SparseColumn<MT,false>::Iterator SparseColumn<MT,false>::find( size_t index )
2453 {
2454  const typename MT::Iterator pos( matrix_.find( index, col_ ) );
2455 
2456  if( pos != matrix_.end( index ) )
2457  return Iterator( matrix_, index, col_, pos );
2458  else
2459  return end();
2460 }
2462 //*************************************************************************************************
2463 
2464 
2465 //*************************************************************************************************
2479 template< typename MT > // Type of the sparse matrix
2480 inline typename SparseColumn<MT,false>::ConstIterator SparseColumn<MT,false>::find( size_t index ) const
2481 {
2482  const typename MT::ConstIterator pos( matrix_.find( index, col_ ) );
2483 
2484  if( pos != matrix_.end( index ) )
2485  return ConstIterator( matrix_, index, col_, pos );
2486  else
2487  return end();
2488 }
2490 //*************************************************************************************************
2491 
2492 
2493 //*************************************************************************************************
2503 template< typename MT > // Type of the sparse matrix
2504 void SparseColumn<MT,false>::reserve( size_t n )
2505 {
2506  return;
2507 }
2509 //*************************************************************************************************
2510 
2511 
2512 //*************************************************************************************************
2519 template< typename MT > // Type of the sparse matrix
2520 template< typename Other > // Data type of the scalar value
2521 inline SparseColumn<MT,false>& SparseColumn<MT,false>::scale( Other scalar )
2522 {
2523  for( Iterator element=begin(); element!=end(); ++element )
2524  element->value() *= scalar;
2525  return *this;
2526 }
2528 //*************************************************************************************************
2529 
2530 
2531 
2532 
2533 //=================================================================================================
2534 //
2535 // LOW-LEVEL UTILITY FUNCTIONS
2536 //
2537 //=================================================================================================
2538 
2539 //*************************************************************************************************
2564 template< typename MT > // Type of the sparse matrix
2565 inline void SparseColumn<MT,false>::append( size_t index, const ElementType& value, bool /*check*/ )
2566 {
2567  matrix_.insert( index, col_, value );
2568 }
2570 //*************************************************************************************************
2571 
2572 
2573 
2574 
2575 //=================================================================================================
2576 //
2577 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
2578 //
2579 //=================================================================================================
2580 
2581 //*************************************************************************************************
2592 template< typename MT > // Type of the sparse matrix
2593 template< typename Other > // Data type of the foreign expression
2594 inline bool SparseColumn<MT,false>::canAlias( const Other* alias ) const
2595 {
2596  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
2597 }
2599 //*************************************************************************************************
2600 
2601 
2602 //*************************************************************************************************
2609 template< typename MT > // Type of the sparse matrix
2610 template< typename Other > // Data type of the foreign expression
2611 inline bool SparseColumn<MT,false>::isAliased( const Other* alias ) const
2612 {
2613  return static_cast<const void*>( &matrix_ ) == static_cast<const void*>( alias );
2614 }
2616 //*************************************************************************************************
2617 
2618 
2619 //*************************************************************************************************
2631 template< typename MT > // Type of the sparse matrix
2632 template< typename VT > // Type of the right-hand side dense vector
2633 inline void SparseColumn<MT,false>::assign( const DenseVector<VT,false>& rhs )
2634 {
2635  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2636 
2637  for( size_t i=0UL; i<(~rhs).size(); ++i ) {
2638  matrix_(i,col_) = (~rhs)[i];
2639  }
2640 }
2642 //*************************************************************************************************
2643 
2644 
2645 //*************************************************************************************************
2657 template< typename MT > // Type of the sparse matrix
2658 template< typename VT > // Type of the right-hand side sparse vector
2659 inline void SparseColumn<MT,false>::assign( const SparseVector<VT,false>& rhs )
2660 {
2661  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2662 
2663  size_t i( 0UL );
2664 
2665  for( typename VT::ConstIterator element=(~rhs).begin(); element!=(~rhs).end(); ++element ) {
2666  for( ; i<element->index(); ++i )
2667  matrix_.erase( i, col_ );
2668  matrix_(i++,col_) = element->value();
2669  }
2670  for( ; i<size(); ++i ) {
2671  matrix_.erase( i, col_ );
2672  }
2673 }
2675 //*************************************************************************************************
2676 
2677 
2678 //*************************************************************************************************
2690 template< typename MT > // Type of the sparse matrix
2691 template< typename VT > // Type of the right-hand side vector
2692 inline void SparseColumn<MT,false>::addAssign( const Vector<VT,false>& rhs )
2693 {
2694  typedef typename AddTrait<This,typename VT::ResultType>::Type AddType;
2695 
2698 
2699  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2700 
2701  const AddType tmp( *this + (~rhs) );
2702  assign( tmp );
2703 }
2705 //*************************************************************************************************
2706 
2707 
2708 //*************************************************************************************************
2720 template< typename MT > // Type of the sparse matrix
2721 template< typename VT > // Type of the right-hand side vector
2722 inline void SparseColumn<MT,false>::subAssign( const Vector<VT,false>& rhs )
2723 {
2724  typedef typename SubTrait<This,typename VT::ResultType>::Type SubType;
2725 
2728 
2729  BLAZE_INTERNAL_ASSERT( size() == (~rhs).size(), "Invalid vector sizes" );
2730 
2731  const SubType tmp( *this - (~rhs) );
2732  assign( tmp );
2733 }
2735 //*************************************************************************************************
2736 
2737 
2738 
2739 
2740 
2741 
2742 
2743 
2744 //=================================================================================================
2745 //
2746 // SPARSECOLUMN OPERATORS
2747 //
2748 //=================================================================================================
2749 
2750 //*************************************************************************************************
2753 template< typename MT, bool SO >
2754 inline void reset( SparseColumn<MT,SO>& column );
2755 
2756 template< typename MT, bool SO >
2757 inline void clear( SparseColumn<MT,SO>& column );
2758 
2759 template< typename MT, bool SO >
2760 inline bool isnan( const SparseColumn<MT,SO>& column );
2761 
2762 template< typename MT, bool SO >
2763 inline bool isDefault( const SparseColumn<MT,SO>& column );
2765 //*************************************************************************************************
2766 
2767 
2768 //*************************************************************************************************
2775 template< typename MT // Type of the sparse matrix
2776  , bool SO > // Storage order
2777 inline void reset( SparseColumn<MT,SO>& column )
2778 {
2779  column.reset();
2780 }
2781 //*************************************************************************************************
2782 
2783 
2784 //*************************************************************************************************
2791 template< typename MT // Type of the sparse matrix
2792  , bool SO > // Storage order
2793 inline void clear( SparseColumn<MT,SO>& column )
2794 {
2795  column.reset();
2796 }
2797 //*************************************************************************************************
2798 
2799 
2800 //*************************************************************************************************
2816 template< typename MT // Type of the sparse matrix
2817  , bool SO > // Storage order
2818 inline bool isnan( const SparseColumn<MT,SO>& column )
2819 {
2820  typedef typename SparseColumn<MT,SO>::ConstIterator ConstIterator;
2821 
2822  const ConstIterator end( column.end() );
2823  for( ConstIterator element=column.begin(); element!=end; ++element ) {
2824  if( isnan( element->value() ) ) return true;
2825  }
2826  return false;
2827 }
2828 //*************************************************************************************************
2829 
2830 
2831 //*************************************************************************************************
2849 template< typename MT // Type of the sparse matrix
2850  , bool SO > // Storage order
2851 inline bool isDefault( const SparseColumn<MT,SO>& column )
2852 {
2853  typedef typename SparseColumn<MT,SO>::ConstIterator ConstIterator;
2854 
2855  const ConstIterator end( column.end() );
2856  for( ConstIterator element=column.begin(); element!=end; ++element )
2857  if( !isDefault( element->value() ) ) return false;
2858  return true;
2859 }
2860 //*************************************************************************************************
2861 
2862 
2863 
2864 
2865 //=================================================================================================
2866 //
2867 // GLOBAL OPERATORS
2868 //
2869 //=================================================================================================
2870 
2871 //*************************************************************************************************
2890 template< typename MT // Type of the sparse matrix
2891  , bool SO > // Storage order
2892 inline SparseColumn<MT> column( SparseMatrix<MT,SO>& sm, size_t index )
2893 {
2895 
2896  return SparseColumn<MT>( ~sm, index );
2897 }
2898 //*************************************************************************************************
2899 
2900 
2901 //*************************************************************************************************
2920 template< typename MT // Type of the sparse matrix
2921  , bool SO > // Storage order
2922 inline SparseColumn<const MT> column( const SparseMatrix<MT,SO>& sm, size_t index )
2923 {
2925 
2926  return SparseColumn<const MT>( ~sm, index );
2927 }
2928 //*************************************************************************************************
2929 
2930 
2931 
2932 
2933 //=================================================================================================
2934 //
2935 // ADDTRAIT SPECIALIZATIONS
2936 //
2937 //=================================================================================================
2938 
2939 //*************************************************************************************************
2941 template< typename T1, bool SO, typename T2, size_t N >
2942 struct AddTrait< SparseColumn<T1,SO>, StaticVector<T2,N,false> >
2943 {
2944  typedef typename AddTrait< typename SparseColumn<T1,SO>::ResultType,
2945  StaticVector<T2,N,false> >::Type Type;
2946 };
2947 
2948 template< typename T1, size_t N, typename T2, bool SO >
2949 struct AddTrait< StaticVector<T1,N,false>, SparseColumn<T2,SO> >
2950 {
2951  typedef typename AddTrait< StaticVector<T1,N,false>,
2952  typename SparseColumn<T2,SO>::ResultType >::Type Type;
2953 };
2954 
2955 template< typename T1, bool SO, typename T2 >
2956 struct AddTrait< SparseColumn<T1,SO>, DynamicVector<T2,false> >
2957 {
2958  typedef typename AddTrait< typename SparseColumn<T1,SO>::ResultType,
2959  DynamicVector<T2,false> >::Type Type;
2960 };
2961 
2962 template< typename T1, typename T2, bool SO >
2963 struct AddTrait< DynamicVector<T1,false>, SparseColumn<T2,SO> >
2964 {
2965  typedef typename AddTrait< DynamicVector<T1,false>,
2966  typename SparseColumn<T2,SO>::ResultType >::Type Type;
2967 };
2968 
2969 template< typename T1, bool SO1, typename T2, bool SO2 >
2970 struct AddTrait< SparseColumn<T1,SO1>, DenseColumn<T2,SO2> >
2971 {
2972  typedef typename AddTrait< typename SparseColumn<T1,SO1>::ResultType,
2973  typename DenseColumn <T2,SO2>::ResultType >::Type Type;
2974 };
2975 
2976 template< typename T1, bool SO1, typename T2, bool SO2 >
2977 struct AddTrait< DenseColumn<T1,SO1>, SparseColumn<T2,SO2> >
2978 {
2979  typedef typename AddTrait< typename DenseColumn <T1,SO1>::ResultType,
2980  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
2981 };
2982 
2983 template< typename T1, bool SO, typename T2 >
2984 struct AddTrait< SparseColumn<T1,SO>, CompressedVector<T2,false> >
2985 {
2986  typedef typename AddTrait< typename SparseColumn<T1,SO>::ResultType,
2987  CompressedVector<T2,false> >::Type Type;
2988 };
2989 
2990 template< typename T1, typename T2, bool SO >
2991 struct AddTrait< CompressedVector<T1,false>, SparseColumn<T2,SO> >
2992 {
2993  typedef typename AddTrait< CompressedVector<T1,false>,
2994  typename SparseColumn<T2,SO>::ResultType >::Type Type;
2995 };
2996 
2997 template< typename T1, bool SO1, typename T2, bool SO2 >
2998 struct AddTrait< SparseColumn<T1,SO1>, SparseColumn<T2,SO2> >
2999 {
3000  typedef typename AddTrait< typename SparseColumn<T1,SO1>::ResultType,
3001  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3002 };
3004 //*************************************************************************************************
3005 
3006 
3007 
3008 
3009 //=================================================================================================
3010 //
3011 // SUBTRAIT SPECIALIZATIONS
3012 //
3013 //=================================================================================================
3014 
3015 //*************************************************************************************************
3017 template< typename T1, bool SO, typename T2, size_t N >
3018 struct SubTrait< SparseColumn<T1,SO>, StaticVector<T2,N,false> >
3019 {
3020  typedef typename SubTrait< typename SparseColumn<T1,SO>::ResultType,
3021  StaticVector<T2,N,false> >::Type Type;
3022 };
3023 
3024 template< typename T1, size_t N, typename T2, bool SO >
3025 struct SubTrait< StaticVector<T1,N,false>, SparseColumn<T2,SO> >
3026 {
3027  typedef typename SubTrait< StaticVector<T1,N,false>,
3028  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3029 };
3030 
3031 template< typename T1, bool SO, typename T2 >
3032 struct SubTrait< SparseColumn<T1,SO>, DynamicVector<T2,false> >
3033 {
3034  typedef typename SubTrait< typename SparseColumn<T1,SO>::ResultType,
3035  DynamicVector<T2,false> >::Type Type;
3036 };
3037 
3038 template< typename T1, typename T2, bool SO >
3039 struct SubTrait< DynamicVector<T1,false>, SparseColumn<T2,SO> >
3040 {
3041  typedef typename SubTrait< DynamicVector<T1,false>,
3042  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3043 };
3044 
3045 template< typename T1, bool SO1, typename T2, bool SO2 >
3046 struct SubTrait< SparseColumn<T1,SO1>, DenseColumn<T2,SO2> >
3047 {
3048  typedef typename SubTrait< typename SparseColumn<T1,SO1>::ResultType,
3049  typename DenseColumn <T2,SO2>::ResultType >::Type Type;
3050 };
3051 
3052 template< typename T1, bool SO1, typename T2, bool SO2 >
3053 struct SubTrait< DenseColumn<T1,SO1>, SparseColumn<T2,SO2> >
3054 {
3055  typedef typename SubTrait< typename DenseColumn <T1,SO1>::ResultType,
3056  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3057 };
3058 
3059 template< typename T1, bool SO, typename T2 >
3060 struct SubTrait< SparseColumn<T1,SO>, CompressedVector<T2,false> >
3061 {
3062  typedef typename SubTrait< typename SparseColumn<T1,SO>::ResultType,
3063  CompressedVector<T2,false> >::Type Type;
3064 };
3065 
3066 template< typename T1, typename T2, bool SO >
3067 struct SubTrait< CompressedVector<T1,false>, SparseColumn<T2,SO> >
3068 {
3069  typedef typename SubTrait< CompressedVector<T1,false>,
3070  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3071 };
3072 
3073 template< typename T1, bool SO1, typename T2, bool SO2 >
3074 struct SubTrait< SparseColumn<T1,SO1>, SparseColumn<T2,SO2> >
3075 {
3076  typedef typename SubTrait< typename SparseColumn<T1,SO1>::ResultType,
3077  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3078 };
3080 //*************************************************************************************************
3081 
3082 
3083 
3084 
3085 //=================================================================================================
3086 //
3087 // MULTTRAIT SPECIALIZATIONS
3088 //
3089 //=================================================================================================
3090 
3091 //*************************************************************************************************
3093 template< typename T1, bool SO, typename T2 >
3094 struct MultTrait< SparseColumn<T1,SO>, T2 >
3095 {
3096  typedef typename MultTrait< typename SparseColumn<T1,SO>::ResultType, T2 >::Type Type;
3098 };
3099 
3100 template< typename T1, typename T2, bool SO >
3101 struct MultTrait< T1, SparseColumn<T2,SO> >
3102 {
3103  typedef typename MultTrait< T1, typename SparseColumn<T2,SO>::ResultType >::Type Type;
3105 };
3106 
3107 template< typename T1, bool SO, typename T2, size_t N, bool TF >
3108 struct MultTrait< SparseColumn<T1,SO>, StaticVector<T2,N,TF> >
3109 {
3110  typedef typename MultTrait< typename SparseColumn<T1,SO>::ResultType,
3111  StaticVector<T2,N,TF> >::Type Type;
3112 };
3113 
3114 template< typename T1, size_t N, bool TF, typename T2, bool SO >
3115 struct MultTrait< StaticVector<T1,N,TF>, SparseColumn<T2,SO> >
3116 {
3117  typedef typename MultTrait< StaticVector<T1,N,TF>,
3118  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3119 };
3120 
3121 template< typename T1, bool SO, typename T2, bool TF >
3122 struct MultTrait< SparseColumn<T1,SO>, DynamicVector<T2,TF> >
3123 {
3124  typedef typename MultTrait< typename SparseColumn<T1,SO>::ResultType,
3125  DynamicVector<T2,TF> >::Type Type;
3126 };
3127 
3128 template< typename T1, bool TF, typename T2, bool SO >
3129 struct MultTrait< DynamicVector<T1,TF>, SparseColumn<T2,SO> >
3130 {
3131  typedef typename MultTrait< DynamicVector<T1,TF>,
3132  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3133 };
3134 
3135 template< typename T1, bool SO1, typename T2, bool SO2 >
3136 struct MultTrait< SparseColumn<T1,SO1>, DenseColumn<T2,SO2> >
3137 {
3138  typedef typename MultTrait< typename SparseColumn<T1,SO1>::ResultType,
3139  typename DenseColumn <T2,SO2>::ResultType >::Type Type;
3140 };
3141 
3142 template< typename T1, bool SO1, typename T2, bool SO2 >
3143 struct MultTrait< DenseColumn<T1,SO1>, SparseColumn<T2,SO2> >
3144 {
3145  typedef typename MultTrait< typename DenseColumn <T1,SO1>::ResultType,
3146  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3147 };
3148 
3149 template< typename T1, bool SO, typename T2, bool TF >
3150 struct MultTrait< SparseColumn<T1,SO>, CompressedVector<T2,TF> >
3151 {
3152  typedef typename MultTrait< typename SparseColumn<T1,SO>::ResultType,
3153  CompressedVector<T2,TF> >::Type Type;
3154 };
3155 
3156 template< typename T1, bool TF, typename T2, bool SO >
3157 struct MultTrait< CompressedVector<T1,TF>, SparseColumn<T2,SO> >
3158 {
3159  typedef typename MultTrait< CompressedVector<T1,TF>,
3160  typename SparseColumn<T2,SO>::ResultType >::Type Type;
3161 };
3162 
3163 template< typename T1, bool SO1, typename T2, bool SO2 >
3164 struct MultTrait< SparseColumn<T1,SO1>, SparseColumn<T2,SO2> >
3165 {
3166  typedef typename MultTrait< typename SparseColumn<T1,SO1>::ResultType,
3167  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3168 };
3169 
3170 template< typename T1, size_t M, size_t N, bool SO1, typename T2, bool SO2 >
3171 struct MultTrait< StaticMatrix<T1,M,N,SO1>, SparseColumn<T2,SO2> >
3172 {
3173  typedef typename MultTrait< StaticMatrix<T1,M,N,SO1>,
3174  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3175 };
3176 
3177 template< typename T1, bool SO1, typename T2, bool SO2 >
3178 struct MultTrait< DynamicMatrix<T1,SO1>, SparseColumn<T2,SO2> >
3179 {
3180  typedef typename MultTrait< DynamicMatrix<T1,SO1>,
3181  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3182 };
3183 
3184 template< typename T1, bool SO1, typename T2, bool SO2 >
3185 struct MultTrait< CompressedMatrix<T1,SO1>, SparseColumn<T2,SO2> >
3186 {
3187  typedef typename MultTrait< CompressedMatrix<T1,SO1>,
3188  typename SparseColumn<T2,SO2>::ResultType >::Type Type;
3189 };
3191 //*************************************************************************************************
3192 
3193 
3194 
3195 
3196 //=================================================================================================
3197 //
3198 // DIVTRAIT SPECIALIZATIONS
3199 //
3200 //=================================================================================================
3201 
3202 //*************************************************************************************************
3204 template< typename T1, bool SO, typename T2 >
3205 struct DivTrait< SparseColumn<T1,SO>, T2 >
3206 {
3207  typedef typename DivTrait< typename SparseColumn<T1,SO>::ResultType, T2 >::Type Type;
3209 };
3211 //*************************************************************************************************
3212 
3213 } // namespace blaze
3214 
3215 #endif