Fix up resetting local metrics
@@ -679,14 +679,14 @@ def fast_metric_intersection(
@numba.njit()
-def reprocess_row(probabilities):
- target = np.log2(15)
+def reprocess_row(probabilities, k=15, n_iters=32):
+ target = np.log2(k)
lo = 0.0
hi = NPY_INFINITY
mid = 1.0
- for n in range(128):
+ for n in range(n_iters):
psum = 0.0
for j in range(probabilities.shape[0]):
@@ -708,14 +708,13 @@ def reprocess_row(probabilities):
return np.power(probabilities, mid)
-@numba.jit()
-def reset_local_metrics(simplicial_set):
- csr_mat = simplicial_set.tocsr()
- for i in range(csr_mat.indptr.shape[0] - 1):
- csr_mat.data[csr_mat.indptr[i] : csr_mat.indptr[i + 1]] = reprocess_row(
- csr_mat.data[csr_mat.indptr[i] : csr_mat.indptr[i + 1]]
+@numba.njit()
+def reset_local_metrics(simplicial_set_indptr, simplicial_set_data):
+ for i in range(simplicial_set_indptr.shape[0] - 1):
+ simplicial_set_data[simplicial_set_indptr[i] : simplicial_set_indptr[i + 1]] = reprocess_row(
+ simplicial_set_data[simplicial_set_indptr[i] : simplicial_set_indptr[i + 1]]
)
- return csr_mat.tocoo()
+ return
def reset_local_connectivity(simplicial_set, reset_local_metric=False):
@@ -738,7 +737,11 @@ def reset_local_connectivity(simplicial_set, reset_local_metric=False):
"""
simplicial_set = normalize(simplicial_set, norm="max")
if reset_local_metric:
- simplicial_set = reset_local_metrics(simplicial_set)
+ simplicial_set = simplicial_set.tocsr()
+ reset_local_metrics(
+ simplicial_set.indptr, simplicial_set.data
+ )
+ simplicial_set = simplicial_set.tocoo()
transpose = simplicial_set.transpose()
prod_matrix = simplicial_set.multiply(transpose)
simplicial_set = simplicial_set + transpose - prod_matrix
