Repository navigation
BUG: Fix uint-overflow if padding with linear_ramp and negative gain (backport) - #14211
Merged
charris merged 1 commit intoSep 9, 2019
Merged
Conversation
Contributor
Author
|
I'll update this once gh-14209 is finalized and merged. |
2 tasks done
linspace supports non-scalar values since version 1.16. This can simplify construction of the ramp for the pad mode "linear_ramp". This removes a bug in the old implementation where certain edge and end values resulted in an integer underflow for unsigned dtypes (see numpygh-14191). Protect against this regression with a new test for all numeric dtypes.
lagru
force-pushed
the
fix-linear-ramp-backport-1-16
branch
from
September 5, 2019 18:36
7e84452 to
1c45e0d
Compare
lagru
commented
Sep 5, 2019
| @@ -244,27 +244,19 @@ def _prepend_ramp(arr, pad_amt, end, axis=-1): | |||
| if pad_amt == 0: | |||
| return arr | |||
Contributor
Author
There was a problem hiding this comment.
This optimization path could be removed as well but I left it for now...
lagru
commented
Sep 5, 2019
| # Reverse linear space in appropriate dimension | ||
| ramp_arr = ramp_arr[ | ||
| _slice_at_axis(ramp_arr.shape, slice(None, None, -1), axis) | ||
| ] |
Contributor
Author
There was a problem hiding this comment.
We could avoid this if linspace had something like startpoint=False (similar to endpoint=False) the we could simply switch the start and stop values. IMO not worth it but I'd be interested to know if such a feature was discussed already.
Member
|
Thanks @lagru . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manual backport (see gh-14191 and gh-14209).
In case end_value was greater than the edge values of the array to pad,
the resulting difference was negative and caused overflows in case the
input array used unsigned types. The new behavior will cast to a
compatible signed dtype that is as small as possible (float16 because of
the division).
Note: Simply casting to float64 doesn't work for complex inputs.
Protect against this regression with a new test for all numeric dtypes.
cc @seberg @charris