Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird inexact error in julia

Tags:

julia

I have two instances of my program tracked with git, so I know that they are in sync. One instance is in machine A and the other in machine B.

Machine A runs fine, but when I go to machine B I obtain the following error:

ERROR: InexactError()
in setindex! at array.jl:307
in setindex! at array.jl:345
in main at /path/to/main.jl:122
in include at ./boot.jl:246
in include_from_node1 at loading.jl:128
in process_options at ./client.jl:285
in _start at ./client.jl:354
in _start_3B_3587 at /home/usr/julia/usr/bin/../lib/julia/sys.so
while loading /path/to/main.jl, in expression starting on line 265

I don't understand why it throws and error. Both machines have the last master version of Julia:

Version 0.4.0-dev+3322 (2015-02-12 13:56 UTC)
Commit 1ec68b3* (0 days old master)

The lines that throw the error are

array2 = zeros(Float64,NHn*2000)
for iRealiz in 1:2000
    ...
    ij = (iRealiz-1)*NHn
    egvals_ts, egvecs_ts = eig(timeser)
    array2[ij+1:ij+NHn] = egvals_ts
    ...
end

NHn is the matrix dimension.

like image 423
user2820579 Avatar asked Feb 12 '15 17:02

user2820579


1 Answers

An Inexact Error gets thrown when you try to convert a value x to a type T that cannot represent the value of x. For example, on julia 0.4:

julia> convert(Int, 3.0)
3

julia> convert(Int, 3.2)
ERROR: InexactError()
 in convert at int.jl:189

julia> convert(UInt, -2)
ERROR: InexactError()

and finally, in what is likely relevant for your case:

julia> convert(Float64, 2+0.3im)
ERROR: InexactError()
 in convert at complex.jl:16

My theory is that roundoff errors (which are dependent on the particular CPU) caused it to return complex-valued eigenvalues on one machine but not the other.

like image 87
tholy Avatar answered Nov 09 '22 02:11

tholy