From b3d528bd44794d18efdb3cf46b7aae4a2a9bf32a Mon Sep 17 00:00:00 2001 From: Carlo Lucibello Date: Fri, 27 Dec 2024 12:11:10 +0100 Subject: [PATCH] conver more tests --- GNNGraphs/Project.toml | 20 - GNNGraphs/test/Project.toml | 10 + GNNGraphs/test/chainrules.jl | 25 +- GNNGraphs/test/convert.jl | 36 +- GNNGraphs/test/datastore.jl | 34 +- GNNGraphs/test/ext/SimpleWeightedGraphs.jl | 3 +- GNNGraphs/test/generate.jl | 146 ++--- GNNGraphs/test/gnngraph.jl | 619 +++++++++++---------- GNNGraphs/test/runtests.jl | 14 +- GNNGraphs/test/test_module.jl | 35 +- GNNGraphs/test/transform.jl | 31 +- 11 files changed, 524 insertions(+), 449 deletions(-) diff --git a/GNNGraphs/Project.toml b/GNNGraphs/Project.toml index 0db318a93..7358419ed 100644 --- a/GNNGraphs/Project.toml +++ b/GNNGraphs/Project.toml @@ -4,7 +4,6 @@ authors = ["Carlo Lucibello and contributors"] version = "1.4.1" [deps] -Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" @@ -28,7 +27,6 @@ GNNGraphsCUDAExt = "CUDA" GNNGraphsSimpleWeightedGraphsExt = "SimpleWeightedGraphs" [compat] -Adapt = "4" CUDA = "5" ChainRulesCore = "1" Functors = "0.5" @@ -36,7 +34,6 @@ Graphs = "1.4" KrylovKit = "0.8" LinearAlgebra = "1" MLDataDevices = "1.0" -MLDatasets = "0.7" MLUtils = "0.4" NNlib = "0.9" NearestNeighbors = "0.4" @@ -45,21 +42,4 @@ SimpleWeightedGraphs = "1.4.0" SparseArrays = "1" Statistics = "1" StatsBase = "0.34" -cuDNN = "1" julia = "1.10" - -[extras] -Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" -CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" -ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a" -DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" -InlineStrings = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48" -MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458" -SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" -cuDNN = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd" - -[targets] -test = ["Test", "Adapt", "DataFrames", "InlineStrings", "SimpleWeightedGraphs", "Zygote", "FiniteDifferences", "ChainRulesTestUtils", "MLDatasets", "CUDA", "cuDNN"] diff --git a/GNNGraphs/test/Project.toml b/GNNGraphs/test/Project.toml index befb4a1e6..7e543524c 100644 --- a/GNNGraphs/test/Project.toml +++ b/GNNGraphs/test/Project.toml @@ -1,11 +1,21 @@ [deps] FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000" +Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196" GNNGraphs = "aed8fd31-079b-4b5a-b342-a13352159b8c" +GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +MLDataDevices = "7e8f7934-dd98-4c1a-8fe8-92b47a384d40" MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" +SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe" +Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" + +[compat] +GPUArraysCore = "0.1" diff --git a/GNNGraphs/test/chainrules.jl b/GNNGraphs/test/chainrules.jl index f0df6b6ca..42898d172 100644 --- a/GNNGraphs/test/chainrules.jl +++ b/GNNGraphs/test/chainrules.jl @@ -1,4 +1,5 @@ -@testset "dict constructor" begin +@testitem "dict constructor" setup=[GraphsTestModule] begin + using .GraphsTestModule grad = gradient(1.) do x d = Dict([:x => x, :y => 5]...) return sum(d[:x].^2) @@ -6,19 +7,17 @@ @test grad == 2 - ## BROKEN Constructors - # grad = gradient(1.) do x - # d = Dict([(:x => x), (:y => 5)]) - # return sum(d[:x].^2) - # end[1] - - # @test grad == 2 + grad = gradient(1.) do x + d = Dict([:x => x, :y => 5]) + return sum(d[:x].^2) + end[1] + @test grad == 2 - # grad = gradient(1.) do x - # d = Dict([(:x => x), (:y => 5)]) - # return sum(d[:x].^2) - # end[1] + grad = gradient(1.) do x + d = Dict(:x => x, :y => 5) + return sum(d[:x].^2) + end[1] - # @test grad == 2 + @test grad == 2 end diff --git a/GNNGraphs/test/convert.jl b/GNNGraphs/test/convert.jl index 898a8d771..6f4911577 100644 --- a/GNNGraphs/test/convert.jl +++ b/GNNGraphs/test/convert.jl @@ -1,20 +1,24 @@ -if TEST_GPU - @testset "to_coo(dense) on gpu" begin - get_st(A) = GNNGraphs.to_coo(A)[1][1:2] - get_val(A) = GNNGraphs.to_coo(A)[1][3] +@testitem "to_coo(dense) on gpu" setup=[GraphsTestModule] tags=[:gpu] begin + using .GraphsTestModule + get_st(A) = GNNGraphs.to_coo(A)[1][1:2] + get_val(A) = GNNGraphs.to_coo(A)[1][3] + gpu = gpu_device(force=true) + A = gpu([0 2 2; 2.0 0 2; 2 2 0]) - A = cu([0 2 2; 2.0 0 2; 2 2 0]) + y = get_val(A) + @test y isa AbstractVector{Float32} + @test get_device(y) == get_device(A) + @test Array(y) ≈ [2, 2, 2, 2, 2, 2] - y = get_val(A) - @test y isa CuVector{Float32} - @test Array(y) ≈ [2, 2, 2, 2, 2, 2] + s, t = get_st(A) + @test s isa AbstractVector{<:Integer} + @test t isa AbstractVector{<:Integer} + @test get_device(s) == get_device(A) + @test get_device(t) == get_device(A) + @test Array(s) == [2, 3, 1, 3, 1, 2] + @test Array(t) == [1, 1, 2, 2, 3, 3] - s, t = get_st(A) - @test s isa CuVector{<:Integer} - @test t isa CuVector{<:Integer} - @test Array(s) == [2, 3, 1, 3, 1, 2] - @test Array(t) == [1, 1, 2, 2, 3, 3] - - @test gradient(A -> sum(get_val(A)), A)[1] isa CuMatrix{Float32} - end + grad = gradient(A -> sum(get_val(A)), A)[1] + @test grad isa AbstractMatrix{Float32} + @test get_device(grad) == get_device(A) end diff --git a/GNNGraphs/test/datastore.jl b/GNNGraphs/test/datastore.jl index 404136bdf..dcd3b42ad 100644 --- a/GNNGraphs/test/datastore.jl +++ b/GNNGraphs/test/datastore.jl @@ -1,5 +1,5 @@ -@testset "constructor" begin +@testitem "constructor" begin @test_throws AssertionError DataStore(10, (:x => rand(10), :y => rand(2, 4))) @testset "keyword args" begin @@ -13,7 +13,7 @@ end end -@testset "getproperty / setproperty!" begin +@testitem "getproperty / setproperty!" begin x = rand(10) ds = DataStore(10, (:x => x, :y => rand(2, 10))) @test ds.x == ds[:x] == x @@ -25,14 +25,14 @@ end @test fill(DataStore(), 3) isa Vector end -@testset "setindex!" begin +@testitem "setindex!" begin ds = DataStore(10) x = rand(10) @test (ds[:x] = x) == x # Tests setindex! @test ds.x == ds[:x] == x end -@testset "map" begin +@testitem "map" begin ds = DataStore(10, (:x => rand(10), :y => rand(2, 10))) ds2 = map(x -> x .+ 1, ds) @test ds2.x == ds.x .+ 1 @@ -41,33 +41,34 @@ end @test_throws AssertionError ds2=map(x -> [x; x], ds) end -@testset "getdata / getn" begin +@testitem "getdata / getn" begin ds = DataStore(10, (:x => rand(10), :y => rand(2, 10))) - @test getdata(ds) == getfield(ds, :_data) + @test GNNGraphs.getdata(ds) == getfield(ds, :_data) @test_throws KeyError ds.data - @test getn(ds) == getfield(ds, :_n) + @test GNNGraphs.getn(ds) == getfield(ds, :_n) @test_throws KeyError ds.n end -@testset "cat empty" begin +@testitem "cat empty" begin ds1 = DataStore(2, (:x => rand(2))) ds2 = DataStore(1, (:x => rand(1))) dsempty = DataStore(0, (:x => rand(0))) ds = GNNGraphs.cat_features(ds1, ds2) - @test getn(ds) == 3 + @test GNNGraphs.getn(ds) == 3 ds = GNNGraphs.cat_features(ds1, dsempty) - @test getn(ds) == 2 + @test GNNGraphs.getn(ds) == 2 # issue #280 g = GNNGraph([1], [2]) h = add_edges(g, Int[], Int[]) # adds no edges - @test getn(g.edata) == 1 - @test getn(h.edata) == 1 + @test GNNGraphs.getn(g.edata) == 1 + @test GNNGraphs.getn(h.edata) == 1 end -@testset "gradient" begin +@testitem "gradient" setup=[GraphsTestModule] begin + using .GraphsTestModule ds = DataStore(10, (:x => rand(10), :y => rand(2, 10))) f1(ds) = sum(ds.x) @@ -80,11 +81,12 @@ end @test grad == exp.(x) end -@testset "functor" begin +@testitem "functor" begin + using Functors ds = DataStore(10, (:x => zeros(10), :y => ones(2, 10))) p, re = Functors.functor(ds) - @test p[1] === getn(ds) - @test p[2] === getdata(ds) + @test p[1] === GNNGraphs.getn(ds) + @test p[2] === GNNGraphs.getdata(ds) @test ds == re(p) ds2 = Functors.fmap(ds) do x diff --git a/GNNGraphs/test/ext/SimpleWeightedGraphs.jl b/GNNGraphs/test/ext/SimpleWeightedGraphs.jl index 254498999..7271ad9ca 100644 --- a/GNNGraphs/test/ext/SimpleWeightedGraphs.jl +++ b/GNNGraphs/test/ext/SimpleWeightedGraphs.jl @@ -1,4 +1,5 @@ -@testset "simple_weighted_graph" begin +@testitem "simple_weighted_graph" begin + using SimpleWeightedGraphs srcs = [1, 2, 1] dsts = [2, 3, 3] wts = [0.5, 0.8, 2.0] diff --git a/GNNGraphs/test/generate.jl b/GNNGraphs/test/generate.jl index c26b651c3..63cea373e 100644 --- a/GNNGraphs/test/generate.jl +++ b/GNNGraphs/test/generate.jl @@ -1,86 +1,94 @@ -@testset "rand_graph" begin +@testitem "rand_graph" setup=[GraphsTestModule] begin + using .GraphsTestModule n, m = 10, 20 m2 = m ÷ 2 x = rand(3, n) e = rand(4, m2) + for GRAPH_T in GRAPH_TYPES + g = rand_graph(n, m, ndata = x, edata = e, graph_type = GRAPH_T) + @test g.num_nodes == n + @test g.num_edges == m + @test g.ndata.x === x + if GRAPH_T == :coo + s, t = edge_index(g) + @test s[1:m2] == t[(m2 + 1):end] + @test t[1:m2] == s[(m2 + 1):end] + @test g.edata.e[:, 1:m2] == e + @test g.edata.e[:, (m2 + 1):end] == e + end - g = rand_graph(n, m, ndata = x, edata = e, graph_type = GRAPH_T) - @test g.num_nodes == n - @test g.num_edges == m - @test g.ndata.x === x - if GRAPH_T == :coo - s, t = edge_index(g) - @test s[1:m2] == t[(m2 + 1):end] - @test t[1:m2] == s[(m2 + 1):end] - @test g.edata.e[:, 1:m2] == e - @test g.edata.e[:, (m2 + 1):end] == e - end - - rng = MersenneTwister(17) - g = rand_graph(rng, n, m, bidirected = false, graph_type = GRAPH_T) - @test g.num_nodes == n - @test g.num_edges == m + rng = MersenneTwister(17) + g = rand_graph(rng, n, m, bidirected = false, graph_type = GRAPH_T) + @test g.num_nodes == n + @test g.num_edges == m - rng = MersenneTwister(17) - g2 = rand_graph(rng, n, m, bidirected = false, graph_type = GRAPH_T) - @test edge_index(g2) == edge_index(g) + rng = MersenneTwister(17) + g2 = rand_graph(rng, n, m, bidirected = false, graph_type = GRAPH_T) + @test edge_index(g2) == edge_index(g) - ew = rand(m2) - rng = MersenneTwister(17) - g = rand_graph(rng, n, m, bidirected = true, graph_type = GRAPH_T, edge_weight = ew) - @test get_edge_weight(g) == [ew; ew] broken=(GRAPH_T != :coo) - - ew = rand(m) - rng = MersenneTwister(17) - g = rand_graph(n, m, bidirected = false, graph_type = GRAPH_T, edge_weight = ew) - @test get_edge_weight(g) == ew broken=(GRAPH_T != :coo) + ew = rand(m2) + rng = MersenneTwister(17) + g = rand_graph(rng, n, m, bidirected = true, graph_type = GRAPH_T, edge_weight = ew) + @test get_edge_weight(g) == [ew; ew] broken=(GRAPH_T != :coo) + + ew = rand(m) + rng = MersenneTwister(17) + g = rand_graph(n, m, bidirected = false, graph_type = GRAPH_T, edge_weight = ew) + @test get_edge_weight(g) == ew broken=(GRAPH_T != :coo) + end end -@testset "knn_graph" begin - n, k = 10, 3 - x = rand(3, n) - g = knn_graph(x, k; graph_type = GRAPH_T) - @test g.num_nodes == 10 - @test g.num_edges == n * k - @test degree(g, dir = :in) == fill(k, n) - @test has_self_loops(g) == false +@testitem "knn_graph" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + n, k = 10, 3 + x = rand(3, n) + g = knn_graph(x, k; graph_type = GRAPH_T) + @test g.num_nodes == 10 + @test g.num_edges == n * k + @test degree(g, dir = :in) == fill(k, n) + @test has_self_loops(g) == false - g = knn_graph(x, k; dir = :out, self_loops = true, graph_type = GRAPH_T) - @test g.num_nodes == 10 - @test g.num_edges == n * k - @test degree(g, dir = :out) == fill(k, n) - @test has_self_loops(g) == true + g = knn_graph(x, k; dir = :out, self_loops = true, graph_type = GRAPH_T) + @test g.num_nodes == 10 + @test g.num_edges == n * k + @test degree(g, dir = :out) == fill(k, n) + @test has_self_loops(g) == true - graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] - g = knn_graph(x, k; graph_indicator, graph_type = GRAPH_T) - @test g.num_graphs == 2 - s, t = edge_index(g) - ne = n * k ÷ 2 - @test all(1 .<= s[1:ne] .<= 5) - @test all(1 .<= t[1:ne] .<= 5) - @test all(6 .<= s[(ne + 1):end] .<= 10) - @test all(6 .<= t[(ne + 1):end] .<= 10) + graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] + g = knn_graph(x, k; graph_indicator, graph_type = GRAPH_T) + @test g.num_graphs == 2 + s, t = edge_index(g) + ne = n * k ÷ 2 + @test all(1 .<= s[1:ne] .<= 5) + @test all(1 .<= t[1:ne] .<= 5) + @test all(6 .<= s[(ne + 1):end] .<= 10) + @test all(6 .<= t[(ne + 1):end] .<= 10) + end end -@testset "radius_graph" begin - n, r = 10, 0.5 - x = rand(3, n) - g = radius_graph(x, r; graph_type = GRAPH_T) - @test g.num_nodes == 10 - @test has_self_loops(g) == false +@testitem "radius_graph" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + n, r = 10, 0.5 + x = rand(3, n) + g = radius_graph(x, r; graph_type = GRAPH_T) + @test g.num_nodes == 10 + @test has_self_loops(g) == false - g = radius_graph(x, r; dir = :out, self_loops = true, graph_type = GRAPH_T) - @test g.num_nodes == 10 - @test has_self_loops(g) == true + g = radius_graph(x, r; dir = :out, self_loops = true, graph_type = GRAPH_T) + @test g.num_nodes == 10 + @test has_self_loops(g) == true - graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] - g = radius_graph(x, r; graph_indicator, graph_type = GRAPH_T) - @test g.num_graphs == 2 - s, t = edge_index(g) - @test (s .> 5) == (t .> 5) + graph_indicator = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2] + g = radius_graph(x, r; graph_indicator, graph_type = GRAPH_T) + @test g.num_graphs == 2 + s, t = edge_index(g) + @test (s .> 5) == (t .> 5) + end end -@testset "rand_bipartite_heterograph" begin +@testitem "rand_bipartite_heterograph" begin g = rand_bipartite_heterograph((10, 15), (20, 20)) @test g.num_nodes == Dict(:A => 10, :B => 15) @test g.num_edges == Dict((:A, :to, :B) => 20, (:B, :to, :A) => 20) @@ -97,7 +105,8 @@ end @test !has_edge(g, (:B,:to,:A), 1, 1) end -@testset "rand_temporal_radius_graph" begin +@testitem "rand_temporal_radius_graph" begin + using Statistics number_nodes = 30 number_snapshots = 5 r = 0.1 @@ -110,7 +119,8 @@ end @test mean(mean(degree.(tg.snapshots)))<=mean(mean(degree.(tg2.snapshots))) end -@testset "rand_temporal_hyperbolic_graph" begin +@testitem "rand_temporal_hyperbolic_graph" begin + using Statistics @test GNNGraphs._hyperbolic_distance([1.0,1.0],[1.0,1.0];ζ=1)==0 @test GNNGraphs._hyperbolic_distance([0.23,0.11],[0.98,0.55];ζ=1) == GNNGraphs._hyperbolic_distance([0.98,0.55],[0.23,0.11];ζ=1) number_nodes = 30 diff --git a/GNNGraphs/test/gnngraph.jl b/GNNGraphs/test/gnngraph.jl index abe9518cb..e94ff22d0 100644 --- a/GNNGraphs/test/gnngraph.jl +++ b/GNNGraphs/test/gnngraph.jl @@ -1,132 +1,150 @@ # TODO test that the graph type is preserved # when constructing a GNNGraph from another -@testset "Constructor: adjacency matrix" begin - A = sprand(10, 10, 0.5) - sA, tA, vA = findnz(A) - - g = GNNGraph(A, graph_type = GRAPH_T) - s, t = edge_index(g) - v = get_edge_weight(g) - @test s == sA - @test t == tA - @test v == vA - - g = GNNGraph(Matrix(A), graph_type = GRAPH_T) - s, t = edge_index(g) - v = get_edge_weight(g) - @test s == sA - @test t == tA - @test v == vA - - g = GNNGraph([0 0 0 - 0 0 1 - 0 1 0], graph_type = GRAPH_T) - @test g.num_nodes == 3 - @test g.num_edges == 2 - - g = GNNGraph([0 1 0 - 1 0 0 - 0 0 0], graph_type = GRAPH_T) - @test g.num_nodes == 3 - @test g.num_edges == 2 -end - -@testset "Constructor: integer" begin - g = GNNGraph(10, graph_type = GRAPH_T) - @test g.num_nodes == 10 - @test g.num_edges == 0 - - g2 = rand_graph(10, 30, graph_type = GRAPH_T) - G = typeof(g2) - g = G(10) - @test g.num_nodes == 10 - @test g.num_edges == 0 - - g = GNNGraph(graph_type = GRAPH_T) - @test g.num_nodes == 0 +@testitem "Constructor: adjacency matrix" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + A = sprand(10, 10, 0.5) + sA, tA, vA = findnz(A) + + g = GNNGraph(A, graph_type = GRAPH_T) + s, t = edge_index(g) + v = get_edge_weight(g) + @test s == sA + @test t == tA + @test v == vA + + g = GNNGraph(Matrix(A), graph_type = GRAPH_T) + s, t = edge_index(g) + v = get_edge_weight(g) + @test s == sA + @test t == tA + @test v == vA + + g = GNNGraph([0 0 0 + 0 0 1 + 0 1 0], graph_type = GRAPH_T) + @test g.num_nodes == 3 + @test g.num_edges == 2 + + g = GNNGraph([0 1 0 + 1 0 0 + 0 0 0], graph_type = GRAPH_T) + @test g.num_nodes == 3 + @test g.num_edges == 2 + end end -@testset "symmetric graph" begin - s = [1, 1, 2, 2, 3, 3, 4, 4] - t = [2, 4, 1, 3, 2, 4, 1, 3] - adj_mat = [0 1 0 1 - 1 0 1 0 - 0 1 0 1 - 1 0 1 0] - adj_list_out = [[2, 4], [1, 3], [2, 4], [1, 3]] - adj_list_in = [[2, 4], [1, 3], [2, 4], [1, 3]] - - # core functionality - g = GNNGraph(s, t; graph_type = GRAPH_T) - if TEST_GPU - dev = CUDADevice() - g_gpu = g |> dev +@testitem "Constructor: integer" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g = GNNGraph(10, graph_type = GRAPH_T) + @test g.num_nodes == 10 + @test g.num_edges == 0 + + g2 = rand_graph(10, 30, graph_type = GRAPH_T) + G = typeof(g2) + g = G(10) + @test g.num_nodes == 10 + @test g.num_edges == 0 + + g = GNNGraph(graph_type = GRAPH_T) + @test g.num_nodes == 0 end +end - @test g.num_edges == 8 - @test g.num_nodes == 4 - @test nv(g) == g.num_nodes - @test ne(g) == g.num_edges - @test Tuple.(collect(edges(g))) |> sort == collect(zip(s, t)) |> sort - @test sort(outneighbors(g, 1)) == [2, 4] - @test sort(inneighbors(g, 1)) == [2, 4] - @test is_directed(g) == true - s1, t1 = sort_edge_index(edge_index(g)) - @test s1 == s - @test t1 == t - @test vertices(g) == 1:(g.num_nodes) - - @test sort.(adjacency_list(g; dir = :in)) == adj_list_in - @test sort.(adjacency_list(g; dir = :out)) == adj_list_out - - @testset "adjacency_matrix" begin - @test adjacency_matrix(g) == adj_mat - @test adjacency_matrix(g; dir = :in) == adj_mat - @test adjacency_matrix(g; dir = :out) == adj_mat - +@testitem "symmetric graph" setup=[GraphsTestModule] tags=[:gpu] begin + using .GraphsTestModule + dev = gpu_device() + TEST_GPU = dev != cpu_device() + for GRAPH_T in GRAPH_TYPES + s = [1, 1, 2, 2, 3, 3, 4, 4] + t = [2, 4, 1, 3, 2, 4, 1, 3] + adj_mat = [0 1 0 1 + 1 0 1 0 + 0 1 0 1 + 1 0 1 0] + adj_list_out = [[2, 4], [1, 3], [2, 4], [1, 3]] + adj_list_in = [[2, 4], [1, 3], [2, 4], [1, 3]] + + # core functionality + g = GNNGraph(s, t; graph_type = GRAPH_T) if TEST_GPU - # See https://github.com/JuliaGPU/CUDA.jl/pull/1093 - mat_gpu = adjacency_matrix(g_gpu) - @test mat_gpu isa ACUMatrix{Int} - @test Array(mat_gpu) == adj_mat + g_gpu = g |> dev end - end - @testset "normalized_laplacian" begin - mat = normalized_laplacian(g) - if TEST_GPU - mat_gpu = normalized_laplacian(g_gpu) - @test mat_gpu isa ACUMatrix{Float32} - @test Array(mat_gpu) == mat + @test g.num_edges == 8 + @test g.num_nodes == 4 + @test nv(g) == g.num_nodes + @test ne(g) == g.num_edges + @test Tuple.(collect(edges(g))) |> sort == collect(zip(s, t)) |> sort + @test sort(outneighbors(g, 1)) == [2, 4] + @test sort(inneighbors(g, 1)) == [2, 4] + @test is_directed(g) == true + s1, t1 = sort_edge_index(edge_index(g)) + @test s1 == s + @test t1 == t + @test vertices(g) == 1:(g.num_nodes) + + @test sort.(adjacency_list(g; dir = :in)) == adj_list_in + @test sort.(adjacency_list(g; dir = :out)) == adj_list_out + + @testset "adjacency_matrix" begin + @test adjacency_matrix(g) == adj_mat + @test adjacency_matrix(g; dir = :in) == adj_mat + @test adjacency_matrix(g; dir = :out) == adj_mat + + if TEST_GPU && !(dev isa MetalDevice) + # See https://github.com/JuliaGPU/CUDA.jl/pull/1093 + mat_gpu = adjacency_matrix(g_gpu) + @test mat_gpu isa AbstractMatrix{Int} + @test get_device(mat_gpu) == dev + @test Array(mat_gpu) == adj_mat + end end - end - @testset "scaled_laplacian" begin if TEST_GPU - mat = scaled_laplacian(g) - mat_gpu = scaled_laplacian(g_gpu) - @test mat_gpu isa ACUMatrix{Float32} - @test Array(mat_gpu) ≈ mat - end end + @testset "normalized_laplacian" begin + mat = normalized_laplacian(g) + if TEST_GPU && !(dev isa MetalDevice) + mat_gpu = normalized_laplacian(g_gpu) + @test mat_gpu isa AbstractMatrix{Float32} + @test get_device(mat_gpu) == dev + @test Array(mat_gpu) == mat + end + end - @testset "constructors" begin - adjacency_matrix(g; dir = :out) == adj_mat - adjacency_matrix(g; dir = :in) == adj_mat - end + @testset "scaled_laplacian" begin + if TEST_GPU && !(dev isa MetalDevice) + mat = scaled_laplacian(g) + mat_gpu = scaled_laplacian(g_gpu) + @test mat_gpu isa AbstractMatrix{Float32} + @test get_device(mat_gpu) == dev + @test Array(mat_gpu) ≈ mat + end + end + + @testset "constructors" begin + adjacency_matrix(g; dir = :out) == adj_mat + adjacency_matrix(g; dir = :in) == adj_mat + end - if TEST_GPU - @testset "functor" begin - s_cpu, t_cpu = edge_index(g) - s_gpu, t_gpu = edge_index(g_gpu) - @test s_gpu isa CuVector{Int} - @test Array(s_gpu) == s_cpu - @test t_gpu isa CuVector{Int} - @test Array(t_gpu) == t_cpu + if TEST_GPU + @testset "functor" begin + s_cpu, t_cpu = edge_index(g) + s_gpu, t_gpu = edge_index(g_gpu) + @test s_gpu isa AbstractVector{Int} + @test get_device(s_gpu) == dev + @test Array(s_gpu) == s_cpu + @test t_gpu isa AbstractVector{Int} + @test get_device(t_gpu) == dev + @test Array(t_gpu) == t_cpu + end end end end -@testset "asymmetric graph" begin +@testitem "asymmetric graph" setup=[GraphsTestModule] begin + using .GraphsTestModule s = [1, 2, 3, 4] t = [2, 3, 4, 1] adj_mat_out = [0 1 0 0 @@ -141,210 +159,231 @@ end 0 0 1 0] adj_list_in = [[4], [1], [2], [3]] - # core functionality - g = GNNGraph(s, t; graph_type = GRAPH_T) - if TEST_GPU - dev = CUDADevice() #TODO replace with `gpu_device()` - g_gpu = g |> dev + for GRAPH_T in GRAPH_TYPES + g = GNNGraph(s, t; graph_type = GRAPH_T) + + @test g.num_edges == 4 + @test g.num_nodes == 4 + @test length(edges(g)) == 4 + @test sort(outneighbors(g, 1)) == [2] + @test sort(inneighbors(g, 1)) == [4] + @test is_directed(g) == true + @test is_directed(typeof(g)) == true + s1, t1 = sort_edge_index(edge_index(g)) + @test s1 == s + @test t1 == t + + # adjacency + @test adjacency_matrix(g) == adj_mat_out + @test adjacency_list(g) == adj_list_out + @test adjacency_matrix(g, dir = :out) == adj_mat_out + @test adjacency_list(g, dir = :out) == adj_list_out + @test adjacency_matrix(g, dir = :in) == adj_mat_in + @test adjacency_list(g, dir = :in) == adj_list_in end - - @test g.num_edges == 4 - @test g.num_nodes == 4 - @test length(edges(g)) == 4 - @test sort(outneighbors(g, 1)) == [2] - @test sort(inneighbors(g, 1)) == [4] - @test is_directed(g) == true - @test is_directed(typeof(g)) == true - s1, t1 = sort_edge_index(edge_index(g)) - @test s1 == s - @test t1 == t - - # adjacency - @test adjacency_matrix(g) == adj_mat_out - @test adjacency_list(g) == adj_list_out - @test adjacency_matrix(g, dir = :out) == adj_mat_out - @test adjacency_list(g, dir = :out) == adj_list_out - @test adjacency_matrix(g, dir = :in) == adj_mat_in - @test adjacency_list(g, dir = :in) == adj_list_in end -@testset "zero" begin - g = rand_graph(4, 6, graph_type = GRAPH_T) - G = typeof(g) - @test zero(G) == G(0) +@testitem "zero" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g = rand_graph(4, 6, graph_type = GRAPH_T) + G = typeof(g) + @test zero(G) == G(0) + end end -@testset "Graphs.jl constructor" begin - lg = random_regular_graph(10, 4) - @test !Graphs.is_directed(lg) - g = GNNGraph(lg) - @test g.num_edges == 2 * ne(lg) # g in undirected - @test Graphs.is_directed(g) - for e in Graphs.edges(lg) - i, j = src(e), dst(e) - @test has_edge(g, i, j) - @test has_edge(g, j, i) - end +@testitem "Graphs.jl constructor" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + lg = random_regular_graph(10, 4) + @test !Graphs.is_directed(lg) + g = GNNGraph(lg, graph_type = GRAPH_T) + @test g.num_edges == 2 * ne(lg) # g in undirected + @test Graphs.is_directed(g) + for e in Graphs.edges(lg) + i, j = src(e), dst(e) + @test has_edge(g, i, j) + @test has_edge(g, j, i) + end - @testset "SimpleGraph{Int32}" begin - g = GNNGraph(SimpleGraph{Int32}(6), graph_type = GRAPH_T) - @test g.num_nodes == 6 + @testset "SimpleGraph{Int32}" begin + g = GNNGraph(SimpleGraph{Int32}(6), graph_type = GRAPH_T) + @test g.num_nodes == 6 + end end end -@testset "Features" begin - g = GNNGraph(sprand(10, 10, 0.3), graph_type = GRAPH_T) - - # default names - X = rand(10, g.num_nodes) - E = rand(10, g.num_edges) - U = rand(10, g.num_graphs) - - g = GNNGraph(g, ndata = X, edata = E, gdata = U) - @test g.ndata.x === X - @test g.edata.e === E - @test g.gdata.u === U - @test g.x === g.ndata.x - @test g.e === g.edata.e - @test g.u === g.gdata.u - - # Check no args - g = GNNGraph(g) - @test g.ndata.x === X - @test g.edata.e === E - @test g.gdata.u === U - - # multiple features names - g = GNNGraph(g, ndata = (x2 = 2X, g.ndata...), edata = (e2 = 2E, g.edata...), - gdata = (u2 = 2U, g.gdata...)) - @test g.ndata.x === X - @test g.edata.e === E - @test g.gdata.u === U - @test g.ndata.x2 ≈ 2X - @test g.edata.e2 ≈ 2E - @test g.gdata.u2 ≈ 2U - @test g.x === g.ndata.x - @test g.e === g.edata.e - @test g.u === g.gdata.u - @test g.x2 === g.ndata.x2 - @test g.e2 === g.edata.e2 - @test g.u2 === g.gdata.u2 - - # Dimension checks - @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), edata = rand(29), - graph_type = GRAPH_T) - @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), edata = rand(2, 29), - graph_type = GRAPH_T) - @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), - edata = (; x = rand(30), y = rand(29)), - graph_type = GRAPH_T) - - # Copy features on reverse edge - e = rand(30) - g = GNNGraph(erdos_renyi(10, 30), edata = e, graph_type = GRAPH_T) - @test g.edata.e == [e; e] - - # non-array global - g = rand_graph(10, 30, gdata = "ciao", graph_type = GRAPH_T) - @test g.gdata.u == "ciao" - - # vectors stays vectors - g = rand_graph(10, 30, ndata = rand(10), - edata = rand(30), - gdata = (u = rand(2), z = rand(1), q = 1), - graph_type = GRAPH_T) - @test size(g.ndata.x) == (10,) - @test size(g.edata.e) == (30,) - @test size(g.gdata.u) == (2, 1) - @test size(g.gdata.z) == (1,) - @test g.gdata.q === 1 - - # Error for non-array ndata - @test_throws AssertionError rand_graph(10, 30, ndata = "ciao", graph_type = GRAPH_T) - @test_throws AssertionError rand_graph(10, 30, ndata = 1, graph_type = GRAPH_T) - - # Error for Ambiguous getproperty - g = rand_graph(10, 20, ndata = rand(2, 10), edata = (; x = rand(3, 20)), - graph_type = GRAPH_T) - @test size(g.ndata.x) == (2, 10) - @test size(g.edata.x) == (3, 20) - @test_throws ArgumentError g.x +@testitem "Features" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g = GNNGraph(sprand(10, 10, 0.3), graph_type = GRAPH_T) + + # default names + X = rand(10, g.num_nodes) + E = rand(10, g.num_edges) + U = rand(10, g.num_graphs) + + g = GNNGraph(g, ndata = X, edata = E, gdata = U) + @test g.ndata.x === X + @test g.edata.e === E + @test g.gdata.u === U + @test g.x === g.ndata.x + @test g.e === g.edata.e + @test g.u === g.gdata.u + + # Check no args + g = GNNGraph(g) + @test g.ndata.x === X + @test g.edata.e === E + @test g.gdata.u === U + + # multiple features names + g = GNNGraph(g, ndata = (x2 = 2X, g.ndata...), edata = (e2 = 2E, g.edata...), + gdata = (u2 = 2U, g.gdata...)) + @test g.ndata.x === X + @test g.edata.e === E + @test g.gdata.u === U + @test g.ndata.x2 ≈ 2X + @test g.edata.e2 ≈ 2E + @test g.gdata.u2 ≈ 2U + @test g.x === g.ndata.x + @test g.e === g.edata.e + @test g.u === g.gdata.u + @test g.x2 === g.ndata.x2 + @test g.e2 === g.edata.e2 + @test g.u2 === g.gdata.u2 + + # Dimension checks + @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), edata = rand(29), + graph_type = GRAPH_T) + @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), edata = rand(2, 29), + graph_type = GRAPH_T) + @test_throws AssertionError GNNGraph(erdos_renyi(10, 30), + edata = (; x = rand(30), y = rand(29)), + graph_type = GRAPH_T) + + # Copy features on reverse edge + e = rand(30) + g = GNNGraph(erdos_renyi(10, 30), edata = e, graph_type = GRAPH_T) + @test g.edata.e == [e; e] + + # non-array global + g = rand_graph(10, 30, gdata = "ciao", graph_type = GRAPH_T) + @test g.gdata.u == "ciao" + + # vectors stays vectors + g = rand_graph(10, 30, ndata = rand(10), + edata = rand(30), + gdata = (u = rand(2), z = rand(1), q = 1), + graph_type = GRAPH_T) + @test size(g.ndata.x) == (10,) + @test size(g.edata.e) == (30,) + @test size(g.gdata.u) == (2, 1) + @test size(g.gdata.z) == (1,) + @test g.gdata.q === 1 + + # Error for non-array ndata + @test_throws AssertionError rand_graph(10, 30, ndata = "ciao", graph_type = GRAPH_T) + @test_throws AssertionError rand_graph(10, 30, ndata = 1, graph_type = GRAPH_T) + + # Error for Ambiguous getproperty + g = rand_graph(10, 20, ndata = rand(2, 10), edata = (; x = rand(3, 20)), + graph_type = GRAPH_T) + @test size(g.ndata.x) == (2, 10) + @test size(g.edata.x) == (3, 20) + @test_throws ArgumentError g.x + end end -@testset "MLUtils and DataLoader compat" begin - n, m, num_graphs = 10, 30, 50 - X = rand(10, n) - E = rand(10, m) - U = rand(10, 1) - data = [rand_graph(n, m, ndata = X, edata = E, gdata = U, graph_type = GRAPH_T) - for _ in 1:num_graphs] - g = MLUtils.batch(data) - - @testset "batch then pass to dataloader" begin - @test MLUtils.getobs(g, 3) == getgraph(g, 3) - @test MLUtils.getobs(g, 3:5) == getgraph(g, 3:5) - @test MLUtils.numobs(g) == g.num_graphs - - d = MLUtils.DataLoader(g, batchsize = 2, shuffle = false) - @test first(d) == getgraph(g, 1:2) - end +@testitem "MLUtils and DataLoader compat" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + n, m, num_graphs = 10, 30, 50 + X = rand(10, n) + E = rand(10, m) + U = rand(10, 1) + data = [rand_graph(n, m, ndata = X, edata = E, gdata = U, graph_type = GRAPH_T) + for _ in 1:num_graphs] + g = MLUtils.batch(data) + + @testset "batch then pass to dataloader" begin + @test MLUtils.getobs(g, 3) == getgraph(g, 3) + @test MLUtils.getobs(g, 3:5) == getgraph(g, 3:5) + @test MLUtils.numobs(g) == g.num_graphs + + d = MLUtils.DataLoader(g, batchsize = 2, shuffle = false) + @test first(d) == getgraph(g, 1:2) + end - @testset "pass to dataloader and no automatic collation" begin - @test MLUtils.getobs(data, 3) == data[3] - @test MLUtils.getobs(data, 3:5) isa Vector{<:GNNGraph} - @test MLUtils.getobs(data, 3:5) == [data[3], data[4], data[5]] - @test MLUtils.numobs(data) == g.num_graphs + @testset "pass to dataloader and no automatic collation" begin + @test MLUtils.getobs(data, 3) == data[3] + @test MLUtils.getobs(data, 3:5) isa Vector{<:GNNGraph} + @test MLUtils.getobs(data, 3:5) == [data[3], data[4], data[5]] + @test MLUtils.numobs(data) == g.num_graphs - d = MLUtils.DataLoader(data, batchsize = 2, shuffle = false) - @test first(d) == [data[1], data[2]] + d = MLUtils.DataLoader(data, batchsize = 2, shuffle = false) + @test first(d) == [data[1], data[2]] + end end end -@testset "Graphs.jl integration" begin - g = GNNGraph(erdos_renyi(10, 20), graph_type = GRAPH_T) - @test g isa Graphs.AbstractGraph +@testitem "Graphs.jl integration" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g = GNNGraph(erdos_renyi(10, 20), graph_type = GRAPH_T) + @test g isa Graphs.AbstractGraph + end end -@testset "==" begin - g1 = rand_graph(5, 6, ndata = rand(5), edata = rand(6), graph_type = GRAPH_T) - @test g1 == g1 - @test g1 == deepcopy(g1) - @test g1 !== deepcopy(g1) - - g2 = GNNGraph(g1, graph_type = GRAPH_T) - @test g1 == g2 - @test g1 === g2 # this is true since GNNGraph is immutable - - g2 = GNNGraph(g1, ndata = rand(5), graph_type = GRAPH_T) - @test g1 != g2 - @test g1 !== g2 - - g2 = GNNGraph(g1, edata = rand(6), graph_type = GRAPH_T) - @test g1 != g2 - @test g1 !== g2 +@testitem "==" setup = [GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g1 = rand_graph(5, 6, ndata = rand(5), edata = rand(6), graph_type = GRAPH_T) + @test g1 == g1 + @test g1 == deepcopy(g1) + @test g1 !== deepcopy(g1) + + g2 = GNNGraph(g1, graph_type = GRAPH_T) + @test g1 == g2 + @test g1 === g2 # this is true since GNNGraph is immutable + + g2 = GNNGraph(g1, ndata = rand(5), graph_type = GRAPH_T) + @test g1 != g2 + @test g1 !== g2 + + g2 = GNNGraph(g1, edata = rand(6), graph_type = GRAPH_T) + @test g1 != g2 + @test g1 !== g2 + end end -@testset "hash" begin - g1 = rand_graph(5, 6, ndata = rand(5), edata = rand(6), graph_type = GRAPH_T) - @test hash(g1) == hash(g1) - @test hash(g1) == hash(deepcopy(g1)) - @test hash(g1) == hash(GNNGraph(g1, ndata = g1.ndata, graph_type = GRAPH_T)) - @test hash(g1) == hash(GNNGraph(g1, ndata = g1.ndata, graph_type = GRAPH_T)) - @test hash(g1) != hash(GNNGraph(g1, ndata = rand(5), graph_type = GRAPH_T)) - @test hash(g1) != hash(GNNGraph(g1, edata = rand(6), graph_type = GRAPH_T)) +@testitem "hash" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g1 = rand_graph(5, 6, ndata = rand(5), edata = rand(6), graph_type = GRAPH_T) + @test hash(g1) == hash(g1) + @test hash(g1) == hash(deepcopy(g1)) + @test hash(g1) == hash(GNNGraph(g1, ndata = g1.ndata, graph_type = GRAPH_T)) + @test hash(g1) == hash(GNNGraph(g1, ndata = g1.ndata, graph_type = GRAPH_T)) + @test hash(g1) != hash(GNNGraph(g1, ndata = rand(5), graph_type = GRAPH_T)) + @test hash(g1) != hash(GNNGraph(g1, edata = rand(6), graph_type = GRAPH_T)) + end end -@testset "copy" begin - g1 = rand_graph(10, 4, ndata = rand(2, 10), graph_type = GRAPH_T) - g2 = copy(g1) - @test g1 === g2 # shallow copies are identical for immutable objects +@testitem "copy" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + g1 = rand_graph(10, 4, ndata = rand(2, 10), graph_type = GRAPH_T) + g2 = copy(g1) + @test g1 === g2 # shallow copies are identical for immutable objects - g2 = copy(g1, deep = true) - @test g1 == g2 - @test g1 !== g2 + g2 = copy(g1, deep = true) + @test g1 == g2 + @test g1 !== g2 + end end -@testset "show" begin +@testitem "show" begin # no throw when global data is not an array g = rand_graph(10, 20, gdata = "ciao") @test sprint(show, g) == "GNNGraph(10, 20) with u: string(4) data" diff --git a/GNNGraphs/test/runtests.jl b/GNNGraphs/test/runtests.jl index 455c0be3a..1b340c09a 100644 --- a/GNNGraphs/test/runtests.jl +++ b/GNNGraphs/test/runtests.jl @@ -22,22 +22,22 @@ const ACUMatrix{T} = Union{CuMatrix{T}, CUDA.CUSPARSE.CuSparseMatrix{T}} ENV["DATADEPS_ALWAYS_ACCEPT"] = true # for MLDatasets -include("test_utils.jl") +# include("test_utils.jl") tests = [ - "chainrules", - "datastore", - "gnngraph", - "convert", + # "chainrules", + # "datastore", + # "gnngraph", + # "convert", # "transform", "operators", - "generate", + # "generate", "query", "sampling", "gnnheterograph", "temporalsnapshotsgnngraph", "mldatasets", - "ext/SimpleWeightedGraphs", + # "ext/SimpleWeightedGraphs", "samplers" ] diff --git a/GNNGraphs/test/test_module.jl b/GNNGraphs/test/test_module.jl index 4c44757b9..780d9ae91 100644 --- a/GNNGraphs/test/test_module.jl +++ b/GNNGraphs/test/test_module.jl @@ -1,18 +1,45 @@ @testmodule GraphsTestModule begin + +using Pkg + +## Uncomment below to change the default test settings +# ENV["GNN_TEST_CUDA"] = "true" +# ENV["GNN_TEST_AMDGPU"] = "true" +ENV["GNN_TEST_Metal"] = "true" + +to_test(backend) = get(ENV, "GNN_TEST_$(backend)", "false") == "true" +has_dependecies(pkgs) = all(pkg -> haskey(Pkg.project().dependencies, pkg), pkgs) +deps_dict = Dict(:CUDA => ["CUDA", "cuDNN"], :AMDGPU => ["AMDGPU"], :Metal => ["Metal"]) + +for (backend, deps) in deps_dict + if to_test(backend) + if !has_dependecies(deps) + Pkg.add(deps) + end + @eval using $backend + if backend == :CUDA + @eval using cuDNN + end + @eval $backend.allowscalar(false) + end +end + using FiniteDifferences: FiniteDifferences using Reexport: @reexport using MLUtils: MLUtils - +using Zygote: gradient +using SparseArrays: sprand, findnz +@reexport using MLDataDevices @reexport using Random @reexport using Statistics @reexport using LinearAlgebra @reexport using GNNGraphs @reexport using Test @reexport using Graphs -export MLUtils +export MLUtils, gradient, + sprand, findnz -export ngradient -export GRAPH_TYPES +export ngradient, GRAPH_TYPES # Using this until https://github.com/JuliaDiff/FiniteDifferences.jl/issues/188 is fixed diff --git a/GNNGraphs/test/transform.jl b/GNNGraphs/test/transform.jl index a8fe13001..275efe006 100644 --- a/GNNGraphs/test/transform.jl +++ b/GNNGraphs/test/transform.jl @@ -692,22 +692,25 @@ end end end -@testset "ppr_diffusion" begin - if GRAPH_T == :coo - s = [1, 1, 2, 3] - t = [2, 3, 4, 5] - eweights = [0.1, 0.2, 0.3, 0.4] +@testitem "ppr_diffusion" setup=[GraphsTestModule] begin + using .GraphsTestModule + for GRAPH_T in GRAPH_TYPES + if GRAPH_T == :coo + s = [1, 1, 2, 3] + t = [2, 3, 4, 5] + eweights = [0.1, 0.2, 0.3, 0.4] - g = GNNGraph(s, t, eweights) + g = GNNGraph(s, t, eweights) - g_new = ppr_diffusion(g) - w_new = get_edge_weight(g_new) + g_new = ppr_diffusion(g) + w_new = get_edge_weight(g_new) - check_ew = Float32[0.012749999 - 0.025499998 - 0.038249996 - 0.050999995] + check_ew = Float32[0.012749999 + 0.025499998 + 0.038249996 + 0.050999995] - @test w_new ≈ check_ew + @test w_new ≈ check_ew + end end -end \ No newline at end of file +end