| 1125 | } |
| 1126 | |
| 1127 | PyObject* TFE_Py_TensorShapeOnDevice(PyObject* tensor) { |
| 1128 | if (!EagerTensor_CheckExact(tensor)) { |
| 1129 | PyErr_SetString( |
| 1130 | PyExc_TypeError, |
| 1131 | tensorflow::strings::StrCat("Expected an EagerTensors but got type \"", |
| 1132 | Py_TYPE(tensor)->tp_name, "\"") |
| 1133 | .c_str()); |
| 1134 | return nullptr; |
| 1135 | } |
| 1136 | TFE_TensorHandle* handle = EagerTensor_Handle(tensor); |
| 1137 | |
| 1138 | auto status = tensorflow::make_safe(TF_NewStatus()); |
| 1139 | TFE_TensorDebugInfo* debug_info = |
| 1140 | TFE_TensorHandleTensorDebugInfo(handle, status.get()); |
| 1141 | if (TF_GetCode(status.get()) != TF_OK) { |
| 1142 | PyErr_SetString( |
| 1143 | PyExc_RuntimeError, |
| 1144 | tensorflow::strings::StrCat("Error retrieving tensor's device shape: ", |
| 1145 | TF_Message(status.get())) |
| 1146 | .c_str()); |
| 1147 | return nullptr; |
| 1148 | } |
| 1149 | |
| 1150 | int rank = TFE_TensorDebugInfoOnDeviceNumDims(debug_info); |
| 1151 | PyObject* shape = PyTuple_New(rank); |
| 1152 | for (int i = 0; i < rank; ++i) { |
| 1153 | tensorflow::int64 dim_size = TFE_TensorDebugInfoOnDeviceDim(debug_info, i); |
| 1154 | PyTuple_SET_ITEM(shape, i, PyLong_FromLongLong(dim_size)); |
| 1155 | } |
| 1156 | TFE_DeleteTensorDebugInfo(debug_info); |
| 1157 | |
| 1158 | return shape; |
| 1159 | } |
nothing calls this directly
no test coverage detected