|
|
|
@ -12,39 +12,27 @@
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
|
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 ;
|
|
|
|
long out[1];
|
|
|
|
int silent;
|
|
|
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
|
|
|
void* result[1];
|
|
|
|
int ret = XGDMatrixCreateFromFile(fname, jsilent, &result);
|
|
|
|
unsigned long out[1];
|
|
|
|
out[0] = (long) result;
|
|
|
|
|
|
|
|
if (fname) jenv->ReleaseStringUTFChars(jfname, fname);
|
|
|
|
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);
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
return jresult;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -54,28 +42,21 @@ 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 ;
|
|
|
|
unsigned long out[1];
|
|
|
|
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);
|
|
|
|
out[0] = (long)result;
|
|
|
|
*(void **)&out[0] = *result;
|
|
|
|
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
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 ret;
|
|
|
|
return jresult;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -85,28 +66,24 @@ 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];
|
|
|
|
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;
|
|
|
|
out[0] = (long) result;
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
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 +93,17 @@ 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];
|
|
|
|
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);
|
|
|
|
|
|
|
|
out[0] = (long) result;
|
|
|
|
jresult = (jint) XGDMatrixCreateFromMat((float const *)data, nrow, ncol, miss, result);
|
|
|
|
|
|
|
|
*(void **)&out[0] = *result;
|
|
|
|
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
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,21 @@ 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;
|
|
|
|
bst_ulong len;
|
|
|
|
|
|
|
|
void *result[1];
|
|
|
|
|
|
|
|
unsigned long out[1];
|
|
|
|
unsigned long out[1];
|
|
|
|
|
|
|
|
|
|
|
|
jint* indexset = jenv->GetIntArrayElements(jindexset, 0);
|
|
|
|
jint* indexset = jenv->GetIntArrayElements(jindexset, 0);
|
|
|
|
handle = *(void **)&jhandle;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
len = (bst_ulong)jenv->GetArrayLength(jindexset);
|
|
|
|
bst_ulong 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;
|
|
|
|
out[0] = (long)result;
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
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 +136,11 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
handle = *(void **)&jhandle;
|
|
|
|
int ret = XGDMatrixFree(handle);
|
|
|
|
jresult = (jint) XGDMatrixFree(handle);
|
|
|
|
return ret;
|
|
|
|
return jresult;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -187,19 +150,12 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
char *fname = (char *) 0 ;
|
|
|
|
const char* fname = jenv->GetStringUTFChars(jfname, 0);
|
|
|
|
int silent ;
|
|
|
|
int ret = XGDMatrixSaveBinary(handle, fname, jsilent);
|
|
|
|
handle = *(void **)&jhandle;
|
|
|
|
if (fname) jenv->ReleaseStringUTFChars(jfname, (const char *)fname);
|
|
|
|
fname = 0;
|
|
|
|
return ret;
|
|
|
|
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 +165,18 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
char *field = (char *) 0 ;
|
|
|
|
const char* field = jenv->GetStringUTFChars(jfield, 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 +186,17 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
char *field = (char *) 0 ;
|
|
|
|
const char* field = jenv->GetStringUTFChars(jfield, 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 +206,14 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
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 +223,20 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
char *field = (char *) 0 ;
|
|
|
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
|
|
|
bst_ulong len[1];
|
|
|
|
bst_ulong len[1];
|
|
|
|
*len = 0;
|
|
|
|
float *result[1];
|
|
|
|
float *result[1];
|
|
|
|
int ret = XGDMatrixGetFloatInfo(handle, field, len, (const float **) result);
|
|
|
|
|
|
|
|
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 +246,20 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
char *field = (char *) 0 ;
|
|
|
|
const char* field = jenv->GetStringUTFChars(jfield, 0);
|
|
|
|
bst_ulong len[1];
|
|
|
|
bst_ulong len[1];
|
|
|
|
*len = 0;
|
|
|
|
*len = 0;
|
|
|
|
unsigned int *result[1];
|
|
|
|
unsigned int *result[1];
|
|
|
|
|
|
|
|
int ret = (jint) XGDMatrixGetUIntInfo(handle, field, len, (const unsigned int **) result);
|
|
|
|
handle = *(void **)&jhandle;
|
|
|
|
if (field) jenv->ReleaseStringUTFChars(jfield, field);
|
|
|
|
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 +269,12 @@ 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;
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
handle = (DMatrixHandle) jhandle;
|
|
|
|
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 +284,32 @@ 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];
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out[0] = (long) result;
|
|
|
|
*(void **)&out[0] = *result;
|
|
|
|
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
jenv->SetLongArrayRegion(jout, 0, 1, (const jlong *) out);
|
|
|
|
|
|
|
|
|
|
|
|
return jresult;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -403,9 +319,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 +331,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 +348,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 +360,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,38 +379,27 @@ 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[1];
|
|
|
|
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**
|
|
|
|
//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);
|
|
|
|
evnames[i] = (char *)jenv->GetStringUTFChars(jevname, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
@ -528,7 +415,7 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterEvalO
|
|
|
|
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 +424,19 @@ 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 ;
|
|
|
|
|
|
|
|
int option_mask ;
|
|
|
|
|
|
|
|
unsigned int ntree_limit ;
|
|
|
|
|
|
|
|
bst_ulong len[1];
|
|
|
|
bst_ulong len[1];
|
|
|
|
*len = 0;
|
|
|
|
*len = 0;
|
|
|
|
float *result[1];
|
|
|
|
float *result[1];
|
|
|
|
|
|
|
|
int ret = XGBoosterPredict(handle, dmat, joption_mask, (unsigned int) jntree_limit, len, (const float **) result);
|
|
|
|
|
|
|
|
|
|
|
|
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 +446,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 +461,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 +477,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 +489,17 @@ 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;
|
|
|
|
|
|
|
|
void *handle = (void *) 0 ;
|
|
|
|
|
|
|
|
bst_ulong len[1];
|
|
|
|
bst_ulong len[1];
|
|
|
|
*len = 0;
|
|
|
|
*len = 0;
|
|
|
|
char *result[1];
|
|
|
|
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,23 +509,13 @@ 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 ;
|
|
|
|
|
|
|
|
int with_stats ;
|
|
|
|
|
|
|
|
bst_ulong len[1];
|
|
|
|
bst_ulong len[1];
|
|
|
|
*len = 0;
|
|
|
|
*len = 0;
|
|
|
|
|
|
|
|
|
|
|
|
char **result[1];
|
|
|
|
char **result[1];
|
|
|
|
handle = *(void **)&jhandle;
|
|
|
|
|
|
|
|
fmap = 0;
|
|
|
|
int ret = XGBoosterDumpModel(handle, fmap, jwith_stats, len, (const char ***) result);
|
|
|
|
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(""));
|
|
|
|
@ -674,7 +524,6 @@ JNIEXPORT jint JNICALL Java_org_dmlc_xgboost4j_wrapper_XgboostJNI_XGBoosterDumpM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|