| 210 | static int data_i = 42; |
| 211 | |
| 212 | TEST_SUBMODULE(numpy_array, sm) { |
| 213 | try { |
| 214 | py::module_::import("numpy"); |
| 215 | } catch (const py::error_already_set &) { |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | // test_dtypes |
| 220 | py::class_<DtypeCheck>(sm, "DtypeCheck") |
| 221 | .def_readonly("numpy", &DtypeCheck::numpy) |
| 222 | .def_readonly("pybind11", &DtypeCheck::pybind11) |
| 223 | .def("__repr__", [](const DtypeCheck &self) { |
| 224 | return py::str("<DtypeCheck numpy={} pybind11={}>").format(self.numpy, self.pybind11); |
| 225 | }); |
| 226 | sm.def("get_concrete_dtype_checks", &get_concrete_dtype_checks); |
| 227 | |
| 228 | py::class_<DtypeSizeCheck>(sm, "DtypeSizeCheck") |
| 229 | .def_readonly("name", &DtypeSizeCheck::name) |
| 230 | .def_readonly("size_cpp", &DtypeSizeCheck::size_cpp) |
| 231 | .def_readonly("size_numpy", &DtypeSizeCheck::size_numpy) |
| 232 | .def("__repr__", [](const DtypeSizeCheck &self) { |
| 233 | return py::str("<DtypeSizeCheck name='{}' size_cpp={} size_numpy={} dtype={}>") |
| 234 | .format(self.name, self.size_cpp, self.size_numpy, self.dtype); |
| 235 | }); |
| 236 | sm.def("get_platform_dtype_size_checks", &get_platform_dtype_size_checks); |
| 237 | |
| 238 | // test_array_attributes |
| 239 | sm.def("ndim", [](const arr &a) { return a.ndim(); }); |
| 240 | sm.def("shape", [](const arr &a) { return arr(a.ndim(), a.shape()); }); |
| 241 | sm.def("shape", [](const arr &a, py::ssize_t dim) { return a.shape(dim); }); |
| 242 | sm.def("strides", [](const arr &a) { return arr(a.ndim(), a.strides()); }); |
| 243 | sm.def("strides", [](const arr &a, py::ssize_t dim) { return a.strides(dim); }); |
| 244 | sm.def("writeable", [](const arr &a) { return a.writeable(); }); |
| 245 | sm.def("size", [](const arr &a) { return a.size(); }); |
| 246 | sm.def("itemsize", [](const arr &a) { return a.itemsize(); }); |
| 247 | sm.def("nbytes", [](const arr &a) { return a.nbytes(); }); |
| 248 | sm.def("owndata", [](const arr &a) { return a.owndata(); }); |
| 249 | |
| 250 | #ifdef PYBIND11_HAS_SPAN |
| 251 | // test_shape_strides_span |
| 252 | sm.def("shape_span", [](const arr &a) { |
| 253 | auto span = a.shape_span(); |
| 254 | return std::vector<py::ssize_t>(span.begin(), span.end()); |
| 255 | }); |
| 256 | sm.def("strides_span", [](const arr &a) { |
| 257 | auto span = a.strides_span(); |
| 258 | return std::vector<py::ssize_t>(span.begin(), span.end()); |
| 259 | }); |
| 260 | // Test that spans can be used to construct new arrays |
| 261 | sm.def("array_from_spans", [](const arr &a) { |
| 262 | return py::array(a.dtype(), a.shape_span(), a.strides_span(), a.data(), a); |
| 263 | }); |
| 264 | #endif |
| 265 | |
| 266 | // test_index_offset |
| 267 | def_index_fn(index_at, const arr &); |
| 268 | def_index_fn(index_at_t, const arr_t &); |
| 269 | def_index_fn(offset_at, const arr &); |
nothing calls this directly
no test coverage detected