Browse Source

Operation: implemented support for Tensors in Operation constructor + Test

tags/v0.9
Meinrad Recheis 6 years ago
parent
commit
f079605032
2 changed files with 45 additions and 0 deletions
  1. +7
    -0
      src/TensorFlowNET.Core/Operations/Operation.cs
  2. +38
    -0
      test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs

+ 7
- 0
src/TensorFlowNET.Core/Operations/Operation.cs View File

@@ -117,6 +117,13 @@ namespace Tensorflow
case Operation c1: case Operation c1:
control_input_ops.Add(c1); control_input_ops.Add(c1);
break; break;
case Tensor tensor:
control_input_ops.Add(tensor.op);
break;
// TODO: IndexedSlices don't yet exist, but once they do, this needs to be uncommented
//case IndexedSlices islices:
// control_input_ops.Add(islices.op);
// break;
default: default:
throw new NotImplementedException($"Control input must be an Operation, a Tensor, or IndexedSlices: {c}"); throw new NotImplementedException($"Control input must be an Operation, a Tensor, or IndexedSlices: {c}");
} }


+ 38
- 0
test/TensorFlowNET.UnitTest/ControlDependenciesTest.cs View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tensorflow;
namespace TensorFlowNET.UnitTest
{
/// <summary>
/// tensorflow/python/framework/ops_test.py
/// </summary>
[TestClass]
public class ControlDependenciesTest : Python
{
[TestMethod]
public void TestBasic()
{
var graph = tf.Graph().as_default();
Tensor a=null, b = null, c = null, d = null, e = null;
with<Graph>(graph, g =>
{
a = constant_op.constant(1.0);
b = constant_op.constant(1.0);
with(g.control_dependencies(new ITensorOrOperation[] {a}), x =>
{
c = constant_op.constant(1.0);
d = array_ops.identity(b);
e = array_ops.identity(c);
});
});
Assert.IsTrue(Enumerable.SequenceEqual(c.op.control_inputs, new[] {a.op}));
Assert.IsTrue(Enumerable.SequenceEqual(d.op.control_inputs, new[] {a.op}));
// e should be dominated by c.
Assert.AreEqual(0, e.op.control_inputs.Length);
}
}
}

Loading…
Cancel
Save