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

Function TFE_Py_EncodeArgHelper

tensorflow/python/eager/pywrap_tfe_src.cc:3389–3445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3387}
3388
3389tensorflow::Status TFE_Py_EncodeArgHelper(PyObject* arg,
3390 bool include_tensor_ranks_only,
3391 EncodeResult* result) {
3392 if (tensorflow::swig::IsTensor(arg)) {
3393 absl::StrAppend(&result->str, kTensor);
3394 TF_RETURN_IF_ERROR(
3395 TFE_Py_EncodeTensor(arg, include_tensor_ranks_only, result));
3396 } else if (PyList_Check(arg)) {
3397 TF_RETURN_IF_ERROR(TFE_Py_EncodeSequence(
3398 arg, kList, kListEnd, include_tensor_ranks_only, result));
3399 } else if (PyTuple_Check(arg)) {
3400 TF_RETURN_IF_ERROR(TFE_Py_EncodeSequence(
3401 arg, kTuple, kTupleEnd, include_tensor_ranks_only, result));
3402 } else if (tensorflow::swig::IsMapping(arg)) {
3403 tensorflow::Safe_PyObjectPtr keys(tensorflow::swig::MappingKeys(arg));
3404 if (PyList_Sort(keys.get()) == -1) {
3405 return tensorflow::errors::Internal("Unable to sort keys");
3406 }
3407
3408 absl::StrAppend(&result->str, kDict);
3409 int len = PyList_Size(keys.get());
3410
3411 for (int i = 0; i < len; i++) {
3412 PyObject* key = PyList_GetItem(keys.get(), i);
3413 TF_RETURN_IF_ERROR(
3414 TFE_Py_EncodeArgHelper(key, include_tensor_ranks_only, result));
3415 tensorflow::Safe_PyObjectPtr value(PyObject_GetItem(arg, key));
3416 TF_RETURN_IF_ERROR(TFE_Py_EncodeArgHelper(
3417 value.get(), include_tensor_ranks_only, result));
3418 }
3419 } else if (tensorflow::swig::IsCompositeTensor(arg)) {
3420 absl::StrAppend(&result->str, kCompositeTensor);
3421
3422 // Add the typespec to the list of objects. (Do *not* use a weakref,
3423 // since the type spec is often a temporary object.)
3424 PyObject* type_spec(PyObject_GetAttrString(arg, "_type_spec"));
3425 if (type_spec == nullptr) {
3426 return tensorflow::errors::InvalidArgument(
3427 "Error while reading CompositeTensor._type_spec.");
3428 }
3429 result->objects.push_back(type_spec);
3430 } else {
3431 PyObject* object = PyWeakref_NewRef(arg, nullptr);
3432
3433 if (object == nullptr) {
3434 PyErr_Clear();
3435
3436 object = arg;
3437 Py_INCREF(object);
3438 }
3439
3440 absl::StrAppend(&result->str, kRaw);
3441 result->objects.push_back(object);
3442 }
3443
3444 return tensorflow::Status::OK();
3445}
3446

Callers 2

TFE_Py_EncodeSequenceFunction · 0.85
TFE_Py_EncodeArgFunction · 0.85

Calls 11

IsTensorFunction · 0.85
TFE_Py_EncodeTensorFunction · 0.85
TFE_Py_EncodeSequenceFunction · 0.85
IsMappingFunction · 0.85
MappingKeysFunction · 0.85
InternalFunction · 0.85
IsCompositeTensorFunction · 0.85
InvalidArgumentFunction · 0.85
StrAppendFunction · 0.50
getMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected