Backends/SiaNet.Backend.TensorSharp/Cpu/NativeWrapper.cs
/// <summary>
/// Builds the tensor reference PTR.
/// </summary>
/// <param name="tensor">The tensor.</param>
/// <param name="tensorRefPtr">The tensor reference PTR.</param>
/// <returns>IDisposable.</returns>
Builds the tensor reference PTR.
Builds the tensor reference PTR .
public static IDisposable BuildTensorRefPtr(NDArray tensor, out IntPtr tensorRefPtr)
        {
            var tensorRef = NativeWrapper.AllocTensorRef(tensor);
            var tensorPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TensorRef64)));
            Marshal.StructureToPtr(tensorRef, tensorPtr, false);
            tensorRefPtr = tensorPtr;
            return new DelegateDisposable(() =>
            {
                Marshal.FreeHGlobal(tensorPtr);
                NativeWrapper.FreeTensorRef(tensorRef);
            });
        }
public static IDisposable BuildTensorRefPtr ( NDArray tensor , out IntPtr tensorRefPtr ) { var tensorRef = NativeWrapper . AllocTensorRef ( tensor ) ; var tensorPtr = Marshal . AllocHGlobal ( Marshal . SizeOf ( typeof ( TensorRef64 ) ) ) ; Marshal . StructureToPtr ( tensorRef , tensorPtr , false ) ; tensorRefPtr = tensorPtr ; return new DelegateDisposable ( ( ) => { Marshal . FreeHGlobal ( tensorPtr ) ; NativeWrapper . FreeTensorRef ( tensorRef ) ; } ) ; }
Builds the tensor reference PTR.
Builds the tensor reference PTR .
None
tensor
NDArray
None
IntPtr
out
tensorRefPtr
The tensor reference PTR.
The tensor reference PTR .