-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Rounding rational numbers: default behaviour is not up-to-date with Python #35473
Closed
1 task done
Labels
Comments
5 tasks
5 tasks
2 tasks
vbraun
pushed a commit
to vbraun/sage
that referenced
this issue
Feb 18, 2024
…uadratic` Fix sagemath#37296. Add `warnings.filterwarnings` to ignore `DeprecationWarning` in the failing doctest, since it is an unrelated issue and does not affect correctness of the test. To be more specific, the warning only appears when the rounding error will change, i.e. on $n + \frac{1}{2}$ (I believe). Here are some runs: ```python sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-12-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-14-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) ``` URL: sagemath#37306 Reported by: grhkm21 Reviewer(s): Sebastian A. Spindler
vbraun
pushed a commit
to vbraun/sage
that referenced
this issue
Feb 19, 2024
…uadratic` Fix sagemath#37296. Add `warnings.filterwarnings` to ignore `DeprecationWarning` in the failing doctest, since it is an unrelated issue and does not affect correctness of the test. To be more specific, the warning only appears when the rounding error will change, i.e. on $n + \frac{1}{2}$ (I believe). Here are some runs: ```python sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-12-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-14-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) ``` URL: sagemath#37306 Reported by: grhkm21 Reviewer(s): Sebastian A. Spindler
vbraun
pushed a commit
to vbraun/sage
that referenced
this issue
Feb 22, 2024
…uadratic` Fix sagemath#37296. Add `warnings.filterwarnings` to ignore `DeprecationWarning` in the failing doctest, since it is an unrelated issue and does not affect correctness of the test. To be more specific, the warning only appears when the rounding error will change, i.e. on $n + \frac{1}{2}$ (I believe). Here are some runs: ```python sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-12-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) <ipython-input-14-179149e36f01>:1: DeprecationWarning: the default rounding for rationals, currently `away`, will be changed to `even`. See sagemath#35473 for details. a = QQ.random_element(Integer(3), Integer(3)); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) sage: a = QQ.random_element(3, 3); _ = round(a) ``` URL: sagemath#37306 Reported by: grhkm21 Reviewer(s): Sebastian A. Spindler
ludopulles
added a commit
to ludopulles/lattice-estimator
that referenced
this issue
Sep 19, 2024
Related: sagemath/sage#35473
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Problem Description
The documentation for RationalField's
round
method saysYet the builtin Python
round
currently (since Python3 I think) rounds to nearest, with halfway case rounding to even. The first example in the documentation is(9/2).round()
which yields5
, and consequently in Sageround(9/2)
yields5
as well; whereas in Python the sameround(9/2)
yields4
.Proposed Solution
A simple solution may be to change the default to
even
, which is the current Python convention and is already implemented in this methodround
for rational field.Alternatives Considered
Or, seemingly less ideal: one could keep the current behaviour and modify the documentation to highlight that this diverges from Python's builtin behaviour.
Additional Information
No response
The text was updated successfully, but these errors were encountered: