Treelite
typeinfo_ctypes.h
Go to the documentation of this file.
1 
9 #ifndef TREELITE_COMPILER_NATIVE_TYPEINFO_CTYPES_H_
10 #define TREELITE_COMPILER_NATIVE_TYPEINFO_CTYPES_H_
11 
12 #include <treelite/base.h>
13 #include <string>
14 
15 namespace treelite {
16 namespace compiler {
17 namespace native {
18 
24 inline std::string TypeInfoToCTypeString(TypeInfo type) {
25  switch (type) {
26  case TypeInfo::kInvalid:
27  throw std::runtime_error("Invalid type");
28  return "";
29  case TypeInfo::kUInt32:
30  return "uint32_t";
31  case TypeInfo::kFloat32:
32  return "float";
33  case TypeInfo::kFloat64:
34  return "double";
35  default:
36  throw std::runtime_error(std::string("Unrecognized type: ")
37  + std::to_string(static_cast<int>(type)));
38  return "";
39  }
40 }
41 
47 inline std::string CExpForTypeInfo(TypeInfo type) {
48  switch (type) {
49  case TypeInfo::kInvalid:
50  case TypeInfo::kUInt32:
51  throw std::runtime_error(std::string("Invalid type: ") + TypeInfoToString(type));
52  return "";
53  case TypeInfo::kFloat32:
54  return "expf";
55  case TypeInfo::kFloat64:
56  return "exp";
57  default:
58  throw std::runtime_error(std::string("Unrecognized type: ")
59  + std::to_string(static_cast<int>(type)));
60  return "";
61  }
62 }
63 
69 inline std::string CExp2ForTypeInfo(TypeInfo type) {
70  switch (type) {
71  case TypeInfo::kInvalid:
72  case TypeInfo::kUInt32:
73  throw std::runtime_error(std::string("Invalid type: ") + TypeInfoToString(type));
74  return "";
75  case TypeInfo::kFloat32:
76  return "exp2f";
77  case TypeInfo::kFloat64:
78  return "exp2";
79  default:
80  throw std::runtime_error(std::string("Unrecognized type: ")
81  + std::to_string(static_cast<int>(type)));
82  return "";
83  }
84 }
85 
91 inline std::string CCopySignForTypeInfo(TypeInfo type) {
92  switch (type) {
93  case TypeInfo::kInvalid:
94  case TypeInfo::kUInt32:
95  throw std::runtime_error(std::string("Invalid type: ") + TypeInfoToString(type));
96  return "";
97  case TypeInfo::kFloat32:
98  return "copysignf";
99  case TypeInfo::kFloat64:
100  return "copysign";
101  default:
102  throw std::runtime_error(std::string("Unrecognized type: ")
103  + std::to_string(static_cast<int>(type)));
104  return "";
105  }
106 }
107 
113 inline std::string CLog1PForTypeInfo(TypeInfo type) {
114  switch (type) {
115  case TypeInfo::kInvalid:
116  case TypeInfo::kUInt32:
117  throw std::runtime_error(std::string("Invalid type: ") + TypeInfoToString(type));
118  return "";
119  case TypeInfo::kFloat32:
120  return "log1pf";
121  case TypeInfo::kFloat64:
122  return "log1p";
123  default:
124  throw std::runtime_error(std::string("Unrecognized type: ")
125  + std::to_string(static_cast<int>(type)));
126  return "";
127  }
128 }
129 
130 } // namespace native
131 } // namespace compiler
132 } // namespace treelite
133 #endif // TREELITE_COMPILER_NATIVE_TYPEINFO_CTYPES_H_
std::string CCopySignForTypeInfo(TypeInfo type)
Look up the correct variant of copysign() in C that should be used with a given type.
std::string CExp2ForTypeInfo(TypeInfo type)
Look up the correct variant of exp2() in C that should be used with a given type. ...
TypeInfo
Types used by thresholds and leaf outputs.
Definition: typeinfo.h:22
std::string TypeInfoToString(treelite::TypeInfo type)
Get string representation of type info.
Definition: typeinfo.h:39
std::string CExpForTypeInfo(TypeInfo type)
Look up the correct variant of exp() in C that should be used with a given type.
defines configuration macros of Treelite
std::string TypeInfoToCTypeString(TypeInfo type)
Get string representation of the C type that&#39;s equivalent to the given type info. ...
std::string CLog1PForTypeInfo(TypeInfo type)
Look up the correct variant of log1p() in C that should be used with a given type.