MCPcopy Create free account
hub / github.com/apple/coremltools / import_numpy_core_submodule

Function import_numpy_core_submodule

deps/pybind11/include/pybind11/numpy.h:175–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175PYBIND11_NOINLINE module_ import_numpy_core_submodule(const char *submodule_name) {
176 module_ numpy = module_::import("numpy");
177 str version_string = numpy.attr("__version__");
178
179 module_ numpy_lib = module_::import("numpy.lib");
180 object numpy_version = numpy_lib.attr("NumpyVersion")(version_string);
181 int major_version = numpy_version.attr("major").cast<int>();
182
183#ifdef PYBIND11_NUMPY_1_ONLY
184 if (major_version >= 2) {
185 throw std::runtime_error(
186 "This extension was built with PYBIND11_NUMPY_1_ONLY defined, "
187 "but NumPy 2 is used in this process. For NumPy2 compatibility, "
188 "this extension needs to be rebuilt without the PYBIND11_NUMPY_1_ONLY define.");
189 }
190#endif
191 /* `numpy.core` was renamed to `numpy._core` in NumPy 2.0 as it officially
192 became a private module. */
193 std::string numpy_core_path = major_version >= 2 ? "numpy._core" : "numpy.core";
194 return module_::import((numpy_core_path + "." + submodule_name).c_str());
195}
196
197template <typename T>
198struct same_size {

Callers 2

lookupMethod · 0.85
dtypeClass · 0.85

Calls 2

importFunction · 0.85
attrMethod · 0.80

Tested by

no test coverage detected