| 43 | PyObject* eager_tensor_profiler = nullptr; |
| 44 | |
| 45 | TFE_Context* GetContextHandle(PyObject* py_context) { |
| 46 | tensorflow::Safe_PyObjectPtr py_context_handle( |
| 47 | PyObject_GetAttrString(py_context, "_handle")); |
| 48 | if (py_context_handle == nullptr) { |
| 49 | // Current Python code makes sure this never happens. If it does, or |
| 50 | // becomes hard to maintain, we can call the ensure_initialized() method |
| 51 | // here. |
| 52 | PyErr_SetString( |
| 53 | PyExc_TypeError, |
| 54 | "Expected `context` argument in EagerTensor constructor to have a " |
| 55 | "`_handle` attribute but it did not. Was eager Context initialized?"); |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
| 59 | auto* ctx = reinterpret_cast<TFE_Context*>( |
| 60 | PyCapsule_GetPointer(py_context_handle.get(), nullptr)); |
| 61 | if (ctx == nullptr) { |
| 62 | PyErr_SetString(PyExc_TypeError, |
| 63 | tensorflow::strings::StrCat( |
| 64 | "Expected context._handle to contain a PyCapsule " |
| 65 | "encoded pointer to TFE_Context. Got ", |
| 66 | Py_TYPE(py_context_handle.get())->tp_name) |
| 67 | .c_str()); |
| 68 | } |
| 69 | return ctx; |
| 70 | } |
| 71 | |
| 72 | // Convert a Python numpy.ndarray object to a TFE_TensorHandle. |
| 73 | // The two may share underlying storage so changes to one may reflect in the |
no test coverage detected