Skip to content

Commit

Permalink
bugfix for ldiv!(D::Diagonal, B::StridedVecOrMat) and tests (#32104)
Browse files Browse the repository at this point in the history
(cherry picked from commit 85603e1)
  • Loading branch information
dkarrasch authored and KristofferC committed Feb 20, 2020
1 parent e07c668 commit 90caa80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ function ldiv!(D::Diagonal, B::StridedVecOrMat)
if di == 0
throw(SingularException(i))
end
B[i,j] /= di
B[i,j] = di \ B[i,j]
end
end
return B
Expand Down
9 changes: 9 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ end
@test sqrt(D) == Diagonal([sqrt([1 2; 3 4]), sqrt([1 2; 3 4])])
end

@testset "linear solve for block diagonal matrices" begin
D = Diagonal([rand(2,2) for _ in 1:5])
b = [rand(2,2) for _ in 1:5]
B = [rand(2,2) for _ in 1:5, _ in 1:5]
@test ldiv!(D, copy(b)) Diagonal(inv.(D.diag)) * b
@test ldiv!(D, copy(B)) Diagonal(inv.(D.diag)) * B
@test rdiv!(copy(B), D) B * Diagonal(inv.(D.diag))
end

@testset "multiplication with Symmetric/Hermitian" begin
for T in (Float64, ComplexF64)
D = Diagonal(randn(T, n))
Expand Down

0 comments on commit 90caa80

Please sign in to comment.