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

Test: Numpy Scalar Creation #1530

Merged
merged 1 commit into from
Jun 11, 2019
Merged

Test: Numpy Scalar Creation #1530

merged 1 commit into from
Jun 11, 2019

Conversation

ax3l
Copy link
Collaborator

@ax3l ax3l commented Sep 17, 2018

I found that te numpy array tests already contained an empty-shaped array test, but none with data in it.

Following PEP 3118, scalars have an empty shape and ndim 0. This works already and is now also documented/covered by a test.

Side note for readers: as documented here, Numpy < 1.15 is bugged when handling scalars.

@@ -104,6 +104,8 @@ TEST_SUBMODULE(numpy_array, sm) {

// test_empty_shaped_array
sm.def("make_empty_shaped_array", [] { return py::array(py::dtype("f"), {}, {}); });
// test numpy scalars (empty shape, ndim==0)
sm.def("scalar_int", []() { int i = 42; return py::array(py::dtype("i"), {}, {}, &i); });
Copy link
Collaborator Author

@ax3l ax3l Sep 17, 2018

Choose a reason for hiding this comment

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

ups, local var, dangling ref

I found that te numpy array tests already contained an empty-shaped
array test, but none with data in it.

Following PEP 3118, scalars have an empty shape and ndim 0. This
works already and is now also documented/covered by a test.
@ax3l ax3l force-pushed the test-numpyScalars branch from 47d7e1b to 6fa8cb5 Compare September 17, 2018 12:33
@ax3l
Copy link
Collaborator Author

ax3l commented Oct 11, 2018

ping @jagerman @wjakob this PR documents usage of scalar numpy arrays

@wjakob
Copy link
Member

wjakob commented Jun 11, 2019

LGTM, thanks!

@wjakob wjakob merged commit 000aabb into pybind:master Jun 11, 2019
@ax3l ax3l deleted the test-numpyScalars branch June 11, 2019 12:14
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