Skip to content

Commit e507961

Browse files
committed
Generic path in ldiv! for Diagonal
1 parent 925acef commit e507961

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/diagonal.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ function _rdiv!(B::AbstractVecOrMat, A::AbstractVecOrMat, D::Diagonal)
601601
if (k = length(dd)) != n
602602
throw(DimensionMismatch(lazy"left hand side has $n columns but D is $k by $k"))
603603
end
604-
@inbounds for j in 1:n
604+
@inbounds for j in axes(A,2)
605605
ddj = dd[j]
606606
iszero(ddj) && throw(SingularException(j))
607-
for i in 1:m
607+
@simd for i in axes(A,1)
608608
B[i, j] = A[i, j] / ddj
609609
end
610610
end
@@ -629,8 +629,20 @@ function ldiv!(B::AbstractVecOrMat, D::Diagonal, A::AbstractVecOrMat)
629629
(m, n) == (m′, n′) || throw(DimensionMismatch(lazy"expect output to be $m by $n, but got $m′ by $n′"))
630630
j = findfirst(iszero, D.diag)
631631
isnothing(j) || throw(SingularException(j))
632-
@inbounds for j = 1:n, i = 1:m
633-
B[i, j] = dd[i] \ A[i, j]
632+
_ldiv_Diagonal_loop!(B, D, A)
633+
B
634+
end
635+
function _ldiv_Diagonal_loop!(B::AbstractVecOrMat, D::Diagonal, A::AbstractVecOrMat)
636+
dd = D.diag
637+
@. B = dd \ A
638+
B
639+
end
640+
function _ldiv_Diagonal_loop!(B::StridedVecOrMat, D::Diagonal, A::StridedVecOrMat)
641+
dd = D.diag
642+
@inbounds for j in axes(A,2)
643+
@simd for i in axes(A,1)
644+
B[i, j] = dd[i] \ A[i, j]
645+
end
634646
end
635647
B
636648
end

0 commit comments

Comments
 (0)