GCC Code Coverage Report


Directory: ./
File: tasks/terekhov_d_gauss_vert/stl/src/ops_stl.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 67 68 98.5%
Functions: 9 9 100.0%
Branches: 37 52 71.2%

Line Branch Exec Source
1 #include "terekhov_d_gauss_vert/stl/include/ops_stl.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <thread>
7 #include <vector>
8
9 #include "terekhov_d_gauss_vert/common/include/common.hpp"
10 #include "util/include/util.hpp"
11
12 namespace terekhov_d_gauss_vert {
13
14 namespace {
15
16 10368 inline void ProcessPixel(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int row,
17 int col) {
18 10368 size_t idx = (static_cast<size_t>(row) * static_cast<size_t>(width)) + static_cast<size_t>(col);
19 float sum = 0.0F;
20
2/2
✓ Branch 0 taken 31104 times.
✓ Branch 1 taken 10368 times.
41472 for (int ky = -1; ky <= 1; ++ky) {
21
2/2
✓ Branch 0 taken 93312 times.
✓ Branch 1 taken 31104 times.
124416 for (int kx = -1; kx <= 1; ++kx) {
22 93312 int px = col + kx + 1;
23 93312 int py = row + ky + 1;
24 93312 int kernel_idx = ((ky + 1) * 3) + (kx + 1);
25 93312 size_t padded_idx = (static_cast<size_t>(py) * static_cast<size_t>(padded_width)) + static_cast<size_t>(px);
26 93312 sum += static_cast<float>(padded_image[padded_idx]) * kGaussKernel[static_cast<size_t>(kernel_idx)];
27 }
28 }
29 10368 output.data[idx] = static_cast<int>(std::lround(sum));
30 10368 }
31
32 60 void ProcessBand(OutType &output, const std::vector<int> &padded_image, int padded_width, int width, int height,
33 int band, int band_width, int num_bands) {
34 60 int start_x = band * band_width;
35
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
60 int end_x = (band == num_bands - 1) ? width : ((band + 1) * band_width);
36
2/2
✓ Branch 0 taken 1040 times.
✓ Branch 1 taken 60 times.
1100 for (int row = 0; row < height; ++row) {
37
2/2
✓ Branch 0 taken 10368 times.
✓ Branch 1 taken 1040 times.
11408 for (int col = start_x; col < end_x; ++col) {
38 10368 ProcessPixel(output, padded_image, padded_width, width, row, col);
39 }
40 }
41 60 }
42
43 24 OutType SolveSTL(const std::vector<int> &padded_image, int width, int height) {
44 24 OutType output;
45 24 output.width = width;
46 24 output.height = height;
47
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 output.data.resize(static_cast<size_t>(width) * static_cast<size_t>(height));
48
49 24 const int padded_width = width + 2;
50
2/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
24 const int num_threads = ppc::util::GetNumThreads();
51 const int num_bands = std::min(num_threads, width); // Исправлено!
52
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 const int band_width = std::max(width / num_bands, 1);
53
54 24 std::vector<std::thread> threads;
55
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 threads.reserve(static_cast<size_t>(num_bands));
56
57
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
84 for (int band = 0; band < num_bands; ++band) {
58
1/2
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
60 threads.emplace_back([&output, &padded_image, padded_width, width, height, band, band_width, num_bands]() {
59 60 ProcessBand(output, padded_image, padded_width, width, height, band, band_width, num_bands);
60 60 });
61 }
62
63
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 24 times.
84 for (auto &thread : threads) {
64
1/2
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
60 thread.join();
65 }
66
67 24 return output;
68 24 }
69
70 } // namespace
71
72
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 TerekhovDGaussVertSTL::TerekhovDGaussVertSTL(const InType &in) {
73 SetTypeOfTask(GetStaticTypeOfTask());
74 GetInput() = in;
75 24 }
76
77 24 bool TerekhovDGaussVertSTL::ValidationImpl() {
78 const auto &input = GetInput();
79
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 if (input.width <= 0 || input.height <= 0) {
80 return false;
81 }
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (static_cast<int>(input.data.size()) != input.width * input.height) {
83 return false;
84 }
85 return true;
86 }
87
88 24 bool TerekhovDGaussVertSTL::PreProcessingImpl() {
89 const auto &input = GetInput();
90 24 width_ = input.width;
91 24 height_ = input.height;
92
93 24 int padded_width = width_ + 2;
94 24 int padded_height = height_ + 2;
95 24 padded_image_.resize(static_cast<size_t>(padded_width) * static_cast<size_t>(padded_height));
96
97
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 24 times.
488 for (int row = 0; row < padded_height; ++row) {
98
2/2
✓ Branch 0 taken 12128 times.
✓ Branch 1 taken 464 times.
12592 for (int col = 0; col < padded_width; ++col) {
99 12128 int src_x = col - 1;
100 12128 int src_y = row - 1;
101
102 12128 if (src_x < 0) {
103 src_x = -src_x - 1;
104 }
105
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 11664 times.
12128 if (src_x >= width_) {
106 464 src_x = (2 * width_) - src_x - 1;
107 }
108 12128 if (src_y < 0) {
109 src_y = -src_y - 1;
110 }
111
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 11664 times.
12128 if (src_y >= height_) {
112 464 src_y = (2 * height_) - src_y - 1;
113 }
114
115 12128 size_t padded_idx = (static_cast<size_t>(row) * static_cast<size_t>(padded_width)) + static_cast<size_t>(col);
116 12128 size_t src_idx = (static_cast<size_t>(src_y) * static_cast<size_t>(width_)) + static_cast<size_t>(src_x);
117 12128 padded_image_[padded_idx] = input.data[src_idx];
118 }
119 }
120 24 return true;
121 }
122
123
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool TerekhovDGaussVertSTL::RunImpl() {
124 const auto &input = GetInput();
125
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
24 if (input.data.empty() || width_ <= 0 || height_ <= 0) {
126 return false;
127 }
128 24 GetOutput() = SolveSTL(padded_image_, width_, height_);
129 24 return true;
130 }
131
132 24 bool TerekhovDGaussVertSTL::PostProcessingImpl() {
133 24 return GetOutput().data.size() == (static_cast<size_t>(GetOutput().width) * static_cast<size_t>(GetOutput().height));
134 }
135
136 } // namespace terekhov_d_gauss_vert
137