Skip to content

Commit 9ccbe30

Browse files
committed
Better testing
1 parent 7c1264f commit 9ccbe30

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7979
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
8080

8181
[targets]
82-
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays", "PolyesterForwardDiff"]
82+
test = ["Test", "BandedMatrices", "BlockBandedMatrices", "Enzyme", "IterativeSolvers", "Pkg", "Random", "SafeTestsets", "Symbolics", "Zygote", "StaticArrays"]

test/1.9specific/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
3+
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"

test/allocs/Project.toml

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

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if GROUP == "Core" || GROUP == "All"
4242
end
4343

4444
if GROUP == "InterfaceI" || GROUP == "All"
45-
VERSION v"1.9" && activate_env("allocs")
45+
VERSION v"1.9" && activate_env("1.9specific")
4646
@time @safetestset "Jac Vecs and Hes Vecs" begin
4747
include("test_jaches_products.jl")
4848
end

test/test_sparse_jacobian.jl

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
## Sparse Jacobian tests
2-
using SparseDiffTools, PolyesterForwardDiff, Symbolics, ForwardDiff, LinearAlgebra,
3-
SparseArrays, Zygote, Enzyme, Test, StaticArrays
2+
using SparseDiffTools,
3+
Symbolics, ForwardDiff, LinearAlgebra, SparseArrays, Zygote, Enzyme, Test, StaticArrays
4+
5+
@static if VERSION v"1.9"
6+
using PolyesterForwardDiff
7+
end
8+
9+
function __chunksize(::Union{AutoSparseForwardDiff{C}, AutoForwardDiff{C},
10+
AutoSparsePolyesterForwardDiff{C}, AutoPolyesterForwardDiff{C}}) where {C}
11+
return C
12+
end
13+
14+
function __isinferrable(difftype)
15+
return !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
16+
difftype isa AutoSparsePolyesterForwardDiff ||
17+
difftype isa AutoPolyesterForwardDiff) ||
18+
(__chunksize(difftype) isa Int && __chunksize(difftype) > 0)
19+
end
420

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

41-
@testset "sparse_jacobian $(nameof(typeof(difftype))): Out of Place" for difftype in (AutoSparseZygote(),
42-
AutoZygote(), AutoSparseForwardDiff(), AutoForwardDiff(),
43-
AutoSparseForwardDiff(; chunksize = 0), AutoForwardDiff(; chunksize = 0),
44-
AutoSparseForwardDiff(; chunksize = 4), AutoForwardDiff(; chunksize = 4),
45-
AutoSparsePolyesterForwardDiff(), AutoPolyesterForwardDiff(),
46-
AutoSparsePolyesterForwardDiff(; chunksize = 0),
47-
AutoPolyesterForwardDiff(; chunksize = 0),
48-
AutoSparsePolyesterForwardDiff(; chunksize = 4),
49-
AutoPolyesterForwardDiff(; chunksize = 4), AutoSparseFiniteDiff(),
50-
AutoFiniteDiff(), AutoEnzyme(), AutoSparseEnzyme())
57+
DIFFTYPES = [AutoSparseZygote(), AutoZygote(), AutoSparseForwardDiff(),
58+
AutoForwardDiff(), AutoSparseForwardDiff(; chunksize = 0),
59+
AutoForwardDiff(; chunksize = 0), AutoSparseForwardDiff(; chunksize = 4),
60+
AutoForwardDiff(; chunksize = 4), AutoSparseFiniteDiff(), AutoFiniteDiff(),
61+
AutoEnzyme(), AutoSparseEnzyme()]
62+
63+
if VERSION v"1.9"
64+
append!(DIFFTYPES,
65+
[AutoSparsePolyesterForwardDiff(), AutoPolyesterForwardDiff(),
66+
AutoSparsePolyesterForwardDiff(; chunksize = 0),
67+
AutoPolyesterForwardDiff(; chunksize = 0),
68+
AutoSparsePolyesterForwardDiff(; chunksize = 4),
69+
AutoPolyesterForwardDiff(; chunksize = 4)])
70+
end
71+
72+
@testset "sparse_jacobian $(nameof(typeof(difftype))): Out of Place" for difftype in DIFFTYPES
5173
@testset "Cache & Reuse" begin
5274
cache = sparse_jacobian_cache(difftype, sd, fdiff, x)
5375
J = init_jacobian(cache)
@@ -64,9 +86,7 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
6486

6587
@test J J_true
6688

67-
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
68-
difftype isa AutoSparsePolyesterForwardDiff ||
69-
difftype isa AutoPolyesterForwardDiff)
89+
if __isinferrable(difftype)
7090
@inferred sparse_jacobian(difftype, cache, fdiff, x)
7191
end
7292

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

80100
@test J J_true
81-
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
82-
difftype isa AutoSparsePolyesterForwardDiff ||
83-
difftype isa AutoPolyesterForwardDiff)
101+
if __isinferrable(difftype)
84102
@inferred sparse_jacobian(difftype, sd, fdiff, x)
85103
end
86104

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

125143
@test J J_true
126-
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
127-
difftype isa AutoSparsePolyesterForwardDiff ||
128-
difftype isa AutoPolyesterForwardDiff)
144+
if __isinferrable(difftype)
129145
@inferred sparse_jacobian(difftype, cache, fdiff, y, x)
130146
end
131147

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

139155
@test J J_true
140-
if !(difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff ||
141-
difftype isa AutoSparsePolyesterForwardDiff ||
142-
difftype isa AutoPolyesterForwardDiff)
156+
if __isinferrable(difftype)
143157
@inferred sparse_jacobian(difftype, sd, fdiff, y, x)
144158
end
145159

0 commit comments

Comments
 (0)