| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "lukin_i_ench_contr_lin_hist/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <thread> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "lukin_i_ench_contr_lin_hist/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace lukin_i_ench_contr_lin_hist { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | LukinITestTaskSTL::LukinITestTaskSTL(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetInput() = in; |
| 14 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetOutput() = OutType(GetInput().size()); |
| 15 | 32 | } | |
| 16 | |||
| 17 | 32 | bool LukinITestTaskSTL::ValidationImpl() { | |
| 18 | 32 | return !(GetInput().empty()); | |
| 19 | } | ||
| 20 | |||
| 21 | 32 | bool LukinITestTaskSTL::PreProcessingImpl() { | |
| 22 | 32 | return true; | |
| 23 | } | ||
| 24 | |||
| 25 | 32 | bool LukinITestTaskSTL::RunImpl() { | |
| 26 | const InType &input = GetInput(); | ||
| 27 | |||
| 28 | 32 | size_ = static_cast<int>(input.size()); | |
| 29 | |||
| 30 | 32 | thread_count_ = static_cast<int>(std::thread::hardware_concurrency()); | |
| 31 | 32 | chunk_size_ = static_cast<int>(input.size()) / thread_count_; | |
| 32 | |||
| 33 | 32 | std::vector<unsigned char> loc_mins(thread_count_, 255); | |
| 34 |
1/4✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
32 | std::vector<unsigned char> loc_maxs(thread_count_, 0); |
| 35 | |||
| 36 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | GetLocMinMax(loc_mins, loc_maxs); |
| 37 | |||
| 38 |
1/2✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
|
32 | const int min = *std::ranges::min_element(loc_mins); |
| 39 | 32 | const int max = *std::ranges::max_element(loc_maxs); | |
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 24 times.
|
32 | if (max == min) { |
| 42 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | GetOutput() = GetInput(); |
| 43 | return true; | ||
| 44 | } | ||
| 45 | |||
| 46 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | Process(min, max); |
| 47 | |||
| 48 | return true; | ||
| 49 | } | ||
| 50 | |||
| 51 | 32 | bool LukinITestTaskSTL::PostProcessingImpl() { | |
| 52 | 32 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | void LukinITestTaskSTL::GetLocMinMax(std::vector<unsigned char> &loc_mins, std::vector<unsigned char> &loc_maxs) { |
| 56 | const InType &input = GetInput(); | ||
| 57 | |||
| 58 | 32 | std::vector<std::thread> thread_pool; | |
| 59 |
1/2✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 | thread_pool.reserve(thread_count_); |
| 60 | |||
| 61 | 128 | auto reduction = [&](const int idx, const int start, const int end) { | |
| 62 | 128 | unsigned char loc_min = loc_mins[idx]; | |
| 63 | 128 | unsigned char loc_max = loc_maxs[idx]; | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 2760704 times.
✓ Branch 1 taken 128 times.
|
2760832 | for (int i = start; i < end; i++) { |
| 66 | 2760704 | loc_min = (input[i] < loc_min) ? input[i] : loc_min; | |
| 67 | 2760704 | loc_max = (input[i] > loc_max) ? input[i] : loc_max; | |
| 68 | } | ||
| 69 | |||
| 70 | 128 | loc_mins[idx] = loc_min; | |
| 71 | 128 | loc_maxs[idx] = loc_max; | |
| 72 | 160 | }; | |
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 32 times.
|
160 | for (int i = 0; i < thread_count_; i++) { |
| 75 | 128 | const int start = chunk_size_ * i; | |
| 76 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 96 times.
|
128 | const int end = (i == (thread_count_ - 1)) ? size_ : start + chunk_size_; |
| 77 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | thread_pool.emplace_back(reduction, i, start, end); |
| 78 | } | ||
| 79 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 32 times.
|
160 | for (auto &thread : thread_pool) { |
| 80 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | thread.join(); |
| 81 | } | ||
| 82 | 32 | } | |
| 83 | |||
| 84 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | void LukinITestTaskSTL::Process(int min, int max) { |
| 85 | const InType &input = GetInput(); | ||
| 86 | OutType &output = GetOutput(); | ||
| 87 | |||
| 88 | 24 | const float scale = 255.0F / static_cast<float>(max - min); | |
| 89 | |||
| 90 | auto process = [&](const int start, const int end) { | ||
| 91 |
2/2✓ Branch 0 taken 2752512 times.
✓ Branch 1 taken 96 times.
|
2752608 | for (int i = start; i < end; i++) { |
| 92 | 2752512 | output[i] = static_cast<unsigned char>(static_cast<float>(input[i] - min) * scale); | |
| 93 | } | ||
| 94 | 24 | }; | |
| 95 | |||
| 96 | 24 | std::vector<std::thread> thread_pool; | |
| 97 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | thread_pool.reserve(thread_count_); |
| 98 | |||
| 99 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | for (int i = 0; i < thread_count_; i++) { |
| 100 | 96 | const int start = chunk_size_ * i; | |
| 101 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 72 times.
|
96 | const int end = (i == (thread_count_ - 1)) ? size_ : start + chunk_size_; |
| 102 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | thread_pool.emplace_back(process, start, end); |
| 103 | } | ||
| 104 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 24 times.
|
120 | for (auto &thread : thread_pool) { |
| 105 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | thread.join(); |
| 106 | } | ||
| 107 | 24 | } | |
| 108 | |||
| 109 | } // namespace lukin_i_ench_contr_lin_hist | ||
| 110 |