Skip to content

Commit

Permalink
computeWeightsAnki takes less args
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexErrant committed Feb 19, 2024
1 parent c6b3942 commit 2139920
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
2 changes: 1 addition & 1 deletion fsrs-rs
Submodule fsrs-rs updated 1 files
+34 −30 src/convertor_tests.rs
24 changes: 3 additions & 21 deletions sandbox/src/train.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ async function loadSqliteAndRun(ab: ArrayBuffer) {
FROM cards
WHERE queue != 0
)
AND (type <> 4 AND ease <> 0)
AND (type <> 3 OR factor <> 0)
order by cid`
try {
const countQuery = db.prepare(`SELECT count(*) ${baseQuery}`)
Expand All @@ -45,39 +47,19 @@ async function loadSqliteAndRun(ab: ArrayBuffer) {
let i = 0
const cids = new BigInt64Array(count)
const eases = new Uint8Array(count)
const factors = new Uint32Array(count)
const ids = new BigInt64Array(count)
const ivls = new Int32Array(count)
const lastIvls = new Int32Array(count)
const times = new Uint32Array(count)
const types = new Uint8Array(count)
const usns = new Int32Array(count)
const trainQuery = db.prepare(`SELECT * ${baseQuery}`)
while (trainQuery.step()) {
const row = trainQuery.getAsObject()
cids[i] = BigInt(row.cid as number)
eases[i] = row.ease as number
factors[i] = row.factor as number
ids[i] = BigInt(row.id as number)
ivls[i] = row.ivl as number
lastIvls[i] = row.lastIvl as number
times[i] = row.time as number
types[i] = row.type as number
usns[i] = row.usn as number
i++
}
trainQuery.free()
let weights = fsrs.computeWeightsAnki(
cids,
eases,
factors,
ids,
ivls,
lastIvls,
times,
types,
usns,
)
let weights = fsrs.computeWeightsAnki(cids, eases, ids, types)
console.timeEnd('full training time')
console.log('trained weights are', weights)
console.log('revlog count', count)
Expand Down
9 changes: 1 addition & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@ impl FSRSwasm {
&mut self,
cids: &[i64],
eases: &[u8],
factors: &[u32],
ids: &[i64],
ivls: &[i32],
last_ivls: &[i32],
times: &[u32],
types: &[u8],
usns: &[i32],
) -> Vec<f32> {
let revlog_entries = to_revlog_entry(
cids, eases, factors, ids, ivls, last_ivls, times, types, usns,
);
let revlog_entries = to_revlog_entry(cids, eases, ids, types);
let items = anki_to_fsrs(revlog_entries);
self.train_and_set_weights(items)
}
Expand Down

0 comments on commit 2139920

Please sign in to comment.