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 buffer protocol in Solver.add_clauses #722

Merged
merged 1 commit into from
Jun 24, 2023
Merged

support buffer protocol in Solver.add_clauses #722

merged 1 commit into from
Jun 24, 2023

Conversation

fanosta
Copy link
Contributor

@fanosta fanosta commented Jun 23, 2023

This pull request allows Solver.add_clauses to accept any contiguous buffer according to the Python buffer protocol instead of just array.array. This possibility was already mentioned in #519.

The main advantage of the buffer protocol is that it can be implemented by third party modules as well. Thus, add_clauses will also work with numpy arrays for example. Another advantage is that the C side of the API is much simpler, and thus I was able to remove a bunch of code.

One limitation that remains in the current state of this pull request is that only contiguous buffers, i.e., buffers where the element are contiguous in memory, are supported. Non-contiguous buffers can be created in numpy, for example, if someone indexes only a column of a multidimensional array. If that use-case is desired it would not require too many changes to get it running. (Right now, PyObject_GetBuffer will automatically raise a ValueError when used on a non-contiguous buffer.)

Regarding unit-tests, I did not add any new ones but the existing ones for array.array cover the changed code and they all passed for me.

@msoos
Copy link
Owner

msoos commented Jun 24, 2023

Nice, thanks so much! I'll let the pipelines pass then I'll merge. Then I'll release a new PIP release :)

Thanks again,

Mate

@msoos msoos merged commit 02fc5e8 into msoos:master Jun 24, 2023
5 checks passed
@msoos
Copy link
Owner

msoos commented Jun 24, 2023

Thanks, merged!

@fanosta fanosta deleted the buffer-protocol branch June 24, 2023 15:04
@fanosta
Copy link
Contributor Author

fanosta commented Jun 24, 2023

thank you very much :)

@msoos
Copy link
Owner

msoos commented Jun 25, 2023

:) I released a new version. The PyPi build & release should be automatic once the pipeline succeeds. Let me know if it goes wrong or something. Otherwise, it should be fine!

Thanks again,

Mate

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.

None yet

2 participants