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

Function NumpyToTFE_TensorHandle

tensorflow/python/eager/pywrap_tensor.cc:75–91  ·  view source on GitHub ↗

Convert a Python numpy.ndarray object to a TFE_TensorHandle. The two may share underlying storage so changes to one may reflect in the other.

Source from the content-addressed store, hash-verified

73// The two may share underlying storage so changes to one may reflect in the
74// other.
75TFE_TensorHandle* NumpyToTFE_TensorHandle(PyObject* obj) {
76 tensorflow::TensorHandle* handle;
77 tensorflow::Tensor t;
78 auto cppstatus = tensorflow::NdarrayToTensor(obj, &t);
79 if (cppstatus.ok()) {
80 cppstatus = tensorflow::TensorHandle::CreateLocalHandle(t, &handle);
81 }
82 if (!cppstatus.ok()) {
83 PyErr_SetString(PyExc_ValueError,
84 tensorflow::strings::StrCat(
85 "Failed to convert a NumPy array to a Tensor (",
86 cppstatus.error_message(), ").")
87 .c_str());
88 return nullptr;
89 }
90 return new TFE_TensorHandle(handle);
91}
92
93// Convert a TFE_TensorHandle to a Python numpy.ndarray object.
94// The two may share underlying storage so changes to one may reflect in the

Callers 1

Calls 4

NdarrayToTensorFunction · 0.85
c_strMethod · 0.80
StrCatFunction · 0.50
okMethod · 0.45

Tested by

no test coverage detected