Beispiel #1
0
        internal XArrayRef AllocTensorRef(XArray tensor)
        {
            var tensorRef = new XArrayRef();

            tensorRef.buffer      = GetBufferStart(tensor);
            tensorRef.dimCount    = tensor.Shape.Length;
            tensorRef.sizes       = AllocArray(tensor.Shape.Data);
            tensorRef.strides     = AllocArray(tensor.strides);
            tensorRef.elementType = tensor.DataType;
            return(tensorRef);
        }
Beispiel #2
0
        internal static XArray FromRef(XArrayRef tensorRef)
        {
            long[] shape_data = new long[tensorRef.dimCount];
            Marshal.Copy(tensorRef.sizes, shape_data, 0, shape_data.Length);
            Shape  shape  = new Shape(shape_data);
            XArray result = new XArray(shape, tensorRef.elementType);

            result.NativePtr = tensorRef.buffer;

            return(result);
        }
Beispiel #3
0
 /// <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);
 }