| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "galkin_d_multidim_integrals_rectangles/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "galkin_d_multidim_integrals_rectangles/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace galkin_d_multidim_integrals_rectangles { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
|
184 | GalkinDMultidimIntegralsRectanglesSEQ::GalkinDMultidimIntegralsRectanglesSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | 184 | GetOutput() = 0.0; | |
| 15 | 184 | } | |
| 16 | |||
| 17 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | bool GalkinDMultidimIntegralsRectanglesSEQ::ValidationImpl() { |
| 18 | const auto &[func, borders, n] = GetInput(); | ||
| 19 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (borders.empty()) { |
| 20 | return false; | ||
| 21 | } | ||
| 22 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 184 times.
|
504 | for (const auto &[left_border, right_border] : borders) { |
| 23 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 320 times.
|
320 | if (!std::isfinite(left_border) || !std::isfinite(right_border)) { |
| 24 | return false; | ||
| 25 | } | ||
| 26 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 320 times.
|
320 | if (left_border >= right_border) { |
| 27 | return false; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 184 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 184 times.
|
184 | return func && (n > 0) && (GetOutput() == 0.0); |
| 32 | } | ||
| 33 | |||
| 34 | 184 | bool GalkinDMultidimIntegralsRectanglesSEQ::PreProcessingImpl() { | |
| 35 | 184 | GetOutput() = 0.0; | |
| 36 | 184 | return true; | |
| 37 | } | ||
| 38 | |||
| 39 | namespace { | ||
| 40 | bool NextIndex(std::vector<int> &idx, std::size_t dim, int n) { | ||
| 41 |
2/2✓ Branch 0 taken 20783680 times.
✓ Branch 1 taken 184 times.
|
20783864 | for (std::size_t pos = 0; pos < dim; ++pos) { |
| 42 | 20783680 | ++idx[pos]; | |
| 43 |
2/2✓ Branch 0 taken 377864 times.
✓ Branch 1 taken 20405816 times.
|
20783680 | if (idx[pos] < n) { |
| 44 | return true; | ||
| 45 | } | ||
| 46 | 377864 | idx[pos] = 0; | |
| 47 | } | ||
| 48 | return false; | ||
| 49 | } | ||
| 50 | |||
| 51 | } // namespace | ||
| 52 | |||
| 53 | 184 | bool GalkinDMultidimIntegralsRectanglesSEQ::RunImpl() { | |
| 54 | const auto &[func, borders, n] = GetInput(); | ||
| 55 | const std::size_t dim = borders.size(); | ||
| 56 | |||
| 57 | 184 | std::vector<double> h(dim); | |
| 58 | double cell_v = 1.0; | ||
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 184 times.
|
504 | for (std::size_t i = 0; i < dim; ++i) { |
| 61 | 320 | const double left_border = borders[i].first; | |
| 62 | 320 | const double right_border = borders[i].second; | |
| 63 | |||
| 64 |
1/2✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
|
320 | h[i] = (right_border - left_border) / static_cast<double>(n); |
| 65 |
2/4✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 320 times.
✗ Branch 3 not taken.
|
320 | if (!(h[i] > 0.0) || !std::isfinite(h[i])) { |
| 66 | return false; | ||
| 67 | } | ||
| 68 | |||
| 69 | 320 | cell_v *= h[i]; | |
| 70 | } | ||
| 71 | |||
| 72 |
1/4✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
184 | std::vector<int> idx(dim, 0); |
| 73 |
1/4✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
184 | std::vector<double> x(dim); |
| 74 | |||
| 75 | double sum = 0.0; | ||
| 76 | |||
| 77 | while (true) { | ||
| 78 |
2/2✓ Branch 0 taken 66364400 times.
✓ Branch 1 taken 20406000 times.
|
86770400 | for (std::size_t i = 0; i < dim; ++i) { |
| 79 | 66364400 | const double left_border = borders[i].first; | |
| 80 | 66364400 | x[i] = left_border + ((static_cast<double>(idx[i]) + 0.5) * h[i]); | |
| 81 | } | ||
| 82 | |||
| 83 | const double fx = func(x); | ||
| 84 |
1/2✓ Branch 0 taken 20406000 times.
✗ Branch 1 not taken.
|
20406000 | if (!std::isfinite(fx)) { |
| 85 | return false; | ||
| 86 | } | ||
| 87 | |||
| 88 | 20406000 | sum += fx; | |
| 89 | |||
| 90 |
2/2✓ Branch 0 taken 20405816 times.
✓ Branch 1 taken 184 times.
|
40812000 | if (!NextIndex(idx, dim, n)) { |
| 91 | break; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | 184 | GetOutput() = sum * cell_v; | |
| 96 | |||
| 97 | 184 | return std::isfinite(GetOutput()); | |
| 98 | } | ||
| 99 | |||
| 100 | 184 | bool GalkinDMultidimIntegralsRectanglesSEQ::PostProcessingImpl() { | |
| 101 | 184 | return std::isfinite(GetOutput()); | |
| 102 | } | ||
| 103 | } // namespace galkin_d_multidim_integrals_rectangles | ||
| 104 |