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

Support for np v1.x floats as LHS values #937

Open
Opt-Mucca opened this issue Dec 11, 2024 · 0 comments
Open

Support for np v1.x floats as LHS values #937

Opt-Mucca opened this issue Dec 11, 2024 · 0 comments

Comments

@Opt-Mucca
Copy link
Collaborator

Opt-Mucca commented Dec 11, 2024

Describe the bug
For older (still standard) versions of numpy, we fail to create the below constraints. This issue no longer exists for numpy 2.x, but I predict it will be a few years until 1.x becomes non widely used.
The general reason for the error after looking into for a few hours:
At some point when we create the ExprCons object the __nonzero__ function will be called (probably should change this to __bool__ at some point). It is called after the ExprCons object has been initialised and after the richcmp function has finished. My best guess is that it is being called because np is somehow forcing a comparison between the two objects at some point. This problem is avoided when np is on the RHS and we are then comparing our ExprCons object to the np object (therefore using our comparison function, which doesn't exist I guess?). Somehow when it is on the LHS np is returning some actual value instead of something that hides the comparison.

To Reproduce
a = np.array([1, 2, 3], dtype=np.float32)
scip.addCons(a[1] <= 2 * x + 3 * y)

Expected behavior
A constraint should be added

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

No branches or pull requests

1 participant