GCC Code Coverage Report


Directory: ./
File: tasks/dergachev_a_multistep_2d_parallel/common/include/common.hpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 22 23 95.7%
Functions: 1 1 100.0%
Branches: 14 23 60.9%

Line Branch Exec Source
1 #pragma once
2
3 #include <cmath>
4 #include <functional>
5 #include <string>
6 #include <tuple>
7
8 #include "task/include/task.hpp"
9
10 namespace dergachev_a_multistep_2d_parallel {
11
12
3/5
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
90 struct OptimizationInput {
13 std::function<double(double, double)> func;
14 double x_min{0.0};
15 double x_max{1.0};
16 double y_min{0.0};
17 double y_max{1.0};
18 double epsilon{0.01};
19 double r_param{2.0};
20 int max_iterations{1000};
21
22
1/2
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
60 OptimizationInput() : func(nullptr) {}
23 };
24
25 struct OptimizationResult {
26 double x_opt{0.0};
27 double y_opt{0.0};
28 double func_min{0.0};
29 int iterations{0};
30 bool converged{false};
31
32 OptimizationResult() = default;
33
34 bool operator==(const OptimizationResult &other) const {
35 const double tol = 1e-3;
36 return std::abs(x_opt - other.x_opt) < tol && std::abs(y_opt - other.y_opt) < tol &&
37 std::abs(func_min - other.func_min) < tol;
38 }
39 };
40
41 struct TrialPoint {
42 double x{0.0};
43 double y{0.0};
44 double z{0.0};
45
46 TrialPoint() = default;
47 432 TrialPoint(double px, double py, double pz) : x(px), y(py), z(pz) {}
48
49 bool operator<(const TrialPoint &other) const {
50 if (x != other.x) {
51 return x < other.x;
52 }
53 return y < other.y;
54 }
55 };
56
57 struct Interval {
58 int left_idx{0};
59 int right_idx{0};
60 double characteristic{0.0};
61
62 Interval() = default;
63 Interval(int l, int r, double c) : left_idx(l), right_idx(r), characteristic(c) {}
64 };
65
66 using InType = OptimizationInput;
67 using OutType = OptimizationResult;
68 using TestType = std::tuple<int, std::string>;
69 using BaseTask = ppc::task::Task<InType, OutType>;
70
71 inline double PeanoToX(double t, double x_min, double x_max, double y_min, double y_max, int level);
72 inline double PeanoToY(double t, double x_min, double x_max, double y_min, double y_max, int level);
73
74 namespace detail {
75
76 1500 inline void PeanoMap(double t, int level, double &x, double &y) {
77 1500 x = 0.0;
78 1500 y = 0.0;
79 double scale = 0.5;
80
81
2/2
✓ Branch 0 taken 15000 times.
✓ Branch 1 taken 1500 times.
16500 for (int i = 0; i < level; ++i) {
82 15000 int quadrant = static_cast<int>(t * 4.0);
83 15000 t = (t * 4.0) - quadrant;
84
85 double tx = 0.0;
86 double ty = 0.0;
87
2/2
✓ Branch 0 taken 9864 times.
✓ Branch 1 taken 5136 times.
15000 switch (quadrant) {
88 case 0:
89 tx = 0.0;
90 ty = 0.0;
91 break;
92 case 1:
93 tx = 0.0;
94 ty = 1.0;
95 break;
96 case 2:
97 tx = 1.0;
98 ty = 1.0;
99 break;
100 case 3:
101 tx = 1.0;
102 ty = 0.0;
103 break;
104 default:
105 tx = 0.0;
106 ty = 0.0;
107 break;
108 }
109 15000 x += tx * scale;
110 15000 y += ty * scale;
111 15000 scale *= 0.5;
112 }
113 1500 }
114
115 } // namespace detail
116
117 inline double PeanoToX(double t, double x_min, double x_max, double /*y_min*/, double /*y_max*/, int level) {
118 750 double x = 0.0;
119 750 double y = 0.0;
120 750 detail::PeanoMap(t, level, x, y);
121 750 return x_min + (x * (x_max - x_min));
122 }
123
124 inline double PeanoToY(double t, double /*x_min*/, double /*x_max*/, double y_min, double y_max, int level) {
125 750 double x = 0.0;
126 750 double y = 0.0;
127 750 detail::PeanoMap(t, level, x, y);
128
6/12
✗ Branch 0 not taken.
✓ Branch 1 taken 324 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 27 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 324 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 24 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 24 times.
750 return y_min + (y * (y_max - y_min));
129 }
130
131 } // namespace dergachev_a_multistep_2d_parallel
132