dune-istl 2.12-git
Loading...
Searching...
No Matches
Dune::Experimental::MatrixView< B, P > Class Template Reference

Non-owning matrix view over external block storage and pattern. More...

#include <dune/istl/experimental/matrixview.hh>

Inheritance diagram for Dune::Experimental::MatrixView< B, P >:
Inheritance graph

Classes

class  block_const_iter_type
 Const block iterator adapter. More...
 
class  ConstIterator
 Const random-access iterator over matrix rows. More...
 
class  Iterator
 Mutable random-access iterator over matrix rows. More...
 

Public Types

using block_iter_type = B
 The iterator type used to access the blocks of the matrix.
 
using pattern_type = P
 The type used for the sparsity pattern.
 
using row_index_range_type = std::ranges::range_value_t< pattern_type >
 The type used for the index set of rows.
 
using block_type = std::iter_value_t< block_iter_type >
 The type of blocks in the matrix.
 
using value_type = block_type
 The type of blocks in the matrix.
 
using size_type = std::ranges::range_size_t< pattern_type >
 The type used to count elements in the row and column index sets.
 
using field_type = typename FieldTraits< block_type >::field_type
 The type of the field.
 
using row_type = VectorView< block_iter_type, row_index_range_type >
 The type representing a mutable matrix row.
 
using const_row_type = VectorView< block_const_iter_type, row_index_range_type >
 The type representing a const matrix row.
 
using iterator = Iterator
 The type of mutable matrix iterators over the rows.
 
using const_iterator = ConstIterator
 The type of const matrix iterators over the rows.
 
using RowIterator = Iterator
 The type of mutable matrix iterators over the rows.
 
using ConstRowIterator = ConstIterator
 The type of const matrix iterators over the rows.
 
using ColIterator = typename row_type::iterator
 The type of mutable row iterators over the column blocks.
 
using ConstColIterator = typename const_row_type::const_iterator
 The type of const row iterators over the column blocks.
 

Public Member Functions

 MatrixView (block_iter_type block_iter, pattern_type const *pattern_ptr) noexcept
 Construct a view from data iterator and sparsity pattern.
 
row_type operator[] (size_type i)
 Return a mutable view of row i.
 
const_row_type operator[] (size_type i) const
 Return a const view of row i.
 
Iterator begin ()
 Return iterator to the first row.
 
Iterator end ()
 Return iterator one past the last row.
 
ConstIterator begin () const
 Return const iterator to the first row.
 
ConstIterator end () const
 Return const iterator one past the last row.
 
ConstIterator cbegin () const
 Return const iterator to the first row.
 
ConstIterator cend () const
 Return const iterator one past the last row.
 
template<class OtherB , class OtherI >
MatrixView & axpy (field_type alpha, const MatrixView< OtherB, OtherI > &b)
 Compute \(this \leftarrow this + \alpha b\).
 
template<class X , class Y >
void mv (const X &x, Y &y) const
 Compute \(y = Ax\).
 
template<class X , class Y >
void umv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= Ax\).
 
template<class X , class Y >
void mmv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= Ax\).
 
template<class X , class Y >
void usmv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha Ax\).
 
template<class X , class Y >
void mtv (const X &x, Y &y) const
 Compute \(y = A^T x\).
 
template<class X , class Y >
void umtv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= A^T x\).
 
template<class X , class Y >
void mmtv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= A^T x\).
 
template<class X , class Y >
void usmtv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha A^T x\).
 
template<class X , class Y >
void umhv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= A^H x\) (Hermitian transpose).
 
template<class X , class Y >
void mmhv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= A^H x\) (Hermitian transpose).
 
template<class X , class Y >
void usmhv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha A^H x\) (Hermitian transpose).
 
FieldTraits< field_type >::real_type frobenius_norm2 () const
 Return \(\|A\|_F^2\) (sum of squared block Frobenius norms).
 
FieldTraits< field_type >::real_type frobenius_norm () const
 Return the Frobenius norm \(\|A\|_F\).
 
FieldTraits< field_type >::real_type infinity_norm () const
 Return the block-aware infinity norm.
 
