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

[Merged by Bors] - Fix for type-instability in findranges #277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.12.1"
version = "0.12.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
7 changes: 6 additions & 1 deletion src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,13 @@ end
length(exprs) == 0 && return :(NamedTuple())
return :($(exprs...),)
end

@inline function findranges(f_ranges, f_idcs)
return mapreduce(i -> f_ranges[i], vcat, f_idcs; init=Int[])
results = Int[]
Copy link
Member

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?

Copy link
Member Author

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.

for i in f_idcs
append!(results, f_ranges[i])
end
return results
end

"""
Expand Down