MCPcopy Create free account
hub / github.com/dmlc/treelite / test_invalid_node_id

Function test_invalid_node_id

tests/python/test_model_builder.py:44–85  ·  view source on GitHub ↗

Test for invalid node IDs

()

Source from the content-addressed store, hash-verified

42
43
44def test_invalid_node_id():
45 """Test for invalid node IDs"""
46 builder = ModelBuilder(
47 threshold_type="float32",
48 leaf_output_type="float32",
49 metadata=Metadata(
50 num_feature=1,
51 task_type="kBinaryClf",
52 average_tree_output=False,
53 num_target=1,
54 num_class=[1],
55 leaf_vector_shape=(1, 1),
56 ),
57 tree_annotation=TreeAnnotation(num_tree=1, target_id=[0], class_id=[0]),
58 postprocessor=PostProcessorFunc(name="sigmoid"),
59 base_scores=[0.0],
60 )
61 builder.start_tree()
62 with pytest.raises(TreeliteError):
63 builder.start_node(-1)
64 builder.start_node(0)
65
66 def invalid_numerical_test(left_child_key, right_child_key):
67 builder.numerical_test(
68 feature_id=0,
69 threshold=0.0,
70 default_left=True,
71 opname="<",
72 left_child_key=left_child_key,
73 right_child_key=right_child_key,
74 )
75
76 with pytest.raises(TreeliteError):
77 invalid_numerical_test(0, 1)
78 with pytest.raises(TreeliteError):
79 invalid_numerical_test(2, 2)
80 with pytest.raises(TreeliteError):
81 invalid_numerical_test(-1, -2)
82 with pytest.raises(TreeliteError):
83 invalid_numerical_test(-1, 2)
84 with pytest.raises(TreeliteError):
85 invalid_numerical_test(2, -1)
86
87
88@pytest.mark.parametrize("predict_kind", ["default", "raw", "leaf_id"])

Callers

nothing calls this directly

Calls 7

start_treeMethod · 0.95
start_nodeMethod · 0.95
ModelBuilderClass · 0.90
MetadataClass · 0.90
TreeAnnotationClass · 0.90
PostProcessorFuncClass · 0.90
invalid_numerical_testFunction · 0.85

Tested by

no test coverage detected