From 5fa469bf21c2c015865e861b21432a6ef93a2569 Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Wed, 19 Jun 2019 11:29:27 +0200 Subject: [PATCH] Broaden signature of eigen and eigvals to AbstractMatrix to allow for Adjoint and Transpose input. (#31117) * Broaden signature of eigen and eigvals to AbstractMatrix to allow for Adjoint and Transpose input. Fixes #28714 * Update stdlib/LinearAlgebra/test/eigen.jl Co-Authored-By: andreasnoack * Update stdlib/LinearAlgebra/test/eigen.jl Co-Authored-By: Nick Robinson --- stdlib/LinearAlgebra/src/eigen.jl | 6 +++--- stdlib/LinearAlgebra/test/eigen.jl | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/stdlib/LinearAlgebra/src/eigen.jl b/stdlib/LinearAlgebra/src/eigen.jl index 928f470f2415a..563da9563821a 100644 --- a/stdlib/LinearAlgebra/src/eigen.jl +++ b/stdlib/LinearAlgebra/src/eigen.jl @@ -230,7 +230,7 @@ julia> vals == F.values && vecs == F.vectors true ``` """ -function eigen(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true, sortby::Union{Function,Nothing}=eigsortby) where T +function eigen(A::AbstractMatrix{T}; permute::Bool=true, scale::Bool=true, sortby::Union{Function,Nothing}=eigsortby) where T AA = copy_oftype(A, eigtype(T)) isdiag(AA) && return eigen(Diagonal(AA); permute=permute, scale=scale, sortby=sortby) return eigen!(AA; permute=permute, scale=scale, sortby=sortby) @@ -322,7 +322,7 @@ julia> eigvals(diag_matrix) 4.0 ``` """ -eigvals(A::StridedMatrix{T}; kws...) where T = +eigvals(A::AbstractMatrix{T}; kws...) where T = eigvals!(copy_oftype(A, eigtype(T)); kws...) """ @@ -369,7 +369,7 @@ Stacktrace: [...] ``` """ -function eigmax(A::Union{Number, StridedMatrix}; permute::Bool=true, scale::Bool=true) +function eigmax(A::Union{Number, AbstractMatrix}; permute::Bool=true, scale::Bool=true) v = eigvals(A, permute = permute, scale = scale) if eltype(v)<:Complex throw(DomainError(A, "`A` cannot have complex eigenvalues.")) diff --git a/stdlib/LinearAlgebra/test/eigen.jl b/stdlib/LinearAlgebra/test/eigen.jl index a683202feb2d2..5df14c00f8824 100644 --- a/stdlib/LinearAlgebra/test/eigen.jl +++ b/stdlib/LinearAlgebra/test/eigen.jl @@ -132,4 +132,13 @@ end @test factstring == "$(summary(e))\neigenvalues:\n$valsstring\neigenvectors:\n$vecsstring" end +@testset "eigen of an Adjoint" begin + A = randn(3,3) + @test eigvals(A') == eigvals(copy(A')) + @test eigen(A') == eigen(copy(A')) + @test eigmin(A') == eigmin(copy(A')) + @test eigmax(A') == eigmax(copy(A')) +end + + end # module TestEigen