| 691 | } |
| 692 | |
| 693 | mgb::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 | |
| 710 | PyObject* to_mgb_supported_dtype(PyObject* dtype) { |
| 711 | PYTHON_GIL; |
no test coverage detected