Skip to content

Commit

Permalink
Better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Jan 17, 2024
1 parent 7c1264f commit 9ccbe30
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays", "PolyesterForwardDiff"]
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays"]
3 changes: 3 additions & 0 deletions test/1.9specific/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
2 changes: 0 additions & 2 deletions test/allocs/Project.toml

This file was deleted.

2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if GROUP == "Core" || GROUP == "All"
end

if GROUP == "InterfaceI" || GROUP == "All"
VERSION v"1.9" && activate_env("allocs")
VERSION v"1.9" && activate_env("1.9specific")
@time @safetestset "Jac Vecs and Hes Vecs" begin
include("test_jaches_products.jl")
end
Expand Down
62 changes: 38 additions & 24 deletions test/test_sparse_jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
## Sparse Jacobian tests
using SparseDiffTools, PolyesterForwardDiff, Symbolics, ForwardDiff, LinearAlgebra,
SparseArrays, Zygote, Enzyme, Test, StaticArrays
using SparseDiffTools,
Symbolics, ForwardDiff, LinearAlgebra, SparseArrays, Zygote, Enzyme, Test, StaticArrays

@static if VERSION v"1.9"
using PolyesterForwardDiff
end

function __chunksize(::Union{AutoSparseForwardDiff{C}, AutoForwardDiff{C},
AutoSparsePolyesterForwardDiff{C}, AutoPolyesterForwardDiff{C}}) where {C}
return C
end

function __isinferrable(difftype)
return !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
difftype isa AutoSparsePolyesterForwardDiff ||
difftype isa AutoPolyesterForwardDiff) ||
(__chunksize(difftype) isa Int && __chunksize(difftype) > 0)
end

@views function fdiff(y, x) # in-place
L = length(x)
Expand Down Expand Up @@ -38,16 +54,22 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
@info "Sparsity Detection: $(nameof(typeof(sd)))"
@info "Out of Place Function"

@testset "sparse_jacobian $(nameof(typeof(difftype))): Out of Place" for difftype in (AutoSparseZygote(),
AutoZygote(), AutoSparseForwardDiff(), AutoForwardDiff(),
AutoSparseForwardDiff(; chunksize = 0), AutoForwardDiff(; chunksize = 0),
AutoSparseForwardDiff(; chunksize = 4), AutoForwardDiff(; chunksize = 4),
AutoSparsePolyesterForwardDiff(), AutoPolyesterForwardDiff(),
AutoSparsePolyesterForwardDiff(; chunksize = 0),
AutoPolyesterForwardDiff(; chunksize = 0),
AutoSparsePolyesterForwardDiff(; chunksize = 4),
AutoPolyesterForwardDiff(; chunksize = 4), AutoSparseFiniteDiff(),
AutoFiniteDiff(), AutoEnzyme(), AutoSparseEnzyme())
DIFFTYPES = [AutoSparseZygote(), AutoZygote(), AutoSparseForwardDiff(),
AutoForwardDiff(), AutoSparseForwardDiff(; chunksize = 0),
AutoForwardDiff(; chunksize = 0), AutoSparseForwardDiff(; chunksize = 4),
AutoForwardDiff(; chunksize = 4), AutoSparseFiniteDiff(), AutoFiniteDiff(),
AutoEnzyme(), AutoSparseEnzyme()]

if VERSION v"1.9"
append!(DIFFTYPES,
[AutoSparsePolyesterForwardDiff(), AutoPolyesterForwardDiff(),
AutoSparsePolyesterForwardDiff(; chunksize = 0),
AutoPolyesterForwardDiff(; chunksize = 0),
AutoSparsePolyesterForwardDiff(; chunksize = 4),
AutoPolyesterForwardDiff(; chunksize = 4)])
end

@testset "sparse_jacobian $(nameof(typeof(difftype))): Out of Place" for difftype in DIFFTYPES
@testset "Cache & Reuse" begin
cache = sparse_jacobian_cache(difftype, sd, fdiff, x)
J = init_jacobian(cache)
Expand All @@ -64,9 +86,7 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa

@test J J_true

if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
difftype isa AutoSparsePolyesterForwardDiff ||
difftype isa AutoPolyesterForwardDiff)
if __isinferrable(difftype)
@inferred sparse_jacobian(difftype, cache, fdiff, x)
end

Expand All @@ -78,9 +98,7 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
J = sparse_jacobian(difftype, sd, fdiff, x)

@test J J_true
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
difftype isa AutoSparsePolyesterForwardDiff ||
difftype isa AutoPolyesterForwardDiff)
if __isinferrable(difftype)
@inferred sparse_jacobian(difftype, sd, fdiff, x)
end

Expand Down Expand Up @@ -123,9 +141,7 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
J = sparse_jacobian(difftype, cache, fdiff, y, x)

@test J J_true
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
difftype isa AutoSparsePolyesterForwardDiff ||
difftype isa AutoPolyesterForwardDiff)
if __isinferrable(difftype)
@inferred sparse_jacobian(difftype, cache, fdiff, y, x)
end

Expand All @@ -137,9 +153,7 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
J = sparse_jacobian(difftype, sd, fdiff, y, x)

@test J J_true
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
difftype isa AutoSparsePolyesterForwardDiff ||
difftype isa AutoPolyesterForwardDiff)
if __isinferrable(difftype)
@inferred sparse_jacobian(difftype, sd, fdiff, y, x)
end

Expand Down

0 comments on commit 9ccbe30

Please sign in to comment.