зеркало из https://github.com/microsoft/LightGBM.git
[swig] add wrapper for LGBM_DatasetGetFeatureNames (#4103)
This commit is contained in:
Родитель
98e5a210c0
Коммит
434573eef2
|
@ -104,4 +104,44 @@
|
|||
|
||||
return strings.release();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Wraps LGBM_DatasetGetFeatureNames. Has the same limitations as a
|
||||
* LGBM_BoosterGetFeatureNames:
|
||||
*
|
||||
* Allocates a new StringArray. You must free it yourself if it succeeds.
|
||||
* @see StringArrayHandle_free().
|
||||
* In case of failure such resource is freed and nullptr is returned.
|
||||
* Check for that case with null (lightgbmlib) or 0 (lightgbmlibJNI).
|
||||
*
|
||||
* @param handle Booster handle
|
||||
* @return StringArrayHandle with the feature names (or nullptr in case of error)
|
||||
*/
|
||||
StringArrayHandle LGBM_DatasetGetFeatureNamesSWIG(BoosterHandle handle)
|
||||
{
|
||||
int num_features;
|
||||
size_t max_feature_name_size;
|
||||
std::unique_ptr<StringArray> strings(nullptr);
|
||||
|
||||
// Retrieve required allocation space:
|
||||
API_OK_OR_NULL(LGBM_DatasetGetFeatureNames(handle,
|
||||
0, &num_features,
|
||||
0, &max_feature_name_size,
|
||||
nullptr));
|
||||
try {
|
||||
strings.reset(new StringArray(num_features, max_feature_name_size));
|
||||
} catch (std::bad_alloc &e) {
|
||||
LGBM_SetLastError("Failure to allocate memory.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
API_OK_OR_NULL(LGBM_DatasetGetFeatureNames(handle,
|
||||
num_features, &num_features,
|
||||
max_feature_name_size, &max_feature_name_size,
|
||||
strings->data()));
|
||||
|
||||
return strings.release();
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
Загрузка…
Ссылка в новой задаче