-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from biaslab/dev-performance
Performance improvements
- Loading branch information
Showing
7 changed files
with
157 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
module GraphPPLDistributionsExt | ||
using GraphPPL, Distributions | ||
|
||
using GraphPPL, Distributions, Static | ||
|
||
GraphPPL.NodeBehaviour(::Type{<:Distributions.Distribution}) = GraphPPL.Stochastic() | ||
|
||
function GraphPPL.default_parametrization(::GraphPPL.Atomic, t::Type{<:Distributions.Distribution}, interface_values) | ||
field_names = fieldnames(t) | ||
@assert length(interface_values) == length(field_names) "Distribution $t has $(length(field_names)) fields $(field_names) but $(length(interface_values)) values were provided." | ||
return NamedTuple{fieldnames(t)}(interface_values) | ||
return distributions_ext_default_parametrization(t, distributions_ext_input_interfaces(t), interface_values) | ||
end | ||
|
||
function distributions_ext_default_parametrization(t::Type{<:Distributions.Distribution}, ::GraphPPL.StaticInterfaces{interfaces}, interface_values) where {interfaces} | ||
@assert length(interface_values) == length(interfaces) "Distribution $t has $(length(interfaces)) fields $(interfaces) but $(length(interface_values)) values were provided." | ||
return NamedTuple{interfaces}(interface_values) | ||
end | ||
|
||
function GraphPPL.interfaces(T::Type{<:Distributions.Distribution}, _) | ||
return distributions_ext_interfaces(T) | ||
end | ||
|
||
@generated function distributions_ext_input_interfaces(::Type{T}) where {T} | ||
fnames = fieldnames(T) | ||
return quote | ||
GraphPPL.StaticInterfaces(($(map(QuoteNode, fnames)...), )) | ||
end | ||
end | ||
|
||
@generated function distributions_ext_interfaces(::Type{T}) where {T} | ||
fnames = fieldnames(T) | ||
return quote | ||
GraphPPL.StaticInterfaces((:out, $(map(QuoteNode, fnames)...))) | ||
end | ||
end | ||
GraphPPL.interfaces(t::Type{<:Distributions.Distribution}, val) = (:out, fieldnames(t)...) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters