| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstddef> | ||
| 4 | #include <ostream> | ||
| 5 | #include <string> | ||
| 6 | #include <tuple> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "task/include/task.hpp" | ||
| 11 | |||
| 12 | namespace lobanov_d_multiply_matrix_ccs { | ||
| 13 | |||
| 14 | struct CompressedColumnMatrix { | ||
| 15 | int row_count = 0; | ||
| 16 | int column_count = 0; | ||
| 17 | int non_zero_count = 0; | ||
| 18 | std::vector<double> value_data; | ||
| 19 | std::vector<int> row_index_data; | ||
| 20 | std::vector<int> column_pointer_data; | ||
| 21 | |||
| 22 | CompressedColumnMatrix() = default; | ||
| 23 | |||
| 24 | CompressedColumnMatrix(int r, int c, int nz) : row_count(r), column_count(c), non_zero_count(nz) { | ||
| 25 | if (nz > 0) { | ||
| 26 | value_data.reserve(static_cast<std::size_t>(nz)); | ||
| 27 | row_index_data.reserve(static_cast<std::size_t>(nz)); | ||
| 28 | } | ||
| 29 | column_pointer_data.reserve(static_cast<std::size_t>(c) + 1); | ||
| 30 | } | ||
| 31 | |||
| 32 |
2/4✓ Branch 2 taken 22304 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 22304 times.
✗ Branch 6 not taken.
|
22304 | CompressedColumnMatrix(const CompressedColumnMatrix &other) = default; |
| 33 | 632 | CompressedColumnMatrix &operator=(const CompressedColumnMatrix &other) = default; | |
| 34 | |||
| 35 |
2/2✓ Branch 0 taken 23840 times.
✓ Branch 1 taken 88 times.
|
23928 | ~CompressedColumnMatrix() = default; |
| 36 | |||
| 37 | void ZeroInitialize() { | ||
| 38 | row_count = 0; | ||
| 39 | 8 | column_count = 0; | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | non_zero_count = 0; |
| 41 | value_data.clear(); | ||
| 42 | row_index_data.clear(); | ||
| 43 | column_pointer_data.clear(); | ||
| 44 | } | ||
| 45 | |||
| 46 | [[nodiscard]] bool IsValid() const { | ||
| 47 | if (row_count < 0 || column_count < 0 || non_zero_count < 0) { | ||
| 48 | return false; | ||
| 49 | } | ||
| 50 | if (non_zero_count > 0) { | ||
| 51 | if (value_data.size() != static_cast<std::size_t>(non_zero_count)) { | ||
| 52 | return false; | ||
| 53 | } | ||
| 54 | if (row_index_data.size() != static_cast<std::size_t>(non_zero_count)) { | ||
| 55 | return false; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | if (column_pointer_data.size() != static_cast<std::size_t>(column_count) + 1U) { | ||
| 59 | return false; | ||
| 60 | } | ||
| 61 | if (!column_pointer_data.empty() && column_pointer_data[0] != 0) { | ||
| 62 | return false; | ||
| 63 | } | ||
| 64 | return true; | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | using InType = std::pair<CompressedColumnMatrix, CompressedColumnMatrix>; | ||
| 69 | using OutType = CompressedColumnMatrix; | ||
| 70 | using TestType = std::tuple<std::string, CompressedColumnMatrix, CompressedColumnMatrix, CompressedColumnMatrix>; | ||
| 71 | using BaseTask = ppc::task::Task<InType, OutType>; | ||
| 72 | |||
| 73 | CompressedColumnMatrix CreateRandomCompressedColumnMatrix(int row_count, int column_count, double density_factor, | ||
| 74 | int seed); | ||
| 75 | |||
| 76 | 1344 | inline std::ostream &operator<<(std::ostream &os, const CompressedColumnMatrix &matrix) { | |
| 77 | os << "CompressedColumnMatrix{" | ||
| 78 | 4032 | << "rows=" << matrix.row_count << ", cols=" << matrix.column_count << ", nnz=" << matrix.non_zero_count << "}"; | |
| 79 | 1344 | return os; | |
| 80 | } | ||
| 81 | } // namespace lobanov_d_multiply_matrix_ccs | ||
| 82 |