Skip to content

Commit 5aef3bf

Browse files
npatsakulaMontana Low
authored andcommitted
[*] Booster::from_bytes implemented.
1 parent 04ab0de commit 5aef3bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/booster.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ impl Booster {
1818
Booster { handle }
1919
}
2020

21+
/// Initialize model from bytes.
22+
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
23+
let booster_str = CString::new(bytes).unwrap();
24+
let mut out_num_iteration = 0;
25+
let mut handle = std::ptr::null_mut();
26+
lgbm_call!(lightgbm_sys::LGBM_BoosterLoadModelFromString(
27+
booster_str.as_ptr().cast(),
28+
&mut out_num_iteration,
29+
&mut handle
30+
))?;
31+
32+
Ok(Booster::new(handle))
33+
}
34+
2135
/// Init from model file.
2236
pub fn from_file(filename: &str) -> Result<Self> {
2337
let filename_str = CString::new(filename).unwrap();

0 commit comments

Comments
 (0)