Why would these errors pop up?

Hi all. I am new to Julia and not familiar on troubleshooting my code in this language. I have constructed a block matrix constructed of smaller block matrices - a diagonal one and then an off diagonal one. The construction follows from a function I did, and if I diagonalize this matrix, it returns the respective eigenvalues from it. The matrix has a dimensionality 4N x 4N where N comes from another function - this is a little irrelevant, since I have proven it all works.

Well, when I try to get multiple arrays of eigenvalues following from the variables I feed into the function, I get the following errors:

InexactError: Float64(-8987.992438638395 - 0.008932123138978246im)

Stacktrace:
 [1] Real at .\complex.jl:37 [inlined]
 [2] convert at .\number.jl:7 [inlined]
 [3] setindex! at .\array.jl:849 [inlined]
 [4] macro expansion at .\multidimensional.jl:802 [inlined]
 [5] macro expansion at .\cartesian.jl:64 [inlined]
 [6] macro expansion at .\multidimensional.jl:797 [inlined]
 [7] _unsafe_setindex!(::IndexLinear, ::Array{Float64,2}, ::Array{Complex{Float64},1}, ::Int64, ::Base.Slice{Base.OneTo{Int64}}) at .\multidimensional.jl:789
 [8] _setindex! at .\multidimensional.jl:785 [inlined]
 [9] setindex!(::Array{Float64,2}, ::Array{Complex{Float64},1}, ::Int64, ::Function) at .\abstractarray.jl:1153
 [10] top-level scope at .\In[38]:4
 [11] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

Coming from a python background I find it hard to check where my errors are located at. Can someone help me recognize this error and where to find some additional information about it?

It would be better if you provided a minimal working example. But it seems that you are getting complex eigenvalues and trying to add them into a an array which is set to be of Float64 numbers?

The explicit meaning of the error is just this, for example:

julia> x = sqrt(Complex(-1))
0.0 + 1.0im

julia> Float64(x)
ERROR: InexactError: Float64(0.0 + 1.0im)
Stacktrace:
 [1] Float64(::Complex{Float64}) at ./complex.jl:37
 [2] top-level scope at REPL[22]:1

julia> y = [1.0,2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> y[1] = x
ERROR: InexactError: Float64(0.0 + 1.0im)
Stacktrace:
 [1] Real at ./complex.jl:37 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] setindex!(::Array{Float64,1}, ::Complex{Float64}, ::Int64) at ./array.jl:847
 [4] top-level scope at REPL[26]:1

Somewhere a complex value is trying to be converted to a Float64, maybe to be added to a vector of floats.

1 Like

That’s exactly what was happening, thank you!

1 Like