underworld.function.view module¶
This module includes functions which provide views into the results of function queries. These functions never modify query data.
Module Summary¶
classes:¶
underworld.function.view.min_max |
This function records the min & max result from a queried function. |
Module Details¶
classes:¶
-
class
underworld.function.view.
min_max
(fn, *args, **kwargs)[source]¶ Bases:
underworld.function._function.Function
This function records the min & max result from a queried function.
Note that this function simply records maximum and minimum values encountered as it evaluated. Until it is evaluated at least once, the values returned via one of its methods (‘min_local’, ‘min_global’, etc ) will be the initialisation values and bear no relation to the min or max of the subject function.
For vector input types, this function will report on the magnitude of the vector.
Parameters: fn (underworld.function.Function) – The subject function. Function must return a float type. Example
Create a simple function which returns two times its input:
>>> import underworld as uw >>> import underworld.function as fn >>> import numpy as np >>> fn_simple = fn.input()[0]*2.
Let’s wrap it with a min_max function:
>>> fn_minmax_simple = fn.view.min_max(fn_simple)
Now do an evaluation:
>>> fn_minmax_simple.evaluate(5.) array([[ 10.]])
Since there’s only been one evaluation, min and max values should be identical:
>>> fn_minmax_simple.min_global() 10.0 >>> fn_minmax_simple.max_global() 10.0
Do another evaluation:
>>> fn_minmax_simple.evaluate(-3.) array([[-6.]])
Now check min and max again:
>>> fn_minmax_simple.min_global() -6.0 >>> fn_minmax_simple.max_global() 10.0
Note that if we only evaluate the subject function, no min/max values are recorded:
>>> fn_simple.evaluate(3000.) array([[ 6000.]]) >>> fn_minmax_simple.max_global() 10.0
Also note that for vector valued subject function, only a magnitude is considered:
>>> from . import _systemmath as math >>> fn_vec = fn.view.min_max(fn.input()) >>> fn_vec.evaluate( ( 1., 1.) ) array([[ 1., 1.]]) >>> np.allclose(fn_vec.min_global(), math.sqrt(2.)) True >>> np.allclose(fn_vec.max_global(), math.sqrt(2.)) True >>> fn_vec.evaluate( ( -1., 0.) ) array([[-1., 0.]]) >>> np.allclose(fn_vec.min_global(), 1. ) True >>> np.allclose(fn_vec.max_global(), math.sqrt(2.)) True
-
max_global
()[source]¶ Returns the maximum value encountered across all processes.
Notes
This method must be called by collectively all processes.
Returns: double Return type: maximum value
-
max_local
()[source]¶ Returns the max value encountered locally on the current process.
Returns: double Return type: maximum value
-
min_global
()[source]¶ Returns the minimum value encountered across all processes.
Notes
This method must be called by collectively all processes.
Returns: double Return type: minimum value
-