mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Test: Numpy Scalar Creation (#1530)
I found that the 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.
This commit is contained in:
@@ -68,6 +68,9 @@ template <typename T, typename T2> py::handle auxiliaries(T &&r, T2 &&r2) {
|
||||
return l.release();
|
||||
}
|
||||
|
||||
// note: declaration at local scope would create a dangling reference!
|
||||
static int data_i = 42;
|
||||
|
||||
TEST_SUBMODULE(numpy_array, sm) {
|
||||
try { py::module::import("numpy"); }
|
||||
catch (...) { return; }
|
||||
@@ -104,6 +107,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", []() { return py::array(py::dtype("i"), {}, {}, &data_i); });
|
||||
|
||||
// test_wrap
|
||||
sm.def("wrap", [](py::array a) {
|
||||
|
||||
Reference in New Issue
Block a user