pymor.vectorarrays.numpy

Module Contents

class pymor.vectorarrays.numpy.NumpyVectorArray(space, impl, base=None, ind=None, _len=None)[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.

impl_type[source]
class pymor.vectorarrays.numpy.NumpyVectorArrayImpl(array, l=None)[source]

Bases: pymor.vectorarrays.interface.VectorArrayImpl

Implementation of a VectorArray.

The VectorArray base class defers all calls to interface methods to an internal impl object of this type. Indexing, error checking or non-standard inner products are handled by VectorArray. Possible indices are passed to the methods of VectorArrayImpl as ind, oind or xind parameters. These can either be None, in case the array has not been indexed, a slice object, or a Python list of non-negative numbers.

amax(ind)[source]
append(other, remove_from_other, oind)[source]
axpy(alpha, x, ind, xind)[source]
axpy_copy(alpha, x, ind, xind)[source]
conj(ind)[source]
copy(deep, ind)[source]
delete(ind)[source]
dofs(dof_indices, ind)[source]
imag(ind)[source]
inner(other, ind, oind)[source]
lincomb(coefficients, ind)[source]
norm(ind)[source]
norm2(ind)[source]
pairwise_inner(other, ind, oind)[source]
real(ind)[source]
scal(alpha, ind)[source]
scal_copy(alpha, ind)[source]
to_numpy(ensure_copy, ind)[source]
class pymor.vectorarrays.numpy.NumpyVectorSpace(dim, id=None)[source]

Bases: pymor.vectorarrays.interface.VectorSpace

VectorSpace of NumpyVectorArrays.

Parameters

dim

The dimension of the vectors contained in the space.

id

See id.

Methods

from_file

noindex:

from_numpy

noindex:

full

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

make_array

noindex:

random

Create a VectorArray of vectors with random entries.

zeros

Create a VectorArray of null vectors.

from_file(path, key=None, single_vector=False, transpose=False, id=None)[source]
from_numpy(data, id=None, 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.

make_array(obj, id=None)[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.

random(count=1, distribution='uniform', 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).

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.