|
|
@@ -1,8 +1,10 @@ |
|
|
using System;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text;
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
using Tensorflow;
|
|
|
using Tensorflow;
|
|
|
|
|
|
using Tensorflow.Operations;
|
|
|
|
|
|
|
|
|
namespace TensorFlowNET.UnitTest
|
|
|
namespace TensorFlowNET.UnitTest
|
|
|
{
|
|
|
{
|
|
|
@@ -19,21 +21,21 @@ namespace TensorFlowNET.UnitTest |
|
|
[TestClass]
|
|
|
[TestClass]
|
|
|
public class CreateOpFromTfOperationTest : PythonTest
|
|
|
public class CreateOpFromTfOperationTest : PythonTest
|
|
|
{
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
[TestMethod]
|
|
|
public void TestShape()
|
|
|
public void TestShape()
|
|
|
{
|
|
|
{
|
|
|
var graph = tf.Graph().as_default();
|
|
|
var graph = tf.Graph().as_default();
|
|
|
with<Graph>(graph, g =>
|
|
|
with<Graph>(graph, g =>
|
|
|
{
|
|
|
{
|
|
|
var x = constant_op.constant(new [,] { {1, 2, 3}, {4, 5, 6}});
|
|
|
|
|
|
var (c_op, op_desc) = ops._create_c_op(g, ops._NodeDef("Identity", "myop"), new[] {x}, new Operation[0]);
|
|
|
|
|
|
|
|
|
var x = constant_op.constant(new[,] { { 1, 2, 3 }, { 4, 5, 6 } });
|
|
|
|
|
|
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);
|
|
|
var op = g._create_op_from_tf_operation(c_op);
|
|
|
|
|
|
|
|
|
Assert.AreEqual("myop", op.name);
|
|
|
Assert.AreEqual("myop", op.name);
|
|
|
Assert.AreEqual("Identity", op.type);
|
|
|
Assert.AreEqual("Identity", op.type);
|
|
|
Assert.AreEqual(1, len(op.outputs));
|
|
|
Assert.AreEqual(1, len(op.outputs));
|
|
|
assertItemsEqual(new []{2, 3}, op.outputs[0].shape);
|
|
|
|
|
|
|
|
|
assertItemsEqual(new[] { 2, 3 }, op.outputs[0].shape);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -47,7 +49,7 @@ namespace TensorFlowNET.UnitTest |
|
|
//var (c_op2, op_desc1) = ops._create_c_op(g, ops._NodeDef("Const", "myop_1"), new Tensor[0], new Operation[0]);
|
|
|
//var (c_op2, op_desc1) = ops._create_c_op(g, ops._NodeDef("Const", "myop_1"), new Tensor[0], new Operation[0]);
|
|
|
//var op = g._create_op_from_tf_operation(c_op);
|
|
|
//var op = g._create_op_from_tf_operation(c_op);
|
|
|
//var op2 = g._create_op_from_tf_operation(c_op2);
|
|
|
//var op2 = g._create_op_from_tf_operation(c_op2);
|
|
|
var op = constant_op.constant(0, name:"myop").op;
|
|
|
|
|
|
|
|
|
var op = constant_op.constant(0, name: "myop").op;
|
|
|
var op2 = constant_op.constant(0, name: "myop_1").op;
|
|
|
var op2 = constant_op.constant(0, name: "myop_1").op;
|
|
|
|
|
|
|
|
|
// Create ops with same names as op1 and op2. We expect the new names to be
|
|
|
// Create ops with same names as op1 and op2. We expect the new names to be
|
|
|
@@ -62,7 +64,7 @@ namespace TensorFlowNET.UnitTest |
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
[Ignore("Something is not right, Switch gets not inserted correctly?")]
|
|
|
|
|
|
|
|
|
[Ignore("Switch op gets not inserted correctly in the graph")]
|
|
|
[TestMethod]
|
|
|
[TestMethod]
|
|
|
public void TestCond()
|
|
|
public void TestCond()
|
|
|
{
|
|
|
{
|
|
|
@@ -91,8 +93,7 @@ namespace TensorFlowNET.UnitTest |
|
|
self.assertEqual(op_input.inputs[0], x);
|
|
|
self.assertEqual(op_input.inputs[0], x);
|
|
|
self.assertEqual(op.graph, g);
|
|
|
self.assertEqual(op.graph, g);
|
|
|
self.assertIsNotNone(op._get_control_flow_context());
|
|
|
self.assertIsNotNone(op._get_control_flow_context());
|
|
|
// TODO: op._get_control_flow_context().name not implemented
|
|
|
|
|
|
//self.assertEqual(op._get_control_flow_context().name, "cond/cond_text");
|
|
|
|
|
|
|
|
|
self.assertEqual((op._get_control_flow_context() as ControlFlowContext).name, "cond/cond_text");
|
|
|
});
|
|
|
});
|
|
|
/*
|
|
|
/*
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
@@ -126,7 +127,39 @@ namespace TensorFlowNET.UnitTest |
|
|
# pylint: enable=protected-access
|
|
|
# pylint: enable=protected-access
|
|
|
*/
|
|
|
*/
|
|
|
}
|
|
|
}
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Ignore("Todo: Port")]
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestWhileLoop()
|
|
|
|
|
|
{
|
|
|
|
|
|
var graph = tf.Graph().as_default();
|
|
|
|
|
|
Operation x=null;
|
|
|
|
|
|
with<Graph>(graph, g =>
|
|
|
|
|
|
{
|
|
|
|
|
|
x = constant_op.constant(42);
|
|
|
|
|
|
var body = new Func<int, int>(i =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ops._create_c_op(ops.get_default_graph(), ops._NodeDef("Identity", "myloop/myop"), new[] {x},
|
|
|
|
|
|
new Operation[0]);
|
|
|
|
|
|
var new_ops = g._add_new_tf_operations();
|
|
|
|
|
|
self.assertEqual(len(new_ops), 1);
|
|
|
|
|
|
return i;
|
|
|
|
|
|
});
|
|
|
|
|
|
// TODO: port control_flow_ops.while_loop
|
|
|
|
|
|
//control_flow_ops.while_loop( i => i < 10, body, new int[]{0}, name = "myloop");
|
|
|
|
|
|
});
|
|
|
|
|
|
var op = graph.get_operation_by_name("myloop/myop");
|
|
|
|
|
|
self.assertIsNotNone(op);
|
|
|
|
|
|
self.assertEqual(op.name, "myloop/myop");
|
|
|
|
|
|
self.assertEqual(op.type, "Identity");
|
|
|
|
|
|
self.assertEqual(op.outputs.Length, 0);
|
|
|
|
|
|
var op_input = op.inputs[0].op;
|
|
|
|
|
|
self.assertEqual(op_input.type, "Enter");
|
|
|
|
|
|
self.assertItemsEqual(op_input.inputs.OfType<Operation>().ToArray(), new[] {x});
|
|
|
|
|
|
self.assertEqual(op.graph, graph);
|
|
|
|
|
|
self.assertIsNotNone(op._get_control_flow_context());
|
|
|
|
|
|
self.assertEqual(((ControlFlowContext)op._get_control_flow_context()).name, "myloop/while_context");
|
|
|
|
|
|
/*
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
def testWhileLoop(self):
|
|
|
def testWhileLoop(self):
|
|
|
g = ops.Graph()
|
|
|
g = ops.Graph()
|
|
|
@@ -156,8 +189,15 @@ namespace TensorFlowNET.UnitTest |
|
|
self.assertEqual(op._get_control_flow_context().name,
|
|
|
self.assertEqual(op._get_control_flow_context().name,
|
|
|
"myloop/while_context")
|
|
|
"myloop/while_context")
|
|
|
# pylint: enable=protected-access
|
|
|
# pylint: enable=protected-access
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
|
|
|
|
|
|
[Ignore("Todo: Port")]
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestWhileLoopWithInternalControlDep()
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
def testWhileLoopWithInternalControlDep(self):
|
|
|
def testWhileLoopWithInternalControlDep(self):
|
|
|
g = ops.Graph()
|
|
|
g = ops.Graph()
|
|
|
with g.as_default():
|
|
|
with g.as_default():
|
|
|
@@ -180,7 +220,14 @@ namespace TensorFlowNET.UnitTest |
|
|
self.assertIsNotNone(c)
|
|
|
self.assertIsNotNone(c)
|
|
|
# Internal control dep is preserved
|
|
|
# Internal control dep is preserved
|
|
|
self.assertEqual(op.control_inputs, [c])
|
|
|
self.assertEqual(op.control_inputs, [c])
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Ignore("Todo: Port")]
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void TestWhileLoopWithExternalControlDep()
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
@test_util.run_v1_only("b/120545219")
|
|
|
def testWhileLoopWithExternalControlDep(self):
|
|
|
def testWhileLoopWithExternalControlDep(self):
|
|
|
g = ops.Graph()
|
|
|
g = ops.Graph()
|
|
|
@@ -203,8 +250,8 @@ namespace TensorFlowNET.UnitTest |
|
|
# External control dep is removed and replaced with internal control dep
|
|
|
# External control dep is removed and replaced with internal control dep
|
|
|
self.assertNotEqual(op.control_inputs[0], c.op)
|
|
|
self.assertNotEqual(op.control_inputs[0], c.op)
|
|
|
self.assertIsNotNone(op.control_inputs[0]._get_control_flow_context())
|
|
|
self.assertIsNotNone(op.control_inputs[0]._get_control_flow_context())
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|