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

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. using static Tensorflow.Python;
  4. namespace TensorFlowNET.UnitTest.control_flow_ops_test
  5. {
  6. /// <summary>
  7. /// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py
  8. /// </summary>
  9. [TestClass]
  10. public class CondTestCases : PythonTest
  11. {
  12. [Ignore("need tesnroflow expose AddControlInput API")]
  13. [TestMethod]
  14. public void testCondTrue_ConstOnly()
  15. {
  16. var graph = tf.Graph().as_default();
  17. with(tf.Session(graph), sess =>
  18. {
  19. var x = tf.constant(2, name: "x");
  20. var y = tf.constant(5, name: "y");
  21. var z = control_flow_ops.cond(tf.less(x, y),
  22. () => tf.constant(22, name: "t22"),
  23. () => tf.constant(55, name: "f55"));
  24. int result = z.eval(sess);
  25. assertEquals(result, 22);
  26. });
  27. }
  28. [Ignore("need tesnroflow expose AddControlInput API")]
  29. [TestMethod]
  30. public void testCondFalse_ConstOnly()
  31. {
  32. var graph = tf.Graph().as_default();
  33. with(tf.Session(graph), sess =>
  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("need tesnroflow expose AddControlInput API")]
  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("need tesnroflow expose AddControlInput API")]
  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. }