From 1a2285bb0537eb53d2d7cd2894f0276bfb9f3985 Mon Sep 17 00:00:00 2001 From: Arun sanganal <74652697+ArunSanganal@users.noreply.github.com> Date: Mon, 31 May 2021 22:16:04 +0530 Subject: [PATCH] relaxed eltype for ldiv! and rdiv! methods (#41015) Co-authored-by: Daniel Karrasch --- stdlib/LinearAlgebra/src/diagonal.jl | 8 ++++---- stdlib/LinearAlgebra/test/diagonal.jl | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/stdlib/LinearAlgebra/src/diagonal.jl b/stdlib/LinearAlgebra/src/diagonal.jl index 2b57327fc5e54..ae0743fdc6681 100644 --- a/stdlib/LinearAlgebra/src/diagonal.jl +++ b/stdlib/LinearAlgebra/src/diagonal.jl @@ -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}) @@ -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) = diff --git a/stdlib/LinearAlgebra/test/diagonal.jl b/stdlib/LinearAlgebra/test/diagonal.jl index 382e40d54c0a2..d84141ed330c7 100644 --- a/stdlib/LinearAlgebra/test/diagonal.jl +++ b/stdlib/LinearAlgebra/test/diagonal.jl @@ -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