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.
| 73 | // The two may share underlying storage so changes to one may reflect in the |
| 74 | // other. |
| 75 | TFE_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 |
no test coverage detected