Skip to content

Commit

Permalink
perf(largest_k): use faster k-largest algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Nov 17, 2024
1 parent d48f6c6 commit b6fe047
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cc3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ def largest_k(
return cc_out, 1
return cc_out

preserve = [ (i,ct) for i,ct in enumerate(cts) if i > 0 ]
preserve = np.argpartition(cts[1:], len(cts) - k - 1)[-k:]
preserve += 1
preserve = [ (label,cts[label]) for label in preserve ]
preserve.sort(key=lambda x: x[1])
preserve = [ x[0] for x in preserve[-k:] ]
preserve = [ int(x[0]) for x in preserve ]

try:
import fastremap
Expand Down

0 comments on commit b6fe047

Please sign in to comment.