Stop py::array_t arguments from accepting arrays that do not match the C- or F-contiguity flags (#2484)

* Stop py::array_t arguments from accepting arrays that do not match the C- or F-contiguity flags

* Add trivially-contiguous arrays to the tests
This commit is contained in:
Yannick Jadoul
2020-09-15 14:50:51 +02:00
committed by GitHub
parent f12ec00d70
commit 9df13835c8
3 changed files with 86 additions and 1 deletions

View File

@@ -385,4 +385,42 @@ TEST_SUBMODULE(numpy_array, sm) {
sm.def("index_using_ellipsis", [](py::array a) {
return a[py::make_tuple(0, py::ellipsis(), 0)];
});
// test_argument_conversions
sm.def("accept_double",
[](py::array_t<double, 0>) {},
py::arg("a"));
sm.def("accept_double_forcecast",
[](py::array_t<double, py::array::forcecast>) {},
py::arg("a"));
sm.def("accept_double_c_style",
[](py::array_t<double, py::array::c_style>) {},
py::arg("a"));
sm.def("accept_double_c_style_forcecast",
[](py::array_t<double, py::array::forcecast | py::array::c_style>) {},
py::arg("a"));
sm.def("accept_double_f_style",
[](py::array_t<double, py::array::f_style>) {},
py::arg("a"));
sm.def("accept_double_f_style_forcecast",
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
py::arg("a"));
sm.def("accept_double_noconvert",
[](py::array_t<double, 0>) {},
py::arg("a").noconvert());
sm.def("accept_double_forcecast_noconvert",
[](py::array_t<double, py::array::forcecast>) {},
py::arg("a").noconvert());
sm.def("accept_double_c_style_noconvert",
[](py::array_t<double, py::array::c_style>) {},
py::arg("a").noconvert());
sm.def("accept_double_c_style_forcecast_noconvert",
[](py::array_t<double, py::array::forcecast | py::array::c_style>) {},
py::arg("a").noconvert());
sm.def("accept_double_f_style_noconvert",
[](py::array_t<double, py::array::f_style>) {},
py::arg("a").noconvert());
sm.def("accept_double_f_style_forcecast_noconvert",
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
py::arg("a").noconvert());
}