Merge pull request #713 from yanqingmen/java_wrapper
java wrapper modification
This commit is contained in:
commit
ee8f189bba
13
Makefile
13
Makefile
@ -5,7 +5,7 @@ export MPICXX = mpicxx
|
|||||||
export LDFLAGS= -pthread -lm
|
export LDFLAGS= -pthread -lm
|
||||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops
|
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops
|
||||||
# java include path
|
# java include path
|
||||||
export JAVAINCFLAGS = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux -I./java
|
export JAVAINCFLAGS = -I${JAVA_HOME}/include -I./java
|
||||||
|
|
||||||
ifeq ($(OS), Windows_NT)
|
ifeq ($(OS), Windows_NT)
|
||||||
export CXX = g++ -m64
|
export CXX = g++ -m64
|
||||||
@ -16,6 +16,11 @@ UNAME= $(shell uname)
|
|||||||
|
|
||||||
ifeq ($(UNAME), Linux)
|
ifeq ($(UNAME), Linux)
|
||||||
LDFLAGS += -lrt
|
LDFLAGS += -lrt
|
||||||
|
JAVAINCFLAGS += -I${JAVA_HOME}/include/linux
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(UNAME), Darwin)
|
||||||
|
JAVAINCFLAGS += -I${JAVA_HOME}/include/darwin
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(no_omp),1)
|
ifeq ($(no_omp),1)
|
||||||
@ -71,7 +76,7 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# java lib
|
# java lib
|
||||||
JLIB = java/libxgboostjavawrapper.so
|
JLIB = java/libxgboost4j.so
|
||||||
|
|
||||||
# specify tensor path
|
# specify tensor path
|
||||||
BIN = xgboost
|
BIN = xgboost
|
||||||
@ -103,8 +108,8 @@ main.o: src/xgboost_main.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner
|
|||||||
xgboost: updater.o gbm.o io.o main.o $(LIBRABIT) $(LIBDMLC)
|
xgboost: updater.o gbm.o io.o main.o $(LIBRABIT) $(LIBDMLC)
|
||||||
wrapper/xgboost_wrapper.dll wrapper/libxgboostwrapper.so: wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o $(LIBRABIT) $(LIBDMLC)
|
wrapper/xgboost_wrapper.dll wrapper/libxgboostwrapper.so: wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o $(LIBRABIT) $(LIBDMLC)
|
||||||
|
|
||||||
java: java/libxgboostjavawrapper.so
|
java: java/libxgboost4j.so
|
||||||
java/libxgboostjavawrapper.so: java/xgboost4j_wrapper.cpp wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o $(LIBRABIT) $(LIBDMLC)
|
java/libxgboost4j.so: java/xgboost4j_wrapper.cpp wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o $(LIBRABIT) $(LIBDMLC)
|
||||||
|
|
||||||
# dependency on rabit
|
# dependency on rabit
|
||||||
subtree/rabit/lib/librabit.a: subtree/rabit/src/engine.cc
|
subtree/rabit/lib/librabit.a: subtree/rabit/src/engine.cc
|
||||||
|
|||||||
@ -17,12 +17,17 @@ core of this wrapper is two classes:
|
|||||||
|
|
||||||
## build native library
|
## build native library
|
||||||
|
|
||||||
for windows: open the xgboost.sln in "../windows" folder, you will found the xgboostjavawrapper project, you should do the following steps to build wrapper library:
|
for windows: open the xgboost.sln in "../windows" folder, you will found the xgboost4j project, you should do the following steps to build wrapper library:
|
||||||
* Select x64/win32 and Release in build
|
* Select x64/win32 and Release in build
|
||||||
* (if you have setted `JAVA_HOME` properly in windows environment variables, escape this step) right click on xgboostjavawrapper project -> choose "Properties" -> click on "C/C++" in the window -> change the "Additional Include Directories" to fit your jdk install path.
|
* (if you have setted `JAVA_HOME` properly in windows environment variables, escape this step) right click on xgboost4j project -> choose "Properties" -> click on "C/C++" in the window -> change the "Additional Include Directories" to fit your jdk install path.
|
||||||
* rebuild all
|
* rebuild all
|
||||||
* double click "create_wrap.bat" to set library to proper place
|
* double click "create_wrap.bat" to set library to proper place
|
||||||
|
|
||||||
for linux:
|
for linux:
|
||||||
* make sure you have installed jdk and `JAVA_HOME` has been setted properly
|
* make sure you have installed jdk and `JAVA_HOME` has been setted properly
|
||||||
* run "create_wrap.sh"
|
* run "create_wrap.sh"
|
||||||
|
|
||||||
|
for osx:
|
||||||
|
* make sure you have installed jdk
|
||||||
|
* for single thread xgboost, simply run "create_wrap.sh"
|
||||||
|
* for build with openMP, please refer to [build.md](../doc/build.md) to get openmp supported compiler first, and change the line "dis_omp=1" to "dis_omp=0" in "create_wrap.sh", then run "create_wrap.sh"
|
||||||
@ -1,12 +1,12 @@
|
|||||||
echo "move native library"
|
echo "move native library"
|
||||||
set libsource=..\windows\x64\Release\xgboostjavawrapper.dll
|
set libsource=..\windows\x64\Release\xgboost4j.dll
|
||||||
|
|
||||||
if not exist %libsource% (
|
if not exist %libsource% (
|
||||||
goto end
|
goto end
|
||||||
)
|
)
|
||||||
|
|
||||||
set libfolder=xgboost4j\src\main\resources\lib
|
set libfolder=xgboost4j\src\main\resources\lib
|
||||||
set libpath=%libfolder%\xgboostjavawrapper.dll
|
set libpath=%libfolder%\xgboost4j.dll
|
||||||
if not exist %libfolder% (mkdir %libfolder%)
|
if not exist %libfolder% (mkdir %libfolder%)
|
||||||
if exist %libpath% (del %libpath%)
|
if exist %libpath% (del %libpath%)
|
||||||
move %libsource% %libfolder%
|
move %libsource% %libfolder%
|
||||||
|
|||||||
@ -1,12 +1,22 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
echo "build java wrapper"
|
echo "build java wrapper"
|
||||||
|
|
||||||
# cd to script's directory
|
# cd to script's directory
|
||||||
pushd `dirname $0` > /dev/null
|
pushd `dirname $0` > /dev/null
|
||||||
|
|
||||||
|
#settings according to os
|
||||||
|
dl="so"
|
||||||
|
dis_omp=0
|
||||||
|
|
||||||
|
if [ $(uname) == "Darwin" ]; then
|
||||||
|
export JAVA_HOME=$(/usr/libexec/java_home)
|
||||||
|
dl="dylib"
|
||||||
|
#change this to 0 if your compiler support openmp
|
||||||
|
dis_omp=1
|
||||||
|
fi
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
make java
|
make java no_omp=${dis_omp}
|
||||||
cd java
|
cd java
|
||||||
echo "move native lib"
|
echo "move native lib"
|
||||||
|
|
||||||
@ -15,8 +25,8 @@ if [ ! -d "$libPath" ]; then
|
|||||||
mkdir -p "$libPath"
|
mkdir -p "$libPath"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f xgboost4j/src/main/resources/lib/libxgboostjavawrapper.so
|
rm -f xgboost4j/src/main/resources/lib/libxgboost4j.${dl}
|
||||||
mv libxgboostjavawrapper.so xgboost4j/src/main/resources/lib/
|
mv libxgboost4j.so xgboost4j/src/main/resources/lib/libxgboost4j.${dl}
|
||||||
|
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
echo "complete"
|
echo "complete"
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
# xgboost4j
|
|
||||||
this is a java wrapper for xgboost (https://github.com/dmlc/xgboost)
|
|
||||||
the structure of this wrapper is almost the same as the official python wrapper.
|
|
||||||
core of this wrapper is two classes:
|
|
||||||
|
|
||||||
* DMatrix: for handling data
|
|
||||||
|
|
||||||
* Booster: for train and predict
|
|
||||||
|
|
||||||
## usage:
|
|
||||||
|
|
||||||
simple examples could be found in test package:
|
|
||||||
|
|
||||||
* Simple Train Example: org.dmlc.xgboost4j.TrainExample.java
|
|
||||||
|
|
||||||
* Simple Predict Example: org.dmlc.xgboost4j.PredictExample.java
|
|
||||||
|
|
||||||
* Cross Validation Example: org.dmlc.xgboost4j.example.CVExample.java
|
|
||||||
|
|
||||||
## native library:
|
|
||||||
|
|
||||||
only 64-bit linux/windows is supported now, if you want to build native wrapper library yourself, please refer to
|
|
||||||
https://github.com/yanqingmen/xgboost-java, and put your native library to the "./src/main/resources/lib" folder and replace the originals. (either "libxgboostjavawrapper.so" for linux or "xgboostjavawrapper.dll" for windows)
|
|
||||||
@ -233,7 +233,7 @@ public final class Booster {
|
|||||||
* @param predLeaf
|
* @param predLeaf
|
||||||
* @return predict results
|
* @return predict results
|
||||||
*/
|
*/
|
||||||
private synchronized float[][] pred(DMatrix data, boolean outPutMargin, long treeLimit, boolean predLeaf) throws XGBoostError {
|
private synchronized float[][] pred(DMatrix data, boolean outPutMargin, int treeLimit, boolean predLeaf) throws XGBoostError {
|
||||||
int optionMask = 0;
|
int optionMask = 0;
|
||||||
if(outPutMargin) {
|
if(outPutMargin) {
|
||||||
optionMask = 1;
|
optionMask = 1;
|
||||||
@ -284,7 +284,7 @@ public final class Booster {
|
|||||||
* @return predict result
|
* @return predict result
|
||||||
* @throws org.dmlc.xgboost4j.util.XGBoostError
|
* @throws org.dmlc.xgboost4j.util.XGBoostError
|
||||||
*/
|
*/
|
||||||
public float[][] predict(DMatrix data, boolean outPutMargin, long treeLimit) throws XGBoostError {
|
public float[][] predict(DMatrix data, boolean outPutMargin, int treeLimit) throws XGBoostError {
|
||||||
return pred(data, outPutMargin, treeLimit, false);
|
return pred(data, outPutMargin, treeLimit, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ public final class Booster {
|
|||||||
* @return predict result
|
* @return predict result
|
||||||
* @throws org.dmlc.xgboost4j.util.XGBoostError
|
* @throws org.dmlc.xgboost4j.util.XGBoostError
|
||||||
*/
|
*/
|
||||||
public float[][] predict(DMatrix data , long treeLimit, boolean predLeaf) throws XGBoostError {
|
public float[][] predict(DMatrix data , int treeLimit, boolean predLeaf) throws XGBoostError {
|
||||||
return pred(data, false, treeLimit, predLeaf);
|
return pred(data, false, treeLimit, predLeaf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class Initializer {
|
|||||||
static boolean initialized = false;
|
static boolean initialized = false;
|
||||||
public static final String nativePath = "./lib";
|
public static final String nativePath = "./lib";
|
||||||
public static final String nativeResourcePath = "/lib/";
|
public static final String nativeResourcePath = "/lib/";
|
||||||
public static final String[] libNames = new String[] {"xgboostjavawrapper"};
|
public static final String[] libNames = new String[] {"xgboost4j"};
|
||||||
|
|
||||||
public static synchronized void InitXgboost() throws IOException {
|
public static synchronized void InitXgboost() throws IOException {
|
||||||
if(initialized == false) {
|
if(initialized == false) {
|
||||||
|
|||||||
@ -41,10 +41,10 @@ public class XgboostJNI {
|
|||||||
public final static native int XGBoosterUpdateOneIter(long handle, int iter, long dtrain);
|
public final static native int XGBoosterUpdateOneIter(long handle, int iter, long dtrain);
|
||||||
public final static native int XGBoosterBoostOneIter(long handle, long dtrain, float[] grad, float[] hess);
|
public final static native int XGBoosterBoostOneIter(long handle, long dtrain, float[] grad, float[] hess);
|
||||||
public final static native int XGBoosterEvalOneIter(long handle, int iter, long[] dmats, String[] evnames, String[] eval_info);
|
public final static native int XGBoosterEvalOneIter(long handle, int iter, long[] dmats, String[] evnames, String[] eval_info);
|
||||||
public final static native int XGBoosterPredict(long handle, long dmat, int option_mask, long ntree_limit, float[][] predicts);
|
public final static native int XGBoosterPredict(long handle, long dmat, int option_mask, int ntree_limit, float[][] predicts);
|
||||||
public final static native int XGBoosterLoadModel(long handle, String fname);
|
public final static native int XGBoosterLoadModel(long handle, String fname);
|
||||||
public final static native int XGBoosterSaveModel(long handle, String fname);
|
public final static native int XGBoosterSaveModel(long handle, String fname);
|
||||||
public final static native int XGBoosterLoadModelFromBuffer(long handle, long buf, long len);
|
public final static native int XGBoosterLoadModelFromBuffer(long handle, long buf, long len);
|
||||||
public final static native int XGBoosterGetModelRaw(long handle, String[] out_string);
|
public final static native int XGBoosterGetModelRaw(long handle, String[] out_string);
|
||||||
public final static native int XGBoosterDumpModel(long handle, String fmap, int with_stats, String[][] out_strings);
|
public final static native int XGBoosterDumpModel(long handle, String fmap, int with_stats, String[][] out_strings);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -104,5 +104,39 @@ public class BoosterTest {
|
|||||||
IEvaluation eval = new EvalError();
|
IEvaluation eval = new EvalError();
|
||||||
//error must be less than 0.1
|
//error must be less than 0.1
|
||||||
TestCase.assertTrue(eval.eval(predicts, testMat)<0.1f);
|
TestCase.assertTrue(eval.eval(predicts, testMat)<0.1f);
|
||||||
|
|
||||||
|
//test dump model
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test cross valiation
|
||||||
|
* @throws XGBoostError
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCV() throws XGBoostError {
|
||||||
|
//load train mat
|
||||||
|
DMatrix trainMat = new DMatrix("../../demo/data/agaricus.txt.train");
|
||||||
|
|
||||||
|
//set params
|
||||||
|
Map<String, Object> param= new HashMap<String, Object>() {
|
||||||
|
{
|
||||||
|
put("eta", 1.0);
|
||||||
|
put("max_depth", 3);
|
||||||
|
put("silent", 1);
|
||||||
|
put("nthread", 6);
|
||||||
|
put("objective", "binary:logistic");
|
||||||
|
put("gamma", 1.0);
|
||||||
|
put("eval_metric", "error");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//do 5-fold cross validation
|
||||||
|
int round = 2;
|
||||||
|
int nfold = 5;
|
||||||
|
//set additional eval_metrics
|
||||||
|
String[] metrics = null;
|
||||||
|
|
||||||
|
String[] evalHist = Trainer.crossValiation(param.entrySet(), trainMat, round, nfold, metrics, null, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,39 +12,34 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <jni.h>
|
|
||||||
#include "../wrapper/xgboost_wrapper.h"
|
#include "../wrapper/xgboost_wrapper.h"
|
||||||
#include "xgboost4j_wrapper.h"
|
#include "xgboost4j_wrapper.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
//helper functions
|
||||||
|
//set handle
|
||||||
|
void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
|
||||||
|
long out[1];
|
||||||
|
out[0] = (long) handle;
|
||||||
|
jenv->SetLongArrayRegion(jhandle, 0, 1, (const jlong*) out);
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBGetLastError
|
JNIEXPORT jstring JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBGetLastError
|
||||||
(JNIEnv *jenv, jclass jcls) {
|
(JNIEnv *jenv, jclass jcls) {
|
||||||
jstring jresult = 0 ;
|
jstring jresult = 0 ;
|
||||||
char* result = 0;
|
const char* result = XGBGetLastError();
|
||||||
result = (char *)XGBGetLastError();
|
if (result) jresult = jenv->NewStringUTF(result);
|
||||||
if (result) jresult = jenv->NewStringUTF((const char *)result);
|
|
||||||
return jresult;
|
return jresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromFile
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromFile
|
||||||
(JNIEnv *jenv, jclass jcls, jstring jfname, jint jsilent, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jstring jfname, jint jsilent, jlongArray jout) {
|
||||||
jint jresult = 0 ;
|
DMatrixHandle result;
|
||||||
char *fname = (char *) 0 ;
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
||||||
int silent;
|
int ret = XGDMatrixCreateFromFile(fname, jsilent, &result);
|
||||||
void* result[1];
|
if (fname) jenv->ReleaseStringUTFChars(jfname, fname);
|
||||||
unsigned long out[1];
|
setHandle(jenv, jout, result);
|
||||||
|
return ret;
|
||||||
fname = (char *)jenv->GetStringUTFChars(jfname, 0);
|
|
||||||
|
|
||||||
silent = (int)jsilent;
|
|
||||||
jresult = (jint) XGDMatrixCreateFromFile((char const *)fname, silent, result);
|
|
||||||
|
|
||||||
|
|
||||||
*(void **)&out[0] = *result;
|
|
||||||
|
|
||||||
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
|
||||||
|
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -54,28 +49,19 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromCSR
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromCSR
|
||||||
(JNIEnv *jenv, jclass jcls, jlongArray jindptr, jintArray jindices, jfloatArray jdata, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlongArray jindptr, jintArray jindices, jfloatArray jdata, jlongArray jout) {
|
||||||
jint jresult = 0 ;
|
DMatrixHandle result;
|
||||||
bst_ulong nindptr ;
|
|
||||||
bst_ulong nelem;
|
|
||||||
void *result[1];
|
|
||||||
unsigned long out[1];
|
|
||||||
|
|
||||||
jlong* indptr = jenv->GetLongArrayElements(jindptr, 0);
|
jlong* indptr = jenv->GetLongArrayElements(jindptr, 0);
|
||||||
jint* indices = jenv->GetIntArrayElements(jindices, 0);
|
jint* indices = jenv->GetIntArrayElements(jindices, 0);
|
||||||
jfloat* data = jenv->GetFloatArrayElements(jdata, 0);
|
jfloat* data = jenv->GetFloatArrayElements(jdata, 0);
|
||||||
nindptr = (bst_ulong)jenv->GetArrayLength(jindptr);
|
bst_ulong nindptr = (bst_ulong)jenv->GetArrayLength(jindptr);
|
||||||
nelem = (bst_ulong)jenv->GetArrayLength(jdata);
|
bst_ulong nelem = (bst_ulong)jenv->GetArrayLength(jdata);
|
||||||
|
int ret = (jint) XGDMatrixCreateFromCSR((unsigned long const *)indptr, (unsigned int const *)indices, (float const *)data, nindptr, nelem, &result);
|
||||||
jresult = (jint) XGDMatrixCreateFromCSR((unsigned long const *)indptr, (unsigned int const *)indices, (float const *)data, nindptr, nelem, result);
|
setHandle(jenv, jout, result);
|
||||||
*(void **)&out[0] = *result;
|
//Release
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
|
|
||||||
//release
|
|
||||||
jenv->ReleaseLongArrayElements(jindptr, indptr, 0);
|
jenv->ReleaseLongArrayElements(jindptr, indptr, 0);
|
||||||
jenv->ReleaseIntArrayElements(jindices, indices, 0);
|
jenv->ReleaseIntArrayElements(jindices, indices, 0);
|
||||||
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -85,28 +71,21 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromCSC
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromCSC
|
||||||
(JNIEnv *jenv, jclass jcls, jlongArray jindptr, jintArray jindices, jfloatArray jdata, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlongArray jindptr, jintArray jindices, jfloatArray jdata, jlongArray jout) {
|
||||||
jint jresult = 0;
|
DMatrixHandle result;
|
||||||
bst_ulong nindptr ;
|
|
||||||
bst_ulong nelem;
|
|
||||||
void *result[1];
|
|
||||||
unsigned long out[1];
|
|
||||||
|
|
||||||
jlong* indptr = jenv->GetLongArrayElements(jindptr, NULL);
|
jlong* indptr = jenv->GetLongArrayElements(jindptr, NULL);
|
||||||
jint* indices = jenv->GetIntArrayElements(jindices, 0);
|
jint* indices = jenv->GetIntArrayElements(jindices, 0);
|
||||||
jfloat* data = jenv->GetFloatArrayElements(jdata, NULL);
|
jfloat* data = jenv->GetFloatArrayElements(jdata, NULL);
|
||||||
nindptr = (bst_ulong)jenv->GetArrayLength(jindptr);
|
bst_ulong nindptr = (bst_ulong)jenv->GetArrayLength(jindptr);
|
||||||
nelem = (bst_ulong)jenv->GetArrayLength(jdata);
|
bst_ulong nelem = (bst_ulong)jenv->GetArrayLength(jdata);
|
||||||
|
|
||||||
jresult = (jint) XGDMatrixCreateFromCSC((unsigned long const *)indptr, (unsigned int const *)indices, (float const *)data, nindptr, nelem, result);
|
int ret = (jint) XGDMatrixCreateFromCSC((unsigned long const *)indptr, (unsigned int const *)indices, (float const *)data, nindptr, nelem, &result);
|
||||||
*(void **)&out[0] = *result;
|
setHandle(jenv, jout, result);
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
|
|
||||||
//release
|
//release
|
||||||
jenv->ReleaseLongArrayElements(jindptr, indptr, 0);
|
jenv->ReleaseLongArrayElements(jindptr, indptr, 0);
|
||||||
jenv->ReleaseIntArrayElements(jindices, indices, 0);
|
jenv->ReleaseIntArrayElements(jindices, indices, 0);
|
||||||
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
||||||
|
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,27 +95,15 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromMat
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreateFromMat
|
||||||
(JNIEnv *jenv, jclass jcls, jfloatArray jdata, jint jnrow, jint jncol, jfloat jmiss, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jfloatArray jdata, jint jnrow, jint jncol, jfloat jmiss, jlongArray jout) {
|
||||||
jint jresult = 0 ;
|
DMatrixHandle result;
|
||||||
bst_ulong nrow ;
|
|
||||||
bst_ulong ncol ;
|
|
||||||
float miss ;
|
|
||||||
void *result[1];
|
|
||||||
unsigned long out[1];
|
|
||||||
|
|
||||||
|
|
||||||
jfloat* data = jenv->GetFloatArrayElements(jdata, 0);
|
jfloat* data = jenv->GetFloatArrayElements(jdata, 0);
|
||||||
nrow = (bst_ulong)jnrow;
|
bst_ulong nrow = (bst_ulong)jnrow;
|
||||||
ncol = (bst_ulong)jncol;
|
bst_ulong ncol = (bst_ulong)jncol;
|
||||||
miss = (float)jmiss;
|
int ret = (jint) XGDMatrixCreateFromMat((float const *)data, nrow, ncol, jmiss, &result);
|
||||||
|
setHandle(jenv, jout, result);
|
||||||
jresult = (jint) XGDMatrixCreateFromMat((float const *)data, nrow, ncol, miss, result);
|
|
||||||
*(void **)&out[0] = *result;
|
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
|
|
||||||
//release
|
//release
|
||||||
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
jenv->ReleaseFloatArrayElements(jdata, data, 0);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -146,24 +113,18 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixCreat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSliceDMatrix
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSliceDMatrix
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jintArray jindexset, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jintArray jindexset, jlongArray jout) {
|
||||||
jint jresult = 0 ;
|
DMatrixHandle result;
|
||||||
void *handle = (void *) 0 ;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
bst_ulong len;
|
|
||||||
void *result[1];
|
|
||||||
unsigned long out[1];
|
|
||||||
|
|
||||||
jint* indexset = jenv->GetIntArrayElements(jindexset, 0);
|
jint* indexset = jenv->GetIntArrayElements(jindexset, 0);
|
||||||
handle = *(void **)&jhandle;
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jindexset);
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jindexset);
|
|
||||||
|
|
||||||
jresult = (jint) XGDMatrixSliceDMatrix(handle, (int const *)indexset, len, result);
|
int ret = XGDMatrixSliceDMatrix(handle, (int const *)indexset, len, &result);
|
||||||
*(void **)&out[0] = *result;
|
setHandle(jenv, jout, result);
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
|
|
||||||
//release
|
//release
|
||||||
jenv->ReleaseIntArrayElements(jindexset, indexset, 0);
|
jenv->ReleaseIntArrayElements(jindexset, indexset, 0);
|
||||||
|
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -172,12 +133,10 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSlice
|
|||||||
* Signature: (J)V
|
* Signature: (J)V
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixFree
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixFree
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
int ret = XGDMatrixFree(handle);
|
||||||
handle = *(void **)&jhandle;
|
return ret;
|
||||||
jresult = (jint) XGDMatrixFree(handle);
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -187,19 +146,11 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixFree
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSaveBinary
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSaveBinary
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname, jint jsilent) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname, jint jsilent) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
||||||
char *fname = (char *) 0 ;
|
int ret = XGDMatrixSaveBinary(handle, fname, jsilent);
|
||||||
int silent ;
|
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
||||||
handle = *(void **)&jhandle;
|
return ret;
|
||||||
fname = 0;
|
|
||||||
fname = (char *)jenv->GetStringUTFChars(jfname, 0);
|
|
||||||
|
|
||||||
silent = (int)jsilent;
|
|
||||||
jresult = (jint) XGDMatrixSaveBinary(handle, (char const *)fname, silent);
|
|
||||||
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
|
||||||
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -209,26 +160,16 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSaveB
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetFloatInfo
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetFloatInfo
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jfloatArray jarray) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jfloatArray jarray) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
||||||
char *field = (char *) 0 ;
|
|
||||||
bst_ulong len;
|
|
||||||
|
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
|
|
||||||
field = (char *)jenv->GetStringUTFChars(jfield, 0);
|
|
||||||
|
|
||||||
|
|
||||||
jfloat* array = jenv->GetFloatArrayElements(jarray, NULL);
|
jfloat* array = jenv->GetFloatArrayElements(jarray, NULL);
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jarray);
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jarray);
|
||||||
jresult = (jint) XGDMatrixSetFloatInfo(handle, (char const *)field, (float const *)array, len);
|
int ret = XGDMatrixSetFloatInfo(handle, field, (float const *)array, len);
|
||||||
|
|
||||||
//release
|
//release
|
||||||
if (field) jenv->ReleaseStringUTFChars(jfield, (const char *)field);
|
if (field) jenv->ReleaseStringUTFChars(jfield, field);
|
||||||
jenv->ReleaseFloatArrayElements(jarray, array, 0);
|
jenv->ReleaseFloatArrayElements(jarray, array, 0);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -238,24 +179,16 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetFl
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetUIntInfo
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetUIntInfo
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jintArray jarray) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jintArray jarray) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
||||||
char *field = (char *) 0 ;
|
|
||||||
bst_ulong len ;
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
field = 0;
|
|
||||||
field = (char *)jenv->GetStringUTFChars(jfield, 0);
|
|
||||||
|
|
||||||
|
|
||||||
jint* array = jenv->GetIntArrayElements(jarray, NULL);
|
jint* array = jenv->GetIntArrayElements(jarray, NULL);
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jarray);
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jarray);
|
||||||
|
int ret = XGDMatrixSetUIntInfo(handle, (char const *)field, (unsigned int const *)array, len);
|
||||||
jresult = (jint) XGDMatrixSetUIntInfo(handle, (char const *)field, (unsigned int const *)array, len);
|
|
||||||
//release
|
//release
|
||||||
if (field) jenv->ReleaseStringUTFChars(jfield, (const char *)field);
|
if (field) jenv->ReleaseStringUTFChars(jfield, (const char *)field);
|
||||||
jenv->ReleaseIntArrayElements(jarray, array, 0);
|
jenv->ReleaseIntArrayElements(jarray, array, 0);
|
||||||
|
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -265,20 +198,13 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetUI
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetGroup
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetGroup
|
||||||
(JNIEnv * jenv, jclass jcls, jlong jhandle, jintArray jarray) {
|
(JNIEnv * jenv, jclass jcls, jlong jhandle, jintArray jarray) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
|
||||||
bst_ulong len ;
|
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
jint* array = jenv->GetIntArrayElements(jarray, NULL);
|
jint* array = jenv->GetIntArrayElements(jarray, NULL);
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jarray);
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jarray);
|
||||||
|
int ret = XGDMatrixSetGroup(handle, (unsigned int const *)array, len);
|
||||||
jresult = (jint) XGDMatrixSetGroup(handle, (unsigned int const *)array, len);
|
|
||||||
|
|
||||||
//release
|
//release
|
||||||
jenv->ReleaseIntArrayElements(jarray, array, 0);
|
jenv->ReleaseIntArrayElements(jarray, array, 0);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -288,30 +214,19 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixSetGr
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetFloatInfo
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetFloatInfo
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jobjectArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jobjectArray jout) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
||||||
char *field = (char *) 0 ;
|
bst_ulong len;
|
||||||
bst_ulong len[1];
|
float *result;
|
||||||
*len = 0;
|
int ret = XGDMatrixGetFloatInfo(handle, field, &len, (const float**) &result);
|
||||||
float *result[1];
|
if (field) jenv->ReleaseStringUTFChars(jfield, field);
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
field = 0;
|
|
||||||
if (jfield) {
|
|
||||||
field = (char *)jenv->GetStringUTFChars(jfield, 0);
|
|
||||||
if (!field) return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
jresult = (jint) XGDMatrixGetFloatInfo(handle, (char const *)field, len, (const float **) result);
|
|
||||||
|
|
||||||
if (field) jenv->ReleaseStringUTFChars(jfield, (const char *)field);
|
|
||||||
|
|
||||||
jsize jlen = (jsize)*len;
|
jsize jlen = (jsize) len;
|
||||||
jfloatArray jarray = jenv->NewFloatArray(jlen);
|
jfloatArray jarray = jenv->NewFloatArray(jlen);
|
||||||
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) *result);
|
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) result);
|
||||||
jenv->SetObjectArrayElement(jout, 0, (jobject) jarray);
|
jenv->SetObjectArrayElement(jout, 0, (jobject) jarray);
|
||||||
|
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -321,25 +236,18 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetFl
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetUIntInfo
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetUIntInfo
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jobjectArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfield, jobjectArray jout) {
|
||||||
jint jresult = 0;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
||||||
char *field = (char *) 0 ;
|
bst_ulong len;
|
||||||
bst_ulong len[1];
|
unsigned int *result;
|
||||||
*len = 0;
|
int ret = (jint) XGDMatrixGetUIntInfo(handle, field, &len, (const unsigned int **) &result);
|
||||||
unsigned int *result[1];
|
if (field) jenv->ReleaseStringUTFChars(jfield, field);
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
field = (char *)jenv->GetStringUTFChars(jfield, 0);
|
|
||||||
|
|
||||||
jresult = (jint) XGDMatrixGetUIntInfo(handle, (char const *)field, len, (const unsigned int **) result);
|
|
||||||
|
|
||||||
if (field) jenv->ReleaseStringUTFChars(jfield, (const char *)field);
|
|
||||||
|
|
||||||
jsize jlen = (jsize)*len;
|
jsize jlen = (jsize) len;
|
||||||
jintArray jarray = jenv->NewIntArray(jlen);
|
jintArray jarray = jenv->NewIntArray(jlen);
|
||||||
jenv->SetIntArrayRegion(jarray, 0, jlen, (jint *) *result);
|
jenv->SetIntArrayRegion(jarray, 0, jlen, (jint *) result);
|
||||||
jenv->SetObjectArrayElement(jout, 0, jarray);
|
jenv->SetObjectArrayElement(jout, 0, jarray);
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -349,13 +257,11 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixGetUI
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixNumRow
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixNumRow
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlongArray jout) {
|
||||||
jint jresult = 0 ;
|
DMatrixHandle handle = (DMatrixHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
|
||||||
bst_ulong result[1];
|
bst_ulong result[1];
|
||||||
handle = *(void **)&jhandle;
|
int ret = (jint) XGDMatrixNumRow(handle, result);
|
||||||
jresult = (jint) XGDMatrixNumRow(handle, result);
|
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) result);
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) result);
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -365,35 +271,30 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGDMatrixNumRo
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterCreate
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterCreate
|
||||||
(JNIEnv *jenv, jclass jcls, jlongArray jhandles, jlongArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlongArray jhandles, jlongArray jout) {
|
||||||
jint jresult = 0;
|
DMatrixHandle* handles;
|
||||||
void **handles = 0;
|
|
||||||
bst_ulong len = 0;
|
bst_ulong len = 0;
|
||||||
void *result[1];
|
|
||||||
jlong* cjhandles = 0;
|
jlong* cjhandles = 0;
|
||||||
unsigned long out[1];
|
BoosterHandle result;
|
||||||
|
|
||||||
if(jhandles) {
|
if(jhandles) {
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jhandles);
|
len = (bst_ulong)jenv->GetArrayLength(jhandles);
|
||||||
handles = new void*[len];
|
handles = new DMatrixHandle[len];
|
||||||
//put handle from jhandles to chandles
|
//put handle from jhandles to chandles
|
||||||
cjhandles = jenv->GetLongArrayElements(jhandles, 0);
|
cjhandles = jenv->GetLongArrayElements(jhandles, 0);
|
||||||
for(bst_ulong i=0; i<len; i++) {
|
for(bst_ulong i=0; i<len; i++) {
|
||||||
handles[i] = *(void **)&cjhandles[i];
|
handles[i] = (DMatrixHandle) cjhandles[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jresult = (jint) XGBoosterCreate(handles, len, result);
|
int ret = XGBoosterCreate(handles, len, &result);
|
||||||
|
|
||||||
//release
|
//release
|
||||||
if(jhandles) {
|
if(jhandles) {
|
||||||
delete[] handles;
|
delete[] handles;
|
||||||
jenv->ReleaseLongArrayElements(jhandles, cjhandles, 0);
|
jenv->ReleaseLongArrayElements(jhandles, cjhandles, 0);
|
||||||
}
|
}
|
||||||
|
setHandle(jenv, jout, result);
|
||||||
|
|
||||||
*(void **)&out[0] = *result;
|
return ret;
|
||||||
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
||||||
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -403,9 +304,8 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterCreat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterFree
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterFree
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle) {
|
||||||
void *handle = (void *) 0 ;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
handle = *(void **)&jhandle;
|
return XGBoosterFree(handle);
|
||||||
return (jint) XGBoosterFree(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -416,20 +316,14 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterFree
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSetParam
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSetParam
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jname, jstring jvalue) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jname, jstring jvalue) {
|
||||||
jint jresult = -1;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* name = jenv->GetStringUTFChars(jname, 0);
|
||||||
char *name = (char *) 0 ;
|
const char* value = jenv->GetStringUTFChars(jvalue, 0);
|
||||||
char *value = (char *) 0 ;
|
int ret = XGBoosterSetParam(handle, name, value);
|
||||||
handle = *(void **)&jhandle;
|
//release
|
||||||
|
if (name) jenv->ReleaseStringUTFChars(jname, name);
|
||||||
name = (char *)jenv->GetStringUTFChars(jname, 0);
|
if (value) jenv->ReleaseStringUTFChars(jvalue, value);
|
||||||
value = (char *)jenv->GetStringUTFChars(jvalue, 0);
|
return ret;
|
||||||
|
|
||||||
jresult = (jint) XGBoosterSetParam(handle, (char const *)name, (char const *)value);
|
|
||||||
if (name) jenv->ReleaseStringUTFChars(jname, (const char *)name);
|
|
||||||
if (value) jenv->ReleaseStringUTFChars(jvalue, (const char *)value);
|
|
||||||
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -439,13 +333,9 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSetPa
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterUpdateOneIter
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterUpdateOneIter
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jint jiter, jlong jdtrain) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jint jiter, jlong jdtrain) {
|
||||||
void *handle = (void *) 0 ;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
int iter ;
|
DMatrixHandle dtrain = (DMatrixHandle) jdtrain;
|
||||||
void *dtrain = (void *) 0 ;
|
return XGBoosterUpdateOneIter(handle, jiter, dtrain);
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
iter = (int)jiter;
|
|
||||||
dtrain = *(void **)&jdtrain;
|
|
||||||
return (jint) XGBoosterUpdateOneIter(handle, iter, dtrain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -455,23 +345,16 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterUpdat
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterBoostOneIter
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterBoostOneIter
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jdtrain, jfloatArray jgrad, jfloatArray jhess) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jdtrain, jfloatArray jgrad, jfloatArray jhess) {
|
||||||
jint jresult = 0;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
DMatrixHandle dtrain = (DMatrixHandle) jdtrain;
|
||||||
void *dtrain = (void *) 0 ;
|
|
||||||
bst_ulong len ;
|
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
dtrain = *(void **)&jdtrain;
|
|
||||||
jfloat* grad = jenv->GetFloatArrayElements(jgrad, 0);
|
jfloat* grad = jenv->GetFloatArrayElements(jgrad, 0);
|
||||||
jfloat* hess = jenv->GetFloatArrayElements(jhess, 0);
|
jfloat* hess = jenv->GetFloatArrayElements(jhess, 0);
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jgrad);
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jgrad);
|
||||||
jresult = (jint) XGBoosterBoostOneIter(handle, dtrain, grad, hess, len);
|
int ret = XGBoosterBoostOneIter(handle, dtrain, grad, hess, len);
|
||||||
|
|
||||||
//release
|
//release
|
||||||
jenv->ReleaseFloatArrayElements(jgrad, grad, 0);
|
jenv->ReleaseFloatArrayElements(jgrad, grad, 0);
|
||||||
jenv->ReleaseFloatArrayElements(jhess, hess, 0);
|
jenv->ReleaseFloatArrayElements(jhess, hess, 0);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -481,54 +364,45 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterBoost
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterEvalOneIter
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterEvalOneIter
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jint jiter, jlongArray jdmats, jobjectArray jevnames, jobjectArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jint jiter, jlongArray jdmats, jobjectArray jevnames, jobjectArray jout) {
|
||||||
jint jresult = 0 ;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
DMatrixHandle* dmats = 0;
|
||||||
int iter ;
|
|
||||||
void **dmats = 0;
|
|
||||||
char **evnames = 0;
|
char **evnames = 0;
|
||||||
bst_ulong len ;
|
char *result = 0;
|
||||||
char *result[1];
|
bst_ulong len = (bst_ulong)jenv->GetArrayLength(jdmats);
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
iter = (int)jiter;
|
|
||||||
len = (bst_ulong)jenv->GetArrayLength(jdmats);
|
|
||||||
|
|
||||||
|
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
dmats = new void*[len];
|
dmats = new DMatrixHandle[len];
|
||||||
evnames = new char*[len];
|
evnames = new char*[len];
|
||||||
}
|
}
|
||||||
|
|
||||||
//put handle from jhandles to chandles
|
//put handle from jhandles to chandles
|
||||||
jlong* cjdmats = jenv->GetLongArrayElements(jdmats, 0);
|
jlong* cjdmats = jenv->GetLongArrayElements(jdmats, 0);
|
||||||
for(bst_ulong i=0; i<len; i++) {
|
for(bst_ulong i=0; i<len; i++) {
|
||||||
dmats[i] = *(void **)&cjdmats[i];
|
dmats[i] = (DMatrixHandle) cjdmats[i];
|
||||||
}
|
}
|
||||||
|
//transfer jObjectArray to char**, user strcpy and release JNI char* inplace
|
||||||
//transfer jObjectArray to char**
|
|
||||||
for(bst_ulong i=0; i<len; i++) {
|
for(bst_ulong i=0; i<len; i++) {
|
||||||
jstring jevname = (jstring)jenv->GetObjectArrayElement(jevnames, i);
|
jstring jevname = (jstring)jenv->GetObjectArrayElement(jevnames, i);
|
||||||
evnames[i] = (char *)jenv->GetStringUTFChars(jevname, 0);
|
const char* cevname = jenv->GetStringUTFChars(jevname, 0);
|
||||||
|
evnames[i] = new char[jenv->GetStringLength(jevname)];
|
||||||
|
strcpy(evnames[i], cevname);
|
||||||
|
jenv->ReleaseStringUTFChars(jevname, cevname);
|
||||||
}
|
}
|
||||||
|
|
||||||
jresult = (jint) XGBoosterEvalOneIter(handle, iter, dmats, (char const *(*))evnames, len, (const char **) result);
|
int ret = XGBoosterEvalOneIter(handle, jiter, dmats, (char const *(*)) evnames, len, (const char **) &result);
|
||||||
|
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
delete[] dmats;
|
delete[] dmats;
|
||||||
//release string chars
|
//release string chars
|
||||||
for(bst_ulong i=0; i<len; i++) {
|
for(bst_ulong i=0; i<len; i++) {
|
||||||
jstring jevname = (jstring)jenv->GetObjectArrayElement(jevnames, i);
|
delete[] evnames[i];
|
||||||
jenv->ReleaseStringUTFChars(jevname, (const char*)evnames[i]);
|
|
||||||
}
|
}
|
||||||
delete[] evnames;
|
delete[] evnames;
|
||||||
jenv->ReleaseLongArrayElements(jdmats, cjdmats, 0);
|
jenv->ReleaseLongArrayElements(jdmats, cjdmats, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
jstring jinfo = 0;
|
jstring jinfo = 0;
|
||||||
if (*result) jinfo = jenv->NewStringUTF((const char *) *result);
|
if (result) jinfo = jenv->NewStringUTF((const char *) result);
|
||||||
jenv->SetObjectArrayElement(jout, 0, jinfo);
|
jenv->SetObjectArrayElement(jout, 0, jinfo);
|
||||||
|
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -537,29 +411,18 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterEvalO
|
|||||||
* Signature: (JJIJ)[F
|
* Signature: (JJIJ)[F
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterPredict
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterPredict
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jdmat, jint joption_mask, jlong jntree_limit, jobjectArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jdmat, jint joption_mask, jint jntree_limit, jobjectArray jout) {
|
||||||
jint jresult = 0;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
DMatrixHandle dmat = (DMatrixHandle) jdmat;
|
||||||
void *dmat = (void *) 0 ;
|
bst_ulong len;
|
||||||
int option_mask ;
|
float *result;
|
||||||
unsigned int ntree_limit ;
|
int ret = XGBoosterPredict(handle, dmat, joption_mask, (unsigned int) jntree_limit, &len, (const float **) &result);
|
||||||
bst_ulong len[1];
|
|
||||||
*len = 0;
|
|
||||||
float *result[1];
|
|
||||||
|
|
||||||
handle = *(void **)&jhandle;
|
jsize jlen = (jsize) len;
|
||||||
dmat = *(void **)&jdmat;
|
|
||||||
option_mask = (int)joption_mask;
|
|
||||||
ntree_limit = (unsigned int)jntree_limit;
|
|
||||||
|
|
||||||
jresult = (jint) XGBoosterPredict(handle, dmat, option_mask, ntree_limit, len, (const float **) result);
|
|
||||||
|
|
||||||
jsize jlen = (jsize)*len;
|
|
||||||
jfloatArray jarray = jenv->NewFloatArray(jlen);
|
jfloatArray jarray = jenv->NewFloatArray(jlen);
|
||||||
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) *result);
|
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) result);
|
||||||
jenv->SetObjectArrayElement(jout, 0, jarray);
|
jenv->SetObjectArrayElement(jout, 0, jarray);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -569,18 +432,12 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterPredi
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadModel
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadModel
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname) {
|
||||||
jint jresult = 0;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
||||||
char *fname = (char *) 0 ;
|
|
||||||
handle = *(void **)&jhandle;
|
int ret = XGBoosterLoadModel(handle, fname);
|
||||||
|
if (fname) jenv->ReleaseStringUTFChars(jfname,fname);
|
||||||
fname = (char *)jenv->GetStringUTFChars(jfname, 0);
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
jresult = (jint) XGBoosterLoadModel(handle,(char const *)fname);
|
|
||||||
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
|
||||||
|
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -590,17 +447,13 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadM
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSaveModel
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSaveModel
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfname) {
|
||||||
jint jresult = 0;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
||||||
char *fname = (char *) 0 ;
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
fname = 0;
|
|
||||||
fname = (char *)jenv->GetStringUTFChars(jfname, 0);
|
|
||||||
|
|
||||||
jresult = (jint) XGBoosterSaveModel(handle, (char const *)fname);
|
|
||||||
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
|
||||||
|
|
||||||
return jresult;
|
int ret = XGBoosterSaveModel(handle, fname);
|
||||||
|
if (fname) jenv->ReleaseStringUTFChars(jfname, fname);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -610,13 +463,9 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterSaveM
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadModelFromBuffer
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadModelFromBuffer
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jbuf, jlong jlen) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jlong jbuf, jlong jlen) {
|
||||||
void *handle = (void *) 0 ;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *buf = (void *) 0 ;
|
void *buf = (void*) jbuf;
|
||||||
bst_ulong len ;
|
return XGBoosterLoadModelFromBuffer(handle, (void const *)buf, (bst_ulong) jlen);
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
buf = *(void **)&jbuf;
|
|
||||||
len = (bst_ulong)jlen;
|
|
||||||
return (jint) XGBoosterLoadModelFromBuffer(handle, (void const *)buf, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -626,20 +475,16 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterLoadM
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterGetModelRaw
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterGetModelRaw
|
||||||
(JNIEnv * jenv, jclass jcls, jlong jhandle, jobjectArray jout) {
|
(JNIEnv * jenv, jclass jcls, jlong jhandle, jobjectArray jout) {
|
||||||
jint jresult = 0 ;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
jstring jinfo = 0;
|
bst_ulong len = 0;
|
||||||
void *handle = (void *) 0 ;
|
char *result;
|
||||||
bst_ulong len[1];
|
|
||||||
*len = 0;
|
|
||||||
char *result[1];
|
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
|
|
||||||
jresult = (jint)XGBoosterGetModelRaw(handle, len, (const char **) result);
|
int ret = XGBoosterGetModelRaw(handle, &len, (const char **) &result);
|
||||||
if (*result){
|
if (result){
|
||||||
jinfo = jenv->NewStringUTF((const char *) *result);
|
jstring jinfo = jenv->NewStringUTF((const char *) result);
|
||||||
jenv->SetObjectArrayElement(jout, 0, jinfo);
|
jenv->SetObjectArrayElement(jout, 0, jinfo);
|
||||||
}
|
}
|
||||||
return jresult;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -649,32 +494,20 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterGetMo
|
|||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterDumpModel
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterDumpModel
|
||||||
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfmap, jint jwith_stats, jobjectArray jout) {
|
(JNIEnv *jenv, jclass jcls, jlong jhandle, jstring jfmap, jint jwith_stats, jobjectArray jout) {
|
||||||
jint jresult = 0;
|
BoosterHandle handle = (BoosterHandle) jhandle;
|
||||||
void *handle = (void *) 0 ;
|
const char *fmap = jenv->GetStringUTFChars(jfmap, 0);
|
||||||
char *fmap = (char *) 0 ;
|
bst_ulong len = 0;
|
||||||
int with_stats ;
|
char **result;
|
||||||
bst_ulong len[1];
|
|
||||||
*len = 0;
|
|
||||||
|
|
||||||
char **result[1];
|
int ret = XGBoosterDumpModel(handle, fmap, jwith_stats, &len, (const char ***) &result);
|
||||||
handle = *(void **)&jhandle;
|
|
||||||
fmap = 0;
|
|
||||||
if (jfmap) {
|
|
||||||
fmap = (char *)jenv->GetStringUTFChars(jfmap, 0);
|
|
||||||
if (!fmap) return 0;
|
|
||||||
}
|
|
||||||
with_stats = (int)jwith_stats;
|
|
||||||
|
|
||||||
jresult = (jint) XGBoosterDumpModel(handle, (const char *)fmap, with_stats, len, (const char ***) result);
|
|
||||||
|
|
||||||
jsize jlen = (jsize)*len;
|
jsize jlen = (jsize) len;
|
||||||
jobjectArray jinfos = jenv->NewObjectArray(jlen, jenv->FindClass("java/lang/String"), jenv->NewStringUTF(""));
|
jobjectArray jinfos = jenv->NewObjectArray(jlen, jenv->FindClass("java/lang/String"), jenv->NewStringUTF(""));
|
||||||
for(int i=0 ; i<jlen; i++) {
|
for(int i=0 ; i<jlen; i++) {
|
||||||
jenv->SetObjectArrayElement(jinfos, i, jenv->NewStringUTF((const char*) result[0][i]));
|
jenv->SetObjectArrayElement(jinfos, i, jenv->NewStringUTF((const char*) result[i]));
|
||||||
}
|
}
|
||||||
jenv->SetObjectArrayElement(jout, 0, jinfos);
|
jenv->SetObjectArrayElement(jout, 0, jinfos);
|
||||||
|
|
||||||
if (fmap) jenv->ReleaseStringUTFChars(jfmap, (const char *)fmap);
|
if (fmap) jenv->ReleaseStringUTFChars(jfmap, (const char *)fmap);
|
||||||
|
return ret;
|
||||||
return jresult;
|
|
||||||
}
|
}
|
||||||
@ -173,7 +173,7 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterEvalO
|
|||||||
* Signature: (JJIJ[[F)I
|
* Signature: (JJIJ[[F)I
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterPredict
|
JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterPredict
|
||||||
(JNIEnv *, jclass, jlong, jlong, jint, jlong, jobjectArray);
|
(JNIEnv *, jclass, jlong, jlong, jint, jint, jobjectArray);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_dmlc_xgboost4j_wrapper_XgboostJNI
|
* Class: org_dmlc_xgboost4j_wrapper_XgboostJNI
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{20A0E4D7-20C7-4EC1-BDF6-0D469CE239AA}</ProjectGuid>
|
<ProjectGuid>{20A0E4D7-20C7-4EC1-BDF6-0D469CE239AA}</ProjectGuid>
|
||||||
<RootNamespace>xgboost_wrapper</RootNamespace>
|
<RootNamespace>xgboost_wrapper</RootNamespace>
|
||||||
|
<ProjectName>xgboost4j</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
Loading…
x
Reference in New Issue
Block a user