private protected override unsafe TransformerEstimatorSafeHandle CreateTransformerFromSavedDataHelper(byte *rawData, IntPtr dataSize) { var result = CreateTransformerFromSavedDataNative(rawData, dataSize, out IntPtr transformer, out IntPtr errorHandle); if (!result) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } var handle = new TransformerEstimatorSafeHandle(transformer, DestroyTransformerNative); // Get the result of the transform and cache it. Pass in null so we get the Mode back. result = TransformDataNative(handle, null, out IntPtr output, out IntPtr outputSize, out errorHandle); if (!result) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } using (var handler = new TransformedDataSafeHandle(output, outputSize, DestroyTransformedDataNative)) { #if NETSTANDARD2_0 byte[] buffer = new byte[outputSize.ToInt32()]; Marshal.Copy(output, buffer, 0, buffer.Length); Result = new ReadOnlyMemory <char>(Encoding.UTF8.GetString(buffer).ToArray()); #else var buffer = new ReadOnlySpan <byte>(output.ToPointer(), outputSize.ToInt32()); Result = new ReadOnlyMemory <char>(Encoding.UTF8.GetString(buffer).ToArray()); #endif } return(handle); }
private protected unsafe override bool FitHelper(TransformerEstimatorSafeHandle estimator, ReadOnlyMemory <char> input, out FitResult fitResult, out IntPtr errorHandle) { var inputAsString = input.ToString(); fixed(byte *interopInput = string.IsNullOrEmpty(inputAsString)?null : Encoding.UTF8.GetBytes(inputAsString + char.MinValue)) { return(FitNative(estimator, interopInput, out fitResult, out errorHandle)); } }
private protected override unsafe TransformerEstimatorSafeHandle CreateTransformerFromSavedDataHelper(byte *rawData, IntPtr dataSize) { var success = CreateTransformerFromSavedDataNative(rawData, dataSize, out IntPtr transformer, out IntPtr errorHandle); if (!success) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } var handle = new TransformerEstimatorSafeHandle(transformer, DestroyTransformerNative); // Get the result of the transform and cache it. Pass in double.NaN so we get the Mode back. success = TransformDataNative(handle, double.NaN, out double output, out errorHandle); if (!success) { throw new Exception(GetErrorDetailsAndFreeNativeMemory(errorHandle)); } Result = output; return(handle); }
private static extern bool CreateTransformerSaveDataNative(TransformerEstimatorSafeHandle transformer, out IntPtr buffer, out IntPtr bufferSize, out IntPtr error);
private protected override bool CompleteTrainingHelper(TransformerEstimatorSafeHandle estimator, out FitResult fitResult, out IntPtr errorHandle) => CompleteTrainingNative(estimator, out fitResult, out errorHandle);
private static extern bool CompleteTrainingNative(TransformerEstimatorSafeHandle estimator, out FitResult fitResult, out IntPtr errorHandle);
private static unsafe extern bool FitNative(TransformerEstimatorSafeHandle estimator, byte *input, out FitResult fitResult, out IntPtr errorHandle);
private protected override bool CreateTransformerFromEstimatorHelper(TransformerEstimatorSafeHandle estimator, out IntPtr transformer, out IntPtr errorHandle) => CreateTransformerFromEstimatorNative(estimator, out transformer, out errorHandle);
private static unsafe extern bool TransformDataNative(TransformerEstimatorSafeHandle transformer, byte *input, out IntPtr output, out IntPtr outputSize, out IntPtr errorHandle);
private static extern bool CreateTransformerFromEstimatorNative(TransformerEstimatorSafeHandle estimator, out IntPtr transformer, out IntPtr errorHandle);
private static unsafe extern bool TransformDataNative(TransformerEstimatorSafeHandle transformer, in double input, out double output, out IntPtr errorHandle);
internal abstract void InitializeGetter(DataViewRowCursor cursor, TransformerEstimatorSafeHandle transformerParent, string timeSeriesColumn, string[] grainColumns, string[] dataColumns, string[] allColumnNames, Dictionary <string, TypedColumn> allColumns);