Skip to content

Commit

Permalink
Use C API to implement Operation.name property
Browse files Browse the repository at this point in the history
This name property is used in many existing tests including those that
already run with C API enabled (math_ops_test, framework_ops_test,
session_test, session_partial_run_test, math_ops_test_gpu, etc).

PiperOrigin-RevId: 159645767
  • Loading branch information
tensorflower-gardener committed Jun 21, 2017
1 parent 26239c7 commit 980d3f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tensorflow/python/client/tf_session.i
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ tensorflow::ImportNumpy();
// Constants used by TensorHandle (get_session_handle).
%constant const char* TENSOR_HANDLE_KEY = tensorflow::SessionState::kTensorHandleResourceTypeName;

// Convert TF_OperationName output to unicode python string
%typemap(out) const char* TF_OperationName {
$result = PyUnicode_FromString($1);
}

////////////////////////////////////////////////////////////////////////////////
// BEGIN TYPEMAPS FOR tensorflow::TF_Run_wrapper()
////////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 7 additions & 1 deletion tensorflow/python/framework/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,13 @@ def _set_control_flow_context(self, context):
@property
def name(self):
"""The full name of this operation."""
return self._node_def.name
if _USE_C_API:
# TODO(iga): Remove this assert after converting to C API by default.
# Just being a bit paranoid here.
assert self._node_def.name == c_api.TF_OperationName(self._c_op)
return c_api.TF_OperationName(self._c_op)
else:
return self._node_def.name

@property
def _id(self):
Expand Down

0 comments on commit 980d3f2

Please sign in to comment.