| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "tsyplakov_k_mul_double_crs_matrix/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstdlib> | ||
| 5 | #include <limits> | ||
| 6 | #include <map> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "tsyplakov_k_mul_double_crs_matrix/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace tsyplakov_k_mul_double_crs_matrix { | ||
| 12 | |||
| 13 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | TsyplakovKTestTaskSEQ::TsyplakovKTestTaskSEQ(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 32 | } | |
| 17 | |||
| 18 | 32 | bool TsyplakovKTestTaskSEQ::ValidationImpl() { | |
| 19 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
|
32 | return (GetInput().a.cols == GetInput().b.rows) && (GetInput().a.rows > 0) && (GetInput().a.cols > 0) && |
| 20 |
2/4✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
|
64 | (GetInput().b.rows > 0) && (GetInput().b.cols > 0); |
| 21 | } | ||
| 22 | |||
| 23 | 32 | bool TsyplakovKTestTaskSEQ::PreProcessingImpl() { | |
| 24 | 32 | GetOutput() = SparseMatrixCRS(GetInput().a.rows, GetInput().b.cols); | |
| 25 | 32 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 72 | std::vector<double> TsyplakovKTestTaskSEQ::MultiplyRowByMatrix(const std::vector<double> &row_values, | |
| 29 | const std::vector<int> &row_cols, | ||
| 30 | const SparseMatrixCRS &b, int &result_nnz) { | ||
| 31 | std::map<int, double> temp_result; | ||
| 32 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 72 times.
|
160 | for (size_t i = 0; i < row_cols.size(); ++i) { |
| 33 | 88 | int col_a = row_cols[i]; | |
| 34 | 88 | double val_a = row_values[i]; | |
| 35 | |||
| 36 | 88 | int start = b.row_ptr[col_a]; | |
| 37 | 88 | int end = b.row_ptr[col_a + 1]; | |
| 38 | |||
| 39 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 88 times.
|
176 | for (int j = start; j < end; ++j) { |
| 40 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | int col_b = b.col_index[j]; |
| 41 | 88 | double val_b = b.values[j]; | |
| 42 | |||
| 43 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | temp_result[col_b] += val_a * val_b; |
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | const double eps = std::numeric_limits<double>::epsilon() * 100; | ||
| 48 | 72 | std::vector<double> result_values; | |
| 49 | 72 | result_nnz = 0; | |
| 50 | |||
| 51 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
144 | for (auto it = temp_result.begin(); it != temp_result.end();) { |
| 52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | if (std::abs(it->second) < eps) { |
| 53 | it = temp_result.erase(it); | ||
| 54 | } else { | ||
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | result_values.push_back(it->second); |
| 56 | ++it; | ||
| 57 | 72 | ++result_nnz; | |
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | 72 | return result_values; | |
| 62 | } | ||
| 63 | |||
| 64 | 32 | bool TsyplakovKTestTaskSEQ::RunImpl() { | |
| 65 | const SparseMatrixCRS &a = GetInput().a; | ||
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | const SparseMatrixCRS &b = GetInput().b; |
| 67 | SparseMatrixCRS &c = GetOutput(); | ||
| 68 | |||
| 69 | c.values.clear(); | ||
| 70 | c.col_index.clear(); | ||
| 71 | 32 | c.row_ptr.assign(a.rows + 1, 0); | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 32 times.
|
104 | for (int i = 0; i < a.rows; ++i) { |
| 74 | 72 | int start_a = a.row_ptr[i]; | |
| 75 | 72 | int end_a = a.row_ptr[i + 1]; | |
| 76 | |||
| 77 |
1/2✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
|
72 | std::vector<double> row_values(a.values.begin() + start_a, a.values.begin() + end_a); |
| 78 |
1/4✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
72 | std::vector<int> row_cols(a.col_index.begin() + start_a, a.col_index.begin() + end_a); |
| 79 | |||
| 80 | 72 | int row_nnz = 0; | |
| 81 |
1/2✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
|
72 | std::vector<double> row_result = MultiplyRowByMatrix(row_values, row_cols, b, row_nnz); |
| 82 | |||
| 83 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 16 times.
|
72 | c.row_ptr[i + 1] = c.row_ptr[i] + row_nnz; |
| 84 | } | ||
| 85 | |||
| 86 | c.values.clear(); | ||
| 87 | c.col_index.clear(); | ||
| 88 | 32 | c.row_ptr.assign(a.rows + 1, 0); | |
| 89 | |||
| 90 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 32 times.
|
104 | for (int i = 0; i < a.rows; ++i) { |
| 91 | 72 | int start_a = a.row_ptr[i]; | |
| 92 | 72 | int end_a = a.row_ptr[i + 1]; | |
| 93 | |||
| 94 | std::map<int, double> temp_result; | ||
| 95 | |||
| 96 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 72 times.
|
160 | for (int k_idx = start_a; k_idx < end_a; ++k_idx) { |
| 97 | 88 | int k = a.col_index[k_idx]; | |
| 98 | 88 | double a_ik = a.values[k_idx]; | |
| 99 | |||
| 100 | 88 | int start_b = b.row_ptr[k]; | |
| 101 | 88 | int end_b = b.row_ptr[k + 1]; | |
| 102 | |||
| 103 |
2/2✓ Branch 0 taken 88 times.
✓ Branch 1 taken 88 times.
|
176 | for (int j_idx = start_b; j_idx < end_b; ++j_idx) { |
| 104 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | int j = b.col_index[j_idx]; |
| 105 | 88 | double b_kj = b.values[j_idx]; | |
| 106 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | temp_result[j] += a_ik * b_kj; |
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | const double eps = std::numeric_limits<double>::epsilon() * 100; | ||
| 111 | 72 | c.row_ptr[i] = static_cast<int>(c.values.size()); | |
| 112 | |||
| 113 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
|
144 | for (const auto &[col, val] : temp_result) { |
| 114 |
1/2✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
|
72 | if (std::abs(val) > eps) { |
| 115 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
|
72 | c.col_index.push_back(col); |
| 116 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
|
72 | c.values.push_back(val); |
| 117 | } | ||
| 118 | } | ||
| 119 | } | ||
| 120 | 32 | c.row_ptr[a.rows] = static_cast<int>(c.values.size()); | |
| 121 | |||
| 122 | 32 | return true; | |
| 123 | } | ||
| 124 | |||
| 125 | 32 | bool TsyplakovKTestTaskSEQ::PostProcessingImpl() { | |
| 126 | 32 | return true; | |
| 127 | } | ||
| 128 | |||
| 129 | } // namespace tsyplakov_k_mul_double_crs_matrix | ||
| 130 |