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

highspy (direct calls via pybind11) incorrectly handles sliced numpy arrays #1903

Closed
mathgeekcoder opened this issue Aug 30, 2024 · 1 comment
Assignees

Comments

@mathgeekcoder
Copy link
Contributor

Adding issue for visibility, although I've already fixed the code in #1891.

Consider the following:

h = highspy.Highs()

zero, ones = np.zeros(10), np.ones(10)
h.addCols(10, zero, zero, ones, 0, [], [], [])

x = np.arange(10, dtype=np.int32) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
tmp = x[1::2]                     # [1, 3, 5, 7, 9]

h.addRow(1, 1, len(tmp), tmp, ones)

We should expect that [1, 3, 5, 7, 9] is added as a row, but currently [1, 2, 3, 4, 5] is added instead.

The issue is in highs_bindings.cpp where we use py::array_t<T>. I've changed this to py::array_t<T, py::array::c_style | py::array::forcecast> instead. This will ensure that the underlying raw data is contiguous and of correct type.

mathgeekcoder added a commit to mathgeekcoder/HiGHS that referenced this issue Sep 16, 2024
Major highspy update:
* changed `highs_linear_expression` to be immutable by default
* improved callback support
* improved test coverage (99%)
* performance and usability enhancements
* Support `__iadd__`, `__imul__`, etc.
* Updated chain comparison support in immutable setting
* `h.val()` can take `highs_linear_expression`
* `expr == [lb,ub]` -> `lb <= expr <= ub` syntax
* `qsum`
* added pretty print `__repr__` and `__str__`
* added KeyboardInterrupt support
* added user interrupt
* fixed slicing issues with numpy and highs
* added `resetGlobalScheduler`
* released GIL for `Presolve`
* fixed issues with deadlock on Windows
* fixed MIP solution callback issue
* support `getExpr` that creates a `highs_linear_expression` from existing row

Should address multiple issues: ERGO-Code#1865, ERGO-Code#1882, ERGO-Code#1888, ERGO-Code#1892, ERGO-Code#1903, ERGO-Code#1904, and perhaps ERGO-Code#1905
@jajhall
Copy link
Member

jajhall commented Sep 26, 2024

Closed by #1942

@jajhall jajhall closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants