GCC Code Coverage Report


Directory: ./
File: tasks/ovchinnikov_m_multidim_integrals_rectangle/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 5 5 100.0%
Branches: 30 44 68.2%

Line Branch Exec Source
1 #include "ovchinnikov_m_multidim_integrals_rectangle/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <vector>
6
7 #include "ovchinnikov_m_multidim_integrals_rectangle/common/include/common.hpp"
8
9 namespace ovchinnikov_m_multidim_integrals_rectangle {
10
11 namespace {
12 double MultivariableFunction(const std::vector<double> &point) {
13 double sum = 0.0;
14
2/2
✓ Branch 0 taken 1563576 times.
✓ Branch 1 taken 478048 times.
2041624 for (double coord : point) {
15 1563576 sum += coord * coord;
16 }
17 return sum;
18 }
19 } // namespace
20
21
1/2
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
216 OvchinnikovMMultiDimIntegralsRectangleSEQ::OvchinnikovMMultiDimIntegralsRectangleSEQ(const InType &in) {
22 SetTypeOfTask(GetStaticTypeOfTask());
23 GetInput() = in;
24 216 GetOutput() = 0.0;
25 216 }
26
27 216 bool OvchinnikovMMultiDimIntegralsRectangleSEQ::ValidationImpl() {
28 const auto &input = GetInput();
29
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if (std::get<0>(input) <= 0) {
31 return false;
32 }
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if (std::get<1>(input) <= 0) {
34 return false;
35 }
36
37 const auto &lower_bounds = std::get<2>(input);
38 const auto &upper_bounds = std::get<3>(input);
39 int dim = std::get<1>(input);
40
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if (lower_bounds.size() != static_cast<size_t>(dim)) {
42 return false;
43 }
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if (upper_bounds.size() != static_cast<size_t>(dim)) {
45 return false;
46 }
47
48
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 216 times.
760 for (int i = 0; i < dim; i++) {
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 544 times.
544 if (lower_bounds[i] >= upper_bounds[i]) {
50 return false;
51 }
52 }
53 return true;
54 }
55
56 216 bool OvchinnikovMMultiDimIntegralsRectangleSEQ::PreProcessingImpl() {
57 216 return true;
58 }
59
60 216 bool OvchinnikovMMultiDimIntegralsRectangleSEQ::RunImpl() {
61 const auto &input = GetInput();
62 216 int n = std::get<0>(input);
63 216 int dim = std::get<1>(input);
64 const auto &lower_bounds = std::get<2>(input);
65 const auto &upper_bounds = std::get<3>(input);
66
67 216 std::vector<std::vector<double>> axis_coords(dim);
68 double cell_volume = 1.0;
69
70
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 216 times.
760 for (int curr_dim = 0; curr_dim < dim; curr_dim++) {
71
1/2
✓ Branch 1 taken 544 times.
✗ Branch 2 not taken.
544 double step = (upper_bounds[curr_dim] - lower_bounds[curr_dim]) / n;
72
1/2
✓ Branch 1 taken 544 times.
✗ Branch 2 not taken.
544 cell_volume *= step;
73
74
1/2
✓ Branch 1 taken 544 times.
✗ Branch 2 not taken.
544 axis_coords[curr_dim].resize(n);
75
2/2
✓ Branch 0 taken 7000 times.
✓ Branch 1 taken 544 times.
7544 for (int i = 0; i < n; i++) {
76 7000 axis_coords[curr_dim][i] = lower_bounds[curr_dim] + ((i + 0.5) * step);
77 }
78 }
79
80 double integral = 0.0;
81
1/2
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
216 std::vector<double> point(dim);
82
1/4
✓ Branch 1 taken 216 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
216 std::vector<int> indices(dim, 0);
83
84 bool done = false;
85 216 while (!done) {
86
2/2
✓ Branch 0 taken 1563576 times.
✓ Branch 1 taken 478048 times.
2041624 for (int curr_dim = 0; curr_dim < dim; curr_dim++) {
87 1563576 point[curr_dim] = axis_coords[curr_dim][indices[curr_dim]];
88 }
89
90 478048 integral += MultivariableFunction(point);
91
92 478048 int d = dim - 1;
93
2/2
✓ Branch 0 taken 517288 times.
✓ Branch 1 taken 216 times.
517504 while (d >= 0) {
94
2/2
✓ Branch 0 taken 39456 times.
✓ Branch 1 taken 477832 times.
517288 indices[d]++;
95
2/2
✓ Branch 0 taken 39456 times.
✓ Branch 1 taken 477832 times.
517288 if (indices[d] < n) {
96 break;
97 }
98 39456 indices[d] = 0;
99 39456 d--;
100 }
101
102
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 477832 times.
478048 if (d < 0) {
103 done = true;
104 }
105 }
106
107 216 integral *= cell_volume;
108
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 GetOutput() = integral;
109 216 return true;
110 216 }
111
112 216 bool OvchinnikovMMultiDimIntegralsRectangleSEQ::PostProcessingImpl() {
113 216 return true;
114 }
115
116 } // namespace ovchinnikov_m_multidim_integrals_rectangle
117