@@ -163,9 +163,11 @@ function (cache::LinearSolverCache)(;
163163 cache. lincache = linres. cache
164164 # Unfortunately LinearSolve.jl doesn't have the most uniform ReturnCode handling
165165 if linres. retcode === ReturnCode. Failure
166- # TODO : We need to guard this somehow because this will surely fail if A is on GPU
167- # TODO : or some fancy Matrix type
168- if ! (cache. linsolve isa QRFactorization{ColumnNorm})
166+ structured_mat = ArrayInterface. isstructured (cache. lincache. A)
167+ is_gpuarray = ArrayInterface. device (cache. lincache. A) isa ArrayInterface. GPU
168+ if ! (cache. linsolve isa QRFactorization{ColumnNorm}) &&
169+ ! is_gpuarray &&
170+ ! structured_mat
169171 if verbose
170172 @warn " Potential Rank Deficient Matrix Detected. Attempting to solve using \
171173 Pivoted QR Factorization."
@@ -189,6 +191,20 @@ function (cache::LinearSolverCache)(;
189191 linres. retcode === ReturnCode. Failure &&
190192 return LinearSolveResult (; u = linres. u, success = false )
191193 return LinearSolveResult (; u = linres. u)
194+ elseif ! (cache. linsolve isa QRFactorization{ColumnNorm})
195+ if verbose
196+ if structured_mat
197+ @warn " Potential Rank Deficient Matrix Detected. But Matrix is \
198+ Structured. Currently, we don't attempt to solve Rank Deficient \
199+ Structured Matrices. Please open an issue at \
200+ https://github.com/SciML/NonlinearSolve.jl"
201+ elseif is_gpuarray
202+ @warn " Potential Rank Deficient Matrix Detected. But Matrix is on GPU. \
203+ Currently, we don't attempt to solve Rank Deficient GPU \
204+ Matrices. Please open an issue at \
205+ https://github.com/SciML/NonlinearSolve.jl"
206+ end
207+ end
192208 end
193209 return LinearSolveResult (; u = linres. u, success = false )
194210 end
0 commit comments