pymor.vectorarrays package

Submodules

block module


class pymor.vectorarrays.block.BlockVectorArray(blocks, space)[source]

Bases: pymor.vectorarrays.interface.VectorArray

VectorArray where each vector is a direct sum of sub-vectors.

Given a list of equal length VectorArrays blocks, this VectorArray represents the direct sums of the vectors contained in the arrays. The associated VectorSpace is BlockVectorSpace.

BlockVectorArray can be used in conjunction with BlockOperator.

__delitem__(ind)[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

__len__()[source]

The number of vectors in the array.

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

block(ind)[source]

Returns a copy of each block (no slicing).

conj()[source]

Complex conjugation.

copy(deep=False)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

property imag

Imaginary part.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

lincomb(coefficients)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

property real

Real part.

scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.

sup_norm()[source]

The l-infinity-norms of the vectors contained in the array.

Returns

A NumPy array result such that result[i] contains the norm of self[i].

to_numpy(ensure_copy=False)[source]

Return (len(self), self.dim) NumPy Array with the data stored in the array.

Parameters

ensure_copy

If False, modifying the returned NumPy array might alter the original VectorArray. If True always a copy of the array data is made.


class pymor.vectorarrays.block.BlockVectorArrayView(base, ind)[source]

Bases: pymor.vectorarrays.block.BlockVectorArray


class pymor.vectorarrays.block.BlockVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.interface.VectorSpace

VectorSpace of BlockVectorArrays.

A BlockVectorSpace is defined by the VectorSpaces of the individual subblocks which constitute a given array. In particular for a given :class`BlockVectorArray` U, we have the identity

(U.blocks[0].space, U.blocks[1].space, ..., U.blocks[-1].space) == U.space.

Parameters

subspaces

The tuple defined above.

__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

from_numpy(data, ensure_copy=False)[source]

Create a VectorArray from a NumPy array

Note that this method will not be supported by all vector space implementations.

Parameters

data

NumPy array of shape (len, dim) where len is the number of vectors and dim their dimension.

ensure_copy

If False, modifying the returned VectorArray might alter the original NumPy array. If True always a copy of the array data is made.

Returns

A VectorArray with data as data.

zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each component zero.

constructions module


pymor.vectorarrays.constructions.cat_arrays(vector_arrays)[source]

Return a new VectorArray which is a concatenation of the arrays in vector_arrays.

interface module


class pymor.vectorarrays.interface.VectorArray[source]

Bases: pymor.core.base.BasicObject

Interface for vector arrays.

A vector array should be thought of as a list of (possibly high-dimensional) vectors. While the vectors themselves will be inaccessible in general (e.g. because they are managed by an external PDE solver code), operations on the vectors like addition can be performed via this interface.

It is assumed that the number of vectors is small enough such that scalar data associated to each vector can be handled on the Python side. As such, methods like norm or gramian will always return NumPy arrays.

An implementation of the VectorArray via NumPy arrays is given by NumpyVectorArray. In general, it is the implementors decision how memory is allocated internally (e.g. continuous block of memory vs. list of pointers to the individual vectors.) Thus, no general assumptions can be made on the costs of operations like appending to or removing vectors from the array. As a hint for ‘continuous block of memory’ implementations, zeros provides a reserve keyword argument which allows to specify to what size the array is assumed to grow.

As with NumPy array, VectorArrays can be indexed with numbers, slices and lists or one-dimensional NumPy arrays. Indexing will always return a new VectorArray which acts as a view into the original data. Thus, if the indexed array is modified via scal or axpy, the vectors in the original array will be changed. Indices may be negative, in which case the vector is selected by counting from the end of the array. Moreover indices can be repeated, in which case the corresponding vector is selected several times. The resulting view will be immutable, however.

Note

It is disallowed to append vectors to a VectorArray view or to remove vectors from it. Removing vectors from an array with existing views will lead to undefined behavior of these views. As such, it is generally advisable to make a copy of a view for long term storage. Since copy has copy-on-write semantics, this will usually cause little overhead.

dim

The dimension of the vectors in the array.

is_view

True if the array is a view obtained by indexing another array.

space

The VectorSpace the array belongs to.

abstract __delitem__(ind)[source]

Remove vectors from the array.

abstract __getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

abstract __len__()[source]

The number of vectors in the array.

abstract _norm()[source]

Implementation of norm for the case that no product is given.

abstract _norm2()[source]

Implementation of norm2 for the case that no product is given.

abstract amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

abstract append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

abstract axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

check_ind(ind)[source]

Check if ind is an admissible list of indices in the sense of the class documentation.

check_ind_unique(ind)[source]

Check if ind is an admissible list of non-repeated indices in the sense of the class documentation.

conj()[source]

Complex conjugation.

abstract copy(deep=False)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

abstract dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

empty(reserve=0)[source]

Create an empty VectorArray of the same VectorSpace.

This is a shorthand for self.space.zeros(0, reserve).

Parameters

reserve

Hint for the backend to which length the array will grow.

Returns

An empty VectorArray.

full(value, count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to the same value.

This is a shorthand for self.space.full(value, count, reserve).

Parameters

value

The value each DOF should be set to.

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to value.

gramian(product=None)[source]

Shorthand for self.inner(self, product).

property imag

Imaginary part.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

len_ind(ind)[source]

Return the number of given indices.

len_ind_unique(ind)[source]

Return the number of specified unique indices.

abstract lincomb(coefficients)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

norm(product=None, tol=None, raise_complex=None)[source]

Norm with respect to a given inner product.

If product is None, the Euclidean norms of the dofs of the array are returned, i.e.

U.norm()

is equivalent to:

np.sqrt(U.pairwise_inner(U))

If a product Operator is specified, this Operator is used to compute the norms via:

np.sqrt(product.pairwise_apply2(U, U))

Parameters

product

If not None, the inner product Operator used to compute the norms.

tol

If raise_complex is True, a ValueError exception is raised if there are complex norm squares with an imaginary part of absolute value larger than tol.

raise_complex

See tol.

Returns

A one-dimensional NumPy array of the norms of the vectors in the array.

norm2(product=None, tol=1e-10, raise_complex=True)[source]

Squared norm with respect to a given inner product.

If product is None, the Euclidean norms of the dofs of the array are returned, i.e.

U.norm()

is equivalent to:

U.pairwise_inner(U)

If a product Operator is specified, this Operator is used to compute the norms via:

product.pairwise_apply2(U, U)

Parameters

product

If not None, the inner product Operator used to compute the norms.

tol

If raise_complex is True, a ValueError exception is raised if there are complex norm squares with an imaginary part of absolute value larger than tol.

raise_complex

See tol.

Returns

A one-dimensional NumPy array of the squared norms of the vectors in the array.

Defaults

tol, raise_complex (see pymor.core.defaults)

normalize_ind(ind)[source]

Normalize given indices such that they are independent of the array length.

ones(count=1, reserve=0)[source]

Create a VectorArray of vectors of the same VectorSpace with all DOFs set to one.

This is a shorthand for self.space.full(1., count, reserve).

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to one.

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]

Create a VectorArray of vectors with random entries.

This is a shorthand for self.space.random(count, distribution, radom_state, seed, **kwargs).

Supported random distributions:

'uniform': Uniform distribution in half-open interval
           [`low`, `high`).
'normal':  Normal (Gaussian) distribution with mean
           `loc` and standard deviation `scale`.

Note that not all random distributions are necessarily implemented by all VectorSpace implementations.

Parameters

count

The number of vectors.

distribution

Random distribution to use ('uniform', 'normal').

low

Lower bound for 'uniform' distribution (defaults to 0).

high

Upper bound for 'uniform' distribution (defaults to 1).

loc

Mean for 'normal' distribution (defaults to 0).

scale

Standard deviation for 'normal' distribution (defaults to 1).

random_state

RandomState to use for sampling. If None, a new random state is generated using seed as random seed, or the default random state is used.

seed

If not None, a new radom state with this seed is used.

reserve

Hint for the backend to which length the array will grow.

property real

Real part.

abstract scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.

sub_index(ind, ind_ind)[source]

Return indices corresponding to the view self[ind][ind_ind]

sup_norm()[source]

The l-infinity-norms of the vectors contained in the array.

Returns

A NumPy array result such that result[i] contains the norm of self[i].

to_numpy(ensure_copy=False)[source]

Return (len(self), self.dim) NumPy Array with the data stored in the array.

Parameters

ensure_copy

If False, modifying the returned NumPy array might alter the original VectorArray. If True always a copy of the array data is made.

zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors of the same VectorSpace.

This is a shorthand for self.space.zeros(count, reserve).

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to zero.


class pymor.vectorarrays.interface.VectorSpace(*args, **kwargs)[source]

Bases: pymor.core.base.ImmutableObject

Class describing a vector space.

Vector spaces act as factories for VectorArrays of vectors contained in them. As such, they hold all data necessary to create VectorArrays of a given type (e.g. the dimension of the vectors, or a socket for communication with an external PDE solver).

New VectorArrays of null vectors are created via zeros. The make_array method builds a new VectorArray from given raw data of the underlying linear algebra backend (e.g. a NumPy array in the case of NumpyVectorSpace). Some vector spaces can create new VectorArrays from a given NumPy array via the from_numpy method.

Each vector space has a string id to distinguish mathematically different spaces appearing in the formulation of a given problem.

Vector spaces can be compared for equality via the == and != operators. To test if a given VectorArray is an element of the space, the in operator can be used.

id

None, or a string describing the mathematical identity of the vector space (for instance to distinguish different components in an equation system).

dim

The dimension (number of degrees of freedom) of the vectors contained in the space.

is_scalar

Equivalent to isinstance(space, NumpyVectorSpace) and space.dim == 1 and space.id is None.

__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

__ne__(other)[source]

Return self!=value.

empty(reserve=0)[source]

Create an empty VectorArray

This is a shorthand for self.zeros(0, reserve).

Parameters

reserve

Hint for the backend to which length the array will grow.

Returns

An empty VectorArray.

from_numpy(data, ensure_copy=False)[source]

Create a VectorArray from a NumPy array

Note that this method will not be supported by all vector space implementations.

Parameters

data

NumPy array of shape (len, dim) where len is the number of vectors and dim their dimension.

ensure_copy

If False, modifying the returned VectorArray might alter the original NumPy array. If True always a copy of the array data is made.

Returns

A VectorArray with data as data.

full(value, count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to the same value.

Parameters

value

The value each DOF should be set to.

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to value.

abstract make_array(**kwargs)[source]

Create a VectorArray from raw data.

This method is used in the implementation of Operators and Models to create new VectorArrays from raw data of the underlying solver backends. The ownership of the data is transferred to the newly created array.

The exact signature of this method depends on the wrapped solver backend.

ones(count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to one.

This is a shorthand for self.full(1., count, reserve).

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to one.

random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]

Create a VectorArray of vectors with random entries.

Supported random distributions:

'uniform': Uniform distribution in half-open interval
           [`low`, `high`).
'normal':  Normal (Gaussian) distribution with mean
           `loc` and standard deviation `scale`.

Note that not all random distributions are necessarily implemented by all VectorSpace implementations.

Parameters

count

The number of vectors.

distribution

Random distribution to use ('uniform', 'normal').

low

Lower bound for 'uniform' distribution (defaults to 0).

high

Upper bound for 'uniform' distribution (defaults to 1).

loc

Mean for 'normal' distribution (defaults to 0).

scale

Standard deviation for 'normal' distribution (defaults to 1).

random_state

RandomState to use for sampling. If None, a new random state is generated using seed as random seed, or the default random state is used.

seed

If not None, a new random state with this seed is used.

reserve

Hint for the backend to which length the array will grow.

abstract zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each component zero.

list module


class pymor.vectorarrays.list.ComplexifiedListVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.list.ListVectorSpace

Methods

ComplexifiedListVectorSpace

full_vector, make_vector, random_vector, real_full_vector, real_make_vector, real_random_vector, real_vector_from_numpy, real_zero_vector, vector_from_numpy, zero_vector

ListVectorSpace

from_numpy, full, make_array, ones, ones_vector, random, space_from_dim, space_from_vector_obj, zeros

VectorSpace

empty

ImmutableObject

with_, __setattr__

BasicObject

disable_logging, enable_logging

complexified_vector_type

alias of ComplexifiedVector


class pymor.vectorarrays.list.ComplexifiedVector(real_part, imag_part)[source]

Bases: pymor.vectorarrays.list.Vector

Methods

ComplexifiedVector

amax, axpy, conj, copy, dofs, inner, norm, norm2, scal, sup_norm, to_numpy

BasicObject

disable_logging, enable_logging


class pymor.vectorarrays.list.CopyOnWriteVector[source]

Bases: pymor.vectorarrays.list.Vector

Methods

CopyOnWriteVector

axpy, copy, from_instance, scal

Vector

amax, conj, dofs, inner, norm, norm2, sup_norm

BasicObject

disable_logging, enable_logging

Attributes

Vector

imag, real

BasicObject

logger, logging_disabled, name, uid


class pymor.vectorarrays.list.ListVectorArray(vectors, space)[source]

Bases: pymor.vectorarrays.interface.VectorArray

VectorArray implemented as a Python list of vectors.

This VectorArray implementation is the first choice when creating pyMOR wrappers for external solvers which are based on single vector objects. In order to do so, a wrapping subclass of Vector has to be provided on which the implementation of ListVectorArray will operate. The associated VectorSpace is a subclass of ListVectorSpace.

For an example, see NumpyVector, NumpyListVectorSpace or FenicsVector, FenicsVectorSpace.

__delitem__(ind)[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

__len__()[source]

The number of vectors in the array.

__str__()[source]

Return str(self).

property _data

Return list of NumPy Array views on vector data for hacking / interactive use.

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

conj()[source]

Complex conjugation.

copy(deep=False)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

gramian(product=None)[source]

Shorthand for self.inner(self, product).

property imag

Imaginary part.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

lincomb(coefficients)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

property real

Real part.

scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.

sup_norm()[source]

The l-infinity-norms of the vectors contained in the array.

Returns

A NumPy array result such that result[i] contains the norm of self[i].

to_numpy(ensure_copy=False)[source]

Return (len(self), self.dim) NumPy Array with the data stored in the array.

Parameters

ensure_copy

If False, modifying the returned NumPy array might alter the original VectorArray. If True always a copy of the array data is made.


class pymor.vectorarrays.list.ListVectorArrayNumpyView(array)[source]

Bases: object

__repr__()[source]

Return repr(self).


class pymor.vectorarrays.list.ListVectorArrayView(base, ind)[source]

Bases: pymor.vectorarrays.list.ListVectorArray

__delitem__(ind)[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.


class pymor.vectorarrays.list.ListVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.interface.VectorSpace

VectorSpace of ListVectorArrays.

Methods

ListVectorSpace

from_numpy, full, full_vector, make_array, make_vector, ones, ones_vector, random, random_vector, space_from_dim, space_from_vector_obj, vector_from_numpy, zero_vector, zeros

VectorSpace

empty

ImmutableObject

with_, __setattr__

BasicObject

disable_logging, enable_logging

full(value, count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to the same value.

Parameters

value

The value each DOF should be set to.

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to value.

ones(count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to one.

This is a shorthand for self.full(1., count, reserve).

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to one.

random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]

Create a VectorArray of vectors with random entries.

Supported random distributions:

'uniform': Uniform distribution in half-open interval
           [`low`, `high`).
'normal':  Normal (Gaussian) distribution with mean
           `loc` and standard deviation `scale`.

Note that not all random distributions are necessarily implemented by all VectorSpace implementations.

Parameters

count

The number of vectors.

distribution

Random distribution to use ('uniform', 'normal').

low

Lower bound for 'uniform' distribution (defaults to 0).

high

Upper bound for 'uniform' distribution (defaults to 1).

loc

Mean for 'normal' distribution (defaults to 0).

scale

Standard deviation for 'normal' distribution (defaults to 1).

random_state

RandomState to use for sampling. If None, a new random state is generated using seed as random seed, or the default random state is used.

seed

If not None, a new random state with this seed is used.

reserve

Hint for the backend to which length the array will grow.

zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each component zero.


class pymor.vectorarrays.list.NumpyListVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.list.ListVectorSpace

Methods

NumpyListVectorSpace

full_vector, make_vector, ones_vector, space_from_dim, space_from_vector_obj, vector_from_numpy, zero_vector

ListVectorSpace

from_numpy, full, make_array, ones, random, random_vector, zeros

VectorSpace

empty

ImmutableObject

with_, __setattr__

BasicObject

disable_logging, enable_logging

__eq__(other)[source]

Return self==value.


class pymor.vectorarrays.list.NumpyVector(array)[source]

Bases: pymor.vectorarrays.list.CopyOnWriteVector

Vector stored in a NumPy 1D-array.

Methods

NumpyVector

amax, conj, dofs, from_instance, inner, norm, norm2, to_numpy

CopyOnWriteVector

axpy, copy, scal

Vector

sup_norm

BasicObject

disable_logging, enable_logging

Attributes

NumpyVector

dim, imag, real

BasicObject

logger, logging_disabled, name, uid


class pymor.vectorarrays.list.Vector[source]

Bases: pymor.core.base.BasicObject

Interface for vectors used in conjunction with ListVectorArray.

This interface must be satisfied by the individual entries of the vector list managed by ListVectorArray. All interface methods have a direct counterpart in the VectorArray interface.

Methods

Vector

amax, axpy, conj, copy, dofs, inner, norm, norm2, scal, sup_norm

BasicObject

disable_logging, enable_logging

Attributes

Vector

imag, real

BasicObject

logger, logging_disabled, name, uid

mpi module

Wrapper classes for building MPI distributed VectorArrays.

This module contains several wrapper classes which allow to transform single rank VectorArrays into MPI distributed VectorArrays which can be used on rank 0 like ordinary VectorArrays.

The implementations are based on the event loop provided by pymor.tools.mpi.


class pymor.vectorarrays.mpi.MPIVectorArray(obj_id, space)[source]

Bases: pymor.vectorarrays.interface.VectorArray

MPI distributed VectorArray.

Given a local VectorArray on each MPI rank, this wrapper class uses the event loop from pymor.tools.mpi to build a global MPI distributed vector array from these local arrays.

Instances of MPIVectorArray can be used on rank 0 like any other (non-distributed) VectorArray.

Note, however, that the implementation of the local VectorArrays needs to be MPI aware. For instance, cls.inner must perform the needed MPI communication to sum up the local inner products and return the sums on rank 0.

Default implementations for all communication requiring interface methods are provided by MPIVectorArrayAutoComm (also see MPIVectorArrayNoComm).

Note that resource cleanup is handled by object.__del__. Please be aware of the peculiarities of destructors in Python!

The associated VectorSpace is MPIVectorSpace.

__delitem__(ind)[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

__len__()[source]

The number of vectors in the array.

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

copy(deep=False)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

lincomb(coefficients)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.


class pymor.vectorarrays.mpi.MPIVectorArrayAutoComm(obj_id, space)[source]

Bases: pymor.vectorarrays.mpi.MPIVectorArray

MPI distributed VectorArray.

This is a subclass of MPIVectorArray which provides default implementations for all communication requiring interface methods for the case when the wrapped array is not MPI aware.

Note, however, that depending on the model these default implementations might lead to wrong results (for instance in the presence of shared DOFs).

The associated VectorSpace is MPIVectorSpaceAutoComm.

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).


class pymor.vectorarrays.mpi.MPIVectorArrayNoComm(obj_id, space)[source]

Bases: pymor.vectorarrays.mpi.MPIVectorArray

MPI distributed VectorArray.

This is a subclass of MPIVectorArray which overrides all communication requiring interface methods to raise NotImplementedError.

This is mainly useful as a security measure when wrapping arrays for which simply calling the respective method on the wrapped arrays would lead to wrong results and MPIVectorArrayAutoComm cannot be used either (for instance in the presence of shared DOFs).

The associated VectorSpace is MPIVectorSpaceNoComm.

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).


class pymor.vectorarrays.mpi.MPIVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.interface.VectorSpace

VectorSpace of MPIVectorArrays.

Parameters

local_spaces

tuple of the different VectorSpaces of the local VectorArrays on the MPI ranks. Alternatively, the length of local_spaces may be 1, in which case the same VectorSpace is assumed for all ranks.

__eq__(other)[source]

Return self==value.

__repr__()[source]

Return repr(self).

array_type

alias of MPIVectorArray

make_array(obj_id)[source]

Create array from rank-local VectorArray instances.

Parameters

obj_id

ObjectId of the MPI distributed instances of cls wrapped by this array.

Returns

The newly created : class:MPIVectorArray.

zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each component zero.


class pymor.vectorarrays.mpi.MPIVectorSpaceAutoComm(*args, **kwargs)[source]

Bases: pymor.vectorarrays.mpi.MPIVectorSpace

VectorSpace for MPIVectorArrayAutoComm.

array_type

alias of MPIVectorArrayAutoComm


class pymor.vectorarrays.mpi.MPIVectorSpaceNoComm(*args, **kwargs)[source]

Bases: pymor.vectorarrays.mpi.MPIVectorSpace

VectorSpace for MPIVectorArrayNoComm.

array_type

alias of MPIVectorArrayNoComm


class pymor.vectorarrays.mpi.RegisteredLocalSpace[source]

Bases: int

Methods

int

bit_length, conjugate, from_bytes, to_bytes, __ceil__, __floor__, __new__, __round__, __sizeof__, __trunc__

Attributes

int

denominator, imag, numerator, real

__repr__()[source]

Return repr(self).

numpy module


class pymor.vectorarrays.numpy.NumpyVectorArray(array, space)[source]

Bases: pymor.vectorarrays.interface.VectorArray

VectorArray implementation via NumPy arrays.

This is the default VectorArray type used by all Operators in pyMOR’s discretization toolkit. Moreover, all reduced Operators are based on NumpyVectorArray.

This class is just a thin wrapper around the underlying NumPy array. Thus, while operations like axpy or inner will be quite efficient, removing or appending vectors will be costly.

Warning

This class is not intended to be instantiated directly. Use the associated VectorSpace instead.

__delitem__(ind)[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

__len__()[source]

The number of vectors in the array.

__str__()[source]

Return str(self).

property _data

Return NumPy Array view on data for hacking / interactive use.

_norm(*, _ind=None)[source]

Implementation of norm for the case that no product is given.

_norm2(*, _ind=None)[source]

Implementation of norm2 for the case that no product is given.

amax(*, _ind=None)[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x, *, _ind=None)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

conj()[source]

Complex conjugation.

copy(deep=False, *, _ind=None)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

dofs(dof_indices, *, _ind=None)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

property imag

Imaginary part.

inner(other, product=None, *, _ind=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

lincomb(coefficients, *, _ind=None)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

pairwise_inner(other, product=None, *, _ind=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

property real

Real part.

scal(alpha, *, _ind=None)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.

sup_norm(*, _ind=None)[source]

The l-infinity-norms of the vectors contained in the array.

Returns

A NumPy array result such that result[i] contains the norm of self[i].

to_numpy(ensure_copy=False)[source]

Return (len(self), self.dim) NumPy Array with the data stored in the array.

Parameters

ensure_copy

If False, modifying the returned NumPy array might alter the original VectorArray. If True always a copy of the array data is made.


class pymor.vectorarrays.numpy.NumpyVectorArrayView(array, ind)[source]

Bases: pymor.vectorarrays.numpy.NumpyVectorArray

__delitem__()[source]

Remove vectors from the array.

__getitem__(ind)[source]

Return a VectorArray view onto a subset of the vectors in the array.

__len__()[source]

The number of vectors in the array.

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

_norm()[source]

Implementation of norm for the case that no product is given.

_norm2()[source]

Implementation of norm2 for the case that no product is given.

amax()[source]

The maximum absolute value of the DOFs contained in the array.

Returns

max_ind

NumPy array containing for each vector a DOF index at which the maximum is attained.

max_val

NumPy array containing for each vector the maximum absolute value of its DOFs.

append(other, remove_from_other=False)[source]

Append vectors to the array.

Parameters

other

A VectorArray containing the vectors to be appended.

remove_from_other

If True, the appended vectors are removed from other. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy(alpha, x)[source]

BLAS AXPY operation.

This method forms the sum

self = alpha*x + self

If the length of x is 1, the same x vector is used for all vectors in self. Otherwise, the lengths of self and x have to agree. If alpha is a scalar, each x vector is multiplied with the same factor alpha. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the coefficients for each x vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in x are multiplied.

x

A VectorArray containing the x-summands.

copy(deep=False)[source]

Returns a copy of the array.

All VectorArray implementations in pyMOR have copy-on-write semantics: if not specified otherwise by setting deep to True, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.

Note that for NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.

Parameters

deep

Ensure that an actual copy of the array data is made (see above).

Returns

A copy of the VectorArray.

dofs(dof_indices)[source]

Extract DOFs of the vectors contained in the array.

Parameters

dof_indices

List or 1D NumPy array of indices of the DOFs that are to be returned.

Returns

A NumPy array result such that result[i, j] is the dof_indices[j]-th DOF of the i-th vector of the array.

inner(other, product=None)[source]

Returns the inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.inner(V)

is equivalent to:

U.dofs(np.arange(U.dim)) @ V.dofs(np.arange(V.dim)).T

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using apply2, i.e. U.inner(V, product) is equivalent to:

product.apply2(U, V)

which in turn is, by default, implemented as:

U.inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i, j] = ( self[i], other[j] ).

lincomb(coefficients)[source]

Returns linear combinations of the vectors contained in the array.

Parameters

coefficients

A NumPy array of dimension 1 or 2 containing the linear coefficients. coefficients.shape[-1] has to agree with len(self).

Returns

A VectorArray result such that

result[i] = ∑ self[j] * coefficients[i,j]

in case coefficients is of dimension 2, otherwise len(result) == 1 and

result[0] = ∑ self[j] * coefficients[j].

pairwise_inner(other, product=None)[source]

Returns the pairwise inner products between VectorArray elements.

If product is None, the Euclidean inner product between the dofs of self and other are returned, i.e.

U.pairwise_inner(V)

is equivalent to:

np.sum(U.dofs(np.arange(U.dim)) * V.dofs(np.arange(V.dim)), axis=-1)

(Note, that dofs is only intended to be called for a small number of DOF indices.)

If a product Operator is specified, this Operator is used to compute the inner products using pairwise_apply2, i.e. U.inner(V, product) is equivalent to:

product.pairwise_apply2(U, V)

which in turn is, by default, implemented as:

U.pairwise_inner(product.apply(V))

In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.

Parameters

other

A VectorArray containing the second factors.

product

If not None an Operator representing the inner product bilinear form.

Returns

A NumPy array result such that

result[i] = ( self[i], other[i] ).

scal(alpha)[source]

BLAS SCAL operation (in-place scalar multiplication).

This method calculates

self = alpha*self

If alpha is a scalar, each vector is multiplied by this scalar. Otherwise, alpha has to be a one-dimensional NumPy array of the same length as self containing the factors for each vector.

Parameters

alpha

The scalar coefficient or one-dimensional NumPy array of coefficients with which the vectors in self are multiplied.

sup_norm()[source]

The l-infinity-norms of the vectors contained in the array.

Returns

A NumPy array result such that result[i] contains the norm of self[i].

to_numpy(ensure_copy=False)[source]

Return (len(self), self.dim) NumPy Array with the data stored in the array.

Parameters

ensure_copy

If False, modifying the returned NumPy array might alter the original VectorArray. If True always a copy of the array data is made.


class pymor.vectorarrays.numpy.NumpyVectorSpace(*args, **kwargs)[source]

Bases: pymor.vectorarrays.interface.VectorSpace

VectorSpace of NumpyVectorArrays.

Parameters

dim

The dimension of the vectors contained in the space.

id

See id.

__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

full(value, count=1, reserve=0)[source]

Create a VectorArray of vectors with all DOFs set to the same value.

Parameters

value

The value each DOF should be set to.

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each DOF set to value.

property is_scalar

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]

Create a VectorArray of vectors with random entries.

Supported random distributions:

'uniform': Uniform distribution in half-open interval
           [`low`, `high`).
'normal':  Normal (Gaussian) distribution with mean
           `loc` and standard deviation `scale`.

Note that not all random distributions are necessarily implemented by all VectorSpace implementations.

Parameters

count

The number of vectors.

distribution

Random distribution to use ('uniform', 'normal').

low

Lower bound for 'uniform' distribution (defaults to 0).

high

Upper bound for 'uniform' distribution (defaults to 1).

loc

Mean for 'normal' distribution (defaults to 0).

scale

Standard deviation for 'normal' distribution (defaults to 1).

random_state

RandomState to use for sampling. If None, a new random state is generated using seed as random seed, or the default random state is used.

seed

If not None, a new random state with this seed is used.

reserve

Hint for the backend to which length the array will grow.

zeros(count=1, reserve=0)[source]

Create a VectorArray of null vectors

Parameters

count

The number of vectors.

reserve

Hint for the backend to which length the array will grow.

Returns

A VectorArray containing count vectors with each component zero.