@@ -49,15 +49,32 @@ function reinit_cache!(cache::LinearSolverCache, args...; kwargs...)
49
49
cache. nfactors = 0
50
50
end
51
51
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
+
52
67
function LinearSolverCache (alg, linsolve, A, b, u; kwargs... )
68
+ u_fixed = __fix_strange_type_combination (A, b, u)
69
+
53
70
if (A isa Number && b isa Number) || (linsolve === nothing && A isa SMatrix) ||
54
71
(A isa Diagonal) || (linsolve isa typeof (\ ))
55
72
return LinearSolverCache (nothing , nothing , A, b, nothing , 0 , 0 )
56
73
end
57
- @bb u_ = copy (u )
74
+ @bb u_ = copy (u_fixed )
58
75
linprob = LinearProblem (A, b; u0 = u_, kwargs... )
59
76
60
- weight = __init_ones (u )
77
+ weight = __init_ones (u_fixed )
61
78
if __hasfield (alg, Val (:precs ))
62
79
precs = alg. precs
63
80
Pl_, Pr_ = precs (A, nothing , u, nothing , nothing , nothing , nothing , nothing ,
@@ -97,7 +114,7 @@ function (cache::LinearSolverCache)(; A = nothing, b = nothing, linu = nothing,
97
114
98
115
__update_A! (cache, A, reuse_A_if_factorization)
99
116
b != = nothing && (cache. lincache. b = b)
100
- linu != = nothing && (cache. lincache . u = linu)
117
+ linu != = nothing && __set_lincache_u! (cache, linu)
101
118
102
119
Plprev = cache. lincache. Pl isa ComposePreconditioner ? cache. lincache. Pl. outer :
103
120
cache. lincache. Pl
0 commit comments