Skip to content

Commit

Permalink
Revert "Reroute Symmetric/Hermitian + Diagonal through triangular (#5…
Browse files Browse the repository at this point in the history
…5605)"

This reverts commit 2878479.
  • Loading branch information
KristofferC committed Sep 11, 2024
1 parent b86812d commit f09de94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
15 changes: 15 additions & 0 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ end
(+)(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag + Db.diag)
(-)(Da::Diagonal, Db::Diagonal) = Diagonal(Da.diag - Db.diag)

for f in (:+, :-)
@eval function $f(D::Diagonal{<:Number}, S::Symmetric)
return Symmetric($f(D, S.data), sym_uplo(S.uplo))
end
@eval function $f(S::Symmetric, D::Diagonal{<:Number})
return Symmetric($f(S.data, D), sym_uplo(S.uplo))
end
@eval function $f(D::Diagonal{<:Real}, H::Hermitian)
return Hermitian($f(D, H.data), sym_uplo(H.uplo))
end
@eval function $f(H::Hermitian, D::Diagonal{<:Real})
return Hermitian($f(H.data, D), sym_uplo(H.uplo))
end
end

(*)(x::Number, D::Diagonal) = Diagonal(x * D.diag)
(*)(D::Diagonal, x::Number) = Diagonal(D.diag * x)
(/)(D::Diagonal, x::Number) = Diagonal(D.diag / x)
Expand Down
19 changes: 0 additions & 19 deletions stdlib/LinearAlgebra/src/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,6 @@ function (-)(A::UniformScaling, B::Diagonal)
Diagonal(Ref(A) .- B.diag)
end

for f in (:+, :-)
@eval function $f(D::Diagonal{<:Number}, S::Symmetric)
uplo = sym_uplo(S.uplo)
return Symmetric(parentof_applytri($f, Symmetric(D, uplo), S), uplo)
end
@eval function $f(S::Symmetric, D::Diagonal{<:Number})
uplo = sym_uplo(S.uplo)
return Symmetric(parentof_applytri($f, S, Symmetric(D, uplo)), uplo)
end
@eval function $f(D::Diagonal{<:Real}, H::Hermitian)
uplo = sym_uplo(H.uplo)
return Hermitian(parentof_applytri($f, Hermitian(D, uplo), H), uplo)
end
@eval function $f(H::Hermitian, D::Diagonal{<:Real})
uplo = sym_uplo(H.uplo)
return Hermitian(parentof_applytri($f, H, Hermitian(D, uplo)), uplo)
end
end

## Diagonal construction from UniformScaling
Diagonal{T}(s::UniformScaling, m::Integer) where {T} = Diagonal{T}(fill(T(s.λ), m))
Diagonal(s::UniformScaling, m::Integer) = Diagonal{eltype(s)}(s, m)
Expand Down
13 changes: 0 additions & 13 deletions stdlib/LinearAlgebra/test/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,4 @@ end
@test v * S isa Matrix
end

@testset "Partly filled Hermitian and Diagonal algebra" begin
D = Diagonal([1,2])
for S in (Symmetric, Hermitian), uplo in (:U, :L)
M = Matrix{BigInt}(undef, 2, 2)
M[1,1] = M[2,2] = M[1+(uplo == :L), 1 + (uplo == :U)] = 3
H = S(M, uplo)
HM = Matrix(H)
@test H + D == D + H == HM + D
@test H - D == HM - D
@test D - H == D - HM
end
end

end # module TestSpecial

0 comments on commit f09de94

Please sign in to comment.