Skip to content

[python-package] Keep constants in sync with C++ library #4321

Closed

Description

Relevant only when #4089 is merged.

Summary

Find a way to keep constants in Python package in sync with C++ library.

This is needed in order to keep python package behaves the same as the cmdline version.

Motivation

#4089 handles data sampling in Python. It defines 2 constant variables ZERO_THRESHOLD and DEFAULT_BIN_CONSTRUCT_SAMPLE_CNT.

Currently they are set to the same value as in C++. If the default value changs in C++ side, we have to manually change them in Python side.

Description

I suggest we expose relevant constants in C API and use them in other language packages.

We can define a map which contains constant name and their value. Then add a C API to get those values, e.g.

const char* LGBM_GetConstant(const char* key);

References

Relevant code in #4089

Constants defined in pyhon package.
https://github.com/cyfdecyf/LightGBM/blob/f86d2db89d89810ddac0bc842af8d392a47edc85/python-package/lightgbm/basic.py#L21-L22

Usage:
https://github.com/cyfdecyf/LightGBM/blob/f86d2db89d89810ddac0bc842af8d392a47edc85/python-package/lightgbm/basic.py#L1556
https://github.com/cyfdecyf/LightGBM/blob/f86d2db89d89810ddac0bc842af8d392a47edc85/python-package/lightgbm/basic.py#L1217
https://github.com/cyfdecyf/LightGBM/blob/f86d2db89d89810ddac0bc842af8d392a47edc85/python-package/lightgbm/basic.py#L1580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions