| 175 | } |
| 176 | |
| 177 | PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name) { |
| 178 | module_ numpy = module_::import("numpy"); |
| 179 | str version_string = numpy.attr("__version__"); |
| 180 | module_ numpy_lib = module_::import("numpy.lib"); |
| 181 | object numpy_version = numpy_lib.attr("NumpyVersion")(version_string); |
| 182 | int major_version = numpy_version.attr("major").cast<int>(); |
| 183 | |
| 184 | /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially |
| 185 | became a private module. */ |
| 186 | std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core"; |
| 187 | return module_::import((numpy_core_path + "." + submodule_name).c_str()); |
| 188 | } |
| 189 | |
| 190 | template <typename T> |
| 191 | struct same_size { |