Skip to content

Generic path in ldiv! for Diagonal #1261

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,10 @@ function _rdiv!(B::AbstractVecOrMat, A::AbstractVecOrMat, D::Diagonal)
if (k = length(dd)) != n
throw(DimensionMismatch(lazy"left hand side has $n columns but D is $k by $k"))
end
@inbounds for j in 1:n
@inbounds for j in axes(A,2)
ddj = dd[j]
iszero(ddj) && throw(SingularException(j))
for i in 1:m
for i in axes(A,1)
B[i, j] = A[i, j] / ddj
end
end
Expand All @@ -629,7 +629,17 @@ function ldiv!(B::AbstractVecOrMat, D::Diagonal, A::AbstractVecOrMat)
(m, n) == (m′, n′) || throw(DimensionMismatch(lazy"expect output to be $m by $n, but got $m′ by $n′"))
j = findfirst(iszero, D.diag)
isnothing(j) || throw(SingularException(j))
@inbounds for j = 1:n, i = 1:m
_ldiv_Diagonal_loop!(B, D, A)
B
end
function _ldiv_Diagonal_loop!(B::AbstractVecOrMat, D::Diagonal, A::AbstractVecOrMat)
dd = D.diag
@. B = dd \ A
B
end
function _ldiv_Diagonal_loop!(B::StridedVecOrMat, D::Diagonal, A::StridedVecOrMat)
dd = D.diag
@inbounds for j in axes(A,2), i in axes(A,1)
B[i, j] = dd[i] \ A[i, j]
end
B
Expand Down