Created
May 28, 2015 08:11
-
-
Save FedericoV/8dcfd6509be88454820a to your computer and use it in GitHub Desktop.
Numba Jaccard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @numba.jit(target='cpu', nopython=True) | |
| def _compute_overlaps(u, v): | |
| a = 0 | |
| b = 0 | |
| c = 0 | |
| m = u.shape[0] | |
| for idx in range(m): | |
| a += u[idx] & v[idx] | |
| b += u[idx] & ~v[idx] | |
| c += ~u[idx] & v[idx] | |
| return a, b, c | |
| @numba.jit(target='cpu', nopython=True) | |
| def jaccard(u, v): | |
| a, b, c = _compute_overlaps(u, v) | |
| return 1 - (a / float(a + b + c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment