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

Complex valued expv! gives MethodError in some cases #61

Open
Lazersmoke opened this issue Jul 13, 2021 · 1 comment
Open

Complex valued expv! gives MethodError in some cases #61

Lazersmoke opened this issue Jul 13, 2021 · 1 comment

Comments

@Lazersmoke
Copy link

A = Diagonal(1 .* ones(ComplexF64,8))
b = ones(ComplexF64,8)

Ks = KrylovSubspace{ComplexF64,ComplexF64}(8,8)
arnoldi!(Ks,A,b) # After this like, Ks.H = [ 1 - epsilon + 0i ; epsilon + 0i ]
out = Vector{ComplexF64}(undef,8)
expv!(out,1.0,Ks) # Causes error

Since H[1:1,1] is hermitian, this branch goes through:

copyto!(cache, @view(H[1:m, :]))
if ishermitian(cache)
# Optimize the case for symtridiagonal H
F = eigen!(SymTridiagonal(cache))

but the efficient eigen! for SymTridiagonal matrices only works for reals (see JuliaLang/julia@fc4c69d) so you get this error:

ERROR: LoadError: MethodError: no method matching eigen!(::SymTridiagonal{ComplexF64, Vector{ComplexF64}})
Closest candidates are:
  eigen!(!Matched::SymTridiagonal{var"#s832", V} where {var"#s832"<:Union{Float32, Float64}, V<:AbstractVector{var"#s832"}}) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\tridiag.jl:280
  eigen!(!Matched::SymTridiagonal{var"#s832", V} where {var"#s832"<:Union{Float32, Float64}, V<:AbstractVector{var"#s832"}}, !Matched::UnitRange) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\tridiag.jl:283
  eigen!(!Matched::SymTridiagonal{var"#s832", V} where {var"#s832"<:Union{Float32, Float64}, V<:AbstractVector{var"#s832"}}, !Matched::Real, !Matched::Real) at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.6\LinearAlgebra\src\tridiag.jl:288
  ...

In the expv! code for complex t, there is this line:

F = eigen!(SymTridiagonal(real(cache)))

which just takes the real part to make it work, but this seems bad... how do you know the matrix is actually real?

Related: SciML/OrdinaryDiffEq.jl#1447 (comment)

@jarlebring
Copy link
Contributor

The MethodError is quite common in Julia when there is no specialized version of the code for that type so I'm not sure what you want instead. Somtimes it is better to throw an error than give wrong results or slow computations.

For the expv!-case, can you construct an MWE?

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

Successfully merging a pull request may close this issue.

2 participants