| 58 | } |
| 59 | |
| 60 | Maybe<DataType> NumpyTypeToOFDataType(int np_type) { |
| 61 | switch (np_type) { |
| 62 | case NPY_BOOL: return DataType::kBool; |
| 63 | case NPY_FLOAT32: return DataType::kFloat; |
| 64 | case NPY_FLOAT64: return DataType::kDouble; |
| 65 | case NPY_INT8: return DataType::kInt8; |
| 66 | case NPY_INT16: return DataType::kInt16; |
| 67 | case NPY_INT32: return DataType::kInt32; |
| 68 | case NPY_INT64: |
| 69 | case NPY_LONGLONG: return DataType::kInt64; |
| 70 | case NPY_UINT8: return DataType::kUInt8; |
| 71 | case NPY_FLOAT16: return DataType::kFloat16; |
| 72 | case NPY_COMPLEX64: return DataType::kComplex64; |
| 73 | case NPY_COMPLEX128: return DataType::kComplex128; |
| 74 | default: |
| 75 | return Error::InvalidValueError() << "Numpy data type " << std::to_string(np_type) |
| 76 | << " is not valid to OneFlow data type."; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | Maybe<DataType> GetOFDataTypeFromNpArray(PyArrayObject* array) { |
| 81 | int np_array_type = PyArray_TYPE(array); |
no test coverage detected