-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
Fix test failures due to global mpmath state #38776
Merged
Merged
Conversation
This file contains 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
We have an mpmath test in this file that sets the global precision (decimal places) and "pretty" variable for all of mpmath. Instead it is safer to use a context manager for the precision, and to call print(foo) to obtain the string representation of foo. This fixes the following two test failures: Failed example: gegenbauer_mp(-7,0.5,0.3) Expected: 0.1291811875 Got: mpf('0.1291811874999999999999999952') and Failed example: gegenbauer_mp(2+3j, -0.75, -1000j) Expected: (-5038991.358609026523401901 + 9414549.285447104177860806j) Got: mpc(real='-5038991.358609026523401901035', imag='9414549.285447104177860806274')
One test in this file sets mp.pretty=True but is failing for me, most likely due to the shared state inherent to mp.pretty. Since this test is inside a TESTS block and not visible to end users, the simplest way to fix it is to delete the mp.pretty=True and to look for the ugly output.
There's a test in this file that is trying to use the global property mp.pretty=True but is failing on my machine. Since the test is inside a TESTS block and not visible to end users, the simplest way to fix it is to expect the ugly output from mpmath; although in one instance we do call str() on an mpmath real number to obtain '2.3' instead of some 2.999... thing that would require a tolerance.
There are two tests in this file that are attempting to test the repr() of an mpmath number with mp.pretty=True set globally. The shared state is causing test failures, but we can't simply leave it off, because that's the point of the test. Instead we can clone() the "mp" object to obtain a new one (whose state is not so global) and then work with that instead.
Documentation preview for this PR (built with commit 441ee05; changes) is ready! 🎉 |
dimpase
approved these changes
Oct 7, 2024
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
dimpase
added
c: packages: standard
s: positive review
and removed
s: needs review
labels
Oct 7, 2024
Thanks, I may finally be able to focus on whatever is happening with GAP soon. |
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 9, 2024
mpmath has a global `mp.pretty` variable that affects how its numbers are printed. On my machine, it's not reliable. For example: ``` Failed example: repr(mp.mpc(2,3)) Expected: '(2.0 + 3.0j)' Got: "mpc(real='2.0', imag='3.0')" ``` I've only fixed the tests that are failing for me, since mpmath-1.4 is on the TODO list. A few different strategies are used: * `print()` will use the pretty format if all we're doing is displaying an answer. * `with workdps` can be used to change the precision only locally. * In TESTS blocks, the ugly output is acceptable. * When actually testing `mp.pretty`, we can first clone the `mp` object with `mp2 = mp.clone()`, and then work on the new one. URL: sagemath#38776 Reported by: Michael Orlitzky Reviewer(s): Dima Pasechnik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
mpmath has a global
mp.pretty
variable that affects how its numbers are printed. On my machine, it's not reliable. For example:I've only fixed the tests that are failing for me, since mpmath-1.4 is on the TODO list. A few different strategies are used:
print()
will use the pretty format if all we're doing is displaying an answer.with workdps
can be used to change the precision only locally.mp.pretty
, we can first clone themp
object withmp2 = mp.clone()
, and then work on the new one.