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.

CondTestCases.cs 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using Tensorflow.UnitTest;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest.control_flow_ops_test
  6. {
  7. /// <summary>
  8. /// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py
  9. /// </summary>
  10. [TestClass]
  11. public class CondTestCases : GraphModeTestBase
  12. {
  13. [Ignore("Dependent on UpdateEdge")]
  14. [TestMethod]
  15. public void testCondTrue_ConstOnly()
  16. {
  17. var graph = tf.Graph().as_default();
  18. using (var sess = tf.Session(graph))
  19. {
  20. var x = tf.constant(2, name: "x");
  21. var y = tf.constant(5, name: "y");
  22. var z = control_flow_ops.cond(tf.less(x, y),
  23. () => tf.constant(22, name: "t22"),
  24. () => tf.constant(55, name: "f55"));
  25. int result = z.eval(sess);
  26. assertEquals(result, 22);
  27. }
  28. }
  29. [TestMethod]
  30. public void testCondFalse_ConstOnly()
  31. {
  32. var graph = tf.Graph().as_default();
  33. using (var sess = tf.Session(graph))
  34. {
  35. var x = tf.constant(2, name: "x");
  36. var y = tf.constant(1, name: "y");
  37. var z = control_flow_ops.cond(tf.less(x, y),
  38. () => tf.constant(22, name: "t22"),
  39. () => tf.constant(11, name: "f11"));
  40. int result = z.eval(sess);
  41. assertEquals(result, 11);
  42. }
  43. }
  44. [Ignore("Dependent on UpdateEdge")]
  45. [TestMethod]
  46. public void testCondTrue()
  47. {
  48. tf.Graph().as_default();
  49. var x = tf.constant(2, name: "x");
  50. var y = tf.constant(5, name: "y");
  51. var z = control_flow_ops.cond(tf.less(x, y),
  52. () => tf.multiply(x, 17),
  53. () => tf.add(y, 23));
  54. var result = evaluate<int>(z);
  55. assertEquals(result, 34);
  56. }
  57. [Ignore("Dependent on UpdateEdge")]
  58. [TestMethod]
  59. public void testCondFalse()
  60. {
  61. tf.Graph().as_default();
  62. var x = tf.constant(2);
  63. var y = tf.constant(1);
  64. var z = control_flow_ops.cond(tf.less(x, y),
  65. () => tf.multiply(x, 17),
  66. () => tf.add(y, 23));
  67. var result = evaluate<int>(z);
  68. assertEquals(result, 24);
  69. }
  70. // NOTE: all other python test cases of this class are either not needed due to strong typing or test a deprecated api
  71. }
  72. }