Skip to content

Commit b38742a

Browse files
committed
1 parent e057d13 commit b38742a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/mps/linalg.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,21 @@ function LinearAlgebra.lu(A::MtlMatrix{T}; check::Bool = true) where {T<:MtlFloa
202202
return LinearAlgebra.LU(B, p, status)
203203
end
204204

205+
function _check_lu_success(info, allowsingular)
206+
if VERSION >= v"1.11.0-DEV.1535"
207+
if info < 0 # zero pivot error from unpivoted LU
208+
LinearAlgebra.checknozeropivot(-info)
209+
else
210+
allowsingular || LinearAlgebra.checknonsingular(info)
211+
end
212+
else
213+
LinearAlgebra.checknonsingular(info)
214+
end
215+
end
216+
205217
# TODO: dispatch on pivot strategy
206-
function LinearAlgebra.lu!(A::MtlMatrix{T}; check::Bool = true) where {T<:MtlFloat}
218+
function LinearAlgebra.lu!(A::MtlMatrix{T};
219+
check::Bool=true, allowsingular::Bool=false) where {T<:MtlFloat}
207220
M,N = size(A)
208221
dev = current_device()
209222
queue = global_queue(dev)
@@ -238,7 +251,7 @@ function LinearAlgebra.lu!(A::MtlMatrix{T}; check::Bool = true) where {T<:MtlFlo
238251
wait_completed(cmdbuf_lu)
239252

240253
status = convert(LinearAlgebra.BlasInt, Metal.@allowscalar status[])
241-
check && checknonsingular(status)
254+
check && _check_lu_success(status, allowsingular)
242255

243256
return LinearAlgebra.LU(A, p, status)
244257
end

0 commit comments

Comments
 (0)