GCC Code Coverage Report


Directory: ./
File: tasks/dolov_v_crs_mat_mult/seq/src/ops_seq.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 57 58 98.3%
Functions: 7 7 100.0%
Branches: 38 50 76.0%

Line Branch Exec Source
1 #include "dolov_v_crs_mat_mult/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <vector>
5
6 #include "dolov_v_crs_mat_mult/common/include/common.hpp"
7
8 namespace dolov_v_crs_mat_mult {
9
10
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 DolovVCrsMatMultSeq::DolovVCrsMatMultSeq(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 GetInput() = in;
13 56 }
14
15
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 bool DolovVCrsMatMultSeq::ValidationImpl() {
16 const auto &input_data = GetInput();
17
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if (input_data.size() != 2) {
18 return false;
19 }
20 const auto &matrix_a = input_data[0];
21 const auto &matrix_b = input_data[1];
22
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 56 times.
56 return matrix_a.num_cols == matrix_b.num_rows && matrix_a.num_rows > 0 && matrix_b.num_cols > 0;
23 }
24
25 56 bool DolovVCrsMatMultSeq::PreProcessingImpl() {
26 const auto &input_data = GetInput();
27 auto &result = GetOutput();
28 56 result.num_rows = input_data[0].num_rows;
29 56 result.num_cols = input_data[1].num_cols;
30
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 56 times.
56 result.row_pointers.assign(result.num_rows + 1, 0);
31 result.values.clear();
32 result.col_indices.clear();
33 56 return true;
34 }
35
36 56 SparseMatrix DolovVCrsMatMultSeq::TransposeMatrix(const SparseMatrix &matrix) {
37 56 SparseMatrix transposed;
38 56 transposed.num_rows = matrix.num_cols;
39 56 transposed.num_cols = matrix.num_rows;
40
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 transposed.row_pointers.assign(transposed.num_rows + 1, 0);
41
42
2/2
✓ Branch 0 taken 2384 times.
✓ Branch 1 taken 56 times.
2440 for (int col_idx : matrix.col_indices) {
43 2384 transposed.row_pointers[col_idx + 1]++;
44 }
45
2/2
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 56 times.
1136 for (int i = 0; i < transposed.num_rows; ++i) {
46 1080 transposed.row_pointers[i + 1] += transposed.row_pointers[i];
47 }
48
49
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 transposed.values.resize(matrix.values.size());
50
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 transposed.col_indices.resize(matrix.col_indices.size());
51
52
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 std::vector<int> current_pos = transposed.row_pointers;
53
2/2
✓ Branch 0 taken 1832 times.
✓ Branch 1 taken 56 times.
1888 for (int i = 0; i < matrix.num_rows; ++i) {
54
2/2
✓ Branch 0 taken 2384 times.
✓ Branch 1 taken 1832 times.
4216 for (int j = matrix.row_pointers[i]; j < matrix.row_pointers[i + 1]; ++j) {
55 2384 int col = matrix.col_indices[j];
56 2384 int dest_idx = current_pos[col]++;
57 2384 transposed.values[dest_idx] = matrix.values[j];
58 2384 transposed.col_indices[dest_idx] = i;
59 }
60 }
61 56 return transposed;
62 }
63
64 83488 double DolovVCrsMatMultSeq::DotProduct(const SparseMatrix &matrix_a, int row_a, const SparseMatrix &matrix_b_t,
65 int row_b) {
66 double sum = 0.0;
67 83488 int ptr_a = matrix_a.row_pointers[row_a];
68 83488 int ptr_b = matrix_b_t.row_pointers[row_b];
69 83488 const int end_a = matrix_a.row_pointers[row_a + 1];
70 83488 const int end_b = matrix_b_t.row_pointers[row_b + 1];
71
72
2/2
✓ Branch 0 taken 201752 times.
✓ Branch 1 taken 83488 times.
285240 while (ptr_a < end_a && ptr_b < end_b) {
73
2/2
✓ Branch 0 taken 4936 times.
✓ Branch 1 taken 196816 times.
201752 if (matrix_a.col_indices[ptr_a] == matrix_b_t.col_indices[ptr_b]) {
74 4936 sum += matrix_a.values[ptr_a] * matrix_b_t.values[ptr_b];
75 4936 ptr_a++;
76 4936 ptr_b++;
77
2/2
✓ Branch 0 taken 105400 times.
✓ Branch 1 taken 91416 times.
196816 } else if (matrix_a.col_indices[ptr_a] < matrix_b_t.col_indices[ptr_b]) {
78 105400 ptr_a++;
79 } else {
80 91416 ptr_b++;
81 }
82 }
83 83488 return sum;
84 }
85
86 56 bool DolovVCrsMatMultSeq::RunImpl() {
87 const auto &input_data = GetInput();
88 const auto &matrix_a = input_data[0];
89 const auto &matrix_b = input_data[1];
90 auto &result = GetOutput();
91
92 56 SparseMatrix matrix_b_t = TransposeMatrix(matrix_b);
93
94
2/2
✓ Branch 0 taken 1120 times.
✓ Branch 1 taken 56 times.
1176 for (int i = 0; i < matrix_a.num_rows; ++i) {
95
2/2
✓ Branch 0 taken 83488 times.
✓ Branch 1 taken 1120 times.
84608 for (int j = 0; j < matrix_b_t.num_rows; ++j) {
96
2/2
✓ Branch 0 taken 4504 times.
✓ Branch 1 taken 78984 times.
83488 double sum = DotProduct(matrix_a, i, matrix_b_t, j);
97
98
2/2
✓ Branch 0 taken 4504 times.
✓ Branch 1 taken 78984 times.
83488 if (std::abs(sum) > 1e-15) {
99
2/2
✓ Branch 0 taken 4288 times.
✓ Branch 1 taken 216 times.
4504 result.values.push_back(sum);
100
2/2
✓ Branch 0 taken 4288 times.
✓ Branch 1 taken 216 times.
4504 result.col_indices.push_back(j);
101 }
102 }
103 1120 result.row_pointers[i + 1] = static_cast<int>(result.values.size());
104 }
105 56 return true;
106 56 }
107
108 56 bool DolovVCrsMatMultSeq::PostProcessingImpl() {
109 56 return true;
110 }
111
112 } // namespace dolov_v_crs_mat_mult
113