methods to delete an attribute and get names of available attributes
This commit is contained in:
@@ -685,7 +685,28 @@ int XGBoosterSetAttr(BoosterHandle handle,
|
||||
const char* value) {
|
||||
Booster* bst = static_cast<Booster*>(handle);
|
||||
API_BEGIN();
|
||||
bst->learner()->SetAttr(key, value);
|
||||
if (value == nullptr) {
|
||||
bst->learner()->DelAttr(key);
|
||||
} else {
|
||||
bst->learner()->SetAttr(key, value);
|
||||
}
|
||||
API_END();
|
||||
}
|
||||
|
||||
int XGBoosterGetAttrNames(BoosterHandle handle,
|
||||
bst_ulong* out_len,
|
||||
const char*** out) {
|
||||
std::vector<std::string>& str_vecs = XGBAPIThreadLocalStore::Get()->ret_vec_str;
|
||||
std::vector<const char*>& charp_vecs = XGBAPIThreadLocalStore::Get()->ret_vec_charp;
|
||||
Booster *bst = static_cast<Booster*>(handle);
|
||||
API_BEGIN();
|
||||
str_vecs = bst->learner()->GetAttrNames();
|
||||
charp_vecs.resize(str_vecs.size());
|
||||
for (size_t i = 0; i < str_vecs.size(); ++i) {
|
||||
charp_vecs[i] = str_vecs[i].c_str();
|
||||
}
|
||||
*out = dmlc::BeginPtr(charp_vecs);
|
||||
*out_len = static_cast<bst_ulong>(charp_vecs.size());
|
||||
API_END();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user