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.

NameScopeTest.cs 2.4 kB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Tensorflow;
  4. using static Tensorflow.Binding;
  5. namespace TensorFlowNET.UnitTest
  6. {
  7. [TestClass]
  8. public class NameScopeTest
  9. {
  10. string name = "";
  11. [TestMethod]
  12. public void NestedNameScope()
  13. {
  14. Graph g = tf.Graph().as_default();
  15. tf_with(new ops.NameScope("scope1"), scope1 =>
  16. {
  17. name = scope1;
  18. Assert.AreEqual("scope1", g._name_stack);
  19. Assert.AreEqual("scope1/", name);
  20. var const1 = tf.constant(1.0);
  21. Assert.AreEqual("scope1/Const:0", const1.name);
  22. tf_with(new ops.NameScope("scope2"), scope2 =>
  23. {
  24. name = scope2;
  25. Assert.AreEqual("scope1/scope2", g._name_stack);
  26. Assert.AreEqual("scope1/scope2/", name);
  27. var const2 = tf.constant(2.0);
  28. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  29. });
  30. Assert.AreEqual("scope1", g._name_stack);
  31. var const3 = tf.constant(2.0);
  32. Assert.AreEqual("scope1/Const_1:0", const3.name);
  33. });
  34. g.Dispose();
  35. Assert.AreEqual("", g._name_stack);
  36. }
  37. [TestMethod, Ignore("Unimplemented Usage")]
  38. public void NestedNameScope_Using()
  39. {
  40. Graph g = tf.Graph().as_default();
  41. using (var name = new ops.NameScope("scope1"))
  42. {
  43. Assert.AreEqual("scope1", g._name_stack);
  44. Assert.AreEqual("scope1/", name);
  45. var const1 = tf.constant(1.0);
  46. Assert.AreEqual("scope1/Const:0", const1.name);
  47. using (var name2 = new ops.NameScope("scope2"))
  48. {
  49. Assert.AreEqual("scope1/scope2", g._name_stack);
  50. Assert.AreEqual("scope1/scope2/", name);
  51. var const2 = tf.constant(2.0);
  52. Assert.AreEqual("scope1/scope2/Const:0", const2.name);
  53. }
  54. Assert.AreEqual("scope1", g._name_stack);
  55. var const3 = tf.constant(2.0);
  56. Assert.AreEqual("scope1/Const_1:0", const3.name);
  57. };
  58. g.Dispose();
  59. Assert.AreEqual("", g._name_stack);
  60. }
  61. }
  62. }