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

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