Njit-ing an sklearn function

Hi,

I’m getting this error message:
“untyped global name ‘matthews_corrcoef’: cannot determine numba type of <class ‘function’>”

from the following code:

from sklearn.metrics import matthews_corrcoef

@njit
def wrapped_matthews(df):
    return matthews_corrcoef(df[:,0],df[:,1])

the code of the matthews_corrcoef function is mostly array operations with numpy - is there any way to leverage this in numba without re-writing the code?

thanks!

hi @wilky_way

assuming that everything inside matthews_corrcoef is compatible with Numba (including not calling any other non-jitted function), you could do

from sklearn.metrics import matthews_corrcoef

wrapped_matthews = njit(matthews_corrcoef)

However, even one single non-compatible feature will make the compilation fail. The general way to tackle this problem is using @overload, https://numba.pydata.org/numba-doc/dev/extending/overloading-guide.html

You would have to take the code of matthews_corrcoef and adapt any non-compatible code until the compilation succeeds.

Cheers,
Luk