Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is not possible to instantiate an empty array in the model macro #261

Closed
bvdmitri opened this issue Dec 31, 2024 · 0 comments · Fixed by #263
Closed

It is not possible to instantiate an empty array in the model macro #261

bvdmitri opened this issue Dec 31, 2024 · 0 comments · Fixed by #263
Assignees
Labels
bug Something isn't working

Comments

@bvdmitri
Copy link
Member

Consider the following

@model function huh()
    a = []
end

This might be useful to populate some intermediate values for later usage inside the model, but this currently fails with

LoadError: BoundsError: attempt to access 0-element Vector{Any} at index [1]
in expression starting at In[23]:1

Stacktrace:
  [1] throw_boundserror(A::Vector{Any}, I::Tuple{Int64})
    @ Base ./essentials.jl:14
  [2] getindex
    @ ./essentials.jl:916 [inlined]
  [3] (::GraphPPL.var"#123#124")(x::Expr)
    @ GraphPPL ~/.julia/dev/GraphPPL.jl/src/model_macro.jl:268
  [4] guarded_walk
    @ ~/.julia/dev/GraphPPL.jl/src/model_macro.jl:14 [inlined]
  [5] (::GraphPPL.var"#105#106"{GraphPPL.guarded_walk{GraphPPL.var"#123#124"}, GraphPPL.var"#115#116"{typeof(GraphPPL.convert_to_kwargs_expression)}})(x::Expr)
    @ GraphPPL ~/.julia/dev/GraphPPL.jl/src/model_macro.jl:14
  [6] iterate
    @ ./generator.jl:48 [inlined]
  [7] collect_to!(dest::Vector{Symbol}, itr::Base.Generator{Vector{Any}, GraphPPL.var"#105#106"{GraphPPL.guarded_walk{GraphPPL.var"#123#124"}, GraphPPL.var"#115#116"{typeof(GraphPPL.convert_to_kwargs_expression)}}}, offs::Int64, st::Int64)
    @ Base ./array.jl:849
  [8] collect_to_with_first!(dest::Vector{Symbol}, v1::Symbol, itr::Base.Generator{Vector{Any}, GraphPPL.var"#105#106"{GraphPPL.guarded_walk{GraphPPL.var"#123#124"}, GraphPPL.var"#115#116"{typeof(GraphPPL.convert_to_kwargs_expression)}}}, st::Int64)

This works fine

@model function huhhhh()
    a = Any[]
end
@bvdmitri bvdmitri added the bug Something isn't working label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants