GCC Code Coverage Report


Directory: ./
File: tasks/vlasova_a_matrix_multiply_ccs/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 65 68 95.6%
Functions: 8 8 100.0%
Branches: 47 80 58.8%

Line Branch Exec Source
1 #include "vlasova_a_matrix_multiply_ccs/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <exception>
6 #include <vector>
7
8 #include "vlasova_a_matrix_multiply_ccs/common/include/common.hpp"
9
10 namespace vlasova_a_matrix_multiply_ccs {
11
12 namespace {
13 constexpr double kEpsilon = 1e-10;
14 } // namespace
15
16
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 VlasovaAMatrixMultiplySEQ::VlasovaAMatrixMultiplySEQ(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 GetInput() = in;
19 24 GetOutput() = SparseMatrixCCS{};
20 24 }
21
22 24 bool VlasovaAMatrixMultiplySEQ::ValidationImpl() {
23 const auto &[a, b] = GetInput();
24
5/10
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 24 times.
24 return (a.rows > 0 && a.cols > 0 && b.rows > 0 && b.cols > 0 && a.cols == b.rows);
25 }
26
27 24 bool VlasovaAMatrixMultiplySEQ::PreProcessingImpl() {
28 24 return true;
29 }
30
31 24 void VlasovaAMatrixMultiplySEQ::TransposeMatrix(const SparseMatrixCCS &a, SparseMatrixCCS &at) {
32 24 at.rows = a.cols;
33 24 at.cols = a.rows;
34 24 at.nnz = a.nnz;
35
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (a.nnz == 0) {
37 at.values.clear();
38 at.row_indices.clear();
39 at.col_ptrs.assign(at.cols + 1, 0);
40 return;
41 }
42
43 24 std::vector<int> row_count(at.cols, 0);
44
2/2
✓ Branch 0 taken 6191 times.
✓ Branch 1 taken 24 times.
6215 for (int i = 0; i < a.nnz; i++) {
45 6191 row_count[a.row_indices[i]]++;
46 }
47
48
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 at.col_ptrs.resize(at.cols + 1);
49 24 at.col_ptrs[0] = 0;
50
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 24 times.
1304 for (int i = 0; i < at.cols; i++) {
51 1280 at.col_ptrs[i + 1] = at.col_ptrs[i] + row_count[i];
52 }
53
54
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 at.values.resize(a.nnz);
55
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 at.row_indices.resize(a.nnz);
56
57
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> current_pos(at.cols, 0);
58
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 24 times.
1304 for (int col = 0; col < a.cols; col++) {
59
2/2
✓ Branch 0 taken 6191 times.
✓ Branch 1 taken 1280 times.
7471 for (int i = a.col_ptrs[col]; i < a.col_ptrs[col + 1]; i++) {
60 6191 int row = a.row_indices[i];
61 6191 double val = a.values[i];
62
63 6191 int pos = at.col_ptrs[row] + current_pos[row];
64 6191 at.values[pos] = val;
65 6191 at.row_indices[pos] = col;
66 6191 current_pos[row]++;
67 }
68 }
69 }
70
71 namespace {
72
73 1280 void ProcessColumnSEQ(const SparseMatrixCCS &at, const SparseMatrixCCS &b, int col_index, std::vector<double> &temp_row,
74 std::vector<int> &row_marker, std::vector<double> &res_val, std::vector<int> &res_row_ind) {
75
2/2
✓ Branch 0 taken 6288 times.
✓ Branch 1 taken 1280 times.
7568 for (int k = b.col_ptrs[col_index]; k < b.col_ptrs[col_index + 1]; k++) {
76 6288 int row_b = b.row_indices[k];
77 6288 double val_b = b.values[k];
78
79
2/2
✓ Branch 0 taken 30825 times.
✓ Branch 1 taken 6288 times.
37113 for (int idx = at.col_ptrs[row_b]; idx < at.col_ptrs[row_b + 1]; idx++) {
80
2/2
✓ Branch 0 taken 26197 times.
✓ Branch 1 taken 4628 times.
30825 int row_a = at.row_indices[idx];
81 30825 double val_a = at.values[idx];
82
83
2/2
✓ Branch 0 taken 26197 times.
✓ Branch 1 taken 4628 times.
30825 if (row_marker[row_a] != col_index) {
84 26197 row_marker[row_a] = col_index;
85 26197 temp_row[row_a] = val_a * val_b;
86 } else {
87 4628 temp_row[row_a] += val_a * val_b;
88 }
89 }
90 }
91
92
2/2
✓ Branch 0 taken 100800 times.
✓ Branch 1 taken 1280 times.
102080 for (size_t i = 0; i < temp_row.size(); i++) {
93
3/4
✓ Branch 0 taken 26197 times.
✓ Branch 1 taken 74603 times.
✓ Branch 2 taken 26197 times.
✗ Branch 3 not taken.
100800 if (row_marker[i] == col_index && std::abs(temp_row[i]) > kEpsilon) {
94 res_val.push_back(temp_row[i]);
95 26197 res_row_ind.push_back(static_cast<int>(i));
96 }
97 }
98 1280 }
99
100 } // namespace
101
102 24 void VlasovaAMatrixMultiplySEQ::MultiplyMatrices(const SparseMatrixCCS &a, const SparseMatrixCCS &b,
103 SparseMatrixCCS &c) {
104 24 SparseMatrixCCS at;
105
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 TransposeMatrix(a, at);
106
107 24 c.rows = a.rows;
108 24 c.cols = b.cols;
109
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 c.col_ptrs.push_back(0);
110
111
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<double> temp_row(c.rows, 0.0);
112
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> row_marker(c.rows, -1);
113
114
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 24 times.
1304 for (int j = 0; j < b.cols; j++) {
115
1/2
✓ Branch 1 taken 1280 times.
✗ Branch 2 not taken.
1280 ProcessColumnSEQ(at, b, j, temp_row, row_marker, c.values, c.row_indices);
116
1/4
✓ Branch 1 taken 1280 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1280 c.col_ptrs.push_back(static_cast<int>(c.values.size()));
117 }
118
119
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 c.nnz = static_cast<int>(c.values.size());
120 24 }
121
122
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 bool VlasovaAMatrixMultiplySEQ::RunImpl() {
123 const auto &[a, b] = GetInput();
124
125 try {
126 24 SparseMatrixCCS c;
127
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 MultiplyMatrices(a, b, c);
128
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetOutput() = c;
129 return true;
130
0/2
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 } catch (const std::exception &) {
131 return false;
132 }
133 }
134
135 24 bool VlasovaAMatrixMultiplySEQ::PostProcessingImpl() {
136 const auto &c = GetOutput();
137
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
24 return c.rows > 0 && c.cols > 0 && c.col_ptrs.size() == static_cast<size_t>(c.cols) + 1;
138 }
139
140 } // namespace vlasova_a_matrix_multiply_ccs
141