Open jonathanstrong opened 5 years ago
I think it might be because out_dptr
is a double pointer in the C API (and marked as const
). So making out_dptr
a ptr::null
instead of null_mut
and passing in a mutable reference to it to the C API should work. Something like the following (though I haven't tested it):
/// Returns a `Vec<u8>` with model weights.
pub fn to_vec(&self) -> XGBResult<Vec<u8>> {
debug!("Writing Booster to_vec");
let mut out_len = 0;
let mut out_dptr = ptr::null();
xgb_call!(xgboost_sys::XGBoosterGetModelRaw(self.handle, &mut out_len, &mut out_dptr))?;
let out_ptr_slice = unsafe { slice::from_raw_parts(out_dptr, out_len as usize) };
let out_vec: Vec<u8> = out_ptr_slice.iter()
.map(|str_ptr| unsafe { ffi::CStr::from_ptr(str_ptr).to_bytes().to_owned() })
.collect::<Vec<Vec<u8>>>()
.concat();
Ok(out_vec)
}
hey -
I was trying to implement the other side of the load/save from buffer,
XGBoosterGetModelRaw
, but I'm stuck, and thought maybe you could help.This is where I am (in
Booster
impl):The commented out section is because I can't get past calling the xgboost function.
I have tried a fairly wide variety of various pointer things as it relates to calling
XGBoosterGetModelRaw
, but I get SIGSEGV no matter what.The xgboost api is defined as:
Any ideas? Thanks!