-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
vectorized calc_arrow loop in quiver #15346
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
Welcome to matplotlib and thanks for the PR! There are some failing tests. Please check the test logs and try to fix the errors (Personally, I recommend looking at the Travis CI Python 3.6 or Python 3.7 runs first, because they are quite easy to read.) If you need more assistance please do not hesitate to ask. As for speed comparison tests: The most simple solution would be to test the whole |
The earlier tests I made were done in the following way: Instead, I would like to add tests in the code I cloned from github to test my changes in a more organized manner, but I am encountering an issue. I added a test function to the
Can you instruct me how to add tests inside the matplotlib clone? :) |
Have you followed the instructions on Retrieving and installing the latest version of the code? In particular, have you installed your checked out version in developer mode? |
I haven't followed these instructions and I will do so now :) Thanks! |
Ok i've managed to run the existing tests with the replacement of the function to the vectorized form and they all passed. I'll try to upload it here to see if there are any more issues |
All of the tests passed beside one test in travis, but I'm not sure what is the cause of the failure and how I can fix this. |
We impose a limit of 80 characters per line. You have 3 lines that surpass this limit
|
Oh I indeed see this now in the report, thank you! :) I wasn't sure where to look earlier. |
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.
There is no other user of calc_arrow
and it is not public; you should just replace that with your new implementation.
Now that all the checks pass I would like to create the time comparison. |
%load_ext autoreload
%autoreload 2
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
sizes = [1, 10, 50]
def test_times():
times = []
for n in sizes:
fig = plt.figure()
ax = fig.gca(projection='3d')
x, y, z = [np.random.rand(n) for _ in range(3)]
X, Y, Z = np.meshgrid(x, y, z)
U, V, W = [np.random.rand(*X.shape) for _ in range(3)]
time = %timeit -o ax.quiver(X, Y, Z, U, V, W)
times.append(time)
plt.close()
return times
838 µs ± 6.94 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
906 µs ± 616 ns per loop (mean ± std. dev. of 7 runs, 1000 loops each) plt.figure()
num_vec = np.power(sizes, 3)
averages_old = [t.average for t in times_old]
averages_new = [t.average for t in times_new]
stds_old = [t.stdev for t in times_old]
stds_new = [t.stdev for t in times_new]
plt.errorbar(num_vec, averages_old, stds_old, label='loop')
plt.errorbar(num_vec, averages_new, stds_new, label='vectorization')
plt.legend()
plt.ylabel('time[sec]')
plt.xlabel('num vectors')
plt.yscale('log')
plt.xscale('log') |
Is there anything more I should provide? |
Power-cycled to re-start CI against current master. |
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.
Looks good to me
Thanks @GalAvineri !
Looks great! Do you want to squash your commits? |
Yeah I'll squash my commits when I get to the pc :) |
90af056
to
01b0eb9
Compare
Thanks, hoping to see you around again! |
I hope so too! :D |
PR Summary
The
quiver
function, in the axes3d module, has a loop callingcalc_arrow
which operates on a single vector. This can become very time consuming when the number of vectors is large.The
calc_arrow
function could be easily vectorized, which could achieve speedup, and this PR presents a vectorized version.PR Checklist
I did some tests that show significant time reduction, where this loop is the bottle neck, but the tests were not so organized.
I would like to supply simple speed comparison test, but the
calc_arrow
function is an inner function of thequiver
function and I couldn't find an elegant way to test.Could you suggest a method by which I could supply a time comparison?
Btw i'm quite new in contributing to projects so if there are additional things I should know about, I would love to have guidance :)