"vscode:/vscode.git/clone" did not exist on "d163c2c16629e3da41dc5d7b8dbb76b8fc6249db"
Commit 95246cda authored by Ilya Matiach's avatar Ilya Matiach Committed by Guolin Ke
Browse files

lightgbm SWIG Java wrapper changes needed to add early stopping in mmlspark (#2047)

* lightgbm SWIG Java wrapper changes needed to add early stopping in mmlspark

* updated based on comments
parent b020a25d
/* lightgbmlib.i */
%module lightgbmlib
%ignore LGBM_BoosterSaveModelToString;
%ignore LGBM_BoosterGetEvalNames;
%{
/* Includes the header in the wrapper code */
#include "../include/LightGBM/export.h"
#include "../include/LightGBM/utils/log.h"
#include "../include/LightGBM/utils/common.h"
#include "../include/LightGBM/c_api.h"
%}
......@@ -22,6 +24,26 @@
int64_t* out_len) {
char* dst = new char[buffer_len];
int result = LGBM_BoosterSaveModelToString(handle, start_iteration, num_iteration, buffer_len, out_len, dst);
// Reallocate to use larger length
if (*out_len > buffer_len) {
delete [] dst;
int64_t realloc_len = *out_len;
dst = new char[realloc_len];
result = LGBM_BoosterSaveModelToString(handle, start_iteration, num_iteration, realloc_len, out_len, dst);
}
if (result != 0) {
return nullptr;
}
return dst;
}
char ** LGBM_BoosterGetEvalNamesSWIG(BoosterHandle handle,
int eval_counts) {
char** dst = new char*[eval_counts];
for (int i = 0; i < eval_counts; ++i) {
dst[i] = new char[128];
}
int result = LGBM_BoosterGetEvalNames(handle, &eval_counts, dst);
if (result != 0) {
return nullptr;
}
......@@ -49,6 +71,7 @@
%array_functions(float, floatArray)
%array_functions(int, intArray)
%array_functions(long, longArray)
%array_functions(char *, stringArray)
/* Custom pointer manipulation template */
%define %pointer_manipulation(TYPE,NAME)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment