| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "dilshodov_a_spmm_double_css/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <map> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "dilshodov_a_spmm_double_css/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace dilshodov_a_spmm_double_css { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | constexpr double kEps = 1e-10; | ||
| 14 | |||
| 15 | bool HasValidDimensions(const SparseMatrixCCS &m) { | ||
| 16 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | return m.rows_count > 0 && m.cols_count > 0; |
| 17 | } | ||
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool HasValidContainers(const SparseMatrixCCS &m) { |
| 20 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (m.col_ptrs.size() != static_cast<size_t>(m.cols_count) + 1) { |
| 21 | return false; | ||
| 22 | } | ||
| 23 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (m.row_indices.size() != m.values.size()) { |
| 24 | return false; | ||
| 25 | } | ||
| 26 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | if (m.col_ptrs.empty() || m.col_ptrs.front() != 0) { |
| 27 | return false; | ||
| 28 | } | ||
| 29 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (std::cmp_not_equal(m.col_ptrs.back(), m.values.size())) { |
| 30 | ✗ | return false; | |
| 31 | } | ||
| 32 | |||
| 33 | return true; | ||
| 34 | } | ||
| 35 | |||
| 36 | 48 | bool HasValidColumnOrdering(const SparseMatrixCCS &m) { | |
| 37 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 48 times.
|
168 | for (int j = 0; j < m.cols_count; ++j) { |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (m.col_ptrs[j] > m.col_ptrs[j + 1]) { |
| 39 | return false; | ||
| 40 | } | ||
| 41 | int prev_row = -1; | ||
| 42 |
2/2✓ Branch 0 taken 184 times.
✓ Branch 1 taken 120 times.
|
304 | for (int idx = m.col_ptrs[j]; idx < m.col_ptrs[j + 1]; ++idx) { |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | const int row = m.row_indices[idx]; |
| 44 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 184 times.
|
184 | if (row < 0 || row >= m.rows_count) { |
| 45 | return false; | ||
| 46 | } | ||
| 47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
|
184 | if (row <= prev_row) { |
| 48 | return false; | ||
| 49 | } | ||
| 50 | prev_row = row; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | return true; | ||
| 55 | } | ||
| 56 | |||
| 57 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool IsValidCCS(const SparseMatrixCCS &m) { |
| 58 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | return HasValidDimensions(m) && HasValidContainers(m) && HasValidColumnOrdering(m); |
| 59 | } | ||
| 60 | |||
| 61 | } // namespace | ||
| 62 | |||
| 63 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | DilshodovASpmmDoubleCssSeq::DilshodovASpmmDoubleCssSeq(const InType &in) { |
| 64 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 65 | GetInput() = in; | ||
| 66 | 24 | } | |
| 67 | |||
| 68 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | bool DilshodovASpmmDoubleCssSeq::ValidationImpl() { |
| 69 | const auto &matrix_a = std::get<0>(GetInput()); | ||
| 70 | const auto &matrix_b = std::get<1>(GetInput()); | ||
| 71 |
3/6✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
24 | return IsValidCCS(matrix_a) && IsValidCCS(matrix_b) && matrix_a.cols_count == matrix_b.rows_count; |
| 72 | } | ||
| 73 | |||
| 74 | 24 | bool DilshodovASpmmDoubleCssSeq::PreProcessingImpl() { | |
| 75 | 24 | GetOutput() = SparseMatrixCCS{}; | |
| 76 | 24 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | 24 | bool DilshodovASpmmDoubleCssSeq::RunImpl() { | |
| 80 | const auto &matrix_a = std::get<0>(GetInput()); | ||
| 81 | const auto &matrix_b = std::get<1>(GetInput()); | ||
| 82 | auto &matrix_c = GetOutput(); | ||
| 83 | |||
| 84 | 24 | matrix_c.rows_count = matrix_a.rows_count; | |
| 85 | 24 | matrix_c.cols_count = matrix_b.cols_count; | |
| 86 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
|
24 | matrix_c.col_ptrs.assign(static_cast<size_t>(matrix_c.cols_count) + 1, 0); |
| 87 | matrix_c.row_indices.clear(); | ||
| 88 | matrix_c.values.clear(); | ||
| 89 | |||
| 90 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 24 times.
|
80 | for (int col_b = 0; col_b < matrix_b.cols_count; ++col_b) { |
| 91 | std::map<int, double> accumulator; | ||
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 56 times.
|
152 | for (int idx_b = matrix_b.col_ptrs[col_b]; idx_b < matrix_b.col_ptrs[col_b + 1]; ++idx_b) { |
| 94 | 96 | const int pivot_row = matrix_b.row_indices[idx_b]; | |
| 95 | 96 | const double pivot_value = matrix_b.values[idx_b]; | |
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 128 times.
✓ Branch 1 taken 96 times.
|
224 | for (int idx_a = matrix_a.col_ptrs[pivot_row]; idx_a < matrix_a.col_ptrs[pivot_row + 1]; ++idx_a) { |
| 98 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | const int result_row = matrix_a.row_indices[idx_a]; |
| 99 |
1/2✓ Branch 1 taken 128 times.
✗ Branch 2 not taken.
|
128 | accumulator[result_row] += matrix_a.values[idx_a] * pivot_value; |
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 56 times.
|
152 | for (const auto &[row, value] : accumulator) { |
| 104 |
1/2✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
|
96 | if (std::abs(value) > kEps) { |
| 105 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 72 times.
|
96 | matrix_c.row_indices.push_back(row); |
| 106 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 72 times.
|
96 | matrix_c.values.push_back(value); |
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | 56 | matrix_c.col_ptrs[col_b + 1] = static_cast<int>(matrix_c.values.size()); | |
| 111 | } | ||
| 112 | |||
| 113 | 24 | matrix_c.non_zeros = static_cast<int>(matrix_c.values.size()); | |
| 114 | 24 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | 24 | bool DilshodovASpmmDoubleCssSeq::PostProcessingImpl() { | |
| 118 | 24 | GetOutput().non_zeros = static_cast<int>(GetOutput().values.size()); | |
| 119 | 24 | return true; | |
| 120 | } | ||
| 121 | |||
| 122 | } // namespace dilshodov_a_spmm_double_css | ||
| 123 |