Skip to content

Commit bde2c6a

Browse files
remove graph function
1 parent 0510d2b commit bde2c6a

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

src/gnngraph.jl

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ function GNNGraph(data;
133133
ndata, edata, gdata)
134134
end
135135

136-
normalize_graphdata(data::NamedTuple, s) = data
137-
normalize_graphdata(data::Nothing, s) = NamedTuple()
138-
normalize_graphdata(data, s) = NamedTuple{(s,)}((data,))
139-
140136
# COO convenience constructors
141137
GNNGraph(s::AbstractVector, t::AbstractVector, v = nothing; kws...) = GNNGraph((s, t, v); kws...)
142138
GNNGraph((s, t)::NTuple{2}; kws...) = GNNGraph((s, t, nothing); kws...)
@@ -161,7 +157,6 @@ function GNNGraph(g::GNNGraph; ndata=g.ndata, edata=g.edata, gdata=g.gdata)
161157
ndata, edata, gdata)
162158
end
163159

164-
165160
"""
166161
edge_index(g::GNNGraph)
167162
@@ -172,19 +167,11 @@ the source and target nodes for each edges in `g`.
172167
s, t = edge_index(g)
173168
```
174169
"""
175-
edge_index(g::GNNGraph{<:COO_T}) = graph(g)[1:2]
176-
177-
edge_index(g::GNNGraph{<:ADJMAT_T}) = to_coo(graph(g))[1][1:2]
170+
edge_index(g::GNNGraph{<:COO_T}) = g.graph[1:2]
178171

179-
edge_weight(g::GNNGraph{<:COO_T}) = graph(g)[3]
172+
edge_index(g::GNNGraph{<:ADJMAT_T}) = to_coo(g.graph)[1][1:2]
180173

181-
"""
182-
graph(g::GNNGraph)
183-
184-
Return the underlying implementation of the graph structure of `g`,
185-
either an adjacency matrix or an edge list in the COO format.
186-
"""
187-
graph(g::GNNGraph) = g.graph
174+
edge_weight(g::GNNGraph{<:COO_T}) = g.graph[3]
188175

189176
LightGraphs.edges(g::GNNGraph) = zip(edge_index(g)...)
190177

@@ -195,7 +182,7 @@ function LightGraphs.has_edge(g::GNNGraph{<:COO_T}, i::Integer, j::Integer)
195182
return any((s .== i) .& (t .== j))
196183
end
197184

198-
LightGraphs.has_edge(g::GNNGraph{<:ADJMAT_T}, i::Integer, j::Integer) = graph(g)[i,j] != 0
185+
LightGraphs.has_edge(g::GNNGraph{<:ADJMAT_T}, i::Integer, j::Integer) = g.graph[i,j] != 0
199186

200187
LightGraphs.nv(g::GNNGraph) = g.num_nodes
201188
LightGraphs.ne(g::GNNGraph) = g.num_edges
@@ -208,7 +195,7 @@ function LightGraphs.outneighbors(g::GNNGraph{<:COO_T}, i::Integer)
208195
end
209196

210197
function LightGraphs.outneighbors(g::GNNGraph{<:ADJMAT_T}, i::Integer)
211-
A = graph(g)
198+
A = g.graph
212199
return findall(!=(0), A[i,:])
213200
end
214201

@@ -218,7 +205,7 @@ function LightGraphs.inneighbors(g::GNNGraph{<:COO_T}, i::Integer)
218205
end
219206

220207
function LightGraphs.inneighbors(g::GNNGraph{<:ADJMAT_T}, i::Integer)
221-
A = graph(g)
208+
A = g.graph
222209
return findall(!=(0), A[:,i])
223210
end
224211

@@ -232,14 +219,14 @@ function adjacency_list(g::GNNGraph; dir=:out)
232219
end
233220

234221
function LightGraphs.adjacency_matrix(g::GNNGraph{<:COO_T}, T::DataType=Int; dir=:out)
235-
A, n, m = to_sparse(graph(g), T, num_nodes=g.num_nodes)
222+
A, n, m = to_sparse(g.graph, T, num_nodes=g.num_nodes)
236223
@assert size(A) == (n, n)
237224
return dir == :out ? A : A'
238225
end
239226

240-
function LightGraphs.adjacency_matrix(g::GNNGraph{<:ADJMAT_T}, T::DataType=eltype(graph(g)); dir=:out)
227+
function LightGraphs.adjacency_matrix(g::GNNGraph{<:ADJMAT_T}, T::DataType=eltype(g.graph); dir=:out)
241228
@assert dir [:in, :out]
242-
A = graph(g)
229+
A = g.graph
243230
A = T != eltype(A) ? T.(A) : A
244231
return dir == :out ? A : A'
245232
end

src/utils.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ function cat_features(x1::NamedTuple, x2::NamedTuple)
1919

2020
NamedTuple(k => cat_features(getfield(x1,k), getfield(x2,k)) for k in keys(x1))
2121
end
22+
23+
# Turns generic type into named tuple
24+
normalize_graphdata(data::NamedTuple, s::Symbol) = data
25+
normalize_graphdata(data::Nothing, s::Symbol) = NamedTuple()
26+
normalize_graphdata(data, s::Symbol) = NamedTuple{(s,)}((data,))

0 commit comments

Comments
 (0)