| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "posternak_a_crs_mul_complex_matrix/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <complex> | ||
| 6 | #include <unordered_map> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "posternak_a_crs_mul_complex_matrix/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace posternak_a_crs_mul_complex_matrix { | ||
| 13 | |||
| 14 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | PosternakACRSMulComplexMatrixSEQ::PosternakACRSMulComplexMatrixSEQ(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 | GetInput() = in; | ||
| 17 | 48 | GetOutput() = CRSMatrix{}; | |
| 18 | 48 | } | |
| 19 | |||
| 20 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool PosternakACRSMulComplexMatrixSEQ::ValidationImpl() { |
| 21 | const auto &[a, b] = GetInput(); | ||
| 22 | |||
| 23 |
2/4✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | if (!a.IsValid() || !b.IsValid()) { |
| 24 | return false; | ||
| 25 | } | ||
| 26 | |||
| 27 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (a.cols != b.rows) { |
| 28 | ✗ | return false; | |
| 29 | } | ||
| 30 | |||
| 31 | return true; | ||
| 32 | } | ||
| 33 | |||
| 34 | 48 | bool PosternakACRSMulComplexMatrixSEQ::PreProcessingImpl() { | |
| 35 | const auto &[a, b] = GetInput(); | ||
| 36 | |||
| 37 | 48 | GetOutput().rows = a.rows; | |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | GetOutput().cols = b.cols; |
| 39 | GetOutput().values.clear(); | ||
| 40 | GetOutput().index_col.clear(); | ||
| 41 | GetOutput().index_row.clear(); | ||
| 42 | 48 | GetOutput().index_row.reserve(a.rows + 1); | |
| 43 | |||
| 44 | 48 | return true; | |
| 45 | } | ||
| 46 | |||
| 47 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
|
48 | bool PosternakACRSMulComplexMatrixSEQ::RunImpl() { |
| 48 | const auto &[a, b] = GetInput(); | ||
| 49 | auto &res = GetOutput(); | ||
| 50 | |||
| 51 | // одна из матриц пустая - результат пустой | ||
| 52 |
4/4✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 32 times.
|
48 | if (a.values.empty() || b.values.empty()) { |
| 53 | 16 | res.index_row.assign(res.rows + 1, 0); | |
| 54 | 16 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 32 times.
|
112 | for (int row = 0; row < res.rows; ++row) { |
| 58 | // создаем хранилище результатов, где: | ||
| 59 | // ключ - номер столбца в res | ||
| 60 | // значение - сумма произведений столбца | ||
| 61 | std::unordered_map<int, std::complex<double>> row_sum; | ||
| 62 | |||
| 63 |
2/2✓ Branch 0 taken 96 times.
✓ Branch 1 taken 80 times.
|
176 | for (int idx_a = a.index_row[row]; idx_a < a.index_row[row + 1]; ++idx_a) { |
| 64 | 96 | const int col_a = a.index_col[idx_a]; | |
| 65 | const auto &val_a = a.values[idx_a]; | ||
| 66 | |||
| 67 |
2/2✓ Branch 0 taken 136 times.
✓ Branch 1 taken 96 times.
|
232 | for (int idx_b = b.index_row[col_a]; idx_b < b.index_row[col_a + 1]; ++idx_b) { |
| 68 |
1/2✓ Branch 1 taken 136 times.
✗ Branch 2 not taken.
|
136 | const int col_b = b.index_col[idx_b]; |
| 69 | const auto &val_b = b.values[idx_b]; | ||
| 70 | |||
| 71 | row_sum[col_b] += val_a * val_b; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | // указатель на начало текущей строки в res | ||
| 76 |
2/4✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
|
80 | res.index_row.push_back(static_cast<int>(res.values.size())); |
| 77 | |||
| 78 | // копирование и сортировка результата | ||
| 79 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | std::vector<std::pair<int, std::complex<double>>> sorted_elements(row_sum.begin(), row_sum.end()); |
| 80 |
1/22✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 32 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
32 | std::ranges::sort(sorted_elements, [](const auto &a, const auto &b) { return a.first < b.first; }); |
| 81 | |||
| 82 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 80 times.
|
192 | for (const auto &[col_idx, value] : sorted_elements) { |
| 83 | // добавляем только значимые ненулевые элементы | ||
| 84 |
1/2✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
|
112 | if (std::abs(value) > 1e-12) { |
| 85 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 80 times.
|
112 | res.values.push_back(value); |
| 86 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 80 times.
|
112 | res.index_col.push_back(col_idx); |
| 87 | } | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | // последнее значение index_row - общее количество элементов | ||
| 92 | 32 | res.index_row.push_back(static_cast<int>(res.values.size())); | |
| 93 | |||
| 94 | 32 | return res.IsValid(); | |
| 95 | } | ||
| 96 | |||
| 97 | 48 | bool PosternakACRSMulComplexMatrixSEQ::PostProcessingImpl() { | |
| 98 | 48 | return GetOutput().IsValid(); | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace posternak_a_crs_mul_complex_matrix | ||
| 102 |