Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Jan 15, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 14, 2017

See #7802.

@codecov-io
Copy link

codecov-io commented Jan 14, 2017

Current coverage is 62.10% (diff: 100%)

Merging #7827 into master will not change coverage

@@             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          

Powered by Codecov. Last update 9edcb03...c87133a

Copy link
Member

@NelleV NelleV left a 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))
Copy link
Member

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))

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@NelleV NelleV changed the title Cast stackplot input to float when required. [MRG+1] Cast stackplot input to float when required. Jan 14, 2017
@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Jan 14, 2017
@tacaswell
Copy link
Member

Please do not backport until after 2.0

@anntzer anntzer force-pushed the stackplot-integer-input branch from c87133a to e81b280 Compare January 15, 2017 04:14
@tacaswell tacaswell merged commit 86bf661 into matplotlib:master Jan 15, 2017
@tacaswell
Copy link
Member

Thanks!

@QuLogic
Copy link
Member

QuLogic commented Jan 30, 2017

Backported to v2.0.x as 7cd3068.

@QuLogic QuLogic changed the title [MRG+1] Cast stackplot input to float when required. Cast stackplot input to float when required. Jan 30, 2017
@anntzer anntzer deleted the stackplot-integer-input branch January 30, 2017 03:26
QuLogic pushed a commit that referenced this pull request Jan 30, 2017
MNT: Cast stackplot input to float when required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants