From 83e7363a0541cf4f4335df872453d429347731e9 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 7 Jun 2019 17:14:28 -0400 Subject: [PATCH] use `AbstractMatrix` as the eltype of `Symmetric` for array of arrays (#32041) instead of a 3-element Union type (cherry picked from commit 7b34f1b86ecd20e1e1fd8a9543470b6f2ddb23a2) --- stdlib/LinearAlgebra/src/symmetric.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stdlib/LinearAlgebra/src/symmetric.jl b/stdlib/LinearAlgebra/src/symmetric.jl index 71f557b15fbed..e9317bc207e7c 100644 --- a/stdlib/LinearAlgebra/src/symmetric.jl +++ b/stdlib/LinearAlgebra/src/symmetric.jl @@ -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} @@ -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))