pymor.vectorarrays.numpy¶
Module Contents¶
- class pymor.vectorarrays.numpy.NumpyVectorArray(space, impl, base=None, ind=None, _len=None)[source]¶
Bases:
pymor.vectorarrays.interface.VectorArrayVectorArrayimplementation viaNumPy arrays.This is the default
VectorArraytype used by allOperatorsin pyMOR’s discretization toolkit. Moreover, all reducedOperatorsare based onNumpyVectorArray.This class is just a thin wrapper around the underlying
NumPy array. Thus, while operations likeaxpyorinnerwill be quite efficient, removing or appending vectors will be costly.Warning
This class is not intended to be instantiated directly. Use the associated
VectorSpaceinstead.
- class pymor.vectorarrays.numpy.NumpyVectorArrayImpl(array, l=None)[source]¶
Bases:
pymor.vectorarrays.interface.VectorArrayImplImplementation of a
VectorArray.The
VectorArraybase class defers all calls to interface methods to an internalimplobject of this type. Indexing, error checking or non-standard inner products are handled byVectorArray. Possible indices are passed to the methods ofVectorArrayImplasind,oindorxindparameters. These can either beNone, in case the array has not been indexed, asliceobject, or a Python list of non-negative numbers.Methods
- class pymor.vectorarrays.numpy.NumpyVectorSpace(dim, id=None)[source]¶
Bases:
pymor.vectorarrays.interface.VectorSpaceVectorSpaceofNumpyVectorArrays.Parameters
- dim
The dimension of the vectors contained in the space.
- id
See
id.
Methods
- noindex:
- noindex:
Create a
VectorArrayof vectors with all DOFs set to the same value.- noindex:
Create a
VectorArrayof vectors with random entries.Create a
VectorArrayof null vectors.- from_numpy(data, id=None, ensure_copy=False)[source]¶
Create a
VectorArrayfrom aNumPy array.Note that this method will not be supported by all vector space implementations.
Parameters
- data
NumPyarray of shape(len, dim)wherelenis the number of vectors anddimtheir dimension.- ensure_copy
If
False, modifying the returnedVectorArraymight alter the originalNumPy array. IfTruealways a copy of the array data is made.
Returns
A
VectorArraywithdataas data.
- full(value, count=1, reserve=0)[source]¶
Create a
VectorArrayof 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
VectorArraycontainingcountvectors with each DOF set tovalue.
- make_array(obj, id=None)[source]¶
Create a
VectorArrayfrom raw data.This method is used in the implementation of
OperatorsandModelsto create newVectorArraysfrom 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
VectorArrayof 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
VectorSpaceimplementations.Parameters
- count
The number of vectors.
- distribution
Random distribution to use (
'uniform','normal').- low
Lower bound for
'uniform'distribution (defaults to0).- high
Upper bound for
'uniform'distribution (defaults to1).- loc
Mean for
'normal'distribution (defaults to0).- scale
Standard deviation for
'normal'distribution (defaults to1).- reserve
Hint for the backend to which length the array will grow.
- zeros(count=1, reserve=0)[source]¶
Create a
VectorArrayof null vectors.Parameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.