Skip to content

fix: copy every item of a zero-stride buffer in bind_vector - #6236

Open
kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-vector-buffer-zero-stride
Open

kroplabeskidu wants to merge 1 commit into
pybind:masterfrom
kroplabeskidu:fix-vector-buffer-zero-stride

Conversation

@kroplabeskidu

Copy link
Copy Markdown

Description

Item 14 from #6159. The buffer constructor from py::bind_vector computes end = p + shape * step and loops until p == end. With a stride of 0, as in np.broadcast_to, end == p, so the result is an empty vector with no error:

m.VectorInt(np.broadcast_to(np.array(7, dtype=np.uintc), (3,)))  # was [], now [7, 7, 7]

The loop now counts items instead of comparing pointers. I also added a test for negative strides, which already worked and had no test.

Suggested changelog entry:

  • py::bind_vector's buffer constructor now copies every item from zero-stride buffers instead of returning an empty vector.

This branch has not been deployed

No deployments
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.

1 participant