From 36194576f6a92b82894ed68404ee0fbcf37beb97 Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Mon, 7 Oct 2024 18:42:43 +0200 Subject: [PATCH] #37 Fixed bug when running connected components where the last chunk was larger on the z axis than the rest. --- src/lib/cpp/cpu/connected_components.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/cpp/cpu/connected_components.cc b/src/lib/cpp/cpu/connected_components.cc index bfc1705..7ef3ec8 100644 --- a/src/lib/cpp/cpu/connected_components.cc +++ b/src/lib/cpp/cpu/connected_components.cc @@ -658,6 +658,12 @@ namespace cpu_par { apply_renaming(chunks + (i*chunk_size), this_chunk_size, renames[i]); } + // Handle the remainder of the last chunk, if it exists + if (total_z > n_chunks * global_shape.z) { + int64_t last_chunk_size = (total_z - (n_chunks * global_shape.z)) * global_shape.y * global_shape.x; + apply_renaming(chunks + (n_chunks*chunk_size), last_chunk_size, renames[n_chunks-1]); + } + return n_labels[std::get<0>(index_tree[index_tree.size()-1][0])]; }