| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "makoveeva_s_cannon_algorithm/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <tuple> | ||
| 5 | #include <utility> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "makoveeva_s_cannon_algorithm/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace makoveeva_s_cannon_algorithm { | ||
| 11 | |||
| 12 | namespace { | ||
| 13 | |||
| 14 | bool CheckMatrixSizes(const std::vector<double> &a, const std::vector<double> &b, int n) { | ||
| 15 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | if (n <= 0) { |
| 16 | return false; | ||
| 17 | } | ||
| 18 | 144 | const auto n_sz = static_cast<std::size_t>(n); | |
| 19 |
2/4✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
|
144 | const auto expected = n_sz * n_sz; |
| 20 |
4/8✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 72 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 72 times.
|
144 | return (a.size() == expected) && (b.size() == expected); |
| 21 | } | ||
| 22 | |||
| 23 | 72 | void MultiplyDense(const std::vector<double> &a, const std::vector<double> &b, int n, std::vector<double> *c) { | |
| 24 | 72 | const auto n_sz = static_cast<std::size_t>(n); | |
| 25 | 72 | c->assign(n_sz * n_sz, 0.0); | |
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 744 times.
✓ Branch 1 taken 72 times.
|
816 | for (int i = 0; i < n; ++i) { |
| 28 | 744 | const auto i_sz = static_cast<std::size_t>(i); | |
| 29 |
2/2✓ Branch 0 taken 14584 times.
✓ Branch 1 taken 744 times.
|
15328 | for (int k = 0; k < n; ++k) { |
| 30 | 14584 | const auto k_sz = static_cast<std::size_t>(k); | |
| 31 | 14584 | const double a_ik = a[(i_sz * n_sz) + k_sz]; | |
| 32 |
2/2✓ Branch 0 taken 366552 times.
✓ Branch 1 taken 14584 times.
|
381136 | for (int j = 0; j < n; ++j) { |
| 33 | 366552 | const auto j_sz = static_cast<std::size_t>(j); | |
| 34 | 366552 | (*c)[(i_sz * n_sz) + j_sz] += a_ik * b[(k_sz * n_sz) + j_sz]; | |
| 35 | } | ||
| 36 | } | ||
| 37 | } | ||
| 38 | 72 | } | |
| 39 | |||
| 40 | } // namespace | ||
| 41 | |||
| 42 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | MakoveevaSCannonAlgorithmSEQ::MakoveevaSCannonAlgorithmSEQ(const InType &in) { |
| 43 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 44 | GetInput() = in; | ||
| 45 | 72 | GetOutput() = std::vector<double>{}; | |
| 46 | 72 | } | |
| 47 | |||
| 48 | 72 | bool MakoveevaSCannonAlgorithmSEQ::ValidationImpl() { | |
| 49 | const auto &input = GetInput(); | ||
| 50 | const auto &a = std::get<0>(input); | ||
| 51 | const auto &b = std::get<1>(input); | ||
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | const int n = std::get<2>(input); |
| 53 | |||
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | if (!GetOutput().empty()) { |
| 55 | return false; | ||
| 56 | } | ||
| 57 | return CheckMatrixSizes(a, b, n); | ||
| 58 | } | ||
| 59 | |||
| 60 | 72 | bool MakoveevaSCannonAlgorithmSEQ::PreProcessingImpl() { | |
| 61 | 72 | const int n = std::get<2>(GetInput()); | |
| 62 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if (n <= 0) { |
| 63 | return false; | ||
| 64 | } | ||
| 65 | 72 | const auto n_sz = static_cast<std::size_t>(n); | |
| 66 | 72 | GetOutput().assign(n_sz * n_sz, 0.0); | |
| 67 | 72 | return true; | |
| 68 | } | ||
| 69 | |||
| 70 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | bool MakoveevaSCannonAlgorithmSEQ::RunImpl() { |
| 71 | const auto &input = GetInput(); | ||
| 72 | const auto &a = std::get<0>(input); | ||
| 73 | const auto &b = std::get<1>(input); | ||
| 74 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | const int n = std::get<2>(input); |
| 75 | |||
| 76 | if (!CheckMatrixSizes(a, b, n)) { | ||
| 77 | return false; | ||
| 78 | } | ||
| 79 | |||
| 80 | 72 | std::vector<double> result; | |
| 81 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | MultiplyDense(a, b, n, &result); |
| 82 | GetOutput() = std::move(result); | ||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | 72 | bool MakoveevaSCannonAlgorithmSEQ::PostProcessingImpl() { | |
| 87 | 72 | const int n = std::get<2>(GetInput()); | |
| 88 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if (n <= 0) { |
| 89 | return false; | ||
| 90 | } | ||
| 91 | 72 | const auto n_sz = static_cast<std::size_t>(n); | |
| 92 | 72 | return GetOutput().size() == (n_sz * n_sz); | |
| 93 | } | ||
| 94 | |||
| 95 | } // namespace makoveeva_s_cannon_algorithm | ||
| 96 |