-
Notifications
You must be signed in to change notification settings - Fork 32
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
[Merged by Bors] - Fix for type-instability in findranges
#277
Conversation
bors try |
@inline function findranges(f_ranges, f_idcs) | ||
return mapreduce(i -> f_ranges[i], vcat, f_idcs; init=Int[]) | ||
results = Int[] |
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.
Since the size of results array is known, maybe pre-allocate memory for results here to improve efficiency?
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.
It's not known though, since these are ranges that being concatenated, not just 1 Int
per element in f_ranges
. We could of course compute it by doing something like map(length, f_ranges)
, but can we always guarantee that f_idcs
holds all the f_ranges
? I wasn't sure about this, so preferred to leave it with size not specified.
Bors r+ |
TuringLang/Turing.jl#1661 With this PR: ```julia julia> using Turing, DynamicPPL, ReverseDiff julia> Turing.setadbackend(:reversediff); julia> @model function demo(x, ::Type{TV} = Vector{Float64}) where {TV} m = TV(undef, length(x)) m ~ MvNormal(length(x), 1.0) x ~ MvNormal(m, 1.0) end; julia> m = demo(randn(2)); julia> spl = DynamicPPL.Sampler(NUTS(0.65)) Sampler{NUTS{Turing.Core.ReverseDiffAD{false}, (), AdvancedHMC.DiagEuclideanMetric}}(NUTS{Turing.Core.ReverseDiffAD{false}, (), AdvancedHMC.DiagEuclideanMetric}(-1, 0.65, 10, 1000.0, 0.0), DynamicPPL.Selector(0x000f976df8fc2a48, :default, false)) julia> vi = DynamicPPL.VarInfo(m); julia> θ = vi[spl]; julia> new_vi = VarInfo(vi, spl, ReverseDiff.track(θ)); julia> eltype(new_vi, spl) # (✓) inference succeeds ReverseDiff.TrackedReal{Float64, Float64, ReverseDiff.TrackedArray{Float64, Float64, 1, Vector{Float64}, Vector{Float64}}} ```
findranges
findranges
TuringLang/Turing.jl#1661
With this PR: