diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2020-05-17 15:26:25 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2020-05-18 22:26:32 +0100 |
commit | f70c2c507f3664901e97754e98b8e30e8e39b85d (patch) | |
tree | 2069da43d28868b43669f9e10aea2e9a9af6976f /numpy/lib/function_base.py | |
parent | 49a84f6fd548c0d01d5dbd6ee286cdaa49fd6209 (diff) | |
download | numpy-f70c2c507f3664901e97754e98b8e30e8e39b85d.tar.gz |
MAINT: Extract a lerp helper function to make the algorithm of quantile clearer
This does not affect the behavior in any way
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 2d1adc362..9b547d823 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3870,6 +3870,11 @@ def _quantile_is_valid(q): return True +def _lerp(a, b, t, out=None): + """ Linearly interpolate from a to b by a factor of t """ + return add(a*(1 - t), b*t, out=out) + + def _quantile_ureduce_func(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False): a = asarray(a) @@ -3958,14 +3963,14 @@ def _quantile_ureduce_func(a, q, axis=None, out=None, overwrite_input=False, indices_above = indices_above[:-1] n = np.isnan(ap[-1:, ...]) - x1 = take(ap, indices_below, axis=axis) * (1 - weights_above) - x2 = take(ap, indices_above, axis=axis) * weights_above - + x1 = take(ap, indices_below, axis=axis) + x2 = take(ap, indices_above, axis=axis) if zerod: x1 = x1.squeeze(0) x2 = x2.squeeze(0) + weights_above = weights_above.squeeze(0) - r = add(x1, x2, out=out) + r = _lerp(x1, x2, weights_above, out=out) if np.any(n): if zerod: |