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

Function TFE_Py_TensorShapeOnDevice

tensorflow/python/eager/pywrap_tensor.cc:1127–1159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1125}
1126
1127PyObject* 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}

Callers

nothing calls this directly

Calls 10

TF_NewStatusFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
c_strMethod · 0.80
StrCatFunction · 0.50
make_safeFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected