Skip to content
Snippets Groups Projects
Commit 22280da1 authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

Allow SVG writer to have empty rows and cols

Nested sparse matrices were not allowed to have empty rows/cols. By choosing the minimum offset of other blocks, we get an educated guess for these cases.
parent 6bfade7a
No related branches found
No related tags found
1 merge request!484Allow SVG writer to have empty rows and cols
Pipeline #52255 passed
......@@ -590,8 +590,9 @@ namespace Dune {
} else {
// before we write anything, we need to calculate the
// offset for every {row,col} index
std::vector<std::size_t> col_offsets(cols + 1, 0);
std::vector<std::size_t> row_offsets(rows + 1, 0);
const auto null_offset = std::numeric_limits<std::size_t>::max();
std::vector<std::size_t> col_offsets(cols + 1, null_offset);
std::vector<std::size_t> row_offsets(rows + 1, null_offset);
for_each_entry([&](const auto &row, const auto &col, const auto &val) {
NullStream dev0;
// get size of sub-block
......@@ -599,18 +600,20 @@ namespace Dune {
writeSVGMatrix(val, dev0, opts, row_prefix, col_prefix);
// if we didn't see col size before
if (col_offsets[col + 1] == 0) // write it in the offset vector
if (col_offsets[col + 1] == null_offset) // write it in the offset vector
col_offsets[col + 1] = sub_size.first;
else // check that is the same we saw before
assert(col_offsets[col + 1] == sub_size.first);
// repeat proces for row sizes
if (row_offsets[row + 1] == 0)
if (row_offsets[row + 1] == null_offset)
row_offsets[row + 1] = sub_size.second;
else
assert(row_offsets[row + 1] == sub_size.second);
});
// if some rows/cols were not visited, make an educated guess with the minimum offset
auto min_row_offset = *std::min_element(begin(row_offsets), end(row_offsets));
std::replace(begin(row_offsets), end(row_offsets), null_offset, min_row_offset);
auto min_col_offset = *std::min_element(begin(col_offsets), end(col_offsets));
std::replace(begin(col_offsets), end(col_offsets), null_offset, min_col_offset);
// we have sizes for every block: to get offsets we make a partial sum
col_offsets[0] = interspace;
row_offsets[0] = interspace;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment