diff --git a/Cargo.toml b/Cargo.toml index fbba381..6b98b2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ documentation = "https://docs.rs/xgboost" readme = "README.md" [dependencies] -xgboost-sys = "0.1.2" +xgboost-sys = { path="./xgboost-sys" } libc = "0.2" derive_builder = "0.5" log = "0.4" diff --git a/examples/basic/src/main.rs b/examples/basic/src/main.rs index c6cad33..9be50b4 100644 --- a/examples/basic/src/main.rs +++ b/examples/basic/src/main.rs @@ -97,7 +97,7 @@ fn main() { let mut data = Vec::new(); let reader = BufReader::new(File::open("../../xgboost-sys/xgboost/demo/data/agaricus.txt.train").unwrap()); - let mut current_row = 0; + let mut current_row: u64 = 0; for line in reader.lines() { let line = line.unwrap(); let sample: Vec<&str> = line.split_whitespace().collect(); @@ -106,7 +106,7 @@ fn main() { for entry in &sample[1..] { let pair: Vec<&str> = entry.split(':').collect(); rows.push(current_row); - cols.push(pair[0].parse::().unwrap()); + cols.push(pair[0].parse::().unwrap()); data.push(pair[1].parse::().unwrap()); } @@ -114,8 +114,8 @@ fn main() { } // work out size of sparse matrix from max row/col values - let shape = (*rows.iter().max().unwrap() + 1 as usize, - *cols.iter().max().unwrap() + 1 as usize); + let shape = ((*rows.iter().max().unwrap() + 1) as usize, + (*cols.iter().max().unwrap() + 1) as usize); let triplet_mat = sprs::TriMatBase::from_triplets(shape, rows, cols, data); let csr_mat = triplet_mat.to_csr(); diff --git a/examples/multiclass_classification/Cargo.toml b/examples/multiclass_classification/Cargo.toml index 3bd9292..6398437 100644 --- a/examples/multiclass_classification/Cargo.toml +++ b/examples/multiclass_classification/Cargo.toml @@ -8,4 +8,4 @@ publish = false xgboost = { path = "../../" } log = "0.4" env_logger = "0.5" -reqwest = "0.8" +reqwest = { version = "0.11", features = ["blocking"] } diff --git a/examples/multiclass_classification/src/main.rs b/examples/multiclass_classification/src/main.rs index 0aa84db..7bfa93d 100644 --- a/examples/multiclass_classification/src/main.rs +++ b/examples/multiclass_classification/src/main.rs @@ -73,7 +73,7 @@ fn download_dataset>(dst: P) { } debug!("Fetching training dataset from {}", url); - let mut response = reqwest::get(url).expect("failed to download training set data"); + let mut response = reqwest::blocking::get(url).expect("failed to download training set data"); let file = File::create(dst).expect(&format!("failed to create file {}", dst.display())); let mut writer = BufWriter::new(file); diff --git a/src/booster.rs b/src/booster.rs index 1f040e3..0a3a59c 100644 --- a/src/booster.rs +++ b/src/booster.rs @@ -178,7 +178,7 @@ impl Booster { for (dmat, dmat_name) in eval_sets { let margin = bst.predict_margin(dmat)?; let eval_result = eval_fn(&margin, dmat); - let mut eval_results = dmat_eval_results.entry(eval_name.to_string()) + let eval_results = dmat_eval_results.entry(eval_name.to_string()) .or_insert_with(IndexMap::new); eval_results.insert(dmat_name.to_string(), eval_result); } @@ -188,7 +188,7 @@ impl Booster { let mut eval_dmat_results = BTreeMap::new(); for (dmat_name, eval_results) in &dmat_eval_results { for (eval_name, result) in eval_results { - let mut dmat_results = eval_dmat_results.entry(eval_name).or_insert_with(BTreeMap::new); + let dmat_results = eval_dmat_results.entry(eval_name).or_insert_with(BTreeMap::new); dmat_results.insert(dmat_name, result); } } @@ -548,7 +548,7 @@ impl Booster { let score = metric_parts[1].parse::() .unwrap_or_else(|_| panic!("Unable to parse XGBoost metrics output: {}", eval)); - let mut metric_map = result.entry(evname.to_string()).or_insert_with(IndexMap::new); + let metric_map = result.entry(evname.to_string()).or_insert_with(IndexMap::new); metric_map.insert(metric.to_owned(), score); } } diff --git a/src/dmatrix.rs b/src/dmatrix.rs index fa2494b..9a09a14 100644 --- a/src/dmatrix.rs +++ b/src/dmatrix.rs @@ -1,6 +1,7 @@ use std::{slice, ffi, ptr, path::Path}; use libc::{c_uint, c_float}; use std::os::unix::ffi::OsStrExt; +use std::convert::TryInto; use xgboost_sys; @@ -123,7 +124,7 @@ impl DMatrix { /// `data[indptr[i]:indptr[i+1]`. /// /// If `num_cols` is set to None, number of columns will be inferred from given data. - pub fn from_csr(indptr: &[usize], indices: &[usize], data: &[f32], num_cols: Option) -> XGBResult { + pub fn from_csr(indptr: &[u64], indices: &[usize], data: &[f32], num_cols: Option) -> XGBResult { assert_eq!(indices.len(), data.len()); let mut handle = ptr::null_mut(); let indices: Vec = indices.iter().map(|x| *x as u32).collect(); @@ -131,9 +132,9 @@ impl DMatrix { xgb_call!(xgboost_sys::XGDMatrixCreateFromCSREx(indptr.as_ptr(), indices.as_ptr(), data.as_ptr(), - indptr.len(), - data.len(), - num_cols, + indptr.len().try_into().unwrap(), + data.len().try_into().unwrap(), + num_cols.try_into().unwrap(), &mut handle))?; Ok(DMatrix::new(handle)?) } @@ -146,7 +147,7 @@ impl DMatrix { /// `data[indptr[i]:indptr[i+1]`. /// /// If `num_rows` is set to None, number of rows will be inferred from given data. - pub fn from_csc(indptr: &[usize], indices: &[usize], data: &[f32], num_rows: Option) -> XGBResult { + pub fn from_csc(indptr: &[u64], indices: &[usize], data: &[f32], num_rows: Option) -> XGBResult { assert_eq!(indices.len(), data.len()); let mut handle = ptr::null_mut(); let indices: Vec = indices.iter().map(|x| *x as u32).collect(); @@ -154,9 +155,9 @@ impl DMatrix { xgb_call!(xgboost_sys::XGDMatrixCreateFromCSCEx(indptr.as_ptr(), indices.as_ptr(), data.as_ptr(), - indptr.len(), - data.len(), - num_rows, + indptr.len().try_into().unwrap(), + data.len().try_into().unwrap(), + num_rows.try_into().unwrap(), &mut handle))?; Ok(DMatrix::new(handle)?) } diff --git a/src/error.rs b/src/error.rs index e0dcb75..5059eea 100644 --- a/src/error.rs +++ b/src/error.rs @@ -31,7 +31,7 @@ impl XGBError { match ret_val { 0 => Ok(()), -1 => Err(XGBError::from_xgboost()), - _ => panic!(format!("unexpected return value '{}', expected 0 or -1", ret_val)), + _ => panic!("unexpected return value '{}', expected 0 or -1", ret_val), } } diff --git a/src/lib.rs b/src/lib.rs index ae268cc..5ba0ee9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,6 @@ extern crate libc; extern crate tempfile; extern crate indexmap; -#[macro_use] macro_rules! xgb_call { ($x:expr) => { XGBError::check_return_value(unsafe { $x }) diff --git a/xgboost-sys/Cargo.toml b/xgboost-sys/Cargo.toml index 55b124f..958ed00 100644 --- a/xgboost-sys/Cargo.toml +++ b/xgboost-sys/Cargo.toml @@ -13,4 +13,4 @@ readme = "README.md" libc = "0.2" [build-dependencies] -bindgen = "0.36" +bindgen = "0.59"