1
1
use std:: { slice, ffi, ptr, path:: Path } ;
2
2
use libc:: { c_uint, c_float} ;
3
3
use std:: os:: unix:: ffi:: OsStrExt ;
4
+ use std:: convert:: TryInto ;
4
5
5
6
use xgboost_sys;
6
7
@@ -123,17 +124,17 @@ impl DMatrix {
123
124
/// `data[indptr[i]:indptr[i+1]`.
124
125
///
125
126
/// If `num_cols` is set to None, number of columns will be inferred from given data.
126
- pub fn from_csr ( indptr : & [ usize ] , indices : & [ usize ] , data : & [ f32 ] , num_cols : Option < usize > ) -> XGBResult < Self > {
127
+ pub fn from_csr ( indptr : & [ u64 ] , indices : & [ usize ] , data : & [ f32 ] , num_cols : Option < usize > ) -> XGBResult < Self > {
127
128
assert_eq ! ( indices. len( ) , data. len( ) ) ;
128
129
let mut handle = ptr:: null_mut ( ) ;
129
130
let indices: Vec < u32 > = indices. iter ( ) . map ( |x| * x as u32 ) . collect ( ) ;
130
131
let num_cols = num_cols. unwrap_or ( 0 ) ; // infer from data if 0
131
132
xgb_call ! ( xgboost_sys:: XGDMatrixCreateFromCSREx ( indptr. as_ptr( ) ,
132
133
indices. as_ptr( ) ,
133
134
data. as_ptr( ) ,
134
- indptr. len( ) ,
135
- data. len( ) ,
136
- num_cols,
135
+ indptr. len( ) . try_into ( ) . unwrap ( ) ,
136
+ data. len( ) . try_into ( ) . unwrap ( ) ,
137
+ num_cols. try_into ( ) . unwrap ( ) ,
137
138
& mut handle) ) ?;
138
139
Ok ( DMatrix :: new ( handle) ?)
139
140
}
@@ -146,17 +147,17 @@ impl DMatrix {
146
147
/// `data[indptr[i]:indptr[i+1]`.
147
148
///
148
149
/// If `num_rows` is set to None, number of rows will be inferred from given data.
149
- pub fn from_csc ( indptr : & [ usize ] , indices : & [ usize ] , data : & [ f32 ] , num_rows : Option < usize > ) -> XGBResult < Self > {
150
+ pub fn from_csc ( indptr : & [ u64 ] , indices : & [ usize ] , data : & [ f32 ] , num_rows : Option < usize > ) -> XGBResult < Self > {
150
151
assert_eq ! ( indices. len( ) , data. len( ) ) ;
151
152
let mut handle = ptr:: null_mut ( ) ;
152
153
let indices: Vec < u32 > = indices. iter ( ) . map ( |x| * x as u32 ) . collect ( ) ;
153
154
let num_rows = num_rows. unwrap_or ( 0 ) ; // infer from data if 0
154
155
xgb_call ! ( xgboost_sys:: XGDMatrixCreateFromCSCEx ( indptr. as_ptr( ) ,
155
156
indices. as_ptr( ) ,
156
157
data. as_ptr( ) ,
157
- indptr. len( ) ,
158
- data. len( ) ,
159
- num_rows,
158
+ indptr. len( ) . try_into ( ) . unwrap ( ) ,
159
+ data. len( ) . try_into ( ) . unwrap ( ) ,
160
+ num_rows. try_into ( ) . unwrap ( ) ,
160
161
& mut handle) ) ?;
161
162
Ok ( DMatrix :: new ( handle) ?)
162
163
}
0 commit comments