Skip to content

Instantly share code, notes, and snippets.

@FedericoV
Created May 28, 2015 08:11
Show Gist options
  • Select an option

  • Save FedericoV/8dcfd6509be88454820a to your computer and use it in GitHub Desktop.

Select an option

Save FedericoV/8dcfd6509be88454820a to your computer and use it in GitHub Desktop.
Numba Jaccard
@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