Skip to content

Commit 6704a30

Browse files
ilancoulonyuehhua
authored andcommitted
Splitting graph/utils.jl to include some functions only when necessary
1 parent b1e2d62 commit 6704a30

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

src/GeometricFlux.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ function __init__()
151151
end
152152
@require SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" begin
153153
include("graph/weightedgraphs.jl")
154-
include("graph/utils.jl")
155154
end
156155
@require MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5" begin
157156
include("graph/metagraphs.jl")

src/graph/simplegraphs.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1-
using LightGraphs: AbstractSimpleGraph, nv, adjacency_matrix, inneighbors, outneighbors, all_neighbors
1+
using LightGraphs: AbstractSimpleGraph, nv, inneighbors, outneighbors, all_neighbors
2+
import LightGraphs: adjacency_matrix
3+
4+
## Utils for AbstractSimpleGraph
5+
6+
function adjlist(g::AbstractSimpleGraph)
7+
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)
25+
end
26+
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)
232

333
## Convolution layers accepting AbstractSimpleGraph
434

src/graph/utils.jl

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

src/graph/weightedgraphs.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
using SimpleWeightedGraphs: AbstractSimpleWeightedGraph, nv
1+
using SimpleWeightedGraphs: AbstractSimpleWeightedGraph, nv, outneighbors
2+
3+
## Utils for AbstractSimpleWeightedGraph
4+
5+
function adjlist(g::AbstractSimpleWeightedGraph)
6+
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)
15+
end
16+
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+
235

336
## Convolution layers accepting AbstractSimpleWeightedGraph
437

0 commit comments

Comments
 (0)