|
11 | 11 |
|
12 | 12 | # core functionality
|
13 | 13 | g = GNNGraph(s, t; graph_type=GRAPH_T)
|
| 14 | + if TEST_GPU |
| 15 | + g_gpu = g |> gpu |
| 16 | + end |
| 17 | + |
14 | 18 | @test g.num_edges == 8
|
15 | 19 | @test g.num_nodes == 4
|
16 | 20 | @test collect(edges(g)) |> sort == collect(zip(s, t)) |> sort
|
|
21 | 25 | @test s1 == s
|
22 | 26 | @test t1 == t
|
23 | 27 |
|
24 |
| - # adjacency |
25 |
| - @test adjacency_matrix(g) == adj_mat |
26 |
| - @test adjacency_matrix(g; dir=:in) == adj_mat |
27 |
| - @test adjacency_matrix(g; dir=:out) == adj_mat |
28 | 28 | @test sort.(adjacency_list(g; dir=:in)) == adj_list_in
|
29 | 29 | @test sort.(adjacency_list(g; dir=:out)) == adj_list_out
|
30 | 30 |
|
| 31 | + @testset "adjacency_matrix" begin |
| 32 | + @test adjacency_matrix(g) == adj_mat |
| 33 | + @test adjacency_matrix(g; dir=:in) == adj_mat |
| 34 | + @test adjacency_matrix(g; dir=:out) == adj_mat |
| 35 | + |
| 36 | + if TEST_GPU |
| 37 | + # See https://github.com/JuliaGPU/CUDA.jl/pull/1093 |
| 38 | + mat_gpu = adjacency_matrix(g_gpu) |
| 39 | + @test mat_gpu isa ACUMatrix{Int} |
| 40 | + @test Array(mat_gpu) == adj_mat |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + @testset "normalized_laplacian" begin |
| 45 | + mat = normalized_laplacian(g) |
| 46 | + if TEST_GPU |
| 47 | + mat_gpu = normalized_laplacian(g_gpu) |
| 48 | + @test mat_gpu isa ACUMatrix{Float32} |
| 49 | + @test Array(mat_gpu) == mat |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + |
| 54 | + @testset "scaled_laplacian" begin |
| 55 | + if TEST_GPU |
| 56 | + @test_broken begin |
| 57 | + mat = scaled_laplacian(g) |
| 58 | + mat_gpu = scaled_laplacian(g_gpu) |
| 59 | + @test mat_gpu isa ACUMatrix{Float32} |
| 60 | + @test Array(mat_gpu) == mat |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + |
31 | 65 | @testset "constructors" begin
|
32 |
| - g = GNNGraph(adj_mat; graph_type=GRAPH_T) |
33 | 66 | adjacency_matrix(g; dir=:out) == adj_mat
|
34 | 67 | adjacency_matrix(g; dir=:in) == adj_mat
|
35 | 68 | end
|
36 | 69 |
|
37 | 70 | @testset "degree" begin
|
38 |
| - g = GNNGraph(adj_mat; graph_type=GRAPH_T) |
39 | 71 | @test degree(g, dir=:out) == vec(sum(adj_mat, dims=2))
|
40 | 72 | @test degree(g, dir=:in) == vec(sum(adj_mat, dims=1))
|
| 73 | + |
| 74 | + if TEST_GPU |
| 75 | + d = degree(g) |
| 76 | + d_gpu = degree(g_gpu) |
| 77 | + @test d_gpu isa CuVector |
| 78 | + @test Array(d_gpu) == d |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + if TEST_GPU |
| 83 | + @testset "functor" begin |
| 84 | + s_cpu, t_cpu = edge_index(g) |
| 85 | + s_gpu, t_gpu = edge_index(g_gpu) |
| 86 | + @test s_gpu isa CuVector{Int} |
| 87 | + @test Array(s_gpu) == s_cpu |
| 88 | + @test t_gpu isa CuVector{Int} |
| 89 | + @test Array(t_gpu) == t_cpu |
| 90 | + end |
41 | 91 | end
|
42 | 92 | end
|
43 | 93 |
|
|
59 | 109 |
|
60 | 110 | # core functionality
|
61 | 111 | g = GNNGraph(s, t; graph_type=GRAPH_T)
|
| 112 | + if TEST_GPU |
| 113 | + g_gpu = g |> gpu |
| 114 | + end |
| 115 | + |
62 | 116 | @test g.num_edges == 4
|
63 | 117 | @test g.num_nodes == 4
|
64 | 118 | @test collect(edges(g)) |> sort == collect(zip(s, t)) |> sort
|
|
78 | 132 | @test adjacency_list(g, dir=:in) == adj_list_in
|
79 | 133 |
|
80 | 134 | @testset "degree" begin
|
81 |
| - g = GNNGraph(adj_mat_out; graph_type=GRAPH_T) |
82 | 135 | @test degree(g, dir=:out) == vec(sum(adj_mat_out, dims=2))
|
83 | 136 | @test degree(g, dir=:in) == vec(sum(adj_mat_out, dims=1))
|
84 | 137 | end
|
|
221 | 274 | @test first(d) == getgraph(g, 1:2)
|
222 | 275 | end
|
223 | 276 | end
|
| 277 | + |
| 278 | + |
0 commit comments