Skip to content

Commit

Permalink
Cleanup the test help.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Nov 14, 2021
1 parent 181074c commit d463894
Showing 2 changed files with 11 additions and 24 deletions.
11 changes: 11 additions & 0 deletions tests/cpp/common/test_hist_util.cu
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

#include <xgboost/data.h>
#include <xgboost/c_api.h>
#include <xgboost/linalg.h>

#include "test_hist_util.h"
#include "../helpers.h"
@@ -24,6 +25,16 @@

namespace xgboost {
namespace common {
namespace {
data::CupyAdapter AdapterFromData(thrust::device_vector<float> const& x, int num_rows,
int num_columns) {
auto str =
linalg::TensorView<float const, 2>{
Span<float const>{x.data().get(), x.size()}, {num_rows, num_columns}, 0}
.ArrayInterfaceStr();
return data::CupyAdapter(str);
}
} // anonymous namespace

template <typename AdapterT>
HistogramCuts GetHostCuts(AdapterT *adapter, int num_bins, float missing) {
24 changes: 0 additions & 24 deletions tests/cpp/common/test_hist_util.h
Original file line number Diff line number Diff line change
@@ -14,11 +14,6 @@
#include "../../../src/data/simple_dmatrix.h"
#include "../../../src/data/adapter.h"

#ifdef __CUDACC__
#include <xgboost/json.h>
#include "../../../src/data/device_adapter.cuh"
#endif // __CUDACC__

// Some helper functions used to test both GPU and CPU algorithms
//
namespace xgboost {
@@ -46,25 +41,6 @@ inline std::vector<float> GenerateRandomWeights(int num_rows) {
return w;
}

#ifdef __CUDACC__
inline data::CupyAdapter AdapterFromData(const thrust::device_vector<float> &x,
int num_rows, int num_columns) {
Json array_interface{Object()};
std::vector<Json> shape = {Json(static_cast<Integer::Int>(num_rows)),
Json(static_cast<Integer::Int>(num_columns))};
array_interface["shape"] = Array(shape);
std::vector<Json> j_data{
Json(Integer(reinterpret_cast<Integer::Int>(x.data().get()))),
Json(Boolean(false))};
array_interface["data"] = j_data;
array_interface["version"] = 3;
array_interface["typestr"] = String("<f4");
std::string str;
Json::Dump(array_interface, &str);
return data::CupyAdapter(str);
}
#endif

inline std::shared_ptr<data::SimpleDMatrix>
GetDMatrixFromData(const std::vector<float> &x, int num_rows, int num_columns) {
data::DenseAdapter adapter(x.data(), num_rows, num_columns);

0 comments on commit d463894

Please sign in to comment.