Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: in fieldtype, expected DataType, got Type{Union{}} #43

Closed
MatsuBasho opened this issue Mar 1, 2021 · 5 comments
Closed

TypeError: in fieldtype, expected DataType, got Type{Union{}} #43

MatsuBasho opened this issue Mar 1, 2021 · 5 comments

Comments

@MatsuBasho
Copy link

Sir,

I am struggling with the method geneigsolve of KrylovKit. With the Clement matrix C of size 101*101 whose the lowest eigenvalue is -100, when I use eigsolve: it works:

eigsolve(C, 2, :SR, eltype(C))
(Complex{Float64}[-100.00000000000057 + 0.0im, -97.9999999999994 + 0.0im], Array{Complex{Float64},1}[[-5.934823977225039e-17 + 0.0im, 3.320208037214963e-17 + 0.0im, 4.9512960751656277e-17 + 0.0im, -1.0008367950905649e-16 + 0.0im, 1.9294724938278272e-16 + 0.0im, -1.567962742202036e-17 + 0.0im, -3.9153858197655655e-17 + 0.0im, 3.1427591972433225e-18 + 0.0im, -7.05722251471179e-17 + 0.0im, 1.7906628918386472e-16 + 0.0im … 5.564153874360254e-16 + 0.0im, -4.962583320636797e-17 + 0.0im, -2.350694315844001e-16 + 0.0im, 1.7194234008369993e-16 + 0.0im, -1.4898044751323327e-16 + 0.0im, 2.1723558020234293e-16 + 0.0im, -1.6117744893327697e-16 + 0.0im, 1.2940048266310558e-16 + 0.0im, 4.700943375695305e-17 + 0.0im, -9.93535915208007e-17 + 0.0im], [-2.125811387704412e-18 + 0.0im, -2.1103217340835757e-17 + 0.0im, 4.0638801159622474e-17 + 0.0im, 3.0122951033892746e-17 + 0.0im, -7.833453391488912e-17 + 0.0im, 2.2458218145930223e-17 + 0.0im, 1.3680484459243355e-16 + 0.0im, -1.811268606205335e-16 + 0.0im, 3.0930102966243023e-16 + 0.0im, -7.470590659650482e-16 + 0.0im … -8.288981774225782e-16 + 0.0im, 2.856106009589991e-16 + 0.0im, -3.289414921445156e-16 + 0.0im, 3.156433357758001e-16 + 0.0im, 1.5492772606972423e-17 + 0.0im, -1.0742140666038115e-16 + 0.0im, 5.890215683339088e-17 + 0.0im, 5.669760393049083e-17 + 0.0im, -3.249941094882854e-17 + 0.0im, -4.870621770281174e-18 + 0.0im]], ConvergenceInfo: 2 converged values after 13 iterations and 171 applications of the linear map;
norms of residuals are given by (4.9392800197204625e-15, 3.152148007644767e-13).
)

But when I try geneigsolve, I got a error message that I don't understand, see below:

