3#ifndef DUNE_ISTL_MATRIX_HH
4#define DUNE_ISTL_MATRIX_HH
13#include <dune/common/ftraits.hh>
33 template<
class B,
class A=std::allocator<B> >
96 this->
p = allocator_.allocate(this->
n);
97 new (this->
p)B[this->
n];
114 columns_ = a.columns_;
118 this->
p = allocator_.allocate(this->
n);
119 new (this->
p)B[this->
n];
122 for (size_type i=0; i<this->
n; i++)
142 allocator_.deallocate(this->
p,this->
n);
154 allocator_.deallocate(this->
p,this->
n);
161 this->
p = allocator_.allocate(this->
n);
162 new (this->
p)B[this->
n];
180 columns_ = a.columns_;
183 if (this->
n!=a.
n || rows_!=a.rows_)
190 allocator_.deallocate(this->
p,this->
n);
198 this->
p = allocator_.allocate(this->
n);
199 new (this->
p)B[this->
n];
237#ifdef DUNE_ISTL_WITH_CHECKING
246#ifdef DUNE_ISTL_WITH_CHECKING
312 return window_.
getptr() ==
it.window_.getptr();
318 return window_.
getptr() !=
it.window_.getptr();
324 return window_.
getptr() ==
it.window_.getptr();
330 return window_.
getptr() !=
it.window_.getptr();
367 return Iterator(this->
p, columns_, rows_);
374 return Iterator(this->
p, columns_, rows_-1);
387 return Iterator(this->
p, columns_, std::min(i,rows_));
415 : i(
it.i), window_(
it.window_.getptr(),
it.window_.getsize())
453 return window_.
getptr() ==
it.window_.getptr();
459 return window_.
getptr() !=
it.window_.getptr();
465 return window_.
getptr() ==
it.window_.getptr();
471 return window_.
getptr() !=
it.window_.getptr();
553 template<
class T,
class A=std::allocator<T> >
604 data_.resize(rows,cols);
611 return data_.begin();
624 return data_.beforeEnd();
631 return data_.beforeBegin();
637 return data_.begin();
650 return data_.beforeEnd();
657 return data_.beforeBegin();
669#ifdef DUNE_ISTL_WITH_CHECKING
680#ifdef DUNE_ISTL_WITH_CHECKING
717#ifdef DUNE_ISTL_WITH_CHECKING
718 if(
N()!=b.
N() ||
M() != b.
M())
731#ifdef DUNE_ISTL_WITH_CHECKING
732 if(
N()!=b.
N() ||
M() != b.
M())
744 out[j][i] = (*
this)[i][j];
757 out[i][j] +=
m1[i][k]*
m2[k][j];
764 template <
class X,
class Y>
766#ifdef DUNE_ISTL_WITH_CHECKING
767 if (m.M()!=
vec.size())
782 template <
class X,
class Y>
783 void mv(
const X& x,
Y&
y)
const
785#ifdef DUNE_ISTL_WITH_CHECKING
793 (*
this)[i][j].umv(x[j],
y[i]);
800 template<
class X,
class Y>
803#ifdef DUNE_ISTL_WITH_CHECKING
814 template <
class X,
class Y>
817#ifdef DUNE_ISTL_WITH_CHECKING
825 (*
this)[i][j].umv(x[j],
y[i]);
832 template<
class X,
class Y>
835#ifdef DUNE_ISTL_WITH_CHECKING
844 (*j).mmv(x[j.index()],
y[i.index()]);
849 template <
class X,
class Y>
852#ifdef DUNE_ISTL_WITH_CHECKING
860 (*
this)[i][j].usmv(alpha, x[j],
y[i]);
867 template<
class X,
class Y>
870#ifdef DUNE_ISTL_WITH_CHECKING
879 (*j).umtv(x[i.index()],
y[j.index()]);
884 template<
class X,
class Y>
887#ifdef DUNE_ISTL_WITH_CHECKING
896 (*j).mmtv(x[i.index()],
y[j.index()]);
901 template<
class X,
class Y>
904#ifdef DUNE_ISTL_WITH_CHECKING
913 (*j).usmtv(alpha,x[i.index()],
y[j.index()]);
918 template<
class X,
class Y>
921#ifdef DUNE_ISTL_WITH_CHECKING
930 (*j).umhv(x[i.index()],
y[j.index()]);
935 template<
class X,
class Y>
938#ifdef DUNE_ISTL_WITH_CHECKING
947 (*j).mmhv(x[i.index()],
y[j.index()]);
952 template<
class X,
class Y>
955#ifdef DUNE_ISTL_WITH_CHECKING
964 (*j).usmhv(alpha,x[i.index()],
y[j.index()]);
988 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
994 for (
auto const &x : *
this) {
996 for (
auto const &
y : x)
997 sum +=
y.infinity_norm();
998 norm = max(sum, norm);
1005 typename std::enable_if<!has_nan<ft>::value,
int>::type = 0>
1011 for (
auto const &x : *
this) {
1013 for (
auto const &
y : x)
1014 sum +=
y.infinity_norm_real();
1015 norm = max(sum, norm);
1022 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
1028 real_type
isNaN = 1;
1029 for (
auto const &x : *
this) {
1031 for (
auto const &
y : x)
1032 sum +=
y.infinity_norm();
1033 norm = max(sum, norm);
1037 return norm *
isNaN;
1042 typename std::enable_if<has_nan<ft>::value,
int>::type = 0>
1048 real_type
isNaN = 1;
1049 for (
auto const &x : *
this) {
1051 for (
auto const &
y : x)
1052 sum +=
y.infinity_norm_real();
1053 norm = max(sum, norm);
1057 return norm *
isNaN;
1065#ifdef DUNE_ISTL_WITH_CHECKING
This file implements a vector space as a tensor product of a given vector space. The number of compon...
Definition basearray.hh:19
size_type n
Definition basearray.hh:254
B * p
Definition basearray.hh:255
Iterator implementation class
Definition basearray.hh:84
Statistics about compression achieved in implicit mode.
Definition bcrsmatrix.hh:81
An unmanaged vector of blocks.
Definition bvector.hh:42
Definition bvector.hh:660
B * getptr()
get pointer
Definition bvector.hh:774
void set(size_type _n, B *_p)
set size and pointer
Definition bvector.hh:755
size_type getsize()
get size
Definition bvector.hh:780
void setptr(B *_p)
set pointer only
Definition bvector.hh:768
derive error class from the base class in common
Definition istlexception.hh:16
A Vector of blocks with different blocksizes.
Definition matrix.hh:38
BlockVector< B, A > block_type
Same as value_type, here for historical reasons.
Definition matrix.hh:61
DenseMatrixBase & operator=(const DenseMatrixBase &a)
assignment
Definition matrix.hh:176
Iterator beforeBegin() const
Definition matrix.hh:379
void resize(size_type rows, size_type columns)
same effect as constructor with same argument
Definition matrix.hh:147
const window_type const_reference
Definition matrix.hh:68
DenseMatrixBase(size_type rows, size_type columns)
Definition matrix.hh:89
BlockVectorWindow< B, A > window_type
Definition matrix.hh:64
Iterator end()
end Iterator
Definition matrix.hh:365
reference operator[](size_type i)
random access to blocks
Definition matrix.hh:235
BlockVector< B, A > value_type
Type of the elements of the outer vector, i.e., dynamic vectors of B.
Definition matrix.hh:57
Iterator find(size_type i)
random access returning iterator (end if not contained)
Definition matrix.hh:385
size_type N() const
number of blocks in the vector (are of variable size here)
Definition matrix.hh:533
ConstIterator beforeEnd() const
Definition matrix.hh:519
ConstIterator end() const
end ConstIterator
Definition matrix.hh:512
window_type reference
Definition matrix.hh:66
ConstIterator rend() const
end ConstIterator
Definition matrix.hh:525
Iterator beforeEnd()
Definition matrix.hh:372
ConstIterator begin() const
begin ConstIterator
Definition matrix.hh:506
A allocator_type
export the allocator type
Definition matrix.hh:47
DenseMatrixBase()
Definition matrix.hh:76
ConstIterator find(size_type i) const
random access returning iterator (end if not contained)
Definition matrix.hh:391
A::size_type size_type
The size type for the index access.
Definition matrix.hh:50
~DenseMatrixBase()
free dynamic memory
Definition matrix.hh:136
B::field_type field_type
export the type representing the field
Definition matrix.hh:44
Iterator begin()
begin Iterator
Definition matrix.hh:359
DenseMatrixBase(const DenseMatrixBase &a)
copy constructor, has copy semantics
Definition matrix.hh:110
Iterator class for sequential access.
Definition matrix.hh:257
Iterator & operator--()
prefix decrement
Definition matrix.hh:302
size_type index() const
Definition matrix.hh:346
Iterator(Iterator &other)=default
Iterator(Iterator &&other)=default
bool operator!=(const Iterator &it) const
inequality
Definition matrix.hh:316
Iterator & operator=(Iterator &&other)
Move assignment.
Definition matrix.hh:276
Iterator & operator++()
prefix increment
Definition matrix.hh:294
Iterator()
constructor, no arguments
Definition matrix.hh:260
window_type & operator*() const
dereferencing
Definition matrix.hh:334
bool operator==(const Iterator &it) const
equality
Definition matrix.hh:310
Iterator & operator=(Iterator &other)
Copy assignment.
Definition matrix.hh:285
Iterator(B *data, size_type columns, size_type _i)
constructor
Definition matrix.hh:270
window_type * operator->() const
arrow
Definition matrix.hh:340
ConstIterator class for sequential access.
Definition matrix.hh:398
const window_type * operator->() const
arrow
Definition matrix.hh:481
const window_type & operator*() const
dereferencing
Definition matrix.hh:475
ConstIterator & operator++()
prefix increment
Definition matrix.hh:435
ConstIterator(const B *data, size_type columns, size_type _i)
constructor from pointer
Definition matrix.hh:408
ConstIterator & operator--()
prefix decrement
Definition matrix.hh:443
ConstIterator(const Iterator &it)
constructor from non_const iterator
Definition matrix.hh:414
bool operator!=(const ConstIterator &it) const
inequality
Definition matrix.hh:457
ConstIterator()
constructor
Definition matrix.hh:401
bool operator==(const ConstIterator &it) const
equality
Definition matrix.hh:451
size_type index() const
Definition matrix.hh:487
ConstIterator & operator=(Iterator &&other)
Definition matrix.hh:418
ConstIterator & operator=(Iterator &other)
Definition matrix.hh:426
A generic dynamic dense matrix.
Definition matrix.hh:555
size_type cols_
Number of columns of the matrix.
Definition matrix.hh:1085
FieldTraits< ft >::real_type infinity_norm() const
infinity norm (row sum norm, how to generalize for blocks?)
Definition matrix.hh:989
A allocator_type
Export the allocator.
Definition matrix.hh:565
FieldTraits< ft >::real_type infinity_norm_real() const
simplified infinity norm (uses Manhattan norm for complex values)
Definition matrix.hh:1006
void usmhv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^H x
Definition matrix.hh:953
void usmv(const field_type &alpha, const X &x, Y &y) const
Definition matrix.hh:850
A::size_type size_type
Type for indices and sizes.
Definition matrix.hh:571
MatrixImp::DenseMatrixBase< T, A > data_
Abuse DenseMatrixBase as an engine for a 2d array ISTL-style.
Definition matrix.hh:1078
Matrix transpose() const
Return the transpose of the matrix.
Definition matrix.hh:740
void mtv(const X &x, Y &y) const
y = A^T x
Definition matrix.hh:801
void umv(const X &x, Y &y) const
y += A x
Definition matrix.hh:815
void mv(const X &x, Y &y) const
y = A x
Definition matrix.hh:783
MatrixImp::DenseMatrixBase< T, A >::ConstIterator ConstRowIterator
Const iterator over the matrix rows.
Definition matrix.hh:580
void setSize(size_type rows, size_type cols)
Change the matrix size.
Definition matrix.hh:603
T::field_type field_type
Export the type representing the underlying field.
Definition matrix.hh:559
RowIterator beforeBegin()
Definition matrix.hh:629
RowIterator beforeEnd()
Definition matrix.hh:622
Matrix()
Create empty matrix.
Definition matrix.hh:591
Matrix & operator-=(const Matrix &b)
Subtract the entries of another matrix from this one.
Definition matrix.hh:730
FieldTraits< field_type >::real_type frobenius_norm2() const
square of frobenius norm, need for block recursion
Definition matrix.hh:977
row_type::iterator ColIterator
Iterator for the entries of each row.
Definition matrix.hh:577
ConstRowIterator beforeEnd() const
Definition matrix.hh:648
Matrix & operator=(const field_type &t)
Assignment from scalar.
Definition matrix.hh:661
RowIterator end()
Get iterator to one beyond last row.
Definition matrix.hh:615
const row_type operator[](size_type row) const
The const index operator.
Definition matrix.hh:679
ConstRowIterator end() const
Get const iterator to one beyond last row.
Definition matrix.hh:641
friend Y operator*(const Matrix< T > &m, const X &vec)
Generic matrix-vector multiplication.
Definition matrix.hh:765
Matrix< T > & operator*=(const field_type &scalar)
Multiplication with a scalar.
Definition matrix.hh:700
row_type operator[](size_type row)
The index operator.
Definition matrix.hh:668
void mmv(const X &x, Y &y) const
y -= A x
Definition matrix.hh:833
Matrix & operator+=(const Matrix &b)
Add the entries of another matrix to this one.
Definition matrix.hh:716
ConstRowIterator begin() const
Get const iterator to first row.
Definition matrix.hh:635
void mmhv(const X &x, Y &y) const
y -= A^H x
Definition matrix.hh:936
RowIterator begin()
Get iterator to first row.
Definition matrix.hh:609
row_type::const_iterator ConstColIterator
Const iterator for the entries of each row.
Definition matrix.hh:583
@ blocklevel
The number of nesting levels the matrix contains.
Definition matrix.hh:587
size_type M() const
Return the number of columns.
Definition matrix.hh:695
T block_type
Export the type representing the components.
Definition matrix.hh:562
bool exists(size_type i, size_type j) const
return true if (i,j) is in pattern
Definition matrix.hh:1063
Matrix< T > & operator/=(const field_type &scalar)
Division by a scalar.
Definition matrix.hh:706
friend Matrix< T > operator*(const Matrix< T > &m1, const Matrix< T > &m2)
Generic matrix multiplication.
Definition matrix.hh:750
void umtv(const X &x, Y &y) const
y += A^T x
Definition matrix.hh:868
void mmtv(const X &x, Y &y) const
y -= A^T x
Definition matrix.hh:885
MatrixImp::DenseMatrixBase< T, A >::window_type row_type
The type implementing a matrix row.
Definition matrix.hh:568
FieldTraits< field_type >::real_type frobenius_norm() const
frobenius norm: sqrt(sum over squared values of entries)
Definition matrix.hh:971
void usmtv(const field_type &alpha, const X &x, Y &y) const
y += alpha A^T x
Definition matrix.hh:902
void umhv(const X &x, Y &y) const
y += A^H x
Definition matrix.hh:919
size_type N() const
Return the number of rows.
Definition matrix.hh:690
ConstRowIterator beforeBegin() const
Definition matrix.hh:655
Matrix(size_type rows, size_type cols)
Create uninitialized matrix of size rows x cols.
Definition matrix.hh:596
MatrixImp::DenseMatrixBase< T, A >::Iterator RowIterator
Iterator over the matrix rows.
Definition matrix.hh:574