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

**URL:** <https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531>\
**Category:** Geo\
**Created:** [February 7, 2019, 5:40am UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531 "2019-02-07T05:40:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlagos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlagos/32/4490_2.png) [@tlagos](https://discourse.julialang.org/u/tlagos)\
**Post date:** [February 7, 2019, 5:40am UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/1 "2019-02-07T05:40:27Z")

</div>

Hi everyone,

I’ve been dealing with a similar error that [this one](https://github.com/JuliaMath/Interpolations.jl/issues/215). The output is the following:

```julia
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:

```julia
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:

```julia
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!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 7, 2019, 8:23am UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/2 "2019-02-07T08:23:29Z")

</div>

Please provide a minimal self-contained example.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![tlagos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlagos/32/4490_2.png) [@tlagos](https://discourse.julialang.org/u/tlagos)\
**Post date:** [February 7, 2019, 1:38pm UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/3 "2019-02-07T13:38:00Z")

</div>

Hello Tamas,  
Thank you for your response.  
Here a minimal self-contained example that replicates the error msg [(here are the input files)](https://www.dropbox.com/sh/w3frje24jin54jt/AADElD_0GN30-30pXI97vcWja?dl=0):

```julia
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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 7, 2019, 2:04pm UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/4 "2019-02-07T14:04:50Z")

</div>

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

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

```

and just call

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

```

which should allow you to study your error as

```julia
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

```julia
intf(first(y[I3]))

```

works.

---

<div class="post-metadata">

**Author:** ![tlagos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlagos/32/4490_2.png) [@tlagos](https://discourse.julialang.org/u/tlagos)\
**Post date:** [February 7, 2019, 5:20pm UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/5 "2019-02-07T17:20:15Z")

</div>

You are right, it works when you remove the

```julia
, 1

```

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

```julia
simu=readdlm("simu.txt");

```

takes me thousands of lines of codes to get, and

```julia
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!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 7, 2019, 5:26pm UTC](https://discourse.julialang.org/t/stackoverflowerror-with-julia-v1-1-similar-to-previous-bug-v0-7/20531/6 "2019-02-07T17:26:42Z")

</div>

> [@tlagos](#):
>
> open an issue on Interpolations with a somewhat minimal self-contained example?

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

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

```
