| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "klimenko_v_lsh_contrast_incr/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <thread> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "klimenko_v_lsh_contrast_incr/common/include/common.hpp" | ||
| 9 | #include "util/include/util.hpp" | ||
| 10 | |||
| 11 | namespace klimenko_v_lsh_contrast_incr { | ||
| 12 | |||
| 13 | namespace { | ||
| 14 | |||
| 15 | void GetThreadRange(size_t tid, size_t total, size_t num_t, size_t &b, size_t &e) { | ||
| 16 | 120 | size_t chunk = total / num_t; | |
| 17 | 120 | b = tid * chunk; | |
| 18 | 72 | e = (tid == num_t - 1) ? total : b + chunk; | |
| 19 | } | ||
| 20 | |||
| 21 | } // namespace | ||
| 22 | |||
| 23 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | KlimenkoVLSHContrastIncrSTL::KlimenkoVLSHContrastIncrSTL(const InType &in) { |
| 24 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 25 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetInput() = in; |
| 26 | 24 | } | |
| 27 | |||
| 28 | 24 | bool KlimenkoVLSHContrastIncrSTL::ValidationImpl() { | |
| 29 | 24 | return !GetInput().empty(); | |
| 30 | } | ||
| 31 | |||
| 32 | 24 | bool KlimenkoVLSHContrastIncrSTL::PreProcessingImpl() { | |
| 33 | 24 | GetOutput().resize(GetInput().size()); | |
| 34 | 24 | return true; | |
| 35 | } | ||
| 36 | |||
| 37 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | bool KlimenkoVLSHContrastIncrSTL::RunImpl() { |
| 38 | const auto &input = GetInput(); | ||
| 39 | auto &output = GetOutput(); | ||
| 40 | 24 | const size_t total_size = input.size(); | |
| 41 | |||
| 42 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (total_size == 0) { |
| 43 | return false; | ||
| 44 | } | ||
| 45 | |||
| 46 | 24 | const int num_t = ppc::util::GetNumThreads(); | |
| 47 | 24 | std::vector<std::thread> threads; | |
| 48 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | threads.reserve(num_t); |
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | std::vector<int> local_min(num_t); |
| 51 |
1/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
24 | std::vector<int> local_max(num_t); |
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
|
84 | for (int tid = 0; tid < num_t; tid++) { |
| 54 |
1/2✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
|
60 | threads.emplace_back([&, tid]() { |
| 55 | size_t begin = 0; | ||
| 56 | size_t end = 0; | ||
| 57 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | GetThreadRange(tid, total_size, num_t, begin, end); |
| 58 | |||
| 59 | 60 | int current_min = input[begin]; | |
| 60 | 60 | int current_max = input[begin]; | |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 10368 times.
✓ Branch 1 taken 60 times.
|
10428 | for (size_t i = begin; i < end; i++) { |
| 63 |
2/2✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 7598 times.
|
10368 | current_min = std::min(current_min, input[i]); |
| 64 | 10368 | current_max = std::max(current_max, input[i]); | |
| 65 | } | ||
| 66 | |||
| 67 | 60 | local_min[tid] = current_min; | |
| 68 | 60 | local_max[tid] = current_max; | |
| 69 | 60 | }); | |
| 70 | } | ||
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
|
84 | for (auto &th : threads) { |
| 73 |
1/2✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
|
60 | th.join(); |
| 74 | } | ||
| 75 | 24 | threads.clear(); | |
| 76 | |||
| 77 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | const int global_min = *std::ranges::min_element(local_min); |
| 78 | 24 | const int global_max = *std::ranges::max_element(local_max); | |
| 79 | |||
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (global_max == global_min) { |
| 81 | std::ranges::copy(input, output.begin()); | ||
| 82 | return true; | ||
| 83 | } | ||
| 84 | |||
| 85 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
|
84 | for (int tid = 0; tid < num_t; tid++) { |
| 86 |
1/4✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
60 | threads.emplace_back([&, tid]() { |
| 87 | size_t begin = 0; | ||
| 88 | size_t end = 0; | ||
| 89 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | GetThreadRange(tid, total_size, num_t, begin, end); |
| 90 | |||
| 91 |
2/2✓ Branch 0 taken 10368 times.
✓ Branch 1 taken 60 times.
|
10428 | for (size_t i = begin; i < end; i++) { |
| 92 | 10368 | output[i] = ((input[i] - global_min) * 255) / (global_max - global_min); | |
| 93 | } | ||
| 94 | 60 | }); | |
| 95 | } | ||
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
|
84 | for (auto &th : threads) { |
| 98 |
1/2✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
|
60 | th.join(); |
| 99 | } | ||
| 100 | |||
| 101 | return true; | ||
| 102 | 24 | } | |
| 103 | |||
| 104 | 24 | bool KlimenkoVLSHContrastIncrSTL::PostProcessingImpl() { | |
| 105 | 24 | return GetOutput().size() == GetInput().size(); | |
| 106 | } | ||
| 107 | |||
| 108 | } // namespace klimenko_v_lsh_contrast_incr | ||
| 109 |