Skip to content

Commit 6d2e9ab

Browse files
authored
Diagonal for lower triangular of LU decomposition set incorrectly (#1813)
1 parent f3156e3 commit 6d2e9ab

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/cusolver/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ function Base.getproperty(F::LU{T,<:StridedCuMatrix}, d::Symbol) where T
455455
m, n = size(F)
456456
if d === :L
457457
L = tril!(getfield(F, :factors)[1:m, 1:min(m,n)])
458-
L[1:min(m,n)+1:end] .= one(T) # set the diagonal (linear indexing trick)
458+
L[1:m+1:end] .= one(T) # set the diagonal (linear indexing trick)
459459
return L
460460
elseif VERSION >= v"1.9.0-DEV.1775"
461461
invoke(getproperty, Tuple{LU{T}, Symbol}, F, d)

test/cusolver/dense.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,18 @@ k = 1
602602
lu_gpu = lu(A_d)
603603
@test ldiv!(lu_cpu, B) collect(ldiv!(lu_gpu, B_d))
604604
end
605+
606+
A = CuMatrix(rand(1024, 1024))
607+
lua = lu(A)
608+
@test Matrix(lua.L) * Matrix(lua.U) Matrix(lua.P) * Matrix(A)
609+
610+
A = CuMatrix(rand(1024, 512))
611+
lua = lu(A)
612+
@test Matrix(lua.L) * Matrix(lua.U) Matrix(lua.P) * Matrix(A)
613+
614+
A = CuMatrix(rand(512, 1024))
615+
lua = lu(A)
616+
@test Matrix(lua.L) * Matrix(lua.U) Matrix(lua.P) * Matrix(A)
605617
end
606618
end
607619

0 commit comments

Comments
 (0)