GCC Code Coverage Report


Directory: ./
File: tasks/viderman_a_sparse_matrix_mult_crs_complex/common/include/common.hpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 3 3 100.0%
Branches: 24 44 54.5%

Line Branch Exec Source
1 #pragma once
2
3 #include <algorithm>
4 #include <complex>
5 #include <cstddef>
6 #include <string>
7 #include <tuple>
8 #include <vector>
9
10 #include "task/include/task.hpp"
11
12 namespace viderman_a_sparse_matrix_mult_crs_complex {
13
14 using Complex = std::complex<double>;
15
16
4/8
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 140 times.
✗ Branch 10 not taken.
224 struct CRSMatrix {
17 int rows = 0;
18 int cols = 0;
19 std::vector<int> row_ptr;
20 std::vector<int> col_indices;
21 std::vector<Complex> values;
22
23
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 CRSMatrix() = default;
24
25
1/2
✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
401 CRSMatrix(int r, int c) : rows(r), cols(c) {
26
1/4
✓ Branch 1 taken 401 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
401 row_ptr.resize(r + 1, 0);
27 401 }
28
29 446 [[nodiscard]] bool IsValid() const {
30
4/8
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 446 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 446 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 446 times.
✗ Branch 7 not taken.
1338 return HasValidShape() && HasValidRowPtrSize() && HasMatchingValueSizes() && HasMonotonicRowPtr() &&
31 446 HasValidColIndices() && HasSortedRows();
32 }
33
34 [[nodiscard]] std::size_t NonZeros() const {
35 return values.size();
36 }
37
38 private:
39 [[nodiscard]] bool HasValidShape() const {
40
2/4
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 446 times.
✗ Branch 3 not taken.
446 return rows >= 0 && cols >= 0;
41 }
42
43 [[nodiscard]] bool HasValidRowPtrSize() const {
44
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 const auto expected = static_cast<std::size_t>(rows) + 1;
45 return row_ptr.size() == expected;
46 }
47
48 [[nodiscard]] bool HasMatchingValueSizes() const {
49 return col_indices.size() == values.size();
50 }
51
52 [[nodiscard]] bool HasMonotonicRowPtr() const {
53
2/2
✓ Branch 0 taken 968 times.
✓ Branch 1 taken 446 times.
1414 for (int i = 0; i < rows; ++i) {
54
1/2
✓ Branch 0 taken 968 times.
✗ Branch 1 not taken.
968 if (row_ptr[i] > row_ptr[i + 1]) {
55 return false;
56 }
57 }
58 return true;
59 }
60
61 [[nodiscard]] bool HasValidColIndices() const {
62
2/4
✓ Branch 0 taken 468 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 468 times.
✗ Branch 3 not taken.
468 return std::ranges::all_of(col_indices, [this](int col) { return col >= 0 && col < cols; });
63 }
64
65 446 [[nodiscard]] bool HasSortedRows() const {
66
2/2
✓ Branch 0 taken 968 times.
✓ Branch 1 taken 446 times.
1414 for (int i = 0; i < rows; ++i) {
67
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 968 times.
1041 for (int j = row_ptr[i]; j < row_ptr[i + 1] - 1; ++j) {
68
1/2
✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
73 if (col_indices[j] >= col_indices[j + 1]) {
69 return false;
70 }
71 }
72 }
73 return true;
74 }
75 };
76
77 using InType = std::tuple<CRSMatrix, CRSMatrix>;
78 using OutType = CRSMatrix;
79 using TestType = std::tuple<int, int, int, int, int, std::string>;
80 using BaseTask = ppc::task::Task<InType, OutType>;
81
82 constexpr double kEpsilon = 1e-14;
83
84 } // namespace viderman_a_sparse_matrix_mult_crs_complex
85