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.

CApi.Eager.cs 1.1 kB

123456789101112131415161718192021222324252627282930313233
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using Tensorflow;
  4. using Tensorflow.Eager;
  5. using Buffer = System.Buffer;
  6. namespace TensorFlowNET.UnitTest.Eager
  7. {
  8. /// <summary>
  9. /// tensorflow\c\eager\c_api_test.cc
  10. /// </summary>
  11. [TestClass]
  12. public partial class CApiEagerTest : CApiTest
  13. {
  14. unsafe IntPtr TestMatrixTensorHandle()
  15. {
  16. var dims = new long[] { 2, 2 };
  17. var data = new float[] { 1.0f, 2.0f, 3.0f, 4.0f };
  18. var t = c_api.TF_AllocateTensor(TF_FLOAT, dims, dims.Length, (ulong)data.Length * sizeof(float));
  19. fixed(void *src = &data[0])
  20. {
  21. Buffer.MemoryCopy(src, (void*)c_api.TF_TensorData(t), (long)c_api.TF_TensorByteSize(t), data.Length * sizeof(float));
  22. }
  23. var status = c_api.TF_NewStatus();
  24. var th = c_api.TFE_NewTensorHandle(t, status);
  25. CHECK_EQ(TF_OK, TF_GetCode(status), TF_Message(status));
  26. c_api.TF_DeleteTensor(t);
  27. c_api.TF_DeleteStatus(status);
  28. return th;
  29. }
  30. }
  31. }