-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cast stackplot input to float when required. #7827
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
Conversation
Current coverage is 62.10% (diff: 100%)@@ master #7827 diff @@
==========================================
Files 174 174
Lines 56052 56052
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
Hits 34809 34809
Misses 21243 21243
Partials 0 0
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a minor comment, but else LGTM 👍
@@ -68,7 +68,8 @@ def stackplot(axes, x, *args, **kwargs): | |||
|
|||
baseline = kwargs.pop('baseline', 'zero') | |||
# Assume data passed has not been 'stacked', so stack it here. | |||
stack = np.cumsum(y, axis=0) | |||
# We'll need a float buffer for the upcoming calculations. | |||
stack = np.cumsum(y, axis=0).astype(np.promote_types(y.dtype, np.float32)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use np.cumsum's dtype's argument instead of casting explicitly after the sum.
np.cumsum(y, axis=0, dtype=np.promote_types(y.dtype, np.float32))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a performance, functional, or an aesthetic improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no clue what it does under the hood, so it might be a performance improvement or just aesthetic improvement. It might avoid a memory allocation, but I wouldn't bet on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea whether it is optimized to avoid the memory allocation but at least it could do so in theory, whereas astype
certainly cannot... so I changed it accordingly.
Please do not backport until after 2.0 |
c87133a
to
e81b280
Compare
Thanks! |
Backported to |
MNT: Cast stackplot input to float when required.
See #7802.