From ba8b0f37af17516b3838f5994413e5fbfbd41142 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Tue, 7 Jul 2020 07:53:20 -0500 Subject: [PATCH] add disable_eager_execution, clean unit test. --- src/TensorFlowNET.Console/Program.cs | 2 +- src/TensorFlowNET.Core/APIs/tf.compat.cs | 30 ++++++++ src/TensorFlowNET.Core/APIs/tf.compat.v1.cs | 30 ++++++++ src/TensorFlowNET.Core/Graphs/Graph.cs | 7 +- .../Operations/Operation.Control.cs | 4 +- .../Operations/Operation.cs | 4 +- .../Tensors/c_api.tensor.cs | 6 -- src/TensorFlowNET.Core/ops.cs | 6 +- .../Basics/QueueTest.cs | 4 +- .../Basics/VariableTest.cs | 2 - .../GraphModeTestBase.cs | 24 +++++++ test/TensorFlowNET.UnitTest/NameScopeTest.cs | 4 +- .../{ => NativeAPI}/GraphTest.cs | 0 test/TensorFlowNET.UnitTest/OperationsTest.cs | 5 +- .../{ => TF_API}/ConstantTest.cs | 18 +---- .../control_flow_ops_test/CondTestCases.cs | 7 +- .../control_flow_ops_test/ShapeTestCase.cs | 4 +- .../WhileContextTestCase.cs | 6 +- .../img_test/TestCrop.cs | 5 +- .../layers_test/flatten.cs | 4 +- .../ops_test/ControlDependenciesTest.cs | 70 +------------------ .../ops_test/CreateOpFromTfOperationTest.cs | 2 +- 22 files changed, 121 insertions(+), 123 deletions(-) create mode 100644 src/TensorFlowNET.Core/APIs/tf.compat.cs create mode 100644 src/TensorFlowNET.Core/APIs/tf.compat.v1.cs create mode 100644 test/TensorFlowNET.UnitTest/GraphModeTestBase.cs rename test/TensorFlowNET.UnitTest/{ => NativeAPI}/GraphTest.cs (100%) rename test/TensorFlowNET.UnitTest/{ => TF_API}/ConstantTest.cs (86%) diff --git a/src/TensorFlowNET.Console/Program.cs b/src/TensorFlowNET.Console/Program.cs index 32f85fb8..b8709849 100644 --- a/src/TensorFlowNET.Console/Program.cs +++ b/src/TensorFlowNET.Console/Program.cs @@ -27,7 +27,7 @@ namespace Tensorflow // 100K gradient 44M. mm.Execute(10, 10 * batchSize, cases.Gradient); - // 120M + // 95M Console.WriteLine("Finished."); Console.ReadLine(); } diff --git a/src/TensorFlowNET.Core/APIs/tf.compat.cs b/src/TensorFlowNET.Core/APIs/tf.compat.cs new file mode 100644 index 00000000..870ef82f --- /dev/null +++ b/src/TensorFlowNET.Core/APIs/tf.compat.cs @@ -0,0 +1,30 @@ +/***************************************************************************** + Copyright 2020 The TensorFlow.NET Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +******************************************************************************/ + +using NumSharp; + +namespace Tensorflow +{ + public partial class tensorflow + { + public CompatApi compat { get; } = new CompatApi(); + + public class CompatApi + { + public CompatV1Api v1 { get; } = new CompatV1Api(); + } + } +} diff --git a/src/TensorFlowNET.Core/APIs/tf.compat.v1.cs b/src/TensorFlowNET.Core/APIs/tf.compat.v1.cs new file mode 100644 index 00000000..97e3ac6e --- /dev/null +++ b/src/TensorFlowNET.Core/APIs/tf.compat.v1.cs @@ -0,0 +1,30 @@ +/***************************************************************************** + Copyright 2020 The TensorFlow.NET Authors. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +******************************************************************************/ + +using System; +using Tensorflow.Eager; +using static Tensorflow.Binding; + +namespace Tensorflow +{ + public class CompatV1Api + { + public void disable_eager_execution() + { + tf.context.default_execution_mode = Context.GRAPH_MODE; + } + } +} diff --git a/src/TensorFlowNET.Core/Graphs/Graph.cs b/src/TensorFlowNET.Core/Graphs/Graph.cs index cfa782ea..9ca97d09 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.cs @@ -259,7 +259,8 @@ namespace Tensorflow public Operation create_op(string op_type, Tensor[] inputs, TF_DataType[] dtypes, TF_DataType[] input_types = null, string name = null, - Dictionary attrs = null, OpDef op_def = null) + Dictionary attrs = null, OpDef op_def = null, + bool compute_device = true) { if (inputs == null) inputs = new Tensor[0]; @@ -270,7 +271,7 @@ namespace Tensorflow // If a names ends with a '/' it is a "name scope" and we use it as-is, // after removing the trailing '/'. name = name.EndsWith("/") ? ops.name_from_scope_name(name) : unique_name(name); - var node_def = ops._NodeDef(op_type, name, device: "", attrs: attrs); + var node_def = ops._NodeDef(op_type, name, attrs: attrs); var input_ops = inputs.Select(x => x.op).ToArray(); var control_inputs = _control_dependencies_for_inputs(input_ops); @@ -284,7 +285,7 @@ namespace Tensorflow original_op: null, op_def: op_def); - _create_op_helper(op, true); + _create_op_helper(op, compute_device); /*Console.Write($"create_op: {op_type} '{node_def.Name}'"); Console.Write($", inputs: {(inputs.Length == 0 ? "empty" : String.Join(", ", inputs.Select(x => x.name)))}"); diff --git a/src/TensorFlowNET.Core/Operations/Operation.Control.cs b/src/TensorFlowNET.Core/Operations/Operation.Control.cs index d6f73884..e2e83fa8 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Control.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Control.cs @@ -40,8 +40,8 @@ namespace Tensorflow public void _add_control_input(Operation op) { - //c_api.TF_AddControlInput(_operDesc, op); - c_api.AddControlInput(graph, _handle, op); + c_api.TF_AddControlInput(OpDesc, op); + //c_api.AddControlInput(graph, _handle, op); } public void _add_control_inputs(Operation[] ops) diff --git a/src/TensorFlowNET.Core/Operations/Operation.cs b/src/TensorFlowNET.Core/Operations/Operation.cs index 8af7a422..6c8e4485 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.cs @@ -64,7 +64,7 @@ namespace Tensorflow public string Device => _handle == IntPtr.Zero ? null : c_api.StringPiece(c_api.TF_OperationDevice(_handle)); bool _is_stateful; - + public OperationDescription OpDesc { get; set; } public NodeDef node_def { @@ -170,7 +170,7 @@ namespace Tensorflow op_def = g.GetOpDef(node_def.Op); var grouped_inputs = _reconstruct_sequence_inputs(op_def, inputs, node_def.Attr); - _handle = ops._create_c_op(g, node_def, grouped_inputs, control_input_ops.ToArray()); + (_handle, OpDesc) = ops._create_c_op(g, node_def, grouped_inputs, control_input_ops.ToArray()); _is_stateful = op_def.IsStateful; // Initialize self._outputs. diff --git a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs index 22b042d1..ee249de1 100644 --- a/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/c_api.tensor.cs @@ -187,9 +187,6 @@ namespace Tensorflow [DllImport(TensorFlowLibName)] public static extern unsafe ulong TF_StringEncode(byte* src, ulong src_len, sbyte* dst, ulong dst_len, SafeStatusHandle status); - [DllImport(TensorFlowLibName)] - public static extern unsafe ulong TF_StringEncode(IntPtr src, ulong src_len, IntPtr dst, ulong dst_len, SafeStatusHandle status); - /// /// Decode a string encoded using TF_StringEncode. /// @@ -199,9 +196,6 @@ namespace Tensorflow /// size_t* /// TF_Status* /// - [DllImport(TensorFlowLibName)] - public static extern ulong TF_StringDecode(IntPtr src, ulong src_len, IntPtr dst, ref ulong dst_len, SafeStatusHandle status); - [DllImport(TensorFlowLibName)] public static extern unsafe ulong TF_StringDecode(byte* src, ulong src_len, byte** dst, ref ulong dst_len, SafeStatusHandle status); diff --git a/src/TensorFlowNET.Core/ops.cs b/src/TensorFlowNET.Core/ops.cs index 87b0cfa1..93e2ba7a 100644 --- a/src/TensorFlowNET.Core/ops.cs +++ b/src/TensorFlowNET.Core/ops.cs @@ -155,7 +155,7 @@ namespace Tensorflow /// /// A list of `Operation`s to set as control dependencies. /// A wrapped TF_Operation*. - public static IntPtr _create_c_op(Graph graph, NodeDef node_def, T[] inputs, Operation[] control_inputs) + public static (IntPtr, OperationDescription) _create_c_op(Graph graph, NodeDef node_def, T[] inputs, Operation[] control_inputs) { lock (Locks.ProcessWide) { @@ -198,7 +198,7 @@ namespace Tensorflow status.Check(true); - return c_op; + return (c_op, op_desc); } } @@ -207,7 +207,7 @@ namespace Tensorflow return graph.GetOpDef(type); } - public static NodeDef _NodeDef(string op_type, string name, string device = "", Dictionary attrs = null) + public static NodeDef _NodeDef(string op_type, string name, Dictionary attrs = null) { var node_def = new NodeDef(); node_def.Op = op_type; diff --git a/test/TensorFlowNET.UnitTest/Basics/QueueTest.cs b/test/TensorFlowNET.UnitTest/Basics/QueueTest.cs index 991b875a..8d2d846d 100644 --- a/test/TensorFlowNET.UnitTest/Basics/QueueTest.cs +++ b/test/TensorFlowNET.UnitTest/Basics/QueueTest.cs @@ -4,13 +4,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.Basics { - [Ignore] [TestClass] - public class QueueTest + public class QueueTest : GraphModeTestBase { [TestMethod] public void PaddingFIFOQueue() diff --git a/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs b/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs index 8f78e768..41d4e6f1 100644 --- a/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs +++ b/test/TensorFlowNET.UnitTest/Basics/VariableTest.cs @@ -10,7 +10,6 @@ namespace TensorFlowNET.UnitTest.Basics [TestClass] public class VariableTest { - [Ignore] [TestMethod] public void NewVariable() { @@ -34,7 +33,6 @@ namespace TensorFlowNET.UnitTest.Basics Assert.AreEqual(4, (int)y.numpy()); } - [Ignore] [TestMethod] public void Assign1() { diff --git a/test/TensorFlowNET.UnitTest/GraphModeTestBase.cs b/test/TensorFlowNET.UnitTest/GraphModeTestBase.cs new file mode 100644 index 00000000..56d4de46 --- /dev/null +++ b/test/TensorFlowNET.UnitTest/GraphModeTestBase.cs @@ -0,0 +1,24 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Text; +using TensorFlowNET.UnitTest; +using static Tensorflow.Binding; + +namespace Tensorflow.UnitTest +{ + public class GraphModeTestBase : PythonTest + { + [TestInitialize] + public void TestInit() + { + tf.compat.v1.disable_eager_execution(); + } + + [TestCleanup] + public void TestClean() + { + tf.enable_eager_execution(); + } + } +} diff --git a/test/TensorFlowNET.UnitTest/NameScopeTest.cs b/test/TensorFlowNET.UnitTest/NameScopeTest.cs index 2ea44d8a..f631f422 100644 --- a/test/TensorFlowNET.UnitTest/NameScopeTest.cs +++ b/test/TensorFlowNET.UnitTest/NameScopeTest.cs @@ -1,16 +1,16 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.Basics { [TestClass] - public class NameScopeTest + public class NameScopeTest : GraphModeTestBase { string name = ""; - [Ignore] [TestMethod] public void NestedNameScope() { diff --git a/test/TensorFlowNET.UnitTest/GraphTest.cs b/test/TensorFlowNET.UnitTest/NativeAPI/GraphTest.cs similarity index 100% rename from test/TensorFlowNET.UnitTest/GraphTest.cs rename to test/TensorFlowNET.UnitTest/NativeAPI/GraphTest.cs diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs index ba503dca..51c9fb64 100644 --- a/test/TensorFlowNET.UnitTest/OperationsTest.cs +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -7,12 +7,12 @@ using Tensorflow; using Tensorflow.Util; using Buffer = Tensorflow.Buffer; using static Tensorflow.Binding; +using Tensorflow.UnitTest; namespace TensorFlowNET.UnitTest.Basics { - [Ignore] [TestClass] - public class OperationsTest + public class OperationsTest : GraphModeTestBase { /// /// Port from tensorflow\c\c_api_test.cc @@ -726,6 +726,7 @@ namespace TensorFlowNET.UnitTest.Basics #endregion } + [Ignore] [TestMethod] public void divOpTests() { diff --git a/test/TensorFlowNET.UnitTest/ConstantTest.cs b/test/TensorFlowNET.UnitTest/TF_API/ConstantTest.cs similarity index 86% rename from test/TensorFlowNET.UnitTest/ConstantTest.cs rename to test/TensorFlowNET.UnitTest/TF_API/ConstantTest.cs index bc6679a9..9cdcec73 100644 --- a/test/TensorFlowNET.UnitTest/ConstantTest.cs +++ b/test/TensorFlowNET.UnitTest/TF_API/ConstantTest.cs @@ -3,6 +3,7 @@ using NumSharp; using System; using System.Linq; using System.Runtime.InteropServices; +using System.Text; using Tensorflow; using static Tensorflow.Binding; @@ -160,23 +161,6 @@ namespace TensorFlowNET.UnitTest.Basics Assert.AreEqual(6.0, (double)c); } - [TestMethod] - public void StringEncode() - { - string str = "Hello, TensorFlow.NET!"; - var handle = Marshal.StringToHGlobalAnsi(str); - var dst_len = c_api.TF_StringEncodedSize((ulong)str.Length); - Assert.AreEqual(dst_len, (ulong)23); - IntPtr dst = Marshal.AllocHGlobal((int)dst_len); - var encoded_len = c_api.TF_StringEncode(handle, (ulong)str.Length, dst, dst_len, status.Handle); - Assert.AreEqual((ulong)23, encoded_len); - Assert.AreEqual(status.Code, TF_Code.TF_OK); - string encoded_str = Marshal.PtrToStringUTF8(dst + sizeof(byte)); - Assert.AreEqual(encoded_str, str); - Assert.AreEqual(str.Length, Marshal.ReadByte(dst)); - // c_api.TF_StringDecode(dst, (ulong)str.Length, IntPtr.Zero, ref dst_len, status.Handle); - } - [TestMethod] public void Reshape() { diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs index e606104b..4fae3de3 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs @@ -1,5 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.control_flow_ops_test @@ -7,10 +8,10 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test /// /// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py /// - [Ignore] [TestClass] - public class CondTestCases : PythonTest + public class CondTestCases : GraphModeTestBase { + [Ignore("Dependent on UpdateEdge")] [TestMethod] public void testCondTrue_ConstOnly() { @@ -49,6 +50,7 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test } } + [Ignore("Dependent on UpdateEdge")] [TestMethod] public void testCondTrue() { @@ -65,6 +67,7 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test assertEquals(result, 34); } + [Ignore("Dependent on UpdateEdge")] [TestMethod] public void testCondFalse() { diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/ShapeTestCase.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/ShapeTestCase.cs index bcbab528..ae013c69 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/ShapeTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/ShapeTestCase.cs @@ -1,14 +1,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using Tensorflow.UnitTest; namespace TensorFlowNET.UnitTest.control_flow_ops_test { /// /// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py /// - [Ignore] [TestClass] - public class ShapeTestCase : PythonTest + public class ShapeTestCase : GraphModeTestBase { [TestMethod] diff --git a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs index 9527e689..f29b6a4a 100644 --- a/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs +++ b/test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs @@ -1,24 +1,24 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.control_flow_ops_test { [TestClass] - public class WhileContextTestCase : PythonTest + public class WhileContextTestCase : GraphModeTestBase { /// /// https://www.tensorflow.org/api_docs/python/tf/while_loop /// - [Ignore] [TestMethod] public void SimpleWhileLoop() { var i = constant_op.constant(0, name: "i"); var c = new Func(x => tf.less(x, 10, name: "c")); var b = new Func(x => tf.add(x, 1, name: "c")); - //var r = control_flow_ops.while_loop(c, b, i); + // var r = control_flow_ops.while_loop(c, b, i); } private void _testWhileContextHelper(int maximum_iterations) diff --git a/test/TensorFlowNET.UnitTest/img_test/TestCrop.cs b/test/TensorFlowNET.UnitTest/img_test/TestCrop.cs index 5c1d4a8d..f1897d8f 100644 --- a/test/TensorFlowNET.UnitTest/img_test/TestCrop.cs +++ b/test/TensorFlowNET.UnitTest/img_test/TestCrop.cs @@ -2,15 +2,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.img_test { - [Ignore] [TestClass] - public class TestCrop + public class TestCrop : GraphModeTestBase { - [TestMethod] public void TestCropAndResize() { diff --git a/test/TensorFlowNET.UnitTest/layers_test/flatten.cs b/test/TensorFlowNET.UnitTest/layers_test/flatten.cs index ae6e5622..eb3fef93 100644 --- a/test/TensorFlowNET.UnitTest/layers_test/flatten.cs +++ b/test/TensorFlowNET.UnitTest/layers_test/flatten.cs @@ -3,13 +3,13 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using NumSharp; using Tensorflow; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.layers_test { - [Ignore] [TestClass] - public class flatten + public class flatten : GraphModeTestBase { [TestMethod] public void Case1() diff --git a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs index 62c64393..b689250d 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/ControlDependenciesTest.cs @@ -3,6 +3,7 @@ using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Tensorflow; using Tensorflow.Eager; +using Tensorflow.UnitTest; using static Tensorflow.Binding; namespace TensorFlowNET.UnitTest.ops_test @@ -10,9 +11,8 @@ namespace TensorFlowNET.UnitTest.ops_test /// /// excerpt of tensorflow/python/framework/ops_test.py /// - [Ignore] [TestClass] - public class ControlDependenciesTest : PythonTest + public class ControlDependenciesTest : GraphModeTestBase { [TestMethod] public void TestBasic() @@ -35,72 +35,6 @@ namespace TensorFlowNET.UnitTest.ops_test Assert.AreEqual(0, e.op.control_inputs.Length); } - [Ignore("Future is not supported yet")] - [TestMethod] - public void TestEager() - { - Tensor a = null, c = null; - object b = null; - var calls = 0; - Func future = () => - { - calls += 1; - return constant_op.constant(2.0); - }; - using (var opts = new ContextOptions()) - using (var status = new Status()) - using (var context = new Context(opts, status)) - { - if (context.executing_eagerly()) - { - // TODO: make this compile (see original Python code below) - a = constant_op.constant(1.0); - b = future; // <--- {henon} obviously, this doesn't compile, looks like control_dependencies needs to be able to take callables as well. - tf_with(ops.control_dependencies(new object[] { a, b }), ctrl => - { - return c = constant_op.constant(3.0); - }); - Assert.AreEqual(calls, 1); - } - else - { - var g = tf.Graph().as_default(); - a = constant_op.constant(1.0); - var b1 = future(); - tf_with(g.control_dependencies(new[] { a, b }), ctrl => - { - c = constant_op.constant(3.0); - }); - Assert.IsTrue(Enumerable.SequenceEqual(c.op.control_inputs, new[] { a.op, b1.op })); - Assert.AreEqual(1, calls); - } - } - /* - def testEager(self): - def future(): - future.calls += 1 - return constant_op.constant(2.0) - future.calls = 0 - - if context.executing_eagerly(): - a = constant_op.constant(1.0) - b = future - with ops.control_dependencies([a, b]): - c = constant_op.constant(3.0) - self.assertEqual(future.calls, 1) - else: - g = ops.Graph() - with g.as_default(): - a = constant_op.constant(1.0) - b = future() - with g.control_dependencies([a, b]): - c = constant_op.constant(3.0) - self.assertEqual(c.op.control_inputs, [a.op, b.op]) - self.assertEqual(future.calls, 1) - */ - } - - [Ignore("How to port the ConvertibleObj?")] [TestMethod] public void TestBasicWithConversion() diff --git a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs index 2bcab16a..1d6c4219 100644 --- a/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs +++ b/test/TensorFlowNET.UnitTest/ops_test/CreateOpFromTfOperationTest.cs @@ -28,7 +28,7 @@ namespace TensorFlowNET.UnitTest.ops_test using (var g = tf.Graph().as_default()) { var x = constant_op.constant(new[,] {{1, 2, 3}, {4, 5, 6}}); - var c_op = ops._create_c_op(g, ops._NodeDef("Identity", "myop"), new[] {x}, new Operation[0]); + var (c_op, op_desc) = ops._create_c_op(g, ops._NodeDef("Identity", "myop"), new[] {x}, new Operation[0]); var op = g._create_op_from_tf_operation(c_op); Assert.AreEqual("myop", op.name);