probcomp / Gen.jl

A general-purpose probabilistic programming system with programmable inference
https://gen.dev
Apache License 2.0
1.79k stars 160 forks source link

`_from_array` impl for vector doesn't handle nested elements #515

Open sritchie opened 8 months ago

sritchie commented 8 months ago

For example, we can fill a nested choicemap from an array:

julia> Gen._from_array(Gen.choicemap(:face => Gen.choicemap(:cake => 2), :foo => 3), [4, 5], 1)
(2, DynamicChoiceMap(Dict{Any, Any}(:face => DynamicChoiceMap(Dict{Any, Any}(:cake => 4), Dict{Any, Any}()), :foo => 5), Dict{Any, Any}()))

but the implementation of _from_array for vectors doesn't recursively call _from_array on its elements:

julia> Gen._from_array([1,2,[3]], [4,5,6], 1)
ERROR: MethodError: no method matching _from_array(::Vector{Any}, ::Vector{Int64}, ::Int64)
ztangent commented 8 months ago

Is there a reason why we need this implementation? (It's actually not clear to me where Gen._from_array(::Vector, ::Vector, ::Type) is even used elsewhere in the code.)

sritchie commented 8 months ago

@ztangent maybe not and it might be worth removing!