Generate auto config file. Parameters ---------- config_hpp : string Path to the config header file. config_out_cpp : string Path to the auto config file. Returns ------- infos : tuple Tuple with names and content of sections.
(config_hpp, config_out_cpp)
| 242 | |
| 243 | |
| 244 | def gen_parameter_code(config_hpp, config_out_cpp): |
| 245 | """Generate auto config file. |
| 246 | |
| 247 | Parameters |
| 248 | ---------- |
| 249 | config_hpp : string |
| 250 | Path to the config header file. |
| 251 | config_out_cpp : string |
| 252 | Path to the auto config file. |
| 253 | |
| 254 | Returns |
| 255 | ------- |
| 256 | infos : tuple |
| 257 | Tuple with names and content of sections. |
| 258 | """ |
| 259 | keys, infos = get_parameter_infos(config_hpp) |
| 260 | names = get_names(infos) |
| 261 | alias = get_alias(infos) |
| 262 | str_to_write = r"""/*! |
| 263 | * Copyright (c) 2018 Microsoft Corporation. All rights reserved. |
| 264 | * Licensed under the MIT License. See LICENSE file in the project root for license information. |
| 265 | * |
| 266 | * \note |
| 267 | * This file is auto generated by LightGBM\helpers\parameter_generator.py from LightGBM\include\LightGBM\config.h file. |
| 268 | */ |
| 269 | """ |
| 270 | str_to_write += "#include<LightGBM/config.h>\nnamespace LightGBM {\n" |
| 271 | # alias table |
| 272 | str_to_write += "std::unordered_map<std::string, std::string> Config::alias_table({\n" |
| 273 | for pair in alias: |
| 274 | str_to_write += " {\"%s\", \"%s\"},\n" % (pair[0], pair[1]) |
| 275 | str_to_write += "});\n\n" |
| 276 | # names |
| 277 | str_to_write += "std::unordered_set<std::string> Config::parameter_set({\n" |
| 278 | for name in names: |
| 279 | str_to_write += " \"%s\",\n" % (name) |
| 280 | str_to_write += "});\n\n" |
| 281 | # from strings |
| 282 | str_to_write += "void Config::GetMembersFromString(const std::unordered_map<std::string, std::string>& params) {\n" |
| 283 | str_to_write += " std::string tmp_str = \"\";\n" |
| 284 | for x in infos: |
| 285 | for y in x: |
| 286 | if "[doc-only]" in y: |
| 287 | continue |
| 288 | param_type = y["inner_type"][0] |
| 289 | name = y["name"][0] |
| 290 | checks = [] |
| 291 | if "check" in y: |
| 292 | checks = y["check"] |
| 293 | tmp = set_one_var_from_string(name, param_type, checks) |
| 294 | str_to_write += tmp |
| 295 | # tails |
| 296 | str_to_write = str_to_write.strip() + "\n}\n\n" |
| 297 | str_to_write += "std::string Config::SaveMembersToString() const {\n" |
| 298 | str_to_write += " std::stringstream str_buf;\n" |
| 299 | for x in infos: |
| 300 | for y in x: |
| 301 | if "[doc-only]" in y: |
no test coverage detected