Skip to content

Commit 59c8a7f

Browse files
reorg tests
1 parent 1a31606 commit 59c8a7f

File tree

3 files changed

+64
-62
lines changed

3 files changed

+64
-62
lines changed

test/cuda/gnngraph.jl

Lines changed: 0 additions & 50 deletions
This file was deleted.

test/gnngraph.jl

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
# core functionality
1313
g = GNNGraph(s, t; graph_type=GRAPH_T)
14+
if TEST_GPU
15+
g_gpu = g |> gpu
16+
end
17+
1418
@test g.num_edges == 8
1519
@test g.num_nodes == 4
1620
@test collect(edges(g)) |> sort == collect(zip(s, t)) |> sort
@@ -21,23 +25,69 @@
2125
@test s1 == s
2226
@test t1 == t
2327

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
2828
@test sort.(adjacency_list(g; dir=:in)) == adj_list_in
2929
@test sort.(adjacency_list(g; dir=:out)) == adj_list_out
3030

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+
3165
@testset "constructors" begin
32-
g = GNNGraph(adj_mat; graph_type=GRAPH_T)
3366
adjacency_matrix(g; dir=:out) == adj_mat
3467
adjacency_matrix(g; dir=:in) == adj_mat
3568
end
3669

3770
@testset "degree" begin
38-
g = GNNGraph(adj_mat; graph_type=GRAPH_T)
3971
@test degree(g, dir=:out) == vec(sum(adj_mat, dims=2))
4072
@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
4191
end
4292
end
4393

@@ -59,6 +109,10 @@
59109

60110
# core functionality
61111
g = GNNGraph(s, t; graph_type=GRAPH_T)
112+
if TEST_GPU
113+
g_gpu = g |> gpu
114+
end
115+
62116
@test g.num_edges == 4
63117
@test g.num_nodes == 4
64118
@test collect(edges(g)) |> sort == collect(zip(s, t)) |> sort
@@ -78,7 +132,6 @@
78132
@test adjacency_list(g, dir=:in) == adj_list_in
79133

80134
@testset "degree" begin
81-
g = GNNGraph(adj_mat_out; graph_type=GRAPH_T)
82135
@test degree(g, dir=:out) == vec(sum(adj_mat_out, dims=2))
83136
@test degree(g, dir=:in) == vec(sum(adj_mat_out, dims=1))
84137
end
@@ -221,3 +274,5 @@
221274
@test first(d) == getgraph(g, 1:2)
222275
end
223276
end
277+
278+

test/runtests.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ using Test
1111
using MLDatasets
1212
CUDA.allowscalar(false)
1313

14+
const ACUMatrix{T} = Union{CuMatrix{T}, CUDA.CUSPARSE.CuSparseMatrix{T}}
15+
1416
ENV["DATADEPS_ALWAYS_ACCEPT"] = true # for MLDatasets
1517

1618
include("test_utils.jl")
@@ -26,17 +28,12 @@ tests = [
2628

2729
!CUDA.functional() && @warn("CUDA unavailable, not testing GPU support")
2830

29-
# Testing all graph types. :sparse is a bit broken at the moment
3031
@testset "GraphNeuralNetworks: graph format $graph_type" for graph_type in (:coo,:sparse,:dense)
3132

3233
global GRAPH_T = graph_type
3334
global TEST_GPU = CUDA.functional()# && GRAPH_T != :sparse
3435

3536
for t in tests
3637
include("$t.jl")
37-
38-
if TEST_GPU && isfile("cuda/$t.jl")
39-
include("cuda/$t.jl")
40-
end
4138
end
4239
end

0 commit comments

Comments
 (0)