-
Notifications
You must be signed in to change notification settings - Fork 19
Fix undefined reference error when type widening #40
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
==========================================
+ Coverage 97.54% 97.61% +0.07%
==========================================
Files 5 5
Lines 122 126 +4
==========================================
+ Hits 119 123 +4
Misses 3 3
Continue to review full report at Codecov.
|
Do you have a MWE? IMO we should keep the interface and implementation in AbstractMCMC as general as possible, and as pointed out above the changes are quite restrictive. Maybe the underlying issue of the undefined reference could be fixed differently? Downstream packages can also always add their own implementation of |
Here is a MWE: julia> struct M <: AbstractMCMC.AbstractModel end
julia> struct S <: AbstractMCMC.AbstractSampler end
julia> a = Vector{Base.RefValue{Int}}(undef, 5); AbstractMCMC.save!!(a, Ref(1.0), 1, M(), S(), 5)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getindex at .\array.jl:787 [inlined]
[2] copyto!(::Array{Base.RefValue,1}, ::Int64, ::Array{Base.RefValue{Int64},1}, ::Int64, ::Int64) at .\abstractarray.jl:841
[3] append! at .\array.jl:955 [inlined]
[4] copy! at .\abstractarray.jl:708 [inlined]
[5] _setindex(::Array{Base.RefValue{Int64},1}, ::Base.RefValue{Float64}, ::Int64) at C:\Users\user\.julia\dev\BangBang\src\NoBang\base.jl:135
[6] may at C:\Users\user\.julia\dev\BangBang\src\core.jl:10 [inlined]
[7] setindex!! at C:\Users\user\.julia\dev\BangBang\src\base.jl:365 [inlined]
[8] #save!!#11 at C:\Users\user\.julia\dev\AbstractMCMC\src\interface.jl:139 [inlined]
[9] save!!(::Array{Base.RefValue{Int64},1}, ::Base.RefValue{Float64}, ::Int64, ::M, ::S, ::Int64) at C:\Users\user\.julia\dev\AbstractMCMC\src\interface.jl:139
[10] top-level scope at REPL[23]:1
[11] eval(::Module, ::Any) at .\boot.jl:331
[12] eval_user_input(::Any, ::REPL.REPLBackend) at C:\Users\user\AppData\Local\Programs\Julia\Julia-1.4.0\share\julia\stdlib\v1.4\REPL\src\REPL.jl:86
[13] run_backend(::REPL.REPLBackend) at C:\Users\user\.julia\packages\Revise\MgvIv\src\Revise.jl:1023
[14] top-level scope at REPL[1]:0 |
Do you need to work with |
I don't work with |
Yeah, I guess we could just switch to Can you revert the changes and just use AbstractMCMC.jl/src/interface.jl Line 139 in c7efc8a
(and adjust the docstring), change AbstractMCMC.jl/src/interface.jl Line 106 in c7efc8a
t = Vector{typeof(transition)}(undef, 0)
sizehint!(t, N)
return t and (while we're at it) AbstractMCMC.jl/src/interface.jl Line 115 in c7efc8a
to return Vector{typeof(transition)}(undef, 0) ? Then we keep the general interface but can optimize it still a bit for the default case of vectors. |
Sounds good to me. |
5501485
to
7e478f3
Compare
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devmotion I'm fine with this one if you are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the docstring and restricted the default implementation to containers that are Vector
s. Looks good to me if tests pass.
While testing stochastic control flow in Turing and DynamicPPL, I ran into an issue where
BangBang.setindex!!
tries to copy all of the old vector of transitions. Some of the elements of this vector would be undefined so it would throw and undefined reference error. This PR usesBangBang.push!!
andsizehint!
instead.