(
self,
booster: xgb.Booster,
dtrain: xgb.DMatrix,
num_parallel_tree: int,
num_classes: int,
num_boost_round: int,
use_np_type: bool,
)
| 270 | assert d.find(r"feature \"2\"") != -1 |
| 271 | |
| 272 | def run_slice( |
| 273 | self, |
| 274 | booster: xgb.Booster, |
| 275 | dtrain: xgb.DMatrix, |
| 276 | num_parallel_tree: int, |
| 277 | num_classes: int, |
| 278 | num_boost_round: int, |
| 279 | use_np_type: bool, |
| 280 | ): |
| 281 | beg = 3 |
| 282 | if use_np_type: |
| 283 | end: Integer = np.int32(7) |
| 284 | else: |
| 285 | end = 7 |
| 286 | |
| 287 | sliced: xgb.Booster = booster[beg:end] |
| 288 | assert sliced.feature_types == booster.feature_types |
| 289 | |
| 290 | sliced_trees = (end - beg) * num_parallel_tree * num_classes |
| 291 | assert sliced_trees == len(sliced.get_dump()) |
| 292 | |
| 293 | sliced_trees = sliced_trees // 2 |
| 294 | sliced = booster[beg:end:2] |
| 295 | assert sliced_trees == len(sliced.get_dump()) |
| 296 | |
| 297 | sliced = booster[beg:] |
| 298 | sliced_trees = (num_boost_round - beg) * num_parallel_tree * num_classes |
| 299 | assert sliced_trees == len(sliced.get_dump()) |
| 300 | |
| 301 | sliced = booster[beg:] |
| 302 | sliced_trees = (num_boost_round - beg) * num_parallel_tree * num_classes |
| 303 | assert sliced_trees == len(sliced.get_dump()) |
| 304 | |
| 305 | sliced = booster[:end] |
| 306 | sliced_trees = end * num_parallel_tree * num_classes |
| 307 | assert sliced_trees == len(sliced.get_dump()) |
| 308 | |
| 309 | sliced = booster[:end] |
| 310 | sliced_trees = end * num_parallel_tree * num_classes |
| 311 | assert sliced_trees == len(sliced.get_dump()) |
| 312 | |
| 313 | with pytest.raises(ValueError, match=r">= 0"): |
| 314 | booster[-1:0] |
| 315 | |
| 316 | # we do not accept empty slice. |
| 317 | with pytest.raises(ValueError, match="Empty slice"): |
| 318 | booster[1:1] |
| 319 | # stop can not be smaller than begin |
| 320 | with pytest.raises(ValueError, match=r"Invalid.*"): |
| 321 | booster[3:0] |
| 322 | with pytest.raises(ValueError, match=r"Invalid.*"): |
| 323 | booster[3:-1] |
| 324 | # negative step is not supported. |
| 325 | with pytest.raises(ValueError, match=r".*>= 1.*"): |
| 326 | booster[0:2:-1] |
| 327 | # step can not be 0. |
| 328 | with pytest.raises(ValueError, match=r".*>= 1.*"): |
| 329 | booster[0:2:0] |
no test coverage detected