Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncated feature names when loaded booster loaded from a file #26

Open
geohardtke opened this issue Feb 22, 2021 · 2 comments
Open

Truncated feature names when loaded booster loaded from a file #26

geohardtke opened this issue Feb 22, 2021 · 2 comments

Comments

@geohardtke
Copy link

Hi there!
First of all thanks for writing this awsome crate!

I just run into a problem. When loading a model from a file, the feature names get truncated to a n_features -1 length (i.e if I have 3 features, the names get truncated to 2 characters.)
I'm trying to fix the issue myself and if I can, I submit a PR :). But I'm new to rust, and not very good with C, so I'm not sure I'll be able to fix it. The problem must be around like 173 in booster.rs

@geohardtke
Copy link
Author

I think I've got it, I think you swapped num_features and feature_name_length when you call LGBM_BoosterGetFeatureNames. The call is currently:

        lgbm_call!(lightgbm_sys::LGBM_BoosterGetFeatureNames(
            self.handle,
            feature_name_length as i32,
            &mut num_feature_names,
            num_feature as u64,
            &mut out_buffer_len,
            out_strs.as_ptr() as *mut *mut c_char
        ))?;

but should be (c api as comment for reference)

        lgbm_call!(lightgbm_sys::LGBM_BoosterGetFeatureNames(
            self.handle,
            num_feature as i32, // len: Number of char* pointers stored at out_strs. If smaller than the max size, only this many strings are copied
            &mut num_feature_names, //  [out] num_feature_names: Number of feature names
            feature_name_length as u64, //buffer_len: Size of pre-allocated strings. Content is copied up to buffer_len - 1 and null-terminated
            &mut out_buffer_len,//
            out_strs.as_ptr() as *mut *mut c_char
        ))?;

Let me know if you want me to make a PR or would it be easier to fix it yourself.

Cheers!

@vaaaaanquish
Copy link
Owner

@geohardtke Thanks. This issue can indeed be reproduced.
If you available for PR, I wait from you!:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants