@@ -119,6 +119,15 @@ default_alias_b(::Any, ::Any, ::Any) = false
119119default_alias_A (:: AbstractKrylovSubspaceMethod , :: Any , :: Any ) = true
120120default_alias_b (:: AbstractKrylovSubspaceMethod , :: Any , :: Any ) = true
121121
122+ function __init_u0_from_Ab (A, b)
123+ u0 = similar (b, size (A, 2 ))
124+ fill! (u0, false )
125+ return u0
126+ end
127+ function __init_u0_from_Ab (A:: SMatrix{S1, S2} , b) where {S1, S2}
128+ return zeros (SVector{S2, eltype (b)})
129+ end
130+
122131function SciMLBase. init (prob:: LinearProblem , alg:: SciMLLinearSolveAlgorithm ,
123132 args... ;
124133 alias_A = default_alias_A (alg, prob. A, prob. b),
@@ -133,7 +142,7 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
133142 kwargs... )
134143 @unpack A, b, u0, p = prob
135144
136- A = if alias_A
145+ A = if alias_A || A isa SMatrix
137146 A
138147 elseif A isa Array || A isa SparseMatrixCSC
139148 copy (A)
@@ -143,34 +152,29 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
143152
144153 b = if b isa SparseArrays. AbstractSparseArray && ! (A isa Diagonal)
145154 Array (b) # the solution to a linear solve will always be dense!
146- elseif alias_b
155+ elseif alias_b || b isa SVector
147156 b
148157 elseif b isa Array || b isa SparseMatrixCSC
149158 copy (b)
150159 else
151160 deepcopy (b)
152161 end
153162
154- u0 = if u0 != = nothing
155- u0
156- else
157- u0 = similar (b, size (A, 2 ))
158- fill! (u0, false )
159- end
163+ u0_ = u0 != = nothing ? u0 : __init_u0_from_Ab (A, b)
160164
161165 # Guard against type mismatch for user-specified reltol/abstol
162166 reltol = real (eltype (prob. b))(reltol)
163167 abstol = real (eltype (prob. b))(abstol)
164168
165- cacheval = init_cacheval (alg, A, b, u0 , Pl, Pr, maxiters, abstol, reltol, verbose,
169+ cacheval = init_cacheval (alg, A, b, u0_ , Pl, Pr, maxiters, abstol, reltol, verbose,
166170 assumptions)
167171 isfresh = true
168172 Tc = typeof (cacheval)
169173
170174 cache = LinearCache{
171175 typeof (A),
172176 typeof (b),
173- typeof (u0 ),
177+ typeof (u0_ ),
174178 typeof (p),
175179 typeof (alg),
176180 Tc,
@@ -180,7 +184,7 @@ function SciMLBase.init(prob::LinearProblem, alg::SciMLLinearSolveAlgorithm,
180184 typeof (assumptions. issq),
181185 }(A,
182186 b,
183- u0 ,
187+ u0_ ,
184188 p,
185189 alg,
186190 cacheval,
0 commit comments