Skip to content

Commit

Permalink
SparseArrays: Allow division by diagonal matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Apr 23, 2020
1 parent dd738f9 commit 9d4c542
Show file tree
Hide file tree
Showing 2 changed files with 3 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 @@ -483,7 +483,7 @@ rdiv!(A::AbstractMatrix{T}, adjD::Adjoint{<:Any,<:Diagonal{T}}) where {T} =
rdiv!(A::AbstractMatrix{T}, transD::Transpose{<:Any,<:Diagonal{T}}) where {T} =
(D = transD.parent; rdiv!(A, D))

(/)(A::Union{StridedMatrix, AbstractTriangular}, D::Diagonal) =
(/)(A::AbstractMatrix, D::Diagonal) =
rdiv!((typeof(oneunit(eltype(D))/oneunit(eltype(A)))).(A), D)

(\)(F::Factorization, D::Diagonal) =
Expand Down
2 changes: 2 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ dA = Array(sA)
@test lmul!(Diagonal(bi), copy(dA)) ldiv!(Diagonal(b), copy(sA))
@test lmul!(Diagonal(bi), copy(dA)) ldiv!(transpose(Diagonal(b)), copy(sA))
@test lmul!(Diagonal(conj(bi)), copy(dA)) ldiv!(adjoint(Diagonal(b)), copy(sA))
@test Diagonal(b) \ copy(sA) == ldiv!(Diagonal(b), copy(sA))
@test_throws DimensionMismatch ldiv!(Diagonal(fill(1., length(b)+1)), copy(sA))
@test_throws LinearAlgebra.SingularException ldiv!(Diagonal(zeros(length(b))), copy(sA))

Expand All @@ -527,6 +528,7 @@ dA = Array(sA)
@test rmul!(copy(dAt), Diagonal(bi)) rdiv!(copy(sAt), Diagonal(b))
@test rmul!(copy(dAt), Diagonal(bi)) rdiv!(copy(sAt), transpose(Diagonal(b)))
@test rmul!(copy(dAt), Diagonal(conj(bi))) rdiv!(copy(sAt), adjoint(Diagonal(b)))
@test copy(sAt) / Diagonal(b) == rdiv!(copy(dAt), Diagonal(b))
@test_throws DimensionMismatch rdiv!(copy(sAt), Diagonal(fill(1., length(b)+1)))
@test_throws LinearAlgebra.SingularException rdiv!(copy(sAt), Diagonal(zeros(length(b))))
end
Expand Down

0 comments on commit 9d4c542

Please sign in to comment.