Treelite
base.h
Go to the documentation of this file.
1 
7 #ifndef TREELITE_BASE_H_
8 #define TREELITE_BASE_H_
9 
10 #include <cstdint>
11 #include <typeinfo>
12 #include <string>
13 #include <unordered_map>
14 #include <stdexcept>
15 #include "./typeinfo.h"
16 
17 namespace treelite {
18 
20 typedef float tl_float;
22 enum class SplitFeatureType : int8_t {
23  kNone, kNumerical, kCategorical
24 };
26 enum class Operator : int8_t {
27  kNone,
28  kEQ,
29  kLT,
30  kLE,
31  kGT,
32  kGE,
33 };
34 
36 extern const std::unordered_map<std::string, Operator> optable;
37 
43 inline std::string OpName(Operator op) {
44  switch (op) {
45  case Operator::kEQ: return "==";
46  case Operator::kLT: return "<";
47  case Operator::kLE: return "<=";
48  case Operator::kGT: return ">";
49  case Operator::kGE: return ">=";
50  default: return "";
51  }
52 }
53 
62 template <typename ElementType, typename ThresholdType>
63 inline bool CompareWithOp(ElementType lhs, Operator op, ThresholdType rhs) {
64  switch (op) {
65  case Operator::kEQ: return lhs == rhs;
66  case Operator::kLT: return lhs < rhs;
67  case Operator::kLE: return lhs <= rhs;
68  case Operator::kGT: return lhs > rhs;
69  case Operator::kGE: return lhs >= rhs;
70  default:
71  throw std::runtime_error("operator undefined");
72  return false;
73  }
74 }
75 
76 } // namespace treelite
77 
78 #endif // TREELITE_BASE_H_
SplitFeatureType
feature split type
Definition: base.h:22
float tl_float
float type to be used internally
Definition: base.h:20
std::string OpName(Operator op)
get string representation of comparison operator
Definition: base.h:43
bool CompareWithOp(ElementType lhs, Operator op, ThresholdType rhs)
perform comparison between two float&#39;s using a comparsion operator The comparison will be in the form...
Definition: base.h:63
Defines TypeInfo class and utilities.
const std::unordered_map< std::string, Operator > optable
conversion table from string to Operator, defined in tables.cc
Definition: optable.cc:14
Operator
comparison operators
Definition: base.h:26