In-place Prediction in C++

Hello,

The code below is a way I use to call InplacePredict function instead of two function calls dMatrix construction and the predict function for performace benefits.

Can anyone please answer the questions below:

  1. If there is a friendly interface to call InplacePredict in C++? Is it designed to be called in C++?

  2. In my experiments the execution time is the same for settings learner->SetParam(“nthread”,“1”); and learner->SetParam(“nthread”,“8”) on machine with more than 8 cores. How can multithreading improve performance of the InplacePredict?

  3. Is there any plan to support the Shapley values for InplacePredict (PredictionType::kContribution is not supported currently)

Thanks,
Dmitry

    HostDeviceVector<float>* preds;
    std::shared_ptr<data::DMatrixProxy> proxy{new data::DMatrixProxy{}};
    Json array_interface{Object()};
    vector<Json> shape = {Json(static_cast<Integer::Int>(nRow)), Json(static_cast<Integer::Int>(nCol))};
    array_interface["shape"] = Array(shape);
    array_interface["data"] = std::vector<Json>(2);
    array_interface["data"][1] = Boolean(false);
    array_interface["version"] = 3;
    array_interface["typestr"] = String("<f4");
    array_interface["stream"] = nullptr;
                            
   array_interface["data"][0] = Integer(reinterpret_cast<int64_t>(testData.data()));
   string out;
 Json::Dump(array_interface, &out);
  proxy->SetArrayData(out.c_str());

 //PredictionType predType = contrib ? PredictionType::kContribution : PredictionType::kValue;
learner->InplacePredict(proxy, PredictionType::kValue, missing,
                                                                                            &preds, 0, 0);