Skip to content

Commit

Permalink
[SWIG] added typemap for string arrays in SWIG interface (#2118)
Browse files Browse the repository at this point in the history
* added typemap for string arrays in SWIG interface

* added voidp pointer casts
  • Loading branch information
imatiach-msft authored and guolinke committed Apr 29, 2019
1 parent c45ec4f commit de82ed5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions swig/lightgbmlib.i
Expand Up @@ -10,11 +10,18 @@
#include "../include/LightGBM/c_api.h"
%}

%include "various.i"
%include "carrays.i"
%include "cpointer.i"

/* Note: instead of using array_functions for string array we apply a typemap instead.
Future char** parameter names should be added to the typemap.
*/
%apply char **STRING_ARRAY { char **feature_names, char **out_strs }

/* header files */
%include "../include/LightGBM/export.h"
%include "../include/LightGBM/c_api.h"
%include "cpointer.i"
%include "carrays.i"

%typemap(in, numinputs=0) JNIEnv *jenv %{
$1 = jenv;
Expand Down Expand Up @@ -68,7 +75,7 @@
double* data0 = (double*)jenv->GetPrimitiveArrayCritical(data, 0);

int ret = LGBM_BoosterPredictForMatSingleRow(handle, data0, data_type, ncol, is_row_major, predict_type,
num_iteration, parameter, out_len, out_result);
num_iteration, parameter, out_len, out_result);

jenv->ReleasePrimitiveArrayCritical(data, data0, JNI_ABORT);

Expand Down Expand Up @@ -199,14 +206,21 @@
%pointer_cast(int32_t *, int *, int32_t_to_int_ptr)
%pointer_cast(long *, int64_t *, long_to_int64_t_ptr)
%pointer_cast(double *, int64_t *, double_to_int64_t_ptr)
%pointer_cast(double *, void *, double_to_voidp_ptr)
%pointer_cast(int *, int32_t *, int_to_int32_t_ptr)

%pointer_cast(double *, void *, double_to_voidp_ptr)
%pointer_cast(float *, void *, float_to_voidp_ptr)
%pointer_cast(int *, void *, int_to_voidp_ptr)
%pointer_cast(int32_t *, void *, int32_t_to_voidp_ptr)
%pointer_cast(int64_t *, void *, int64_t_to_voidp_ptr)

%array_functions(double, doubleArray)
%array_functions(float, floatArray)
%array_functions(int, intArray)
%array_functions(long, longArray)
/* Note: there is a bug in the SWIG generated string arrays when creating
a new array with strings where the strings are prematurely deallocated
*/
%array_functions(char *, stringArray)

/* Custom pointer manipulation template */
Expand Down Expand Up @@ -256,4 +270,3 @@ TYPE *NAME##_handle();

/* Allow retrieving handle to void** */
%pointer_handle(void*, voidpp)

0 comments on commit de82ed5

Please sign in to comment.