| 81 | } |
| 82 | |
| 83 | Result<uint16_t> PyFloat_AsHalf(PyObject* obj) { |
| 84 | if (PyFloat_Check(obj)) { |
| 85 | arrow::util::Float16 half_val = |
| 86 | arrow::util::Float16::FromDouble(PyFloat_AsDouble(obj)); |
| 87 | return half_val.bits(); |
| 88 | } else if (has_numpy() && PyArray_IsScalar(obj, Half)) { |
| 89 | return PyArrayScalar_VAL(obj, Half); |
| 90 | } else { |
| 91 | return Status::TypeError("conversion to float16 expects a `float` or ", |
| 92 | "`np.float16` object, got ", Py_TYPE(obj)->tp_name); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | namespace internal { |
| 97 |
no test coverage detected