Skip to content
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

Resolve errors in mapping ScalarVar to numpy ndarray #3423

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

jsiirola
Copy link
Member

Fixes #3418 .

Summary/Motivation:

This resolves how we map ScalarVar (and other scalar numeric expression types) into numpy ndarray objects. With this change, Pyomo Var objects behave in a manner consistent with other python scalars (like float).

Changes proposed in this PR:

  • implicit casting of a ScalarVar to numpy array should result in a 0d ndarray
  • add testing for (current) expected numpy behavior
  • update assertExpressionsEqual to allow for lists / ndarrays of expressions (and to compare list and 1d ndarray as being equal)

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:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link

codecov bot commented Nov 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.69%. Comparing base (180924a) to head (05bdaf7).
Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3423   +/-   ##
=======================================
  Coverage   88.69%   88.69%           
=======================================
  Files         882      882           
  Lines      100615   100623    +8     
=======================================
+ Hits        89237    89247   +10     
+ Misses      11378    11376    -2     
Flag Coverage Δ
linux 86.15% <100.00%> (+<0.01%) ⬆️
osx 76.17% <100.00%> (+<0.01%) ⬆️
other 86.65% <100.00%> (+<0.01%) ⬆️
win 84.54% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@blnicho blnicho merged commit 3f21a2d into Pyomo:main Nov 18, 2024
36 checks passed
@jsiirola jsiirola deleted the numpy-scalar branch November 19, 2024 15:50
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.

Fix/Clarify Interactions of IndexedComponent with numpy.array()
2 participants