Skip to content

Commit

Permalink
Fix dispatch for rdiv! with LU (#55764)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Nov 1, 2024
1 parent bf5675b commit 3ccd11c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ function ldiv!(adjA::AdjointFactorization{<:Any,<:LU{T,Tridiagonal{T,V}}}, B::Ab
return B
end

rdiv!(B::AbstractMatrix, A::LU) = transpose(ldiv!(transpose(A), transpose(B)))
rdiv!(B::AbstractMatrix, A::LU{T,Tridiagonal{T,V}}) where {T,V} = transpose(ldiv!(transpose(A), transpose(B)))

# Conversions
AbstractMatrix(F::LU) = (F.L * F.U)[invperm(F.p),:]
Expand Down
33 changes: 28 additions & 5 deletions stdlib/LinearAlgebra/src/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -919,9 +919,20 @@ _trimul!(C::AbstractMatrix, A::UpperOrLowerTriangular, B::AbstractTriangular) =
_trimul!(C::AbstractMatrix, A::AbstractTriangular, B::UpperOrLowerTriangular) =
generic_mattrimul!(C, uplo_char(B), isunit_char(B), wrapperop(parent(B)), A, _unwrap_at(parent(B)))

lmul!(A::AbstractTriangular, B::AbstractVecOrMat) = @inline _trimul!(B, A, B)
rmul!(A::AbstractMatrix, B::AbstractTriangular) = @inline _trimul!(A, A, B)

function lmul!(A::AbstractTriangular, B::AbstractVecOrMat)
if istriu(A)
_trimul!(B, uppertriangular(A), B)
else
_trimul!(B, lowertriangular(A), B)
end
end
function rmul!(A::AbstractMatrix, B::AbstractTriangular)
if istriu(B)
_trimul!(A, A, uppertriangular(B))
else
_trimul!(A, A, lowertriangular(B))
end
end

for TC in (:AbstractVector, :AbstractMatrix)
@eval @inline function _mul!(C::$TC, A::AbstractTriangular, B::AbstractVector, alpha::Number, beta::Number)
Expand Down Expand Up @@ -957,8 +968,20 @@ _ldiv!(C::AbstractVecOrMat, A::UpperOrLowerTriangular, B::AbstractVecOrMat) =
_rdiv!(C::AbstractMatrix, A::AbstractMatrix, B::UpperOrLowerTriangular) =
generic_mattridiv!(C, uplo_char(B), isunit_char(B), wrapperop(parent(B)), A, _unwrap_at(parent(B)))

ldiv!(A::AbstractTriangular, B::AbstractVecOrMat) = @inline _ldiv!(B, A, B)
rdiv!(A::AbstractMatrix, B::AbstractTriangular) = @inline _rdiv!(A, A, B)
function ldiv!(A::AbstractTriangular, B::AbstractVecOrMat)
if istriu(A)
_ldiv!(B, uppertriangular(A), B)
else
_ldiv!(B, lowertriangular(A), B)
end
end
function rdiv!(A::AbstractMatrix, B::AbstractTriangular)
if istriu(B)
_rdiv!(A, A, uppertriangular(B))
else
_rdiv!(A, A, lowertriangular(B))
end
end

# preserve triangular structure in in-place multiplication/division
for (cty, aty, bty) in ((:UpperTriangular, :UpperTriangular, :UpperTriangular),
Expand Down

0 comments on commit 3ccd11c

Please sign in to comment.