-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-118750: Asymptotically faster int(string)
#118751
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
Merged
Merged
Changes from 53 commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
7ecf234
Adding new, but unsued, `_dec_str_to_int_inner()`, + discussion.
tim-one 6abc9cc
Correction: `decimal` in this conext computes reciprocals of powers
tim-one f4c15ce
Clarify precedence in assert.
tim-one 8673dcb
Update Lib/_pylong.py
tim-one b1aa316
Update Lib/_pylong.py
tim-one d9490d0
Update Lib/_pylong.py
tim-one 734ca08
Merge branch 'main' into str2int
tim-one 0512f07
Merge branch 'main' into str2int
tim-one b2734c2
My memory was wrong: using explicit, cached reciprocal approximations…
tim-one c0570e7
Merge branch 'str2int' of https://github.com/tim-one/cpython into str…
tim-one 9906417
Repair mysterious damage to comment.
tim-one 27b00ea
Cut the precision of the reciprocal too before multiplying.
tim-one 46c400b
Merge branch 'main' into str2int
tim-one 1e1b26d
New comments.
tim-one 2f3b6b8
Typo repair.
tim-one fc2f646
Raise BYTELIM.
tim-one 0a1daab
For long strings, switch to the new implementation if `_decimal` is p…
tim-one 1977774
📜🤖 Added by blurb_it.
blurb-it[bot] 5ce49ae
Update 2024-05-09-02-37-25.gh-issue-118750.7aLfT-.rst
tim-one 998b871
Do a better job of picking working precision for the multiply.
tim-one 35605ea
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 53b4fa8
Fotce the initial `w` to be an upper bound on the true value.
tim-one 34774d6
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 1a78510
Serhiy wore me out ;-) Add best possible log(10, 255) constant.
tim-one b766ebf
Repair comment.
tim-one 3b585fb
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 9cccb8d
Repair test for "close to maybe wrong" initial computation of `w`.
tim-one 96df6f5
Merge remote-tracking branch 'upstream/main' into str2int
tim-one a241843
Added exact quotient correction for cases adding 1 once isn't enough.
tim-one d67dfd1
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 45708db
Check in testing helper I kept ripping out before earlier commits.
tim-one 83f07da
And one more test, of thta absurdly large inputs are rejected.
tim-one ae41a10
Trying to repair new test that failed on some test platforms.
tim-one 3779a92
I don't know what the "WASI" testbot is, except that it's annoying ;-)
tim-one 5140c23
And more random thrashing.
tim-one 45c1da0
Another random stab at making WASI happy.
tim-one ee17e54
More random thrashing to try to shut up WASI :-(
tim-one 98cfca4
Merge remote-tracking branch 'upstream/main' into str2int
tim-one ed18fdc
Make GUARD a keyword-only argument. Plus many comment changes.
tim-one a5def42
repair spelling mistake in comment
tim-one 727d396
Update Lib/_pylong.py
tim-one 505012c
Update Lib/_pylong.py
tim-one 25b47c7
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 83ea161
I now believe GUARD=3(!) is sufficient. And that's the smallest
tim-one 07c70bd
Apply suggestions from code review
tim-one fcfa5aa
The lint checker whinef about a blank line at the end of the file.
tim-one 7763ab2
And restoring another code review change.
tim-one b1443ef
Update Lib/test/test_int.py
tim-one 3ee6247
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 44c85ac
Made suggested word change.
tim-one 1a90eb6
Just commehts: be more careful about explaining how bad the
tim-one cd07da3
Typo repair.
tim-one a985009
Someone should contribute a spell-checker to IDLE ;-)
tim-one 7d4c3e8
Merge remote-tracking branch 'upstream/main' into str2int
tim-one ec326b3
Free the memory for `hi` as soon as we're done with it.
tim-one 922dca1
Add notes about the details of how reciprocals are computed.
tim-one 9fe92f3
Repair grammar.
tim-one 4e360e8
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 4eaccfc
Apply suggestions from code review
tim-one 19c0690
Merge branch 'str2int' of https://github.com/tim-one/cpython into str…
tim-one 5178e09
Big change: keeping the exact reciprocals now.
tim-one 5a0a574
Remove no-longer-useful reset of ctx.prec.
tim-one 1ee272e
Reciprocal approximations are back - you knew it was coming ;-)
tim-one 3129d5f
Comment repair.
tim-one d1a1fce
Merge remote-tracking branch 'upstream/main' into str2int
tim-one bfd6247
Finished the proof - no more hand-waving on any point :-)
tim-one 751aab4
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 81ef287
Fix tiny typos in comments.
tim-one d5818df
Fudge. Typo repair is adding new typos too :-(
tim-one 70e7240
Merge remote-tracking branch 'upstream/main' into str2int
tim-one ca621e2
Consolidate all the seemingly random observations aboud .adjusted(),
tim-one c8b69b8
typo
tim-one 5cff910
And we don't ever need exact reicrocals after all!
tim-one 29ecb3f
Remove a mention of exact reciprocals, since they're no longer used.
tim-one a2bbe09
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 495fe8e
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 617b5e2
Update comments. No code changes.
tim-one 28552fb
And exact reciprocals are back.
tim-one a523fd4
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 03225f3
Split on ceiling(w/2) instead of on the floor.
tim-one 0b454ba
Delete a line of unused code.
tim-one 1afe4df
Update Lib/_pylong.py
tim-one 6999ec7
Merge branch 'str2int' of https://github.com/tim-one/cpython into str…
tim-one 1f52d1d
typo
tim-one f1469cf
Bah. Another typo.
tim-one aa8381a
Merge branch 'main' into str2int
tim-one d24ae92
Repair thinko in comment.
tim-one e1549b6
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 3d74801
Splitting on ceiling(w/2) gave compute_powers() a harder job.
tim-one e435907
Merge branch 'main' into str2int
tim-one c6f6126
Reduce excessive indentation.
tim-one 74bcebb
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 52205b4
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 61253a4
Give compute_powers() another IQ boost.
tim-one a2814b5
Add basic compoute_powers() test.
tim-one b16e639
At least whan I make a typo, auto-commplete reproduces it ;-)
tim-one bc440b8
Fix old typo in comment everyone missed ;-)
tim-one 60797ab
Correct technical detail in comment.
tim-one 1d4f3a0
And another stray typo :-(
tim-one c5ef2ce
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 0033cd5
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 057b5e9
Apply suggestions from code review
tim-one 7570147
Merge branch 'str2int' of https://github.com/tim-one/cpython into str…
tim-one fc09650
Apply suggestions from code review
tim-one 484dd0b
Merge branch 'str2int' of https://github.com/tim-one/cpython into str…
tim-one 6c634c7
Add limit=0 to compute_powers() "by hand" testing.
tim-one a288adc
Merge remote-tracking branch 'upstream/main' into str2int
tim-one 9ee61f6
Reduce cutoff for calling the new implementation from 3.5M to 2M.
tim-one 8d5bc36
Update NEWS.
tim-one 46cf316
Sheesh - put a wrong number in the new NEWS.
tim-one e39985e
Merge remote-tracking branch 'upstream/main' into str2int
tim-one f1cf315
Spell out the additional new reason not to do int(Decimal) directly.
tim-one File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Core and Builtins/2024-05-09-02-37-25.gh-issue-118750.7aLfT-.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| If the C version of the ``decimal`` module is available, ``int(str)`` now uses it to supply an asymptotically much faster conversion. However, this only applies if the string contains over about 3.5 million digits. |
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.
Uh oh!
There was an error while loading. Please reload this page.