Skip to content

added py::ellipsis() method for slicing of multidimensional NumPy arrays #1502

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

Merged
merged 2 commits into from
Aug 28, 2018

Conversation

wjakob
Copy link
Member

@wjakob wjakob commented Aug 27, 2018

This PR adds a new py::ellipsis() method which can be used in conjunction with NumPy's generalized slicing support. For instance, the following is now valid (where a is a NumPy array):

py::array b = a[py::make_tuple(0, py::ellipsis(), 0)];

@wjakob wjakob requested a review from jagerman August 27, 2018 22:26
@@ -408,3 +408,7 @@ def test_array_create_and_resize(msg):
a = m.create_and_resize(2)
assert(a.size == 4)
assert(np.all(a == 42.))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Flake8 error in CI:

./tests/test_numpy_array.py:412:1: E302 expected 2 blank lines, found 1
def test_index_using_ellipsis():

@@ -295,4 +295,8 @@ TEST_SUBMODULE(numpy_array, sm) {
std::fill(a.mutable_data(), a.mutable_data() + a.size(), 42.);
return a;
});

sm.def("index_using_ellipsis", [](py::array a) {
return a[py::make_tuple(0, py::ellipsis(), 0)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

must be excluded in python 2 tests

This PR adds a new py::ellipsis() method which can be used in
conjunction with NumPy's generalized slicing support. For instance,
the following is now valid (where "a" is a NumPy array):

py::array b = a[py::make_tuple(0, py::ellipsis(), 0)];
@wjakob
Copy link
Member Author

wjakob commented Aug 28, 2018

@ax3l : thanks!

@wjakob wjakob merged commit 885b5b9 into pybind:master Aug 28, 2018
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.

2 participants