GCC Code Coverage Report


Directory: ./
File: tasks/alekseev_a_mult_matrix_crs/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 40 40 100.0%
Functions: 6 6 100.0%
Branches: 38 58 65.5%

Line Branch Exec Source
1 #include "alekseev_a_mult_matrix_crs/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <utility>
7 #include <vector>
8
9 #include "alekseev_a_mult_matrix_crs/common/include/common.hpp"
10
11 namespace alekseev_a_mult_matrix_crs {
12
13 namespace {
14 96 bool IsValidCRS(const CRSMatrix &m) {
15
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 if (m.rows == 0 || m.cols == 0) {
16 return false;
17 }
18
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 if (m.row_ptr.size() != m.rows + 1) {
19 return false;
20 }
21
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 if (m.row_ptr.empty() || m.row_ptr.front() != 0) {
22 return false;
23 }
24
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 if (m.row_ptr.back() != m.values.size() || m.col_indices.size() != m.values.size()) {
25 return false;
26 }
27
28
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 96 times.
296 for (std::size_t i = 0; i < m.rows; ++i) {
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
200 if (m.row_ptr[i] > m.row_ptr[i + 1]) {
30 return false;
31 }
32 }
33 return std::ranges::all_of(m.col_indices, [&m](std::size_t idx) { return idx < m.cols; });
34 }
35 } // namespace
36
37
1/2
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 AlekseevAMultMatrixCRSSEQ::AlekseevAMultMatrixCRSSEQ(const InType &in) {
38 SetTypeOfTask(GetStaticTypeOfTask());
39 GetInput() = in;
40 48 }
41
42
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 bool AlekseevAMultMatrixCRSSEQ::ValidationImpl() {
43 const auto &a = std::get<0>(GetInput());
44 const auto &b = std::get<1>(GetInput());
45
3/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48 times.
48 return IsValidCRS(a) && IsValidCRS(b) && a.cols == b.rows;
46 }
47
48 48 bool AlekseevAMultMatrixCRSSEQ::PreProcessingImpl() {
49 48 GetOutput() = {};
50 48 return true;
51 }
52
53 48 bool AlekseevAMultMatrixCRSSEQ::RunImpl() {
54 const auto &a = std::get<0>(GetInput());
55 const auto &b = std::get<1>(GetInput());
56 auto &c = GetOutput();
57
58 48 c.rows = a.rows;
59 48 c.cols = b.cols;
60 48 c.row_ptr.assign(c.rows + 1, 0);
61
62 48 std::vector<double> accum(c.cols, 0.0);
63
1/4
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
48 std::vector<int> touched_flag(c.cols, -1);
64 48 std::vector<std::size_t> touched_cols;
65
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 touched_cols.reserve(c.cols);
66
67
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
144 for (std::size_t i = 0; i < a.rows; ++i) {
68
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 96 times.
200 for (std::size_t pos_a = a.row_ptr[i]; pos_a < a.row_ptr[i + 1]; ++pos_a) {
69 104 std::size_t k = a.col_indices[pos_a];
70 104 double val_a = a.values[pos_a];
71
72
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 104 times.
264 for (std::size_t pos_b = b.row_ptr[k]; pos_b < b.row_ptr[k + 1]; ++pos_b) {
73
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 80 times.
160 std::size_t j = b.col_indices[pos_b];
74
75
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 80 times.
160 if (std::cmp_not_equal(touched_flag[j], i)) {
76
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 touched_flag[j] = static_cast<int>(i);
77 touched_cols.push_back(j);
78 120 accum[j] = 0.0;
79 }
80 160 accum[j] += val_a * b.values[pos_b];
81 }
82 }
83
84 std::ranges::sort(touched_cols);
85
86
3/4
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 96 times.
216 for (auto col : touched_cols) {
87
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (std::abs(accum[col]) > 1e-15) {
88
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
120 c.values.push_back(accum[col]);
89
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
120 c.col_indices.push_back(col);
90 }
91 }
92
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 16 times.
96 c.row_ptr[i + 1] = c.values.size();
93 touched_cols.clear();
94 }
95 48 return true;
96 }
97
98 48 bool AlekseevAMultMatrixCRSSEQ::PostProcessingImpl() {
99 48 return true;
100 }
101
102 } // namespace alekseev_a_mult_matrix_crs
103