MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / NumpyTypeToOFDataType

Function NumpyTypeToOFDataType

oneflow/extension/python/numpy.cpp:60–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60Maybe<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
80Maybe<DataType> GetOFDataTypeFromNpArray(PyArrayObject* array) {
81 int np_array_type = PyArray_TYPE(array);

Callers 2

InferScalarTypeFunction · 0.85
GetOFDataTypeFromNpArrayFunction · 0.85

Calls 1

to_stringFunction · 0.85

Tested by

no test coverage detected