GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-38629: implement __floor__ and __ceil__ for float by isidentical · Pull Request #16985 · python/cpython

Conversation

@isidentical

@isidentical isidentical commented Oct 29, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue38629

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Oct 29, 2019
@bedevere-bot bedevere-bot added the awaiting review label Oct 29, 2019
vstinner
vstinner reviewed Oct 29, 2019
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

What is the performance impact on math.floor(1.0) and math.ceil(1.0)? Faster, slower, no significant impact?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdickinson reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Objects/floatobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

mdickinson
mdickinson reviewed Oct 29, 2019
View reviewed changes
Comment thread Objects/floatobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mdickinson

mdickinson commented Oct 29, 2019

Copy link
Copy Markdown
Member

This PR needs tests.

serhiy-storchaka and ZackerySpytz reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdickinson
mdickinson suggested changes Oct 29, 2019
View reviewed changes

@mdickinson mdickinson left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Thanks for this PR. Some changes are needed:

  • The PR needs unit tests.
  • The implementations won't do the right thing on machines with 32-bit longs: there's no adjustment for non-integer values in the non-fast path.
  • As @vstinner suggested, it would be much simpler to just use the libm functions ceil and floor.
  • There's no real need for the fast path, given #15611: I'd suggest dropping that and simply sending the output of ceil and floor into PyLong_FromDouble.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot removed the awaiting review label Oct 29, 2019
@bedevere-bot

bedevere-bot commented Oct 29, 2019

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added the awaiting changes label Oct 29, 2019
@isidentical
bpo-38629: implement __floor__ and __ceil__ for float
0b36750
@isidentical
isidentical force-pushed the bpo-38629 branch from e4ff4b8 to 0b36750 Compare October 30, 2019 15:13
@isidentical

isidentical commented Oct 30, 2019

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Oct 30, 2019
@bedevere-bot

bedevere-bot commented Oct 30, 2019

Copy link
Copy Markdown

Thanks for making the requested changes!

@mdickinson: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot
bedevere-bot requested a review from mdickinson October 30, 2019 15:14
@isidentical
update generated files
e1ac18c
@isidentical

isidentical commented Oct 30, 2019

Copy link
Copy Markdown
Member Author

I submitted benchmarks to bpo

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brandtbucher brandtbucher added the type-feature A feature request or enhancement label Oct 30, 2019
mdickinson
mdickinson approved these changes Oct 30, 2019
View reviewed changes

@mdickinson mdickinson left a comment

Copy link
Copy Markdown
Member

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.

Changes LGTM; thank you! The performance is still a concern, but if some form of #16991 gets merged then that wouldn't be so much of an issue.

@serhiy-storchaka @vstinner Does the current state of the PR seem okay to you?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting change review labels Oct 30, 2019
serhiy-storchaka
serhiy-storchaka reviewed Oct 30, 2019
View reviewed changes
Comment thread Objects/floatobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Oct 30, 2019

Copy link
Copy Markdown
Member

#16991 will solve the performance issue for exact floats, but not for subclasses.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdickinson

mdickinson commented Oct 31, 2019

Copy link
Copy Markdown
Member

will solve the performance issue for exact floats, but not for subclasses.

I don't think there's too much reason to care about fine-tuning of performance for float subclasses. The most common subclass is NumPy's float64, and if you're using NumPy you're likely using NumPy's floor instead of math.floor anyway.

isidentical reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@isidentical
isidentical requested a review from serhiy-storchaka November 1, 2019 11:37
@isidentical
isidentical requested a review from vstinner November 15, 2019 13:38
@isidentical
use PyFloat_AS_DOUBLE for getting direct value without checking
40db4db
@isidentical
isidentical force-pushed the bpo-38629 branch from b2bd4eb to 40db4db Compare December 3, 2019 14:59
@vstinner

vstinner commented Dec 5, 2019

Copy link
Copy Markdown
Member

me:

What is the performance impact on math.floor(1.0) and math.ceil(1.0)? Faster, slower, no significant impact?

I checked the current implementation of math.floor(): there is a fast-path for exact type float which does something like PyLong_FromDouble(floor(PyFloat_AS_DOUBLE(number))).

I'm fine with calling the __floor__() method for subclasses. That's the purpose of subclasses: being able to override some methods. That's part of the Python semantics.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Dec 5, 2019

Copy link
Copy Markdown
Member

I checked the current implementation of math.floor(): there is a fast-path for exact type float which does something like PyLong_FromDouble(floor(PyFloat_AS_DOUBLE(number))).

Oh, that's @serhiy-storchaka 's PR #16991 which has just been merged. I didn't notice ;-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner approved these changes Dec 5, 2019
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

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.

LGTM. There is no performance overhead on math.floor() and math.ceil() for exact float.

I'm fine with having a small overhead for float subclasses. I didn't measure the overhead, I expect it to be really small or even not significant.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner

vstinner commented Dec 5, 2019

Copy link
Copy Markdown
Member

@mdickinson @serhiy-storchaka: I'm not sure that you agree, so I didn't merge the PR. I approve the PR, so I'm fine with merging it. What about you?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Dec 14, 2019

Copy link
Copy Markdown
Member

@mdickinson @serhiy-storchaka: I plan to merge this PR next Friday (December 21) if no one replies.

@isidentical: Please ping me next Friday if I forget to merge your PR.

isidentical reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdickinson

mdickinson commented Dec 15, 2019

Copy link
Copy Markdown
Member

@vstinner Merging is fine with me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit cb8b946 into python:master Dec 15, 2019
@bedevere-bot bedevere-bot removed the awaiting merge label Dec 15, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
@isidentical @shihai1991
bpo-38629: implement __floor__ and __ceil__ for float type (pythonGH-…
5d7d318
…16985)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@serhiy-storchaka serhiy-storchaka Awaiting requested review from serhiy-storchaka
+1 more reviewer
@mdickinson mdickinson mdickinson approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@isidentical @mdickinson @bedevere-bot @serhiy-storchaka @vstinner @the-knights-who-say-ni @brandtbucher
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.