| 160 | static int data_i = 42; |
| 161 | |
| 162 | TEST_SUBMODULE(numpy_array, sm) { |
| 163 | try { |
| 164 | py::module_::import("numpy"); |
| 165 | } catch (const py::error_already_set &) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | // test_dtypes |
| 170 | py::class_<DtypeCheck>(sm, "DtypeCheck") |
| 171 | .def_readonly("numpy", &DtypeCheck::numpy) |
| 172 | .def_readonly("pybind11", &DtypeCheck::pybind11) |
| 173 | .def("__repr__", [](const DtypeCheck &self) { |
| 174 | return py::str("<DtypeCheck numpy={} pybind11={}>").format(self.numpy, self.pybind11); |
| 175 | }); |
| 176 | sm.def("get_concrete_dtype_checks", &get_concrete_dtype_checks); |
| 177 | |
| 178 | py::class_<DtypeSizeCheck>(sm, "DtypeSizeCheck") |
| 179 | .def_readonly("name", &DtypeSizeCheck::name) |
| 180 | .def_readonly("size_cpp", &DtypeSizeCheck::size_cpp) |
| 181 | .def_readonly("size_numpy", &DtypeSizeCheck::size_numpy) |
| 182 | .def("__repr__", [](const DtypeSizeCheck &self) { |
| 183 | return py::str("<DtypeSizeCheck name='{}' size_cpp={} size_numpy={} dtype={}>") |
| 184 | .format(self.name, self.size_cpp, self.size_numpy, self.dtype); |
| 185 | }); |
| 186 | sm.def("get_platform_dtype_size_checks", &get_platform_dtype_size_checks); |
| 187 | |
| 188 | // test_array_attributes |
| 189 | sm.def("ndim", [](const arr &a) { return a.ndim(); }); |
| 190 | sm.def("shape", [](const arr &a) { return arr(a.ndim(), a.shape()); }); |
| 191 | sm.def("shape", [](const arr &a, py::ssize_t dim) { return a.shape(dim); }); |
| 192 | sm.def("strides", [](const arr &a) { return arr(a.ndim(), a.strides()); }); |
| 193 | sm.def("strides", [](const arr &a, py::ssize_t dim) { return a.strides(dim); }); |
| 194 | sm.def("writeable", [](const arr &a) { return a.writeable(); }); |
| 195 | sm.def("size", [](const arr &a) { return a.size(); }); |
| 196 | sm.def("itemsize", [](const arr &a) { return a.itemsize(); }); |
| 197 | sm.def("nbytes", [](const arr &a) { return a.nbytes(); }); |
| 198 | sm.def("owndata", [](const arr &a) { return a.owndata(); }); |
| 199 | |
| 200 | // test_index_offset |
| 201 | def_index_fn(index_at, const arr &); |
| 202 | def_index_fn(index_at_t, const arr_t &); |
| 203 | def_index_fn(offset_at, const arr &); |
| 204 | def_index_fn(offset_at_t, const arr_t &); |
| 205 | // test_data |
| 206 | def_index_fn(data, const arr &); |
| 207 | def_index_fn(data_t, const arr_t &); |
| 208 | // test_mutate_data, test_mutate_readonly |
| 209 | def_index_fn(mutate_data, arr &); |
| 210 | def_index_fn(mutate_data_t, arr_t &); |
| 211 | def_index_fn(at_t, const arr_t &); |
| 212 | def_index_fn(mutate_at_t, arr_t &); |
| 213 | |
| 214 | // test_make_c_f_array |
| 215 | sm.def("make_f_array", [] { return py::array_t<float>({2, 2}, {4, 8}); }); |
| 216 | sm.def("make_c_array", [] { return py::array_t<float>({2, 2}, {8, 4}); }); |
| 217 | |
| 218 | // test_empty_shaped_array |
| 219 | sm.def("make_empty_shaped_array", [] { return py::array(py::dtype("f"), {}, {}); }); |
nothing calls this directly
no test coverage detected