@@ -20,23 +20,20 @@ get_edge_weight(g::GNNGraph{<:ADJMAT_T}) = to_coo(g.graph, num_nodes=g.num_nodes
20
20
Graphs. edges (g:: GNNGraph ) = zip (edge_index (g)... )
21
21
22
22
Graphs. edgetype (g:: GNNGraph ) = Tuple{Int, Int}
23
- nodetype (g:: GNNGraph ) = Base. eltype (g)
24
23
25
- """
26
- nodetype (g::GNNGraph)
27
-
28
- Type of nodes in `g`,
29
- an integer type like `Int`, `Int32`, `Uint16`, ....
30
- """
31
- function nodetype (g:: GNNGraph{<:COO_T} , T = nothing )
24
+ # """
25
+ # eltype (g::GNNGraph)
26
+ #
27
+ # Type of nodes in `g`,
28
+ # an integer type like `Int`, `Int32`, `Uint16`, ....
29
+ # """
30
+ function Base . eltype (g:: GNNGraph{<:COO_T} )
32
31
s, t = edge_index (g)
33
- return eltype (s)
32
+ w = get_edge_weight (g)
33
+ return w != = nothing ? eltype (w) : eltype (s)
34
34
end
35
35
36
- function nodetype (g:: GNNGraph{<:ADJMAT_T} , T= nothing )
37
- T != = nothing && return T
38
- return eltype (g. graph)
39
- end
36
+ Base. eltype (g:: GNNGraph{<:ADJMAT_T} ) = eltype (g. graph)
40
37
41
38
function Graphs. has_edge (g:: GNNGraph{<:COO_T} , i:: Integer , j:: Integer )
42
39
s, t = edge_index (g)
@@ -94,7 +91,7 @@ function adjacency_list(g::GNNGraph; dir=:out)
94
91
return [fneighs (g, i) for i in 1 : g. num_nodes]
95
92
end
96
93
97
- function Graphs. adjacency_matrix (g:: GNNGraph{<:COO_T} , T:: DataType = nodetype (g); dir= :out )
94
+ function Graphs. adjacency_matrix (g:: GNNGraph{<:COO_T} , T:: DataType = eltype (g); dir= :out )
98
95
if g. graph[1 ] isa CuVector
99
96
# TODO revisit after https://github.com/JuliaGPU/CUDA.jl/pull/1152
100
97
A, n, m = to_dense (g. graph, T, num_nodes= g. num_nodes)
@@ -105,7 +102,7 @@ function Graphs.adjacency_matrix(g::GNNGraph{<:COO_T}, T::DataType=nodetype(g);
105
102
return dir == :out ? A : A'
106
103
end
107
104
108
- function Graphs. adjacency_matrix (g:: GNNGraph{<:ADJMAT_T} , T:: DataType = nodetype (g); dir= :out )
105
+ function Graphs. adjacency_matrix (g:: GNNGraph{<:ADJMAT_T} , T:: DataType = eltype (g); dir= :out )
109
106
@assert dir ∈ [:in , :out ]
110
107
A = g. graph
111
108
A = T != eltype (A) ? T .(A) : A
@@ -165,7 +162,7 @@ function Graphs.degree(g::GNNGraph{<:ADJMAT_T}, T=nothing; dir=:out, edge_weight
165
162
@assert ! (edge_weight isa AbstractArray) " passing the edge weights is not support by adjacency matrix representations"
166
163
@assert dir ∈ (:in , :out , :both )
167
164
if T === nothing
168
- Nt = nodetype (g)
165
+ Nt = eltype (g)
169
166
if edge_weight === false && ! (Nt <: Integer )
170
167
T = Nt == Float32 ? Int32 :
171
168
Nt == Float16 ? Int16 : Int
@@ -183,7 +180,7 @@ function Graphs.degree(g::GNNGraph{<:ADJMAT_T}, T=nothing; dir=:out, edge_weight
183
180
vec (sum (A, dims= 1 )) .+ vec (sum (A, dims= 2 ))
184
181
end
185
182
186
- function Graphs. laplacian_matrix (g:: GNNGraph , T:: DataType = nodetype (g); dir:: Symbol = :out )
183
+ function Graphs. laplacian_matrix (g:: GNNGraph , T:: DataType = eltype (g); dir:: Symbol = :out )
187
184
A = adjacency_matrix (g, T; dir= dir)
188
185
D = Diagonal (vec (sum (A; dims= 2 )))
189
186
return D - A
0 commit comments