diff --git a/cornac/models/bpr/recom_bpr.pyx b/cornac/models/bpr/recom_bpr.pyx index 3e6ba9574..f99818f7f 100644 --- a/cornac/models/bpr/recom_bpr.pyx +++ b/cornac/models/bpr/recom_bpr.pyx @@ -216,7 +216,6 @@ class BPR(Recommender, ANNMixin): """ cdef: long num_samples = len(user_ids), s, i_index, j_index, correct = 0, skipped = 0 - long num_items = self.num_items integral f, i_id, j_id, thread_id floating z, score, temp bool use_bias = self.use_bias diff --git a/cornac/models/mf/backend_cpu.pyx b/cornac/models/mf/backend_cpu.pyx index 4dd4174a3..78622be6c 100644 --- a/cornac/models/mf/backend_cpu.pyx +++ b/cornac/models/mf/backend_cpu.pyx @@ -19,7 +19,6 @@ import multiprocessing cimport cython from cython.parallel import prange -from cython cimport floating, integral from libcpp cimport bool from libc.math cimport abs @@ -28,27 +27,32 @@ cimport numpy as np from tqdm.auto import trange +ctypedef np.int64_t INT64_t + + @cython.boundscheck(False) @cython.wraparound(False) -def fit_sgd(integral[:] rid, integral[:] cid, floating[:] val, - floating[:, :] U, floating[:, :] V, - floating[:] Bu, floating[:] Bi, - integral num_users, integral num_items, - floating lr, floating reg, floating mu, +def fit_sgd(INT64_t[:] rid, INT64_t[:] cid, float[:] val, + float[:, :] U, float[:, :] V, + float[:] Bu, float[:] Bi, + float lr, float reg, float mu, int max_iter, int num_threads, bool use_bias, bool early_stop, bool verbose): """Fit the model parameters (U, V, Bu, Bi) with SGD""" cdef: - integral num_ratings = val.shape[0] - integral num_factors = U.shape[1] + INT64_t num_ratings = val.shape[0] + INT64_t u, i, j + + int num_factors = U.shape[1] + int f - floating loss = 0 - floating last_loss = 0 - floating r, r_pred, error, u_f, i_f, delta_loss - integral u, i, f, j + float loss = 0 + float last_loss = 0 + float r, r_pred, error, u_f, i_f, delta_loss + - floating * user - floating * item + float * user + float * item progress = trange(max_iter, disable=not verbose) for epoch in progress: diff --git a/cornac/models/mf/recom_mf.py b/cornac/models/mf/recom_mf.py index e948d2684..cfd04012a 100644 --- a/cornac/models/mf/recom_mf.py +++ b/cornac/models/mf/recom_mf.py @@ -198,8 +198,6 @@ def _fit_cpu(self, train_set, val_set): self.i_factors, self.u_biases, self.i_biases, - self.num_users, - self.num_items, self.learning_rate, self.lambda_reg, self.global_mean,