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

Skip to content

Further shorten quiver3d computation... #15373

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
Mar 16, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 3, 2019

... by using einsum instead of juggling axis order.

This has essentially no effect on performance.

followup to #15346.

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

@tacaswell tacaswell added this to the v3.3.0 milestone Oct 4, 2019
@GalAvineri
Copy link

GalAvineri commented Oct 8, 2019

I compared the running time to my PR and I do see about 10% reduction in time when the number of vectors is high when using your PR, so I disagree with the "no effect on performance" part ;)

In addition I received an issue when running your code:

   2622             heads = shafts[:, :1] - np.multiply.outer(arrow_dt, head_dirs)
   2623             # stack left and right head lines together
-> 2624             heads.shape = (len(arrow_dt), -1, 3)
   2625             # transpose to get a list of lines
   2626             heads = heads.swapaxes(0, 1)
AttributeError: incompatible shape for a non-contiguous array

This could be reproduced with this MRE:

x, y, z = [np.random.rand(10) for _ in range(3)]
X, Y, Z = np.meshgrid(x, y, z)
U, V, W = [np.random.rand(*X.shape) for _ in range(3)]
ax.quiver(X, Y, Z, U, V, W)

I believe I solved this with expand_dims before the matrix multiplication on my PR.

Can you confirm that you can reproduce this issue?

@GalAvineri
Copy link

If you can reproduce this as well, that also means that the automatic checks missed it somehow and perhaps they need to be improved as well

@anntzer
Copy link
Contributor Author

anntzer commented Oct 8, 2019

I compared the running time to my PR and I do see about 10% reduction in time when the number of vectors is high when using your PR, so I disagree with the "no effect on performance" part ;)

Is my version faster or yours?

In addition I received an issue when running your code: (elided)

Did you miss https://github.com/matplotlib/matplotlib/pull/15373/files#diff-84224cb1c8cd1f13b7adc5930ee2fc8fR2625?

@GalAvineri
Copy link

Did you miss https://github.com/matplotlib/matplotlib/pull/15373/files#diff-84224cb1c8cd1f13b7adc5930ee2fc8fR2625?

I indeed missed the reshape, thanks! Now there is no issue indeed :)

Is my version faster or yours?

I ran it again and it isn't faster now. I guess this happened because I only looked at the mean and not at the std as well?

@anntzer
Copy link
Contributor Author

anntzer commented Mar 15, 2020

rebased

@timhoffm
Copy link
Member

Flake8:

./lib/mpl_toolkits/mplot3d/axes3d.py:2544:17: E128 continuation line under-indented for visual indent

... by using einsum instead of juggling axis order.

This has essentially no effect on performance.
@anntzer
Copy link
Contributor Author

anntzer commented Mar 15, 2020

fixed

@timhoffm timhoffm merged commit 95c8c88 into matplotlib:master Mar 16, 2020
@anntzer anntzer deleted the morequiver3d branch March 16, 2020 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants