/// <summary>
        /// Creates a <see cref="FixedBufferOnnxValue"/> object from the tensor and pins its underlying buffer.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static FixedBufferOnnxValue CreateFromTensor <T>(Tensor <T> value)
        {
            NativeOnnxValueHelper.CreateNativeOnnxValue(value, out IntPtr onnxValue, out MemoryHandle pinnedMemoryHandle, out OnnxValueType onnxValueType, out TensorElementType elementType);

            Debug.Assert(onnxValueType == OnnxValueType.ONNX_TYPE_TENSOR, "the value should always be a tensor");

            return(new FixedBufferOnnxValue(pinnedMemoryHandle, onnxValue, onnxValueType, elementType));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Pin the underlying memory and create native onnx value
 /// </summary>
 /// <param name="onnxValue"></param>
 /// <param name="pinnedMemoryHandle"></param>
 /// <param name="disposeOnnxValueAfterUse"></param>
 internal virtual void ToNativeOnnxValue(
     out IntPtr onnxValue,
     out MemoryHandle pinnedMemoryHandle,
     out bool disposeOnnxValueAfterUse)
 {
     NativeOnnxValueHelper.CreateNativeOnnxValue(_value, out onnxValue, out pinnedMemoryHandle, out OnnxValueType onnxValueType, out TensorElementType elementType);
     disposeOnnxValueAfterUse = true;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="FixedBufferOnnxValue"/> object from the tensor and pins its underlying buffer.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <returns></returns>
        public static FixedBufferOnnxValue CreateFromTensor <T>(Tensor <T> value)
        {
            if (value is Tensor <string> )
            {
                throw new ArgumentException("Only numeric tensors can be used to create FixedBufferOnnxValue.", nameof(value));
            }

            NativeOnnxValueHelper.CreateNativeOnnxValue(value, out IntPtr onnxValue, out MemoryHandle pinnedMemoryHandle, out OnnxValueType onnxValueType, out TensorElementType elementType);

            Debug.Assert(
                onnxValueType == OnnxValueType.ONNX_TYPE_TENSOR && elementType != TensorElementType.String,
                "the value should always be a numeric tensor");

            return(new FixedBufferOnnxValue(pinnedMemoryHandle, onnxValue, onnxValueType, elementType));
        }