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.

CApiAttributesTestcs.cs 3.1 kB

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