From 12e57dc768e5b2a0b00f1c252b33ca9cb562865b Mon Sep 17 00:00:00 2001 From: Hercules Date: Sun, 23 Jan 2022 07:40:25 +0200 Subject: [PATCH] Disable bounds checking & negative indexing for sgd() in SVD and SVDpp - significant performance gains - we don't ever use negative indexing, and our code is always within numpy array bounds, so this should be safe --- surprise/prediction_algorithms/matrix_factorization.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/surprise/prediction_algorithms/matrix_factorization.pyx b/surprise/prediction_algorithms/matrix_factorization.pyx index 38e051d6..5202fce3 100644 --- a/surprise/prediction_algorithms/matrix_factorization.pyx +++ b/surprise/prediction_algorithms/matrix_factorization.pyx @@ -17,6 +17,7 @@ from ..utils import get_rng from libcpp.map cimport map as mapcpp from libcpp.vector cimport vector as vectorcpp from cython.operator import dereference, postincrement +import cython class SVD(AlgoBase): @@ -160,6 +161,8 @@ class SVD(AlgoBase): return self + @cython.boundscheck(False) # Deactivate bounds checking + @cython.wraparound(False) # Deactivate negative indexing. def sgd(self, trainset): # OK, let's breath. I've seen so many different implementation of this @@ -409,6 +412,8 @@ class SVDpp(AlgoBase): return self + @cython.boundscheck(False) # Deactivate bounds checking + @cython.wraparound(False) # Deactivate negative indexing. def sgd(self, trainset): # user biases