GCC Code Coverage Report


Directory: ./
File: tasks/klimovich_v_crs_complex_mat_mul/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 42 43 97.7%
Functions: 8 8 100.0%
Branches: 32 42 76.2%

Line Branch Exec Source
1 #include "klimovich_v_crs_complex_mat_mul/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "klimovich_v_crs_complex_mat_mul/common/include/common.hpp"
9
10 namespace klimovich_v_crs_complex_mat_mul {
11 namespace {
12
13
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 120 times.
456 void AccumulateRow(const CrsMatrix &lhs, const CrsMatrix &rhs, int row, std::vector<Cplx> &spa,
14 std::vector<int> &touched_by_row, std::vector<int> &touched_cols) {
15 touched_cols.clear();
16
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 456 times.
1128 for (int lp = lhs.row_offsets[row]; lp < lhs.row_offsets[row + 1]; ++lp) {
17 672 const int k = lhs.col_indices[lp];
18 672 const Cplx a_ik = lhs.data[lp];
19
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 672 times.
1880 for (int rq = rhs.row_offsets[k]; rq < rhs.row_offsets[k + 1]; ++rq) {
20
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 536 times.
1208 const int j = rhs.col_indices[rq];
21
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 536 times.
1208 if (touched_by_row[j] != row) {
22
1/2
✓ Branch 0 taken 672 times.
✗ Branch 1 not taken.
672 touched_by_row[j] = row;
23 touched_cols.push_back(j);
24 672 spa[j] = a_ik * rhs.data[rq];
25 } else {
26 spa[j] += a_ik * rhs.data[rq];
27 }
28 }
29 }
30 456 }
31
32 456 void FinalizeRow(CrsMatrix &result, std::vector<Cplx> &spa, std::vector<int> &touched_cols, int row) {
33 std::ranges::sort(touched_cols);
34
35 int kept = 0;
36
2/2
✓ Branch 0 taken 672 times.
✓ Branch 1 taken 456 times.
1128 for (const int j : touched_cols) {
37
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 640 times.
672 const Cplx v = spa[j];
38
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 640 times.
672 spa[j] = Cplx(0.0);
39
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 640 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
672 if (std::abs(v.real()) > kZeroDropTol || std::abs(v.imag()) > kZeroDropTol) {
40
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 280 times.
672 result.col_indices.push_back(j);
41
2/2
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 280 times.
672 result.data.push_back(v);
42 672 ++kept;
43 }
44 }
45
46 456 result.row_offsets[row + 1] = result.row_offsets[row] + kept;
47 456 }
48
49 } // namespace
50
51
1/2
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
80 KlimovichVCrsComplexMatMulSeq::KlimovichVCrsComplexMatMulSeq(const InType &in) {
52 SetTypeOfTask(GetStaticTypeOfTask());
53 GetInput() = in;
54 80 GetOutput() = CrsMatrix();
55 80 }
56
57 80 bool KlimovichVCrsComplexMatMulSeq::ValidationImpl() {
58 const auto &lhs = std::get<0>(GetInput());
59 const auto &rhs = std::get<1>(GetInput());
60 80 return lhs.n_cols == rhs.n_rows;
61 }
62
63 80 bool KlimovichVCrsComplexMatMulSeq::PreProcessingImpl() {
64 80 return true;
65 }
66
67 80 CrsMatrix KlimovichVCrsComplexMatMulSeq::MultiplyCrs(const CrsMatrix &lhs, const CrsMatrix &rhs) {
68 80 CrsMatrix result(lhs.n_rows, rhs.n_cols);
69
70
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 std::vector<Cplx> spa(static_cast<std::size_t>(rhs.n_cols), Cplx(0.0));
71
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<int> touched_by_row(static_cast<std::size_t>(rhs.n_cols), -1);
72 80 std::vector<int> touched_cols;
73
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 touched_cols.reserve(static_cast<std::size_t>(rhs.n_cols));
74
75
2/2
✓ Branch 0 taken 456 times.
✓ Branch 1 taken 80 times.
536 for (int i = 0; i < lhs.n_rows; ++i) {
76
1/2
✓ Branch 1 taken 456 times.
✗ Branch 2 not taken.
456 AccumulateRow(lhs, rhs, i, spa, touched_by_row, touched_cols);
77
1/2
✓ Branch 1 taken 456 times.
✗ Branch 2 not taken.
456 FinalizeRow(result, spa, touched_cols, i);
78 }
79
80 80 return result;
81 }
82
83 80 bool KlimovichVCrsComplexMatMulSeq::RunImpl() {
84 const auto &lhs = std::get<0>(GetInput());
85 const auto &rhs = std::get<1>(GetInput());
86 80 GetOutput() = MultiplyCrs(lhs, rhs);
87 80 return true;
88 }
89
90 80 bool KlimovichVCrsComplexMatMulSeq::PostProcessingImpl() {
91 80 return true;
92 }
93
94 } // namespace klimovich_v_crs_complex_mat_mul
95