treelite
code_folder_template.h
Go to the documentation of this file.
1 
8 #ifndef TREELITE_COMPILER_NATIVE_CODE_FOLDER_TEMPLATE_H_
9 #define TREELITE_COMPILER_NATIVE_CODE_FOLDER_TEMPLATE_H_
10 
11 namespace treelite {
12 namespace compiler {
13 namespace native {
14 
15 const char* eval_loop_template =
16 R"TREELITETEMPLATE(
17 nid = 0;
18 while (nid >= 0) {{ /* negative nid implies leaf */
19  fid = {node_array_name}[nid].split_index;
20  if (data[fid].missing == -1) {{
21  cond = {node_array_name}[nid].default_left;
22  }} else if (is_categorical[fid]) {{
23  tmp = (unsigned int)data[fid].fvalue;
24  cond = ({cat_bitmap_name}[{cat_begin_name}[nid] + tmp / 64] >> (tmp % 64)) & 1;
25  }} else {{
26  cond = (data[fid].{data_field} {comp_op} {node_array_name}[nid].threshold);
27  }}
28  nid = cond ? {node_array_name}[nid].left_child : {node_array_name}[nid].right_child;
29 }}
30 
31 {output_switch_statement}
32 )TREELITETEMPLATE";
33 
34 const char* code_folder_arrays_template =
35 R"TREELITETEMPLATE(
36 const struct Node {node_array_name}[] = {{
37 {array_nodes}
38 }};
39 
40 const uint64_t {cat_bitmap_name}[] = {{
41 {array_cat_bitmap}
42 }};
43 
44 const size_t {cat_begin_name}[] = {{
45 {array_cat_begin}
46 }};
47 )TREELITETEMPLATE";
48 
49 const char* code_folder_arrays_declaration_template =
50 R"TREELITETEMPLATE(
51 extern const struct Node {node_array_name}[];
52 extern const uint64_t {cat_bitmap_name}[];
53 extern const size_t {cat_begin_name}[];
54 )TREELITETEMPLATE";
55 
56 } // namespace native
57 } // namespace compiler
58 } // namespace treelite
59 #endif // TREELITE_COMPILER_NATIVE_CODE_FOLDER_TEMPLATE_H_