Skip to content

Commit

Permalink
Proper dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 31, 2023
1 parent 2cb87b9 commit 23b4e74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ function LineSearch(; method = nothing, autodiff = AutoFiniteDiff(), alpha = tru
return LineSearch(method, autodiff, alpha)
end

@inline function init_linesearch_cache(ls::LineSearch, args...)
return init_linesearch_cache(ls.method, ls, args...)
@inline function init_linesearch_cache(ls::LineSearch, f::F, u, p, fu, iip) where {F}
return init_linesearch_cache(ls.method, ls, f, u, p, fu, iip)
end

@concrete struct NoLineSearchCache
α
end

function init_linesearch_cache(::Nothing, ls, f::F, u, p, fu, iip) where {F}
function init_linesearch_cache(::Nothing, ls::LineSearch, f::F, u, p, fu, iip) where {F}
return NoLineSearchCache(convert(eltype(u), ls.α))
end

perform_linesearch!(cache::NoLineSearchCache, u, du) = cache.α

# LineSearches.jl doesn't have a supertype so default to that
function init_linesearch_cache(_, ls, f::F, u, p, fu, iip) where {F}
function init_linesearch_cache(_, ls::LineSearch, f::F, u, p, fu, iip) where {F}
return LineSearchesJLCache(ls, f, u, p, fu, iip)
end

Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function default_adargs_to_adtype(; chunk_size = missing, autodiff = nothing,

ad = _unwrap_val(autodiff)
# We don't really know the typeof the input yet, so we can't use the correct tag!
ad && return AutoForwardDiff{_unwrap_val(chunk_size), NonlinearSolveTag}(;
tag = NonlinearSolveTag())
ad && return AutoForwardDiff{_unwrap_val(chunk_size), NonlinearSolveTag}(
NonlinearSolveTag())
return AutoFiniteDiff(; fdtype = diff_type)
end

Expand Down

0 comments on commit 23b4e74

Please sign in to comment.