Skip to content

Commit

Permalink
use AbstractMatrix as the eltype of Symmetric for array of arrays (
Browse files Browse the repository at this point in the history
…#32041)

instead of a 3-element Union type

(cherry picked from commit 7b34f1b)
  • Loading branch information
JeffBezanson authored and KristofferC committed Jun 9, 2019
1 parent 9ce9000 commit 83e7363
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ implemented for a custom type, so should be `symmetric_type`, and vice versa.
function symmetric_type(::Type{T}) where {S, T<:AbstractMatrix{S}}
return Symmetric{Union{S, promote_op(transpose, S), symmetric_type(S)}, T}
end
function symmetric_type(::Type{T}) where {S<:Number, T<:AbstractMatrix{S}}
return Symmetric{S, T}
end
function symmetric_type(::Type{T}) where {S<:AbstractMatrix, T<:AbstractMatrix{S}}
return Symmetric{AbstractMatrix, T}
end
symmetric_type(::Type{T}) where {T<:Number} = T

struct Hermitian{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
Expand Down Expand Up @@ -147,9 +153,15 @@ The type of the object returned by `hermitian(::T, ::Symbol)`. For matrices, thi
appropriately typed `Hermitian`, for `Number`s, it is the original type. If `hermitian` is
implemented for a custom type, so should be `hermitian_type`, and vice versa.
"""
function hermitian_type(::Type{T}) where {S,T<:AbstractMatrix{S}}
function hermitian_type(::Type{T}) where {S, T<:AbstractMatrix{S}}
return Hermitian{Union{S, promote_op(adjoint, S), hermitian_type(S)}, T}
end
function hermitian_type(::Type{T}) where {S<:Number, T<:AbstractMatrix{S}}
return Hermitian{S, T}
end
function hermitian_type(::Type{T}) where {S<:AbstractMatrix, T<:AbstractMatrix{S}}
return Hermitian{AbstractMatrix, T}
end
hermitian_type(::Type{T}) where {T<:Number} = T

for (S, H) in ((:Symmetric, :Hermitian), (:Hermitian, :Symmetric))
Expand Down

0 comments on commit 83e7363

Please sign in to comment.