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 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Tensorflow;
  3. namespace TensorFlowNET.UnitTest.control_flow_ops_test
  4. {
  5. /// <summary>
  6. /// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py
  7. /// </summary>
  8. [TestClass]
  9. public class CondTestCases : PythonTest
  10. {
  11. [Ignore("Todo")]
  12. [TestMethod]
  13. public void testCondTrue()
  14. {
  15. //var x = constant_op.constant(2);
  16. //var y = constant_op.constant(5);
  17. // var z = control_flow_ops.cond(math_ops.less(x,y), ()=> math_ops.multiply(x, 17), ()=> math_ops.add(y, 23))
  18. //self.assertEquals(self.evaluate(z), 34);
  19. }
  20. [Ignore("Todo")]
  21. [TestMethod]
  22. public void testCondFalse()
  23. {
  24. // def testCondFalse(self):
  25. // x = constant_op.constant(2)
  26. // y = constant_op.constant(1)
  27. // z = control_flow_ops.cond(
  28. // math_ops.less(
  29. // x,
  30. // y), lambda: math_ops.multiply(x, 17), lambda: math_ops.add(y, 23))
  31. // self.assertEquals(self.evaluate(z), 24)
  32. }
  33. [Ignore("Todo")]
  34. [TestMethod]
  35. public void testCondTrueLegacy()
  36. {
  37. // def testCondTrueLegacy(self):
  38. // x = constant_op.constant(2)
  39. // y = constant_op.constant(5)
  40. // z = control_flow_ops.cond(
  41. // math_ops.less(x, y),
  42. // fn1=lambda: math_ops.multiply(x, 17),
  43. // fn2=lambda: math_ops.add(y, 23))
  44. // self.assertEquals(self.evaluate(z), 34)
  45. }
  46. [Ignore("Todo")]
  47. [TestMethod]
  48. public void testCondFalseLegacy()
  49. {
  50. // def testCondFalseLegacy(self):
  51. // x = constant_op.constant(2)
  52. // y = constant_op.constant(1)
  53. // z = control_flow_ops.cond(
  54. // math_ops.less(x, y),
  55. // fn1=lambda: math_ops.multiply(x, 17),
  56. // fn2=lambda: math_ops.add(y, 23))
  57. // self.assertEquals(self.evaluate(z), 24)
  58. }
  59. [Ignore("Todo")]
  60. [TestMethod]
  61. public void testCondMissingArg1()
  62. {
  63. // def testCondMissingArg1(self):
  64. // x = constant_op.constant(1)
  65. // with self.assertRaises(TypeError):
  66. // control_flow_ops.cond(True, false_fn=lambda: x)
  67. }
  68. [Ignore("Todo")]
  69. [TestMethod]
  70. public void testCondMissingArg2()
  71. {
  72. // def testCondMissingArg2(self):
  73. // x = constant_op.constant(1)
  74. // with self.assertRaises(TypeError):
  75. // control_flow_ops.cond(True, lambda: x)
  76. }
  77. [Ignore("Todo")]
  78. [TestMethod]
  79. public void testCondDuplicateArg1()
  80. {
  81. // def testCondDuplicateArg1(self):
  82. // x = constant_op.constant(1)
  83. // with self.assertRaises(TypeError):
  84. // control_flow_ops.cond(True, lambda: x, lambda: x, fn1=lambda: x)
  85. }
  86. [Ignore("Todo")]
  87. [TestMethod]
  88. public void testCondDuplicateArg2()
  89. {
  90. // def testCondDuplicateArg2(self):
  91. // x = constant_op.constant(1)
  92. // with self.assertRaises(TypeError):
  93. // control_flow_ops.cond(True, lambda: x, lambda: x, fn2=lambda: x)
  94. }
  95. }
  96. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。