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

Function EagerTensor_getbuffer

tensorflow/python/eager/pywrap_tensor.cc:771–793  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

769};
770
771static int EagerTensor_getbuffer(EagerTensor* self, Py_buffer* view,
772 int flags) {
773 if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
774 PyErr_SetString(PyExc_BufferError, "EagerTensor is not writable.");
775 return -1;
776 }
777
778 // TensorHandleToNumpy is zero-copy for everything but DT_RESOURCE and
779 // DT_STRING so the following is only slightly slower than a NumPy-free
780 // implementation.
781 auto py_array = tensorflow::make_safe(
782 TFE_TensorHandleToNumpy(self->handle, self->status));
783 if (MaybeRaiseExceptionFromTFStatus(self->status, PyExc_BufferError)) {
784 // Cleanup self->status before returning.
785 TF_SetStatus(self->status, TF_OK, "");
786 return -1;
787 }
788 if (PyObject_GetBuffer(py_array.get(), view, flags) < 0) {
789 return -1;
790 }
791 view->readonly = 1;
792 return 0;
793}
794
795static PyBufferProcs EagerTensor_as_buffer = {
796#if PY_MAJOR_VERSION < 3

Callers

nothing calls this directly

Calls 5

TFE_TensorHandleToNumpyFunction · 0.85
TF_SetStatusFunction · 0.85
make_safeFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected