Skip to content

Commit

Permalink
Disable bounds checking & negative indexing for sgd() in SVD and SVDpp
Browse files Browse the repository at this point in the history
- significant performance gains
- we don't ever use negative indexing, and our code is always within numpy array bounds, so this should be safe
  • Loading branch information
ProfHercules committed Jan 23, 2022
1 parent 7d44b79 commit 12e57dc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions surprise/prediction_algorithms/matrix_factorization.pyx
Expand Up @@ -17,6 +17,7 @@ from ..utils import get_rng
from libcpp.map cimport map as mapcpp from libcpp.map cimport map as mapcpp
from libcpp.vector cimport vector as vectorcpp from libcpp.vector cimport vector as vectorcpp
from cython.operator import dereference, postincrement from cython.operator import dereference, postincrement
import cython




class SVD(AlgoBase): class SVD(AlgoBase):
Expand Down Expand Up @@ -160,6 +161,8 @@ class SVD(AlgoBase):


return self return self


@cython.boundscheck(False) # Deactivate bounds checking
@cython.wraparound(False) # Deactivate negative indexing.
def sgd(self, trainset): def sgd(self, trainset):


# OK, let's breath. I've seen so many different implementation of this # OK, let's breath. I've seen so many different implementation of this
Expand Down Expand Up @@ -409,6 +412,8 @@ class SVDpp(AlgoBase):


return self return self


@cython.boundscheck(False) # Deactivate bounds checking
@cython.wraparound(False) # Deactivate negative indexing.
def sgd(self, trainset): def sgd(self, trainset):


# user biases # user biases
Expand Down

0 comments on commit 12e57dc

Please sign in to comment.