xgboost

parameter.h
Go to the documentation of this file.
1
8 #ifndef XGBOOST_PARAMETER_H_
9 #define XGBOOST_PARAMETER_H_
10
11 #include <dmlc/parameter.h>
12 #include <xgboost/base.h>
13 #include <string>
14 #include <type_traits>
15
50 #define DECLARE_FIELD_ENUM_CLASS(EnumClass) \
51 namespace dmlc { \
52 namespace parameter { \
53 template <> \
54 class FieldEntry<EnumClass> : public FieldEntry<int> { \
55 public: \
56 FieldEntry<EnumClass>() { \
57 static_assert( \
58 std::is_same<int, typename std::underlying_type<EnumClass>::type>::value, \
59 "enum class must be backed by int"); \
60 is_enum_ = true; \
61 } \
62 using Super = FieldEntry<int>; \
63 void Set(void *head, const std::string &value) const override { \
64 Super::Set(head, value); \
65 } \
66 inline FieldEntry<EnumClass>& add_enum(const std::string &key, EnumClass value) { \
67 Super::add_enum(key, static_cast<int>(value)); \
68 return *this; \
69 } \
70 inline FieldEntry<EnumClass>& set_default(const EnumClass& default_value) { \
71 default_value_ = static_cast<int>(default_value); \
72 has_default_ = true; \
73 return *this; \
74 } \
75 inline void Init(const std::string &key, void *head, EnumClass& ref) { /* NOLINT */ \
76 Super::Init(key, head, *reinterpret_cast<int*>(&ref)); \
77 } \
78 }; \
79 } /* namespace parameter */ \
80 } /* namespace dmlc */
81
82 namespace xgboost {
83 template <typename Type>
84 struct XGBoostParameter : public dmlc::Parameter<Type> {
85 protected:
86 bool initialised_ {false};
87
88 public:
89 template <typename Container>
90 Args UpdateAllowUnknown(Container const& kwargs, bool* out_changed = nullptr) {
91 if (initialised_) {
92 return dmlc::Parameter<Type>::UpdateAllowUnknown(kwargs, out_changed);
93 } else {
94 auto unknown = dmlc::Parameter<Type>::InitAllowUnknown(kwargs);
95 if (out_changed) {
96 *out_changed = true;
97 }
98 initialised_ = true;
99 return unknown;
100 }
101 }
102 bool GetInitialised() const { return static_cast<bool>(this->initialised_); }
103 };
104 } // namespace xgboost
105
106 #endif // XGBOOST_PARAMETER_H_
xgboost::XGBoostParameter::initialised_
bool initialised_
Definition: parameter.h:86
xgboost::XGBoostParameter
Definition: parameter.h:84
xgboost::XGBoostParameter::UpdateAllowUnknown
Args UpdateAllowUnknown(Container const &kwargs, bool *out_changed=nullptr)
Definition: parameter.h:90
xgboost::Args
std::vector< std::pair< std::string, std::string > > Args
Definition: base.h:245
xgboost
namespace of xgboost
Definition: base.h:102
base.h
defines configuration macros of xgboost.
xgboost::XGBoostParameter::GetInitialised
bool GetInitialised() const
Definition: parameter.h:102