Skip to content

Commit ee0a029

Browse files
committed
Clean up some comments (+5 squashed commits)
Squashed commits: [99b8f1f] Remove pom change [7b80fef] Remove changes from cpu_predictor, fix rebase miss [a531053] Cleaning up XGBoosterInplacePredict Further de-newification More clean-up [de6e109] pom change git didn't pick up (+5 squashed commits) Squashed commits: [6182244] One missed pom [ab5bc5e] Update all the poms, even the unused ones [a96c3b9] More clean-up [aea9cd3] Further de-newification [1539100] Cleaning up XGBoosterInplacePredict [a81361d] increment our version (+15 squashed commits) Squashed commits: [c4d6d52] missed param [b343f89] Remove redundant line [5609102] Remove need to pass DMatrix [e31c53d] another missed logging message [f6a2508] comment out some logging [148e29e] undo static cast [6372805] More logging [a173763] change how proxy is cast in cpu predictor [5a08ff8] proxy to stuff [823c92f] Dense adapter changes [9a3214b] change some variables and things [d9dd5c4] uncomment stuff, more logging [7968bca] Set dense data [9e79c2e] Try some stuff with DMatrix [2b8cca6] Print result of p_m.get()
1 parent c5d448e commit ee0a029

File tree

10 files changed

+39
-30
lines changed

10 files changed

+39
-30
lines changed

