| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "spichek_d_jacobi/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "spichek_d_jacobi/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace spichek_d_jacobi { | ||
| 12 | |||
| 13 | 56 | SpichekDJacobiSEQ::SpichekDJacobiSEQ(InType in) : input_(std::move(in)) { | |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | 56 | } | |
| 16 | |||
| 17 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | bool SpichekDJacobiSEQ::ValidationImpl() { |
| 18 | const auto &[A, b, eps, max_iter] = input_; | ||
| 19 |
4/8✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 56 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 56 times.
|
56 | return !A.empty() && A.size() == b.size() && eps > 0 && max_iter > 0; |
| 20 | } | ||
| 21 | |||
| 22 | 56 | bool SpichekDJacobiSEQ::PreProcessingImpl() { | |
| 23 | GetInput() = input_; | ||
| 24 | 56 | GetOutput().assign(std::get<1>(input_).size(), 0.0); | |
| 25 | 56 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 56 | bool SpichekDJacobiSEQ::RunImpl() { | |
| 29 | const auto &[A, b, eps, max_iter] = GetInput(); | ||
| 30 | size_t n = b.size(); | ||
| 31 | |||
| 32 | 56 | std::vector<double> x(n, 0.0); | |
| 33 |
1/4✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
56 | std::vector<double> x_new(n, 0.0); |
| 34 | |||
| 35 |
1/2✓ Branch 0 taken 464 times.
✗ Branch 1 not taken.
|
464 | for (int iter = 0; iter < max_iter; ++iter) { |
| 36 | 464 | double max_diff = 0.0; | |
| 37 | |||
| 38 |
2/2✓ Branch 0 taken 1568 times.
✓ Branch 1 taken 464 times.
|
2032 | for (size_t i = 0; i < n; ++i) { |
| 39 | double sum = 0.0; | ||
| 40 |
2/2✓ Branch 0 taken 5792 times.
✓ Branch 1 taken 1568 times.
|
7360 | for (size_t j = 0; j < n; ++j) { |
| 41 |
2/2✓ Branch 0 taken 4224 times.
✓ Branch 1 taken 1568 times.
|
5792 | if (j != i) { |
| 42 | 4224 | sum += A[i][j] * x[j]; | |
| 43 | } | ||
| 44 | } | ||
| 45 | 1568 | x_new[i] = (b[i] - sum) / A[i][i]; | |
| 46 | 1568 | max_diff = std::max(max_diff, std::abs(x_new[i] - x[i])); | |
| 47 | } | ||
| 48 | |||
| 49 |
1/2✓ Branch 1 taken 464 times.
✗ Branch 2 not taken.
|
464 | x = x_new; |
| 50 |
2/2✓ Branch 0 taken 408 times.
✓ Branch 1 taken 56 times.
|
464 | if (max_diff < eps) { |
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 |
1/2✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
|
56 | GetOutput() = x; |
| 56 | 56 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | 56 | bool SpichekDJacobiSEQ::PostProcessingImpl() { | |
| 60 | 56 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | } // namespace spichek_d_jacobi | ||
| 64 |