MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / EagerTensor_numpy

Function EagerTensor_numpy

tensorflow/python/eager/pywrap_tensor.cc:688–698  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

686// other.
687// Note that if `self` is not on CPU, we raise an Exception.
688static 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`.
701static PyObject* EagerTensor_device(EagerTensor* self) {

Callers

nothing calls this directly

Calls 3

TFE_TensorHandleToNumpyFunction · 0.85
TF_SetStatusFunction · 0.85

Tested by

no test coverage detected