Skip to content

Commit 74e4914

Browse files
fix tests
1 parent 87674d8 commit 74e4914

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

src/GNNGraphs/query.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function Graphs.degree(g::GNNGraph{<:ADJMAT_T}, T=nothing; dir=:out, edge_weight
174174
end
175175
A = adjacency_matrix(g)
176176
if (edge_weight === false) || (edge_weight === nothing)
177-
A = map(x -> x > 0 ? T(1) : T(0), A)
177+
A = map(>(0), A)
178178
end
179179
A = eltype(A) != T ? T.(A) : A
180180
return dir == :out ? vec(sum(A, dims=2)) :

test/GNNGraphs/query.jl

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,54 @@
3434
end
3535

3636
@testset "degree" begin
37-
s = [1, 1, 2, 3]
38-
t = [2, 2, 2, 4]
39-
g = GNNGraph(s, t, graph_type=GRAPH_T)
37+
@testset "unweighted" begin
38+
s = [1, 1, 2, 3]
39+
t = [2, 2, 2, 4]
40+
g = GNNGraph(s, t, graph_type=GRAPH_T)
4041

41-
@test degree(g) == degree(g; dir=:out) == [2, 1, 1, 0] # default is outdegree
42-
@test degree(g; dir=:in) == [0, 3, 0, 1]
43-
@test degree(g; dir=:both) == [2, 4, 1, 1]
44-
@test eltype(degree(g, Float32)) == Float32
42+
@test degree(g) == degree(g; dir=:out) == [2, 1, 1, 0] # default is outdegree
43+
@test degree(g; dir=:in) == [0, 3, 0, 1]
44+
@test degree(g; dir=:both) == [2, 4, 1, 1]
45+
@test eltype(degree(g, Float32)) == Float32
4546

46-
# weighted degree
47-
eweight = [0.1, 2.1, 1.2, 1]
48-
g = GNNGraph((s, t, eweight), graph_type=GRAPH_T)
49-
@test degree(g) == [2.2, 1.2, 1.0, 0.0]
50-
d = degree(g, edge_weight=false)
51-
if GRAPH_T == :coo
52-
@test d == [2, 1, 1, 0]
53-
@test degree(g, edge_weight=nothing) == [2, 1, 1, 0]
54-
else
55-
# Adjacency matrix representation cannot disambiguate multiple edges
56-
# and edge weights
57-
@test d == [1, 1, 1, 0]
58-
@test degree(g, edge_weight=nothing) == [1, 1, 1, 0]
59-
end
60-
@test eltype(d) <: Integer
61-
if GRAPH_T == :coo
62-
@test degree(g, edge_weight=2*eweight) == [4.4, 2.4, 2.0, 0.0]
47+
if TEST_GPU
48+
g_gpu = g |> gpu
49+
d = degree(g)
50+
d_gpu = degree(g_gpu)
51+
@test d_gpu isa CuVector{Int}
52+
@test Array(d_gpu) == d
53+
end
6354
end
55+
56+
@testset "weighted" begin
57+
# weighted degree
58+
s = [1, 1, 2, 3]
59+
t = [2, 2, 2, 4]
60+
eweight = [0.1, 2.1, 1.2, 1]
61+
g = GNNGraph((s, t, eweight), graph_type=GRAPH_T)
62+
@test degree(g) == [2.2, 1.2, 1.0, 0.0]
63+
d = degree(g, edge_weight=false)
64+
if GRAPH_T == :coo
65+
@test d == [2, 1, 1, 0]
66+
@test degree(g, edge_weight=nothing) == [2, 1, 1, 0]
67+
else
68+
# Adjacency matrix representation cannot disambiguate multiple edges
69+
# and edge weights
70+
@test d == [1, 1, 1, 0]
71+
@test degree(g, edge_weight=nothing) == [1, 1, 1, 0]
72+
end
73+
@test eltype(d) <: Integer
74+
if GRAPH_T == :coo
75+
@test degree(g, edge_weight=2*eweight) == [4.4, 2.4, 2.0, 0.0]
76+
end
6477

65-
if TEST_GPU
66-
d = degree(g)
67-
d_gpu = degree(g_gpu)
68-
@test d_gpu isa CuVector
69-
@test Array(d_gpu) == d
78+
if TEST_GPU
79+
g_gpu = g |> gpu
80+
d = degree(g)
81+
d_gpu = degree(g_gpu)
82+
@test d_gpu isa CuVector{Float32}
83+
@test Array(d_gpu) d
84+
end
7085
end
7186
end
7287
end

0 commit comments

Comments
 (0)