MCPcopy Create free account
hub / github.com/pybind/pybind11 / import_numpy_core_submodule

Function import_numpy_core_submodule

include/pybind11/numpy.h:177–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177PYBIND11_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
190template <typename T>
191struct same_size {

Callers 2

lookupMethod · 0.85
dtypeClass · 0.85

Calls 2

importFunction · 0.85
attrMethod · 0.80

Tested by

no test coverage detected