Support numpy array interface (#6998)

This commit is contained in:
Jiaming Yuan
2021-05-27 16:08:22 +08:00
committed by GitHub
parent ab6fd304c4
commit 4cf95a6041
6 changed files with 59 additions and 38 deletions

View File

@@ -261,6 +261,20 @@ XGB_DLL int XGDMatrixCreateFromCSR(char const *indptr,
API_END();
}
XGB_DLL int XGDMatrixCreateFromArray(char const *data,
char const *c_json_config,
DMatrixHandle *out) {
API_BEGIN();
xgboost::data::ArrayAdapter adapter{
xgboost::data::ArrayAdapter(StringView{data})};
auto config = Json::Load(StringView{c_json_config});
float missing = GetMissing(config);
auto nthread = get<Integer const>(config["nthread"]);
*out =
new std::shared_ptr<DMatrix>(DMatrix::Create(&adapter, missing, nthread));
API_END();
}
XGB_DLL int XGDMatrixCreateFromCSCEx(const size_t* col_ptr,
const unsigned* indices,
const bst_float* data,