Skip to content

Commit

Permalink
Broaden signature of eigen and eigvals to AbstractMatrix to allow for…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>

* Update stdlib/LinearAlgebra/test/eigen.jl

Co-Authored-By: Nick Robinson <[email protected]>
  • Loading branch information
andreasnoack and nickrobinson251 authored Jun 19, 2019
1 parent 1e06e68 commit 5fa469b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stdlib/LinearAlgebra/src/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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...)

"""
Expand Down Expand Up @@ -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."))
Expand Down
9 changes: 9 additions & 0 deletions stdlib/LinearAlgebra/test/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5fa469b

Please sign in to comment.