GCC Code Coverage Report


Directory: ./
File: tasks/kosolapov_v_gauss_method_tape_hor_scheme/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 60 64 93.8%
Functions: 9 10 90.0%
Branches: 36 54 66.7%

Line Branch Exec Source
1 #include "kosolapov_v_gauss_method_tape_hor_scheme/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "kosolapov_v_gauss_method_tape_hor_scheme/common/include/common.hpp"
9
10 namespace kosolapov_v_gauss_method_tape_hor_scheme {
11
12
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 KosolapovVGaussMethodTapeHorSchemeSEQ::KosolapovVGaussMethodTapeHorSchemeSEQ(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
3/6
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 72 times.
✗ Branch 9 not taken.
72 GetInput() = InType(in);
15 GetOutput() = {};
16 72 }
17
18
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 bool KosolapovVGaussMethodTapeHorSchemeSEQ::ValidationImpl() {
19 const auto &input = GetInput();
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (input.matrix.empty()) {
21 return false;
22 }
23 72 int n = static_cast<int>(input.matrix.size());
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (input.matrix.size() != static_cast<size_t>(n)) {
25 return false;
26 }
27
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 72 times.
392 for (const auto &row : input.matrix) {
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 320 times.
320 if (row.size() != static_cast<size_t>(n)) {
29 return false;
30 }
31 }
32 72 return input.r_side.size() == static_cast<size_t>(n);
33 }
34
35 72 bool KosolapovVGaussMethodTapeHorSchemeSEQ::PreProcessingImpl() {
36 const auto &input = GetInput();
37 72 int n = static_cast<int>(input.matrix.size());
38 72 GetOutput() = std::vector<double>(n, 0.0);
39 72 return true;
40 }
41
42 72 bool KosolapovVGaussMethodTapeHorSchemeSEQ::RunImpl() {
43 const auto &input = GetInput();
44 72 int n = static_cast<int>(input.matrix.size());
45
46 72 std::vector<std::vector<double>> a = input.matrix;
47
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 std::vector<double> b = input.r_side;
48
1/4
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
72 std::vector<int> col_order(n);
49
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 72 times.
392 for (int i = 0; i < n; i++) {
50 320 col_order[i] = i;
51 }
52 72 ForwardElimination(a, b, col_order, n);
53
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 std::vector<double> result = BackwardSubstitution(a, b, col_order, n);
54
1/2
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
72 GetOutput() = result;
55 72 return true;
56 72 }
57
58 72 bool KosolapovVGaussMethodTapeHorSchemeSEQ::PostProcessingImpl() {
59 72 return true;
60 }
61
62 72 void KosolapovVGaussMethodTapeHorSchemeSEQ::ForwardElimination(std::vector<std::vector<double>> &a,
63 std::vector<double> &b, std::vector<int> &col_order,
64 int n) {
65
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 72 times.
392 for (int i = 0; i < n; i++) {
66 int leading_col = i;
67 320 double max_elem = std::abs(a[i][i]);
68 SelectPivot(i, n, a, max_elem, leading_col);
69 320 SwapRows(leading_col, n, i, a, col_order);
70 320 double cur_el = a[i][i];
71
2/2
✓ Branch 0 taken 952 times.
✓ Branch 1 taken 320 times.
1272 for (int j = i; j < n; j++) {
72 952 a[i][j] /= cur_el;
73 }
74 320 b[i] /= cur_el;
75 320 RowSub(i, n, a, b);
76 }
77 72 }
78 72 std::vector<double> KosolapovVGaussMethodTapeHorSchemeSEQ::BackwardSubstitution(std::vector<std::vector<double>> &a,
79 std::vector<double> &b,
80 std::vector<int> &col_order, int n) {
81 72 std::vector<double> output(n);
82
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 72 times.
392 for (int i = n - 1; i >= 0; --i) {
83 320 output[col_order[i]] = b[i];
84
2/2
✓ Branch 0 taken 632 times.
✓ Branch 1 taken 320 times.
952 for (int j = i + 1; j < n; ++j) {
85 632 output[col_order[i]] -= a[i][j] * output[col_order[j]];
86 }
87 }
88 72 return output;
89 }
90 void KosolapovVGaussMethodTapeHorSchemeSEQ::SelectPivot(int i, int n, const std::vector<std::vector<double>> &a,
91 double &max_elem, int &leading_col) {
92
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 632 times.
✓ Branch 3 taken 320 times.
952 for (int j = i + 1; j < n; j++) {
93
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 568 times.
632 if (std::abs(a[i][j]) > max_elem) {
94 max_elem = std::abs(a[i][j]);
95 leading_col = j;
96 }
97 }
98 }
99 320 void KosolapovVGaussMethodTapeHorSchemeSEQ::SwapRows(int leading_col, int n, int i, std::vector<std::vector<double>> &a,
100 std::vector<int> &col_order) {
101
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 272 times.
320 if (leading_col != i) {
102
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 48 times.
232 for (int k = 0; k < n; k++) {
103 184 std::swap(a[k][i], a[k][leading_col]);
104 }
105 48 std::swap(col_order[i], col_order[leading_col]);
106 }
107 320 }
108 320 void KosolapovVGaussMethodTapeHorSchemeSEQ::RowSub(int i, int n, std::vector<std::vector<double>> &a,
109 std::vector<double> &b) {
110
2/2
✓ Branch 0 taken 632 times.
✓ Branch 1 taken 320 times.
952 for (int k = i + 1; k < n; k++) {
111 632 double ratio = a[k][i];
112
2/2
✓ Branch 0 taken 2784 times.
✓ Branch 1 taken 632 times.
3416 for (int j = i; j < n; j++) {
113 2784 a[k][j] -= ratio * a[i][j];
114 }
115 632 b[k] -= ratio * b[i];
116 }
117 320 }
118 } // namespace kosolapov_v_gauss_method_tape_hor_scheme
119