GCC Code Coverage Report


Directory: ./
File: tasks/kiselev_i_gauss_method_horizontal_tape_scheme/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 6 6 100.0%
Branches: 25 38 65.8%

Line Branch Exec Source
1 #include "kiselev_i_gauss_method_horizontal_tape_scheme/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <tuple>
7 #include <vector>
8
9 #include "kiselev_i_gauss_method_horizontal_tape_scheme/common/include/common.hpp"
10
11 namespace kiselev_i_gauss_method_horizontal_tape_scheme {
12
13
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 KiselevITestTaskSEQ::KiselevITestTaskSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 auto &buf = GetInput();
16 InType tmp(in);
17 buf.swap(tmp);
18 GetOutput().clear();
19 112 }
20
21
1/2
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
112 bool KiselevITestTaskSEQ::ValidationImpl() {
22 const auto &a_vector = std::get<0>(GetInput());
23 const auto &b_vector = std::get<1>(GetInput());
24
25
3/6
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 112 times.
112 return !a_vector.empty() && a_vector.size() == b_vector.size() && GetOutput().empty();
26 }
27
28
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 bool KiselevITestTaskSEQ::PreProcessingImpl() {
29 GetOutput().clear();
30 112 return true;
31 }
32
33 namespace {
34
35 112 void BackSubstitution(const std::vector<std::vector<double>> &mat, const std::vector<double> &rhs,
36 std::vector<double> &result, std::size_t band) {
37 const std::size_t num = mat.size();
38
39
2/2
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 112 times.
520 for (std::size_t step = 0; step < num; ++step) {
40 408 const std::size_t index = num - 1 - step;
41 408 double acc = rhs[index];
42
43 408 const std::size_t col_end = std::min(num, index + band + 1);
44
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 408 times.
704 for (std::size_t j = index + 1; j < col_end; ++j) {
45 296 acc -= mat[index][j] * result[j];
46 }
47
48 408 result[index] = acc;
49 }
50 112 }
51
52 } // namespace
53
54 112 bool KiselevITestTaskSEQ::RunImpl() {
55 112 auto mat = std::get<0>(GetInput());
56
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 auto rhs = std::get<1>(GetInput());
57
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 const std::size_t band = std::get<2>(GetInput());
58
59
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 const std::size_t num = mat.size();
60
1/4
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
112 GetOutput().assign(num, 0.0);
61
62 constexpr double kEps = 1e-12;
63
64
2/2
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 112 times.
520 for (std::size_t k_index = 0; k_index < num; ++k_index) {
65 408 const double diag = mat[k_index][k_index];
66
1/2
✓ Branch 0 taken 408 times.
✗ Branch 1 not taken.
408 if (std::fabs(diag) < kEps) {
67 return false;
68 }
69
70 408 const std::size_t col_end = std::min(num, k_index + band + 1);
71
72
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 408 times.
1112 for (std::size_t j_index = k_index; j_index < col_end; ++j_index) {
73 704 mat[k_index][j_index] /= diag;
74 }
75 408 rhs[k_index] /= diag;
76
77 const std::size_t row_end = std::min(num, k_index + band + 1);
78
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 408 times.
704 for (std::size_t index = k_index + 1; index < row_end; ++index) {
79 296 const double factor = mat[index][k_index];
80
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 272 times.
296 if (factor == 0.0) {
81 24 continue;
82 }
83
84
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 272 times.
944 for (std::size_t j_index = k_index; j_index < col_end; ++j_index) {
85 672 mat[index][j_index] -= factor * mat[k_index][j_index];
86 }
87 272 rhs[index] -= factor * rhs[k_index];
88 }
89 }
90
91 112 BackSubstitution(mat, rhs, GetOutput(), band);
92 112 return true;
93 112 }
94
95 112 bool KiselevITestTaskSEQ::PostProcessingImpl() {
96 112 return !GetOutput().empty();
97 }
98
99 } // namespace kiselev_i_gauss_method_horizontal_tape_scheme
100