GCC Code Coverage Report


Directory: ./
File: tasks/lobanov_d_multi_matrix_crs/common/include/common.hpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 0 4 0.0%
Functions: 0 3 0.0%
Branches: 0 6 0.0%

Line Branch Exec Source
1 #pragma once
2
3 #include <cstddef>
4 #include <ostream>
5 #include <string>
6 #include <tuple>
7 #include <utility>
8 #include <vector>
9
10 #include "task/include/task.hpp"
11
12 namespace lobanov_d_multi_matrix_crs {
13
14 struct CompressedRowMatrix {
15 int row_count = 0;
16 int column_count = 0;
17 int non_zero_count = 0;
18 std::vector<double> value_data;
19 std::vector<int> column_index_data;
20 std::vector<int> row_pointer_data;
21
22 CompressedRowMatrix() = default;
23
24 CompressedRowMatrix(int r, int c, int nz) : row_count(r), column_count(c), non_zero_count(nz) {
25 if (nz > 0) {
26 value_data.reserve(static_cast<std::size_t>(nz));
27 column_index_data.reserve(static_cast<std::size_t>(nz));
28 }
29 row_pointer_data.reserve(static_cast<std::size_t>(r) + 1);
30 }
31
32 CompressedRowMatrix(const CompressedRowMatrix &other) = default;
33 CompressedRowMatrix &operator=(const CompressedRowMatrix &other) = default;
34
35 ~CompressedRowMatrix() = default;
36
37 void ZeroInitialize() {
38 row_count = 0;
39 column_count = 0;
40 non_zero_count = 0;
41 value_data.clear();
42 column_index_data.clear();
43 row_pointer_data.clear();
44 }
45
46 [[nodiscard]] bool IsValid() const {
47 if (row_count < 0 || column_count < 0 || non_zero_count < 0) {
48 return false;
49 }
50 if (non_zero_count > 0) {
51 if (value_data.size() != static_cast<std::size_t>(non_zero_count)) {
52 return false;
53 }
54 if (column_index_data.size() != static_cast<std::size_t>(non_zero_count)) {
55 return false;
56 }
57 }
58 if (row_pointer_data.size() != static_cast<std::size_t>(row_count) + 1U) {
59 return false;
60 }
61 if (!row_pointer_data.empty() && row_pointer_data[0] != 0) {
62 return false;
63 }
64 return true;
65 }
66 };
67
68 using InType = std::pair<CompressedRowMatrix, CompressedRowMatrix>;
69 using OutType = CompressedRowMatrix;
70 using TestType = std::tuple<std::string, CompressedRowMatrix, CompressedRowMatrix, CompressedRowMatrix>;
71 using BaseTask = ppc::task::Task<InType, OutType>;
72
73 inline std::ostream &operator<<(std::ostream &os, const CompressedRowMatrix &matrix) {
74 os << "CompressedRowMatrix{"
75 << "rows=" << matrix.row_count << ", cols=" << matrix.column_count << ", nnz=" << matrix.non_zero_count << "}";
76 return os;
77 }
78 } // namespace lobanov_d_multi_matrix_crs
79