| 127 | } |
| 128 | |
| 129 | void test_matrix() |
| 130 | { |
| 131 | auto map0 = std::make_shared<common::IndexMap>(MPI_COMM_WORLD, 8); |
| 132 | la::SparsityPattern p(MPI_COMM_WORLD, {map0, map0}, {1, 1}); |
| 133 | p.insert(0, 0); |
| 134 | p.insert(4, 5); |
| 135 | p.insert(5, 4); |
| 136 | p.finalize(); |
| 137 | |
| 138 | using T = float; |
| 139 | la::MatrixCSR<T> A(p); |
| 140 | A.add(std::vector<decltype(A)::value_type>{1}, std::vector{0}, |
| 141 | std::vector{0}); |
| 142 | A.add(std::vector<decltype(A)::value_type>{2.3}, std::vector{4}, |
| 143 | std::vector{5}); |
| 144 | |
| 145 | const std::vector Adense0 = A.to_dense(); |
| 146 | |
| 147 | // Note: we cut off the ghost rows by intent here! But therefore we are not |
| 148 | // able to work with the dimensions of Adense0 to compute indices, these |
| 149 | // contain the ghost rows, which also vary between processes. |
| 150 | md::mdspan<const T, md::extents<std::size_t, 8, md::dynamic_extent>> Adense( |
| 151 | Adense0.data(), 8, A.index_map(1)->size_global()); |
| 152 | |
| 153 | std::vector<T> Aref_data(8 * A.index_map(1)->size_global(), 0); |
| 154 | md::mdspan<T, md::extents<std::size_t, 8, md::dynamic_extent>> Aref( |
| 155 | Aref_data.data(), 8, A.index_map(1)->size_global()); |
| 156 | |
| 157 | auto to_global_col = [&](auto col) |
| 158 | { |
| 159 | std::array<std::int64_t, 1> tmp; |
| 160 | A.index_map(1)->local_to_global(std::vector<std::int32_t>{col}, tmp); |
| 161 | return tmp[0]; |
| 162 | }; |
| 163 | Aref(0, to_global_col(0)) = 1; |
| 164 | Aref(4, to_global_col(5)) = 2.3; |
| 165 | |
| 166 | for (std::size_t i = 0; i < Adense.extent(0); ++i) |
| 167 | for (std::size_t j = 0; j < Adense.extent(1); ++j) |
| 168 | CHECK(Adense(i, j) == Aref(i, j)); |
| 169 | |
| 170 | Aref(4, to_global_col(4)) = 2.3; |
| 171 | CHECK(Adense(4, to_global_col(4)) != Aref(4, to_global_col(4))); |
| 172 | } |
| 173 | |
| 174 | } // namespace |
| 175 |
no test coverage detected