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

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