-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pep8ify examples/ part 3 #3183
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
pep8ify examples/ part 3 #3183
Conversation
@@ -82,48 +84,53 @@ def get_ind_under_point(self, event): | |||
xy = np.asarray(self.pathpatch.get_path().vertices) | |||
xyt = self.pathpatch.get_transform().transform(xy) | |||
xt, yt = xyt[:, 0], xyt[:, 1] | |||
d = np.sqrt((xt-event.x)**2 + (yt-event.y)**2) | |||
d = np.abs((xt - event.x) + (yt - event.y) * 1j) |
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.
I did this in several places - hope you are fine with that.
I just discovered that the sqrt version is the fastest compared to the complex version and np.hypot.
In [5]: import numpy as np
In [6]: a = np.random.rand(int(1e6))
In [7]: b = np.random.rand(int(1e6))
In [10]: %timeit np.abs(a + 1j * b)
10 loops, best of 3: 40.4 ms per loop
In [11]: %timeit np.hypot(a, b)
10 loops, best of 3: 23.4 ms per loop
In [12]: %timeit np.sqrt(a ** 2 + b ** 2)
100 loops, best of 3: 8.13 ms per loop
Probably I'll change it back, WDYT ?
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.
I changed it to np.hypot
I don't approve of the blanket use of whitespace around all binary operators. In many cases this renders the code less readable than before, and is contrary to PEP8, which says:
PEP8 encourages
and discourages
I'll indicate some of the changes that use excessive whitespace regardless of operator priority, contrary to PEP8. If we are going to use an automated tool to correct PEP8 compliance, it must be configured to be less aggressive than this. |
print('idle', on_idle.count) | ||
line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N))) | ||
line1.set_ydata(np.sin(2 * np.pi * t * (N - on_idle.count) / float(N))) |
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.
Excessive whitespace.
@ianthomas23 I absolutely agree (see PyCQA/pycodestyle#292 (comment)). |
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
@ianthomas23 I think it would be the best to ignore the space issues for the moment and fix them in a different PR |
I want to hold off on these until after 1.4. Touching this many files makes me nervous. |
I'll recreate a PR once 1.4 is released. |
examples/pylab_examples
,examples/units
andexamples/use_interface
remain to be done.