3030
3131function check_input(:: typeof (eig_full!), A:: AbstractMatrix , DV, :: DiagonalAlgorithm )
3232 m, n = size(A)
33- @assert m == n && isdiag(A)
33+ (( m == n) && isdiag(A)) || throw(DimensionMismatch( " diagonal input matrix expected " ) )
3434 D, V = DV
35- @assert D isa Diagonal
35+ @assert D isa Diagonal && V isa AbstractMatrix
3636 @check_size(D, (m, m))
37+ @check_scalar(D, A, complex)
3738 @check_size(V, (m, m))
38- # Diagonal doesn't need to promote to complex scalartype since we know it is diagonalizable
39- @check_scalar(D, A)
40- @check_scalar(V, A, real)
39+ @check_scalar(V, A, complex)
4140 return nothing
4241end
4342function check_input(:: typeof (eig_vals!), A:: AbstractMatrix , D, :: DiagonalAlgorithm )
4443 m, n = size(A)
45- @assert m == n && isdiag(A)
44+ (( m == n) && isdiag(A)) || throw(DimensionMismatch( " diagonal input matrix expected " ) )
4645 @assert D isa AbstractVector
4746 @check_size(D, (n,))
48- # Diagonal doesn't need to promote to complex scalartype since we know it is diagonalizable
49- @check_scalar(D, A)
47+ @check_scalar(D, A, complex)
5048 return nothing
5149end
5250
@@ -70,10 +68,14 @@ function initialize_output(::Union{typeof(eig_trunc!), typeof(eig_trunc_no_error
7068end
7169
7270function initialize_output(:: typeof (eig_full!), A:: Diagonal , :: DiagonalAlgorithm )
73- return A, similar(A, real(eltype(A)), size(A))
71+ T = eltype(A)
72+ Tc = complex(T)
73+ D = T <: Complex ? A : Diagonal(similar(A, Tc, size(A, 1 )))
74+ return D, similar(A, Tc, size(A))
7475end
7576function initialize_output(:: typeof (eig_vals!), A:: Diagonal , :: DiagonalAlgorithm )
76- return diagview(A)
77+ T = eltype(A)
78+ return T <: Complex ? diagview(A) : similar(A, complex(T), size(A, 1 ))
7779end
7880
7981# Implementation
0 commit comments