Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix for ldiv!(D::Diagonal, B::StridedVecOrMat) and tests #32104

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,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 @@ -441,6 +441,15 @@ end
@test det(D) == 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