| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "tochilin_e_integral_trapezium/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "tochilin_e_integral_trapezium/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace tochilin_e_integral_trapezium { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | TochilinEIntegralTrapeziumSEQ::TochilinEIntegralTrapeziumSEQ(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
|
120 | GetInput() = in; |
| 13 | 120 | GetOutput() = 0.0; | |
| 14 | 120 | } | |
| 15 | |||
| 16 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | bool TochilinEIntegralTrapeziumSEQ::ValidationImpl() { |
| 17 | const auto &input = GetInput(); | ||
| 18 | |||
| 19 |
2/4✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
|
120 | if (input.lower_bounds.empty() || input.upper_bounds.empty()) { |
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (input.lower_bounds.size() != input.upper_bounds.size()) { |
| 24 | return false; | ||
| 25 | } | ||
| 26 | |||
| 27 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (input.num_steps <= 0) { |
| 28 | return false; | ||
| 29 | } | ||
| 30 | |||
| 31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (!input.func) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 | |||
| 35 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 120 times.
|
320 | for (std::size_t idx = 0; idx < input.lower_bounds.size(); ++idx) { |
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | if (input.lower_bounds[idx] > input.upper_bounds[idx]) { |
| 37 | return false; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | return true; | ||
| 42 | } | ||
| 43 | |||
| 44 | 120 | bool TochilinEIntegralTrapeziumSEQ::PreProcessingImpl() { | |
| 45 | const auto &input = GetInput(); | ||
| 46 | 120 | lower_bounds_ = input.lower_bounds; | |
| 47 | 120 | upper_bounds_ = input.upper_bounds; | |
| 48 | 120 | num_steps_ = input.num_steps; | |
| 49 | 120 | func_ = input.func; | |
| 50 | 120 | result_ = 0.0; | |
| 51 | 120 | return true; | |
| 52 | } | ||
| 53 | |||
| 54 | 120 | double TochilinEIntegralTrapeziumSEQ::ComputeIntegral() { | |
| 55 | std::size_t dimensions = lower_bounds_.size(); | ||
| 56 | 120 | std::vector<double> step_sizes(dimensions); | |
| 57 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 120 times.
|
320 | for (std::size_t idx = 0; idx < dimensions; ++idx) { |
| 58 | 200 | step_sizes[idx] = (upper_bounds_[idx] - lower_bounds_[idx]) / num_steps_; | |
| 59 | } | ||
| 60 | |||
| 61 | int total_points = 1; | ||
| 62 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 120 times.
|
320 | for (std::size_t idx = 0; idx < dimensions; ++idx) { |
| 63 | 200 | total_points *= (num_steps_ + 1); | |
| 64 | } | ||
| 65 | |||
| 66 | double sum = 0.0; | ||
| 67 |
1/4✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
120 | std::vector<double> point(dimensions); |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 750928 times.
✓ Branch 1 taken 120 times.
|
751048 | for (int idx = 0; idx < total_points; ++idx) { |
| 70 | int temp = idx; | ||
| 71 | double weight = 1.0; | ||
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 1804608 times.
✓ Branch 1 taken 750928 times.
|
2555536 | for (std::size_t dim = 0; dim < dimensions; ++dim) { |
| 74 | 1804608 | int grid_idx = temp % (num_steps_ + 1); | |
| 75 |
2/2✓ Branch 0 taken 1762008 times.
✓ Branch 1 taken 42600 times.
|
1804608 | temp /= (num_steps_ + 1); |
| 76 | 1804608 | point[dim] = lower_bounds_[dim] + (grid_idx * step_sizes[dim]); | |
| 77 | |||
| 78 |
4/4✓ Branch 0 taken 1762008 times.
✓ Branch 1 taken 42600 times.
✓ Branch 2 taken 42600 times.
✓ Branch 3 taken 1719408 times.
|
1804608 | if (grid_idx == 0 || grid_idx == num_steps_) { |
| 79 | 85200 | weight *= 0.5; | |
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | 750928 | sum += weight * func_(point); | |
| 84 | } | ||
| 85 | |||
| 86 | double volume = 1.0; | ||
| 87 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 120 times.
|
320 | for (std::size_t idx = 0; idx < dimensions; ++idx) { |
| 88 | 200 | volume *= step_sizes[idx]; | |
| 89 | } | ||
| 90 | |||
| 91 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
240 | return sum * volume; |
| 92 | } | ||
| 93 | |||
| 94 | 120 | bool TochilinEIntegralTrapeziumSEQ::RunImpl() { | |
| 95 | 120 | result_ = ComputeIntegral(); | |
| 96 | 120 | return true; | |
| 97 | } | ||
| 98 | |||
| 99 | 120 | bool TochilinEIntegralTrapeziumSEQ::PostProcessingImpl() { | |
| 100 | 120 | GetOutput() = result_; | |
| 101 | 120 | return true; | |
| 102 | } | ||
| 103 | |||
| 104 | } // namespace tochilin_e_integral_trapezium | ||
| 105 |