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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Linq;
  4. using Tensorflow;
  5. using static Tensorflow.Binding;
  6. namespace TensorFlowNET.UnitTest.ControlFlowTest
  7. {
  8. [TestClass]
  9. public class WhileContextTestCase : GraphModeTestBase
  10. {
  11. /// <summary>
  12. /// https://www.tensorflow.org/api_docs/python/tf/while_loop
  13. /// </summary>
  14. [TestMethod]
  15. public void SimpleWhileLoop()
  16. {
  17. var i = constant_op.constant(0, name: "i");
  18. var c = new Func<Tensor, Tensor>(x => tf.less(x, 10, name: "c"));
  19. var b = new Func<Tensor, Tensor>(x => tf.add(x, 1, name: "c"));
  20. // var r = control_flow_ops.while_loop(c, b, i);
  21. }
  22. private void _testWhileContextHelper(int maximum_iterations)
  23. {
  24. // TODO: implement missing code dependencies
  25. var sess = this.cached_session();
  26. var i = constant_op.constant(0, name: "i");
  27. var c = new Func<Tensor, Tensor>(x => gen_math_ops.less(x, ops.convert_to_tensor(10), name: "c"));
  28. var b = new Func<Tensor, Tensor>(x => 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.Single().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. [Ignore("TODO")]
  41. [TestMethod]
  42. public void testWhileContextWithMaximumIterations()
  43. {
  44. _testWhileContextHelper(maximum_iterations: 10);
  45. }
  46. }
  47. }