diff options
author | Tobias Pitters <tobias.pitters@gmail.com> | 2020-05-26 21:25:28 +0200 |
---|---|---|
committer | Tobias Pitters <tobias.pitters@gmail.com> | 2020-05-27 19:35:59 +0200 |
commit | bf65d6bd293205dda748115db897b14d3d2ececf (patch) | |
tree | 584c2d1d10b5458e77eb92c71835ddef5923718e /numpy/lib | |
parent | 2ffcb119c0235ee7b5c169cae65fcac44064b35a (diff) | |
download | numpy-bf65d6bd293205dda748115db897b14d3d2ececf.tar.gz |
use symmetric lerp function
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 12 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 2 |
2 files changed, 5 insertions, 9 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 6799b2a4f..f56a8844e 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3875,14 +3875,10 @@ def _quantile_is_valid(q): def _lerp(a, b, t, out=None): """ Linearly interpolate from a to b by a factor of t """ - #a + (b-a)*t if t < 0.5 else b - (b-a)*(1-t) - #if t < 0.5: - # return add(a, subtract(b, a)*t, out=out) - #else: - # return subtract(b, subtract(b, a)*(1-t), out=out) - # a + (b-a)*t - offset = subtract(b, a) * t - return add(a, offset, out=out) + if t < 0.5: + return add(a, subtract(b, a)*t, out=out) + else: + return subtract(b, subtract(b, a)*(1-t), out=out) def _quantile_ureduce_func(a, q, axis=None, out=None, overwrite_input=False, diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index de2716bf1..8ef72ea21 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -3153,7 +3153,7 @@ class TestLerp: a=st.floats(allow_nan=False, allow_infinity=False), b=st.floats(allow_nan=False, allow_infinity=False)) def test_lerp_symmetric(self, t, a, b): - assert np.isclose(np.lib.function_base._lerp(a, b, t), np.lib.function_base._lerp(b, a, (1-t))) + assert np.lib.function_base._lerp(a, b, 1 - (1 - t)) == np.lib.function_base._lerp(b, a, 1 - t) class TestMedian: |