Small cleanups to various data types. (#8086)

- Use `bst_bin_t` in batch param constructor.
- Use `StringView` to avoid `std::string` when appropriate.
- Avoid using `MetaInfo` in quantile constructor to limit the scope of parameter.
This commit is contained in:
Jiaming Yuan
2022-07-18 22:39:36 +08:00
committed by GitHub
parent e28f6f6657
commit 4083440690
9 changed files with 52 additions and 53 deletions

View File

@@ -48,8 +48,8 @@ class DMatrixProxy : public DMatrix {
Context ctx_;
#if defined(XGBOOST_USE_CUDA)
void FromCudaColumnar(std::string interface_str);
void FromCudaArray(std::string interface_str);
void FromCudaColumnar(StringView interface_str);
void FromCudaArray(StringView interface_str);
#endif // defined(XGBOOST_USE_CUDA)
public:
@@ -58,9 +58,8 @@ class DMatrixProxy : public DMatrix {
void SetCUDAArray(char const* c_interface) {
common::AssertGPUSupport();
#if defined(XGBOOST_USE_CUDA)
std::string interface_str = c_interface;
Json json_array_interface =
Json::Load({interface_str.c_str(), interface_str.size()});
StringView interface_str{c_interface};
Json json_array_interface = Json::Load(interface_str);
if (IsA<Array>(json_array_interface)) {
this->FromCudaColumnar(interface_str);
} else {
@@ -114,10 +113,11 @@ class DMatrixProxy : public DMatrix {
}
};
inline DMatrixProxy *MakeProxy(DMatrixHandle proxy) {
auto proxy_handle = static_cast<std::shared_ptr<DMatrix> *>(proxy);
inline DMatrixProxy* MakeProxy(DMatrixHandle proxy) {
auto proxy_handle = static_cast<std::shared_ptr<DMatrix>*>(proxy);
CHECK(proxy_handle) << "Invalid proxy handle.";
DMatrixProxy *typed = static_cast<DMatrixProxy *>(proxy_handle->get());
DMatrixProxy* typed = static_cast<DMatrixProxy*>(proxy_handle->get());
CHECK(typed) << "Invalid proxy handle.";
return typed;
}