Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
twmr wants to merge4 commits intomatplotlib:masterfromtwmr:pep8examplesapiv3

Conversation

twmr
Copy link
Contributor

@twmrtwmr commentedJul 4, 2014

examples/pylab_examples,examples/units andexamples/use_interface remain to be done.

@@ -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)
Copy link
ContributorAuthor

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]:importnumpyasnpIn [6]:a=np.random.rand(int(1e6))In [7]:b=np.random.rand(int(1e6))In [10]:%timeitnp.abs(a+1j*b)10loops,bestof3:40.4msperloopIn [11]:%timeitnp.hypot(a,b)10loops,bestof3:23.4msperloopIn [12]:%timeitnp.sqrt(a**2+b**2)100loops,bestof3:8.13msperloop

Probably I'll change it back, WDYT ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I changed it tonp.hypot

@ianthomas23
Copy link
Member

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:

If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however.

PEP8 encourages

x = x*2 - 1hypot2 = x*x + y*yc = (a+b) * (a-b)

and discourages

x = x * 2 - 1hypot2 = x * x + y * yc = (a + b) * (a - b)

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)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Excessive whitespace.

@twmr
Copy link
ContributorAuthor

twmr commentedJul 4, 2014

@ianthomas23 I absolutely agree (seePyCQA/pycodestyle#292 (comment)).

@twmr
Copy link
ContributorAuthor

twmr commentedJul 4, 2014

@ianthomas23 I think it would be the best to ignore the space issues for the moment and fix them in a different PR

@tacaswell
Copy link
Member

I want to hold off on these until after 1.4. Touching this many files makes me nervous.

@tacaswelltacaswell added this to thev1.4.x milestoneJul 4, 2014
@twmr
Copy link
ContributorAuthor

twmr commentedAug 8, 2014

I'll recreate a PR once 1.4 is released.

@twmrtwmr closed thisAug 8, 2014
@twmrtwmr mentioned this pull requestAug 27, 2014
@twmrtwmr deleted the pep8examplesapiv3 branchOctober 10, 2014 14:24
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v1.4.x
Development

Successfully merging this pull request may close these issues.

5 participants
@twmr@ianthomas23@tacaswell@efiring@WeatherGod

[8]ページ先頭

©2009-2025 Movatter.jp