| 508 | } |
| 509 | |
| 510 | void TestXGDMatrixGetQuantileCut(Context const *ctx) { |
| 511 | bst_idx_t n_samples{1024}; |
| 512 | bst_feature_t n_features{16}; |
| 513 | |
| 514 | Json dconfig{Object{}}; |
| 515 | dconfig["ntread"] = Integer{Context{}.Threads()}; |
| 516 | dconfig["missing"] = Number{std::numeric_limits<float>::quiet_NaN()}; |
| 517 | |
| 518 | auto check_result = [n_features, &ctx](std::shared_ptr<DMatrix> Xy, StringView s_out_data, |
| 519 | StringView s_out_indptr) { |
| 520 | auto i_out_data = ArrayInterface<1, false>{s_out_data}; |
| 521 | ASSERT_EQ(i_out_data.type, ArrayInterfaceHandler::kF4); |
| 522 | auto out_data = static_cast<float const *>(i_out_data.data); |
| 523 | ASSERT_TRUE(out_data); |
| 524 | |
| 525 | auto i_out_indptr = ArrayInterface<1, false>{s_out_indptr}; |
| 526 | ASSERT_EQ(i_out_indptr.type, ArrayInterfaceHandler::kU8); |
| 527 | auto out_indptr = static_cast<std::uint64_t const *>(i_out_indptr.data); |
| 528 | ASSERT_TRUE(out_data); |
| 529 | |
| 530 | if (ctx->IsCPU()) { |
| 531 | CheckResult<GHistIndexMatrix>(ctx, n_features, Xy, out_data, out_indptr); |
| 532 | } else { |
| 533 | CheckResult<EllpackPage>(ctx, n_features, Xy, out_data, out_indptr); |
| 534 | } |
| 535 | }; |
| 536 | |
| 537 | Json config{Null{}}; |
| 538 | std::string s_config; |
| 539 | Json::Dump(config, &s_config); |
| 540 | char const *out_indptr; |
| 541 | char const *out_data; |
| 542 | |
| 543 | { |
| 544 | // SimpleDMatrix |
| 545 | auto [p_fmat, Xy] = MakeSimpleDMatrixForTest(n_samples, n_features, dconfig); |
| 546 | // assert fail, we don't have the quantile yet. |
| 547 | ASSERT_EQ(XGDMatrixGetQuantileCut(p_fmat, s_config.c_str(), &out_indptr, &out_data), -1); |
| 548 | |
| 549 | std::array<DMatrixHandle, 1> mats{p_fmat}; |
| 550 | BoosterHandle booster; |
| 551 | ASSERT_EQ(XGBoosterCreate(mats.data(), 1, &booster), 0); |
| 552 | ASSERT_EQ(XGBoosterSetParam(booster, "max_bin", "16"), 0); |
| 553 | if (ctx->IsCUDA()) { |
| 554 | ASSERT_EQ(XGBoosterSetParam(booster, "device", ctx->DeviceName().c_str()), 0); |
| 555 | } |
| 556 | ASSERT_EQ(XGBoosterUpdateOneIter(booster, 0, p_fmat), 0); |
| 557 | ASSERT_EQ(XGDMatrixGetQuantileCut(p_fmat, s_config.c_str(), &out_indptr, &out_data), 0); |
| 558 | |
| 559 | check_result(Xy, out_data, out_indptr); |
| 560 | |
| 561 | XGDMatrixFree(p_fmat); |
| 562 | XGBoosterFree(booster); |
| 563 | } |
| 564 | |
| 565 | { |
| 566 | // IterativeDMatrix |
| 567 | auto [p_fmat, Xy] = MakeQDMForTest(ctx, n_samples, n_features, dconfig); |
no test coverage detected