@@ -16,20 +16,6 @@ TEST(Tree, ModelShape) {
1616 RegTree tree{1u , n_features};
1717 ASSERT_EQ (tree.NumFeatures (), n_features);
1818
19- dmlc::TemporaryDirectory tempdir;
20- const std::string tmp_file = tempdir.path + " /tree.model" ;
21- {
22- // binary dump
23- std::unique_ptr<dmlc::Stream> fo (dmlc::Stream::Create (tmp_file.c_str (), " w" ));
24- tree.Save (fo.get ());
25- }
26- {
27- // binary load
28- RegTree new_tree;
29- std::unique_ptr<dmlc::Stream> fi (dmlc::Stream::Create (tmp_file.c_str (), " r" ));
30- new_tree.Load (fi.get ());
31- ASSERT_EQ (new_tree.NumFeatures (), n_features);
32- }
3319 {
3420 // json
3521 Json j_tree{Object{}};
@@ -56,88 +42,6 @@ TEST(Tree, ModelShape) {
5642 }
5743}
5844
59- #if DMLC_IO_NO_ENDIAN_SWAP // skip on big-endian machines
60- // Manually construct tree in binary format
61- // Do not use structs in case they change
62- // We want to preserve backwards compatibility
63- TEST (Tree, Load) {
64- dmlc::TemporaryDirectory tempdir;
65- const std::string tmp_file = tempdir.path + " /tree.model" ;
66- std::unique_ptr<dmlc::Stream> fo (dmlc::Stream::Create (tmp_file.c_str (), " w" ));
67-
68- // Write params
69- EXPECT_EQ (sizeof (TreeParam), (31 + 6 ) * sizeof (int ));
70- int num_roots = 1 ;
71- int num_nodes = 2 ;
72- int num_deleted = 0 ;
73- int max_depth = 1 ;
74- int num_feature = 0 ;
75- int size_leaf_vector = 0 ;
76- int reserved[31 ];
77- fo->Write (&num_roots, sizeof (int ));
78- fo->Write (&num_nodes, sizeof (int ));
79- fo->Write (&num_deleted, sizeof (int ));
80- fo->Write (&max_depth, sizeof (int ));
81- fo->Write (&num_feature, sizeof (int ));
82- fo->Write (&size_leaf_vector, sizeof (int ));
83- fo->Write (reserved, sizeof (int ) * 31 );
84-
85- // Write 2 nodes
86- EXPECT_EQ (sizeof (RegTree::Node),
87- 3 * sizeof (int ) + 1 * sizeof (unsigned ) + sizeof (float ));
88- int parent = -1 ;
89- int cleft = 1 ;
90- int cright = -1 ;
91- unsigned sindex = 5 ;
92- float split_or_weight = 0.5 ;
93- fo->Write (&parent, sizeof (int ));
94- fo->Write (&cleft, sizeof (int ));
95- fo->Write (&cright, sizeof (int ));
96- fo->Write (&sindex, sizeof (unsigned ));
97- fo->Write (&split_or_weight, sizeof (float ));
98- parent = 0 ;
99- cleft = -1 ;
100- cright = -1 ;
101- sindex = 2 ;
102- split_or_weight = 0.1 ;
103- fo->Write (&parent, sizeof (int ));
104- fo->Write (&cleft, sizeof (int ));
105- fo->Write (&cright, sizeof (int ));
106- fo->Write (&sindex, sizeof (unsigned ));
107- fo->Write (&split_or_weight, sizeof (float ));
108-
109- // Write 2x node stats
110- EXPECT_EQ (sizeof (RTreeNodeStat), 3 * sizeof (float ) + sizeof (int ));
111- bst_float loss_chg = 5.0 ;
112- bst_float sum_hess = 1.0 ;
113- bst_float base_weight = 3.0 ;
114- int leaf_child_cnt = 0 ;
115- fo->Write (&loss_chg, sizeof (float ));
116- fo->Write (&sum_hess, sizeof (float ));
117- fo->Write (&base_weight, sizeof (float ));
118- fo->Write (&leaf_child_cnt, sizeof (int ));
119-
120- loss_chg = 50.0 ;
121- sum_hess = 10.0 ;
122- base_weight = 30.0 ;
123- leaf_child_cnt = 0 ;
124- fo->Write (&loss_chg, sizeof (float ));
125- fo->Write (&sum_hess, sizeof (float ));
126- fo->Write (&base_weight, sizeof (float ));
127- fo->Write (&leaf_child_cnt, sizeof (int ));
128- fo.reset ();
129- std::unique_ptr<dmlc::Stream> fi (dmlc::Stream::Create (tmp_file.c_str (), " r" ));
130-
131- xgboost::RegTree tree;
132- tree.Load (fi.get ());
133- EXPECT_EQ (tree.GetDepth (1 ), 1 );
134- EXPECT_EQ (tree[0 ].SplitCond (), 0 .5f );
135- EXPECT_EQ (tree[0 ].SplitIndex (), 5ul );
136- EXPECT_EQ (tree[1 ].LeafValue (), 0 .1f );
137- EXPECT_TRUE (tree[1 ].IsLeaf ());
138- }
139- #endif // DMLC_IO_NO_ENDIAN_SWAP
140-
14145TEST (Tree, AllocateNode) {
14246 RegTree tree;
14347 tree.ExpandNode (0 , 0 , 0 .0f , false , 0 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f ,
0 commit comments