Reference documentation for deal.II version Git 7f58f27 2017-09-20 15:35:49 -0600
Public Types | Public Member Functions | Private Attributes | List of all members
SparseMatrixIterators::Iterator< number, Constness > Class Template Reference

#include <deal.II/lac/sparse_matrix.h>

Public Types

typedef Accessor< number, Constness >::MatrixType MatrixType
 
typedef const Accessor< number, Constness > & value_type
 

Public Member Functions

 Iterator (MatrixType *matrix, const std::size_t index_within_matrix)
 
 Iterator (MatrixType *matrix)
 
 Iterator (const SparseMatrixIterators::Iterator< number, false > &i)
 
Iteratoroperator++ ()
 
Iterator operator++ (int)
 
const Accessor< number, Constness > & operator* () const
 
const Accessor< number, Constness > * operator-> () const
 
bool operator== (const Iterator &) const
 
bool operator!= (const Iterator &) const
 
bool operator< (const Iterator &) const
 
bool operator> (const Iterator &) const
 
int operator- (const Iterator &p) const
 
Iterator operator+ (const size_type n) const
 

Private Attributes

Accessor< number, Constness > accessor
 

Detailed Description

template<typename number, bool Constness>
class SparseMatrixIterators::Iterator< number, Constness >

Iterator for constant and non-constant matrices.

The typical use for these iterators is to iterate over the elements of a sparse matrix or over the elements of individual rows. Note that there is no guarantee that the elements of a row are actually traversed in an order in which columns monotonically increase. See the documentation of the SparsityPattern class for more information.

The first template argument denotes the underlying numeric type, the second the constness of the matrix.

Since there is a specialization of this class for Constness=false, this class is for iterators to constant matrices.

Note
This class operates directly on the internal data structures of the SparsityPattern and SparseMatrix classes. As a consequence, some operations are cheap and some are not. In particular, it is cheap to access the column index and the value of an entry pointed to. On the other hand, it is expensive to access the row index (this requires \(O(\log(N))\) operations for a matrix with \(N\) row). As a consequence, when you design algorithms that use these iterators, it is common practice to not loop over all elements of a sparse matrix at once, but to have an outer loop over all rows and within this loop iterate over the elements of this row. This way, you only ever need to dereference the iterator to obtain the column indices and values whereas the (expensive) lookup of the row index can be avoided by using the loop index instead.

Definition at line 63 of file sparse_matrix.h.

Member Typedef Documentation

template<typename number, bool Constness>
typedef Accessor<number,Constness>::MatrixType SparseMatrixIterators::Iterator< number, Constness >::MatrixType

Typedef for the matrix type (including constness) we are to operate on.

Definition at line 329 of file sparse_matrix.h.

template<typename number, bool Constness>
typedef const Accessor<number,Constness>& SparseMatrixIterators::Iterator< number, Constness >::value_type

A typedef for the type you get when you dereference an iterator of the current kind.

Definition at line 336 of file sparse_matrix.h.

Constructor & Destructor Documentation

template<typename number, bool Constness>
SparseMatrixIterators::Iterator< number, Constness >::Iterator ( MatrixType matrix,
const std::size_t  index_within_matrix 
)

Constructor. Create an iterator into the matrix matrix for the given index in the complete matrix (counting from the zeroth entry).

template<typename number, bool Constness>
SparseMatrixIterators::Iterator< number, Constness >::Iterator ( MatrixType matrix)

Constructor. Create the end iterator for the given matrix.

template<typename number, bool Constness>
SparseMatrixIterators::Iterator< number, Constness >::Iterator ( const SparseMatrixIterators::Iterator< number, false > &  i)

Conversion constructor to get from a non-const iterator to a const iterator.

Member Function Documentation

template<typename number, bool Constness>
Iterator& SparseMatrixIterators::Iterator< number, Constness >::operator++ ( )

Prefix increment.

template<typename number, bool Constness>
Iterator SparseMatrixIterators::Iterator< number, Constness >::operator++ ( int  )

Postfix increment.

template<typename number, bool Constness>
const Accessor<number,Constness>& SparseMatrixIterators::Iterator< number, Constness >::operator* ( ) const

Dereferencing operator.

template<typename number, bool Constness>
const Accessor<number,Constness>* SparseMatrixIterators::Iterator< number, Constness >::operator-> ( ) const

Dereferencing operator.

template<typename number, bool Constness>
bool SparseMatrixIterators::Iterator< number, Constness >::operator== ( const Iterator< number, Constness > &  ) const

Comparison. True, if both iterators point to the same matrix position.

template<typename number, bool Constness>
bool SparseMatrixIterators::Iterator< number, Constness >::operator!= ( const Iterator< number, Constness > &  ) const

Inverse of ==.

template<typename number, bool Constness>
bool SparseMatrixIterators::Iterator< number, Constness >::operator< ( const Iterator< number, Constness > &  ) const

Comparison operator. Result is true if either the first row number is smaller or if the row numbers are equal and the first index is smaller.

This function is only valid if both iterators point into the same matrix.

template<typename number, bool Constness>
bool SparseMatrixIterators::Iterator< number, Constness >::operator> ( const Iterator< number, Constness > &  ) const

Comparison operator. Works in the same way as above operator, just the other way round.

template<typename number, bool Constness>
int SparseMatrixIterators::Iterator< number, Constness >::operator- ( const Iterator< number, Constness > &  p) const

Return the distance between the current iterator and the argument. The distance is given by how many times one has to apply operator++ to the current iterator to get the argument (for a positive return value), or operator-- (for a negative return value).

template<typename number, bool Constness>
Iterator SparseMatrixIterators::Iterator< number, Constness >::operator+ ( const size_type  n) const

Return an iterator that is n ahead of the current one.

Member Data Documentation

template<typename number, bool Constness>
Accessor<number,Constness> SparseMatrixIterators::Iterator< number, Constness >::accessor
private

Store an object of the accessor class.

Definition at line 418 of file sparse_matrix.h.


The documentation for this class was generated from the following file: