Skip to content

Commit

Permalink
relaxed eltype for ldiv! and rdiv! methods (#41015)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
  • Loading branch information
ArunS-tack and dkarrasch authored May 31, 2021
1 parent 70d8b25 commit 1a2285b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ mul!(C::AbstractMatrix, A::Transpose{<:Any,<:Diagonal}, B::Transpose{<:Any,<:Rea

ldiv!(x::AbstractArray, A::Diagonal, b::AbstractArray) = (x .= A.diag .\ b)

ldiv!(adjD::Adjoint{<:Any,<:Diagonal{T}}, B::AbstractVecOrMat{T}) where {T} =
ldiv!(adjD::Adjoint{<:Any,<:Diagonal}, B::AbstractVecOrMat) =
(D = adjD.parent; ldiv!(conj(D), B))
ldiv!(transD::Transpose{<:Any,<:Diagonal{T}}, B::AbstractVecOrMat{T}) where {T} =
ldiv!(transD::Transpose{<:Any,<:Diagonal}, B::AbstractVecOrMat) =
(D = transD.parent; ldiv!(D, B))

function ldiv!(D::Diagonal, A::Union{LowerTriangular,UpperTriangular})
Expand Down Expand Up @@ -486,9 +486,9 @@ function rdiv!(A::Union{LowerTriangular,UpperTriangular}, D::Diagonal)
A
end

rdiv!(A::AbstractMatrix{T}, adjD::Adjoint{<:Any,<:Diagonal{T}}) where {T} =
rdiv!(A::AbstractMatrix, adjD::Adjoint{<:Any,<:Diagonal}) =
(D = adjD.parent; rdiv!(A, conj(D)))
rdiv!(A::AbstractMatrix{T}, transD::Transpose{<:Any,<:Diagonal{T}}) where {T} =
rdiv!(A::AbstractMatrix, transD::Transpose{<:Any,<:Diagonal}) =
(D = transD.parent; rdiv!(A, D))

(/)(A::Union{StridedMatrix, AbstractTriangular}, D::Diagonal) =
Expand Down
7 changes: 7 additions & 0 deletions stdlib/LinearAlgebra/test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,11 @@ end
@test dot(A, B) conj(dot(B, A))
end

@testset "eltype relaxation(#41015)" begin
A = rand(3,3)
for trans in (identity, Adjoint, Transpose)
@test ldiv!(trans(I(3)), A) == A
@test rdiv!(A, trans(I(3))) == A
end
end
end # module TestDiagonal

0 comments on commit 1a2285b

Please sign in to comment.