-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix parsing and printing of numpy types for numpy 2.0 #26112
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
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
886b339
to
4890a14
Compare
@@ -88,8 +90,8 @@ def _convert_numpy_types(a, **sympify_args): | |||
prec = np.finfo(a).nmant + 1 |
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.
Are we sure this logic is correct?
>>> a = np.float32(232132.2)
>>> a
232132.2
>>> sympify(a)
232132.
>>> Float('232132.2', precision=24)
232132.
>>> Float('232132.2', precision=25)
232132.2
Not completely sure why this happens. Some discrepancy between how a mpmath and machine float are implemented.
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.
Or maybe this is an issue with sympy
>>> Float('232132.2', precision=24)._mpf_
(0, mpz(14856461), -6, 24)
>>> Float('232132.2', precision=25)._mpf_
(0, mpz(14856461), -6, 24)
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 don't think that numpy's nmant is consistent: numpy/numpy#22333
Or maybe this is an issue with sympy
>>> Float('232132.2', precision=24)._mpf_ (0, mpz(14856461), -6, 24) >>> Float('232132.2', precision=25)._mpf_ (0, mpz(14856461), -6, 24)
The _mpf_
is not expected to be affects by the precision argument.
Are we sure this logic is correct?
>>> a = np.float32(232132.2) >>> a 232132.2 >>> sympify(a) 232132. >>> Float('232132.2', precision=24) 232132. >>> Float('232132.2', precision=25) 232132.2
This is to do with printing:
In [8]: a = np.float32(232132.2)
In [9]: sa = sympify(a)
In [10]: sa
Out[10]: 232132.
In [11]: sa._prec
Out[11]: 24
In [12]: Float(sa, precision=25)
Out[12]: 232132.2
Not really related to this PR, but where is the logic that converts numpy arrays to ImmutableDenseNDimArray? It's confusing that it's not in the same place here. |
Lines 417 to 425 in e077db8
|
I don't see a simple way to disable the doctests in biomechanics.rst when matplotlib is not installed. |
I manually ran the test_optional_dependencies script locally with the git numpy. I got this failure, which seems legitimate
and didn't find any other errors. I don't know where the "numpy nightly" CI builds came from, but I wouldn't worry about it too much. NumPy is going to release a release candidate for 2.0 in a week or so, and once that happens it will presumably be easier to get compatible versions of scipy, matplotlib, and so on. |
The changes here look good to me. |
Thanks |
References to other Issues or PRs
#26094
Brief description of what is fixed or changed
Changed conversion from numpy types to Float and printing of numpy types like
np.PINF
in preparation for numpy 2.0.Other comments
Release Notes