Commit 8cced061 authored by Ted Themistokleous's avatar Ted Themistokleous
Browse files

Use std::back_inserter instead of push_back in filter_boxes_by_score()

Less code, simple to read.
parent 7785e68e
...@@ -230,8 +230,6 @@ struct nonmaxsuppression ...@@ -230,8 +230,6 @@ struct nonmaxsuppression
filter_boxes_by_score(T scores_start, std::size_t num_boxes, double score_threshold) const filter_boxes_by_score(T scores_start, std::size_t num_boxes, double score_threshold) const
{ {
std::vector<std::pair<double, int64_t>> boxes_heap; std::vector<std::pair<double, int64_t>> boxes_heap;
auto insert_to_boxes_heap =
make_function_output_iterator([&](const auto& x) { boxes_heap.push_back(x); });
int64_t box_idx = 0; int64_t box_idx = 0;
if(score_threshold > 0.0) if(score_threshold > 0.0)
...@@ -239,7 +237,7 @@ struct nonmaxsuppression ...@@ -239,7 +237,7 @@ struct nonmaxsuppression
transform_if( transform_if(
scores_start, scores_start,
scores_start + num_boxes, scores_start + num_boxes,
insert_to_boxes_heap, std::back_inserter(boxes_heap),
[&](auto sc) { [&](auto sc) {
box_idx++; box_idx++;
return sc >= score_threshold; return sc >= score_threshold;
...@@ -248,11 +246,13 @@ struct nonmaxsuppression ...@@ -248,11 +246,13 @@ struct nonmaxsuppression
} }
else else
{ // score is irrelevant, just push into boxes_heap and make a score-index pair { // score is irrelevant, just push into boxes_heap and make a score-index pair
std::transform( std::transform(scores_start,
scores_start, scores_start + num_boxes, insert_to_boxes_heap, [&](auto sc) { scores_start + num_boxes,
box_idx++; std::back_inserter(boxes_heap),
return std::make_pair(sc, box_idx - 1); [&](auto sc) {
}); box_idx++;
return std::make_pair(sc, box_idx - 1);
});
} }
std::sort(std::execution::par, boxes_heap.begin(), boxes_heap.end()); std::sort(std::execution::par, boxes_heap.begin(), boxes_heap.end());
return boxes_heap; return boxes_heap;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment