From ca0c35b0076568ffaa71db2aa6e7e86f0b3caced Mon Sep 17 00:00:00 2001 From: Pete <35971555+peterlionelnewman@users.noreply.github.com> Date: Sat, 20 Jul 2024 08:34:03 +1000 Subject: [PATCH] speed up join close components (#90) Co-authored-by: Peter Newman --- .gitignore | 3 +++ kimimaro/postprocess.py | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 4d08e2b..8769af1 100644 --- a/.gitignore +++ b/.gitignore @@ -106,4 +106,7 @@ venv.bak/ test.py .DS_Store +# Itelli J +.idea/ + ext/skeletontricks/skeletontricks.cpp diff --git a/kimimaro/postprocess.py b/kimimaro/postprocess.py index a66cf0f..edb23a7 100644 --- a/kimimaro/postprocess.py +++ b/kimimaro/postprocess.py @@ -107,15 +107,11 @@ def join_close_components(skeletons, radius=None): while len(skels) > 1: N = len(skels) - radii_matrix = np.zeros( (N, N), dtype=np.float32 ) + np.inf - index_matrix = np.zeros( (N, N, 2), dtype=np.uint32 ) + -1 - - for i in range(len(skels)): - for j in range(len(skels)): - if i == j: - continue - elif radii_matrix[i,j] != np.inf: - continue + radii_matrix = np.full( (N, N), np.inf, dtype=np.float32 ) + index_matrix = np.full( (N, N, 2), -1, dtype=np.uint32 ) + + for i in range(N): + for j in range(i + 1, N): # compute upper triangle only s1, s2 = skels[i], skels[j] dist_matrix = scipy.spatial.distance.cdist(s1.vertices, s2.vertices)