From f5c84f89b2dd804e902739c8b58c7ad521496f34 Mon Sep 17 00:00:00 2001 From: massquantity Date: Thu, 9 Nov 2023 12:00:41 +0800 Subject: [PATCH] [Rust] Add `PyUserCF` (#400) --- rust/src/lib.rs | 2 +- rust/src/user_cf.rs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 4cc670fe..68187321 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -9,6 +9,6 @@ mod user_cf; /// RecFarm module #[pymodule] fn recfarm(_py: Python, m: &PyModule) -> PyResult<()> { - m.add_class::()?; + m.add_class::()?; Ok(()) } diff --git a/rust/src/user_cf.rs b/rust/src/user_cf.rs index de56a84d..0d195895 100644 --- a/rust/src/user_cf.rs +++ b/rust/src/user_cf.rs @@ -9,9 +9,8 @@ use rand::seq::SliceRandom; use crate::similarities::{invert_cosine, sort_by_sims, SimOrd}; use crate::sparse::SparseMatrix; -// todo: PyUserCF -#[pyclass] -pub struct UserCF { +#[pyclass(module = "recfarm", name = "UserCF")] +pub struct PyUserCF { task: String, k_sim: usize, n_users: usize, @@ -27,7 +26,7 @@ pub struct UserCF { } #[pymethods] -impl UserCF { +impl PyUserCF { #[new] fn new( task: &str, @@ -56,7 +55,7 @@ impl UserCF { data: item_sparse_data.extract::>()?, }; let user_consumed = user_consumed.extract::>>()?; - Ok(UserCF { + Ok(Self { task: task.to_string(), k_sim, n_users,