11# # Sparse Jacobian tests
2- using AllocCheck, SparseDiffTools,
2+ using SparseDiffTools,
33 Symbolics, ForwardDiff, LinearAlgebra, SparseArrays, Zygote, Enzyme, Test, StaticArrays
44
55@views function fdiff (y, x) # in-place
@@ -164,28 +164,32 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(; jac_prototype = J_spa
164164 end
165165end
166166
167- # Testing that the non-sparse jacobian's are non-allocating.
168- fvcat (x) = vcat (x, x)
167+ @static if VERSION ≥ v " 1.9 "
168+ using AllocCheck
169169
170- x_sa = @SVector randn (Float32, 10 );
170+ # Testing that the non-sparse jacobian's are non-allocating.
171+ fvcat (x) = vcat (x, x)
171172
172- J_true_sa = ForwardDiff . jacobian (fvcat, x_sa)
173+ x_sa = @SVector randn (Float32, 10 );
173174
174- @check_allocs function __sparse_jacobian_no_allocs (ad, sd, f:: F , x) where {F}
175- return sparse_jacobian (ad, sd, f, x)
176- end
175+ J_true_sa = ForwardDiff. jacobian (fvcat, x_sa)
177176
178- @testset " Static Arrays" begin
179- @testset " No Allocations: $(difftype) " for difftype in (AutoSparseForwardDiff (),
180- AutoForwardDiff ())
181- J = __sparse_jacobian_no_allocs (difftype, NoSparsityDetection (), fvcat, x_sa)
182- @test J ≈ J_true_sa
177+ @check_allocs function __sparse_jacobian_no_allocs (ad, sd, f:: F , x) where {F}
178+ return sparse_jacobian (ad, sd, f, x)
183179 end
184180
185- @testset " Other Backends: $(difftype) " for difftype in (AutoSparseZygote (),
186- AutoZygote (), AutoSparseEnzyme (), AutoEnzyme (), AutoSparseFiniteDiff (),
187- AutoFiniteDiff ())
188- J = sparse_jacobian (difftype, NoSparsityDetection (), fvcat, x_sa)
189- @test J ≈ J_true_sa
181+ @testset " Static Arrays" begin
182+ @testset " No Allocations: $(difftype) " for difftype in (AutoSparseForwardDiff (),
183+ AutoForwardDiff ())
184+ J = __sparse_jacobian_no_allocs (difftype, NoSparsityDetection (), fvcat, x_sa)
185+ @test J ≈ J_true_sa
186+ end
187+
188+ @testset " Other Backends: $(difftype) " for difftype in (AutoSparseZygote (),
189+ AutoZygote (), AutoSparseEnzyme (), AutoEnzyme (), AutoSparseFiniteDiff (),
190+ AutoFiniteDiff ())
191+ J = sparse_jacobian (difftype, NoSparsityDetection (), fvcat, x_sa)
192+ @test J ≈ J_true_sa
193+ end
190194 end
191- end
195+ end
0 commit comments