Support host data in proxy DMatrix. (#7087)

This commit is contained in:
Jiaming Yuan
2021-07-08 11:35:48 +08:00
committed by GitHub
parent 5d7cdf2e36
commit 84d359efb8
9 changed files with 188 additions and 30 deletions

View File

@@ -11,6 +11,7 @@
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "xgboost/base.h"
#include "xgboost/data.h"
@@ -416,5 +417,24 @@ class ArrayInterface {
Type type;
};
template <typename T> std::string MakeArrayInterface(T const *data, size_t n) {
Json arr{Object{}};
arr["data"] = Array(std::vector<Json>{
Json{Integer{reinterpret_cast<int64_t>(data)}}, Json{Boolean{false}}});
arr["shape"] = Array{std::vector<Json>{Json{Integer{n}}, Json{Integer{1}}}};
std::string typestr;
if (DMLC_LITTLE_ENDIAN) {
typestr.push_back('<');
} else {
typestr.push_back('>');
}
typestr.push_back(ArrayInterfaceHandler::TypeChar<T>());
typestr += std::to_string(sizeof(T));
arr["typestr"] = typestr;
arr["version"] = 3;
std::string str;
Json::Dump(arr, &str);
return str;
}
} // namespace xgboost
#endif // XGBOOST_DATA_ARRAY_INTERFACE_H_