Skip to content

simplify inference #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ function (cache::LinearSolveJLCache)(;
cache.stats.nsolve += 1

update_A!(cache, A, reuse_A_if_factorization)
b !== nothing && setproperty!(cache.lincache, :b, b)
b !== nothing && (cache.lincache.b = b)
linu !== nothing && NonlinearSolveBase.set_lincache_u!(cache, linu)

linres = solve!(cache.lincache)
if linres.retcode === ReturnCode.Failure
return LinearSolveResult(; linres.u, success = false)
else
return LinearSolveResult(; linres.u)
end
LinearSolveResult(linres.u, linres.retcode != ReturnCode.Failure)
end

function NonlinearSolveBase.needs_square_A(linsolve::SciMLLinearSolveAlgorithm, ::Any)
Expand Down
8 changes: 4 additions & 4 deletions lib/NonlinearSolveBase/src/linear_solve.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@kwdef @concrete struct LinearSolveResult
@concrete struct LinearSolveResult
u
success::Bool = true
success::Bool
end

@concrete mutable struct LinearSolveJLCache <: AbstractLinearSolverCache
Expand Down Expand Up @@ -93,7 +93,7 @@ function (cache::NativeJLLinearSolveCache)(;
else
res = cache.A \ cache.b
end
return LinearSolveResult(; u = res)
return LinearSolveResult(res, true)
end

fix_incompatible_linsolve_arguments(A, b, u) = u
Expand All @@ -106,7 +106,7 @@ function fix_incompatible_linsolve_arguments(A, b, u::SArray)
return MArray(u)
end

set_lincache_u!(cache, u) = setproperty!(cache.lincache, :u, u)
set_lincache_u!(cache, u) = cache.lincache.u = u
function set_lincache_u!(cache, u::SArray)
cache.lincache.u isa MArray && return set_lincache_u!(cache, MArray(u))
cache.lincache.u = u
Expand Down
Loading