Skip to content

Commit

Permalink
Fix/use default weights when weights is none (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex <[email protected]>
  • Loading branch information
L-M-Sherlock and AlexErrant authored Feb 21, 2024
1 parent d647c4d commit ec256ae
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use burn::backend::NdArray;
use fsrs::{anki_to_fsrs, to_revlog_entry, FSRSItem, FSRSReview, MemoryState, NextStates, FSRS};
use fsrs::{
anki_to_fsrs, to_revlog_entry, FSRSItem, FSRSReview, MemoryState, NextStates, DEFAULT_WEIGHTS,
FSRS,
};
use log::info;
use wasm_bindgen::prelude::*;

Expand All @@ -18,9 +21,12 @@ impl Default for FSRSwasm {
impl FSRSwasm {
#[cfg_attr(target_family = "wasm", wasm_bindgen(constructor))]
pub fn new(weights: Option<Vec<f32>>) -> Self {
Self {
model: FSRS::new(weights.as_deref()).unwrap(),
let model = match weights {
Some(weights) => FSRS::new(Some(&weights)),
None => FSRS::new(Some(&DEFAULT_WEIGHTS)),
}
.unwrap();
Self { model }
}

#[wasm_bindgen(js_name = computeWeightsAnki)]
Expand Down

0 comments on commit ec256ae

Please sign in to comment.