@@ -49,15 +49,32 @@ function reinit_cache!(cache::LinearSolverCache, args...; kwargs...)
4949 cache. nfactors = 0
5050end
5151
52+ @inline __fix_strange_type_combination (A, b, u) = u
53+ @inline function __fix_strange_type_combination (A, b, u:: SArray )
54+ A isa SArray && b isa SArray && return u
55+ @warn " Solving Linear System A::$(typeof (A)) x::$(typeof (u)) = b::$(typeof (u)) is not \
56+ properly supported. Converting `x` to a mutable array. Check the return type \
57+ of the nonlinear function provided for optimal performance." maxlog= 1
58+ return MArray (u)
59+ end
60+
61+ @inline __set_lincache_u! (cache, u) = (cache. lincache. u = u)
62+ @inline function __set_lincache_u! (cache, u:: SArray )
63+ cache. lincache. u isa MArray && return __set_lincache_u! (cache, MArray (u))
64+ cache. lincache. u = u
65+ end
66+
5267function LinearSolverCache (alg, linsolve, A, b, u; kwargs... )
68+ u_fixed = __fix_strange_type_combination (A, b, u)
69+
5370 if (A isa Number && b isa Number) || (linsolve === nothing && A isa SMatrix) ||
5471 (A isa Diagonal) || (linsolve isa typeof (\ ))
5572 return LinearSolverCache (nothing , nothing , A, b, nothing , 0 , 0 )
5673 end
57- @bb u_ = copy (u )
74+ @bb u_ = copy (u_fixed )
5875 linprob = LinearProblem (A, b; u0 = u_, kwargs... )
5976
60- weight = __init_ones (u )
77+ weight = __init_ones (u_fixed )
6178 if __hasfield (alg, Val (:precs ))
6279 precs = alg. precs
6380 Pl_, Pr_ = precs (A, nothing , u, nothing , nothing , nothing , nothing , nothing ,
@@ -97,7 +114,7 @@ function (cache::LinearSolverCache)(; A = nothing, b = nothing, linu = nothing,
97114
98115 __update_A! (cache, A, reuse_A_if_factorization)
99116 b != = nothing && (cache. lincache. b = b)
100- linu != = nothing && (cache. lincache . u = linu)
117+ linu != = nothing && __set_lincache_u! (cache, linu)
101118
102119 Plprev = cache. lincache. Pl isa ComposePreconditioner ? cache. lincache. Pl. outer :
103120 cache. lincache. Pl
0 commit comments