From e27bf7bb83cfff015af438fd511f4fbfb5df4738 Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Tue, 9 Apr 2019 11:36:14 +0200 Subject: [PATCH] _ControlDependenciesController: fixed a bug related to stack order --- src/TensorFlowNET.Core/Graphs/Graph.Control.cs | 18 ++++-------------- .../Graphs/_ControlDependenciesController.cs | 4 ++-- .../ControlDependenciesTest.cs | 1 - 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Control.cs b/src/TensorFlowNET.Core/Graphs/Graph.Control.cs index 9c2881e1..0ac0becf 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Control.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Control.cs @@ -10,18 +10,8 @@ namespace Tensorflow { public IControlFlowContext _control_flow_context; - private Queue<_ControlDependenciesController> _graph_control_dependencies_stack = new Queue<_ControlDependenciesController>(); - public Queue<_ControlDependenciesController> _control_dependencies_stack - { - get - { - return _graph_control_dependencies_stack; - } - set - { - _graph_control_dependencies_stack = value; - } - } + // represents the nested with(...) statements + public List<_ControlDependenciesController> _control_dependencies_stack { get; set; } = new List<_ControlDependenciesController>(); /// /// For an op that takes `input_ops` as inputs, compute control inputs. @@ -122,12 +112,12 @@ namespace Tensorflow public void _push_control_dependencies_controller(_ControlDependenciesController controller) { - _control_dependencies_stack.Enqueue(controller); + _control_dependencies_stack.Add(controller); } public void _pop_control_dependencies_controller(_ControlDependenciesController controller) { - _control_dependencies_stack.Dequeue(); + _control_dependencies_stack.RemoveAt(_control_dependencies_stack.Count-1); } /// diff --git a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs index 8def1417..36832b35 100644 --- a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs +++ b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs @@ -13,7 +13,7 @@ namespace Tensorflow private Graph _graph; private List _control_inputs_val; private List _seen_nodes; - private Queue<_ControlDependenciesController> _old_stack; + private List<_ControlDependenciesController> _old_stack; private bool _new_stack; private IControlFlowContext _old_control_flow_context; @@ -73,7 +73,7 @@ namespace Tensorflow { // Clear the control_dependencies graph. _old_stack = _graph._control_dependencies_stack; - _graph._control_dependencies_stack = new Queue<_ControlDependenciesController>(); + _graph._control_dependencies_stack = new List<_ControlDependenciesController>(); // Clear the control_flow_context too. _old_control_flow_context = _graph._get_control_flow_context(); diff --git a/test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs b/test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs index 3be4e80e..389f0206 100644 --- a/test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs +++ b/test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs @@ -161,7 +161,6 @@ namespace TensorFlowNET.UnitTest AssertItemsEqual(b_1.op.control_inputs, b_2.op.control_inputs); } - [Ignore("Fails")] [TestMethod] public void TestClear() {