Skip to content

Commit

Permalink
Enable py::ellipsis tests on Python 2 and mention Ellipsis in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickJadoul committed Aug 3, 2020
1 parent 056f7e5 commit 0fd116d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/advanced/pycpp/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ Ellipsis
Python 3 provides a convenient ``...`` ellipsis notation that is often used to
slice multidimensional arrays. For instance, the following snippet extracts the
middle dimensions of a tensor with the first and last index set to zero.
In Python 2, the syntactic sugar ``...`` is not available, but the singleton
``Ellipsis`` (of type ``ellipsis``) can still be used directly.

.. code-block:: python
Expand Down
8 changes: 3 additions & 5 deletions tests/test_numpy_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ TEST_SUBMODULE(numpy_array, sm) {
return a;
});

#if PY_MAJOR_VERSION >= 3
sm.def("index_using_ellipsis", [](py::array a) {
return a[py::make_tuple(0, py::ellipsis(), 0)];
});
#endif
sm.def("index_using_ellipsis", [](py::array a) {
return a[py::make_tuple(0, py::ellipsis(), 0)];
});
}
1 change: 0 additions & 1 deletion tests/test_numpy_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ def test_array_create_and_resize(msg):
assert(np.all(a == 42.))


@pytest.unsupported_on_py2
def test_index_using_ellipsis():
a = m.index_using_ellipsis(np.zeros((5, 6, 7)))
assert a.shape == (6,)
Expand Down

0 comments on commit 0fd116d

Please sign in to comment.