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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  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. [Ignore]
  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, new[] { i });
  21. }
  22. private void _testWhileContextHelper(int? maximum_iterations = null)
  23. {
  24. // TODO: implement missing code dependencies
  25. using (var sess = this.cached_session())
  26. {
  27. var i = constant_op.constant(0, name: "i");
  28. var c = new Func<Tensor, Tensor>(x => gen_math_ops.less(x, 10, name: "c"));
  29. var b = new Func<Tensor, Tensor>(x => gen_math_ops.add(x, 1, name: "c"));
  30. control_flow_ops.while_loop(
  31. c, b, new[] { i }, maximum_iterations: maximum_iterations);
  32. foreach (Operation op in sess.graph.get_operations())
  33. {
  34. var control_flow_context = op._get_control_flow_context();
  35. /*if (control_flow_context != null)
  36. self.assertProtoEquals(control_flow_context.to_proto(),
  37. WhileContext.from_proto(
  38. control_flow_context.to_proto()).to_proto(), "");*/
  39. }
  40. }
  41. }
  42. [Ignore("TODO")]
  43. [TestMethod]
  44. public void testWhileContext()
  45. {
  46. _testWhileContextHelper();
  47. }
  48. [Ignore("TODO")]
  49. [TestMethod]
  50. public void testWhileContextWithMaximumIterations()
  51. {
  52. _testWhileContextHelper(maximum_iterations: 10);
  53. }
  54. }
  55. }