Skip to content

Increase numerical precision of log1p #5757

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 1 commit into from
Apr 30, 2025
Merged

Conversation

kralka
Copy link

@kralka kralka commented Apr 29, 2025

Use Rust native ln_1p to increase numerical precision matching what is expected by test_mtestfile.

Use Rust native ln_1p to increase numerical precision matching what is
expected by `test_mtestfile`.
@kralka
Copy link
Author

kralka commented Apr 29, 2025

The test test_mtestfile passes now under 0.1s on my machine but perhaps the decorator is referring to some CI pipeline?

@unittest.skip("TODO: RUSTPYTHON, Taking a few minutes.")

@arihant2math
Copy link
Collaborator

Does commenting out that line lead to the test being visibly slower?
@unittest.skip unconditionally skips the test everywhere, fyi.

@youknowone
Copy link
Member

yep, please try remove the line and check your test pass

@kralka
Copy link
Author

kralka commented Apr 30, 2025

@arihant2math @youknowone

Removing the line and running on a laptop with SSD and https://hub.docker.com/_/rust (linux). Running RUSTPYTHONPATH=Lib cargo run --release Lib/test/test_math.py MathTests.test_mtestfile

  • Skipping the test takes 0.0s
  • Not skipping the test takes 0.003s.
  • The test failing (without the change of (x+1).ln to x.ln_1p) takes 0.006s.

This is why I left the test skipping since there was a comment that said "TODO: RUSTPYTHON, Taking a few minutes." because it takes a few minutes somewhere (CI like github actions, different operating system?). Perhaps you as authors of #5733 have more information here?

The downside is that Rust documentation is saying that numerical stability of ln_1p (and many other functions) could change: https://doc.rust-lang.org/std/primitive.f64.html#method.ln_1p But I assume that is still better than calling a C library over pymath. What do you think?

@arihant2math
Copy link
Collaborator

Usually we skip a test because of CI. I suggest removing that line and pushing it up, because it is likely no longer relevant due to performance gains for some reason or another. If it takes to long the CI will immediately indicate and it can be reverted.

@youknowone
Copy link
Member

Oh, the test must be my mistake. I checked it and confirmed the test doesn't take long. Thank you for checking.

I think this patch is good unless it is very different from CPython.

@youknowone youknowone merged commit 301c32d into RustPython:main Apr 30, 2025
10 of 11 checks passed
@kralka
Copy link
Author

kralka commented Apr 30, 2025

ack thank you for checking

@kralka kralka mentioned this pull request May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants