GCC Code Coverage Report


Directory: ./
File: tasks/badanov_a_sparse_matrix_mult_double_ccs/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 65 70 92.9%
Functions: 6 7 85.7%
Branches: 36 66 54.5%

Line Branch Exec Source
1 #include "badanov_a_sparse_matrix_mult_double_ccs/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <tuple>
7 #include <vector>
8
9 #include "badanov_a_sparse_matrix_mult_double_ccs/common/include/common.hpp"
10
11 namespace badanov_a_sparse_matrix_mult_double_ccs {
12
13
1/2
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
120 BadanovASparseMatrixMultDoubleCcsSEQ::BadanovASparseMatrixMultDoubleCcsSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 120 GetOutput() = {};
17 120 }
18
19 120 bool BadanovASparseMatrixMultDoubleCcsSEQ::ValidationImpl() {
20 const auto &in = GetInput();
21
22 const auto &values_a = std::get<0>(in);
23 const auto &row_indices_a = std::get<1>(in);
24 const auto &col_pointers_a = std::get<2>(in);
25 const auto &value_b = std::get<3>(in);
26 const auto &row_indices_b = std::get<4>(in);
27 const auto &col_pointers_b = std::get<5>(in);
28 120 int rows_a = std::get<6>(in);
29 120 int cols_a = std::get<7>(in);
30 120 int cols_b = std::get<8>(in);
31
32
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (rows_a <= 0 || cols_a <= 0) {
33 return false;
34 }
35
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (values_a.size() != row_indices_a.size()) {
36 return false;
37 }
38
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (col_pointers_a.size() != static_cast<size_t>(cols_a) + 1) {
39 return false;
40 }
41
42
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (cols_b <= 0) {
43 return false;
44 }
45
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (value_b.size() != row_indices_b.size()) {
46 return false;
47 }
48
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (col_pointers_b.size() != static_cast<size_t>(cols_b) + 1) {
49 return false;
50 }
51
52
2/4
✓ Branch 0 taken 730977 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✗ Branch 3 not taken.
731097 if (!std::ranges::all_of(row_indices_b, [cols_a](int row_idx) { return row_idx >= 0 && row_idx < cols_a; })) {
53 return false;
54 }
55
56
1/2
✓ Branch 0 taken 733476 times.
✗ Branch 1 not taken.
733476 if (!std::ranges::all_of(row_indices_a, [rows_a](int row_idx) { return row_idx >= 0 && row_idx < rows_a; })) {
57 return false;
58 }
59
60 return true;
61 }
62
63 120 bool BadanovASparseMatrixMultDoubleCcsSEQ::PreProcessingImpl() {
64 120 GetOutput() = {};
65 120 return true;
66 }
67
68 double BadanovASparseMatrixMultDoubleCcsSEQ::DotProduct(const std::vector<double> &col_a,
69 const std::vector<double> &col_b) {
70 double result = 0.0;
71 for (size_t i = 0; i < col_a.size(); ++i) {
72 result += col_a[i] * col_b[i];
73 }
74 return result;
75 }
76
77 120 SparseMatrix BadanovASparseMatrixMultDoubleCcsSEQ::MultiplyCCS(const SparseMatrix &a, const SparseMatrix &b) {
78 120 std::vector<double> value_c;
79 120 std::vector<int> row_indices_c;
80
1/4
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
120 std::vector<int> col_pointers_c(b.cols + 1, 0);
81
82
2/2
✓ Branch 0 taken 36880 times.
✓ Branch 1 taken 120 times.
37000 for (int j = 0; j < b.cols; ++j) {
83
1/4
✓ Branch 1 taken 36880 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
36880 std::vector<double> temp_result(a.rows, 0.0);
84
85
2/2
✓ Branch 0 taken 730977 times.
✓ Branch 1 taken 36880 times.
767857 for (int idx_b = b.col_pointers[j]; idx_b < b.col_pointers[j + 1]; ++idx_b) {
86 730977 int row_b = b.row_indices[idx_b];
87 730977 double val_b = b.values[idx_b];
88
89
2/2
✓ Branch 0 taken 18064701 times.
✓ Branch 1 taken 730977 times.
18795678 for (int idx_a = a.col_pointers[row_b]; idx_a < a.col_pointers[row_b + 1]; ++idx_a) {
90 18064701 int row_a = a.row_indices[idx_a];
91 18064701 double val_a = a.values[idx_a];
92 18064701 temp_result[row_a] += val_a * val_b;
93 }
94 }
95
96
2/2
✓ Branch 0 taken 19140800 times.
✓ Branch 1 taken 36880 times.
19177680 for (int i = 0; i < a.rows; ++i) {
97
2/2
✓ Branch 0 taken 9709319 times.
✓ Branch 1 taken 9431481 times.
19140800 if (std::abs(temp_result[i]) > 1e-10) {
98 value_c.push_back(temp_result[i]);
99 row_indices_c.push_back(i);
100 9709319 col_pointers_c[j + 1]++;
101 }
102 }
103 }
104
105
2/2
✓ Branch 0 taken 36880 times.
✓ Branch 1 taken 120 times.
37000 for (int j = 0; j < b.cols; ++j) {
106 36880 col_pointers_c[j + 1] += col_pointers_c[j];
107 }
108
109 120 SparseMatrix c;
110
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 c.values = value_c;
111
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 c.row_indices = row_indices_c;
112
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 c.col_pointers = col_pointers_c;
113 120 c.rows = a.rows;
114
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 c.cols = b.cols;
115
116 120 return c;
117 }
118
119
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 bool BadanovASparseMatrixMultDoubleCcsSEQ::RunImpl() {
120 const auto &in = GetInput();
121
122 const auto &values_a = std::get<0>(in);
123 const auto &row_indices_a = std::get<1>(in);
124 const auto &col_pointers_a = std::get<2>(in);
125 const auto &value_b = std::get<3>(in);
126 const auto &row_indices_b = std::get<4>(in);
127 const auto &col_pointers_b = std::get<5>(in);
128 120 int rows_a = std::get<6>(in);
129 120 int cols_a = std::get<7>(in);
130 120 int cols_b = std::get<8>(in);
131
132 120 SparseMatrix a;
133
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 a.values = values_a;
134
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 a.row_indices = row_indices_a;
135
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 a.col_pointers = col_pointers_a;
136 120 a.rows = rows_a;
137 120 a.cols = cols_a;
138
139 120 SparseMatrix b;
140
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 b.values = value_b;
141
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 b.row_indices = row_indices_b;
142
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 b.col_pointers = col_pointers_b;
143 120 b.rows = cols_a;
144 120 b.cols = cols_b;
145
146
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 SparseMatrix c = MultiplyCCS(a, b);
147
148 120 GetOutput() = std::make_tuple(c.values, c.row_indices, c.col_pointers);
149
150 120 return true;
151 120 }
152
153 120 bool BadanovASparseMatrixMultDoubleCcsSEQ::PostProcessingImpl() {
154 120 return true;
155 }
156
157 } // namespace badanov_a_sparse_matrix_mult_double_ccs
158