Commit dfd8a9ed authored by Kloss's avatar Kloss

rearange arguments of _match_functions, update tests

parent 3e1668f5
......@@ -419,7 +419,7 @@ def _save_ordering(func):
def _match_functions(func, xmin=-1, xmax=1, tol=1E-8, min_iter=10,
interval_converged=None, evaluated=None, max_iter=100000):
max_iter=100000, interval_converged=None, evaluated=None):
"""Match the elements of a vector valued function, such that
each vector element describes a continous function.
......@@ -434,13 +434,16 @@ def _match_functions(func, xmin=-1, xmax=1, tol=1E-8, min_iter=10,
Upper interval boundary to order the function. Defaut = 1.
tol : float, optional
Numerical tolerance.
min_iter : int, optional
Minimal number of iterations of the matching alorithm.
Defaut = 10
max_iter : int, optional
Maximum number of iterations of the matching alorithm. Defaut = 100000
interval_converged : callable, optional
Error estimate for the interval.
Defaut: 3-point estimate for local cubic interpolants
evaluated : dict, optional
Dict of precalculated function values
max_iter : int, optional
Maximum number of iterations of the matching alorithm. Defaut = 100000
Returns
-------
......@@ -501,9 +504,9 @@ def _match_functions(func, xmin=-1, xmax=1, tol=1E-8, min_iter=10,
assert _is_type(xmin, 'real_number')
assert _is_type(xmax, 'real_number')
assert _is_type(tol, 'real_number')
assert _is_type(max_iter, 'integer')
assert _is_type(min_iter, 'integer')
assert min_iter > 0
assert _is_type(max_iter, 'integer')
assert 0 < min_iter < max_iter
assert tol > 0
assert callable(func)
......
......@@ -126,7 +126,7 @@ def test_gap_detection_tolerance():
def gap_detected(x0, gap, tol):
func = partial(gap_function, gap=gap, x0=x0)
x, y, dy, *_ = ks._match_functions(func, -1, 1, tol=tol)
x, y, dy, *_ = ks._match_functions(func, -1, 1, tol=tol, min_iter=1)
yy = func(x)[0].T
return np.allclose(y, yy)
......@@ -292,6 +292,19 @@ def test_function_mapping():
xr = 2
assert not ks._leftmost_crossing(func(xl), func(xr), xl, xr)
# test from benoit rossignol where
# f(-pi) = f(0) = f(pi) = 1 and f'(-pi) = f'(0) = f'(pi) = 0
# such that the symmetric center point convergence estimate
# (on the points -pi, 0, pi) fails. if no minimal number of splits
# is required (which can be simulated by setting min_split = 1) the
# algorithm will erroneously assume to be converged with only three points.
def f(x):
return np.array([[np.cos(2*x)], [-2*np.sin(2*x)]])
x, y, dy, *_ = ks._match_functions(f, xmin=-np.pi, xmax=np.pi)
assert len(x) > 3
def test_cost_matrix():
# take linear functions since cost matrix is calculated in linear approx.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment