Skip to content

Commit

Permalink
Fix ambiguity errors in neighborhood (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Apr 4, 2024
1 parent 161e678 commit 8e7d9af
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
12 changes: 0 additions & 12 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ g₁ ⊔ g₂ # Same as above
rename_vertices(v -> v[1], subgraph(v -> v[2] == 1, g₁ g₂))
rename_vertices(v -> v[1], subgraph(v -> v[2] == 2, g₁ g₂))

## #' Additionally, we can use standard array concatenation syntax, such as:
## #+ term=true
##
## [g; g]
##
## #' which is equivalent to `vcat(g, g)` or:
## #+ term=true
##
## [g;; g]
##
## #' which is the same as `hcat(g, g)`.

#' ## Generating this README

#' This file was generated with [Weave.jl](https://github.com/JunoLab/Weave.jl) with the following commands:
Expand Down
48 changes: 45 additions & 3 deletions src/abstractnamedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ function degree_histogram(g::AbstractNamedGraph, degfn=degree)
return hist
end

function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out)
function _neighborhood(
graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out
)
parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx)
parent_vertices = neighborhood(
parent_graph(graph), vertex_to_parent_vertex(graph, vertex), d, parent_distmx; dir
Expand All @@ -206,9 +208,25 @@ function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph
]
end

function neighborhood_dists(
graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out
function neighborhood(graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out)
return _neighborhood(graph, vertex, d, distmx; dir)
end

# Fix for ambiguity error with `AbstractGraph` version
function neighborhood(
graph::AbstractNamedGraph, vertex::Integer, d, distmx=weights(graph); dir=:out
)
return _neighborhood(graph, vertex, d, distmx; dir)
end

# Fix for ambiguity error with `AbstractGraph` version
function neighborhood(
graph::AbstractNamedGraph, vertex::Integer, d, distmx::AbstractMatrix{<:Real}; dir=:out
)
return _neighborhood(graph, vertex, d, distmx; dir)
end

function _neighborhood_dists(graph::AbstractNamedGraph, vertex, d, distmx; dir)
parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx)
parent_vertices_and_dists = neighborhood_dists(
parent_graph(graph), vertex_to_parent_vertex(graph, vertex), d, parent_distmx; dir
Expand All @@ -219,6 +237,30 @@ function neighborhood_dists(
]
end

function neighborhood_dists(
graph::AbstractNamedGraph, vertex, d, distmx=weights(graph); dir=:out
)
return _neighborhood_dists(graph, vertex, d, distmx; dir)
end

# Fix for ambiguity error with `AbstractGraph` version
function neighborhood_dists(
graph::AbstractNamedGraph, vertex::Integer, d, distmx=weights(graph); dir=:out
)
return _neighborhood_dists(graph, vertex, d, distmx; dir)
end

# Fix for ambiguity error with `AbstractGraph` version
function neighborhood_dists(
graph::AbstractNamedGraph,
vertex::Integer,
d,
distmx::AbstractMatrix{<:Real}=weights(graph);
dir=:out,
)
return _neighborhood_dists(graph, vertex, d, distmx; dir)
end

function _mincut(graph::AbstractNamedGraph, distmx)
parent_distmx = dist_matrix_to_parent_dist_matrix(graph, distmx)
parent_parity, bestcut = mincut(parent_graph(graph), parent_distmx)
Expand Down
5 changes: 5 additions & 0 deletions test/test_namedgraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ end
((1, 4), 3),
]
@test issetequal(neighborhood_dists(g, (1, 1), 3), ns_ds)

# Test ambiguity with Graphs.jl AbstractGraph definition
g = named_path_graph(5)
@test issetequal(neighborhood(g, 3, 1), [2, 3, 4])
@test issetequal(neighborhood_dists(g, 3, 1), [(2, 1), (3, 0), (4, 1)])
end
@testset "Basics (directed)" begin
g = NamedDiGraph(["A", "B", "C", "D"])
Expand Down

0 comments on commit 8e7d9af

Please sign in to comment.