@@ -296,6 +296,7 @@ def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
296
296
cdef:
297
297
Py_ssize_t i, j, xi, yi, N, K
298
298
ndarray[float64_t, ndim= 2 ] result
299
+ ndarray[float64_t, ndim= 2 ] ranked_mat
299
300
ndarray[float64_t, ndim= 1 ] maskedx
300
301
ndarray[float64_t, ndim= 1 ] maskedy
301
302
ndarray[uint8_t, ndim= 2 ] mask
@@ -307,6 +308,11 @@ def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
307
308
result = np.empty((K, K), dtype = np.float64)
308
309
mask = np.isfinite(mat).view(np.uint8)
309
310
311
+ ranked_mat = np.empty((N, K), dtype = np.float64)
312
+
313
+ for i in range (K):
314
+ ranked_mat[:, i] = rank_1d_float64(mat[:, i])
315
+
310
316
for xi in range (K):
311
317
for yi in range (xi + 1 ):
312
318
nobs = 0
@@ -322,11 +328,9 @@ def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
322
328
j = 0
323
329
for i in range (N):
324
330
if mask[i, xi] and mask[i, yi]:
325
- maskedx[j] = mat [i, xi]
326
- maskedy[j] = mat [i, yi]
331
+ maskedx[j] = ranked_mat [i, xi]
332
+ maskedy[j] = ranked_mat [i, yi]
327
333
j += 1
328
- maskedx = rank_1d_float64(maskedx)
329
- maskedy = rank_1d_float64(maskedy)
330
334
331
335
mean = (nobs + 1 ) / 2.
332
336
0 commit comments