-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Improved checked_isqrt
and isqrt
methods
#128166
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
Conversation
This comment has been minimized.
This comment has been minimized.
I'll take a closer look in a bit but FYI your last commit message has a typo (s/sped/speed) |
The last force push added a missing file.
OK, thanks for taking a look. Oh, I was using 'sped' as a past tense of the verb form of 'speed'. |
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 left a very superficial review, will need to take some time to double check the important parts (I think the proposed deduplication will make this a bit more straightforward). At a high level these changes are awesome, thanks for the PR!
Ah, I see you did the same for the other commits too. Commit messages are usually in imperative mood to describe what the change does, i.e. "Improve test", "Add benchmarks" "Greatly speed up". Hence my confusion :) (Rust has no commit message policy so no need to anything if you don't feel like it). |
Looks pretty reasonable after a more thorough read through, awesome improvements to the tests. I think this should be good after combining some similar code, just to make things a bit easier to understand & maintain. If you run benchmarks again, could you post your cpu model for a reference? @rustbot author |
I was using After I replaced the benchmarks with equivalents to BenchmarksBefore this pull request
When I first made this pull request
With the changes I'm going to push soon
There's a tradeoff here. In the push I'm going to make soon, randomly chosen inputs from the whole input type range get a decent speedup from the initial pull request's code, but randomly chosen small inputs get about 3 times slower. Is that a good tradeoff? Is there another benchmark that should be added? |
This comment was marked as outdated.
This comment was marked as outdated.
With a uniform distribution, we get these results: Uniform distribution benchmarks
|
Thanks for the changes, this looks a lot tidier with the deduplication. I left a handful of new comments but those are just small things, nothing major. I'm not sure whether you had been waiting on a review, but comment |
This comment was marked as outdated.
This comment was marked as outdated.
With regard to the squash, would it be alright to have two final commits, one for the testing and benchmarking and the next for the implementation? This would allow the benchmarking at least to be run on the prior implementation for comparison. |
@rustbot ready |
☀️ Try build successful - checks-actions |
Great! Thanks for the fix. @bors r+ |
Sorry to bother but is there a particular reason that |
I thought about that too - but it runs the tests on a range of numbers, so it's not really feasible. In theory we could spot check a few numbers or we probably don't really need to test this, but it seems pretty harmless. |
hm, okay! |
The most useful negative integers to test are usually -1, -2, -10, and The last often manages to do something clever. |
Ah that's actually a good point - I thought we were checking a range but it looks like we are checking @ChaiTRex am I missing something? If not, it would be good to add Jubilee's other suggested spot checks since the machinery is already there. It can just be a follow up since this is already in a rollup, and I don't really expect them to fail. |
for n in (0..=127) | ||
.chain(<$T>::MAX - 127..=<$T>::MAX) | ||
.chain((0..<$T>::MAX.count_ones()).map(|exponent| (1 << exponent) - 1)) | ||
.chain((0..<$T>::MAX.count_ones()).map(|exponent| 1 << exponent)) | ||
{ | ||
isqrt_consistency_check(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.
this is the range.
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.
Yeah, I meant specifically a range including negative values
@tgross35 @workingjubilee There are several places where Do |
nemo157 mentioned on the community Discord server that |
I missed that it checked
We can pretty reasonably expect that if it panics on one platform and all other tests pass, it will continue on panic on others. So no worries here, I don't think you need a follow up. |
Improved tests of
isqrt
andchecked_isqrt
implementationsisqrt
andchecked_isqrt
have equivalent results for signed types, either equivalent numerically or equivalent as a panic and aNone
.isqrt
has numerically-equivalent results for unsigned types and theirNonZero
counterparts.Added benchmarks for
isqrt
implementationsGreatly sped up
checked_isqrt
andisqrt
methodsFeature tracking issue
isqrt
is an unstable feature tracked at #116226.Benchmarked improvements
Command used to benchmark
Before
After
Tracking Issue for {u8,i8,...}::isqrt #116226
try-job: test-various