public void SaveModel(int startIteration, int numIteration, string fileName) { Check.NonNull(fileName, nameof(fileName)); if (startIteration < 0) throw new ArgumentOutOfRangeException(nameof(startIteration)); if (numIteration < 0) throw new ArgumentOutOfRangeException(nameof(numIteration)); PInvoke.CApiFeatureImportanceType featImp = PInvoke.CApiFeatureImportanceType.Split; // not used? PInvokeException.Check(PInvoke.BoosterSaveModel(Handle, startIteration, numIteration, featImp, fileName), nameof(PInvoke.BoosterSaveModel)); }
private unsafe string GetModelJSON(int startIteration, int numIteration) { long bufLen = 2L << 15; byte[] buffer = new byte[bufLen]; long size = 0L; PInvoke.CApiFeatureImportanceType featImp = PInvoke.CApiFeatureImportanceType.Split; // not used? fixed (byte* ptr = buffer) PInvokeException.Check(PInvoke.BoosterDumpModel(Handle, startIteration, numIteration, featImp, bufLen, ref size, ptr), nameof(PInvoke.BoosterDumpModel)); // If buffer size is not enough, reallocate buffer and get again. if (size > bufLen) { bufLen = size; buffer = new byte[bufLen]; fixed (byte* ptr = buffer) PInvokeException.Check(PInvoke.BoosterDumpModel(Handle, startIteration, numIteration, featImp, bufLen, ref size, ptr), nameof(PInvoke.BoosterDumpModel)); } byte[] content = new byte[size]; Array.Copy(buffer, content, size); fixed (byte* ptr = content) return Marshal.PtrToStringAnsi((IntPtr)ptr); }
public unsafe string GetModelString() { long bufLen = 2L << 16; byte[] buffer = new byte[bufLen]; long size = 0; PInvoke.CApiFeatureImportanceType featImp = PInvoke.CApiFeatureImportanceType.Split; // not used by consumer of GetModelString? fixed (byte* ptr = buffer) PInvokeException.Check(PInvoke.BoosterSaveModelToString(Handle, -1, BestIteration, featImp, bufLen, ref size, ptr), nameof(PInvoke.BoosterSaveModelToString)); // If buffer size is not enough, reallocate buffer and get again. if (size > bufLen) { bufLen = size; buffer = new byte[bufLen]; fixed (byte* ptr = buffer) PInvokeException.Check(PInvoke.BoosterSaveModelToString(Handle, -1, BestIteration, featImp, bufLen, ref size, ptr), nameof(PInvoke.BoosterSaveModelToString)); } byte[] content = new byte[size]; Array.Copy(buffer, content, size); fixed (byte* ptr = content) return Marshal.PtrToStringAnsi((IntPtr)ptr); }