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.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Tensorflow;
  4. using static Tensorflow.Python;
  5. namespace TensorFlowNET.UnitTest.control_flow_ops_test
  6. {
  7. [TestClass]
  8. public class WhileContextTestCase : PythonTest
  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, new[] { i });
  20. }
  21. private void _testWhileContextHelper(int? maximum_iterations = null)
  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, new[] { i }, maximum_iterations: 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 testWhileContext()
  44. {
  45. _testWhileContextHelper();
  46. }
  47. [Ignore("TODO")]
  48. [TestMethod]
  49. public void testWhileContextWithMaximumIterations()
  50. {
  51. _testWhileContextHelper(maximum_iterations: 10);
  52. }
  53. }
  54. }