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.

BindingArray.cs 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*****************************************************************************
  2. Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ******************************************************************************/
  13. using System;
  14. using System.Runtime.InteropServices;
  15. namespace Tensorflow
  16. {
  17. [StructLayout(LayoutKind.Sequential)]
  18. public struct BindingArray
  19. {
  20. public IntPtr array;
  21. public int length;
  22. public static implicit operator BindingArray(IntPtr handle)
  23. => handle == IntPtr.Zero ? default : Marshal.PtrToStructure<BindingArray>(handle);
  24. public unsafe IntPtr this[int index]
  25. => array == IntPtr.Zero ? IntPtr.Zero : * ((IntPtr*)array + index);
  26. public unsafe IntPtr[] Data()
  27. {
  28. var results = new IntPtr[length];
  29. for (int i = 0; i < length; i++)
  30. results[i] = array == IntPtr.Zero ? IntPtr.Zero : * ((IntPtr*)array + i);
  31. return results;
  32. }
  33. }
  34. }