MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / dtype_np2mgb

Function dtype_np2mgb

imperative/python/src/helper.cpp:693–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

691}
692
693mgb::DType dtype_np2mgb(PyObject* obj) {
694 mgb_assert(obj && obj != Py_None, "can not convert null PyObject to numpy dtype");
695 // see
696 // http://stackoverflow.com/questions/8477122/numpy-c-api-convert-type-object-to-type-number
697 PYTHON_GIL;
698
699 PyArray_Descr* dtype;
700 if (!PyArray_DescrConverter(obj, &dtype)) {
701 throw ConversionError(ssprintf(
702 "can not convert to np.dtype from %s", repr_pyobj(obj).c_str()));
703 }
704
705 mgb::DType result = dtype_np2mgb_descr(dtype);
706 Py_DECREF(dtype);
707 return result;
708}
709
710PyObject* to_mgb_supported_dtype(PyObject* dtype) {
711 PYTHON_GIL;

Callers 3

_get_dtype_numFunction · 0.85
_get_serialized_dtypeFunction · 0.85
loadMethod · 0.85

Calls 3

ConversionErrorClass · 0.85
repr_pyobjFunction · 0.85
dtype_np2mgb_descrFunction · 0.85

Tested by

no test coverage detected