| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "viderman_a_sparse_matrix_mult_crs_complex/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cmath> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "viderman_a_sparse_matrix_mult_crs_complex/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace viderman_a_sparse_matrix_mult_crs_complex { | ||
| 10 | |||
| 11 |
1/2✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 | VidermanASparseMatrixMultCRSComplexSEQ::VidermanASparseMatrixMultCRSComplexSEQ(const InType &in) { |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | GetInput() = in; | ||
| 14 | 48 | GetOutput() = CRSMatrix(); | |
| 15 | 48 | } | |
| 16 | |||
| 17 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool VidermanASparseMatrixMultCRSComplexSEQ::ValidationImpl() { |
| 18 | const auto &input = GetInput(); | ||
| 19 | const auto &a = std::get<0>(input); | ||
| 20 | const auto &b = std::get<1>(input); | ||
| 21 | |||
| 22 |
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()) { |
| 23 | return false; | ||
| 24 | } | ||
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 40 times.
|
48 | if (a.cols != b.rows) { |
| 27 | 8 | return false; | |
| 28 | } | ||
| 29 | |||
| 30 | return true; | ||
| 31 | } | ||
| 32 | |||
| 33 | 40 | bool VidermanASparseMatrixMultCRSComplexSEQ::PreProcessingImpl() { | |
| 34 | const auto &input = GetInput(); | ||
| 35 | |||
| 36 | 40 | a_ = &std::get<0>(input); | |
| 37 | 40 | b_ = &std::get<1>(input); | |
| 38 | |||
| 39 | 40 | return true; | |
| 40 | } | ||
| 41 | |||
| 42 | 40 | void VidermanASparseMatrixMultCRSComplexSEQ::Multiply(const CRSMatrix &a, const CRSMatrix &b, CRSMatrix &c) { | |
| 43 | 40 | c.rows = a.rows; | |
| 44 | 40 | c.cols = b.cols; | |
| 45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
|
40 | c.row_ptr.assign(a.rows + 1, 0); |
| 46 | c.col_indices.clear(); | ||
| 47 | c.values.clear(); | ||
| 48 | |||
| 49 | 40 | std::vector<Complex> accumulator(b.cols, Complex(0.0, 0.0)); | |
| 50 |
1/4✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
40 | std::vector<int> marker(b.cols, -1); |
| 51 | 40 | std::vector<int> current_row_indices; | |
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 40 times.
|
120 | for (int i = 0; i < a.rows; ++i) { |
| 54 | current_row_indices.clear(); | ||
| 55 | |||
| 56 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 80 times.
|
136 | for (int j = a.row_ptr[i]; j < a.row_ptr[i + 1]; ++j) { |
| 57 | 56 | int col_a = a.col_indices[j]; | |
| 58 | 56 | Complex val_a = a.values[j]; | |
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 56 times.
|
112 | for (int k = b.row_ptr[col_a]; k < b.row_ptr[col_a + 1]; ++k) { |
| 61 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | int col_b = b.col_indices[k]; |
| 62 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | accumulator[col_b] += val_a * b.values[k]; |
| 63 | |||
| 64 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (marker[col_b] != i) { |
| 65 | current_row_indices.push_back(col_b); | ||
| 66 | 56 | marker[col_b] = i; | |
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | std::ranges::sort(current_row_indices); | ||
| 72 | |||
| 73 | 80 | c.row_ptr[i + 1] = c.row_ptr[i]; | |
| 74 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 80 times.
|
136 | for (int idx : current_row_indices) { |
| 75 |
1/2✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
|
56 | if (std::abs(accumulator[idx]) > kEpsilon) { |
| 76 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 48 times.
|
56 | c.values.push_back(accumulator[idx]); |
| 77 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 48 times.
|
56 | c.col_indices.push_back(idx); |
| 78 | 56 | ++c.row_ptr[i + 1]; | |
| 79 | } | ||
| 80 | 56 | accumulator[idx] = Complex(0.0, 0.0); | |
| 81 | } | ||
| 82 | } | ||
| 83 | 40 | } | |
| 84 | |||
| 85 | 40 | bool VidermanASparseMatrixMultCRSComplexSEQ::RunImpl() { | |
| 86 |
2/4✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
40 | if (a_ == nullptr || b_ == nullptr) { |
| 87 | return false; | ||
| 88 | } | ||
| 89 | |||
| 90 | CRSMatrix &c = GetOutput(); | ||
| 91 | 40 | Multiply(*a_, *b_, c); | |
| 92 | |||
| 93 | 40 | return true; | |
| 94 | } | ||
| 95 | |||
| 96 | 40 | bool VidermanASparseMatrixMultCRSComplexSEQ::PostProcessingImpl() { | |
| 97 | CRSMatrix &c = GetOutput(); | ||
| 98 | 40 | return c.IsValid(); | |
| 99 | } | ||
| 100 | |||
| 101 | } // namespace viderman_a_sparse_matrix_mult_crs_complex | ||
| 102 |