| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "redkina_a_integral_simpson/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <functional> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "redkina_a_integral_simpson/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace redkina_a_integral_simpson { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | 1850272 | void EvaluatePoint(const std::vector<double> &a, const std::vector<double> &h, const std::vector<int> &n, | |
| 15 | const std::vector<int> &indices, const std::function<double(const std::vector<double> &)> &func, | ||
| 16 | std::vector<double> &point, double &sum) { | ||
| 17 | size_t dim = a.size(); | ||
| 18 | double w_prod = 1.0; | ||
| 19 |
2/2✓ Branch 0 taken 4247856 times.
✓ Branch 1 taken 1850272 times.
|
6098128 | for (size_t dim_idx = 0; dim_idx < dim; ++dim_idx) { |
| 20 | 4247856 | int idx = indices[dim_idx]; | |
| 21 |
2/2✓ Branch 0 taken 4193536 times.
✓ Branch 1 taken 54320 times.
|
4247856 | point[dim_idx] = a[dim_idx] + (static_cast<double>(idx) * h[dim_idx]); |
| 22 | |||
| 23 | int w = 0; | ||
| 24 |
4/4✓ Branch 0 taken 4193536 times.
✓ Branch 1 taken 54320 times.
✓ Branch 2 taken 4139216 times.
✓ Branch 3 taken 54320 times.
|
4247856 | if (idx == 0 || idx == n[dim_idx]) { |
| 25 | w = 1; | ||
| 26 |
2/2✓ Branch 0 taken 2042448 times.
✓ Branch 1 taken 2096768 times.
|
4139216 | } else if (idx % 2 == 1) { |
| 27 | w = 4; | ||
| 28 | } else { | ||
| 29 | w = 2; | ||
| 30 | } | ||
| 31 | 4247856 | w_prod *= static_cast<double>(w); | |
| 32 | } | ||
| 33 | 1850272 | sum += w_prod * func(point); | |
| 34 | 1850272 | } | |
| 35 | |||
| 36 | 1850272 | bool AdvanceIndices(std::vector<int> &indices, const std::vector<int> &n) { | |
| 37 | 1850272 | int dim = static_cast<int>(indices.size()); | |
| 38 | 1850272 | int d = dim - 1; | |
| 39 |
4/4✓ Branch 0 taken 1870960 times.
✓ Branch 1 taken 160 times.
✓ Branch 2 taken 20848 times.
✓ Branch 3 taken 1850112 times.
|
1871120 | while (d >= 0 && indices[d] == n[d]) { |
| 40 | 20848 | indices[d] = 0; | |
| 41 | 20848 | --d; | |
| 42 | } | ||
| 43 |
2/2✓ Branch 0 taken 1850112 times.
✓ Branch 1 taken 160 times.
|
1850272 | if (d < 0) { |
| 44 | return false; | ||
| 45 | } | ||
| 46 | 1850112 | ++indices[d]; | |
| 47 | 1850112 | return true; | |
| 48 | } | ||
| 49 | |||
| 50 | } // namespace | ||
| 51 | |||
| 52 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | RedkinaAIntegralSimpsonSEQ::RedkinaAIntegralSimpsonSEQ(const InType &in) { |
| 53 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 54 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | GetInput() = in; |
| 55 | 160 | } | |
| 56 | |||
| 57 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | bool RedkinaAIntegralSimpsonSEQ::ValidationImpl() { |
| 58 | const auto &in = GetInput(); | ||
| 59 | size_t dim = in.a.size(); | ||
| 60 | |||
| 61 |
3/6✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 160 times.
|
160 | if (dim == 0 || in.b.size() != dim || in.n.size() != dim) { |
| 62 | return false; | ||
| 63 | } | ||
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 160 times.
|
464 | for (size_t i = 0; i < dim; ++i) { |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
|
304 | if (in.a[i] >= in.b[i]) { |
| 67 | return false; | ||
| 68 | } | ||
| 69 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 304 times.
|
304 | if (in.n[i] <= 0 || in.n[i] % 2 != 0) { |
| 70 | return false; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | 160 | return static_cast<bool>(in.func); | |
| 75 | } | ||
| 76 | |||
| 77 | 160 | bool RedkinaAIntegralSimpsonSEQ::PreProcessingImpl() { | |
| 78 | const auto &in = GetInput(); | ||
| 79 | 160 | func_ = in.func; | |
| 80 | 160 | a_ = in.a; | |
| 81 | 160 | b_ = in.b; | |
| 82 | 160 | n_ = in.n; | |
| 83 | 160 | result_ = 0.0; | |
| 84 | 160 | return true; | |
| 85 | } | ||
| 86 | |||
| 87 | 160 | bool RedkinaAIntegralSimpsonSEQ::RunImpl() { | |
| 88 | size_t dim = a_.size(); | ||
| 89 | |||
| 90 | 160 | std::vector<double> h(dim); | |
| 91 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 160 times.
|
464 | for (size_t i = 0; i < dim; ++i) { |
| 92 | 304 | h[i] = (b_[i] - a_[i]) / static_cast<double>(n_[i]); | |
| 93 | } | ||
| 94 | |||
| 95 | double h_prod = 1.0; | ||
| 96 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 160 times.
|
464 | for (size_t i = 0; i < dim; ++i) { |
| 97 | 304 | h_prod *= h[i]; | |
| 98 | } | ||
| 99 | |||
| 100 |
1/4✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
160 | std::vector<double> point(dim); |
| 101 | 160 | double sum = 0.0; | |
| 102 | |||
| 103 |
1/4✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
160 | std::vector<int> indices(dim, 0); |
| 104 | |||
| 105 | bool has_next = true; | ||
| 106 |
2/2✓ Branch 0 taken 1850272 times.
✓ Branch 1 taken 160 times.
|
1850432 | while (has_next) { |
| 107 |
1/2✓ Branch 1 taken 1850272 times.
✗ Branch 2 not taken.
|
1850272 | EvaluatePoint(a_, h, n_, indices, func_, point, sum); |
| 108 | 1850272 | has_next = AdvanceIndices(indices, n_); | |
| 109 | } | ||
| 110 | |||
| 111 | double denominator = 1.0; | ||
| 112 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 160 times.
|
464 | for (size_t i = 0; i < dim; ++i) { |
| 113 | 304 | denominator *= 3.0; | |
| 114 | } | ||
| 115 | |||
| 116 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | result_ = (h_prod / denominator) * sum; |
| 117 | 160 | return true; | |
| 118 | } | ||
| 119 | |||
| 120 | 160 | bool RedkinaAIntegralSimpsonSEQ::PostProcessingImpl() { | |
| 121 | 160 | GetOutput() = result_; | |
| 122 | 160 | return true; | |
| 123 | } | ||
| 124 | |||
| 125 | } // namespace redkina_a_integral_simpson | ||
| 126 |