diff --git a/Project.toml b/Project.toml index 5e36a090..ac09c34a 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/test/1.9specific/Project.toml b/test/1.9specific/Project.toml new file mode 100644 index 00000000..c151568d --- /dev/null +++ b/test/1.9specific/Project.toml @@ -0,0 +1,3 @@ +[deps] +AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a" +PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b" diff --git a/test/allocs/Project.toml b/test/allocs/Project.toml deleted file mode 100644 index 2ce39fac..00000000 --- a/test/allocs/Project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[deps] -AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a" diff --git a/test/runtests.jl b/test/runtests.jl index 52b53f92..38085bb0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 diff --git a/test/test_sparse_jacobian.jl b/test/test_sparse_jacobian.jl index 2b0bb4fa..395604c5 100644 --- a/test/test_sparse_jacobian.jl +++ b/test/test_sparse_jacobian.jl @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 @@ -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