Skip to content

Commit 1c90035

Browse files
Merge pull request #348 from SciML/ChrisRackauckas-patch-1
Fiox solution handling for KrylovJL on subarrays
2 parents 0886d05 + 6a2aac0 commit 1c90035

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/iterative_wrappers.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ function SciMLBase.solve!(cache::LinearCache, alg::KrylovJL; kwargs...)
282282
ReturnCode.Success
283283
end
284284

285+
# Copy the solution to the allocated output vector
286+
cacheval = @get_cacheval(cache, :KrylovJL_GMRES)
287+
if cache.u !== cacheval.x
288+
cache.u .= cacheval.x
289+
end
290+
285291
return SciMLBase.build_linear_solution(alg, cache.u, resid, cache;
286292
iters = stats.niter)
287293
end

test/basictests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,10 @@ end
459459
end
460460
end
461461
end # testset
462+
463+
# https://github.com/SciML/LinearSolve.jl/issues/347
464+
A = rand(4, 4); b = rand(4); u0 = zeros(4);
465+
lp = LinearProblem(A, b; u0 = view(u0, :));
466+
truesol = solve(lp, LUFactorization())
467+
krylovsol = solve(lp, KrylovJL_GMRES())
468+
@test truesol krylovsol

0 commit comments

Comments
 (0)