| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <tuple> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "task/include/task.hpp" | ||
| 8 | |||
| 9 | namespace potashnik_m_matrix_mult_complex { | ||
| 10 | |||
| 11 | struct Complex { | ||
| 12 | double real; | ||
| 13 | double imaginary; | ||
| 14 | |||
| 15 |
2/6✓ Branch 0 taken 10296 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4232 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
25208 | explicit Complex(double real = 0.0, double imaginary = 0.0) : real(real), imaginary(imaginary) {} |
| 16 | |||
| 17 | bool operator==(const Complex &comp) const { | ||
| 18 |
6/8✗ Branch 0 not taken.
✓ Branch 1 taken 5148 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5148 times.
✓ Branch 4 taken 2412 times.
✓ Branch 5 taken 8268 times.
✓ Branch 6 taken 576 times.
✓ Branch 7 taken 1836 times.
|
15828 | return comp.real == real && comp.imaginary == imaginary; |
| 19 | } | ||
| 20 | |||
| 21 | bool operator!=(const Complex &comp) const { | ||
| 22 | return !(comp == *this); | ||
| 23 | } | ||
| 24 | |||
| 25 | Complex operator*(const Complex &comp) const { | ||
| 26 | 59680 | double tmp_real = (real * comp.real) - (imaginary * comp.imaginary); | |
| 27 |
1/2✓ Branch 1 taken 59680 times.
✗ Branch 2 not taken.
|
59680 | double tmp_imaginary = (real * comp.imaginary) + (imaginary * comp.real); |
| 28 | return Complex{tmp_real, tmp_imaginary}; | ||
| 29 | } | ||
| 30 | |||
| 31 | Complex operator+(const Complex &comp) const { | ||
| 32 | double tmp_real = real + comp.real; | ||
| 33 | double tmp_imaginary = imaginary + comp.imaginary; | ||
| 34 | return Complex{tmp_real, tmp_imaginary}; | ||
| 35 | } | ||
| 36 | |||
| 37 | Complex &operator+=(const Complex &comp) { | ||
| 38 | 63912 | real += comp.real; | |
| 39 | 63912 | imaginary += comp.imaginary; | |
| 40 | return *this; | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | |||
| 44 | struct CCSMatrix { | ||
| 45 | std::vector<Complex> val; | ||
| 46 | std::vector<size_t> row_ind; | ||
| 47 | std::vector<size_t> col_ptr; | ||
| 48 | size_t height = 0; | ||
| 49 | size_t width = 0; | ||
| 50 | |||
| 51 | CCSMatrix() = default; | ||
| 52 | |||
| 53 |
1/2✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
|
240 | explicit CCSMatrix(const std::vector<std::vector<Complex>> &matr) : height(matr.size()) { |
| 54 |
1/2✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
|
240 | if (!matr.empty()) { |
| 55 | 240 | width = matr[0].size(); | |
| 56 | } else { | ||
| 57 | width = 0; | ||
| 58 | } | ||
| 59 | |||
| 60 |
2/4✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 240 times.
✗ Branch 3 not taken.
|
240 | if (height == 0 || width == 0) { |
| 61 | return; | ||
| 62 | } | ||
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 1548 times.
✓ Branch 1 taken 240 times.
|
1788 | for (size_t col = 0; col < width; ++col) { |
| 65 |
2/2✓ Branch 0 taken 10680 times.
✓ Branch 1 taken 1548 times.
|
12228 | for (size_t row = 0; row < height; ++row) { |
| 66 | if (matr[row][col] != Complex(0.0)) { | ||
| 67 |
2/2✓ Branch 0 taken 8544 times.
✓ Branch 1 taken 1560 times.
|
10104 | val.push_back(matr[row][col]); |
| 68 |
2/2✓ Branch 0 taken 8544 times.
✓ Branch 1 taken 1560 times.
|
10104 | row_ind.push_back(row); |
| 69 |
2/2✓ Branch 0 taken 8544 times.
✓ Branch 1 taken 1560 times.
|
10104 | col_ptr.push_back(col); |
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | [[nodiscard]] size_t Count() const { | ||
| 76 | return val.size(); | ||
| 77 | } | ||
| 78 | |||
| 79 | 120 | bool Compare(const CCSMatrix &matr) { | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (height != matr.height) { |
| 81 | return false; | ||
| 82 | } | ||
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (width != matr.width) { |
| 84 | return false; | ||
| 85 | } | ||
| 86 | |||
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (val.size() != matr.val.size()) { |
| 88 | return false; | ||
| 89 | } | ||
| 90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (row_ind.size() != matr.row_ind.size()) { |
| 91 | return false; | ||
| 92 | } | ||
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
|
120 | if (col_ptr.size() != matr.col_ptr.size()) { |
| 94 | return false; | ||
| 95 | } | ||
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 5148 times.
✓ Branch 1 taken 120 times.
|
5268 | for (size_t i = 0; i < val.size(); i++) { |
| 98 | if (val[i] != matr.val[i]) { | ||
| 99 | return false; | ||
| 100 | } | ||
| 101 | } | ||
| 102 |
2/2✓ Branch 0 taken 5148 times.
✓ Branch 1 taken 120 times.
|
5268 | for (size_t i = 0; i < row_ind.size(); i++) { |
| 103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5148 times.
|
5148 | if (row_ind[i] != matr.row_ind[i]) { |
| 104 | return false; | ||
| 105 | } | ||
| 106 | } | ||
| 107 |
2/2✓ Branch 0 taken 5148 times.
✓ Branch 1 taken 120 times.
|
5268 | for (size_t i = 0; i < col_ptr.size(); i++) { |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5148 times.
|
5148 | if (col_ptr[i] != matr.col_ptr[i]) { |
| 109 | return false; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | return true; | ||
| 114 | } | ||
| 115 | }; | ||
| 116 | |||
| 117 | using InType = std::tuple<CCSMatrix, CCSMatrix>; | ||
| 118 | using OutType = CCSMatrix; | ||
| 119 | using TestType = std::tuple<size_t, size_t, size_t>; | ||
| 120 | using BaseTask = ppc::task::Task<InType, OutType>; | ||
| 121 | |||
| 122 | } // namespace potashnik_m_matrix_mult_complex | ||
| 123 |