From 587d8cabc8e5b9879055147a44bab89821caa182 Mon Sep 17 00:00:00 2001 From: Tamas Nagy Date: Tue, 25 Apr 2023 12:10:03 -0700 Subject: [PATCH] patch for doubling edge case (#64) It was possible with the previous version where if the doubling was very close the resizing that you could end up in a situation where it fails to resize and it outgrows the container after subsampling. --- src/selection.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/selection.jl b/src/selection.jl index 6d3d942..da4e034 100644 --- a/src/selection.jl +++ b/src/selection.jl @@ -115,11 +115,14 @@ function select(setup::GrowthScreen, sample!(1:num_cells, picked, replace=false) @debug "Selecting $(length(picked))" else - # if we have room to grow, don't subsample, just shuffle and grow - # the available space + # if we have room to grow, don't subsample, just shuffle picked .= 0 picked[1:num_cells] .= shuffle(1:num_cells) + end + # if next doubling could exceed the space available, grow the + # preallocated arrays + if num_cells * 4 > length(output_c) resize!(output_c, num_cells * 4) resize!(output_p, num_cells * 4) end