Cast stackplot input to float when required.#7827
Cast stackplot input to float when required.#7827tacaswell merged 1 commit intomatplotlib:masterfrom
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
|
NelleV
left a comment
There was a problem hiding this comment.
I have a minor comment, but else LGTM 👍
lib/matplotlib/stackplot.py
Outdated
| # 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.
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.
Is this a performance, functional, or an aesthetic improvement?
There was a problem hiding this comment.
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.
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.