Skip to content

Commit e33da11

Browse files
perf: faster dilate operator (#11)
* perf: use network sort for 9-elements * perf: also sort the neighbors vector with smallsort * perf: add more network sorts to smallsort * refactor: remove old commented code * install: add smallsort to MANIFEST.in
1 parent d834d90 commit e33da11

3 files changed

Lines changed: 852 additions & 6 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include fastmorph/threadpool.h
2+
include fastmorph/smallsort.hpp
23
include fastmorph/fastmorph.hpp
34
include fastmorph/fastmorphops.cpp
45
include COPYING

fastmorph/fastmorph.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <cstdlib>
66
#include <cmath>
77
#include <functional>
8+
9+
#include "smallsort.hpp"
810
#include "threadpool.h"
911

1012
namespace fastmorph {
@@ -203,8 +205,8 @@ void multilabel_dilate(
203205
continue;
204206
}
205207

206-
std::sort(middle.begin(), middle.end());
207-
std::sort(right.begin(), right.end());
208+
fastmorph::sort(middle);
209+
fastmorph::sort(right);
208210

209211
if ((right.size() + middle.size() >= 14)
210212
&& right[0] == right[right.size() - 1]
@@ -229,7 +231,7 @@ void multilabel_dilate(
229231
neighbors.insert(neighbors.end(), middle.begin(), middle.end());
230232
neighbors.insert(neighbors.end(), right.begin(), right.end());
231233

232-
std::sort(neighbors.begin(), neighbors.end());
234+
fastmorph::sort(neighbors);
233235

234236
int size = neighbors.size();
235237

@@ -387,8 +389,8 @@ void multilabel_dilate(
387389
continue;
388390
}
389391

390-
std::sort(middle.begin(), middle.end());
391-
std::sort(right.begin(), right.end());
392+
fastmorph::sort(middle);
393+
fastmorph::sort(right);
392394

393395
if ((right.size() + middle.size() >= 5)
394396
&& right[0] == right[right.size() - 1]
@@ -413,7 +415,7 @@ void multilabel_dilate(
413415
neighbors.insert(neighbors.end(), middle.begin(), middle.end());
414416
neighbors.insert(neighbors.end(), right.begin(), right.end());
415417

416-
std::sort(neighbors.begin(), neighbors.end());
418+
fastmorph::sort(neighbors);
417419

418420
int size = neighbors.size();
419421

0 commit comments

Comments
 (0)