| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "shvetsova_k_gausse_vert_strip/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "shvetsova_k_gausse_vert_strip/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace shvetsova_k_gausse_vert_strip { | ||
| 10 | |||
| 11 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | ShvetsovaKGaussVertStripSEQ::ShvetsovaKGaussVertStripSEQ(const InType &in) : size_of_rib_(1) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | auto &input_buffer = GetInput(); | ||
| 14 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | InType tmp(in); |
| 15 | input_buffer.swap(tmp); | ||
| 16 | GetOutput().clear(); | ||
| 17 | 40 | } | |
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool ShvetsovaKGaussVertStripSEQ::ValidationImpl() { |
| 20 | const auto &matrix = GetInput().first; | ||
| 21 | const auto &vec = GetInput().second; | ||
| 22 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (matrix.empty()) { |
| 23 | return true; | ||
| 24 | } | ||
| 25 | 40 | return matrix.size() == vec.size(); | |
| 26 | } | ||
| 27 | |||
| 28 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool ShvetsovaKGaussVertStripSEQ::PreProcessingImpl() { |
| 29 | const auto &matrix = GetInput().first; | ||
| 30 | 40 | int n = static_cast<int>(matrix.size()); | |
| 31 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (n == 0) { |
| 32 | return true; | ||
| 33 | } | ||
| 34 | |||
| 35 | 40 | size_of_rib_ = 1; | |
| 36 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 40 times.
|
240 | for (int i = 0; i < n; ++i) { |
| 37 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 200 times.
|
1200 | for (int j = 0; j < n; ++j) { |
| 38 |
4/4✓ Branch 0 taken 800 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 320 times.
✓ Branch 3 taken 480 times.
|
1000 | if (i != j && std::abs(matrix[i][j]) > 1e-12) { |
| 39 | 320 | size_of_rib_ = std::max(size_of_rib_, std::abs(i - j) + 1); | |
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | return true; | ||
| 44 | } | ||
| 45 | |||
| 46 | 200 | void ShvetsovaKGaussVertStripSEQ::ProcessRow(int i, int row_end, std::vector<std::vector<double>> &a, | |
| 47 | std::vector<double> &x, double eps) { | ||
| 48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | double pivot = a[i][i]; |
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | if (std::abs(pivot) < eps) { |
| 50 | ✗ | pivot = (pivot >= 0) ? eps : -eps; | |
| 51 | } | ||
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 360 times.
✓ Branch 1 taken 200 times.
|
560 | for (int j = i; j < row_end; ++j) { |
| 54 | 360 | a[i][j] /= pivot; | |
| 55 | } | ||
| 56 | 200 | x[i] /= pivot; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 200 times.
|
360 | for (int k = i + 1; k < row_end; ++k) { |
| 59 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | double factor = a[k][i]; |
| 60 |
1/2✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
|
160 | if (std::abs(factor) < eps) { |
| 61 | ✗ | continue; | |
| 62 | } | ||
| 63 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 160 times.
|
480 | for (int j = i; j < row_end; ++j) { |
| 64 | 320 | a[k][j] -= factor * a[i][j]; | |
| 65 | } | ||
| 66 | 160 | x[k] -= factor * x[i]; | |
| 67 | } | ||
| 68 | 200 | } | |
| 69 | |||
| 70 | ✗ | void ShvetsovaKGaussVertStripSEQ::ForwardElimination(int n, std::vector<std::vector<double>> &a, | |
| 71 | std::vector<double> &x) const { | ||
| 72 | const double eps = 1e-15; | ||
| 73 |
2/4✓ Branch 0 taken 200 times.
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
240 | for (int i = 0; i < n; ++i) { |
| 74 | 200 | int row_end = std::min(n, i + size_of_rib_); | |
| 75 | 200 | ProcessRow(i, row_end, a, x, eps); | |
| 76 | } | ||
| 77 | ✗ | } | |
| 78 | |||
| 79 | 40 | std::vector<double> ShvetsovaKGaussVertStripSEQ::BackSubstitution(int n, const std::vector<std::vector<double>> &a, | |
| 80 | const std::vector<double> &x) const { | ||
| 81 | 40 | std::vector<double> res(n); | |
| 82 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 40 times.
|
240 | for (int i = n - 1; i >= 0; --i) { |
| 83 | 200 | double sum = x[i]; | |
| 84 | 200 | int row_end = std::min(n, i + size_of_rib_); | |
| 85 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 200 times.
|
360 | for (int j = i + 1; j < row_end; ++j) { |
| 86 | 160 | sum -= a[i][j] * res[j]; | |
| 87 | } | ||
| 88 | 200 | res[i] = sum; | |
| 89 | } | ||
| 90 | 40 | return res; | |
| 91 | } | ||
| 92 | |||
| 93 | 40 | bool ShvetsovaKGaussVertStripSEQ::RunImpl() { | |
| 94 | 40 | const auto &matrix_a = GetInput().first; | |
| 95 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | const auto &vec_b = GetInput().second; |
| 96 | 40 | int n = static_cast<int>(matrix_a.size()); | |
| 97 | |||
| 98 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (n == 0) { |
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | 40 | std::vector<std::vector<double>> a = matrix_a; | |
| 103 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | std::vector<double> x = vec_b; |
| 104 | |||
| 105 | ForwardElimination(n, a, x); | ||
| 106 |
2/6✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
80 | GetOutput() = BackSubstitution(n, a, x); |
| 107 | |||
| 108 | return true; | ||
| 109 | 40 | } | |
| 110 | |||
| 111 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool ShvetsovaKGaussVertStripSEQ::PostProcessingImpl() { |
| 112 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | if (GetInput().first.empty()) { |
| 113 | return true; | ||
| 114 | } | ||
| 115 | 40 | return !GetOutput().empty(); | |
| 116 | } | ||
| 117 | |||
| 118 | } // namespace shvetsova_k_gausse_vert_strip | ||
| 119 |