Last active
January 26, 2016 15:47
-
-
Save mikaem/f7fe4b94517a3f40f640 to your computer and use it in GitHub Desktop.
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
# memview_bench_v6.pyx | |
import numpy as np | |
cimport numpy as np | |
from libc.math cimport sqrt | |
cimport cython | |
@cython.boundscheck(False) | |
@cython.wraparound(False) | |
def pairwise(np.ndarray[double, ndim=2, mode='c'] X not None): | |
cdef np.intp_t i, j, k, n_samples, n_dim | |
cdef double tmp, d | |
n_samples = X.shape[0] | |
n_dim = X.shape[1] | |
cdef np.ndarray[double, ndim=2, mode='c'] D = np.empty((n_samples, | |
n_samples)) | |
for i in xrange(n_samples): | |
for j in xrange(n_samples): | |
d = 0.0 | |
for k in xrange(n_dim): | |
tmp = X[i, k] - X[j, k] | |
d += tmp*tmp | |
D[i, j] = sqrt(d) | |
return D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment