-
Notifications
You must be signed in to change notification settings - Fork 526
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
Update Pyomo for NumPy 2 #3292
Update Pyomo for NumPy 2 #3292
Conversation
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.
One (mostly stylistic) question
FYI for anyone watching this PR: it needs some work on the NL writer's processing of NumPy representations. @jsiirola is going to look at it soon. |
In Python 3.x, str() and repr() are the same for float, and beginning in numpy 2.0 `repr(float64(n))` produces `numpy.float64(n)`, whereas str() produces `n`
numpy_bool_names.append('bool_') | ||
if numpy.__version__[0] == '2': | ||
numpy_bool_names.append('bool') | ||
else: | ||
numpy_bool_names.append('bool_') |
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.
Why do you check version here, but everywhere else you use hasattr
?
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.
Because John added that one...
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.
Oh but also, I can answer - this is a forwards-compatible one. bool
and bool_
are both valid in NumPy 2, whereas bool
does not exist in older NumPys. The other ones are forcing backwards compatibility.
# float96 and float128 may or may not be defined in this particular | ||
# numpy build (it depends on platform and version). | ||
# Register them only if they are present | ||
if hasattr(np, 'float_'): | ||
# Prepend to preserve previous functionality |
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.
Note that float_
/complex_
were simple aliases to float64
/complex128
, so it is not necessary to handle them for numpy 1.x, just dropping them is fully backwards compatible.
Fixes #3290
Summary/Motivation:
Add in the updates for NumPy 2.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: