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.

AttributesTestcs.cs 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. namespace Tensorflow.Native.UnitTest
  4. {
  5. /// <summary>
  6. /// tensorflow\c\c_api_test.cc
  7. /// `class CApiAttributesTest`
  8. /// </summary>
  9. [TestClass]
  10. public class AttributesTestcs : CApiTest, IDisposable
  11. {
  12. private Graph graph_;
  13. private int counter_;
  14. private Status s_;
  15. public AttributesTestcs()
  16. {
  17. s_ = new Status();
  18. graph_ = new Graph();
  19. }
  20. private OperationDescription init(string type)
  21. {
  22. // Construct op_name to match the name used by REGISTER_OP in the
  23. // ATTR_TEST_REGISTER calls above.
  24. string op_name = "CApiAttributesTestOp";
  25. if (type.Contains("list("))
  26. {
  27. op_name += "List";
  28. type = type.Substring(5, type.Length - 6);
  29. }
  30. op_name += type;
  31. return c_api.TF_NewOperation(graph_, op_name, $"name{counter_++}");
  32. }
  33. /// <summary>
  34. /// REGISTER_OP for CApiAttributesTest test cases.
  35. /// Registers two ops, each with a single attribute called 'v'.
  36. /// The attribute in one op will have a type 'type', the other
  37. /// will have list(type).
  38. /// </summary>
  39. /// <param name="type"></param>
  40. private void ATTR_TEST_REGISTER_OP(string type)
  41. {
  42. }
  43. private void EXPECT_TF_META(Operation oper, string attr_name, int expected_list_size, TF_AttrType expected_type, uint expected_total_size)
  44. {
  45. var m = c_api.TF_OperationGetAttrMetadata(oper, attr_name, s_.Handle);
  46. EXPECT_EQ(TF_Code.TF_OK, s_.Code);
  47. char e = expected_list_size >= 0 ? (char)1 : (char)0;
  48. /*EXPECT_EQ(e, m.is_list);
  49. EXPECT_EQ(expected_list_size, m.list_size);
  50. EXPECT_EQ(expected_type, m.type);
  51. EXPECT_EQ(expected_total_size, m.total_size);*/
  52. }
  53. [TestMethod]
  54. public void String()
  55. {
  56. var desc = init("string");
  57. c_api.TF_SetAttrString(desc, "v", "bunny", 5);
  58. var oper = c_api.TF_FinishOperation(desc, s_.Handle);
  59. //ASSERT_EQ(TF_Code.TF_OK, s_.Code);
  60. //EXPECT_TF_META(oper, "v", -1, TF_AttrType.TF_ATTR_STRING, 5);
  61. //var value = new char[5];
  62. //c_api.TF_OperationGetAttrString(oper, "v", value, 5, s_);
  63. //EXPECT_EQ(TF_Code.TF_OK, s_.Code);
  64. //EXPECT_EQ("bunny", value, 5));
  65. }
  66. [TestMethod]
  67. public void GetAttributesTest()
  68. {
  69. var desc = graph_.NewOperation("Placeholder", "node");
  70. desc.SetAttrType("dtype", TF_DataType.TF_FLOAT);
  71. long[] ref_shape = new long[3] { 1, 2, 3 };
  72. desc.SetAttrShape("shape", ref_shape);
  73. var oper = desc.FinishOperation(s_);
  74. var metadata = oper.GetAttributeMetadata("shape", s_);
  75. }
  76. public void Dispose()
  77. {
  78. graph_.Dispose();
  79. s_.Dispose();
  80. }
  81. }
  82. }