diff --git a/implicit/evaluation.cpp b/implicit/evaluation.cpp index d0cca1c0..70d7f573 100644 --- a/implicit/evaluation.cpp +++ b/implicit/evaluation.cpp @@ -1835,6 +1835,7 @@ static const char __pyx_k_precision_at_k[] = "precision_at_k"; static const char __pyx_k_View_MemoryView[] = "View.MemoryView"; static const char __pyx_k_allocate_buffer[] = "allocate_buffer"; static const char __pyx_k_dtype_is_object[] = "dtype_is_object"; +static const char __pyx_k_eliminate_zeros[] = "eliminate_zeros"; static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_test_user_items[] = "test_user_items"; @@ -1913,6 +1914,7 @@ static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_disable; static PyObject *__pyx_n_s_dtype; static PyObject *__pyx_n_s_dtype_is_object; +static PyObject *__pyx_n_s_eliminate_zeros; static PyObject *__pyx_n_s_encode; static PyObject *__pyx_n_s_enumerate; static PyObject *__pyx_n_s_error; @@ -2427,7 +2429,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_train_test_split(CYTHON_UNUSED * test = csr_matrix((ratings.data[test_index], * (ratings.row[test_index], ratings.col[test_index])), # <<<<<<<<<<<<<< * shape=ratings.shape, dtype=ratings.dtype) - * return train, test + * */ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_ratings, __pyx_n_s_row); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); @@ -2473,8 +2475,8 @@ static PyObject *__pyx_pf_8implicit_10evaluation_train_test_split(CYTHON_UNUSED * test = csr_matrix((ratings.data[test_index], * (ratings.row[test_index], ratings.col[test_index])), * shape=ratings.shape, dtype=ratings.dtype) # <<<<<<<<<<<<<< - * return train, test * + * test.data[test.data < 0] = 0 */ __pyx_t_3 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 40, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); @@ -2502,24 +2504,70 @@ static PyObject *__pyx_pf_8implicit_10evaluation_train_test_split(CYTHON_UNUSED __pyx_v_test = __pyx_t_2; __pyx_t_2 = 0; - /* "implicit/evaluation.pyx":41 - * (ratings.row[test_index], ratings.col[test_index])), + /* "implicit/evaluation.pyx":42 * shape=ratings.shape, dtype=ratings.dtype) + * + * test.data[test.data < 0] = 0 # <<<<<<<<<<<<<< + * test.eliminate_zeros() + * + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_test, __pyx_n_s_data); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_test, __pyx_n_s_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_t_5, __pyx_int_0) < 0)) __PYX_ERR(0, 42, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "implicit/evaluation.pyx":43 + * + * test.data[test.data < 0] = 0 + * test.eliminate_zeros() # <<<<<<<<<<<<<< + * + * return train, test + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_test, __pyx_n_s_eliminate_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (__pyx_t_3) { + __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else { + __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error) + } + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "implicit/evaluation.pyx":45 + * test.eliminate_zeros() + * * return train, test # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_train); __Pyx_GIVEREF(__pyx_v_train); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_train); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_train); __Pyx_INCREF(__pyx_v_test); __Pyx_GIVEREF(__pyx_v_test); - PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_test); - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_test); + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; /* "implicit/evaluation.pyx":14 @@ -2551,7 +2599,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_train_test_split(CYTHON_UNUSED return __pyx_r; } -/* "implicit/evaluation.pyx":45 +/* "implicit/evaluation.pyx":49 * * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -2577,7 +2625,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_3precision_at_k(PyObject *__pyx static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_model,&__pyx_n_s_train_user_items,&__pyx_n_s_test_user_items,&__pyx_n_s_K,&__pyx_n_s_show_progress,&__pyx_n_s_num_threads,0}; PyObject* values[6] = {0,0,0,0,0,0}; - /* "implicit/evaluation.pyx":46 + /* "implicit/evaluation.pyx":50 * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, * show_progress=True, int num_threads=1): # <<<<<<<<<<<<<< @@ -2613,13 +2661,13 @@ static PyObject *__pyx_pw_8implicit_10evaluation_3precision_at_k(PyObject *__pyx case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_train_user_items)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, 1); __PYX_ERR(0, 45, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, 1); __PYX_ERR(0, 49, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_test_user_items)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, 2); __PYX_ERR(0, 45, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, 2); __PYX_ERR(0, 49, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: @@ -2641,7 +2689,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_3precision_at_k(PyObject *__pyx } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "precision_at_k") < 0)) __PYX_ERR(0, 45, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "precision_at_k") < 0)) __PYX_ERR(0, 49, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2662,20 +2710,20 @@ static PyObject *__pyx_pw_8implicit_10evaluation_3precision_at_k(PyObject *__pyx __pyx_v_train_user_items = values[1]; __pyx_v_test_user_items = values[2]; if (values[3]) { - __pyx_v_K = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_K == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 45, __pyx_L3_error) + __pyx_v_K = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_K == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 49, __pyx_L3_error) } else { __pyx_v_K = ((int)10); } __pyx_v_show_progress = values[4]; if (values[5]) { - __pyx_v_num_threads = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_num_threads == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 46, __pyx_L3_error) + __pyx_v_num_threads = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_num_threads == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 50, __pyx_L3_error) } else { __pyx_v_num_threads = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 45, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("precision_at_k", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 49, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("implicit.evaluation.precision_at_k", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2683,7 +2731,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_3precision_at_k(PyObject *__pyx __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_8implicit_10evaluation_2precision_at_k(__pyx_self, __pyx_v_model, __pyx_v_train_user_items, __pyx_v_test_user_items, __pyx_v_K, __pyx_v_show_progress, __pyx_v_num_threads); - /* "implicit/evaluation.pyx":45 + /* "implicit/evaluation.pyx":49 * * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -2742,28 +2790,28 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __Pyx_INCREF(__pyx_v_train_user_items); __Pyx_INCREF(__pyx_v_test_user_items); - /* "implicit/evaluation.pyx":72 + /* "implicit/evaluation.pyx":76 * the calculated p@k * """ * if not isinstance(train_user_items, csr_matrix): # <<<<<<<<<<<<<< * train_user_items = train_user_items.tocsr() * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_IsInstance(__pyx_v_train_user_items, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_2 = PyObject_IsInstance(__pyx_v_train_user_items, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0); if (__pyx_t_3) { - /* "implicit/evaluation.pyx":73 + /* "implicit/evaluation.pyx":77 * """ * if not isinstance(train_user_items, csr_matrix): * train_user_items = train_user_items.tocsr() # <<<<<<<<<<<<<< * * if not isinstance(test_user_items, csr_matrix): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_train_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 73, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_train_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -2776,17 +2824,17 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_train_user_items, __pyx_t_1); __pyx_t_1 = 0; - /* "implicit/evaluation.pyx":72 + /* "implicit/evaluation.pyx":76 * the calculated p@k * """ * if not isinstance(train_user_items, csr_matrix): # <<<<<<<<<<<<<< @@ -2795,28 +2843,28 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ } - /* "implicit/evaluation.pyx":75 + /* "implicit/evaluation.pyx":79 * train_user_items = train_user_items.tocsr() * * if not isinstance(test_user_items, csr_matrix): # <<<<<<<<<<<<<< * test_user_items = test_user_items.tocsr() * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_IsInstance(__pyx_v_test_user_items, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 75, __pyx_L1_error) + __pyx_t_3 = PyObject_IsInstance(__pyx_v_test_user_items, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":76 + /* "implicit/evaluation.pyx":80 * * if not isinstance(test_user_items, csr_matrix): * test_user_items = test_user_items.tocsr() # <<<<<<<<<<<<<< * * cdef int users = test_user_items.shape[0], u, i */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -2829,17 +2877,17 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_test_user_items, __pyx_t_1); __pyx_t_1 = 0; - /* "implicit/evaluation.pyx":75 + /* "implicit/evaluation.pyx":79 * train_user_items = train_user_items.tocsr() * * if not isinstance(test_user_items, csr_matrix): # <<<<<<<<<<<<<< @@ -2848,23 +2896,23 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ } - /* "implicit/evaluation.pyx":78 + /* "implicit/evaluation.pyx":82 * test_user_items = test_user_items.tocsr() * * cdef int users = test_user_items.shape[0], u, i # <<<<<<<<<<<<<< * cdef double relevant = 0, total = 0 * cdef int[:] test_indptr = test_user_items.indptr */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 78, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_users = __pyx_t_6; - /* "implicit/evaluation.pyx":79 + /* "implicit/evaluation.pyx":83 * * cdef int users = test_user_items.shape[0], u, i * cdef double relevant = 0, total = 0 # <<<<<<<<<<<<<< @@ -2874,67 +2922,67 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __pyx_v_relevant = 0.0; __pyx_v_total = 0.0; - /* "implicit/evaluation.pyx":80 + /* "implicit/evaluation.pyx":84 * cdef int users = test_user_items.shape[0], u, i * cdef double relevant = 0, total = 0 * cdef int[:] test_indptr = test_user_items.indptr # <<<<<<<<<<<<<< * cdef int[:] test_indices = test_user_items.indices * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indptr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indptr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_test_indptr = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "implicit/evaluation.pyx":81 + /* "implicit/evaluation.pyx":85 * cdef double relevant = 0, total = 0 * cdef int[:] test_indptr = test_user_items.indptr * cdef int[:] test_indices = test_user_items.indices # <<<<<<<<<<<<<< * * cdef int * ids */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indices); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 81, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indices); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 81, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_test_indices = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "implicit/evaluation.pyx":86 + /* "implicit/evaluation.pyx":90 * cdef unordered_set[int] * likes * * progress = tqdm.tqdm(total=users, disable=not show_progress) # <<<<<<<<<<<<<< * * with nogil, parallel(num_threads=num_threads): */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tqdm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tqdm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_users); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_users); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_total, __pyx_t_5) < 0) __PYX_ERR(0, 86, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_total, __pyx_t_5) < 0) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_show_progress); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 86, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_show_progress); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_disable, __pyx_t_5) < 0) __PYX_ERR(0, 86, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_disable, __pyx_t_5) < 0) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_progress = __pyx_t_5; __pyx_t_5 = 0; - /* "implicit/evaluation.pyx":88 + /* "implicit/evaluation.pyx":92 * progress = tqdm.tqdm(total=users, disable=not show_progress) * * with nogil, parallel(num_threads=num_threads): # <<<<<<<<<<<<<< @@ -2973,7 +3021,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __pyx_v_ids = ((int *)1); __pyx_v_likes = ((std::unordered_set *)1); - /* "implicit/evaluation.pyx":89 + /* "implicit/evaluation.pyx":93 * * with nogil, parallel(num_threads=num_threads): * ids = malloc(sizeof(int) * K) # <<<<<<<<<<<<<< @@ -2982,7 +3030,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ __pyx_v_ids = ((int *)malloc(((sizeof(int)) * __pyx_v_K))); - /* "implicit/evaluation.pyx":90 + /* "implicit/evaluation.pyx":94 * with nogil, parallel(num_threads=num_threads): * ids = malloc(sizeof(int) * K) * likes = new unordered_set[int]() # <<<<<<<<<<<<<< @@ -2999,11 +3047,11 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 90, __pyx_L10_error) + __PYX_ERR(0, 94, __pyx_L10_error) } __pyx_v_likes = __pyx_t_8; - /* "implicit/evaluation.pyx":91 + /* "implicit/evaluation.pyx":95 * ids = malloc(sizeof(int) * K) * likes = new unordered_set[int]() * try: # <<<<<<<<<<<<<< @@ -3012,7 +3060,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ /*try:*/ { - /* "implicit/evaluation.pyx":92 + /* "implicit/evaluation.pyx":96 * likes = new unordered_set[int]() * try: * for u in prange(users, schedule='guided'): # <<<<<<<<<<<<<< @@ -3043,7 +3091,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P /* Initialize private variables to invalid values */ __pyx_v_i = ((int)0xbad0bad0); - /* "implicit/evaluation.pyx":94 + /* "implicit/evaluation.pyx":98 * for u in prange(users, schedule='guided'): * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: # <<<<<<<<<<<<<< @@ -3057,7 +3105,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __pyx_t_2 = (((*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_11 * __pyx_v_test_indptr.strides[0]) ))) == (*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_12 * __pyx_v_test_indptr.strides[0]) )))) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":95 + /* "implicit/evaluation.pyx":99 * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: * continue # <<<<<<<<<<<<<< @@ -3066,7 +3114,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ goto __pyx_L17_continue; - /* "implicit/evaluation.pyx":94 + /* "implicit/evaluation.pyx":98 * for u in prange(users, schedule='guided'): * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: # <<<<<<<<<<<<<< @@ -3075,7 +3123,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ } - /* "implicit/evaluation.pyx":96 + /* "implicit/evaluation.pyx":100 * if test_indptr[u] == test_indptr[u+1]: * continue * memset(ids, 0, sizeof(int) * K) # <<<<<<<<<<<<<< @@ -3084,7 +3132,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ (void)(memset(__pyx_v_ids, 0, ((sizeof(int)) * __pyx_v_K))); - /* "implicit/evaluation.pyx":98 + /* "implicit/evaluation.pyx":102 * memset(ids, 0, sizeof(int) * K) * * with gil: # <<<<<<<<<<<<<< @@ -3097,18 +3145,18 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P #endif /*try:*/ { - /* "implicit/evaluation.pyx":99 + /* "implicit/evaluation.pyx":103 * * with gil: * recs = model.recommend(u, train_user_items, N=K) # <<<<<<<<<<<<<< * for i in range(len(recs)): * ids[i] = recs[i][0] */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_model, __pyx_n_s_recommend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_model, __pyx_n_s_recommend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_u); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_u); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); @@ -3116,13 +3164,13 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __Pyx_GIVEREF(__pyx_v_train_user_items); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_train_user_items); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_K); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_K); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_t_13) < 0) __PYX_ERR(0, 99, __pyx_L25_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_t_13) < 0) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 99, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 103, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3130,51 +3178,51 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __Pyx_XDECREF_SET(__pyx_v_recs, __pyx_t_13); __pyx_t_13 = 0; - /* "implicit/evaluation.pyx":100 + /* "implicit/evaluation.pyx":104 * with gil: * recs = model.recommend(u, train_user_items, N=K) * for i in range(len(recs)): # <<<<<<<<<<<<<< * ids[i] = recs[i][0] * progress.update(1) */ - __pyx_t_14 = PyObject_Length(__pyx_v_recs); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 100, __pyx_L25_error) + __pyx_t_14 = PyObject_Length(__pyx_v_recs); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 104, __pyx_L25_error) __pyx_t_15 = __pyx_t_14; for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { __pyx_v_i = __pyx_t_16; - /* "implicit/evaluation.pyx":101 + /* "implicit/evaluation.pyx":105 * recs = model.recommend(u, train_user_items, N=K) * for i in range(len(recs)): * ids[i] = recs[i][0] # <<<<<<<<<<<<<< * progress.update(1) * */ - __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_recs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 101, __pyx_L25_error) + __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_recs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 105, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 101, __pyx_L25_error) + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 101, __pyx_L25_error) + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 105, __pyx_L25_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; (__pyx_v_ids[__pyx_v_i]) = __pyx_t_17; } - /* "implicit/evaluation.pyx":102 + /* "implicit/evaluation.pyx":106 * for i in range(len(recs)): * ids[i] = recs[i][0] * progress.update(1) # <<<<<<<<<<<<<< * * # mostly we're going to be blocked on the gil here, */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_update); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 102, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_update); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 106, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 102, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 106, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } - /* "implicit/evaluation.pyx":98 + /* "implicit/evaluation.pyx":102 * memset(ids, 0, sizeof(int) * K) * * with gil: # <<<<<<<<<<<<<< @@ -3198,7 +3246,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } - /* "implicit/evaluation.pyx":106 + /* "implicit/evaluation.pyx":110 * # mostly we're going to be blocked on the gil here, * # so try to do actual scoring without it * likes.clear() # <<<<<<<<<<<<<< @@ -3207,7 +3255,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ __pyx_v_likes->clear(); - /* "implicit/evaluation.pyx":107 + /* "implicit/evaluation.pyx":111 * # so try to do actual scoring without it * likes.clear() * for i in range(test_indptr[u], test_indptr[u+1]): # <<<<<<<<<<<<<< @@ -3223,7 +3271,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P for (__pyx_t_20 = (*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_19 * __pyx_v_test_indptr.strides[0]) ))); __pyx_t_20 < __pyx_t_17; __pyx_t_20+=1) { __pyx_v_i = __pyx_t_20; - /* "implicit/evaluation.pyx":108 + /* "implicit/evaluation.pyx":112 * likes.clear() * for i in range(test_indptr[u], test_indptr[u+1]): * likes.insert(test_indices[i]) # <<<<<<<<<<<<<< @@ -3235,7 +3283,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P (void)(__pyx_v_likes->insert((*((int *) ( /* dim=0 */ (__pyx_v_test_indices.data + __pyx_t_21 * __pyx_v_test_indices.strides[0]) ))))); } - /* "implicit/evaluation.pyx":110 + /* "implicit/evaluation.pyx":114 * likes.insert(test_indices[i]) * * total += fmin(K, likes.size()) # <<<<<<<<<<<<<< @@ -3244,7 +3292,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ __pyx_v_total = (__pyx_v_total + fmin(__pyx_v_K, __pyx_v_likes->size())); - /* "implicit/evaluation.pyx":112 + /* "implicit/evaluation.pyx":116 * total += fmin(K, likes.size()) * * for i in range(K): # <<<<<<<<<<<<<< @@ -3256,7 +3304,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_17; __pyx_t_20+=1) { __pyx_v_i = __pyx_t_20; - /* "implicit/evaluation.pyx":113 + /* "implicit/evaluation.pyx":117 * * for i in range(K): * if likes.find(ids[i]) != likes.end(): # <<<<<<<<<<<<<< @@ -3266,7 +3314,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __pyx_t_2 = ((__pyx_v_likes->find((__pyx_v_ids[__pyx_v_i])) != __pyx_v_likes->end()) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":114 + /* "implicit/evaluation.pyx":118 * for i in range(K): * if likes.find(ids[i]) != likes.end(): * relevant += 1 # <<<<<<<<<<<<<< @@ -3275,7 +3323,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ __pyx_v_relevant = (__pyx_v_relevant + 1.0); - /* "implicit/evaluation.pyx":113 + /* "implicit/evaluation.pyx":117 * * for i in range(K): * if likes.find(ids[i]) != likes.end(): # <<<<<<<<<<<<<< @@ -3308,7 +3356,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P goto __pyx_L34; __pyx_L34:; #ifdef _OPENMP - #pragma omp critical(__pyx_parallel_lastprivates7) + #pragma omp critical(__pyx_parallel_lastprivates0) #endif /* _OPENMP */ { __pyx_parallel_temp0 = __pyx_v_i; @@ -3351,7 +3399,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } - /* "implicit/evaluation.pyx":116 + /* "implicit/evaluation.pyx":120 * relevant += 1 * finally: * free(ids) # <<<<<<<<<<<<<< @@ -3362,7 +3410,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P /*normal exit:*/{ free(__pyx_v_ids); - /* "implicit/evaluation.pyx":117 + /* "implicit/evaluation.pyx":121 * finally: * free(ids) * del likes # <<<<<<<<<<<<<< @@ -3402,7 +3450,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P #endif { - /* "implicit/evaluation.pyx":116 + /* "implicit/evaluation.pyx":120 * relevant += 1 * finally: * free(ids) # <<<<<<<<<<<<<< @@ -3411,7 +3459,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P */ free(__pyx_v_ids); - /* "implicit/evaluation.pyx":117 + /* "implicit/evaluation.pyx":121 * finally: * free(ids) * del likes # <<<<<<<<<<<<<< @@ -3529,7 +3577,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P #endif } - /* "implicit/evaluation.pyx":88 + /* "implicit/evaluation.pyx":92 * progress = tqdm.tqdm(total=users, disable=not show_progress) * * with nogil, parallel(num_threads=num_threads): # <<<<<<<<<<<<<< @@ -3555,14 +3603,14 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } - /* "implicit/evaluation.pyx":119 + /* "implicit/evaluation.pyx":123 * del likes * * progress.close() # <<<<<<<<<<<<<< * return relevant / total * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -3575,16 +3623,16 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P } } if (__pyx_t_1) { - __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 123, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 123, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - /* "implicit/evaluation.pyx":120 + /* "implicit/evaluation.pyx":124 * * progress.close() * return relevant / total # <<<<<<<<<<<<<< @@ -3594,15 +3642,15 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_total == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 120, __pyx_L1_error) + __PYX_ERR(0, 124, __pyx_L1_error) } - __pyx_t_13 = PyFloat_FromDouble((__pyx_v_relevant / __pyx_v_total)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 120, __pyx_L1_error) + __pyx_t_13 = PyFloat_FromDouble((__pyx_v_relevant / __pyx_v_total)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_r = __pyx_t_13; __pyx_t_13 = 0; goto __pyx_L0; - /* "implicit/evaluation.pyx":45 + /* "implicit/evaluation.pyx":49 * * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -3631,7 +3679,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_2precision_at_k(CYTHON_UNUSED P return __pyx_r; } -/* "implicit/evaluation.pyx":124 +/* "implicit/evaluation.pyx":128 * * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -3657,7 +3705,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_5mean_average_precision_at_k(Py static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_model,&__pyx_n_s_train_user_items,&__pyx_n_s_test_user_items,&__pyx_n_s_K,&__pyx_n_s_show_progress,&__pyx_n_s_num_threads,0}; PyObject* values[6] = {0,0,0,0,0,0}; - /* "implicit/evaluation.pyx":125 + /* "implicit/evaluation.pyx":129 * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, * show_progress=True, int num_threads=1): # <<<<<<<<<<<<<< @@ -3693,13 +3741,13 @@ static PyObject *__pyx_pw_8implicit_10evaluation_5mean_average_precision_at_k(Py case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_train_user_items)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, 1); __PYX_ERR(0, 124, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, 1); __PYX_ERR(0, 128, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_test_user_items)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, 2); __PYX_ERR(0, 124, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, 2); __PYX_ERR(0, 128, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: @@ -3721,7 +3769,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_5mean_average_precision_at_k(Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mean_average_precision_at_k") < 0)) __PYX_ERR(0, 124, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mean_average_precision_at_k") < 0)) __PYX_ERR(0, 128, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3742,20 +3790,20 @@ static PyObject *__pyx_pw_8implicit_10evaluation_5mean_average_precision_at_k(Py __pyx_v_train_user_items = values[1]; __pyx_v_test_user_items = values[2]; if (values[3]) { - __pyx_v_K = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_K == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 124, __pyx_L3_error) + __pyx_v_K = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_K == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 128, __pyx_L3_error) } else { __pyx_v_K = ((int)10); } __pyx_v_show_progress = values[4]; if (values[5]) { - __pyx_v_num_threads = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_num_threads == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 125, __pyx_L3_error) + __pyx_v_num_threads = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_num_threads == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L3_error) } else { __pyx_v_num_threads = ((int)1); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 124, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("mean_average_precision_at_k", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 128, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("implicit.evaluation.mean_average_precision_at_k", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -3763,7 +3811,7 @@ static PyObject *__pyx_pw_8implicit_10evaluation_5mean_average_precision_at_k(Py __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(__pyx_self, __pyx_v_model, __pyx_v_train_user_items, __pyx_v_test_user_items, __pyx_v_K, __pyx_v_show_progress, __pyx_v_num_threads); - /* "implicit/evaluation.pyx":124 + /* "implicit/evaluation.pyx":128 * * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -3826,28 +3874,28 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __Pyx_INCREF(__pyx_v_train_user_items); __Pyx_INCREF(__pyx_v_test_user_items); - /* "implicit/evaluation.pyx":153 + /* "implicit/evaluation.pyx":157 * # TODO: there is a fair amount of boilerplate here that is cut and paste * # from precision_at_k. refactor it out. * if not isinstance(train_user_items, csr_matrix): # <<<<<<<<<<<<<< * train_user_items = train_user_items.tocsr() * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_IsInstance(__pyx_v_train_user_items, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 153, __pyx_L1_error) + __pyx_t_2 = PyObject_IsInstance(__pyx_v_train_user_items, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0); if (__pyx_t_3) { - /* "implicit/evaluation.pyx":154 + /* "implicit/evaluation.pyx":158 * # from precision_at_k. refactor it out. * if not isinstance(train_user_items, csr_matrix): * train_user_items = train_user_items.tocsr() # <<<<<<<<<<<<<< * * if not isinstance(test_user_items, csr_matrix): */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_train_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_train_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -3860,17 +3908,17 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_train_user_items, __pyx_t_1); __pyx_t_1 = 0; - /* "implicit/evaluation.pyx":153 + /* "implicit/evaluation.pyx":157 * # TODO: there is a fair amount of boilerplate here that is cut and paste * # from precision_at_k. refactor it out. * if not isinstance(train_user_items, csr_matrix): # <<<<<<<<<<<<<< @@ -3879,28 +3927,28 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ } - /* "implicit/evaluation.pyx":156 + /* "implicit/evaluation.pyx":160 * train_user_items = train_user_items.tocsr() * * if not isinstance(test_user_items, csr_matrix): # <<<<<<<<<<<<<< * test_user_items = test_user_items.tocsr() * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_csr_matrix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_IsInstance(__pyx_v_test_user_items, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_3 = PyObject_IsInstance(__pyx_v_test_user_items, __pyx_t_1); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":157 + /* "implicit/evaluation.pyx":161 * * if not isinstance(test_user_items, csr_matrix): * test_user_items = test_user_items.tocsr() # <<<<<<<<<<<<<< * * cdef int users = test_user_items.shape[0], u, i, total = 0 */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_tocsr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -3913,17 +3961,17 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } if (__pyx_t_5) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_test_user_items, __pyx_t_1); __pyx_t_1 = 0; - /* "implicit/evaluation.pyx":156 + /* "implicit/evaluation.pyx":160 * train_user_items = train_user_items.tocsr() * * if not isinstance(test_user_items, csr_matrix): # <<<<<<<<<<<<<< @@ -3932,24 +3980,24 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ } - /* "implicit/evaluation.pyx":159 + /* "implicit/evaluation.pyx":163 * test_user_items = test_user_items.tocsr() * * cdef int users = test_user_items.shape[0], u, i, total = 0 # <<<<<<<<<<<<<< * cdef double mean_ap = 0, ap = 0, relevant = 0 * cdef int[:] test_indptr = test_user_items.indptr */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 159, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 159, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_users = __pyx_t_6; __pyx_v_total = 0; - /* "implicit/evaluation.pyx":160 + /* "implicit/evaluation.pyx":164 * * cdef int users = test_user_items.shape[0], u, i, total = 0 * cdef double mean_ap = 0, ap = 0, relevant = 0 # <<<<<<<<<<<<<< @@ -3960,67 +4008,67 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __pyx_v_ap = 0.0; __pyx_v_relevant = 0.0; - /* "implicit/evaluation.pyx":161 + /* "implicit/evaluation.pyx":165 * cdef int users = test_user_items.shape[0], u, i, total = 0 * cdef double mean_ap = 0, ap = 0, relevant = 0 * cdef int[:] test_indptr = test_user_items.indptr # <<<<<<<<<<<<<< * cdef int[:] test_indices = test_user_items.indices * */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indptr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indptr); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 165, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 161, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 165, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_test_indptr = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "implicit/evaluation.pyx":162 + /* "implicit/evaluation.pyx":166 * cdef double mean_ap = 0, ap = 0, relevant = 0 * cdef int[:] test_indptr = test_user_items.indptr * cdef int[:] test_indices = test_user_items.indices # <<<<<<<<<<<<<< * * cdef int * ids */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indices); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_test_user_items, __pyx_n_s_indices); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 162, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_int(__pyx_t_4, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_test_indices = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "implicit/evaluation.pyx":167 + /* "implicit/evaluation.pyx":171 * cdef unordered_set[int] * likes * * progress = tqdm.tqdm(total=users, disable=not show_progress) # <<<<<<<<<<<<<< * * with nogil, parallel(num_threads=num_threads): */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tqdm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_tqdm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_users); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_users); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_total, __pyx_t_5) < 0) __PYX_ERR(0, 167, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_total, __pyx_t_5) < 0) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_show_progress); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 167, __pyx_L1_error) - __pyx_t_5 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_show_progress); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_disable, __pyx_t_5) < 0) __PYX_ERR(0, 167, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_disable, __pyx_t_5) < 0) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 167, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_progress = __pyx_t_5; __pyx_t_5 = 0; - /* "implicit/evaluation.pyx":169 + /* "implicit/evaluation.pyx":173 * progress = tqdm.tqdm(total=users, disable=not show_progress) * * with nogil, parallel(num_threads=num_threads): # <<<<<<<<<<<<<< @@ -4059,7 +4107,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __pyx_v_ids = ((int *)1); __pyx_v_likes = ((std::unordered_set *)1); - /* "implicit/evaluation.pyx":170 + /* "implicit/evaluation.pyx":174 * * with nogil, parallel(num_threads=num_threads): * ids = malloc(sizeof(int) * K) # <<<<<<<<<<<<<< @@ -4068,7 +4116,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ __pyx_v_ids = ((int *)malloc(((sizeof(int)) * __pyx_v_K))); - /* "implicit/evaluation.pyx":171 + /* "implicit/evaluation.pyx":175 * with nogil, parallel(num_threads=num_threads): * ids = malloc(sizeof(int) * K) * likes = new unordered_set[int]() # <<<<<<<<<<<<<< @@ -4085,11 +4133,11 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 171, __pyx_L10_error) + __PYX_ERR(0, 175, __pyx_L10_error) } __pyx_v_likes = __pyx_t_8; - /* "implicit/evaluation.pyx":172 + /* "implicit/evaluation.pyx":176 * ids = malloc(sizeof(int) * K) * likes = new unordered_set[int]() * try: # <<<<<<<<<<<<<< @@ -4098,7 +4146,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ /*try:*/ { - /* "implicit/evaluation.pyx":173 + /* "implicit/evaluation.pyx":177 * likes = new unordered_set[int]() * try: * for u in prange(users, schedule='guided'): # <<<<<<<<<<<<<< @@ -4133,7 +4181,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __pyx_v_i = ((int)0xbad0bad0); __pyx_v_relevant = ((double)__PYX_NAN()); - /* "implicit/evaluation.pyx":175 + /* "implicit/evaluation.pyx":179 * for u in prange(users, schedule='guided'): * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: # <<<<<<<<<<<<<< @@ -4147,7 +4195,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __pyx_t_2 = (((*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_11 * __pyx_v_test_indptr.strides[0]) ))) == (*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_12 * __pyx_v_test_indptr.strides[0]) )))) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":176 + /* "implicit/evaluation.pyx":180 * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: * continue # <<<<<<<<<<<<<< @@ -4156,7 +4204,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ goto __pyx_L17_continue; - /* "implicit/evaluation.pyx":175 + /* "implicit/evaluation.pyx":179 * for u in prange(users, schedule='guided'): * # if we don't have any test items, skip this user * if test_indptr[u] == test_indptr[u+1]: # <<<<<<<<<<<<<< @@ -4165,7 +4213,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ } - /* "implicit/evaluation.pyx":177 + /* "implicit/evaluation.pyx":181 * if test_indptr[u] == test_indptr[u+1]: * continue * memset(ids, 0, sizeof(int) * K) # <<<<<<<<<<<<<< @@ -4174,7 +4222,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ (void)(memset(__pyx_v_ids, 0, ((sizeof(int)) * __pyx_v_K))); - /* "implicit/evaluation.pyx":179 + /* "implicit/evaluation.pyx":183 * memset(ids, 0, sizeof(int) * K) * * with gil: # <<<<<<<<<<<<<< @@ -4187,18 +4235,18 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #endif /*try:*/ { - /* "implicit/evaluation.pyx":180 + /* "implicit/evaluation.pyx":184 * * with gil: * recs = model.recommend(u, train_user_items, N=K) # <<<<<<<<<<<<<< * for i in range(len(recs)): * ids[i] = recs[i][0] */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_model, __pyx_n_s_recommend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_model, __pyx_n_s_recommend); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_u); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_u); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); @@ -4206,13 +4254,13 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __Pyx_GIVEREF(__pyx_v_train_user_items); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_train_user_items); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_K); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_K); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); - if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_t_13) < 0) __PYX_ERR(0, 180, __pyx_L25_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_t_13) < 0) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 180, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 184, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -4220,51 +4268,51 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __Pyx_XDECREF_SET(__pyx_v_recs, __pyx_t_13); __pyx_t_13 = 0; - /* "implicit/evaluation.pyx":181 + /* "implicit/evaluation.pyx":185 * with gil: * recs = model.recommend(u, train_user_items, N=K) * for i in range(len(recs)): # <<<<<<<<<<<<<< * ids[i] = recs[i][0] * progress.update(1) */ - __pyx_t_14 = PyObject_Length(__pyx_v_recs); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 181, __pyx_L25_error) + __pyx_t_14 = PyObject_Length(__pyx_v_recs); if (unlikely(__pyx_t_14 == ((Py_ssize_t)-1))) __PYX_ERR(0, 185, __pyx_L25_error) __pyx_t_15 = __pyx_t_14; for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) { __pyx_v_i = __pyx_t_16; - /* "implicit/evaluation.pyx":182 + /* "implicit/evaluation.pyx":186 * recs = model.recommend(u, train_user_items, N=K) * for i in range(len(recs)): * ids[i] = recs[i][0] # <<<<<<<<<<<<<< * progress.update(1) * */ - __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_recs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 182, __pyx_L25_error) + __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_recs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 186, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); - __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 182, __pyx_L25_error) + __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 186, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 182, __pyx_L25_error) + __pyx_t_17 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_17 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 186, __pyx_L25_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; (__pyx_v_ids[__pyx_v_i]) = __pyx_t_17; } - /* "implicit/evaluation.pyx":183 + /* "implicit/evaluation.pyx":187 * for i in range(len(recs)): * ids[i] = recs[i][0] * progress.update(1) # <<<<<<<<<<<<<< * * # mostly we're going to be blocked on the gil here, */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_update); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 183, __pyx_L25_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_update); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 187, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 183, __pyx_L25_error) + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 187, __pyx_L25_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } - /* "implicit/evaluation.pyx":179 + /* "implicit/evaluation.pyx":183 * memset(ids, 0, sizeof(int) * K) * * with gil: # <<<<<<<<<<<<<< @@ -4288,7 +4336,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } - /* "implicit/evaluation.pyx":187 + /* "implicit/evaluation.pyx":191 * # mostly we're going to be blocked on the gil here, * # so try to do actual scoring without it * likes.clear() # <<<<<<<<<<<<<< @@ -4297,7 +4345,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ __pyx_v_likes->clear(); - /* "implicit/evaluation.pyx":188 + /* "implicit/evaluation.pyx":192 * # so try to do actual scoring without it * likes.clear() * for i in range(test_indptr[u], test_indptr[u+1]): # <<<<<<<<<<<<<< @@ -4313,7 +4361,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY for (__pyx_t_20 = (*((int *) ( /* dim=0 */ (__pyx_v_test_indptr.data + __pyx_t_19 * __pyx_v_test_indptr.strides[0]) ))); __pyx_t_20 < __pyx_t_17; __pyx_t_20+=1) { __pyx_v_i = __pyx_t_20; - /* "implicit/evaluation.pyx":189 + /* "implicit/evaluation.pyx":193 * likes.clear() * for i in range(test_indptr[u], test_indptr[u+1]): * likes.insert(test_indices[i]) # <<<<<<<<<<<<<< @@ -4325,7 +4373,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY (void)(__pyx_v_likes->insert((*((int *) ( /* dim=0 */ (__pyx_v_test_indices.data + __pyx_t_21 * __pyx_v_test_indices.strides[0]) ))))); } - /* "implicit/evaluation.pyx":191 + /* "implicit/evaluation.pyx":195 * likes.insert(test_indices[i]) * * ap = 0 # <<<<<<<<<<<<<< @@ -4334,7 +4382,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ __pyx_v_ap = 0.0; - /* "implicit/evaluation.pyx":192 + /* "implicit/evaluation.pyx":196 * * ap = 0 * relevant = 0 # <<<<<<<<<<<<<< @@ -4343,7 +4391,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ __pyx_v_relevant = 0.0; - /* "implicit/evaluation.pyx":193 + /* "implicit/evaluation.pyx":197 * ap = 0 * relevant = 0 * for i in range(K): # <<<<<<<<<<<<<< @@ -4355,7 +4403,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_17; __pyx_t_20+=1) { __pyx_v_i = __pyx_t_20; - /* "implicit/evaluation.pyx":194 + /* "implicit/evaluation.pyx":198 * relevant = 0 * for i in range(K): * if likes.find(ids[i]) != likes.end(): # <<<<<<<<<<<<<< @@ -4365,7 +4413,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __pyx_t_2 = ((__pyx_v_likes->find((__pyx_v_ids[__pyx_v_i])) != __pyx_v_likes->end()) != 0); if (__pyx_t_2) { - /* "implicit/evaluation.pyx":195 + /* "implicit/evaluation.pyx":199 * for i in range(K): * if likes.find(ids[i]) != likes.end(): * relevant = relevant + 1 # <<<<<<<<<<<<<< @@ -4374,7 +4422,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ __pyx_v_relevant = (__pyx_v_relevant + 1.0); - /* "implicit/evaluation.pyx":196 + /* "implicit/evaluation.pyx":200 * if likes.find(ids[i]) != likes.end(): * relevant = relevant + 1 * ap = ap + relevant / (i + 1) # <<<<<<<<<<<<<< @@ -4390,11 +4438,11 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 196, __pyx_L19_error) + __PYX_ERR(0, 200, __pyx_L19_error) } __pyx_v_ap = (__pyx_v_ap + (__pyx_v_relevant / __pyx_t_22)); - /* "implicit/evaluation.pyx":194 + /* "implicit/evaluation.pyx":198 * relevant = 0 * for i in range(K): * if likes.find(ids[i]) != likes.end(): # <<<<<<<<<<<<<< @@ -4404,7 +4452,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } - /* "implicit/evaluation.pyx":197 + /* "implicit/evaluation.pyx":201 * relevant = relevant + 1 * ap = ap + relevant / (i + 1) * mean_ap += ap / fmin(K, likes.size()) # <<<<<<<<<<<<<< @@ -4420,11 +4468,11 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #ifdef WITH_THREAD __Pyx_PyGILState_Release(__pyx_gilstate_save); #endif - __PYX_ERR(0, 197, __pyx_L19_error) + __PYX_ERR(0, 201, __pyx_L19_error) } __pyx_v_mean_ap = (__pyx_v_mean_ap + (__pyx_v_ap / __pyx_t_23)); - /* "implicit/evaluation.pyx":198 + /* "implicit/evaluation.pyx":202 * ap = ap + relevant / (i + 1) * mean_ap += ap / fmin(K, likes.size()) * total += 1 # <<<<<<<<<<<<<< @@ -4456,7 +4504,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY goto __pyx_L34; __pyx_L34:; #ifdef _OPENMP - #pragma omp critical(__pyx_parallel_lastprivates8) + #pragma omp critical(__pyx_parallel_lastprivates1) #endif /* _OPENMP */ { __pyx_parallel_temp0 = __pyx_v_ap; @@ -4503,7 +4551,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } - /* "implicit/evaluation.pyx":200 + /* "implicit/evaluation.pyx":204 * total += 1 * finally: * free(ids) # <<<<<<<<<<<<<< @@ -4514,7 +4562,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY /*normal exit:*/{ free(__pyx_v_ids); - /* "implicit/evaluation.pyx":201 + /* "implicit/evaluation.pyx":205 * finally: * free(ids) * del likes # <<<<<<<<<<<<<< @@ -4554,7 +4602,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #endif { - /* "implicit/evaluation.pyx":200 + /* "implicit/evaluation.pyx":204 * total += 1 * finally: * free(ids) # <<<<<<<<<<<<<< @@ -4563,7 +4611,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY */ free(__pyx_v_ids); - /* "implicit/evaluation.pyx":201 + /* "implicit/evaluation.pyx":205 * finally: * free(ids) * del likes # <<<<<<<<<<<<<< @@ -4681,7 +4729,7 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY #endif } - /* "implicit/evaluation.pyx":169 + /* "implicit/evaluation.pyx":173 * progress = tqdm.tqdm(total=users, disable=not show_progress) * * with nogil, parallel(num_threads=num_threads): # <<<<<<<<<<<<<< @@ -4707,13 +4755,13 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } - /* "implicit/evaluation.pyx":203 + /* "implicit/evaluation.pyx":207 * del likes * * progress.close() # <<<<<<<<<<<<<< * return mean_ap / total */ - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 207, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { @@ -4726,16 +4774,16 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY } } if (__pyx_t_1) { - __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 207, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { - __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 207, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - /* "implicit/evaluation.pyx":204 + /* "implicit/evaluation.pyx":208 * * progress.close() * return mean_ap / total # <<<<<<<<<<<<<< @@ -4743,15 +4791,15 @@ static PyObject *__pyx_pf_8implicit_10evaluation_4mean_average_precision_at_k(CY __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_total == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 204, __pyx_L1_error) + __PYX_ERR(0, 208, __pyx_L1_error) } - __pyx_t_13 = PyFloat_FromDouble((__pyx_v_mean_ap / __pyx_v_total)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 204, __pyx_L1_error) + __pyx_t_13 = PyFloat_FromDouble((__pyx_v_mean_ap / __pyx_v_total)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_r = __pyx_t_13; __pyx_t_13 = 0; goto __pyx_L0; - /* "implicit/evaluation.pyx":124 + /* "implicit/evaluation.pyx":128 * * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< @@ -18447,6 +18495,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 0, 1, 1}, {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1}, {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, + {&__pyx_n_s_eliminate_zeros, __pyx_k_eliminate_zeros, sizeof(__pyx_k_eliminate_zeros), 0, 0, 1, 1}, {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1}, {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1}, {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, @@ -18543,7 +18592,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 100, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 104, __pyx_L1_error) __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(1, 132, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(1, 147, __pyx_L1_error) __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(1, 150, __pyx_L1_error) @@ -18560,25 +18609,25 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "implicit/evaluation.pyx":102 + /* "implicit/evaluation.pyx":106 * for i in range(len(recs)): * ids[i] = recs[i][0] * progress.update(1) # <<<<<<<<<<<<<< * * # mostly we're going to be blocked on the gil here, */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 102, __pyx_L1_error) + __pyx_tuple_ = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "implicit/evaluation.pyx":183 + /* "implicit/evaluation.pyx":187 * for i in range(len(recs)): * ids[i] = recs[i][0] * progress.update(1) # <<<<<<<<<<<<<< * * # mostly we're going to be blocked on the gil here, */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 183, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 187, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); @@ -18819,29 +18868,29 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(__pyx_tuple__24); __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_implicit_evaluation_pyx, __pyx_n_s_train_test_split, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 14, __pyx_L1_error) - /* "implicit/evaluation.pyx":45 + /* "implicit/evaluation.pyx":49 * * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< * show_progress=True, int num_threads=1): * """ Calculates P@K for a given trained model */ - __pyx_tuple__26 = PyTuple_Pack(17, __pyx_n_s_model, __pyx_n_s_train_user_items, __pyx_n_s_test_user_items, __pyx_n_s_K, __pyx_n_s_show_progress, __pyx_n_s_num_threads, __pyx_n_s_users, __pyx_n_s_u, __pyx_n_s_i, __pyx_n_s_relevant, __pyx_n_s_total, __pyx_n_s_test_indptr, __pyx_n_s_test_indices, __pyx_n_s_ids, __pyx_n_s_likes, __pyx_n_s_progress, __pyx_n_s_recs); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_tuple__26 = PyTuple_Pack(17, __pyx_n_s_model, __pyx_n_s_train_user_items, __pyx_n_s_test_user_items, __pyx_n_s_K, __pyx_n_s_show_progress, __pyx_n_s_num_threads, __pyx_n_s_users, __pyx_n_s_u, __pyx_n_s_i, __pyx_n_s_relevant, __pyx_n_s_total, __pyx_n_s_test_indptr, __pyx_n_s_test_indices, __pyx_n_s_ids, __pyx_n_s_likes, __pyx_n_s_progress, __pyx_n_s_recs); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); - __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(6, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_implicit_evaluation_pyx, __pyx_n_s_precision_at_k, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(6, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_implicit_evaluation_pyx, __pyx_n_s_precision_at_k, 49, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 49, __pyx_L1_error) - /* "implicit/evaluation.pyx":124 + /* "implicit/evaluation.pyx":128 * * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< * show_progress=True, int num_threads=1): * """ Calculates MAP@K for a given trained model */ - __pyx_tuple__28 = PyTuple_Pack(19, __pyx_n_s_model, __pyx_n_s_train_user_items, __pyx_n_s_test_user_items, __pyx_n_s_K, __pyx_n_s_show_progress, __pyx_n_s_num_threads, __pyx_n_s_users, __pyx_n_s_u, __pyx_n_s_i, __pyx_n_s_total, __pyx_n_s_mean_ap, __pyx_n_s_ap, __pyx_n_s_relevant, __pyx_n_s_test_indptr, __pyx_n_s_test_indices, __pyx_n_s_ids, __pyx_n_s_likes, __pyx_n_s_progress, __pyx_n_s_recs); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 124, __pyx_L1_error) + __pyx_tuple__28 = PyTuple_Pack(19, __pyx_n_s_model, __pyx_n_s_train_user_items, __pyx_n_s_test_user_items, __pyx_n_s_K, __pyx_n_s_show_progress, __pyx_n_s_num_threads, __pyx_n_s_users, __pyx_n_s_u, __pyx_n_s_i, __pyx_n_s_total, __pyx_n_s_mean_ap, __pyx_n_s_ap, __pyx_n_s_relevant, __pyx_n_s_test_indptr, __pyx_n_s_test_indices, __pyx_n_s_ids, __pyx_n_s_likes, __pyx_n_s_progress, __pyx_n_s_recs); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); - __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(6, 0, 19, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_implicit_evaluation_pyx, __pyx_n_s_mean_average_precision_at_k, 124, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 124, __pyx_L1_error) + __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(6, 0, 19, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_implicit_evaluation_pyx, __pyx_n_s_mean_average_precision_at_k, 128, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 128, __pyx_L1_error) /* "View.MemoryView":285 * return self.name @@ -19284,28 +19333,28 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_train_test_split, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "implicit/evaluation.pyx":45 + /* "implicit/evaluation.pyx":49 * * @cython.boundscheck(False) * def precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< * show_progress=True, int num_threads=1): * """ Calculates P@K for a given trained model */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_8implicit_10evaluation_3precision_at_k, NULL, __pyx_n_s_implicit_evaluation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_8implicit_10evaluation_3precision_at_k, NULL, __pyx_n_s_implicit_evaluation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_precision_at_k, __pyx_t_2) < 0) __PYX_ERR(0, 45, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_precision_at_k, __pyx_t_2) < 0) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "implicit/evaluation.pyx":124 + /* "implicit/evaluation.pyx":128 * * @cython.boundscheck(False) * def mean_average_precision_at_k(model, train_user_items, test_user_items, int K=10, # <<<<<<<<<<<<<< * show_progress=True, int num_threads=1): * """ Calculates MAP@K for a given trained model */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_8implicit_10evaluation_5mean_average_precision_at_k, NULL, __pyx_n_s_implicit_evaluation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error) + __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_8implicit_10evaluation_5mean_average_precision_at_k, NULL, __pyx_n_s_implicit_evaluation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_mean_average_precision_at_k, __pyx_t_2) < 0) __PYX_ERR(0, 124, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_mean_average_precision_at_k, __pyx_t_2) < 0) __PYX_ERR(0, 128, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "implicit/evaluation.pyx":1 diff --git a/implicit/evaluation.pyx b/implicit/evaluation.pyx index 16fc2930..d64997a0 100644 --- a/implicit/evaluation.pyx +++ b/implicit/evaluation.pyx @@ -38,6 +38,10 @@ def train_test_split(ratings, train_percentage=0.8): test = csr_matrix((ratings.data[test_index], (ratings.row[test_index], ratings.col[test_index])), shape=ratings.shape, dtype=ratings.dtype) + + test.data[test.data < 0] = 0 + test.eliminate_zeros() + return train, test