StackOverflowError with julia v1.1 similar to previous bug v0.7


#1

Hi everyone,

I’ve been dealing with a similar error that this one. The output is the following:

ERROR: LoadError: StackOverflowError:
Stacktrace:
 [1] (::Interpolations.GriddedInterpolation{Float64,1,Float64,Gridded{Linear},Tuple{Array{Float64,1}}})(::Float64, ::Int64) at /home/tomas/.julia/packages/Interpolations/0OnYb/src/gridded/indexing.jl:8 (repeats 80000 times).

When executing the following code:

if !isempty(I3)
    println("typeof(table)=",typeof(table));
    open("t.txt", "w") do ff
    writedlm(ff,table);
end
table=readdlm("t.txt");
intf = interpolate( (table[:,2],) , table[:,1] , Gridded(Linear()));
 

The weird thing is that when I run a new Julia process in the same directory with this:

table=readdlm("t.txt");
intf = interpolate( (table[:,2],) , table[:,1] , Gridded(Linear()));

it works perfectly…

typeof(table)=Array{Float64,2} and its size 12000x2.

Thanks!


#2

Please provide a minimal self-contained example.


#3

Hello Tamas,
Thank you for your response.
Here a minimal self-contained example that replicates the error msg (here are the input files):

using Distributions,DelimitedFiles,Interpolations
function backtr(y,table,zmin,zmax,tail)

#----------------------------------------------------
# Back-transformation from Gaussian to original scale
#----------------------------------------------------

    p = size(table,1);
    m,n = size(y);
    z = zeros(m,n);


# Do not perform back-transformation if the conversion table is empty
#--------------------------------------------------------------------

    if isempty(table)
      z = y;
      return z;
    end

# Values in the lower tail (exponential extrapolation)
#-----------------------------------------------------

    z1 = table[1,1];
    y1 = table[1,2];
    I1 =  (LinearIndices(y))[findall( x->(x < y1), y)];


    if !isempty(I1)
      b0 = (z1-zmin)*exp.(-tail[1]*y1);
      z[I1] = zmin .+ b0*exp.(tail[1]*y[I1]);
    end

# Values in the upper tail (exponential extrapolation)
#-----------------------------------------------------

    zp = table[p,1];
    yp = table[p,2];

    I2 = (LinearIndices(y))[findall( x->(x > yp), y)];# find(y>yp);

    if !isempty(I2)
      bp = (zp-zmax)*exp(tail[2]*yp);
      z[I2] = zmax .+ bp*exp.(-tail[2]*y[I2]);
    end

# Within-class values
#--------------------

    I = sort(union(I1,I2));
    I3 = [ii for ii=1:(m*n)];
    deleteat!(I3,I);

    if !isempty(I3)
      # println("typeof(table)=",typeof(table));
      # open("t.txt", "w") do ff
      #   writedlm(ff,table);
      # end
      # table=readdlm("t.txt");
      intf = interpolate( (table[:,2],) , table[:,1] , Gridded(Linear()));
      z[I3] = Float64[intf(zz,1) for zz in y[I3] ]; # Table lookup
    end

    return z
end

simu=readdlm("simu.txt");
tableZY=readdlm("tableZY.txt");
zmin,zmax=readdlm("zmin-zmax.txt");
tail=readdlm("tail.txt");
simu = backtr(simu,tableZY,zmin,zmax,tail);

Thanks in advance. Let me know if you need something else.


#4

Note that this example is far from minimal — you could generate the arrays randomly, include the zmin and zmax as constants, etc.

That said, you can replace the block at the end with

    intf = interpolate( (table[:,2],) , table[:,1] , Gridded(Linear()));
    I3, intf, y

and just call

I3, intf, y = backtr(simu,tableZY,zmin,zmax,tail);

which should allow you to study your error as

intf(first(y[I3]), 1)

where I think it comes from having an incorrect number of arguments, as you are interpolating a one-dimensional function. But you could report the minimal case as an issue with Interpolations, which could perhaps give a more informative error (but I don’t know the details). The one-argument verison

intf(first(y[I3]))

works.


#5

You are right, it works when you remove the

, 1

Yes, I can set the z constants without reading a file, but

simu=readdlm("simu.txt");

takes me thousands of lines of codes to get, and

tableZY=readdlm("tableZY.txt");

actually depends on an input that I read and has the same size, so adding more code is pointless. Do you think I should open an issue on Interpolations with a somewhat minimal self-contained example?
Otherwise I think this problem is solved.
Thanks!


#6

Yes, I think it is worth doing. But check existing issues first. This may serve as an MWE:

using Interpolations
itp = interpolate(((0:10)./10, ), sort(rand(11)), Gridded(Linear()));
itp(1.0, 1)