@@ -53,11 +53,11 @@ function bootstrap(
5353 data = prepare_data_bootstrap (data, fitted. model)
5454 start = solution (fitted)
5555 # pre-allocations
56- out = []
57- conv = []
56+ out = Vector {Any} ( nothing , n_boot)
57+ conv = fill ( false , n_boot)
5858 # fit to bootstrap samples
5959 if ! parallel
60- for _ in 1 : n_boot
60+ for i in 1 : n_boot
6161 sample_data = bootstrap_sample (data)
6262 new_model = replace_observed (
6363 fitted. model;
@@ -68,8 +68,8 @@ function bootstrap(
6868 new_fit = fit (new_model; start_val = start, engine = engine, fit_kwargs... )
6969 sample = statistic (new_fit)
7070 c = converged (new_fit)
71- push! ( out, sample)
72- push! ( conv, c)
71+ out[i] = sample
72+ conv[i] = c
7373 end
7474 else
7575 n_threads = Threads. nthreads ()
@@ -80,7 +80,7 @@ function bootstrap(
8080 end
8181 # fit models in parallel
8282 lk = ReentrantLock ()
83- Threads. @threads for _ in 1 : n_boot
83+ Threads. @threads for i in 1 : n_boot
8484 thread_model = take! (model_pool)
8585 sample_data = bootstrap_sample (data)
8686 new_model = replace_observed (
@@ -92,17 +92,15 @@ function bootstrap(
9292 new_fit = fit (new_model; start_val = start, engine = engine, fit_kwargs... )
9393 sample = statistic (new_fit)
9494 c = converged (new_fit)
95- lock (lk) do
96- push! (out, sample)
97- push! (conv, c)
98- end
95+ out[i] = sample
96+ conv[i] = c
9997 put! (model_pool, thread_model)
10098 end
10199 end
102100 return Dict (
103- :samples => out,
101+ :samples => collect (a for a in out) ,
104102 :n_boot => n_boot,
105- :n_converged => isempty (conv) ? 0 : sum (conv),
103+ :n_converged => sum (conv),
106104 :converged => conv,
107105 )
108106end
0 commit comments