diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7422f3..c036643 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: if: matrix.os == 'macos-latest' run: | brew install cmake libomp - cargo build --features=polars #--features=openmp + cargo build --features=openmp --features=polars - name: Build for Ubuntu if: matrix.os == 'ubuntu-latest' run: | @@ -41,7 +41,7 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --features=polars -- --no-deps #--features=openmp + args: --features=polars --features=openmp -- --no-deps format_check: name: Run Rustfmt runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index f875050..e8a1b53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,13 @@ [package] name = "lightgbm3" -version = "1.0.3" +version = "1.0.4" edition = "2021" -authors = ["Dmitry Mottl ", "vaaaaanquish <6syun9@gmail.com>"] +authors = [ + "Dmitry Mottl ", + "vaaaaanquish <6syun9@gmail.com>", + "paq <89paku@gmail.com>", + "Benjamin Ellis ", +] license = "MIT" repository = "https://github.com/Mottl/lightgbm3-rs" description = "Rust bindings for LightGBM library" @@ -13,11 +18,9 @@ readme = "README.md" exclude = [".gitignore", ".github", ".gitmodules", "examples", "benches", "lightgbm3-sys"] [dependencies] -lightgbm3-sys = { path = "lightgbm3-sys", version = "1.0.3" } -libc = "0.2.155" -derive_builder = "0.20.0" -serde_json = "1.0.122" -polars = { version = "0.41.3", optional = true } +lightgbm3-sys = { path = "lightgbm3-sys", version = "1.0.4" } +serde_json = "1.0.125" +polars = { version = "0.42.0", optional = true } [features] default = [] diff --git a/lightgbm3-sys/Cargo.toml b/lightgbm3-sys/Cargo.toml index a7c34c7..b75bebc 100644 --- a/lightgbm3-sys/Cargo.toml +++ b/lightgbm3-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lightgbm3-sys" -version = "1.0.3" +version = "1.0.4" edition = "2021" authors = ["Dmitry Mottl ", "vaaaaanquish <6syun9@gmail.com>"] build = "build.rs" diff --git a/lightgbm3-sys/lightgbm b/lightgbm3-sys/lightgbm index 3f7e608..6025283 160000 --- a/lightgbm3-sys/lightgbm +++ b/lightgbm3-sys/lightgbm @@ -1 +1 @@ -Subproject commit 3f7e6081275624edfca1f9b3096bea7a81a744ed +Subproject commit 602528315c6d5e4ae1e8f5de106cf56cf5869b16 diff --git a/src/booster.rs b/src/booster.rs index 66ba863..0cdd82a 100644 --- a/src/booster.rs +++ b/src/booster.rs @@ -1,7 +1,7 @@ //! LightGBM booster -use libc::{c_char, c_double, c_longlong, c_void}; use serde_json::Value; +use std::os::raw::{c_char, c_longlong, c_void}; use std::{convert::TryInto, ffi::CString}; use crate::{dataset::DType, Dataset, Error, Result}; @@ -56,7 +56,7 @@ impl Booster { let mut out_num_iterations = 0; let mut handle = std::ptr::null_mut(); lgbm_call!(lightgbm3_sys::LGBM_BoosterCreateFromModelfile( - filename_str.as_ptr() as *const c_char, + filename_str.as_ptr(), &mut out_num_iterations, &mut handle ))?; @@ -70,7 +70,7 @@ impl Booster { let mut out_num_iterations = 0; let mut handle = std::ptr::null_mut(); lgbm_call!(lightgbm3_sys::LGBM_BoosterLoadModelFromString( - cstring.as_ptr() as *const c_char, + cstring.as_ptr(), &mut out_num_iterations, &mut handle ))?; @@ -86,7 +86,7 @@ impl Booster { 0_i32, -1_i32, 0_i32, - filename_str.as_ptr() as *const c_char + filename_str.as_ptr(), ))?; Ok(()) } @@ -102,8 +102,8 @@ impl Booster { -1_i32, 0_i32, 0, - &mut out_size as *mut _, - std::ptr::null_mut() as *mut i8 + &mut out_size, + std::ptr::null_mut(), ))?; // write data to buffer and convert @@ -119,7 +119,7 @@ impl Booster { -1_i32, 0_i32, buffer.len() as c_longlong, - &mut out_size as *mut _, + &mut out_size, buffer.as_mut_ptr() as *mut c_char ))?; @@ -210,7 +210,7 @@ impl Booster { let mut handle = std::ptr::null_mut(); lgbm_call!(lightgbm3_sys::LGBM_BoosterCreate( dataset.handle, - params_cstring.as_ptr() as *const c_char, + params_cstring.as_ptr(), &mut handle ))?; @@ -254,12 +254,11 @@ impl Booster { } let n_rows = flat_x.len() / n_features as usize; let params_cstring = parameters - .map(|s| CString::new(s)) + .map(CString::new) .unwrap_or(CString::new("")) .unwrap(); let mut out_length: c_longlong = 0; - - let out_result: Vec = vec![Default::default(); n_rows * self.n_classes as usize]; + let mut out_result: Vec = vec![Default::default(); n_rows * self.n_classes as usize]; lgbm_call!(lightgbm3_sys::LGBM_BoosterPredictForMat( self.handle, flat_x.as_ptr() as *const c_void, @@ -270,9 +269,9 @@ impl Booster { predict_type.into(), // predict_type 0_i32, // start_iteration self.max_iterations, // num_iteration, <= 0 means no limit - params_cstring.as_ptr() as *const c_char, + params_cstring.as_ptr(), &mut out_length, - out_result.as_ptr() as *mut c_double + out_result.as_mut_ptr() ))?; Ok(out_result) @@ -421,7 +420,7 @@ impl Booster { let mut cur_iteration: i32 = 0; lgbm_call!(lightgbm3_sys::LGBM_BoosterGetCurrentIteration( self.handle, - &mut cur_iteration as *mut _ + &mut cur_iteration ))?; Ok(cur_iteration + 1) } @@ -429,14 +428,14 @@ impl Booster { /// Gets features names. pub fn feature_name(&self) -> Result> { let num_feature = self.inner_num_features()?; - let feature_name_length = 32; + let feature_name_length = 64; let mut num_feature_names = 0; let mut out_buffer_len = 0; let out_strs = (0..num_feature) .map(|_| { CString::new(" ".repeat(feature_name_length)) .unwrap() - .into_raw() as *mut c_char + .into_raw() }) .collect::>(); lgbm_call!(lightgbm3_sys::LGBM_BoosterGetFeatureNames( @@ -457,12 +456,12 @@ impl Booster { /// Get feature importance. Refer to [`ImportanceType`] pub fn feature_importance(&self, importance_type: ImportanceType) -> Result> { let num_feature = self.inner_num_features()?; - let out_result: Vec = vec![Default::default(); num_feature as usize]; + let mut out_result: Vec = vec![Default::default(); num_feature as usize]; lgbm_call!(lightgbm3_sys::LGBM_BoosterFeatureImportance( self.handle, 0_i32, importance_type.into(), - out_result.as_ptr() as *mut c_double + out_result.as_mut_ptr() ))?; Ok(out_result) } diff --git a/src/dataset.rs b/src/dataset.rs index 0e03d93..2760a4d 100644 --- a/src/dataset.rs +++ b/src/dataset.rs @@ -1,7 +1,7 @@ //! LightGBM Dataset used for training -use libc::{c_char, c_void}; use lightgbm3_sys::{DatasetHandle, C_API_DTYPE_FLOAT32, C_API_DTYPE_FLOAT64}; +use std::os::raw::c_void; use std::{self, ffi::CString}; #[cfg(feature = "polars")] @@ -103,14 +103,14 @@ impl Dataset { n_rows as i32, n_features, if is_row_major { 1_i32 } else { 0_i32 }, // is_row_major – 1 for row-major, 0 for column-major - params.as_ptr() as *const c_char, + params.as_ptr(), reference, &mut dataset_handle ))?; lgbm_call!(lightgbm3_sys::LGBM_DatasetSetField( dataset_handle, - label_str.as_ptr() as *const c_char, + label_str.as_ptr(), label.as_ptr() as *const c_void, n_rows as i32, C_API_DTYPE_FLOAT32 as i32 // labels should be always float32 @@ -174,8 +174,8 @@ impl Dataset { let mut handle = std::ptr::null_mut(); lgbm_call!(lightgbm3_sys::LGBM_DatasetCreateFromFile( - file_path_str.as_ptr() as *const c_char, - params.as_ptr() as *const c_char, + file_path_str.as_ptr(), + params.as_ptr(), std::ptr::null_mut(), &mut handle ))?; @@ -275,7 +275,7 @@ impl Dataset { let field_name = CString::new("weight").unwrap(); lgbm_call!(lightgbm3_sys::LGBM_DatasetSetField( self.handle, - field_name.as_ptr() as *const c_char, + field_name.as_ptr(), weights.as_ptr() as *const c_void, weights.len() as i32, C_API_DTYPE_FLOAT32 as i32, // weights other than float32 are not supported by LightGBM