| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "sannikov_i_horizontal_band_gauss/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <tuple> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "sannikov_i_horizontal_band_gauss/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace sannikov_i_horizontal_band_gauss { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | SannikovIHorizontalBandGaussSEQ::SannikovIHorizontalBandGaussSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | auto &input_buffer = GetInput(); | ||
| 16 | InType tmp(in); | ||
| 17 | input_buffer.swap(tmp); | ||
| 18 | GetOutput().clear(); | ||
| 19 | 96 | } | |
| 20 | |||
| 21 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | bool SannikovIHorizontalBandGaussSEQ::ValidationImpl() { |
| 22 | (void)this; | ||
| 23 | |||
| 24 | const auto &a = std::get<0>(GetInput()); | ||
| 25 | const auto &rhs = std::get<1>(GetInput()); | ||
| 26 | |||
| 27 |
2/4✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
|
96 | if (a.empty() || rhs.empty()) { |
| 28 | return false; | ||
| 29 | } | ||
| 30 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | if (a.size() != rhs.size()) { |
| 31 | return false; | ||
| 32 | } | ||
| 33 | 96 | return GetOutput().empty(); | |
| 34 | } | ||
| 35 | |||
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | bool SannikovIHorizontalBandGaussSEQ::PreProcessingImpl() { |
| 37 | (void)this; | ||
| 38 | |||
| 39 | GetOutput().clear(); | ||
| 40 | 96 | return GetOutput().empty(); | |
| 41 | } | ||
| 42 | |||
| 43 | 96 | bool SannikovIHorizontalBandGaussSEQ::RunImpl() { | |
| 44 | (void)this; | ||
| 45 | |||
| 46 | 96 | auto a = std::get<0>(GetInput()); | |
| 47 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | auto rhs = std::get<1>(GetInput()); |
| 48 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | const std::size_t band = std::get<2>(GetInput()); |
| 49 | |||
| 50 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | const std::size_t n = a.size(); |
| 51 |
1/4✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
96 | GetOutput().assign(n, 0.0); |
| 52 | |||
| 53 | constexpr double kEps = 1e-8; | ||
| 54 | |||
| 55 |
2/2✓ Branch 0 taken 376 times.
✓ Branch 1 taken 96 times.
|
472 | for (std::size_t i = 0; i < n; ++i) { |
| 56 | 376 | const double pivot = a[i][i]; | |
| 57 |
1/2✓ Branch 0 taken 376 times.
✗ Branch 1 not taken.
|
376 | if (std::fabs(pivot) < kEps) { |
| 58 | return false; | ||
| 59 | } | ||
| 60 | |||
| 61 | 376 | const std::size_t j_end = std::min(n, i + band + 1); | |
| 62 | |||
| 63 |
2/2✓ Branch 0 taken 680 times.
✓ Branch 1 taken 376 times.
|
1056 | for (std::size_t j = i; j < j_end; ++j) { |
| 64 | 680 | a[i][j] /= pivot; | |
| 65 | } | ||
| 66 | 376 | rhs[i] /= pivot; | |
| 67 | |||
| 68 | const std::size_t row_end = std::min(n, i + band + 1); | ||
| 69 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 376 times.
|
680 | for (std::size_t row = i + 1; row < row_end; ++row) { |
| 70 | 304 | const double mult = a[row][i]; | |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 768 times.
✓ Branch 1 taken 304 times.
|
1072 | for (std::size_t j = i; j < j_end; ++j) { |
| 73 | 768 | a[row][j] -= mult * a[i][j]; | |
| 74 | } | ||
| 75 | 304 | rhs[row] -= mult * rhs[i]; | |
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 |
2/2✓ Branch 0 taken 376 times.
✓ Branch 1 taken 96 times.
|
472 | for (std::size_t idx = 0; idx < n; ++idx) { |
| 80 | 376 | const std::size_t i = n - 1 - idx; | |
| 81 | 376 | double sum = rhs[i]; | |
| 82 | |||
| 83 | 376 | const std::size_t j_end = std::min(n, i + band + 1); | |
| 84 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 376 times.
|
680 | for (std::size_t j = i + 1; j < j_end; ++j) { |
| 85 | 304 | sum -= a[i][j] * GetOutput()[j]; | |
| 86 | } | ||
| 87 | 376 | GetOutput()[i] = sum; | |
| 88 | } | ||
| 89 | |||
| 90 | 96 | return !GetOutput().empty(); | |
| 91 | 96 | } | |
| 92 | |||
| 93 | 96 | bool SannikovIHorizontalBandGaussSEQ::PostProcessingImpl() { | |
| 94 | (void)this; | ||
| 95 | |||
| 96 | 96 | return !GetOutput().empty(); | |
| 97 | } | ||
| 98 | |||
| 99 | } // namespace sannikov_i_horizontal_band_gauss | ||
| 100 |