| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "klimenko_v_lsh_contrast_incr/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "klimenko_v_lsh_contrast_incr/common/include/common.hpp" | ||
| 10 | #include "oneapi/tbb/parallel_for.h" | ||
| 11 | |||
| 12 | namespace klimenko_v_lsh_contrast_incr { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | KlimenkoVLSHContrastIncrTBB::KlimenkoVLSHContrastIncrTBB(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | GetInput() = in; |
| 17 | 12 | } | |
| 18 | |||
| 19 | 12 | bool KlimenkoVLSHContrastIncrTBB::ValidationImpl() { | |
| 20 | 12 | return !GetInput().empty(); | |
| 21 | } | ||
| 22 | |||
| 23 | 12 | bool KlimenkoVLSHContrastIncrTBB::PreProcessingImpl() { | |
| 24 | 12 | GetOutput().resize(GetInput().size()); | |
| 25 | 12 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | bool KlimenkoVLSHContrastIncrTBB::RunImpl() { |
| 29 | const auto &input = GetInput(); | ||
| 30 | auto &output = GetOutput(); | ||
| 31 | |||
| 32 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (input.empty()) { |
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | const size_t size = input.size(); | ||
| 37 | |||
| 38 | struct MinMax { | ||
| 39 | int min_val; | ||
| 40 | int max_val; | ||
| 41 | }; | ||
| 42 | |||
| 43 | MinMax result = | ||
| 44 | 24 | tbb::parallel_reduce(tbb::blocked_range<size_t>(0, size), MinMax{.min_val = input[0], .max_val = input[0]}, | |
| 45 | 2269 | [&](const tbb::blocked_range<size_t> &r, MinMax local) { | |
| 46 |
2/2✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 2257 times.
|
7441 | for (size_t i = r.begin(); i < r.end(); ++i) { |
| 47 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 5184 times.
✓ Branch 2 taken 1411 times.
✓ Branch 3 taken 3773 times.
|
5184 | local.min_val = std::min(local.min_val, input[i]); |
| 48 | 5184 | local.max_val = std::max(local.max_val, input[i]); | |
| 49 | } | ||
| 50 | 2257 | return local; | |
| 51 | 12 | }, [](const MinMax &a, const MinMax &b) { | |
| 52 | return MinMax{.min_val = std::min(a.min_val, b.min_val), .max_val = std::max(a.max_val, b.max_val)}; | ||
| 53 | }); | ||
| 54 | |||
| 55 | 12 | int min_val = result.min_val; | |
| 56 | 12 | int max_val = result.max_val; | |
| 57 | |||
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (max_val == min_val) { |
| 59 | ✗ | tbb::parallel_for(tbb::blocked_range<size_t>(0, size), [&](const tbb::blocked_range<size_t> &r) { | |
| 60 | ✗ | for (size_t i = r.begin(); i < r.end(); ++i) { | |
| 61 | ✗ | output[i] = input[i]; | |
| 62 | } | ||
| 63 | }); | ||
| 64 | ✗ | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | 2270 | tbb::parallel_for(tbb::blocked_range<size_t>(0, size), [&](const tbb::blocked_range<size_t> &r) { | |
| 68 |
2/2✓ Branch 0 taken 5184 times.
✓ Branch 1 taken 2258 times.
|
7442 | for (size_t i = r.begin(); i < r.end(); ++i) { |
| 69 | 5184 | output[i] = ((input[i] - min_val) * 255) / (max_val - min_val); | |
| 70 | } | ||
| 71 | 2258 | }); | |
| 72 | |||
| 73 | 12 | return true; | |
| 74 | } | ||
| 75 | |||
| 76 | 12 | bool KlimenkoVLSHContrastIncrTBB::PostProcessingImpl() { | |
| 77 | 12 | return GetOutput().size() == GetInput().size(); | |
| 78 | } | ||
| 79 | |||
| 80 | } // namespace klimenko_v_lsh_contrast_incr | ||
| 81 |