Skip to content

Commit 553af1d

Browse files
fix heterograph docs
1 parent a48126d commit 553af1d

File tree

7 files changed

+5
-481
lines changed

7 files changed

+5
-481
lines changed

GNNGraphs/docs/src/api/gnngraph.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ Private = false
3131

3232
```@autodocs
3333
Modules = [GNNGraphs]
34-
Pages = ["query.jl"]
34+
Pages = ["src/query.jl"]
3535
Private = false
3636
```
3737

38-
3938
```@docs
4039
Graphs.neighbors(::GNNGraph, ::Integer)
4140
```
@@ -44,7 +43,7 @@ Graphs.neighbors(::GNNGraph, ::Integer)
4443

4544
```@autodocs
4645
Modules = [GNNGraphs]
47-
Pages = ["transform.jl"]
46+
Pages = ["src/transform.jl"]
4847
Private = false
4948
```
5049

@@ -59,17 +58,16 @@ GNNGraphs.color_refinement
5958

6059
```@autodocs
6160
Modules = [GNNGraphs]
62-
Pages = ["generate.jl"]
61+
Pages = ["src/generate.jl"]
6362
Private = false
6463
Filter = t -> typeof(t) <: Function && t!=rand_temporal_radius_graph && t!=rand_temporal_hyperbolic_graph
65-
6664
```
6765

6866
## Operators
6967

7068
```@autodocs
7169
Modules = [GNNGraphs]
72-
Pages = ["operators.jl"]
70+
Pages = ["src/operators.jl"]
7371
Private = false
7472
```
7573

@@ -81,7 +79,7 @@ Base.intersect
8179

8280
```@autodocs
8381
Modules = [GNNGraphs]
84-
Pages = ["sampling.jl"]
82+
Pages = ["src/sampling.jl"]
8583
Private = false
8684
```
8785

GNNGraphs/docs/src/api/heterograph.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ CollapsedDocStrings = true
99
## GNNHeteroGraph
1010
Documentation page for the type `GNNHeteroGraph` representing heterogeneous graphs, where nodes and edges can have different types.
1111

12-
1312
```@autodocs
1413
Modules = [GNNGraphs]
1514
Pages = ["gnnheterograph.jl"]
1615
Private = false
1716
```
1817

19-
```@docs
20-
Graphs.has_edge(::GNNHeteroGraph, ::Tuple{Symbol, Symbol, Symbol}, ::Integer, ::Integer)
21-
```
22-
2318
## Query
2419

2520
```@autodocs

GNNGraphs/docs/src/api/samplers.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ CollapsedDocStrings = true
55

66
# Samplers
77

8-
9-
## Docs
10-
118
```@autodocs
129
Modules = [GNNGraphs]
1310
Pages = ["samplers.jl"]

