Skip to content

Commit 08a3f04

Browse files
committed
Divide graph/utils.jl as well
Conflicts: src/graph/simplegraphs.jl src/graph/weightedgraphs.jl
1 parent 6704a30 commit 08a3f04

File tree

7 files changed

+27
-82
lines changed

7 files changed

+27
-82
lines changed

src/GeometricFlux.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export
9494
feature,
9595
nv,
9696

97-
# graph/utils
97+
# graph/simplegraphs
9898
adjlist,
9999

100100
# utils

src/graph/simplegraphs.jl

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1-
using LightGraphs: AbstractSimpleGraph, nv, inneighbors, outneighbors, all_neighbors
2-
import LightGraphs: adjacency_matrix
3-
4-
## Utils for AbstractSimpleGraph
1+
using LightGraphs: AbstractSimpleGraph, nv, adjacency_matrix, inneighbors, outneighbors,
2+
all_neighbors
53

64
function adjlist(g::AbstractSimpleGraph)
75
N = nv(g)
8-
el = Vector{Int}[outneighbors(g, i) for i = 1:N]
9-
return el
10-
end
11-
12-
13-
## Linear algebra API for AbstractSimpleGraph
14-
15-
function degrees(sg::AbstractSimpleGraph, T::DataType=eltype(sg); dir::Symbol=:out)
16-
degrees(adjacency_matrix(sg, T; dir=dir), T; dir=dir)
17-
end
18-
19-
function degree_matrix(sg::AbstractSimpleGraph, T::DataType=eltype(sg); dir::Symbol=:out)
20-
degree_matrix(adjacency_matrix(sg, T; dir=dir), T; dir=dir)
21-
end
22-
23-
function inv_sqrt_degree_matrix(sg::AbstractSimpleGraph, T::DataType=eltype(sg); dir::Symbol=:out)
24-
inv_sqrt_degree_matrix(adjacency_matrix(sg, T; dir=dir), T; dir=dir)
6+
Vector{Int}[outneighbors(g, i) for i = 1:N]
257
end
268

27-
function laplacian_matrix(sg::AbstractSimpleGraph, T::DataType=eltype(sg); dir::Symbol=:out)
28-
laplacian_matrix(adjacency_matrix(sg, T; dir=dir), T; dir=dir)
29-
end
30-
31-
adjacency_matrix(sg::Base.RefValue{<:AbstractSimpleGraph}, T::DataType=eltype(sg)) = adjacency_matrix(sg[], T)
32-
339
## Convolution layers accepting AbstractSimpleGraph
3410

3511
function GCNConv(g::AbstractSimpleGraph, ch::Pair{<:Integer,<:Integer}, σ = identity;

src/graph/weightedgraphs.jl

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
using SimpleWeightedGraphs: AbstractSimpleWeightedGraph, nv, outneighbors
22

3-
## Utils for AbstractSimpleWeightedGraph
4-
53
function adjlist(g::AbstractSimpleWeightedGraph)
64
N = nv(g)
7-
el = Vector{Int}[outneighbors(g, i) for i = 1:N]
8-
return el
9-
end
10-
11-
## Linear algebra API for AbstractSimpleWeightedGraph
12-
13-
function degrees(wg::AbstractSimpleWeightedGraph, T::DataType=eltype(wg); dir::Symbol=:out)
14-
degrees(adjacency_matrix(wg, T; dir=dir), T; dir=dir)
5+
Vector{Int}[outneighbors(g, i) for i = 1:N]
156
end
167

17-
function degree_matrix(wg::AbstractSimpleWeightedGraph, T::DataType=eltype(wg); dir::Symbol=:out)
18-
degree_matrix(adjacency_matrix(wg, T; dir=dir), T; dir=dir)
19-
end
20-
21-
function inv_sqrt_degree_matrix(wg::AbstractSimpleWeightedGraph, T::DataType=eltype(wg); dir::Symbol=:out)
22-
inv_sqrt_degree_matrix(adjacency_matrix(wg, T; dir=dir), T; dir=dir)
23-
end
24-
25-
function laplacian_matrix(wg::AbstractSimpleWeightedGraph, T::DataType=eltype(wg); dir::Symbol=:out)
26-
laplacian_matrix(adjacency_matrix(wg, T; dir=dir), T; dir=dir)
27-
end
28-
29-
function normalized_laplacian(wg::AbstractSimpleWeightedGraph, T::DataType=eltype(wg); selfloop::Bool=false)
30-
adj = adjacency_matrix(wg, T)
31-
selfloop && (adj += I)
32-
normalized_laplacian(adj, T)
33-
end
34-
35-
368
## Convolution layers accepting AbstractSimpleWeightedGraph
379

3810
function GCNConv(g::AbstractSimpleWeightedGraph, ch::Pair{<:Integer,<:Integer}, σ = identity;

test/graph/simplegraphs.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ ug = SimpleGraph(6)
3030
add_edge!(ug, 1, 2); add_edge!(ug, 1, 3); add_edge!(ug, 2, 3)
3131
add_edge!(ug, 3, 4); add_edge!(ug, 2, 5); add_edge!(ug, 3, 6)
3232

33+
dg = SimpleDiGraph(6)
34+
add_edge!(dg, 1, 3); add_edge!(dg, 2, 3); add_edge!(dg, 1, 6)
35+
add_edge!(dg, 2, 5); add_edge!(dg, 3, 4); add_edge!(dg, 3, 5)
36+
37+
el_ug = Vector{Int64}[[2, 3], [1, 3, 5], [1, 2, 4, 6], [3], [2], [3]]
38+
el_dg = Vector{Int64}[[3, 6], [3, 5], [4, 5], [], [], []]
3339

3440
@testset "simplegraphs" begin
41+
@testset "adjlist" begin
42+
@test adjlist(ug) == el_ug
43+
@test adjlist(dg) == el_dg
44+
end
45+
3546
@testset "linalg" begin
3647
for T in [Int8, Int16, Int32, Int64, Int128]
3748
@test degree_matrix(adj, T, dir=:out) == T.(deg)

test/graph/utils.jl

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/graph/weightedgraphs.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ ug = SimpleWeightedGraph(6)
3030
add_edge!(ug, 1, 2, 2); add_edge!(ug, 1, 3, 2); add_edge!(ug, 2, 3, 1)
3131
add_edge!(ug, 3, 4, 5); add_edge!(ug, 2, 5, 2); add_edge!(ug, 3, 6, 2)
3232

33+
dg = SimpleWeightedDiGraph(6)
34+
add_edge!(dg, 1, 3, 2); add_edge!(dg, 2, 3, 2); add_edge!(dg, 1, 6, 1)
35+
add_edge!(dg, 2, 5, -2); add_edge!(dg, 3, 4, -2); add_edge!(dg, 3, 5, -1)
36+
37+
el_ug = Vector{Int64}[[2, 3], [1, 3, 5], [1, 2, 4, 6], [3], [2], [3]]
38+
el_dg = Vector{Int64}[[3, 6], [3, 5], [4, 5], [], [], []]
3339

3440
@testset "weightedgraphs" begin
41+
@testset "adjlist" begin
42+
@test adjlist(ug) == el_ug
43+
@test adjlist(dg) == el_dg
44+
end
45+
3546
@testset "linalg" begin
3647
for T in [Int8, Int16, Int32, Int64, Int128]
3748
@test degree_matrix(adj, T, dir=:out) == T.(deg)

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ tests = [
4141
"graph/simplegraphs",
4242
"graph/weightedgraphs",
4343
"graph/metagraphs",
44-
"graph/utils",
4544
"utils",
4645
]
4746

0 commit comments

Comments
 (0)