|
34 | 34 | end
|
35 | 35 |
|
36 | 36 | @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) |
40 | 41 |
|
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 |
45 | 46 |
|
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 |
63 | 54 | 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 |
64 | 77 |
|
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 |
70 | 85 | end
|
71 | 86 | end
|
72 | 87 | end
|
0 commit comments