Title: Increase speed of Fractions.limit_denominator · Issue #93476 · python/cpython · GitHub
Open Graph Title: Increase speed of Fractions.limit_denominator · Issue #93476 · python/cpython
X Title: Increase speed of Fractions.limit_denominator · Issue #93476 · python/cpython
Description: Feature or enhancement Speed up Fractions.limit_denominator by not creating intermediary Fraction objects Pitch Fractions.limit_denominator returns a new Fraction, but along the way for Fractions > max_denominator creates 3 Fraction obje...
Open Graph Description: Feature or enhancement Speed up Fractions.limit_denominator by not creating intermediary Fraction objects Pitch Fractions.limit_denominator returns a new Fraction, but along the way for Fractions >...
X Description: Feature or enhancement Speed up Fractions.limit_denominator by not creating intermediary Fraction objects Pitch Fractions.limit_denominator returns a new Fraction, but along the way for Fractions &...
Opengraph URL: https://github.com/python/cpython/issues/93476
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Increase speed of Fractions.limit_denominator","articleBody":"**Feature or enhancement**\r\n\r\nSpeed up Fractions.limit_denominator by not creating intermediary Fraction objects\r\n\r\n**Pitch**\r\n\r\n`Fractions.limit_denominator` returns a new Fraction, but along the way for Fractions \u003e max_denominator creates 3 Fraction objects that are discarded: the fraction farther from the bound and two temporary fractions (`bound1 - self` and `bound2 - shelf`) which are created just for getting their absolute values.\r\n\r\nSimilar code speedups have been part of the `music21` library since 2015--where we call limit_denominator after every arithmetic operation on note placement--and timing tests give a 7.3x speedup. (see [music21 Source](https://github.com/cuthbertLab/music21/blob/dcd23748052bfc4e02d5f94a9ff3de5b88ffcb89/music21/common/numberTools.py#L150) )\r\n\r\nFor fractions with denominators equal to or below max_denominator, instantiate the new Fraction with `Fraction(self._numerator, self._denominator)` instead of `Fraction(self)` for a 23% speedup.\r\n\r\nPR to follow.","author":{"url":"https://github.com/mscuthbert","@type":"Person","name":"mscuthbert"},"datePublished":"2022-06-03T21:05:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/93476/cpython/issues/93476"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:98c6f33f-f7cd-16c1-d5c4-b11f0f801919 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD10:31B257:913B0C:C205EA:69697DE5 |
| html-safe-nonce | 6123018529d9c384257bb709501268771dc01c1028166624e3a55703621463ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDEwOjMxQjI1Nzo5MTNCMEM6QzIwNUVBOjY5Njk3REU1IiwidmlzaXRvcl9pZCI6IjI5Mjg2OTAzNTkyNzAyMTEwNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ddf941ce4fa0d32f5643db1e1034daf92c40cb347bb1a146fc450815d296d77c |
| hovercard-subject-tag | issue:1260379256 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/93476/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d87e1991719a565b4fc0200fb7387ab3616a0d8b954852189056d136151d511/python/cpython/issues/93476 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d87e1991719a565b4fc0200fb7387ab3616a0d8b954852189056d136151d511/python/cpython/issues/93476 |
| og:image:alt | Feature or enhancement Speed up Fractions.limit_denominator by not creating intermediary Fraction objects Pitch Fractions.limit_denominator returns a new Fraction, but along the way for Fractions >... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mscuthbert |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width