/// <summary> /// This works only for allocations accessible from host memory /// </summary> /// <param name="buffer"></param> /// <param name="elements"></param> private static void PopulateNativeBufferFloat(OrtMemoryAllocation buffer, float[] elements) { if (buffer.Size < elements.Length * sizeof(float)) { Assert.True(false); } PopulateNativeBuffer(buffer.Pointer, elements); }
/// <summary> /// Return the numeric (double) based training parameter. /// </summary> /// <param name="key">Specifies the key of the value to get.</param> /// <returns>The double based value is returned.</returns> public double GetTrainingParameter(OrtTrainingNumericParameter key) { string str = null; var allocator = OrtAllocator.DefaultInstance; IntPtr valHandle = IntPtr.Zero; NativeApiStatus.VerifySuccess(NativeMethodsTraining.OrtGetNumericParameter(_nativeHandle, key, allocator.Pointer, out valHandle)); using (var ortAllocation = new OrtMemoryAllocation(allocator, valHandle, 0)) { str = NativeOnnxValueHelper.StringFromNativeUtf8(valHandle); } return(double.Parse(str)); }
/// <summary> /// Returns the OrtValue at a given index as well as its name. /// </summary> /// <param name="nIdx">Specifies the index to get.</param> /// <param name="strName">Returns the name of the OrtValue.</param> /// <returns>The OrtValue at the index is returned.</returns> public OrtValue GetAt(int nIdx, out string strName) { IntPtr valData; var allocator = OrtAllocator.DefaultInstance; IntPtr valName; NativeApiStatus.VerifySuccess(NativeMethodsTraining.OrtGetAt(_nativeHandle, nIdx, out valData, allocator.Pointer, out valName)); using (var ortAllocation = new OrtMemoryAllocation(allocator, valName, 0)) { strName = NativeOnnxValueHelper.StringFromNativeUtf8(valName); } return(new OrtValue(valData, false)); }
/// <summary> /// This works only for allocations accessible from host memory /// </summary> /// <param name="buffer"></param> /// <param name="elements"></param> private static void PopulateNativeBufferFloat(OrtMemoryAllocation buffer, float[] elements) { if (buffer.Size < elements.Length * sizeof(float)) { Assert.True(false); } unsafe { float *p = (float *)buffer.Pointer; for (int i = 0; i < elements.Length; ++i) { *p++ = elements[i]; } } }