| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "dorofeev_i_monte_carlo_integration/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <random> | ||
| 6 | #include <ranges> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "dorofeev_i_monte_carlo_integration/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace dorofeev_i_monte_carlo_integration_processes { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | DorofeevIMonteCarloIntegrationSEQ::DorofeevIMonteCarloIntegrationSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | GetInput() = in; |
| 17 | 64 | GetOutput() = 0.0; | |
| 18 | 64 | } | |
| 19 | |||
| 20 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | bool DorofeevIMonteCarloIntegrationSEQ::ValidationImpl() { |
| 21 | const auto &in = GetInput(); | ||
| 22 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
|
128 | return in.func && !in.a.empty() && in.a.size() == in.b.size() && |
| 23 |
2/4✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
128 | std::ranges::all_of(std::views::iota(size_t{0}, in.a.size()), [&](size_t i) { return in.b[i] > in.a[i]; }) && |
| 24 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
|
64 | in.samples > 0; |
| 25 | } | ||
| 26 | |||
| 27 | 64 | bool DorofeevIMonteCarloIntegrationSEQ::PreProcessingImpl() { | |
| 28 | 64 | GetOutput() = 0.0; | |
| 29 | 64 | return true; | |
| 30 | } | ||
| 31 | |||
| 32 | 64 | bool DorofeevIMonteCarloIntegrationSEQ::RunImpl() { | |
| 33 | const auto &in = GetInput(); | ||
| 34 | const std::size_t dims = in.a.size(); | ||
| 35 | 64 | const int n = in.samples; | |
| 36 | |||
| 37 | int seed = 777; | ||
| 38 | std::mt19937 gen(seed); | ||
| 39 | 64 | std::vector<std::uniform_real_distribution<double>> dist; | |
| 40 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | dist.reserve(dims); |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 64 times.
|
128 | for (std::size_t i = 0; std::cmp_less(i, dims); i++) { |
| 43 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | dist.emplace_back(in.a[i], in.b[i]); |
| 44 | } | ||
| 45 | |||
| 46 | double sum = 0.0; | ||
| 47 |
1/4✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
64 | std::vector<double> point(dims); |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 1272008 times.
✓ Branch 1 taken 64 times.
|
1272072 | for (int sample = 0; sample < n; sample++) { |
| 50 |
2/2✓ Branch 0 taken 1272008 times.
✓ Branch 1 taken 1272008 times.
|
2544016 | for (std::size_t dim = 0; dim < dims; dim++) { |
| 51 | 1272008 | point[dim] = dist[dim](gen); | |
| 52 | } | ||
| 53 | 1272008 | sum += in.func(point); | |
| 54 | } | ||
| 55 | |||
| 56 | double volume = 1.0; | ||
| 57 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 64 times.
|
128 | for (std::size_t i = 0; std::cmp_less(i, dims); i++) { |
| 58 | 64 | volume *= (in.b[i] - in.a[i]); | |
| 59 | } | ||
| 60 | |||
| 61 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | GetOutput() = volume * (sum / n); |
| 62 | 64 | return true; | |
| 63 | } | ||
| 64 | |||
| 65 | 64 | bool DorofeevIMonteCarloIntegrationSEQ::PostProcessingImpl() { | |
| 66 | 64 | return true; | |
| 67 | } | ||
| 68 | |||
| 69 | } // namespace dorofeev_i_monte_carlo_integration_processes | ||
| 70 |