geneigsolve((C,I), 1, :SR, promote_type(eltype(C),eltype(I)))
ERROR: TypeError: in fieldtype, expected DataType, got Type{Union{}}
Stacktrace:
[1] tuple_type_head(::Type{T} where T) at ./essentials.jl:208
[2] geneigsolve(::Tuple{Tridiagonal{Float64,Array{Float64,1}},UniformScaling{Bool}}, ::Array{Float64,1}, ::Int64, ::Symbol; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:148
[3] geneigsolve(::Tuple{Tridiagonal{Float64,Array{Float64,1}},UniformScaling{Bool}}, ::Array{Float64,1}, ::Int64, ::Symbol) at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:146
[4] geneigsolve(::Tuple{Tridiagonal{Float64,Array{Float64,1}},UniformScaling{Bool}}, ::Int64, ::Symbol, ::Type{T} where T; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:139
[5] geneigsolve(::Tuple{Tridiagonal{Float64,Array{Float64,1}},UniformScaling{Bool}}, ::Int64, ::Symbol, ::Type{T} where T) at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:139
[6] top-level scope at REPL[32]:1

Please, could you explain me how to fix it ?

Sincerely,

Etienne

@Jutho
Copy link
Owner

Jutho commented Mar 1, 2021

It seems you were entering geneigsolve((A, I), ...) with A some Tridiagonal matrix and I the LinearAlgebra.UniformScaling object. The problem is that the latter is not recognized as a matrix (literally, because UniformScaling <: AbstractMatrix is false), but I can fix that. However, alternatively, if you would want to use the identity matrix in geneigsolve (you are better of using eigsolve in that case, but anyway, for testing purposes), you could also do so by using geneigsolve((A, identity), ...). Here, identity is a standard Julia function which just returns its argument.

@MatsuBasho
Copy link
Author

Thank you for your reply, I wanted to test geneigsolve in the most simplest case (with B = I) in order to understand it before really using it. That being said, I think that there are an issue with Tridiagonal matrix. When I define A and M by:

julia> diagM = [1.0 for 1 in 1:100];

julia> diagM = [1.0 for i in 1:100];

julia> M = SymTridiagonal(diagM, subdiagM);

julia> subdiagA = [-0.5 for i in 1:99];

julia> A = SymTridiagonal(diagM, subdiagA);

and when I try geneigsolve((A,M), 3, :SR), I get:

ERROR: MethodError: no method matching cholesky(::Hermitian{Float64,SymTridiagonal{Float64,Array{Float64,1}}}; check=false)
Closest candidates are:
cholesky(::Union{Hermitian{Complex{T},SparseArrays.SparseMatrixCSC{Complex{T},Int64}}, Hermitian{T,SparseArrays.SparseMatrixCSC{T,Int64}}, Symmetric{T,SparseArrays.SparseMatrixCSC{T,Int64}}, SparseArrays.SparseMatrixCSC{T,Ti} where Ti<:Integer, SparseArrays.SparseMatrixCSC{Complex{T},Ti} where Ti<:Integer}; kws...) where T<:Real at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/SuiteSparse/src/cholmod.jl:1458
cholesky(::Union{StridedArray{T, 2} where T, Union{Hermitian{var"#s823",var"#s822"}, Hermitian{Complex{var"#s823"},var"#s822"}, Symmetric{var"#s823",var"#s822"}} where var"#s822"<:(StridedArray{T, 2} where T) where var"#s823"<:Real}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/cholesky.jl:344 got unsupported keyword argument "check"
cholesky(::Union{StridedArray{T, 2} where T, Union{Hermitian{var"#s821",var"#s820"}, Hermitian{Complex{var"#s821"},var"#s820"}, Symmetric{var"#s821",var"#s820"}} where var"#s820"<:(StridedArray{T, 2} where T) where var"#s821"<:Real}, ::Val{false}; check) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/cholesky.jl:344
...
Stacktrace:
[1] isposdef(::SymTridiagonal{Float64,Array{Float64,1}}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/dense.jl:91
[2] geneigselector(::Tuple{SymTridiagonal{Float64,Array{Float64,1}},SymTridiagonal{Float64,Array{Float64,1}}}, ::Type{T} where T) at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:164
[3] #geneigsolve#64 at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:153 [inlined]
[4] geneigsolve at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:146 [inlined]
[5] #geneigsolve#60 at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:133 [inlined]
[6] geneigsolve at /Users/etiennebernard/.julia/packages/KrylovKit/OLgKs/src/eigsolve/geneigsolve.jl:130 [inlined] (repeats 2 times)
[7] top-level scope at REPL[29]:1

Thank you in advance.

@MatsuBasho
Copy link
Author

I have found out ! With convert(Array, A), the bug is fixed....

@Jutho
Copy link
Owner

Jutho commented Mar 2, 2021

This seems to be a bug in Julia, namely isposdef does not seem to be working on SymTridiagonal matrices. I would advise to report this as a bug/issue on Julia's github page.

That being said, if you are confident that the M matrix is positive definite, you can bypass this check with geneigsolve((A,M), ...; isposdef = true)

@Jutho
Copy link
Owner

Jutho commented Mar 26, 2021

I think this is solved; feel free to reopen if not.

@Jutho Jutho closed this as completed Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants