Repository: JuliaLinearAlgebra/GenericLinearAlgebra.jl (julia)

Issue:
Can't compute eigenvalues of Hermitian Diagonal matrix for generic types
As the title says, the following code fails:
```julia
using LinearAlgebra
using GenericLinearAlgebra
m = Hermitian(Diagonal(randn(BigFloat,2)))
eigvals(m)
```
This is not related to `BigFloat`, it also fails for `Double64` and `Float128`. I think the underlying issue is the same as JuliaLang/LinearAlgebra.jl#1056, the lack of a universal fallback.

To make life even stranger, after `GenericLinearAlgebra` is loaded this code starts failing even for `Float64`. That is,
```julia
using LinearAlgebra
m = Hermitian(Diagonal(randn(Float64,2)))
eigvals(m)
```
works fine, but
```julia
using LinearAlgebra
using GenericLinearAlgebra
m = Hermitian(Diagonal(randn(Float64,2)))
eigvals(m)
```
fails.

I had previously reported this issue under JuliaLang/LinearAlgebra.jl#1070 under the misconception that `GenericLinearAlgebra` was a standard library, but @aravindh-krishnamoorthy noted that it isn't, and this issue is not caused by `LinearAlgebra`.

Pull request:
Fixes #139

Patch:
diff --git a/src/eigenSelfAdjoint.jl b/src/eigenSelfAdjoint.jl
index d8008d3..fb683ca 100644
--- a/src/eigenSelfAdjoint.jl
+++ b/src/eigenSelfAdjoint.jl
@@ -633,29 +633,35 @@ eigen2(A::Hermitian, tol = eps(float(real(one(eltype(A)))))) = eigen2!(copy(A),
 
 # First method of each type here is identical to the method defined in
 # LinearAlgebra but is needed for disambiguation
+const _eigencopy_oftype = if VERSION >= v"1.9"
+    LinearAlgebra.eigencopy_oftype
+else
+    LinearAlgebra.copy_oftype
+end
+
 function LinearAlgebra.eigvals(A::Hermitian{<:Real})
     T = typeof(sqrt(zero(eltype(A))))
-    return eigvals!(LinearAlgebra.copy_oftype(A, T))
+    return eigvals!(_eigencopy_oftype(A, T))
 end
 function LinearAlgebra.eigvals(A::Hermitian{<:Complex})
     T = typeof(sqrt(zero(eltype(A))))
-    return eigvals!(LinearAlgebra.copy_oftype(A, T))
+    return eigvals!(_eigencopy_oftype(A, T))
 end
 function LinearAlgebra.eigvals(A::Hermitian)
     T = typeof(sqrt(zero(eltype(A))))
-    return eigvals!(LinearAlgebra.copy_oftype(A, T))
+    return eigvals!(_eigencopy_oftype(A, T))
 end
 function LinearAlgebra.eigen(A::Hermitian{<:Real})
     T = typeof(sqrt(zero(eltype(A))))
-    return eigen!(LinearAlgebra.copy_oftype(A, T))
+    return eigen!(_eigencopy_oftype(A, T))
 end
 function LinearAlgebra.eigen(A::Hermitian{<:Complex})
     T = typeof(sqrt(zero(eltype(A))))
-    return eigen!(LinearAlgebra.copy_oftype(A, T))
+    return eigen!(_eigencopy_oftype(A, T))
 end
 function LinearAlgebra.eigen(A::Hermitian)
     T = typeof(sqrt(zero(eltype(A))))
-    return eigen!(LinearAlgebra.copy_oftype(A, T))
+    return eigen!(_eigencopy_oftype(A, T))
 end
 
 # Aux (should go somewhere else at some point)


Test patch:
diff --git a/test/eigenselfadjoint.jl b/test/eigenselfadjoint.jl
index e6f6c4f..9565647 100644
--- a/test/eigenselfadjoint.jl
+++ b/test/eigenselfadjoint.jl
@@ -156,4 +156,12 @@ using Test, GenericLinearAlgebra, LinearAlgebra, Quaternions
             @test abs.(eigen(A).vectors) == abs.(eigen(T).vectors) == abs.(eigen(A; sortby=LinearAlgebra.eigsortby).vectors) == abs.(eigen(T; sortby=LinearAlgebra.eigsortby).vectors)
         end
     end
+
+    if VERSION >= v"1.9"
+        @testset "#139" begin
+            A = Hermitian(Diagonal([1.0, 2.0]))
+            @test eigvals(A) == diag(A)
+            @test eigen(A).values == diag(A)
+        end
+    end
 end