Skip to content

Commit 370dade

Browse files
more stuff
1 parent db9de4d commit 370dade

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/GNNGraphs/GNNGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export adjacency_list,
3636
adjacency_matrix,
3737
degree,
3838
has_self_loops,
39+
has_isolated_nodes,
3940
inneighbors,
4041
outneighbors
4142

src/GNNGraphs/query.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ function Graphs.degree(g::GNNGraph{<:ADJMAT_T}, T::TT=nothing; dir=:out, edge_we
240240
vec(sum(A, dims=1)) .+ vec(sum(A, dims=2))
241241
end
242242

243+
"""
244+
has_isolated_nodes(g::GNNGraph; dir=:out)
245+
246+
Return true if the graph `g` contains nodes with out-degree (if `dir=:out`)
247+
or in-degree (if `dir=:in`) equal to zero.
248+
"""
249+
function has_isolated_nodes(g::GNNGraph; dir=:out)
250+
return any(iszero, degree(g; dir))
251+
end
252+
253+
243254
function Graphs.laplacian_matrix(g::GNNGraph, T::DataType=eltype(g); dir::Symbol=:out)
244255
A = adjacency_matrix(g, T; dir=dir)
245256
D = Diagonal(vec(sum(A; dims=2)))

test/GNNGraphs/query.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
end
3030
end
3131

32+
@testset "has_isolated_nodes" begin
33+
s = [1, 2, 3]
34+
t = [2, 3, 2]
35+
g = GNNGraph(s, t, graph_type=GRAPH_T)
36+
@test has_isolated_nodes(g) == false
37+
@test has_isolated_nodes(g, dir=:in) == true
38+
end
39+
3240
@testset "has_self_loops" begin
3341
s = [1, 1, 2, 3]
3442
t = [2, 2, 2, 4]

test/GNNGraphs/transform.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239

240240
@testset "to_unidirected" begin
241241
if GRAPH_T == :coo
242-
s = [1, 2, 3, 4, 4],
242+
s = [1, 2, 3, 4, 4]
243243
t = [2, 3, 4, 3, 4]
244244
w = [1.0, 2.0, 3.0, 4.0, 5.0]
245245
e = [10.0, 20.0, 30.0, 40.0, 50.0]

0 commit comments

Comments
 (0)