Medial Code Documentation
Loading...
Searching...
No Matches
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) \
51namespace dmlc { \
52namespace parameter { \
53template <> \
54class 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
82namespace xgboost {
83template <typename Type>
84struct XGBoostParameter : public dmlc::Parameter<Type> {
85 protected:
86 bool initialised_ {false};
87
88 public:
89 template <typename Container>
90 Args UpdateAllowUnknown(Container const& kwargs) {
91 if (initialised_) {
92 return dmlc::Parameter<Type>::UpdateAllowUnknown(kwargs);
93 } else {
94 auto unknown = dmlc::Parameter<Type>::InitAllowUnknown(kwargs);
95 initialised_ = true;
96 return unknown;
97 }
98 }
99 bool GetInitialised() const { return static_cast<bool>(this->initialised_); }
100};
101} // namespace xgboost
102
103#endif // XGBOOST_PARAMETER_H_
Provide lightweight util to do parameter setup and checking.
Copyright 2015-2023 by XGBoost Contributors.
namespace of xgboost
Definition base.h:90
Definition parameter.h:84