Skip to content

Commit

Permalink
fix: minor test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Sep 27, 2024
1 parent be0f8da commit 59347e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/globalization/line_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function __internal_init(
args...; stats, internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN}
T = promote_type(eltype(fu), eltype(u))
if u isa Number
autodiff = get_concrete_forward_ad(alg.autodiff, prob; check_forward_mode = true)
autodiff = get_dense_ad(get_concrete_forward_ad(
alg.autodiff, prob; check_forward_mode = true))
if !(autodiff isa AutoForwardDiff ||
autodiff isa AutoPolyesterForwardDiff ||
autodiff isa AutoFiniteDiff)
Expand Down
16 changes: 11 additions & 5 deletions src/internal/jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ function JacobianCache(prob, alg, f::F, fu_, u, p; stats, autodiff = nothing,
# While this is technically wasteful, it gives out the type of the Jacobian
# which is needed to create the linear solver cache
stats.njacs += 1
if iip
DI.jacobian(f, fu, di_extras, autodiff, u, Constant(p))
if has_analytic_jac
__similar(
fu, promote_type(eltype(fu), eltype(u)), length(fu), length(u))
else
DI.jacobian(f, autodiff, u, Constant(p))
if iip
DI.jacobian(f, fu, di_extras, autodiff, u, Constant(p))
else
DI.jacobian(f, autodiff, u, Constant(p))
end
end
else
zero(init_jacobian(sdifft_extras; preserve_immutable = Val(true)))
Expand All @@ -120,9 +125,10 @@ function JacobianCache(prob, alg, f::F, ::Number, u::Number, p; stats,
autodiff = nothing, kwargs...) where {F}
fu = f(u, p)
if SciMLBase.has_jac(f) || SciMLBase.has_vjp(f) || SciMLBase.has_jvp(f)
return JacobianCache{false}(u, f, fu, u, p, stats, autodiff, nothing)
return JacobianCache{false}(u, f, fu, u, p, stats, autodiff, nothing, nothing)
end
autodiff = get_concrete_forward_ad(autodiff, prob; check_forward_mode = false)
autodiff = get_dense_ad(get_concrete_forward_ad(
autodiff, prob; check_forward_mode = false))
di_extras = DI.prepare_derivative(f, get_dense_ad(autodiff), u, Constant(prob.p))
return JacobianCache{false}(u, f, fu, u, p, stats, autodiff, di_extras, nothing)
end
Expand Down
4 changes: 2 additions & 2 deletions test/misc/bruss_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@

cache = init(
prob_brusselator_2d, NewtonRaphson(; autodiff = AutoSparse(AutoForwardDiff())))
@test maximum(cache.sdifft_extras.jac_cache.coloring.colorvec) == 12
@test cache.sdifft_extras.autodiff isa AutoSparse{<:AutoForwardDiff}
@test maximum(cache.jac_cache.sdifft_extras.coloring.colorvec) == 12
@test cache.jac_cache.autodiff isa AutoSparse{<:AutoForwardDiff}
end

0 comments on commit 59347e3

Please sign in to comment.