diff --git a/Project.toml b/Project.toml index a5edb83..75ebe4e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PreallocationTools" uuid = "d236fae5-4411-538c-8e31-a6e3d9e00b46" authors = ["Chris Rackauckas "] -version = "0.4.15" +version = "0.4.16" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" @@ -10,11 +10,9 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" [weakdeps] ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" -Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" [extensions] PreallocationToolsReverseDiffExt = "ReverseDiff" -PreallocationToolsSymbolicsExt = "Symbolics" [compat] Adapt = "3.4, 4" diff --git a/ext/PreallocationToolsSymbolicsExt.jl b/ext/PreallocationToolsSymbolicsExt.jl deleted file mode 100644 index 3b3a24d..0000000 --- a/ext/PreallocationToolsSymbolicsExt.jl +++ /dev/null @@ -1,49 +0,0 @@ -module PreallocationToolsSymbolicsExt - -using PreallocationTools -import PreallocationTools: _restructure, get_tmp -using Symbolics, ForwardDiff - -function get_tmp(dc::DiffCache, u::Type{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -function get_tmp(dc::DiffCache, u::X) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -function get_tmp(dc::DiffCache, u::AbstractArray{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -function get_tmp(dc::FixedSizeDiffCache, u::Type{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -function get_tmp(dc::FixedSizeDiffCache, u::X) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -function get_tmp(dc::FixedSizeDiffCache, u::AbstractArray{X}) where {T,N, X<: ForwardDiff.Dual{T, Num, N}} - if length(dc.du) > length(dc.any_du) - resize!(dc.any_du, length(dc.du)) - end - _restructure(dc.du, dc.any_du) -end - -end diff --git a/test/sparsity_support.jl b/test/sparsity_support.jl index e6eba6d..b53273c 100644 --- a/test/sparsity_support.jl +++ b/test/sparsity_support.jl @@ -48,26 +48,3 @@ A = Symbolics.jacobian_sparsity(wrap_res_dae_cache!, output, x0) B = sparse([1 0; 0 1]) @test A == B @test findnz(A) == findnz(B) - -# Test Nesting https://discourse.julialang.org/t/preallocationtools-jl-with-nested-forwarddiff-and-sparsity-pattern-detection-errors/107897 - -function foo(x, cache) - d = get_tmp(cache, x) - - d[:] = x - - 0.5 * x'*x -end - -function residual(r, x, cache) - function foo_wrap(x) - foo(x, cache) - end - - r[:] = ForwardDiff.gradient(foo_wrap, x) -end - -cache = DiffCache(zeros(2)) -pattern = Symbolics.jacobian_sparsity((r, x) -> residual(r, x, cache), zeros(2), zeros(2)) -@test pattern == sparse([1 0 - 0 1])