Summary
The broadcast form of the model DSL raises MethodError (no method matching tuple)
at model-construction time when the RHS supplies both positional and keyword arguments,
e.g. z .~ f(μ, σ = σ). Keyword-only and positional-only broadcast work; only the mixed
case is broken.
Root cause
src/model_macro.jl:617-628 combine_broadcast_args(args::Vector, kwargs::Vector) builds the
keyword NamedTuple from the entire broadcast-argument tuple args instead of just the
keyword values:
GraphPPL.MixedArguments((μ,), NamedTuple{(:σ,)}(args)) # args = (μ, σ) → MethodError
Repro
using GraphPPL, Distributions
import GraphPPL: @model, create_model
@model function bc_mixed(x, y, out)
out ~ Normal(x, y)
end
@model function bc_main2()
local μ, σ
for i in 1:5
μ[i] ~ Normal(0, 1); σ[i] ~ Gamma(1, 1)
end
z .~ bc_mixed(μ, σ = σ) # positional μ + keyword σ → MethodError
out ~ Normal(z[5], 1)
end
create_model(bc_main2()) # ERROR: MethodError no method matching tuple(...)
Suggested fix
Select only the keyword slice of the broadcast args for the NamedTuple in the else branch
of combine_broadcast_args (keep positional values in MixedArguments.args). Add a
regression test for the mixed broadcast case.
Summary
The broadcast form of the model DSL raises
MethodError(no method matchingtuple)at model-construction time when the RHS supplies both positional and keyword arguments,
e.g.
z .~ f(μ, σ = σ). Keyword-only and positional-only broadcast work; only the mixedcase is broken.
Root cause
src/model_macro.jl:617-628combine_broadcast_args(args::Vector, kwargs::Vector)builds thekeyword
NamedTuplefrom the entire broadcast-argument tupleargsinstead of just thekeyword values:
Repro
Suggested fix
Select only the keyword slice of the broadcast args for the NamedTuple in the
elsebranchof
combine_broadcast_args(keep positional values inMixedArguments.args). Add aregression test for the mixed broadcast case.