| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "zyuzin_n_multi_integrals_simpson/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "zyuzin_n_multi_integrals_simpson/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace zyuzin_n_multi_integrals_simpson { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | ZyuzinNSimpsonSEQ::ZyuzinNSimpsonSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | GetInput() = in; |
| 13 | 96 | GetOutput() = 0.0; | |
| 14 | 96 | } | |
| 15 | |||
| 16 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | bool ZyuzinNSimpsonSEQ::ValidationImpl() { |
| 17 | const auto &input = GetInput(); | ||
| 18 |
2/4✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
|
96 | if (input.lower_bounds.size() != input.upper_bounds.size() || input.lower_bounds.size() != input.n_steps.size()) { |
| 19 | return false; | ||
| 20 | } | ||
| 21 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (input.lower_bounds.empty()) { |
| 22 | return false; | ||
| 23 | } | ||
| 24 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 96 times.
|
288 | for (size_t i = 0; i < input.lower_bounds.size(); ++i) { |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
|
192 | if (input.lower_bounds[i] > input.upper_bounds[i]) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 192 times.
|
192 | if (input.n_steps[i] <= 0 || input.n_steps[i] % 2 != 0) { |
| 29 | return false; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | 96 | return static_cast<bool>(input.func); | |
| 33 | } | ||
| 34 | |||
| 35 | 96 | bool ZyuzinNSimpsonSEQ::PreProcessingImpl() { | |
| 36 | 96 | result_ = 0.0; | |
| 37 | 96 | return true; | |
| 38 | } | ||
| 39 | |||
| 40 | ✗ | double ZyuzinNSimpsonSEQ::GetSimpsonWeight(int index, int n) { | |
| 41 |
2/4✓ Branch 0 taken 815168 times.
✓ Branch 1 taken 72544 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
887712 | if (index == 0 || index == n) { |
| 42 | return 1.0; | ||
| 43 | } | ||
| 44 |
2/4✓ Branch 0 taken 425720 times.
✓ Branch 1 taken 389448 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
815168 | if (index % 2 == 1) { |
| 45 | 425720 | return 4.0; | |
| 46 | } | ||
| 47 | return 2.0; | ||
| 48 | } | ||
| 49 | |||
| 50 | 96 | double ZyuzinNSimpsonSEQ::ComputeSimpsonMultiDim() { | |
| 51 | const auto &input = GetInput(); | ||
| 52 | const size_t num_dims = input.lower_bounds.size(); | ||
| 53 | |||
| 54 | 96 | std::vector<double> h(num_dims); | |
| 55 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 96 times.
|
288 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 56 | 192 | h[dim] = (input.upper_bounds[dim] - input.lower_bounds[dim]) / input.n_steps[dim]; | |
| 57 | } | ||
| 58 | |||
| 59 | size_t total_points = 1; | ||
| 60 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 96 times.
|
288 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 61 | 192 | total_points *= static_cast<size_t>(input.n_steps[dim] + 1); | |
| 62 | } | ||
| 63 | |||
| 64 | double sum = 0.0; | ||
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 333936 times.
✓ Branch 1 taken 96 times.
|
334032 | for (size_t point_idx = 0; point_idx < total_points; ++point_idx) { |
| 67 |
1/4✓ Branch 1 taken 333936 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
333936 | std::vector<int> indices(num_dims); |
| 68 | size_t temp = point_idx; | ||
| 69 |
2/2✓ Branch 0 taken 887712 times.
✓ Branch 1 taken 333936 times.
|
1221648 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 70 | 887712 | indices[dim] = static_cast<int>(temp % static_cast<size_t>(input.n_steps[dim] + 1)); | |
| 71 | 887712 | temp /= static_cast<size_t>(input.n_steps[dim] + 1); | |
| 72 | } | ||
| 73 | |||
| 74 |
1/4✓ Branch 1 taken 333936 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
333936 | std::vector<double> point(num_dims); |
| 75 |
2/2✓ Branch 0 taken 887712 times.
✓ Branch 1 taken 333936 times.
|
1221648 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 76 | 887712 | point[dim] = input.lower_bounds[dim] + (indices[dim] * h[dim]); | |
| 77 | } | ||
| 78 | |||
| 79 | double weight = 1.0; | ||
| 80 |
2/2✓ Branch 0 taken 887712 times.
✓ Branch 1 taken 333936 times.
|
1221648 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 81 |
2/2✓ Branch 0 taken 815168 times.
✓ Branch 1 taken 72544 times.
|
1702880 | weight *= GetSimpsonWeight(indices[dim], input.n_steps[dim]); |
| 82 | } | ||
| 83 | |||
| 84 |
1/2✓ Branch 0 taken 333936 times.
✗ Branch 1 not taken.
|
333936 | sum += weight * input.func(point); |
| 85 | } | ||
| 86 | |||
| 87 | double factor = 1.0; | ||
| 88 |
2/2✓ Branch 0 taken 192 times.
✓ Branch 1 taken 96 times.
|
288 | for (size_t dim = 0; dim < num_dims; ++dim) { |
| 89 | 192 | factor *= h[dim] / 3.0; | |
| 90 | } | ||
| 91 | |||
| 92 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
192 | return sum * factor; |
| 93 | } | ||
| 94 | |||
| 95 | 96 | bool ZyuzinNSimpsonSEQ::RunImpl() { | |
| 96 | 96 | result_ = ComputeSimpsonMultiDim(); | |
| 97 | 96 | return true; | |
| 98 | } | ||
| 99 | |||
| 100 | 96 | bool ZyuzinNSimpsonSEQ::PostProcessingImpl() { | |
| 101 | 96 | GetOutput() = result_; | |
| 102 | 96 | return true; | |
| 103 | } | ||
| 104 | |||
| 105 | } // namespace zyuzin_n_multi_integrals_simpson | ||
| 106 |