| 133 | |
| 134 | namespace { |
| 135 | void TestColumnSplitPartitioner(size_t n_samples, size_t base_rowid, std::shared_ptr<DMatrix> Xy, |
| 136 | std::vector<float>* hess, float min_value, float mid_value, |
| 137 | CommonRowPartitioner const& expected_mid_partitioner) { |
| 138 | auto dmat = |
| 139 | std::unique_ptr<DMatrix>{Xy->SliceCol(collective::GetWorldSize(), collective::GetRank())}; |
| 140 | std::vector<CPUExpandEntry> candidates{{0, 0}}; |
| 141 | candidates.front().split.loss_chg = 0.4; |
| 142 | |
| 143 | Context ctx; |
| 144 | ctx.InitAllowUnknown(Args{}); |
| 145 | for (auto const& page : dmat->GetBatches<GHistIndexMatrix>(&ctx, {64, *hess, true})) { |
| 146 | { |
| 147 | RegTree tree; |
| 148 | CommonRowPartitioner partitioner{&ctx, n_samples, base_rowid, true}; |
| 149 | GetSplit(&tree, min_value, &candidates); |
| 150 | partitioner.UpdatePosition(&ctx, page, candidates, tree.HostScView()); |
| 151 | ASSERT_EQ(partitioner.Size(), 3); |
| 152 | ASSERT_EQ(partitioner[1].Size(), 0); |
| 153 | ASSERT_EQ(partitioner[2].Size(), n_samples); |
| 154 | } |
| 155 | { |
| 156 | CommonRowPartitioner partitioner{&ctx, n_samples, base_rowid, true}; |
| 157 | RegTree tree; |
| 158 | GetSplit(&tree, mid_value, &candidates); |
| 159 | partitioner.UpdatePosition(&ctx, page, candidates, tree.HostScView()); |
| 160 | { |
| 161 | auto left_nidx = tree[RegTree::kRoot].LeftChild(); |
| 162 | auto const& elem = partitioner[left_nidx]; |
| 163 | ASSERT_LT(elem.Size(), n_samples); |
| 164 | ASSERT_GT(elem.Size(), 1); |
| 165 | auto const& expected_elem = expected_mid_partitioner[left_nidx]; |
| 166 | ASSERT_EQ(elem.Size(), expected_elem.Size()); |
| 167 | for (auto it = elem.begin(), eit = expected_elem.begin(); it != elem.end(); ++it, ++eit) { |
| 168 | ASSERT_EQ(*it, *eit); |
| 169 | } |
| 170 | } |
| 171 | { |
| 172 | auto right_nidx = tree[RegTree::kRoot].RightChild(); |
| 173 | auto const& elem = partitioner[right_nidx]; |
| 174 | auto const& expected_elem = expected_mid_partitioner[right_nidx]; |
| 175 | ASSERT_EQ(elem.Size(), expected_elem.Size()); |
| 176 | for (auto it = elem.begin(), eit = expected_elem.begin(); it != elem.end(); ++it, ++eit) { |
| 177 | ASSERT_EQ(*it, *eit); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } // anonymous namespace |
| 184 | |
| 185 | TEST(Approx, PartitionerColumnSplit) { |
no test coverage detected