Use global empty tuple/dict.
Small modifications to a change submitted earlier. PiperOrigin-RevId: 308434286 Change-Id: Ifef1e854e681d4b50025496451bae5a8cfe8fd0d
This commit is contained in:
parent
d17488bd97
commit
ef72ad0c7a
@ -44,6 +44,19 @@ namespace {
|
||||
// events on eager tensors. This is set by TFE_Py_InitEagerTensor, if at all.
|
||||
PyObject* eager_tensor_profiler = nullptr;
|
||||
|
||||
// Read-only dict. Please don't use this in any setting where the dict might
|
||||
// actually get mutated. This is only used to pass empty kwargs when creating a
|
||||
// new EagerTensor.
|
||||
PyObject* EmptyDict() {
|
||||
static PyObject* empty_dict = PyDict_New();
|
||||
return empty_dict;
|
||||
}
|
||||
|
||||
PyObject* EmptyTuple() {
|
||||
static PyObject* empty_tuple = PyTuple_New(0);
|
||||
return empty_tuple;
|
||||
}
|
||||
|
||||
TFE_Context* GetContextHandle(PyObject* py_context) {
|
||||
tensorflow::Safe_PyObjectPtr py_context_handle(
|
||||
PyObject_GetAttrString(py_context, "_handle"));
|
||||
@ -800,19 +813,8 @@ PyObject* EagerTensorFromHandle(TFE_TensorHandle* handle) {
|
||||
if (handle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
PyObject* empty_args = PyTuple_New(0);
|
||||
if (empty_args == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
PyObject* empty_kwargs = PyDict_New();
|
||||
if (empty_kwargs == nullptr) {
|
||||
Py_DECREF(empty_args);
|
||||
return nullptr;
|
||||
}
|
||||
EagerTensor* t = reinterpret_cast<EagerTensor*>(
|
||||
EagerTensorType->tp_new(EagerTensorType, empty_args, empty_kwargs));
|
||||
Py_DECREF(empty_kwargs);
|
||||
Py_DECREF(empty_args);
|
||||
EagerTensorType->tp_new(EagerTensorType, EmptyTuple(), EmptyDict()));
|
||||
if (t != nullptr) {
|
||||
t->id = get_uid();
|
||||
Py_INCREF(Py_None);
|
||||
|
Loading…
Reference in New Issue
Block a user