GCC Code Coverage Report


Directory: ./
File: tasks/agafonov_i_matrix_ccs_seq/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 0 37 0.0%
Functions: 0 5 0.0%
Branches: 0 36 0.0%

Line Branch Exec Source
1 #include "agafonov_i_matrix_ccs_seq/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <utility>
7 #include <vector>
8
9 #include "agafonov_i_matrix_ccs_seq/common/include/common.hpp"
10
11 namespace agafonov_i_matrix_ccs_seq {
12
13 AgafonovIMatrixCCSSeq::AgafonovIMatrixCCSSeq(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 }
17
18 bool AgafonovIMatrixCCSSeq::ValidationImpl() {
19 const auto &left = GetInput().first;
20 const auto &right = GetInput().second;
21
22 return (left.cols_num == right.rows_num) && (left.col_ptrs.size() == left.cols_num + 1) &&
23 (right.col_ptrs.size() == right.cols_num + 1);
24 }
25
26 bool AgafonovIMatrixCCSSeq::PreProcessingImpl() {
27 GetOutput().vals.clear();
28 GetOutput().row_inds.clear();
29 return true;
30 }
31
32 bool AgafonovIMatrixCCSSeq::RunImpl() {
33 const auto &a = GetInput().first;
34 const auto &b = GetInput().second;
35 auto &c = GetOutput();
36
37 c.rows_num = a.rows_num;
38 c.cols_num = b.cols_num;
39 c.col_ptrs.assign(c.cols_num + 1, 0);
40
41 std::vector<double> accumulator(a.rows_num, 0.0);
42 std::vector<size_t> active_rows;
43 std::vector<bool> row_mask(a.rows_num, false);
44
45 for (size_t j = 0; j < b.cols_num; ++j) {
46 c.col_ptrs[j] = static_cast<int>(c.vals.size());
47 const auto b_col_start = static_cast<size_t>(b.col_ptrs[j]);
48 const auto b_col_end = static_cast<size_t>(b.col_ptrs[j + 1]);
49
50 for (size_t kb = b_col_start; kb < b_col_end; ++kb) {
51 const auto k = static_cast<size_t>(b.row_inds[kb]);
52 const double v_b = b.vals[kb];
53
54 const auto a_col_start = static_cast<size_t>(a.col_ptrs[k]);
55 const auto a_col_end = static_cast<size_t>(a.col_ptrs[k + 1]);
56
57 for (size_t ka = a_col_start; ka < a_col_end; ++ka) {
58 const auto i = static_cast<size_t>(a.row_inds[ka]);
59 if (!row_mask[i]) {
60 row_mask[i] = true;
61 active_rows.push_back(i);
62 }
63 accumulator[i] += a.vals[ka] * v_b;
64 }
65 }
66
67 std::ranges::sort(active_rows);
68
69 for (const auto row_idx : active_rows) {
70 if (std::abs(accumulator[row_idx]) > 1e-15) {
71 c.vals.push_back(accumulator[row_idx]);
72 c.row_inds.push_back(static_cast<int>(row_idx));
73 }
74 accumulator[row_idx] = 0.0;
75 row_mask[row_idx] = false;
76 }
77 active_rows.clear();
78 }
79
80 c.nnz = c.vals.size();
81 c.col_ptrs[c.cols_num] = static_cast<int>(c.nnz);
82 return true;
83 }
84
85 bool AgafonovIMatrixCCSSeq::PostProcessingImpl() {
86 return true;
87 }
88
89 } // namespace agafonov_i_matrix_ccs_seq
90