FieldTraits< field_type >::real_type infinity_norm_real () const
 Return simplified infinity norm (Manhattan norm for complex values).
 
bool exists (size_type i, size_type j) const DUNE_ISTL_WITH_CHECKING_NOEXCEPT
 Test whether position \((i,j)\) is present in the sparsity pattern.
 
size_type N () const
 Number of block rows.
 
size_type M () const
 Number of block columns.
 
size_type nonzeroes () const
 Number of stored block entries.
 
MatrixView & operator*= (const field_type &k)
 Scale all stored blocks by k.
 
MatrixView & operator/= (const field_type &k)
 Divide all stored blocks by k.
 
template<class OtherB , class OtherI >
MatrixView & operator+= (const MatrixView< OtherB, OtherI > &b)
 Add another matrix view to this one.
 
template<class OtherB , class OtherI >
MatrixView & operator-= (const MatrixView< OtherB, OtherI > &b)
 Subtract another matrix view from this one.
 
MatrixView & operator= (const field_type &k)
 Assign all stored blocks to scalar k.
 
const pattern_type & pattern () const
 
template<class OtherB , class OtherI >
MatrixView< B, I > & operator+= (const MatrixView< OtherB, OtherI > &b)
 
template<class OtherB , class OtherI >
MatrixView< B, I > & operator-= (const MatrixView< OtherB, OtherI > &b)
 
template<class OtherB , class OtherI >
MatrixView< B, I > & axpy (field_type alpha, const MatrixView< OtherB, OtherI > &b)
 

Protected Member Functions

void resetView (block_iter_type block_iter, pattern_type const *pattern_ptr)
 Reset the view to point to block_iter and pattern_ptr.
 
block_iter_type blockIter ()
 Return the underlying block iterator.
 
block_const_iter_type blockIter () const
 Return the underlying block iterator as a const iterator.
 
pattern_type const * patternPtr () const
 Return the underlying pattern pointer.
 

Detailed Description

template<std::random_access_iterator B, class P>
class Dune::Experimental::MatrixView< B, P >

Non-owning matrix view over external block storage and pattern.

MatrixView binds two external objects:

  • a random-access iterator to block values,
  • a pattern that defines row offsets and column indices.

The block iterator is expected to point to at least pattern().count() blocks, which are interpreted in row-major order consistent with index ranges of pattern_type. That is, entries of row \(i\) start at an offset given by pattern().offset(i) and follow the column indices in pattern()[i].

The view does not own memory. The caller must ensure that both the data range and the pattern outlive the view. The pattern is treated as read-only for the lifetime of the view.

A pattern is a sized range of BorrowedOrderedIndexRange with three extra methods:

  • offset(i) counts the total number of entries in rows \(0\) to \(i-1\).
  • count() counts the total number of entries in the matrix.
  • range() returns the logical range of row indices.
Template Parameters
BRandom-access iterator type for matrix blocks.
PPattern type with row ranges and offsets.

Member Typedef Documentation

◆ block_iter_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::block_iter_type = B

The iterator type used to access the blocks of the matrix.

◆ block_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::block_type = std::iter_value_t<block_iter_type>

The type of blocks in the matrix.

◆ ColIterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::ColIterator = typename row_type::iterator

The type of mutable row iterators over the column blocks.

◆ const_iterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::const_iterator = ConstIterator

The type of const matrix iterators over the rows.

◆ const_row_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::const_row_type = VectorView<block_const_iter_type, row_index_range_type>

The type representing a const matrix row.

◆ ConstColIterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::ConstColIterator = typename const_row_type::const_iterator

The type of const row iterators over the column blocks.

◆ ConstRowIterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::ConstRowIterator = ConstIterator

The type of const matrix iterators over the rows.

◆ field_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::field_type = typename FieldTraits<block_type>::field_type

The type of the field.

◆ iterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::iterator = Iterator

The type of mutable matrix iterators over the rows.

◆ pattern_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::pattern_type = P

The type used for the sparsity pattern.

◆ row_index_range_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::row_index_range_type = std::ranges::range_value_t<pattern_type>

The type used for the index set of rows.

◆ row_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::row_type = VectorView<block_iter_type, row_index_range_type>

