-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG ensure monotonic property of lerp in numpy.percentile #15098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
1cdb83d
845d219
aac5e41
313ea69
2fbbf72
786c7bb
5ba6527
64258de
e5f1d0c
64c6fa1
9607d2b
733469d
045a7e3
6f070c2
e9449a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3929,21 +3929,35 @@ 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) * weights_below | ||
x2 = take(ap, indices_above, axis=axis) * weights_above | ||
x1 = take(ap, indices_below, axis=axis) | ||
x2 = take(ap, indices_above, axis=axis) | ||
|
||
# the linear interpolation below ensure monotonicity with floating | ||
# point operations and was proposed in: | ||
# https://math.stackexchange.com/a/1798323 by Pedro Gimeno | ||
diff_x2_x1 = x2 - x1 | ||
r_above = x1 + diff_x2_x1 * we 10000 ights_above | ||
r_below = x2 - diff_x2_x1 * weights_below | ||
|
||
# ensure axis with q-th is first | ||
x1 = np.moveaxis(x1, axis, 0) | ||
x2 = np.moveaxis(x2, axis, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you kept these lines, and did them before the computation, then you'd be able to do:
|
||
r_above = np.moveaxis(r_above, axis, 0) | ||
r_below = np.moveaxis(r_below, axis, 0) | ||
|
||
if zerod: | ||
x1 = x1.squeeze(0) | ||
x2 = x2.squeeze(0) | ||
weights_above = weights_above.squeeze(0) | ||
weights_below = weights_below.squeeze(0) | ||
r_above = r_above.squeeze(0) | ||
r_below = r_below.squeeze(0) | ||
|
||
r = np.where(weights_above < 0.5, r_above, r_below) | ||
glemaitre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if out is not None: | ||
r = add(x1, x2, out=out) | ||
out[...] = r | ||
r = out | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment to out should not be necessary here, the above operation is already in-place (i.e. similar to the old branch, which did not do this). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @seberg is the double-assignment cleanup a blocker? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not on its own, but I think the above also needs some cleanups, maybe I should just put it on my todo list to do it myself. |
||
else: | ||
r = add(x1, x2) | ||
# get the element stored in the 0-d array for backward | ||
# compatibility | ||
r = r[()] | ||
|
||
if np.any(n): | ||
if zerod: | ||
|
Uh oh!
There was an error while loading. Please reload this page.