| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include <algorithm> | ||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "guseva_crs/common/include/common.hpp" | ||
| 8 | #include "guseva_crs/common/include/multiplier.hpp" | ||
| 9 | |||
| 10 | namespace guseva_crs { | ||
| 11 | |||
| 12 | 48 | class MultiplierSeq : public Multiplier { | |
| 13 | public: | ||
| 14 | 48 | [[nodiscard]] CRS Multiply(const CRS &a, const CRS &b) const override { | |
| 15 | 48 | CRS result; | |
| 16 | 48 | result.nrows = a.nrows; | |
| 17 | 48 | result.ncols = b.ncols; | |
| 18 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | result.row_ptrs.push_back(0); |
| 19 | |||
| 20 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | auto bt = this->Transpose(b); |
| 21 | 48 | double sum = 0; | |
| 22 | 48 | std::size_t nz = 0; | |
| 23 | |||
| 24 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | std::vector<int> temp(a.nrows, -1); |
| 25 |
2/2✓ Branch 0 taken 776 times.
✓ Branch 1 taken 48 times.
|
824 | for (std::size_t i = 0; i < a.nrows; i++) { |
| 26 | std::ranges::fill(temp, -1); | ||
| 27 | 776 | std::size_t ind1 = a.row_ptrs[i]; | |
| 28 | 776 | std::size_t ind2 = a.row_ptrs[i + 1]; | |
| 29 |
2/2✓ Branch 0 taken 2344 times.
✓ Branch 1 taken 776 times.
|
3120 | for (std::size_t j = ind1; j < ind2; j++) { |
| 30 | 2344 | temp[a.cols[j]] = static_cast<int>(j); | |
| 31 | } | ||
| 32 |
2/2✓ Branch 0 taken 16072 times.
✓ Branch 1 taken 776 times.
|
16848 | for (std::size_t j = 0; j < bt.nrows; j++) { |
| 33 | 16072 | sum = 0; | |
| 34 | 16072 | std::size_t ind3 = bt.row_ptrs[j]; | |
| 35 | 16072 | std::size_t ind4 = bt.row_ptrs[j + 1]; | |
| 36 |
2/2✓ Branch 0 taken 40568 times.
✓ Branch 1 taken 16072 times.
|
56640 | for (std::size_t k = ind3; k < ind4; k++) { |
| 37 | 40568 | int aind = temp[bt.cols[k]]; | |
| 38 |
2/2✓ Branch 0 taken 5640 times.
✓ Branch 1 taken 34928 times.
|
40568 | if (aind != -1) { |
| 39 | 5640 | sum += a.values[aind] * bt.values[k]; | |
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 |
2/2✓ Branch 0 taken 4088 times.
✓ Branch 1 taken 11984 times.
|
16072 | if (std::fabs(sum) > kZERO) { |
| 44 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 344 times.
|
4088 | result.cols.push_back(j); |
| 45 |
2/2✓ Branch 0 taken 3744 times.
✓ Branch 1 taken 344 times.
|
4088 | result.values.push_back(sum); |
| 46 | 4088 | nz++; | |
| 47 | } | ||
| 48 | } | ||
| 49 | result.row_ptrs.push_back(nz); | ||
| 50 | } | ||
| 51 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | result.nz = nz; |
| 52 | 48 | return result; | |
| 53 | 48 | } | |
| 54 | }; | ||
| 55 | } // namespace guseva_crs | ||
| 56 |