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.

CApiTest.cs 7.4 kB

6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow;
  4. using Tensorflow.Device;
  5. using Tensorflow.Eager;
  6. using Tensorflow.UnitTest;
  7. using Buffer = System.Buffer;
  8. namespace TensorFlowNET.UnitTest
  9. {
  10. public class CApiTest : GraphModeTestBase
  11. {
  12. protected static readonly TF_Code TF_OK = TF_Code.TF_OK;
  13. protected static readonly TF_DataType TF_FLOAT = TF_DataType.TF_FLOAT;
  14. protected static readonly TF_DataType TF_BOOL = TF_DataType.TF_BOOL;
  15. protected void EXPECT_TRUE(bool expected, string msg = "")
  16. => Assert.IsTrue(expected, msg);
  17. protected static void EXPECT_EQ(object expected, object actual, string msg = "")
  18. => Assert.AreEqual(expected, actual, msg);
  19. protected void CHECK_EQ(object expected, object actual, string msg = "")
  20. => Assert.AreEqual(expected, actual, msg);
  21. protected void EXPECT_NE(object expected, object actual, string msg = "")
  22. => Assert.AreNotEqual(expected, actual, msg);
  23. protected void CHECK_NE(object expected, object actual, string msg = "")
  24. => Assert.AreNotEqual(expected, actual, msg);
  25. protected void EXPECT_GE(int expected, int actual, string msg = "")
  26. => Assert.IsTrue(expected >= actual, msg);
  27. protected void ASSERT_EQ(object expected, object actual, string msg = "")
  28. => Assert.AreEqual(expected, actual, msg);
  29. protected void ASSERT_TRUE(bool condition, string msg = "")
  30. => Assert.IsTrue(condition, msg);
  31. protected OperationDescription TF_NewOperation(Graph graph, string opType, string opName)
  32. => c_api.TF_NewOperation(graph, opType, opName);
  33. protected void TF_AddInput(OperationDescription desc, TF_Output input)
  34. => c_api.TF_AddInput(desc, input);
  35. protected Operation TF_FinishOperation(OperationDescription desc, Status s)
  36. => c_api.TF_FinishOperation(desc, s.Handle);
  37. protected void TF_SetAttrTensor(OperationDescription desc, string attrName, Tensor value, Status s)
  38. => c_api.TF_SetAttrTensor(desc, attrName, value, s.Handle);
  39. protected void TF_SetAttrType(OperationDescription desc, string attrName, TF_DataType dtype)
  40. => c_api.TF_SetAttrType(desc, attrName, dtype);
  41. protected void TF_SetAttrBool(OperationDescription desc, string attrName, bool value)
  42. => c_api.TF_SetAttrBool(desc, attrName, value);
  43. protected TF_DataType TFE_TensorHandleDataType(IntPtr h)
  44. => c_api.TFE_TensorHandleDataType(h);
  45. protected int TFE_TensorHandleNumDims(IntPtr h, SafeStatusHandle status)
  46. => c_api.TFE_TensorHandleNumDims(h, status);
  47. protected TF_Code TF_GetCode(Status s)
  48. => s.Code;
  49. protected static TF_Code TF_GetCode(SafeStatusHandle s)
  50. => c_api.TF_GetCode(s);
  51. protected static string TF_Message(SafeStatusHandle s)
  52. => c_api.StringPiece(c_api.TF_Message(s));
  53. protected SafeStatusHandle TF_NewStatus()
  54. => c_api.TF_NewStatus();
  55. protected void TF_DeleteTensor(IntPtr t)
  56. => c_api.TF_DeleteTensor(t);
  57. protected IntPtr TF_TensorData(IntPtr t)
  58. => c_api.TF_TensorData(t);
  59. protected ulong TF_TensorByteSize(IntPtr t)
  60. => c_api.TF_TensorByteSize(t);
  61. protected void TFE_OpAddInput(SafeOpHandle op, IntPtr h, SafeStatusHandle status)
  62. => c_api.TFE_OpAddInput(op, h, status);
  63. protected void TFE_OpSetAttrType(SafeOpHandle op, string attr_name, TF_DataType value)
  64. => c_api.TFE_OpSetAttrType(op, attr_name, value);
  65. protected void TFE_OpSetAttrShape(SafeOpHandle op, string attr_name, long[] dims, int num_dims, SafeStatusHandle out_status)
  66. => c_api.TFE_OpSetAttrShape(op, attr_name, dims, num_dims, out_status);
  67. protected void TFE_OpSetAttrString(SafeOpHandle op, string attr_name, string value, uint length)
  68. => c_api.TFE_OpSetAttrString(op, attr_name, value, length);
  69. protected SafeOpHandle TFE_NewOp(SafeContextHandle ctx, string op_or_function_name, SafeStatusHandle status)
  70. => c_api.TFE_NewOp(ctx, op_or_function_name, status);
  71. protected IntPtr TFE_NewTensorHandle(IntPtr t, SafeStatusHandle status)
  72. => c_api.TFE_NewTensorHandle(t, status);
  73. protected void TFE_Execute(SafeOpHandle op, IntPtr[] retvals, ref int num_retvals, SafeStatusHandle status)
  74. => c_api.TFE_Execute(op, retvals, ref num_retvals, status);
  75. protected SafeContextOptionsHandle TFE_NewContextOptions()
  76. => c_api.TFE_NewContextOptions();
  77. protected SafeContextHandle TFE_NewContext(SafeContextOptionsHandle opts, SafeStatusHandle status)
  78. => c_api.TFE_NewContext(opts, status);
  79. protected int TFE_OpGetInputLength(SafeOpHandle op, string input_name, SafeStatusHandle status)
  80. => c_api.TFE_OpGetInputLength(op, input_name, status);
  81. protected int TFE_OpAddInputList(SafeOpHandle op, IntPtr[] inputs, int num_inputs, SafeStatusHandle status)
  82. => c_api.TFE_OpAddInputList(op, inputs, num_inputs, status);
  83. protected int TFE_OpGetOutputLength(SafeOpHandle op, string input_name, SafeStatusHandle status)
  84. => c_api.TFE_OpGetOutputLength(op, input_name, status);
  85. protected void TFE_DeleteTensorHandle(IntPtr h)
  86. => c_api.TFE_DeleteTensorHandle(h);
  87. protected SafeExecutorHandle TFE_ContextGetExecutorForThread(SafeContextHandle ctx)
  88. => c_api.TFE_ContextGetExecutorForThread(ctx);
  89. protected void TFE_ExecutorWaitForAllPendingNodes(SafeExecutorHandle executor, SafeStatusHandle status)
  90. => c_api.TFE_ExecutorWaitForAllPendingNodes(executor, status);
  91. protected IntPtr TFE_TensorHandleResolve(IntPtr h, SafeStatusHandle status)
  92. => c_api.TFE_TensorHandleResolve(h, status);
  93. protected string TFE_TensorHandleDeviceName(IntPtr h, SafeStatusHandle status)
  94. => c_api.StringPiece(c_api.TFE_TensorHandleDeviceName(h, status));
  95. protected string TFE_TensorHandleBackingDeviceName(IntPtr h, SafeStatusHandle status)
  96. => c_api.StringPiece(c_api.TFE_TensorHandleBackingDeviceName(h, status));
  97. protected SafeDeviceListHandle TFE_ContextListDevices(SafeContextHandle ctx, SafeStatusHandle status)
  98. => c_api.TFE_ContextListDevices(ctx, status);
  99. protected int TF_DeviceListCount(SafeDeviceListHandle list)
  100. => c_api.TF_DeviceListCount(list);
  101. protected string TF_DeviceListType(SafeDeviceListHandle list, int index, SafeStatusHandle status)
  102. => c_api.StringPiece(c_api.TF_DeviceListType(list, index, status));
  103. protected string TF_DeviceListName(SafeDeviceListHandle list, int index, SafeStatusHandle status)
  104. => c_api.TF_DeviceListName(list, index, status);
  105. protected IntPtr TFE_TensorHandleCopyToDevice(IntPtr h, SafeContextHandle ctx, string device_name, SafeStatusHandle status)
  106. => c_api.TFE_TensorHandleCopyToDevice(h, ctx, device_name, status);
  107. protected void TFE_OpSetDevice(SafeOpHandle op, string device_name, SafeStatusHandle status)
  108. => c_api.TFE_OpSetDevice(op, device_name, status);
  109. }
  110. }