The type representing a mutable matrix row.

◆ RowIterator

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::RowIterator = Iterator

The type of mutable matrix iterators over the rows.

◆ size_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::size_type = std::ranges::range_size_t<pattern_type>

The type used to count elements in the row and column index sets.

◆ value_type

template<std::random_access_iterator B, class P >
using Dune::Experimental::MatrixView< B, P >::value_type = block_type

The type of blocks in the matrix.

Constructor & Destructor Documentation

◆ MatrixView()

template<std::random_access_iterator B, class P >
Dune::Experimental::MatrixView< B, P >::MatrixView ( block_iter_type  block_iter,
pattern_type const *  pattern_ptr 
)
inlinenoexcept

Construct a view from data iterator and sparsity pattern.

Parameters
dataIterator to the first stored block.
pattern_ptrPointer to the external sparsity pattern.

Member Function Documentation

◆ axpy() [1/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView & Dune::Experimental::MatrixView< B, P >::axpy ( field_type  alpha,
const MatrixView< OtherB, OtherI > &  b 
)

Compute \(this \leftarrow this + \alpha b\).

◆ axpy() [2/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::axpy ( field_type  alpha,
const MatrixView< OtherB, OtherI > &  b 
)

◆ begin() [1/2]

template<std::random_access_iterator B, class P >
Iterator Dune::Experimental::MatrixView< B, P >::begin ( )
inline

Return iterator to the first row.

◆ begin() [2/2]

template<std::random_access_iterator B, class P >
ConstIterator Dune::Experimental::MatrixView< B, P >::begin ( ) const
inline

Return const iterator to the first row.

◆ blockIter() [1/2]

template<std::random_access_iterator B, class P >
block_iter_type Dune::Experimental::MatrixView< B, P >::blockIter ( )
inlineprotected

Return the underlying block iterator.

◆ blockIter() [2/2]

template<std::random_access_iterator B, class P >
block_const_iter_type Dune::Experimental::MatrixView< B, P >::blockIter ( ) const
inlineprotected

Return the underlying block iterator as a const iterator.

◆ cbegin()

template<std::random_access_iterator B, class P >
ConstIterator Dune::Experimental::MatrixView< B, P >::cbegin ( ) const
inline

Return const iterator to the first row.

◆ cend()

template<std::random_access_iterator B, class P >
ConstIterator Dune::Experimental::MatrixView< B, P >::cend ( ) const
inline

Return const iterator one past the last row.

◆ end() [1/2]

template<std::random_access_iterator B, class P >
Iterator Dune::Experimental::MatrixView< B, P >::end ( )
inline

Return iterator one past the last row.

◆ end() [2/2]

template<std::random_access_iterator B, class P >
ConstIterator Dune::Experimental::MatrixView< B, P >::end ( ) const
inline

Return const iterator one past the last row.

◆ exists()

template<std::random_access_iterator B, class P >
bool Dune::Experimental::MatrixView< B, P >::exists ( size_type  i,
size_type  j 
) const
inline

Test whether position \((i,j)\) is present in the sparsity pattern.

This checks structural existence only. It does not inspect value magnitude.

Exceptions
BCRSMatrixErrorif \(i\) or \(j\) is out of range if DUNE_ISTL_WITH_CHECKING is defined.

◆ frobenius_norm()

template<std::random_access_iterator B, class I >
auto Dune::Experimental::MatrixView< B, I >::frobenius_norm ( ) const

Return the Frobenius norm \(\|A\|_F\).

◆ frobenius_norm2()

template<std::random_access_iterator B, class I >
auto Dune::Experimental::MatrixView< B, I >::frobenius_norm2 ( ) const

Return \(\|A\|_F^2\) (sum of squared block Frobenius norms).

◆ infinity_norm()

template<std::random_access_iterator B, class I >
auto Dune::Experimental::MatrixView< B, I >::infinity_norm ( ) const

Return the block-aware infinity norm.

◆ infinity_norm_real()

template<std::random_access_iterator B, class I >
auto Dune::Experimental::MatrixView< B, I >::infinity_norm_real ( ) const

Return simplified infinity norm (Manhattan norm for complex values).

infinity norm (maximum of absolute values of entries)

◆ M()

template<std::random_access_iterator B, class P >
size_type Dune::Experimental::MatrixView< B, P >::M ( ) const
inline

Number of block columns.

◆ mmhv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::mmhv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{-}= A^H x\) (Hermitian transpose).

◆ mmtv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::mmtv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{-}= A^T x\).

◆ mmv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::mmv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{-}= Ax\).

◆ mtv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::mtv ( const X &  x,
Y &  y 
) const

Compute \(y = A^T x\).

◆ mv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::mv ( const X &  x,
Y &  y 
) const

Compute \(y = Ax\).

◆ N()

template<std::random_access_iterator B, class P >
size_type Dune::Experimental::MatrixView< B, P >::N ( ) const
inline

Number of block rows.

◆ nonzeroes()

template<std::random_access_iterator B, class P >
size_type Dune::Experimental::MatrixView< B, P >::nonzeroes ( ) const
inline

Number of stored block entries.

This is the number of structurally present entries, i.e., entries that may be nonzero.

◆ operator*=()

template<std::random_access_iterator B, class I >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, I >::operator*= ( const field_type &  k)

Scale all stored blocks by k.

◆ operator+=() [1/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView & Dune::Experimental::MatrixView< B, P >::operator+= ( const MatrixView< OtherB, OtherI > &  b)

Add another matrix view to this one.

Parameters
bThe matrix to add to this one. Its sparsity pattern has to be subset of the sparsity pattern of this matrix.

◆ operator+=() [2/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::operator+= ( const MatrixView< OtherB, OtherI > &  b)

◆ operator-=() [1/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView & Dune::Experimental::MatrixView< B, P >::operator-= ( const MatrixView< OtherB, OtherI > &  b)

Subtract another matrix view from this one.

Parameters
bThe matrix to subtract from this one. Its sparsity pattern has to be subset of the sparsity pattern of this matrix.

◆ operator-=() [2/2]

template<std::random_access_iterator B, class P >
template<class OtherB , class OtherI >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::operator-= ( const MatrixView< OtherB, OtherI > &  b)

◆ operator/=()

template<std::random_access_iterator B, class I >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, I >::operator/= ( const field_type &  k)

Divide all stored blocks by k.

◆ operator=()

template<std::random_access_iterator B, class I >
MatrixView< B, I > & Dune::Experimental::MatrixView< B, I >::operator= ( const field_type &  k)

Assign all stored blocks to scalar k.

◆ operator[]() [1/2]

template<std::random_access_iterator B, class P >
row_type Dune::Experimental::MatrixView< B, P >::operator[] ( size_type  i)
inline

Return a mutable view of row i.

◆ operator[]() [2/2]

template<std::random_access_iterator B, class P >
const_row_type Dune::Experimental::MatrixView< B, P >::operator[] ( size_type  i) const
inline

Return a const view of row i.

◆ pattern()

template<std::random_access_iterator B, class P >
const pattern_type & Dune::Experimental::MatrixView< B, P >::pattern ( ) const
inline

◆ patternPtr()

template<std::random_access_iterator B, class P >
pattern_type const * Dune::Experimental::MatrixView< B, P >::patternPtr ( ) const
inlineprotected

Return the underlying pattern pointer.

◆ resetView()

template<std::random_access_iterator B, class P >
void Dune::Experimental::MatrixView< B, P >::resetView ( block_iter_type  block_iter,
pattern_type const *  pattern_ptr 
)
inlineprotected

Reset the view to point to block_iter and pattern_ptr.

◆ umhv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::umhv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= A^H x\) (Hermitian transpose).

◆ umtv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::umtv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= A^T x\).

◆ umv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::umv ( const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= Ax\).

◆ usmhv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::usmhv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= \alpha A^H x\) (Hermitian transpose).

◆ usmtv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::usmtv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= \alpha A^T x\).

◆ usmv()

template<std::random_access_iterator B, class I >
template<class X , class Y >
void Dune::Experimental::MatrixView< B, I >::usmv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const

Compute \(y \mathrel{+}= \alpha Ax\).


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