pymor.functions package¶
Submodules¶
basic module¶
-
class
pymor.functions.basic.
ConstantFunction
(value=array(1.0), dim_domain=1, name=None)[source]¶ Bases:
pymor.functions.basic.FunctionBase
A constant
Function
f: R^d -> R^shape(c), f(x) = c
Parameters
- value
- The constant c.
- dim_domain
- The dimension d.
- name
- The name of the function.
Methods
-
class
pymor.functions.basic.
ExpressionFunction
(expression, dim_domain=1, shape_range=(), parameter_type=None, name=None)[source]¶ Bases:
pymor.functions.basic.GenericFunction
Turns a Python expression given as a string into a
Function
.Some
NumPy
arithmetic functions like ‘sin’, ‘log’, ‘min’ are supported. For a full list see thefunctions
class attribute.Warning
eval
is used to evaluate the given expression. Using this class with expression strings from untrusted sources will cause mayhem and destruction!Parameters
- expression
- A Python expression of one variable
x
and a parametermu
given as a string. - dim_domain
- The dimension of the domain.
- shape_range
- The shape of the values returned by the expression.
- parameter_type
- The
ParameterType
the expression accepts. - name
- The name of the function.
Methods
-
class
pymor.functions.basic.
FunctionBase
[source]¶ Bases:
pymor.functions.interfaces.FunctionInterface
Base class for
Functions
providing some common functionality.Methods
Attributes
-
__add__
(other)[source]¶ Returns a new
LincombFunction
representing the sum of two functions, or of one function and a constant.
-
__mul__
(other)[source]¶ Returns a new
LincombFunction
representing the product of a function by a scalar.
-
__neg__
()[source]¶ Returns a new
LincombFunction
representing the function scaled by -1.
-
__radd__
(other)¶ Returns a new
LincombFunction
representing the sum of two functions, or of one function and a constant.
-
__rmul__
(other)¶ Returns a new
LincombFunction
representing the product of a function by a scalar.
-
__sub__
(other)[source]¶ Returns a new
LincombFunction
representing the difference of two functions, or of one function and a constant.
-
-
class
pymor.functions.basic.
GenericFunction
(mapping, dim_domain=1, shape_range=(), parameter_type=None, name=None)[source]¶ Bases:
pymor.functions.basic.FunctionBase
Wrapper making an arbitrary Python function between
NumPy arrays
a properFunction
.Note that a
GenericFunction
can only bepickled
if the function it is wrapping can be pickled (cf.dumps_function
). For this reason, it is usually preferable to useExpressionFunction
instead ofGenericFunction
.Parameters
- mapping
The function to wrap. If
parameter_type
isNone
, the function is of the formmapping(x)
. Ifparameter_type
is notNone
, the function has to have the signaturemapping(x, mu)
. Moreover, the function is expected to be vectorized, i.e.:mapping(x).shape == x.shape[:-1] + shape_range.
- dim_domain
- The dimension of the domain.
- shape_range
- The shape of the values returned by the mapping.
- parameter_type
- The
ParameterType
the mapping accepts. - name
- The name of the function.
Methods
-
class
pymor.functions.basic.
LincombFunction
(functions, coefficients, name=None)[source]¶ Bases:
pymor.functions.basic.FunctionBase
A
Function
representing a linear combination ofFunctions
.The linear coefficients can be provided either as scalars or as
ParameterFunctionals
.Parameters
- functions
- List of
Functions
whose linear combination is formed. - coefficients
- A list of linear coefficients. A linear coefficient can
either be a fixed number or a
ParameterFunctional
. - name
- Name of the function.
Methods
Attributes
-
functions
¶
-
coefficients
¶
bitmap module¶
-
class
pymor.functions.bitmap.
BitmapFunction
(filename, bounding_box=[[0.0, 0.0], [1.0, 1.0]], range=[0.0, 1.0])[source]¶ Bases:
pymor.functions.basic.FunctionBase
Define a 2D
Function
via a grayscale image.Parameters
- filename
- Path of the image representing the function.
- bounding_box
- Lower left and upper right coordinates of the domain of the function.
- range
- A pixel of value p is mapped to
(p / 255.) * range[1] + range[0]
.
Methods
interfaces module¶
-
class
pymor.functions.interfaces.
FunctionInterface
[source]¶ Bases:
pymor.core.interfaces.ImmutableInterface
,pymor.parameters.base.Parametric
Interface for
Parameter
dependent analytical functions.Every
Function
is a map of the formf(μ): Ω ⊆ R^d -> R^(shape_range)
The returned values are
NumPy arrays
of arbitrary (but fixed) shape. Note that NumPy distinguishes between one-dimensional arrays of length 1 (with shape(1,)
) and zero-dimensional scalar arrays (with shape()
). In pyMOR, we usually expect scalar-valued functions to haveshape_range == ()
.While the function might raise an error if it is evaluated for an argument not in the domain Ω, the exact behavior is left undefined.
Functions are vectorized in the sense, that if
x.ndim == k
, thenf(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).
In particular,
f(x, μ).shape == x.shape[:-1] + shape_range
.Methods
Attributes
-
dim_domain
¶ The dimension d > 0.
-
shape_range
¶ The shape of the function values.
-