| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ashihmin_d_mult_matr_crs/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <unordered_map> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "ashihmin_d_mult_matr_crs/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace ashihmin_d_mult_matr_crs { | ||
| 12 | |||
| 13 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | AshihminDMultMatrCrsSEQ::AshihminDMultMatrCrsSEQ(const InType &input_matrices) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = input_matrices; | ||
| 16 | 48 | } | |
| 17 | |||
| 18 | 48 | bool AshihminDMultMatrCrsSEQ::ValidationImpl() { | |
| 19 | const auto &matrix_a = GetInput().first; | ||
| 20 | const auto &matrix_b = GetInput().second; | ||
| 21 | |||
| 22 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (matrix_a.cols != matrix_b.rows) { |
| 23 | return false; | ||
| 24 | } | ||
| 25 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (matrix_a.row_ptr.size() != static_cast<std::size_t>(matrix_a.rows) + 1) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (matrix_b.row_ptr.size() != static_cast<std::size_t>(matrix_b.rows) + 1) { |
| 29 | return false; | ||
| 30 | } | ||
| 31 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | if (matrix_a.values.size() != matrix_a.col_index.size()) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (matrix_b.values.size() != matrix_b.col_index.size()) { |
| 35 | ✗ | return false; | |
| 36 | } | ||
| 37 | |||
| 38 | return true; | ||
| 39 | } | ||
| 40 | |||
| 41 | 48 | bool AshihminDMultMatrCrsSEQ::PreProcessingImpl() { | |
| 42 | const auto &matrix_a = GetInput().first; | ||
| 43 | |||
| 44 | 48 | GetOutput().rows = matrix_a.rows; | |
| 45 | 48 | GetOutput().cols = GetInput().second.cols; | |
| 46 | 48 | GetOutput().row_ptr.resize(matrix_a.rows + 1, 0); | |
| 47 | |||
| 48 | 48 | return true; | |
| 49 | } | ||
| 50 | |||
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | bool AshihminDMultMatrCrsSEQ::RunImpl() { |
| 52 | const auto &matrix_a = GetInput().first; | ||
| 53 | const auto &matrix_b = GetInput().second; | ||
| 54 | auto &matrix_c = GetOutput(); | ||
| 55 | |||
| 56 | matrix_c.values.clear(); | ||
| 57 | matrix_c.col_index.clear(); | ||
| 58 | |||
| 59 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 48 times.
|
144 | for (int row_index = 0; row_index < matrix_a.rows; ++row_index) { |
| 60 | std::unordered_map<int, double> accumulator; | ||
| 61 | |||
| 62 | 96 | auto row_begin = static_cast<std::size_t>(matrix_a.row_ptr[row_index]); | |
| 63 | 96 | auto row_end = static_cast<std::size_t>(matrix_a.row_ptr[row_index + 1]); | |
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 96 times.
|
200 | for (std::size_t index_a = row_begin; index_a < row_end; ++index_a) { |
| 66 | 104 | int col_a = matrix_a.col_index[index_a]; | |
| 67 | 104 | double value_a = matrix_a.values[index_a]; | |
| 68 | |||
| 69 | 104 | auto col_begin = static_cast<std::size_t>(matrix_b.row_ptr[col_a]); | |
| 70 | 104 | auto col_end = static_cast<std::size_t>(matrix_b.row_ptr[col_a + 1]); | |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 104 times.
|
264 | for (std::size_t index_b = col_begin; index_b < col_end; ++index_b) { |
| 73 | 160 | int col_b = matrix_b.col_index[index_b]; | |
| 74 |
1/2✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
|
160 | double value_b = matrix_b.values[index_b]; |
| 75 | |||
| 76 | 160 | accumulator[col_b] += value_a * value_b; | |
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 |
1/2✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
|
96 | std::vector<std::pair<int, double>> sorted_values(accumulator.begin(), accumulator.end()); |
| 81 | |||
| 82 | std::ranges::sort(sorted_values, {}, &std::pair<int, double>::first); | ||
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 120 times.
✓ Branch 1 taken 96 times.
|
216 | for (const auto &entry : sorted_values) { |
| 85 |
1/2✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
|
120 | if (entry.second != 0.0) { |
| 86 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | matrix_c.values.push_back(entry.second); |
| 87 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 104 times.
|
120 | matrix_c.col_index.push_back(entry.first); |
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 16 times.
|
96 | matrix_c.row_ptr[row_index + 1] = static_cast<int>(matrix_c.values.size()); |
| 92 | } | ||
| 93 | |||
| 94 | 48 | return true; | |
| 95 | } | ||
| 96 | |||
| 97 | 48 | bool AshihminDMultMatrCrsSEQ::PostProcessingImpl() { | |
| 98 | 48 | return true; | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace ashihmin_d_mult_matr_crs | ||
| 102 |