Skip to content

Commit de6e109

Browse files
committed
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
1 parent a81361d commit de6e109

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,8 @@ private synchronized float[][] predict(DMatrix data,
332332
*/
333333
public float[][] inplace_predict(float[] data,
334334
int num_rows,
335-
int num_features,
336-
DMatrix d_matrix) throws XGBoostError {
337-
return this.inplace_predict(data, num_rows, num_features, d_matrix,
335+
int num_features) throws XGBoostError {
336+
return this.inplace_predict(data, num_rows, num_features,
338337
Float.NaN, false, 0, false, false);
339338
}
340339

@@ -356,9 +355,8 @@ public float[][] inplace_predict(float[] data,
356355
public float[][] inplace_predict(float[] data,
357356
int num_rows,
358357
int num_features,
359-
DMatrix d_matrix,
360358
float missing) throws XGBoostError {
361-
return this.inplace_predict(data, num_rows, num_features, d_matrix,
359+
return this.inplace_predict(data, num_rows, num_features,
362360
missing, false, 0, false, false);
363361
}
364362

@@ -383,10 +381,9 @@ public float[][] inplace_predict(float[] data,
383381
public float[][] inplace_predict(float[] data,
384382
int num_rows,
385383
int num_features,
386-
DMatrix d_matrix,
387384
float missing,
388385
boolean outputMargin) throws XGBoostError {
389-
return this.inplace_predict(data, num_rows, num_features, d_matrix, missing,
386+
return this.inplace_predict(data, num_rows, num_features, missing,
390387
outputMargin, 0, false, false);
391388
}
392389

@@ -411,11 +408,10 @@ public float[][] inplace_predict(float[] data,
411408
public float[][] inplace_predict(float[] data,
412409
int num_rows,
413410
int num_features,
414-
DMatrix d_matrix,
415411
float missing,
416412
boolean outputMargin,
417413
int treeLimit) throws XGBoostError {
418-
return this.inplace_predict(data, num_rows, num_features, d_matrix, missing,
414+
return this.inplace_predict(data, num_rows, num_features, missing,
419415
outputMargin, treeLimit, false, false);
420416
}
421417

@@ -437,7 +433,6 @@ public float[][] inplace_predict(float[] data,
437433
public float[][] inplace_predict(float[] data,
438434
int num_rows,
439435
int num_features,
440-
DMatrix d_matrix,
441436
float missing,
442437
boolean outputMargin,
443438
int treeLimit,
@@ -453,10 +448,10 @@ public float[][] inplace_predict(float[] data,
453448
if (predContribs) {
454449
optionMask = 4;
455450
}
456-
451+
DMatrix d_mat = new DMatrix(data, num_rows, num_features, missing);
457452
float[][] rawPredicts = new float[1][];
458453
XGBoostJNI.checkCall(XGBoostJNI.XGBoosterInplacePredict(handle, data, num_rows, num_features,
459-
d_matrix.getHandle(), missing,
454+
d_mat.getHandle(), missing,
460455
optionMask, treeLimit, rawPredicts)); // pass missing and treelimit here?
461456

462457
// System.out.println("Booster.inplace_predict rawPredicts[0].length = " +

jvm-packages/xgboost4j/src/test/java/ml/dmlc/xgboost4j/java/BoosterImplTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,16 @@ class InplacePredictThread extends Thread {
9595
float[][] testX;
9696
int test_rows;
9797
int features;
98-
DMatrix dMatrix;
9998
float[][] true_predicts;
10099
Booster booster;
101100
Random rng = new Random();
102101
int n_preds = 100;
103102

104-
public InplacePredictThread(int n, Booster booster, float[][] testX, int test_rows, int features, DMatrix dMatrix, float[][] true_predicts) {
103+
public InplacePredictThread(int n, Booster booster, float[][] testX, int test_rows, int features, float[][] true_predicts) {
105104
this.thread_num = n;
106105
this.booster = booster;
107106
this.testX = testX;
108107
this.test_rows = test_rows;
109-
this.dMatrix = dMatrix;
110108
this.features = features;
111109
this.true_predicts = true_predicts;
112110
}
@@ -122,7 +120,7 @@ public void run() {
122120
int r = this.rng.nextInt(this.test_rows);
123121

124122
// In-place predict a single random row
125-
float[][] predictions = booster.inplace_predict(this.testX[r], 1, this.features, this.dMatrix);
123+
float[][] predictions = booster.inplace_predict(this.testX[r], 1, this.features);
126124

127125
// Confirm results as expected
128126
if (predictions[0][0] != this.true_predicts[r][0]) {
@@ -146,19 +144,17 @@ class InplacePredictionTask implements Callable<Boolean> {
146144
float[][] testX;
147145
int test_rows;
148146
int features;
149-
DMatrix dMatrix;
150147
float[][] true_predicts;
151148
Booster booster;
152149
Random rng = new Random();
153150
int n_preds = 100;
154151

155-
public InplacePredictionTask(int n, Booster booster, float[][] testX, int test_rows, int features, DMatrix dMatrix, float[][] true_predicts) {
152+
public InplacePredictionTask(int n, Booster booster, float[][] testX, int test_rows, int features, float[][] true_predicts) {
156153
this.task_num = n;
157154
this.booster = booster;
158155
this.testX = testX;
159156
this.test_rows = test_rows;
160157
this.features = features;
161-
this.dMatrix = dMatrix;
162158
this.true_predicts = true_predicts;
163159
}
164160

@@ -172,7 +168,7 @@ public Boolean call() throws Exception {
172168
int r = this.rng.nextInt(this.test_rows);
173169

174170
// In-place predict a single random row
175-
float[][] predictions = booster.inplace_predict(this.testX[r], 1, this.features, this.dMatrix);
171+
float[][] predictions = booster.inplace_predict(this.testX[r], 1, this.features);
176172

177173
// Confirm results as expected
178174
if (predictions[0][0] != this.true_predicts[r][0]) {
@@ -335,7 +331,7 @@ public void testBoosterInplacePredict() throws XGBoostError, IOException {
335331
float[][] predicts = booster.predict(testMat);
336332

337333
// inplace prediction
338-
float[][] inplace_predicts = booster.inplace_predict(testX, test_rows, features, testMat);
334+
float[][] inplace_predicts = booster.inplace_predict(testX, test_rows, features);
339335

340336
// Confirm that the two prediction results are identical
341337
TestCase.assertTrue(ArrayComparator.compare(predicts, inplace_predicts));
@@ -360,7 +356,7 @@ public void testBoosterInplacePredict() throws XGBoostError, IOException {
360356

361357
// Submit all the tasks
362358
for (int i=0; i<n_tasks; i++) {
363-
result.add(executorService.submit(new InplacePredictionTask(i, booster, testX2, test_rows, features, testMat, predicts)));
359+
result.add(executorService.submit(new InplacePredictionTask(i, booster, testX2, test_rows, features, predicts)));
364360
}
365361

366362
// Tell the executor service we are done

src/c_api/c_api.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,35 +1077,45 @@ XGB_DLL int XGBoosterInplacePredict(BoosterHandle handle,
10771077
API_BEGIN();
10781078
CHECK_HANDLE();
10791079
xgboost::bst_ulong out_dim;
1080+
std::shared_ptr<xgboost::data::DenseAdapter> x{new xgboost::data::DenseAdapter(data, num_rows, num_features)};
10801081
//std::shared_ptr<DMatrix> p_m(dMatrixHandle);
10811082
std::shared_ptr<DMatrix> p_m{nullptr};
1082-
if (!dMatrixHandle) {
1083+
/*if (!dMatrixHandle) {
10831084
fprintf (stderr, "dMatrixHandle is null");
10841085
exit(1);
1085-
}
1086+
}*/
10861087
if (!dMatrixHandle) {
10871088
p_m.reset(new data::DMatrixProxy);
1088-
fprintf (stdout, "dmatrix handle is null");
1089+
//fprintf (stdout, "dmatrix handle is null");
10891090
if (!p_m) {
10901091
fprintf (stderr, "p_m 1 is null");
10911092
exit(1);
10921093
}
10931094
} else {
10941095
p_m = *static_cast<std::shared_ptr<DMatrix> *>(dMatrixHandle);
1095-
1096-
fprintf (stdout, "dmatrix handle is not null");
1096+
//fprintf (stdout, "dmatrix handle is not null");
10971097
if (!p_m) {
10981098
fprintf (stderr, "p_m 2 is null");
10991099
exit(1);
11001100
}
11011101
}
1102-
auto proxy = new std::shared_ptr<xgboost::DMatrix>(new xgboost::data::DMatrixProxy);
1102+
//fprintf (stdout, reinterpret_cast<const char *>(p_m.get()));
1103+
p_m.reset(new data::DMatrixProxy);
1104+
auto stuff = dynamic_cast<data::DMatrixProxy *>(p_m.get());
1105+
auto proxy = new std::shared_ptr<xgboost::data::DMatrixProxy>(new xgboost::data::DMatrixProxy);
1106+
//printf ("stuff is %s", typeid(stuff).name());
1107+
//printf ("proxy is %s", typeid(proxy).name());
11031108
if (!proxy) {
1104-
fprintf (stderr, "proxy is null");
1109+
fprintf (stderr, "proxy is null line 1058");
11051110
exit(1);
11061111
}
1112+
if (!stuff) {
1113+
fprintf (stderr, "stuff is null line 1062");
1114+
exit(1);
1115+
}
11071116
auto *learner = static_cast<xgboost::Learner *>(handle);
11081117
auto iteration_end = GetIterationFromTreeLimit(ntree_limit, learner);
1118+
stuff->SetDenseData(data, num_rows, num_features);
11091119
InplacePredictImplCore(p_m, learner, (xgboost::PredictionType)0, missing, num_rows, num_features,
11101120
0, iteration_end, true, len, &out_dim, out_result);
11111121
// printf("XGBoosterInplacePredict len = %u, dim = %u\n", **len, out_dim);

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_; }

src/predictor/cpu_predictor.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,9 @@ class CPUPredictor : public Predictor {
707707
bool InplacePredict(std::shared_ptr<DMatrix> p_m, const gbm::GBTreeModel &model, float missing,
708708
PredictionCacheEntry *out_preds, uint32_t tree_begin,
709709
unsigned tree_end) const override {
710+
//fprintf (stdout, "We are in cpu_predictor");
710711
auto proxy = dynamic_cast<data::DMatrixProxy *>(p_m.get());
711-
if (!proxy) {
712-
fprintf (stderr, "InplacePredict: proxy is null cpu variant");
713-
exit(1);
714-
}
712+
//auto proxy = new std::shared_ptr<xgboost::DMatrix>(new xgboost::data::DMatrixProxy);
715713
auto x = proxy->Adapter();
716714
if (x.type() == typeid(std::shared_ptr<data::DenseAdapter>)) {
717715
this->DispatchedInplacePredict<data::DenseAdapter, kBlockOfRowsSize>(

0 commit comments

Comments
 (0)