Skip to content

Commit 965314c

Browse files
docstrings
1 parent 5968e4d commit 965314c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/GNNGraphs/query.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ function _get_edge_weight(g, edge_weight)
125125
return ew
126126
end
127127

128+
"""
129+
degree(g::GNNGraph, T=nothing; dir=:out, edge_weight=true)
130+
131+
Return a vector containing the degrees of the nodes in `g`.
132+
133+
# Arguments
134+
- `g`: A graph.
135+
- `T`: Element type of the returned vector. If `nothing`, is
136+
chosen based on the graph type and will be an integer
137+
if `edge_weight=false`.
138+
- `dir`: For `dir=:out` the degree of a node is counted based on the outgoing edges.
139+
For `dir=:in`, the ingoing edges are used. If `dir=:both` we have the sum of the two.
140+
- `edge_weight`: If `true` and the graph contains weighted edges, the degree will
141+
be weighted. Set to `false` instead to just count the number of
142+
outgoing/ingoing edges.
143+
In alternative, you can also pass a vector of weights to be used
144+
instead of the graph's own weights.
145+
"""
128146
function Graphs.degree(g::GNNGraph{<:COO_T}, T=nothing; dir=:out, edge_weight=true)
129147
s, t = edge_index(g)
130148

test/GNNGraphs/query.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@
4747
eweight = [0.1, 2.1, 1.2, 1]
4848
g = GNNGraph((s, t, eweight), graph_type=GRAPH_T)
4949
@test degree(g) == [2.2, 1.2, 1.0, 0.0]
50+
d = degree(g, edge_weight=false)
5051
if GRAPH_T == :coo
51-
@test degree(g, edge_weight=false) == [2, 1, 1, 0]
52+
@test d == [2, 1, 1, 0]
5253
@test degree(g, edge_weight=nothing) == [2, 1, 1, 0]
5354
else
5455
# Adjacency matrix representation cannot disambiguate multiple edges
5556
# and edge weights
56-
@test degree(g, edge_weight=false) == [1, 1, 1, 0]
57+
@test d == [1, 1, 1, 0]
5758
@test degree(g, edge_weight=nothing) == [1, 1, 1, 0]
5859
end
60+
@test eltype(d) <: Integer
5961
if GRAPH_T == :coo
6062
@test degree(g, edge_weight=2*eweight) == [4.4, 2.4, 2.0, 0.0]
6163
end

0 commit comments

Comments
 (0)