1
$\begingroup$

I want to evaluate a 2D interpolating function many times in a finite interval. What is the fastest way to do that?

I imagine that its possible to specify a discrete grid and memoize the function on this grid. Afterwards round any input value to values on this grid and call the memoized function. But I am not sure if this is the most convenient and fastest way to do.

$\endgroup$
2
  • 1
    $\begingroup$ I'd try fInt=Interpolation[...,InterpolationOrder->0] first, which is basically what you're describing. If that's not fast enough you can try to build your own version, but that might not be worth the effort. $\endgroup$ – N.J.Evans Nov 29 '17 at 15:17
  • 1
    $\begingroup$ Try using Listable functions first, because they are vectorized. Next try Mapping your functions, and last try ParallelTable to parallelise over cores. $\endgroup$ – Thies Heidecke Nov 29 '17 at 15:17
1
$\begingroup$

InterpolationFunctions are listable, but not in a very obvious way. Take the following example from the documentation:

data = Flatten[Table[{{x, y}, LCM[x, y]}, {x, 4}, {y, 4}], 1]
f = Interpolation[data]

Suppose we want to evaluate f on a grid between {1, 1} and {4, 4}:

grid = N @ Flatten[CoordinateBoundingBoxArray[{{1, 1}, {4, 4}}, Into[20]], 1]

To evaluate f on the grid points in a vectorize way, we have to use the following syntax:

f @@ Transpose[grid]

Note that this is different from the way a PredictorFunction generated by Predict works: a predictor function can directly accept grid as an argument, while InterpolationFunctions expect the arguments in successive slots.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.