include/xgboost/c_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ XGB_DLL int XGBoosterInplacePredict(BoosterHandle handle,
10171017
const float *data,
10181018
size_t num_rows,
10191019
size_t num_features,
1020+
DMatrixHandle d_matrix_handle,
10201021
float missing,
10211022
int option_mask,
10221023
int ntree_limit,

jvm-packages/xgboost4j/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<goal>exec</goal>
7070
</goals>
7171
<configuration>
72-
<executable>python3</executable>
72+
<executable>python</executable>
7373
<arguments>
7474
<argument>create_jni.py</argument>
7575
<argument>--log-capi-invocation</argument>

jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/Booster.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ private synchronized float[][] predict(DMatrix data,
315315
}
316316
return predicts;
317317
}
318+
318319
/**
319320
* Perform thread-safe prediction. Calls
320321
* <code>inplace_predict(data, num_rows, num_features, Float.NaN, false, 0, false, false)</code>.
@@ -332,7 +333,8 @@ private synchronized float[][] predict(DMatrix data,
332333
public float[][] inplace_predict(float[] data,
333334
int num_rows,
334335
int num_features) throws XGBoostError {
335-
return this.inplace_predict(data, num_rows, num_features, Float.NaN, false, 0, false, false);
336+
return this.inplace_predict(data, num_rows, num_features,
337+
Float.NaN, false, 0, false, false);
336338
}
337339

338340
/**
@@ -354,7 +356,8 @@ public float[][] inplace_predict(float[] data,
354356
int num_rows,
355357
int num_features,
356358
float missing) throws XGBoostError {
357-
return this.inplace_predict(data, num_rows, num_features, missing, false, 0, false, false);
359+
return this.inplace_predict(data, num_rows, num_features,
360+
missing, false, 0, false, false);
358361
}
359362

360363
/**
@@ -380,8 +383,8 @@ public float[][] inplace_predict(float[] data,
380383
int num_features,
381384
float missing,
382385
boolean outputMargin) throws XGBoostError {
383-
return this.inplace_predict(data, num_rows, num_features, missing, outputMargin,
384-
0, false, false);
386+
return this.inplace_predict(data, num_rows, num_features, missing,
387+
outputMargin, 0, false, false);
385388
}
386389

387390
/**
@@ -408,8 +411,8 @@ public float[][] inplace_predict(float[] data,
408411
float missing,
409412
boolean outputMargin,
410413
int treeLimit) throws XGBoostError {
411-
return this.inplace_predict(data, num_rows, num_features, missing, outputMargin,
412-
treeLimit, false, false);
414+
return this.inplace_predict(data, num_rows, num_features, missing,
415+
outputMargin, treeLimit, false, false);
413416
}
414417

415418
/**
@@ -418,6 +421,7 @@ public float[][] inplace_predict(float[] data,
418421
* @param data Flattened input matrix of features for prediction
419422
* @param num_rows The number of preditions to make (count of input matrix rows)
420423
* @param num_features The number of features in the model (count of input matrix columns)
424+
* @param d_matrix_h The handle for a dmatrix
421425
* @param missing Value indicating missing element in the <code>data</code> input matrix
422426
* @param outputMargin Whether to only predict margin value instead of transformed prediction
423427
* @param treeLimit limit number of trees, 0 means all trees.
@@ -444,10 +448,11 @@ public float[][] inplace_predict(float[] data,
444448
if (predContribs) {
445449
optionMask = 4;
446450
}
447-
451+
DMatrix d_mat = new DMatrix(data, num_rows, num_features, missing);
448452
float[][] rawPredicts = new float[1][];
449453
XGBoostJNI.checkCall(XGBoostJNI.XGBoosterInplacePredict(handle, data, num_rows, num_features,
450-
missing, optionMask, treeLimit, rawPredicts)); // pass missing and treelimit here?
454+
d_mat.getHandle(), missing,
455+
optionMask, treeLimit, rawPredicts)); // pass missing and treelimit here?
451456

452457
// System.out.println("Booster.inplace_predict rawPredicts[0].length = " +
453458
// rawPredicts[0].length);

jvm-packages/xgboost4j/src/main/java/ml/dmlc/xgboost4j/java/XGBoostJNI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public final static native int XGBoosterEvalOneIter(long handle, int iter, long[
119119
public final static native int XGBoosterPredict(long handle, long dmat, int option_mask,
120120
int ntree_limit, float[][] predicts);
121121

122-
public final static native int XGBoosterInplacePredict(long handle, float[] data, int num_rows, int num_features,
122+
public final static native int XGBoosterInplacePredict(long handle, float[] data, int num_rows, int num_features, long d_matrix_handle,
123123
float missing, int option_mask, int ntree_limit,
124124
float[][] predicts);
125125

jvm-packages/xgboost4j/src/native/xgboost4j.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,18 +667,18 @@ JNIEXPORT jint JNICALL Java_ml_dmlc_xgboost4j_java_XGBoostJNI_XGBoosterPredict
667667
* Signature: (J[FIII[[F)I
668668
*/
669669
JNIEXPORT jint JNICALL Java_ml_dmlc_xgboost4j_java_XGBoostJNI_XGBoosterInplacePredict
670-
(JNIEnv *jenv, jclass jcls, jlong jhandle, jfloatArray jdata, jint num_rows, jint num_features,
670+
(JNIEnv *jenv, jclass jcls, jlong jhandle, jfloatArray jdata, jint num_rows, jint num_features, jlong d_matrix_handle,
671671
jfloat missing, jint option_mask, jint treeLimit, jobjectArray jout) {
672672
BoosterHandle handle = (BoosterHandle) jhandle;
673+
DMatrixHandle dmat = (DMatrixHandle) d_matrix_handle;
673674
jfloat* data = jenv->GetFloatArrayElements(jdata, 0);
674675
const bst_ulong *len;
675676
float *result;
676-
int ret = XGBoosterInplacePredict(handle, data, num_rows, num_features, missing, option_mask, treeLimit,
677+
int ret = XGBoosterInplacePredict(handle, data, num_rows, num_features, dmat, missing, option_mask, treeLimit,
677678
&len, (const float **) &result);
678679
JVM_CHECK_CALL(ret);
679680
jenv->ReleaseFloatArrayElements(jdata, data, 0);
680681
if (*len) {
681-
// printf("JNI XGBoosterInplacePredict len = %u\n", *len);
682682
jsize jlen = (jsize) *len;
683683
jfloatArray jarray = jenv->NewFloatArray(jlen);
684684
jenv->SetFloatArrayRegion(jarray, 0, jlen, (jfloat *) result);

jvm-packages/xgboost4j/src/native/xgboost4j.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python-package/xgboost/spark/core.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,6 @@
157157
pred = Pred("prediction", "rawPrediction", "probability", "predContrib")
158158

159159

160-
# TODO: supply hint message for all other unsupported params.
161-
_unsupported_params_hint_message = {
162-
"enable_categorical": "`xgboost.spark` estimators do not have 'enable_categorical' param, "
163-
"but you can set `feature_types` param and mark categorical features with 'c' string."
164-
}
165-
166-
167160
class _SparkXGBParams(
168161
HasFeaturesCol,
169162
HasLabelCol,

src/c_api/c_api.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ XGB_DLL int XGBoosterInplacePredict(BoosterHandle handle,
10681068
const float *data,
10691069
size_t num_rows,
10701070
size_t num_features,
1071+
DMatrixHandle dMatrixHandle,
10711072
float missing,
10721073
int option_mask,
10731074
int ntree_limit,
@@ -1076,16 +1077,13 @@ XGB_DLL int XGBoosterInplacePredict(BoosterHandle handle,
10761077
API_BEGIN();
10771078
CHECK_HANDLE();
10781079
xgboost::bst_ulong out_dim;
1079-
std::shared_ptr<xgboost::data::DenseAdapter> x{new xgboost::data::DenseAdapter(data, num_rows, num_features)};
1080-
std::shared_ptr<DMatrix> p_m{nullptr};
1081-
p_m.reset(new data::DMatrixProxy);
1082-
auto proxy = dynamic_cast<data::DMatrixProxy *>(p_m.get());
1083-
CHECK(proxy) << "Invalid input type for inplace predict.";
1080+
10841081
auto *learner = static_cast<xgboost::Learner *>(handle);
10851082
auto iteration_end = GetIterationFromTreeLimit(ntree_limit, learner);
1086-
InplacePredictImplCore(p_m, learner, (xgboost::PredictionType)0, missing, num_rows, num_features,
1083+
auto proxy = std::make_shared<data::DMatrixProxy>();
1084+
proxy->SetDenseData(data, num_rows, num_features);
1085+
InplacePredictImplCore(proxy, learner, (xgboost::PredictionType)0, missing, num_rows, num_features,
10871086
0, iteration_end, true, len, &out_dim, out_result);
1088-
// printf("XGBoosterInplacePredict len = %u, dim = %u\n", **len, out_dim);
10891087
API_END();
10901088
}
10911089

src/data/proxy_dmatrix.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ void DMatrixProxy::SetArrayData(char const *c_interface) {
1515
this->ctx_.gpu_id = Context::kCpuId;
1616
}
1717

18+
void DMatrixProxy::SetDenseData(const float *data, size_t num_rows,
19+
size_t num_features) {
20+
std::shared_ptr<xgboost::data::DenseAdapter> adapter{new xgboost::data::DenseAdapter(data, num_rows, num_features)};
21+
this->batch_ = adapter;
22+
this->Info().num_col_ = adapter->NumColumns();
23+
this->Info().num_row_ = adapter->NumRows();
24+
this->ctx_.gpu_id = Context::kCpuId;
25+
}
26+
1827
void DMatrixProxy::SetCSRData(char const *c_indptr, char const *c_indices,
1928
char const *c_values, bst_feature_t n_features, bool on_host) {
2029
CHECK(on_host) << "Not implemented on device.";

src/data/proxy_dmatrix.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ class DMatrixProxy : public DMatrix {
6363
}
6464

6565
void SetArrayData(char const* c_interface);
66-
void SetCSRData(char const* c_indptr, char const* c_indices, char const* c_values,
67-
bst_feature_t n_features, bool on_host);
66+
void SetDenseData(const float *data,size_t num_rows,
67+
size_t num_features);
68+
void SetCSRData(char const *c_indptr, char const *c_indices,
69+
char const *c_values, bst_feature_t n_features,
70+
bool on_host);
6871

6972
MetaInfo& Info() override { return info_; }
7073
MetaInfo const& Info() const override { return info_; }

0 commit comments

Comments
 (0)