Skip to content

Commit

Permalink
conver more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Dec 27, 2024
1 parent 15ea38b commit b3d528b
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 449 deletions.
20 changes: 0 additions & 20 deletions GNNGraphs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,15 +27,13 @@ GNNGraphsCUDAExt = "CUDA"
GNNGraphsSimpleWeightedGraphsExt = "SimpleWeightedGraphs"

[compat]
Adapt = "4"
CUDA = "5"
ChainRulesCore = "1"
Functors = "0.5"
Graphs = "1.4"
KrylovKit = "0.8"
LinearAlgebra = "1"
MLDataDevices = "1.0"
MLDatasets = "0.7"
MLUtils = "0.4"
NNlib = "0.9"
NearestNeighbors = "0.4"
Expand All @@ -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"]
10 changes: 10 additions & 0 deletions GNNGraphs/test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 12 additions & 13 deletions GNNGraphs/test/chainrules.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
@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)
end[1]

@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
36 changes: 20 additions & 16 deletions GNNGraphs/test/convert.jl
Original file line number Diff line number Diff line change
@@ -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
34 changes: 18 additions & 16 deletions GNNGraphs/test/datastore.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion GNNGraphs/test/ext/SimpleWeightedGraphs.jl
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Loading

0 comments on commit b3d528b

Please sign in to comment.