Check that multi-target rows are consistently sampled and return count.
| 15 | namespace xgboost::tree { |
| 16 | // Check that multi-target rows are consistently sampled and return count. |
| 17 | inline bst_idx_t CheckSampledRows(linalg::MatrixView<GradientPair const> gpair_0, |
| 18 | linalg::MatrixView<GradientPair const> gpair_1) { |
| 19 | CHECK_EQ(gpair_0.Shape(0), gpair_1.Shape(0)); |
| 20 | CHECK_GE(gpair_1.Shape(1), gpair_1.Shape(1)); |
| 21 | auto n_samples = gpair_0.Shape(0); |
| 22 | auto n_targets = gpair_1.Shape(1); |
| 23 | bst_idx_t sampled_count = 0; |
| 24 | for (std::size_t i = 0; i < n_samples; ++i) { |
| 25 | bool first_is_zero = gpair_0(i, 0).GetHess() == 0.0f; |
| 26 | for (bst_target_t t = 0; t < n_targets; ++t) { |
| 27 | bool is_zero = (gpair_1(i, t).GetGrad() == 0.0f && gpair_1(i, t).GetHess() == 0.0f); |
| 28 | EXPECT_EQ(first_is_zero, is_zero); |
| 29 | } |
| 30 | if (!first_is_zero) { |
| 31 | ++sampled_count; |
| 32 | } |
| 33 | } |
| 34 | return sampled_count; |
| 35 | } |
| 36 | |
| 37 | // Check that sampling mask was correctly applied from split gradient to value gradient. |
| 38 | inline void CheckSamplingMask(linalg::MatrixView<GradientPair> h_split, |
no test coverage detected