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

MAINT: optimize.linprog: ensure integrality can be an array #16684

Merged
merged 1 commit into from Jul 24, 2022

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Jul 23, 2022

Reference issue

Closes gh-16681

What does this implement/fix?

scipy.optimize.lingprog's new integrality parameter did not accept np.ndarray because a branching statement relied on its "truthiness" (i.e. if integrality). This PR fixes that and adds to an existing test to guard against regression.

@mdhaber mdhaber added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize backport-candidate This fix should be ported by a maintainer to previous SciPy versions. labels Jul 23, 2022
@mdhaber mdhaber added this to the 1.9.0 milestone Jul 23, 2022
@mdhaber mdhaber requested a review from andyfaff as a code owner July 23, 2022 16:18
Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Matt.

@tupui tupui merged commit d128efa into scipy:main Jul 24, 2022
@@ -581,7 +581,7 @@ def linprog(c, A_ub=None, b_ub=None, A_eq=None, b_eq=None,
warning_message = "x0 is used only when method is 'revised simplex'. "
warn(warning_message, OptimizeWarning)

if integrality and not meth == "highs":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't equivalent, right?

>>> a = [0, 0]
>>> if a:
...   print("here")
...
here
>>> if np.any(a):
...   print("here 2")
...
>>>

Copy link
Contributor Author

@mdhaber mdhaber Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it's appropriate in context. It's just a little less noisy. Previously, it would warn if the user passed [0, 0], but explicitly stating that there are no inequality constraints like this doesn't affect the problem, so there's no real need to warn.

mdhaber added a commit to mdhaber/scipy that referenced this pull request Jul 28, 2022
tylerjereddy pushed a commit to tylerjereddy/scipy that referenced this pull request Jul 28, 2022
@tylerjereddy tylerjereddy removed the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: linprog integrality only accepts list, not array
4 participants