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

Function MakeArgTuple

tensorflow/python/lib/core/py_func.cc:78–111  ·  view source on GitHub ↗

Givens the 'call', prepares the token and inputs as a python tuple that is appropriate for calling the trampoline.

Source from the content-addressed store, hash-verified

76// Givens the 'call', prepares the token and inputs as a python tuple
77// that is appropriate for calling the trampoline.
78Status MakeArgTuple(const PyCall* call, EagerContext* ctx, PyObject** tuple) {
79 int64 n = call->ins.size();
80 PyObject* lst = PyList_New(n);
81 CHECK(lst);
82 // TFE_TensorHandle assumes that CPU is identified by nullptr.
83 Device* device = IsCPUDevice(call->device) ? nullptr : call->device;
84 for (int64 i = 0; i < n; ++i) {
85 PyObject* arg = nullptr;
86 const Tensor& t = call->ins[i];
87 if (call->eager) {
88 TensorHandle* handle;
89 TF_RETURN_IF_ERROR(TensorHandle::CreateLocalHandle(
90 t, ctx->CanonicalDevice(device), ctx, &handle));
91 arg = EagerTensorFromHandle(new TFE_TensorHandle(handle));
92 if (arg == nullptr) {
93 Py_DECREF(lst);
94 return errors::Internal("Unable to procure EagerTensor from Tensor.");
95 }
96 } else {
97 Status s = TensorToNdarray(t, &arg);
98 if (!s.ok()) {
99 Py_DECREF(lst);
100 return s;
101 }
102 arg = PyArray_Return(reinterpret_cast<PyArrayObject*>(arg));
103 }
104 PyList_SetItem(lst, i, arg);
105 }
106 const char* device_name =
107 device == nullptr ? nullptr : device->attributes().name().c_str();
108 *tuple = Py_BuildValue("(ssN)", call->token.c_str(), device_name, lst);
109 CHECK(*tuple);
110 return Status::OK();
111}
112
113bool IsSingleNone(PyObject* obj) {
114 if (!PyArray_Check(obj)) {

Callers 1

DoCallPyFuncFunction · 0.85

Calls 9

IsCPUDeviceFunction · 0.85
EagerTensorFromHandleFunction · 0.85
InternalFunction · 0.85
TensorToNdarrayFunction · 0.85
CanonicalDeviceMethod · 0.80
c_strMethod · 0.80
nameMethod · 0.65
sizeMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected