Function `_numpy`. Convert an EagerTensor to a Python numpy.ndarray object. The two may share underlying storage so changes to one may reflect in the other. Note that if `self` is not on CPU, we raise an Exception.
| 686 | // other. |
| 687 | // Note that if `self` is not on CPU, we raise an Exception. |
| 688 | static PyObject* EagerTensor_numpy(EagerTensor* self) { |
| 689 | auto* py_array = TFE_TensorHandleToNumpy(self->handle, self->status); |
| 690 | if (MaybeRaiseExceptionFromTFStatus(self->status, PyExc_ValueError)) { |
| 691 | Py_XDECREF(py_array); |
| 692 | // Cleanup self->status before returning. |
| 693 | TF_SetStatus(self->status, TF_OK, ""); |
| 694 | return nullptr; |
| 695 | } else { |
| 696 | return PyArray_Return(reinterpret_cast<PyArrayObject*>(py_array)); |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | // Getter `device`. |
| 701 | static PyObject* EagerTensor_device(EagerTensor* self) { |
nothing calls this directly
no test coverage detected