Extract make metric name from ranking metric. (#8768)
- Extract the metric parsing routine from ranking. - Add a test. - Accept null for string view.
This commit is contained in:
29
src/common/ranking_utils.h
Normal file
29
src/common/ranking_utils.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright 2023 by XGBoost contributors
|
||||
*/
|
||||
#ifndef XGBOOST_COMMON_RANKING_UTILS_H_
|
||||
#define XGBOOST_COMMON_RANKING_UTILS_H_
|
||||
|
||||
#include <cstddef> // std::size_t
|
||||
#include <cstdint> // std::uint32_t
|
||||
#include <string> // std::string
|
||||
|
||||
#include "xgboost/string_view.h" // StringView
|
||||
|
||||
namespace xgboost {
|
||||
namespace ltr {
|
||||
/**
|
||||
* \brief Construct name for ranking metric given parameters.
|
||||
*
|
||||
* \param [in] name Null terminated string for metric name
|
||||
* \param [in] param Null terminated string for parameter like the `3-` in `ndcg@3-`.
|
||||
* \param [out] topn Top n documents parsed from param. Unchanged if it's not specified.
|
||||
* \param [out] minus Whether we should turn the score into loss. Unchanged if it's not
|
||||
* specified.
|
||||
*
|
||||
* \return The name of the metric.
|
||||
*/
|
||||
std::string MakeMetricName(StringView name, StringView param, std::uint32_t* topn, bool* minus);
|
||||
} // namespace ltr
|
||||
} // namespace xgboost
|
||||
#endif // XGBOOST_COMMON_RANKING_UTILS_H_
|
||||
Reference in New Issue
Block a user