| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "sizov_d_sparse_crs_mult/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "sizov_d_sparse_crs_mult/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace sizov_d_sparse_crs_mult { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | 96 | bool IsValidCRS(const CRSMatrix &m) { | |
| 15 |
2/4✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
|
96 | if (m.rows == 0 || m.cols == 0) { |
| 16 | return false; | ||
| 17 | } | ||
| 18 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
|
96 | if (m.row_ptr.size() != m.rows + 1) { |
| 19 | return false; | ||
| 20 | } | ||
| 21 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
|
96 | if (m.row_ptr.empty() || m.row_ptr.front() != 0) { |
| 22 | return false; | ||
| 23 | } | ||
| 24 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
|
96 | if (m.row_ptr.back() != m.values.size() || m.col_indices.size() != m.values.size()) { |
| 25 | return false; | ||
| 26 | } | ||
| 27 |
2/2✓ Branch 0 taken 200 times.
✓ Branch 1 taken 96 times.
|
296 | for (std::size_t i = 0; i < m.rows; ++i) { |
| 28 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
|
200 | if (m.row_ptr[i] > m.row_ptr[i + 1]) { |
| 29 | return false; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | return std::ranges::all_of(m.col_indices, [&m](std::size_t idx) { return idx < m.cols; }); | ||
| 33 | } | ||
| 34 | |||
| 35 | } // namespace | ||
| 36 | |||
| 37 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | SizovDSparseCRSMultSEQ::SizovDSparseCRSMultSEQ(const InType &in) { |
| 38 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 39 | GetInput() = in; | ||
| 40 | 48 | } | |
| 41 | |||
| 42 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool SizovDSparseCRSMultSEQ::ValidationImpl() { |
| 43 | const auto &a = std::get<0>(GetInput()); | ||
| 44 | const auto &b = std::get<1>(GetInput()); | ||
| 45 |
3/6✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48 times.
|
48 | return IsValidCRS(a) && IsValidCRS(b) && a.cols == b.rows; |
| 46 | } | ||
| 47 | |||
| 48 | 48 | bool SizovDSparseCRSMultSEQ::PreProcessingImpl() { | |
| 49 | 48 | GetOutput() = {}; | |
| 50 | 48 | return true; | |
| 51 | } | ||
| 52 | |||
| 53 | 48 | bool SizovDSparseCRSMultSEQ::RunImpl() { | |
| 54 | const auto &a = std::get<0>(GetInput()); | ||
| 55 | const auto &b = std::get<1>(GetInput()); | ||
| 56 | auto &c = GetOutput(); | ||
| 57 | |||
| 58 | 48 | c.rows = a.rows; | |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | c.cols = b.cols; |
| 60 | c.values.clear(); | ||
| 61 | c.col_indices.clear(); | ||
| 62 | 48 | c.row_ptr.assign(c.rows + 1, 0); | |
| 63 | |||
| 64 | 48 | std::vector<double> accum(c.cols, 0.0); | |
| 65 |
1/4✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
48 | std::vector<unsigned char> touched_flag(c.cols, 0); |
| 66 | 48 | std::vector<std::size_t> touched_cols; | |
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (std::size_t row_a = 0; row_a < a.rows; ++row_a) { |
| 69 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 96 times.
|
200 | for (std::size_t pos_a = a.row_ptr[row_a]; pos_a < a.row_ptr[row_a + 1]; ++pos_a) { |
| 70 | 104 | const std::size_t row_b = a.col_indices[pos_a]; | |
| 71 | 104 | const double val_a = a.values[pos_a]; | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 104 times.
|
264 | for (std::size_t pos_b = b.row_ptr[row_b]; pos_b < b.row_ptr[row_b + 1]; ++pos_b) { |
| 74 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 40 times.
|
160 | const std::size_t col_b = b.col_indices[pos_b]; |
| 75 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 40 times.
|
160 | if (touched_flag[col_b] == 0U) { |
| 76 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 64 times.
|
120 | touched_flag[col_b] = 1U; |
| 77 | touched_cols.push_back(col_b); | ||
| 78 | } | ||
| 79 | 160 | accum[col_b] += val_a * b.values[pos_b]; | |
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | std::ranges::sort(touched_cols); | ||
| 84 |
3/4✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 96 times.
|
216 | for (std::size_t col : touched_cols) { |
| 85 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | if (std::abs(accum[col]) > 1e-12) { |
| 86 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | c.col_indices.push_back(col); |
| 87 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | c.values.push_back(accum[col]); |
| 88 | } | ||
| 89 | 120 | accum[col] = 0.0; | |
| 90 | 120 | touched_flag[col] = 0U; | |
| 91 | } | ||
| 92 | touched_cols.clear(); | ||
| 93 | 96 | c.row_ptr[row_a + 1] = c.values.size(); | |
| 94 | } | ||
| 95 | |||
| 96 | 48 | return true; | |
| 97 | } | ||
| 98 | |||
| 99 | 48 | bool SizovDSparseCRSMultSEQ::PostProcessingImpl() { | |
| 100 | 48 | return true; | |
| 101 | } | ||
| 102 | |||
| 103 | } // namespace sizov_d_sparse_crs_mult | ||
| 104 |