|
1 |
| -// Copyright by Contributors |
| 1 | +/** |
| 2 | + * Copyright 2016-2023 by XGBoost Contributors |
| 3 | + */ |
2 | 4 | #include <xgboost/data.h>
|
3 | 5 |
|
4 |
| -#include <array> |
| 6 | +#include <array> // std::array |
| 7 | +#include <limits> // std::numeric_limits |
| 8 | +#include <memory> // std::unique_ptr |
5 | 9 |
|
6 |
| -#include "../../../src/data/adapter.h" |
7 |
| -#include "../../../src/data/simple_dmatrix.h" |
8 |
| -#include "../filesystem.h" // dmlc::TemporaryDirectory |
9 |
| -#include "../helpers.h" |
| 10 | +#include "../../../src/data/adapter.h" // ArrayAdapter |
| 11 | +#include "../../../src/data/simple_dmatrix.h" // SimpleDMatrix |
| 12 | +#include "../filesystem.h" // dmlc::TemporaryDirectory |
| 13 | +#include "../helpers.h" // RandomDataGenerator,CreateSimpleTestData |
10 | 14 | #include "xgboost/base.h"
|
| 15 | +#include "xgboost/host_device_vector.h" // HostDeviceVector |
| 16 | +#include "xgboost/string_view.h" // StringView |
11 | 17 |
|
12 | 18 | using namespace xgboost; // NOLINT
|
13 | 19 |
|
@@ -298,6 +304,17 @@ TEST(SimpleDMatrix, Slice) {
|
298 | 304 | ASSERT_EQ(out->Info().num_col_, out->Info().num_col_);
|
299 | 305 | ASSERT_EQ(out->Info().num_row_, ridxs.size());
|
300 | 306 | ASSERT_EQ(out->Info().num_nonzero_, ridxs.size() * kCols); // dense
|
| 307 | + |
| 308 | + { |
| 309 | + HostDeviceVector<float> data; |
| 310 | + auto arr_str = RandomDataGenerator{kRows, kCols, 0.0}.GenerateArrayInterface(&data); |
| 311 | + auto adapter = data::ArrayAdapter{StringView{arr_str}}; |
| 312 | + auto n_threads = 2; |
| 313 | + std::unique_ptr<DMatrix> p_fmat{ |
| 314 | + DMatrix::Create(&adapter, std::numeric_limits<float>::quiet_NaN(), n_threads, "")}; |
| 315 | + std::unique_ptr<DMatrix> slice{p_fmat->Slice(ridxs)}; |
| 316 | + ASSERT_LE(slice->Ctx()->Threads(), n_threads); |
| 317 | + } |
301 | 318 | }
|
302 | 319 |
|
303 | 320 | TEST(SimpleDMatrix, SaveLoadBinary) {
|
|
0 commit comments