internal static XArray FromRef(XArrayRef tensorRef) { long[] shape_data = new long[tensorRef.dimCount]; Marshal.Copy(tensorRef.sizes, shape_data, 0, shape_data.Length); XArray result = new XArray(shape_data, tensorRef.elementType); result.NativePtr = tensorRef.buffer; return(result); }
internal XArrayRef AllocTensorRef(XArray tensor) { var tensorRef = new XArrayRef(); tensorRef.buffer = GetBufferStart(tensor); tensorRef.dimCount = tensor.Sizes.Length; tensorRef.sizes = AllocArray(tensor.Sizes); tensorRef.strides = AllocArray(tensor.strides); tensorRef.elementType = tensor.DataType; return(tensorRef); }
/// <summary> /// Frees the tensor reference. /// </summary> /// <param name="tensorRef">The tensor reference.</param> internal void FreeTensorRef(XArrayRef tensorRef) { Marshal.FreeHGlobal(tensorRef.sizes); Marshal.FreeHGlobal(tensorRef.strides); }