The line that raises the RecursionError
is indeed:
spline_approx = lambda x: interp1d( args,fdict[k-1](args) )(x)
This line means that spline_approx
is a function that, when given x
returns interp1d(args, fdict[k-1](args)
to x
.
Since interp1d
returns the function you want to put in spline_approx
, this line can be simplified:
spline_approx = interp1d( args,fdict[k-1](args) )
which will stop throwing a RecursionError
.
Why did your source code choose RecursionError
?
In the original line, interp1d(args, fdict[k-1](args))
is not evaluated because it is inside the lambda
expression. This evaluation carries over to calling this lambda
expression.
In other words, every time you call a function from fdict
, all previous functions should evaluate interp1d(args, fdict[k-1](args))
. The problem is that args
is a sequence, so fdict[k-1]
is called as many times as args
has elements.
The number of calls, of course, is exponential, since each function must evaluate the use-case function len(args)
times. The result is a RecursionError
.
On the other hand, the new expression does evaluate interp1d(args, fdict[k-1](args))
. After this evaluation, a call to fdict[k]
will no longer cause a call to fdict[k-1]
.