GNNGraphs/src/generate.jl

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -64,130 +64,6 @@ function rand_graph(rng::AbstractRNG, n::Integer, m::Integer;
6464
return GNNGraph((s, t, edge_weight); num_nodes=n, kws...)
6565
end
6666

67-
"""
68-
rand_heterograph([rng,] n, m; bidirected=false, kws...)
69-
70-
Construct an [`GNNHeteroGraph`](@ref) with random edges and with number of nodes and edges
71-
specified by `n` and `m` respectively. `n` and `m` can be any iterable of pairs
72-
specifing node/edge types and their numbers.
73-
74-
Pass a random number generator as a first argument to make the generation reproducible.
75-
76-
Setting `bidirected=true` will generate a bidirected graph, i.e. each edge will have a reverse edge.
77-
Therefore, for each edge type `(:A, :rel, :B)` a corresponding reverse edge type `(:B, :rel, :A)`
78-
will be generated.
79-
80-
Additional keyword arguments will be passed to the [`GNNHeteroGraph`](@ref) constructor.
81-
82-
# Examples
83-
84-
```jldoctest
85-
julia> g = rand_heterograph((:user => 10, :movie => 20),
86-
(:user, :rate, :movie) => 30)
87-
GNNHeteroGraph:
88-
num_nodes: Dict(:movie => 20, :user => 10)
89-
num_edges: Dict((:user, :rate, :movie) => 30)
90-
```
91-
"""
92-
function rand_heterograph end
93-
94-
# for generic iterators of pairs
95-
rand_heterograph(n, m; kws...) = rand_heterograph(Dict(n), Dict(m); kws...)
96-
rand_heterograph(rng::AbstractRNG, n, m; kws...) = rand_heterograph(rng, Dict(n), Dict(m); kws...)
97-
98-
function rand_heterograph(n::NDict, m::EDict; seed=-1, kws...)
99-
if seed != -1
100-
Base.depwarn("Keyword argument `seed` is deprecated, pass an rng as first argument instead.", :rand_heterograph)
101-
rng = MersenneTwister(seed)
102-
else
103-
rng = Random.default_rng()
104-
end
105-
return rand_heterograph(rng, n, m; kws...)
106-
end
107-
108-
function rand_heterograph(rng::AbstractRNG, n::NDict, m::EDict; bidirected::Bool = false, kws...)
109-
if bidirected
110-
return _rand_bidirected_heterograph(rng, n, m; kws...)
111-
end
112-
graphs = Dict(k => _rand_edges(rng, (n[k[1]], n[k[3]]), m[k]) for k in keys(m))
113-
return GNNHeteroGraph(graphs; num_nodes = n, kws...)
114-
end
115-
116-
function _rand_bidirected_heterograph(rng::AbstractRNG, n::NDict, m::EDict; kws...)
117-
for k in keys(m)
118-
if reverse(k) keys(m)
119-
@assert m[k] == m[reverse(k)] "Number of edges must be the same in reverse edge types for bidirected graphs."
120-
else
121-
m[reverse(k)] = m[k]
122-
end
123-
end
124-
graphs = Dict{EType, Tuple{Vector{Int}, Vector{Int}, Nothing}}()
125-
for k in keys(m)
126-
reverse(k) keys(graphs) && continue
127-
s, t, val = _rand_edges(rng, (n[k[1]], n[k[3]]), m[k])
128-
graphs[k] = s, t, val
129-
graphs[reverse(k)] = t, s, val
130-
end
131-
return GNNHeteroGraph(graphs; num_nodes = n, kws...)
132-
end
133-
134-
135-
"""
136-
rand_bipartite_heterograph([rng,]
137-
(n1, n2), (m12, m21);
138-
bidirected = true,
139-
node_t = (:A, :B),
140-
edge_t = :to,
141-
kws...)
142-
143-
Construct an [`GNNHeteroGraph`](@ref) with random edges representing a bipartite graph.
144-
The graph will have two types of nodes, and edges will only connect nodes of different types.
145-
146-
The first argument is a tuple `(n1, n2)` specifying the number of nodes of each type.
147-
The second argument is a tuple `(m12, m21)` specifying the number of edges connecting nodes of type `1` to nodes of type `2`
148-
and vice versa.
149-
150-
The type of nodes and edges can be specified with the `node_t` and `edge_t` keyword arguments,
151-
which default to `(:A, :B)` and `:to` respectively.
152-
153-
If `bidirected=true` (default), the reverse edge of each edge will be present. In this case
154-
`m12 == m21` is required.
155-
156-
A random number generator can be passed as the first argument to make the generation reproducible.
157-
158-
Additional keyword arguments will be passed to the [`GNNHeteroGraph`](@ref) constructor.
159-
160-
See [`rand_heterograph`](@ref) for a more general version.
161-
162-
# Examples
163-
164-
```julia
165-
julia> g = rand_bipartite_heterograph((10, 15), 20)
166-
GNNHeteroGraph:
167-
num_nodes: (:A => 10, :B => 15)
168-
num_edges: ((:A, :to, :B) => 20, (:B, :to, :A) => 20)
169-
170-
julia> g = rand_bipartite_heterograph((10, 15), (20, 0), node_t=(:user, :item), edge_t=:-, bidirected=false)
171-
GNNHeteroGraph:
172-
num_nodes: Dict(:item => 15, :user => 10)
173-
num_edges: Dict((:item, :-, :user) => 0, (:user, :-, :item) => 20)
174-
```
175-
"""
176-
rand_bipartite_heterograph(n, m; kws...) = rand_bipartite_heterograph(Random.default_rng(), n, m; kws...)
177-
178-
function rand_bipartite_heterograph(rng::AbstractRNG, (n1, n2)::NTuple{2,Int}, m; bidirected=true,
179-
node_t = (:A, :B), edge_t::Symbol = :to, kws...)
180-
if m isa Integer
181-
m12 = m21 = m
182-
else
183-
m12, m21 = m
184-
end
185-
186-
return rand_heterograph(rng, Dict(node_t[1] => n1, node_t[2] => n2),
187-
Dict((node_t[1], edge_t, node_t[2]) => m12, (node_t[2], edge_t, node_t[1]) => m21);
188-
bidirected, kws...)
189-
end
190-
19167
"""
19268
knn_graph(points::AbstractMatrix,
19369
k::Int;

GNNGraphs/src/query.jl

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,10 @@ edge_index(g::GNNGraph{<:COO_T}) = g.graph[1:2]
1313

1414
edge_index(g::GNNGraph{<:ADJMAT_T}) = to_coo(g.graph, num_nodes = g.num_nodes)[1][1:2]
1515

16-
"""
17-
edge_index(g::GNNHeteroGraph, [edge_t])
18-
19-
Return a tuple containing two vectors, respectively storing the source and target nodes
20-
for each edges in `g` of type `edge_t = (src_t, rel_t, trg_t)`.
21-
22-
If `edge_t` is not provided, it will error if `g` has more than one edge type.
23-
"""
24-
edge_index(g::GNNHeteroGraph{<:COO_T}, edge_t::EType) = g.graph[edge_t][1:2]
25-
edge_index(g::GNNHeteroGraph{<:COO_T}) = only(g.graph)[2][1:2]
26-
2716
get_edge_weight(g::GNNGraph{<:COO_T}) = g.graph[3]
2817

2918
get_edge_weight(g::GNNGraph{<:ADJMAT_T}) = to_coo(g.graph, num_nodes = g.num_nodes)[1][3]
3019

31-
get_edge_weight(g::GNNHeteroGraph{<:COO_T}, edge_t::EType) = g.graph[edge_t][3]
32-
3320
Graphs.edges(g::GNNGraph) = Graphs.Edge.(edge_index(g)...)
3421

3522
Graphs.edgetype(g::GNNGraph) = Graphs.Edge{eltype(g)}
@@ -55,31 +42,6 @@ end
5542

5643
Graphs.has_edge(g::GNNGraph{<:ADJMAT_T}, i::Integer, j::Integer) = g.graph[i, j] != 0
5744

58-
"""
59-
has_edge(g::GNNHeteroGraph, edge_t, i, j)
60-
61-
Return `true` if there is an edge of type `edge_t` from node `i` to node `j` in `g`.
62-
63-
# Examples
64-
65-
```jldoctest
66-
julia> g = rand_bipartite_heterograph((2, 2), (4, 0), bidirected=false)
67-
GNNHeteroGraph:
68-
num_nodes: Dict(:A => 2, :B => 2)
69-
num_edges: Dict((:A, :to, :B) => 4, (:B, :to, :A) => 0)
70-
71-
julia> has_edge(g, (:A,:to,:B), 1, 1)
72-
true
73-
74-
julia> has_edge(g, (:B,:to,:A), 1, 1)
75-
false
76-
```
77-
"""
78-
function Graphs.has_edge(g::GNNHeteroGraph, edge_t::EType, i::Integer, j::Integer)
79-
s, t = edge_index(g, edge_t)
80-
return any((s .== i) .& (t .== j))
81-
end
82-
8345
"""
8446
get_graph_type(g::GNNGraph)
8547
@@ -390,36 +352,6 @@ function Graphs.degree(g::GNNGraph{<:ADJMAT_T}, T::TT = nothing; dir = :out,
390352
return _degree(A, T, dir, edge_weight, g.num_nodes)
391353
end
392354

393-
"""
394-
degree(g::GNNHeteroGraph, edge_type::EType; dir = :in)
395-
396-
Return a vector containing the degrees of the nodes in `g` GNNHeteroGraph
397-
given `edge_type`.
398-
399-
# Arguments
400-
401-
- `g`: A graph.
402-
- `edge_type`: A tuple of symbols `(source_t, edge_t, target_t)` representing the edge type.
403-
- `T`: Element type of the returned vector. If `nothing`, is
404-
chosen based on the graph type. Default `nothing`.
405-
- `dir`: For `dir = :out` the degree of a node is counted based on the outgoing edges.
406-
For `dir = :in`, the ingoing edges are used. If `dir = :both` we have the sum of the two.
407-
Default `dir = :out`.
408-
409-
"""
410-
function Graphs.degree(g::GNNHeteroGraph, edge::EType,
411-
T::TT = nothing; dir = :out) where {
412-
TT <: Union{Nothing, Type{<:Number}}}
413-
414-
s, t = edge_index(g, edge)
415-
416-
T = isnothing(T) ? eltype(s) : T
417-
418-
n_type = dir == :in ? g.ntypes[2] : g.ntypes[1]
419-
420-
return _degree((s, t), T, dir, nothing, g.num_nodes[n_type])
421-
end
422-
423355
function _degree((s, t)::Tuple, T::Type, dir::Symbol, edge_weight::Nothing, num_nodes::Int)
424356
_degree((s, t), T, dir, ones_like(s, T), num_nodes)
425357
end
@@ -579,28 +511,7 @@ function graph_indicator(g::GNNGraph; edges = false)
579511
end
580512
end
581513

582-
"""
583-
graph_indicator(g::GNNHeteroGraph, [node_t])
584-
585-
Return a Dict of vectors containing the graph membership
586-
(an integer from `1` to `g.num_graphs`) of each node in the graph for each node type.
587-
If `node_t` is provided, return the graph membership of each node of type `node_t` instead.
588514

589-
See also [`batch`](@ref).
590-
"""
591-
function graph_indicator(g::GNNHeteroGraph)
592-
return g.graph_indicator
593-
end
594-
595-
function graph_indicator(g::GNNHeteroGraph, node_t::Symbol)
596-
@assert node_t g.ntypes
597-
if isnothing(g.graph_indicator)
598-
gi = ones_like(edge_index(g, first(g.etypes))[1], Int, g.num_nodes[node_t])
599-
else
600-
gi = g.graph_indicator[node_t]
601-
end
602-
return gi
603-
end
604515

605516
function node_features(g::GNNGraph)
606517
if isempty(g.ndata)

0 commit comments

Comments
 (0)