Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Avoid unneeded copies from flatten(). #13381

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
Feb 7, 2019
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 7, 2019

flatten() always returns a new copy, but nearly all places that use
flatten() in the codebase don't need to pay that cost; the only place
that needed it did an additional copy. Fix them.
(To be honest it's not clear this will make a measurable difference, but heh.)

As a replacement, there's ravel(), which only makes a copy if the input
is not C-contiguous to start with, and reshape(..., -1) which never
makes a copy (as long as the input is already an ndarray), so prefer the
latter.

Note that in the changed snippet in mplot3d, the AttributeError would
never be raised, as x/y/z are converted to arrays and thus always have a
flatten() method.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

flatten() always returns a new copy, but nearly all places that use
flatten() in the codebase don't need to pay that cost; the only place
that needed it did an additional copy.  Fix them.

As a replacement, there's ravel(), which only makes a copy if the input
is not C-contiguous to start with, and reshape(..., -1) which never
makes a copy (as long as the input is already an ndarray), so prefer the
latter.

Note that in the changed snippet in mplot3d, the AttributeError would
never be raised, as x/y/z are converted to arrays and thus always have a
flatten() method.
@tacaswell tacaswell added this to the v3.1.0 milestone Feb 7, 2019
@NelleV NelleV merged commit e624d6a into matplotlib:master Feb 7, 2019
@anntzer anntzer deleted the unflatten branch February 7, 2019 23:02
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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.