diff options
author | Skye Wanderman-Milne <skyewm@google.com> | 2017-10-18 11:58:01 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-10-18 12:04:54 -0700 |
commit | f5d3bf42b892ecfbde2ce9eb45f00b76473c824a (patch) | |
tree | fe8f8a9965f40ab5a463932b2073df32be21a1af /tensorflow/c/c_api_function_test.cc | |
parent | 6a725f6d0974dc71fe4ac311fc8dd16db4257452 (diff) |
Add TF_GraphGetOpDef() to C API and use in Operation.op_def()
Note that this creates a small change in behavior with the C API
enabled, since previously not all Python Operations had an OpDef
(op_def() returns None). With the C API enabled, op_def() always
returns an OpDef.
PiperOrigin-RevId: 172634411
Diffstat (limited to 'tensorflow/c/c_api_function_test.cc')
-rw-r--r-- | tensorflow/c/c_api_function_test.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tensorflow/c/c_api_function_test.cc b/tensorflow/c/c_api_function_test.cc index 4db9a90fdc..d5580b6589 100644 --- a/tensorflow/c/c_api_function_test.cc +++ b/tensorflow/c/c_api_function_test.cc @@ -1465,5 +1465,26 @@ TEST_F(CApiFunctionTest, AppendHash) { ASSERT_EQ(string("func_name_base_qaJ8jA8UmGY"), fdef.signature().name()); } +TEST_F(CApiFunctionTest, GetOpDef) { + DefineFunction(func_name_, &func_); + TF_GraphCopyFunction(host_graph_, func_, nullptr, s_); + ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_); + + // Test we can retrieve function OpDef from graph + TF_Buffer* buffer = TF_NewBuffer(); + TF_GraphGetOpDef(host_graph_, func_name_, buffer, s_); + ASSERT_EQ(TF_OK, TF_GetCode(s_)) << TF_Message(s_); + + // Sanity check returned OpDef + string data(static_cast<const char*>(buffer->data), buffer->length); + OpDef op_def; + op_def.ParseFromString(data); + EXPECT_EQ(op_def.name(), func_name_); + EXPECT_EQ(op_def.input_arg_size(), 1); + EXPECT_EQ(op_def.output_arg_size(), 1); + + TF_DeleteBuffer(buffer); +} + } // namespace } // namespace tensorflow |