Skip to content

Commit 3e87987

Browse files
committed
require init_params to be a vector of length equal to the nubmer of
chains or nothing
1 parent 95d8bfb commit 3e87987

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/sample.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ function mcmcsample(
314314

315315
# Ensure that initial parameters are `nothing` or of the correct length
316316
check_initial_params(init_params, nchains)
317-
# We will use `getindex` later so we need to `collect`.
318-
_init_params = init_params !== nothing ? collect(init_params) : nothing
319317

320318
# Set up a chains vector.
321319
chains = Vector{Any}(undef, nchains)
@@ -366,10 +364,10 @@ function mcmcsample(
366364
_sampler,
367365
N;
368366
progress=false,
369-
init_params=if _init_params === nothing
367+
init_params=if init_params === nothing
370368
nothing
371369
else
372-
_init_params[chainidx]
370+
init_params[chainidx]
373371
end,
374372
kwargs...,
375373
)
@@ -540,13 +538,21 @@ end
540538
tighten_eltype(x) = x
541539
tighten_eltype(x::Vector{Any}) = map(identity, x)
542540

543-
check_initial_params(x::Nothing, n::Int) = nothing
544-
function check_initial_params(x, n::Int)
541+
@nospecialize check_initial_params(x, n) = throw(
542+
ArgumentError(
543+
"initial parameters must be specified as a vector of length equal to the number of chains or `nothing`",
544+
),
545+
)
546+
547+
check_initial_params(::Nothing, n) = nothing
548+
function check_initial_params(x::AbstractArray, n)
545549
if length(x) != n
546550
throw(
547551
ArgumentError(
548552
"incorrect number of initial parameters (expected $n, received $(length(x))"
549553
),
550554
)
551555
end
556+
557+
return nothing
552558
end

0 commit comments

Comments
 (0)