| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "borunov_v_complex_ccs/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <complex> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "borunov_v_complex_ccs/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace borunov_v_complex_ccs { | ||
| 12 | |||
| 13 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | BorunovVComplexCcsSEQ::BorunovVComplexCcsSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetOutput().resize(1); |
| 17 | 24 | } | |
| 18 | |||
| 19 | 24 | bool BorunovVComplexCcsSEQ::ValidationImpl() { | |
| 20 | const auto &a = GetInput().first; | ||
| 21 | const auto &b = GetInput().second; | ||
| 22 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (a.num_cols != b.num_rows) { |
| 23 | return false; | ||
| 24 | } | ||
| 25 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (a.col_ptrs.size() != static_cast<size_t>(a.num_cols) + 1 || |
| 26 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | b.col_ptrs.size() != static_cast<size_t>(b.num_cols) + 1) { |
| 27 | ✗ | return false; | |
| 28 | } | ||
| 29 | return true; | ||
| 30 | } | ||
| 31 | |||
| 32 | 24 | bool BorunovVComplexCcsSEQ::PreProcessingImpl() { | |
| 33 | const auto &a = GetInput().first; | ||
| 34 | const auto &b = GetInput().second; | ||
| 35 | auto &c = GetOutput()[0]; | ||
| 36 | |||
| 37 | 24 | c.num_rows = a.num_rows; | |
| 38 | 24 | c.num_cols = b.num_cols; | |
| 39 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
|
24 | c.col_ptrs.assign(c.num_cols + 1, 0); |
| 40 | c.values.clear(); | ||
| 41 | c.row_indices.clear(); | ||
| 42 | |||
| 43 | 24 | return true; | |
| 44 | } | ||
| 45 | |||
| 46 | 24 | bool BorunovVComplexCcsSEQ::RunImpl() { | |
| 47 | const auto &a = GetInput().first; | ||
| 48 | const auto &b = GetInput().second; | ||
| 49 | auto &c = GetOutput()[0]; | ||
| 50 | |||
| 51 | 24 | std::vector<std::complex<double>> col_accumulator(a.num_rows, {0.0, 0.0}); | |
| 52 | 24 | std::vector<int> non_zero_indices; | |
| 53 |
1/4✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
24 | std::vector<bool> is_non_zero(a.num_rows, false); |
| 54 | |||
| 55 |
2/2✓ Branch 0 taken 320 times.
✓ Branch 1 taken 24 times.
|
344 | for (int j = 0; j < b.num_cols; ++j) { |
| 56 |
2/2✓ Branch 0 taken 1232 times.
✓ Branch 1 taken 320 times.
|
1552 | for (int b_idx = b.col_ptrs[j]; b_idx < b.col_ptrs[j + 1]; ++b_idx) { |
| 57 | 1232 | int p = b.row_indices[b_idx]; | |
| 58 | 1232 | std::complex<double> b_val = b.values[b_idx]; | |
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 3784 times.
✓ Branch 1 taken 1232 times.
|
5016 | for (int a_idx = a.col_ptrs[p]; a_idx < a.col_ptrs[p + 1]; ++a_idx) { |
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3784 times.
|
3784 | int i = a.row_indices[a_idx]; |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3784 times.
|
3784 | std::complex<double> a_val = a.values[a_idx]; |
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 2672 times.
✓ Branch 1 taken 1112 times.
|
3784 | if (!is_non_zero[i]) { |
| 65 | is_non_zero[i] = true; | ||
| 66 | non_zero_indices.push_back(i); | ||
| 67 | } | ||
| 68 | 3784 | col_accumulator[i] += a_val * b_val; | |
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | std::ranges::sort(non_zero_indices); | ||
| 73 | |||
| 74 |
2/2✓ Branch 0 taken 2672 times.
✓ Branch 1 taken 320 times.
|
2992 | for (int i : non_zero_indices) { |
| 75 |
1/2✓ Branch 0 taken 2672 times.
✗ Branch 1 not taken.
|
2672 | if (std::abs(col_accumulator[i]) > 1e-9) { |
| 76 |
2/2✓ Branch 0 taken 2488 times.
✓ Branch 1 taken 184 times.
|
2672 | c.values.push_back(col_accumulator[i]); |
| 77 |
2/2✓ Branch 0 taken 2488 times.
✓ Branch 1 taken 184 times.
|
2672 | c.row_indices.push_back(i); |
| 78 | } | ||
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2672 times.
|
2672 | col_accumulator[i] = {0.0, 0.0}; |
| 80 | is_non_zero[i] = false; | ||
| 81 | } | ||
| 82 | non_zero_indices.clear(); | ||
| 83 | |||
| 84 | 320 | c.col_ptrs[j + 1] = static_cast<int>(c.values.size()); | |
| 85 | } | ||
| 86 | |||
| 87 | 24 | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | 24 | bool BorunovVComplexCcsSEQ::PostProcessingImpl() { | |
| 91 | 24 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace borunov_v_complex_ccs | ||
| 95 |