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 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. using (var sess = this.cached_session())
  25. {
  26. var i = constant_op.constant(0, name: "i");
  27. var c = new Func<Tensor, Tensor>(x => gen_math_ops.less(x, 10, name: "c"));
  28. var b = new Func<Tensor, Tensor>(x => gen_math_ops.add(x, 1, name: "c"));
  29. //control_flow_ops.while_loop(
  30. // c, b, i , maximum_iterations: tf.constant(maximum_iterations));
  31. foreach (Operation op in sess.graph.get_operations())
  32. {
  33. var control_flow_context = op._get_control_flow_context();
  34. /*if (control_flow_context != null)
  35. self.assertProtoEquals(control_flow_context.to_proto(),
  36. WhileContext.from_proto(
  37. control_flow_context.to_proto()).to_proto(), "");*/
  38. }
  39. }
  40. }
  41. [Ignore("TODO")]
  42. [TestMethod]
  43. public void testWhileContextWithMaximumIterations()
  44. {
  45. _testWhileContextHelper(maximum_iterations: 10);
  46. }
  47. }
  48. }