You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

WhileContextTestCase.cs 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest.ControlFlowTest
  6. {
  7. [TestClass]
  8. public class WhileContextTestCase : GraphModeTestBase
  9. {
  10. /// <summary>
  11. /// https://www.tensorflow.org/api_docs/python/tf/while_loop
  12. /// </summary>
  13. [TestMethod]
  14. public void SimpleWhileLoop()
  15. {
  16. var i = constant_op.constant(0, name: "i");
  17. var c = new Func<Tensor, Tensor>(x => tf.less(x, 10, name: "c"));
  18. var b = new Func<Tensor, Tensor>(x => tf.add(x, 1, name: "c"));
  19. // var r = control_flow_ops.while_loop(c, b, i);
  20. }
  21. private void _testWhileContextHelper(int maximum_iterations)
  22. {
  23. // TODO: implement missing code dependencies
  24. var sess = this.cached_session();
  25. var i = constant_op.constant(0, name: "i");
  26. var c = new Func<Tensor, Tensor>(x => gen_math_ops.less(x, ops.convert_to_tensor(10), name: "c"));
  27. var b = new Func<Tensor, Tensor>(x => math_ops.add(x, 1, name: "c"));
  28. //control_flow_ops.while_loop(
  29. // c, b, i , maximum_iterations: tf.constant(maximum_iterations));
  30. foreach (Operation op in sess.graph.get_operations())
  31. {
  32. var control_flow_context = op._get_control_flow_context();
  33. /*if (control_flow_context != null)
  34. self.assertProtoEquals(control_flow_context.to_proto(),
  35. WhileContext.from_proto(
  36. control_flow_context.to_proto()).to_proto(), "");*/
  37. }
  38. }
  39. [Ignore("TODO")]
  40. [TestMethod]
  41. public void testWhileContextWithMaximumIterations()
  42. {
  43. _testWhileContextHelper(maximum_iterations: 10);
  44. }
  45. }
  46. }