Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,14 @@ end
tighten_eltype(x) = x
tighten_eltype(x::Vector{Any}) = map(identity, x)

@nospecialize check_initial_params(x, n) = throw(
ArgumentError(
"initial_params must be specified as a vector of length equal to the number of chains or `nothing`",
),
)
function check_initial_params(x, n)
@nospecialize
throw(
ArgumentError(
"initial_params must be specified as a vector of length equal to the number of chains or `nothing`",
),
)
end
check_initial_params(::Nothing, n) = nothing
function check_initial_params(x::AbstractArray, n)
if length(x) != n
Expand All @@ -930,11 +933,14 @@ function check_initial_params(x::AbstractArray, n)
return nothing
end

@nospecialize check_initial_state(x, n) = throw(
ArgumentError(
"initial_state must be specified as a vector of length equal to the number of chains or `nothing`",
),
)
function check_initial_state(x, n)
@nospecialize
throw(
ArgumentError(
"initial_state must be specified as a vector of length equal to the number of chains or `nothing`",
),
)
end
check_initial_state(::Nothing, n) = nothing
function check_initial_state(x::AbstractArray, n)
if length(x) != n
Expand Down
18 changes: 18 additions & 0 deletions test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -940,4 +940,22 @@
end
end
end

@testset "Non-vector initial_params and initial_state with $mode" for mode in [
MCMCSerial(), MCMCThreads(), MCMCDistributed()
]
nchains = 4
@test_throws ArgumentError sample(
MyModel(),
MySampler(),
mode,
3,
nchains;
progress=false,
initial_params=(a=randn(), b=rand()),
)
@test_throws ArgumentError sample(
MyModel(), MySampler(), mode, 3, nchains; progress=false, initial_state=10
)
end
end
Loading