Skip to content

Commit

Permalink
Trait fns now come in pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Nov 21, 2023
1 parent 18321b6 commit a3db9c0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/beliefpropagation/beliefpropagation_schedule.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
default_edge_sequence_alg() = "forest_cover"

@traitfn undirected_default_bp_niters(g::AbstractGraph::(!IsDirected)) =
is_tree(g) ? 1 : nothing
function default_bp_niters(g::AbstractGraph)
return undirected_default_bp_niters(undirected_graph(underlying_graph(g)))
@traitfn default_bp_niters(g::::(!IsDirected)) = is_tree(g) ? 1 : nothing
@traitfn function default_bp_niters(g::::IsDirected)
return default_bp_niters(undirected_graph(underlying_graph(g)))
end

@traitfn function edge_sequence(
g::NamedGraph::(!IsDirected); alg=default_edge_sequence_alg(), kwargs...
g::::(!IsDirected); alg=default_edge_sequence_alg(), kwargs...
)
return edge_sequence(Algorithm(alg), g; kwargs...)
end

function edge_sequence(g::AbstractGraph; alg=default_edge_sequence_alg(), kwargs...)
@traitfn function edge_sequence(g::::IsDirected; alg=default_edge_sequence_alg(), kwargs...)
return edge_sequence(Algorithm(alg), undirected_graph(underlying_graph(g)); kwargs...)
end

function edge_sequence(alg::Algorithm, g::AbstractGraph; kwargs...)
@traitfn function edge_sequence(alg::Algorithm, g::::IsDirected; kwargs...)
return edge_sequence(alg, undirected_graph(underlying_graph(g)); kwargs...)
end

@traitfn function edge_sequence(
::Algorithm"forest_cover",
g::NamedGraph::(!IsDirected);
root_vertex=NamedGraphs.default_root_vertex,
::Algorithm"forest_cover", g::::(!IsDirected); root_vertex=NamedGraphs.default_root_vertex
)
forests = NamedGraphs.forest_cover(g)
edges = edgetype(g)[]
Expand All @@ -38,6 +35,6 @@ end
return edges
end

@traitfn function edge_sequence(::Algorithm"parallel", g::NamedGraph::(!IsDirected))
@traitfn function edge_sequence(::Algorithm"parallel", g::::(!IsDirected))
return [[e] for e in vcat(edges(g), reverse.(edges(g)))]
end

0 comments on commit a3db9c0

Please sign in to comment.