Loading...
Searching...
No Matches
matrix.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_MATRIX_HH
#define DUNE_ISTL_MATRIX_HH
#include <cmath>
#include <memory>
#include <dune/common/ftraits.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/scalarvectorview.hh>
#include <dune/common/scalarmatrixview.hh>
#include <dune/istl/bvector.hh>
#include <dune/istl/istlexception.hh>
#include <dune/istl/blocklevel.hh>
namespace Dune {
namespace MatrixImp
{
template<class B, class A=std::allocator<B> >
class DenseMatrixBase : public Imp::block_vector_unmanaged<B,typename A::size_type>
// this derivation gives us all the blas level 1 and norms
// on the large array. However, access operators have to be
// overwritten.
{
public:
//===== type definitions and constants
using field_type = typename Imp::BlockTraits<B>::field_type;
typedef A allocator_type;
typedef typename A::size_type size_type;
typedef BlockVector<B,A> value_type;
typedef BlockVector<B,A> block_type;
// just a shorthand
typedef Imp::BlockVectorWindow<B,A> window_type;
typedef window_type reference;
typedef const window_type const_reference;
//===== constructors and such
DenseMatrixBase () : Imp::block_vector_unmanaged<B,size_type>()
{
// nothing is known ...
rows_ = 0;
columns_ = 0;
}
DenseMatrixBase (size_type rows, size_type columns) : Imp::block_vector_unmanaged<B,size_type>()
{
// and we can allocate the big array in the base class
this->n = rows*columns;
columns_ = columns;
if (this->n>0)
{
this->p = allocator_.allocate(this->n);
new (this->p)B[this->n];
}
else
{
this->n = 0;
this->p = 0;
}
// we can allocate the windows now
rows_ = rows;
}
DenseMatrixBase (const DenseMatrixBase& a)
{
// allocate the big array in the base class
this->n = a.n;
columns_ = a.columns_;
if (this->n>0)
{
// allocate and construct objects
this->p = allocator_.allocate(this->n);
new (this->p)B[this->n];
// copy data
for (size_type i=0; i<this->n; i++)
this->p[i]=a.p[i];
}
else
{
this->n = 0;
this->p = nullptr;
}
// we can allocate the windows now
rows_ = a.rows_;
}
~DenseMatrixBase ()
{
if (this->n>0) {
size_type i=this->n;
while (i)
this->p[--i].~B();
allocator_.deallocate(this->p,this->n);
}
}
void resize (size_type rows, size_type columns)
{
// deconstruct objects and deallocate memory if necessary
if (this->n>0) {
size_type i=this->n;
while (i)
this->p[--i].~B();
allocator_.deallocate(this->p,this->n);
}
// and we can allocate the big array in the base class
this->n = rows*columns;
if (this->n>0)
{
this->p = allocator_.allocate(this->n);
new (this->p)B[this->n];
}
else
{
this->n = 0;
this->p = nullptr;
}
// we can allocate the windows now
rows_ = rows;
columns_ = columns;
}
DenseMatrixBase& operator= (const DenseMatrixBase& a)
{
if (&a!=this) // check if this and a are different objects
{
columns_ = a.columns_;
// reallocate arrays if necessary
// Note: still the block sizes may vary !
if (this->n!=a.n || rows_!=a.rows_)
{
// deconstruct objects and deallocate memory if necessary
if (this->n>0) {
size_type i=this->n;
while (i)
this->p[--i].~B();
allocator_.deallocate(this->p,this->n);
}
// allocate the big array in the base class
this->n = a.n;
if (this->n>0)
{
// allocate and construct objects
this->p = allocator_.allocate(this->n);
new (this->p)B[this->n];
}
else
{
this->n = 0;
this->p = nullptr;
}
// Copy number of rows
rows_ = a.rows_;
}
// and copy the data
for (size_type i=0; i<this->n; i++)
this->p[i]=a.p[i];
}
return *this;
}
//===== assignment from scalar
DenseMatrixBase& operator= (const field_type& k)
{
(static_cast<Imp::block_vector_unmanaged<B,size_type>&>(*this)) = k;
return *this;
}
//===== access to components
// has to be overwritten from base class because it must
// return access to the windows
reference operator[] (size_type i)
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (i>=rows_) DUNE_THROW(ISTLError,"index out of range");
#endif
return window_type(this->p + i*columns_, columns_);
}
const_reference operator[] (size_type i) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (i<0 || i>=rows_) DUNE_THROW(ISTLError,"index out of range");
#endif
return window_type(this->p + i*columns_, columns_);
}
// forward declaration
class ConstIterator;
class Iterator
{
public:
Iterator ()
: window_(nullptr,0)
{
i = 0;
}
Iterator (Iterator& other) = default;
Iterator (Iterator&& other) = default;
Iterator (B* data, size_type columns, size_type _i)
: i(_i),
window_(data + _i*columns, columns)
{}
Iterator& operator=(Iterator&& other)
{
i = other.i;
// Do NOT use window_.operator=, because that copies the window content, not just the window!
window_.set(other.window_.getsize(),other.window_.getptr());
return *this;
}
Iterator& operator=(Iterator& other)
{
i = other.i;
// Do NOT use window_.operator=, because that copies the window content, not just the window!
window_.set(other.window_.getsize(),other.window_.getptr());
return *this;
}
Iterator& operator++()
{
++i;
window_.setptr(window_.getptr()+window_.getsize());
return *this;
}
Iterator& operator--()
{
--i;
window_.setptr(window_.getptr()-window_.getsize());
return *this;
}
bool operator== (const Iterator& it) const
{
return window_.getptr() == it.window_.getptr();
}
bool operator!= (const Iterator& it) const
{
return window_.getptr() != it.window_.getptr();
}
bool operator== (const ConstIterator& it) const
{
return window_.getptr() == it.window_.getptr();
}
bool operator!= (const ConstIterator& it) const
{
return window_.getptr() != it.window_.getptr();
}
window_type& operator* () const
{
return window_;
}
window_type* operator-> () const
{
return &window_;
}
// return index corresponding to pointer
size_type index () const
{
return i;
}
friend class ConstIterator;
private:
size_type i;
mutable window_type window_;
};
Iterator begin ()
{
return Iterator(this->p, columns_, 0);
}
Iterator end ()
{
return Iterator(this->p, columns_, rows_);
}
Iterator beforeEnd ()
{
return Iterator(this->p, columns_, rows_-1);
}
Iterator beforeBegin () const
{
return Iterator(this->p, columns_, -1);
}
Iterator find (size_type i)
{
return Iterator(this->p, columns_, std::min(i,rows_));
}
ConstIterator find (size_type i) const
{
return ConstIterator(this->p, columns_, std::min(i,rows_));
}
class ConstIterator
{
public:
ConstIterator ()
: window_(nullptr,0)
{
i = 0;
}
ConstIterator (const B* data, size_type columns, size_type _i)
: i(_i),
window_(const_cast<B*>(data + _i * columns), columns)
{}
ConstIterator (const Iterator& it)
: i(it.i), window_(it.window_.getptr(),it.window_.getsize())
{}
ConstIterator& operator=(Iterator&& other)
{
i = other.i;
// Do NOT use window_.operator=, because that copies the window content, not just the window!
window_.set(other.window_.getsize(),other.window_.getptr());
return *this;
}
ConstIterator& operator=(Iterator& other)
{
i = other.i;
// Do NOT use window_.operator=, because that copies the window content, not just the window!
window_.set(other.window_.getsize(),other.window_.getptr());
return *this;
}
ConstIterator& operator++()
{
++i;
window_.setptr(window_.getptr()+window_.getsize());
return *this;
}
ConstIterator& operator--()
{
--i;
window_.setptr(window_.getptr()-window_.getsize());
return *this;
}
bool operator== (const ConstIterator& it) const
{
return window_.getptr() == it.window_.getptr();
}
bool operator!= (const ConstIterator& it) const
{
return window_.getptr() != it.window_.getptr();
}
bool operator== (const Iterator& it) const
{
return window_.getptr() == it.window_.getptr();
}
bool operator!= (const Iterator& it) const
{
return window_.getptr() != it.window_.getptr();
}
const window_type& operator* () const
{
return window_;
}
const window_type* operator-> () const
{
return &window_;
}
// return index corresponding to pointer
size_type index () const
{
return i;
}
friend class Iterator;
private:
size_type i;
mutable window_type window_;
};
using iterator = Iterator;
using const_iterator = ConstIterator;
ConstIterator begin () const
{
return ConstIterator(this->p, columns_, 0);
}
ConstIterator end () const
{
return ConstIterator(this->p, columns_, rows_);
}
ConstIterator beforeEnd() const
{
return ConstIterator(this->p, columns_, rows_-1);
}
ConstIterator rend () const
{
return ConstIterator(this->p, columns_, -1);
}
//===== sizes
size_type N () const
{
return rows_;
}
private:
size_type rows_; // number of matrix rows
size_type columns_; // number of matrix columns
A allocator_;
};
} // namespace MatrixImp
template<class T, class A=std::allocator<T> >
class Matrix
{
public:
using field_type = typename Imp::BlockTraits<T>::field_type;
typedef T block_type;
typedef A allocator_type;
typedef typename MatrixImp::DenseMatrixBase<T,A>::window_type row_type;
typedef typename A::size_type size_type;
typedef typename MatrixImp::DenseMatrixBase<T,A>::Iterator RowIterator;
typedef typename row_type::iterator ColIterator;
typedef typename MatrixImp::DenseMatrixBase<T,A>::ConstIterator ConstRowIterator;
typedef typename row_type::const_iterator ConstColIterator;
Matrix() : data_(0,0), cols_(0)
{}
Matrix(size_type rows, size_type cols) : data_(rows,cols), cols_(cols)
{}
void setSize(size_type rows, size_type cols) {
data_.resize(rows,cols);
cols_ = cols;
}
RowIterator begin()
{
return data_.begin();
}
RowIterator end()
{
return data_.end();
}
RowIterator beforeEnd ()
{
return data_.beforeEnd();
}
RowIterator beforeBegin ()
{
return data_.beforeBegin();
}
ConstRowIterator begin() const
{
return data_.begin();
}
ConstRowIterator end() const
{
return data_.end();
}
ConstRowIterator beforeEnd() const
{
return data_.beforeEnd();
}
ConstRowIterator beforeBegin () const
{
return data_.beforeBegin();
}
Matrix& operator= (const field_type& t)
{
data_ = t;
return *this;
}
row_type operator[](size_type row) {
#ifdef DUNE_ISTL_WITH_CHECKING
if (row<0)
DUNE_THROW(ISTLError, "Can't access negative rows!");
if (row>=N())
DUNE_THROW(ISTLError, "Row index out of range!");
#endif
return data_[row];
}
const row_type operator[](size_type row) const {
#ifdef DUNE_ISTL_WITH_CHECKING
if (row<0)
DUNE_THROW(ISTLError, "Can't access negative rows!");
if (row>=N())
DUNE_THROW(ISTLError, "Row index out of range!");
#endif
return data_[row];
}
size_type N() const {
return data_.N();
}
size_type M() const {
return cols_;
}
Matrix<T>& operator*=(const field_type& scalar) {
data_ *= scalar;
return (*this);
}
Matrix<T>& operator/=(const field_type& scalar) {
data_ /= scalar;
return (*this);
}
Matrix& operator+= (const Matrix& b) {
#ifdef DUNE_ISTL_WITH_CHECKING
if(N()!=b.N() || M() != b.M())
DUNE_THROW(RangeError, "Matrix sizes do not match!");
#endif
data_ += b.data_;
return (*this);
}
Matrix& operator-= (const Matrix& b) {
#ifdef DUNE_ISTL_WITH_CHECKING
if(N()!=b.N() || M() != b.M())
DUNE_THROW(RangeError, "Matrix sizes do not match!");
#endif
data_ -= b.data_;
return (*this);
}
Matrix transpose() const {
Matrix out(M(), N());
for (size_type i=0; i<N(); i++)
for (size_type j=0; j<M(); j++)
out[j][i] = (*this)[i][j];
return out;
}
friend Matrix<T> operator*(const Matrix<T>& m1, const Matrix<T>& m2) {
Matrix<T> out(m1.N(), m2.M());
out = 0;
for (size_type i=0; i<out.N(); i++ ) {
for ( size_type j=0; j<out.M(); j++ )
for (size_type k=0; k<m1.M(); k++)
out[i][j] += m1[i][k]*m2[k][j];
}
return out;
}
template <class X, class Y>
friend Y operator*(const Matrix<T>& m, const X& vec) {
#ifdef DUNE_ISTL_WITH_CHECKING
if (m.M()!=vec.size())
DUNE_THROW(ISTLError, "Vector size doesn't match the number of matrix columns!");
#endif
Y out(m.N());
out = 0;
for (size_type i=0; i<out.size(); i++ ) {
for ( size_type j=0; j<vec.size(); j++ )
out[i] += m[i][j]*vec[j];
}
return out;
}
template <class X, class Y>
void mv(const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++) {
y[i]=0;
for (size_type j=0; j<cols_; j++)
{
auto&& xj = Impl::asVector(x[j]);
auto&& yi = Impl::asVector(y[i]);
Impl::asMatrix((*this)[i][j]).umv(xj, yi);
}
}
}
template<class X, class Y>
void mtv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"index out of range");
if (y.N()!=M()) DUNE_THROW(ISTLError,"index out of range");
#endif
for(size_type i=0; i<y.N(); ++i)
y[i]=0;
umtv(x,y);
}
template <class X, class Y>
void umv(const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xj = Impl::asVector(x[j]);
auto&& yi = Impl::asVector(y[i]);
Impl::asMatrix((*this)[i][j]).umv(xj, yi);
}
}
template<class X, class Y>
void mmv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xj = Impl::asVector(x[j]);
auto&& yi = Impl::asVector(y[i]);
Impl::asMatrix((*this)[i][j]).mmv(xj, yi);
}
}
template <class X, class Y>
void usmv(const field_type& alpha, const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xj = Impl::asVector(x[j]);
auto&& yi = Impl::asVector(y[i]);
Impl::asMatrix((*this)[i][j]).usmv(alpha, xj, yi);
}
}
template<class X, class Y>
void umtv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).umtv(xi, yj);
}
}
template<class X, class Y>
void mmtv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).mmtv(xi, yj);
}
}
template<class X, class Y>
void usmtv (const field_type& alpha, const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).usmtv(alpha, xi, yj);
}
}
template<class X, class Y>
void umhv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).umhv(xi,yj);
}
}
template<class X, class Y>
void mmhv (const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).mmhv(xi,yj);
}
}
template<class X, class Y>
void usmhv (const field_type& alpha, const X& x, Y& y) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (x.N()!=N()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
if (y.N()!=M()) DUNE_THROW(ISTLError,"vector/matrix size mismatch!");
#endif
for (size_type i=0; i<data_.N(); i++)
for (size_type j=0; j<cols_; j++)
{
auto&& xi = Impl::asVector(x[i]);
auto&& yj = Impl::asVector(y[j]);
Impl::asMatrix((*this)[i][j]).usmhv(alpha,xi,yj);
}
}
//===== norms
typename FieldTraits<field_type>::real_type frobenius_norm () const
{
return std::sqrt(frobenius_norm2());
}
typename FieldTraits<field_type>::real_type frobenius_norm2 () const
{
typename FieldTraits<field_type>::real_type sum=0;
for (size_type i=0; i<this->N(); i++)
for (size_type j=0; j<this->M(); j++)
sum += Impl::asMatrix(data_[i][j]).frobenius_norm2();
return sum;
}
template <typename ft = field_type,
typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
typename FieldTraits<ft>::real_type infinity_norm() const {
using real_type = typename FieldTraits<ft>::real_type;
using std::max;
real_type norm = 0;
for (auto const &x : *this) {
real_type sum = 0;
for (auto const &y : x)
sum += Impl::asMatrix(y).infinity_norm();
norm = max(sum, norm);
isNaN += sum;
}
return norm;
}
template <typename ft = field_type,
typename std::enable_if<!HasNaN<ft>::value, int>::type = 0>
typename FieldTraits<ft>::real_type infinity_norm_real() const {
using real_type = typename FieldTraits<ft>::real_type;
using std::max;
real_type norm = 0;
for (auto const &x : *this) {
real_type sum = 0;
for (auto const &y : x)
sum += Impl::asMatrix(y).infinity_norm_real();
norm = max(sum, norm);
}
return norm;
}
template <typename ft = field_type,
typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
typename FieldTraits<ft>::real_type infinity_norm() const {
using real_type = typename FieldTraits<ft>::real_type;
using std::max;
real_type norm = 0;
real_type is_nan = 1;
for (auto const &x : *this) {
real_type sum = 0;
for (auto const &y : x)
sum += Impl::asMatrix(y).infinity_norm();
norm = max(sum, norm);
is_nan += sum;
}
return norm * (is_nan / is_nan);
}
template <typename ft = field_type,
typename std::enable_if<HasNaN<ft>::value, int>::type = 0>
typename FieldTraits<ft>::real_type infinity_norm_real() const {
using real_type = typename FieldTraits<ft>::real_type;
using std::max;
real_type norm = 0;
real_type is_nan = 1;
for (auto const &x : *this) {
real_type sum = 0;
for (auto const &y : x)
sum += Impl::asMatrix(y).infinity_norm_real();
norm = max(sum, norm);
is_nan += sum;
}
return norm * (is_nan / is_nan);
}
//===== query
bool exists ([[maybe_unused]] size_type i, [[maybe_unused]] size_type j) const
{
#ifdef DUNE_ISTL_WITH_CHECKING
if (i<0 || i>=N()) DUNE_THROW(ISTLError,"row index out of range");
if (j<0 || i>=M()) DUNE_THROW(ISTLError,"column index out of range");
#endif
return true;
}
protected:
MatrixImp::DenseMatrixBase<T,A> data_;
size_type cols_;
};
template<class T, class A>
struct FieldTraits< Matrix<T, A> >
{
using field_type = typename Matrix<T, A>::field_type;
using real_type = typename FieldTraits<field_type>::real_type;
};
} // end namespace Dune
#endif
blocklevel.hh
Helper functions for determining the vector/matrix block level.
istlexception.hh
bvector.hh
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Dune
Definition allocator.hh:11
Dune::type
const Dtype_t BaseGetSuperLUType< T >::type
Definition supermatrix.hh:135
Dune::MatrixImp
Definition matrix.hh:27
Dune::size_type
Dune::BlockVector
A vector of blocks with memory management.
Definition bvector.hh:392
Dune::ISTLError
derive error class from the base class in common
Definition istlexception.hh:19
Dune::MatrixImp::ConstIterator
Dune::MatrixImp::DenseMatrixBase::window_type
Imp::BlockVectorWindow< B, A > window_type
Definition matrix.hh:70
Dune::MatrixImp::DenseMatrixBase::block_type
BlockVector< B, A > block_type
Same as value_type, here for historical reasons.
Definition matrix.hh:67
Dune::MatrixImp::DenseMatrixBase::operator=
DenseMatrixBase & operator=(const DenseMatrixBase &a)
assignment
Definition matrix.hh:182
Dune::MatrixImp::DenseMatrixBase::field_type
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition matrix.hh:50
Dune::MatrixImp::DenseMatrixBase::beforeBegin
Iterator beforeBegin() const
Definition matrix.hh:385
Dune::MatrixImp::DenseMatrixBase::iterator
Iterator iterator
Export the iterator type using std naming rules.
Definition matrix.hh:506
Dune::MatrixImp::DenseMatrixBase::resize
void resize(size_type rows, size_type columns)
same effect as constructor with same argument
Definition matrix.hh:153
Dune::MatrixImp::DenseMatrixBase::const_reference
const window_type const_reference
Definition matrix.hh:74
Dune::MatrixImp::DenseMatrixBase::DenseMatrixBase
DenseMatrixBase(size_type rows, size_type columns)
Definition matrix.hh:95
Dune::MatrixImp::DenseMatrixBase::end
Iterator end()
end Iterator
Definition matrix.hh:371
Dune::MatrixImp::DenseMatrixBase::operator[]
reference operator[](size_type i)
random access to blocks
Definition matrix.hh:241
Dune::MatrixImp::DenseMatrixBase::value_type
BlockVector< B, A > value_type
Type of the elements of the outer vector, i.e., dynamic vectors of B.
Definition matrix.hh:63
Dune::MatrixImp::DenseMatrixBase::find
Iterator find(size_type i)
random access returning iterator (end if not contained)
Definition matrix.hh:391
Dune::MatrixImp::DenseMatrixBase::N
size_type N() const
number of blocks in the vector (are of variable size here)
Definition matrix.hh:539
Dune::MatrixImp::DenseMatrixBase::beforeEnd
ConstIterator beforeEnd() const
Definition matrix.hh:525
Dune::MatrixImp::DenseMatrixBase::end
ConstIterator end() const
end ConstIterator
Definition matrix.hh:518
Dune::MatrixImp::DenseMatrixBase::reference
window_type reference
Definition matrix.hh:72
Dune::MatrixImp::DenseMatrixBase::rend
ConstIterator rend() const
end ConstIterator
Definition matrix.hh:531
Dune::MatrixImp::DenseMatrixBase::beforeEnd
Iterator beforeEnd()
Definition matrix.hh:378
Dune::MatrixImp::DenseMatrixBase::begin
ConstIterator begin() const
begin ConstIterator
Definition matrix.hh:512
Dune::MatrixImp::DenseMatrixBase::allocator_type
A allocator_type
export the allocator type
Definition matrix.hh:53
Dune::MatrixImp::DenseMatrixBase::DenseMatrixBase
DenseMatrixBase()
Definition matrix.hh:82
Dune::MatrixImp::DenseMatrixBase::find
ConstIterator find(size_type i) const
random access returning iterator (end if not contained)
Definition matrix.hh:397
Dune::MatrixImp::DenseMatrixBase::const_iterator
ConstIterator const_iterator
Export the const iterator type using std naming rules.
Definition matrix.hh:509
Dune::MatrixImp::DenseMatrixBase::size_type
A::size_type size_type
The size type for the index access.
Definition matrix.hh:56
Dune::MatrixImp::DenseMatrixBase::~DenseMatrixBase
~DenseMatrixBase()
free dynamic memory
Definition matrix.hh:142
Dune::MatrixImp::DenseMatrixBase::begin
Iterator begin()
begin Iterator
Definition matrix.hh:365
Dune::MatrixImp::DenseMatrixBase::DenseMatrixBase
DenseMatrixBase(const DenseMatrixBase &a)
copy constructor, has copy semantics
Definition matrix.hh:116
Dune::MatrixImp::DenseMatrixBase::Iterator
Iterator class for sequential access.
Definition matrix.hh:263
Dune::MatrixImp::DenseMatrixBase::Iterator::operator--
Iterator & operator--()
prefix decrement
Definition matrix.hh:308
Dune::MatrixImp::DenseMatrixBase::Iterator::index
size_type index() const
Definition matrix.hh:352
Dune::MatrixImp::DenseMatrixBase::Iterator::Iterator
Iterator(Iterator &other)=default
Dune::MatrixImp::DenseMatrixBase::Iterator::Iterator
Iterator(Iterator &&other)=default
Dune::MatrixImp::DenseMatrixBase::Iterator::ConstIterator
friend class ConstIterator
Definition matrix.hh:357
Dune::MatrixImp::DenseMatrixBase::Iterator::operator!=
bool operator!=(const Iterator &it) const
inequality
Definition matrix.hh:322
Dune::MatrixImp::DenseMatrixBase::Iterator::operator=
Iterator & operator=(Iterator &&other)
Move assignment.
Definition matrix.hh:282
Dune::MatrixImp::DenseMatrixBase::Iterator::operator++
Iterator & operator++()
prefix increment
Definition matrix.hh:300
Dune::MatrixImp::DenseMatrixBase::Iterator::Iterator
Iterator()
constructor, no arguments
Definition matrix.hh:266
Dune::MatrixImp::DenseMatrixBase::Iterator::operator*
window_type & operator*() const
dereferencing
Definition matrix.hh:340
Dune::MatrixImp::DenseMatrixBase::Iterator::operator==
bool operator==(const Iterator &it) const
equality
Definition matrix.hh:316
Dune::MatrixImp::DenseMatrixBase::Iterator::operator=
Iterator & operator=(Iterator &other)
Copy assignment.
Definition matrix.hh:291
Dune::MatrixImp::DenseMatrixBase::Iterator::Iterator
Iterator(B *data, size_type columns, size_type _i)
constructor
Definition matrix.hh:276
Dune::MatrixImp::DenseMatrixBase::Iterator::operator->
window_type * operator->() const
arrow
Definition matrix.hh:346
Dune::MatrixImp::DenseMatrixBase::ConstIterator
ConstIterator class for sequential access.
Definition matrix.hh:404
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator->
const window_type * operator->() const
arrow
Definition matrix.hh:487
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator*
const window_type & operator*() const
dereferencing
Definition matrix.hh:481
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator++
ConstIterator & operator++()
prefix increment
Definition matrix.hh:441
Dune::MatrixImp::DenseMatrixBase::ConstIterator::ConstIterator
ConstIterator(const B *data, size_type columns, size_type _i)
constructor from pointer
Definition matrix.hh:414
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator--
ConstIterator & operator--()
prefix decrement
Definition matrix.hh:449
Dune::MatrixImp::DenseMatrixBase::ConstIterator::ConstIterator
ConstIterator(const Iterator &it)
constructor from non_const iterator
Definition matrix.hh:420
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator!=
bool operator!=(const ConstIterator &it) const
inequality
Definition matrix.hh:463
Dune::MatrixImp::DenseMatrixBase::ConstIterator::Iterator
friend class Iterator
Definition matrix.hh:498
Dune::MatrixImp::DenseMatrixBase::ConstIterator::ConstIterator
ConstIterator()
constructor
Definition matrix.hh:407
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator==
bool operator==(const ConstIterator &it) const
equality
Definition matrix.hh:457
Dune::MatrixImp::DenseMatrixBase::ConstIterator::index
size_type index() const
Definition matrix.hh:493
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator=
ConstIterator & operator=(Iterator &&other)
Definition matrix.hh:424
Dune::MatrixImp::DenseMatrixBase::ConstIterator::operator=
ConstIterator & operator=(Iterator &other)
Definition matrix.hh:432
Dune::Matrix
A generic dynamic dense matrix.
Definition matrix.hh:561
Dune::Matrix< FieldMatrix< K, n, m >, TA >::cols_
size_type cols_
Definition matrix.hh:1084
Dune::Matrix::infinity_norm
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition matrix.hh:988
Dune::Matrix::allocator_type
A allocator_type
Export the allocator.
Definition matrix.hh:571
Dune::Matrix::infinity_norm_real
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition matrix.hh:1007
Dune::Matrix::usmhv
void usmhv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition matrix.hh:952
Dune::Matrix::usmv
void usmv(const field_type &alpha, const X &x, Y &y) const
Definition matrix.hh:850
Dune::Matrix::size_type
A::size_type size_type
Type for indices and sizes.
Definition matrix.hh:577
Dune::Matrix< FieldMatrix< K, n, m >, TA >::data_
MatrixImp::DenseMatrixBase< FieldMatrix< K, n, m >, TA > data_
Definition matrix.hh:1077
Dune::Matrix::transpose
Matrix transpose() const
Return the transpose of the matrix.
Definition matrix.hh:741
Dune::Matrix::mtv
void mtv(const X &x, Y &y) const
y = A^T x
Definition matrix.hh:803
Dune::Matrix::umv
void umv(const X &x, Y &y) const
y += A x
Definition matrix.hh:816
Dune::Matrix::mv
void mv(const X &x, Y &y) const
y = A x
Definition matrix.hh:784
Dune::Matrix::ConstRowIterator
MatrixImp::DenseMatrixBase< T, A >::ConstIterator ConstRowIterator
Const iterator over the matrix rows.
Definition matrix.hh:586
Dune::Matrix::setSize
void setSize(size_type rows, size_type cols)
Change the matrix size.
Definition matrix.hh:604
Dune::Matrix::beforeBegin
RowIterator beforeBegin()
Definition matrix.hh:630
Dune::Matrix::beforeEnd
RowIterator beforeEnd()
Definition matrix.hh:623
Dune::Matrix::Matrix
Matrix()
Create empty matrix.
Definition matrix.hh:592
Dune::Matrix::operator-=
Matrix & operator-=(const Matrix &b)
Subtract the entries of another matrix from this one.
Definition matrix.hh:731
Dune::Matrix::frobenius_norm2
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition matrix.hh:976
Dune::Matrix::ColIterator
row_type::iterator ColIterator
Iterator for the entries of each row.
Definition matrix.hh:583
Dune::Matrix::beforeEnd
ConstRowIterator beforeEnd() const
Definition matrix.hh:649
Dune::Matrix::operator=
Matrix & operator=(const field_type &t)
Assignment from scalar.
Definition matrix.hh:662
Dune::Matrix::end
RowIterator end()
Get iterator to one beyond last row.
Definition matrix.hh:616
Dune::Matrix::operator[]
const row_type operator[](size_type row) const
The const index operator.
Definition matrix.hh:680
Dune::Matrix::end
ConstRowIterator end() const
Get const iterator to one beyond last row.
Definition matrix.hh:642
Dune::Matrix::operator*
friend Y operator*(const Matrix< T > &m, const X &vec)
Generic matrix-vector multiplication.
Definition matrix.hh:766
Dune::Matrix::operator*=
Matrix< T > & operator*=(const field_type &scalar)
Multiplication with a scalar.
Definition matrix.hh:701
Dune::Matrix::operator[]
row_type operator[](size_type row)
The index operator.
Definition matrix.hh:669
Dune::Matrix::mmv
void mmv(const X &x, Y &y) const
y -= A x
Definition matrix.hh:833
Dune::Matrix::operator+=
Matrix & operator+=(const Matrix &b)
Add the entries of another matrix to this one.
Definition matrix.hh:717
Dune::Matrix::begin
ConstRowIterator begin() const
Get const iterator to first row.
Definition matrix.hh:636
Dune::Matrix::mmhv
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition matrix.hh:935
Dune::Matrix::begin
RowIterator begin()
Get iterator to first row.
Definition matrix.hh:610
Dune::Matrix::field_type
typename Imp::BlockTraits< T >::field_type field_type
Export the type representing the underlying field.
Definition matrix.hh:565
Dune::Matrix::ConstColIterator
row_type::const_iterator ConstColIterator
Const iterator for the entries of each row.
Definition matrix.hh:589
Dune::Matrix::M
size_type M() const
Return the number of columns.
Definition matrix.hh:696
Dune::Matrix::block_type
T block_type
Export the type representing the components.
Definition matrix.hh:568
Dune::Matrix::exists
bool exists(size_type i, size_type j) const
return true if (i,j) is in pattern
Definition matrix.hh:1064
Dune::Matrix::operator/=
Matrix< T > & operator/=(const field_type &scalar)
Division by a scalar.
Definition matrix.hh:707
Dune::Matrix::operator*
friend Matrix< T > operator*(const Matrix< T > &m1, const Matrix< T > &m2)
Generic matrix multiplication.
Definition matrix.hh:751
Dune::Matrix::umtv
void umtv(const X &x, Y &y) const
y += A^T x
Definition matrix.hh:867
Dune::Matrix::mmtv
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition matrix.hh:884
Dune::Matrix::row_type
MatrixImp::DenseMatrixBase< T, A >::window_type row_type
The type implementing a matrix row.
Definition matrix.hh:574
Dune::Matrix::frobenius_norm
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition matrix.hh:970
Dune::Matrix::usmtv
void usmtv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition matrix.hh:901
Dune::Matrix::umhv
void umhv(const X &x, Y &y) const
y += A^H x
Definition matrix.hh:918
Dune::Matrix::N
size_type N() const
Return the number of rows.
Definition matrix.hh:691
Dune::Matrix::beforeBegin
ConstRowIterator beforeBegin() const
Definition matrix.hh:656
Dune::Matrix::Matrix
Matrix(size_type rows, size_type cols)
Create uninitialized matrix of size rows x cols.
Definition matrix.hh:597
Dune::Matrix::RowIterator
MatrixImp::DenseMatrixBase< T, A >::Iterator RowIterator
Iterator over the matrix rows.
Definition matrix.hh:580
Dune::FieldTraits< Matrix< T, A > >::field_type
typename Matrix< T, A >::field_type field_type
Definition matrix.hh:1090
Dune::FieldTraits< Matrix< T, A > >::real_type
typename FieldTraits< field_type >::real_type real_type
Definition matrix.hh:1091