finterp icon indicating copy to clipboard operation
finterp copied to clipboard

Support for multi-dimensional output

Open RRiva opened this issue 1 year ago • 3 comments

Hi @jacobwilliams, thanks for the great work! I was wondering if it would be possible to support multi-dimensional outputs. For now, I think that the API requires to initialize a different interpolator per output, which is inefficient, since it requires to find the grid points multiple times.

One way to implement this would be to declare f as assumed-rank, and then place the interpolation algorithm inside select rank. Obviously, the linear interpolation formula stays the same, and to reduce code duplication you might include a file.

What do you think about this?

RRiva avatar Jun 03 '24 12:06 RRiva

Never mind, assumed-rank cannot be used in derived types. An answer and comment list some alternatives, but I'm not too convinced. Supporting n inputs and m outputs requires n*m types, which will make the code very long and the binary unnecessarily heavy. Maybe a better solution is to generate the ranks needed by the user with Fypp. There is an example at stdlib_stats_moment_scalar.fypp.

RRiva avatar Jun 04 '24 10:06 RRiva

I'd need to think about it some more.

I guess there are two inefficiencies currently:

  • storing the independent arrays multiple times (x,y,...). this is a RAM issue.
  • searching for the intervals (the calls to dintrv) is redundant. This is a runtime issue.

For the 2nd one, a workaround might be to add the ability to cache the dintrv outputs for one and push them to others. So, the first one you interpolate will make that call, but the other dimensions won't have to. Just some thoughts.

jacobwilliams avatar Sep 07 '24 15:09 jacobwilliams

Thanks for looking into this 🙂 I think that there might be a simpler solution: the output could be reshaped to 1D array for each point, so a 2D array in total, during the initialization, and then reshaped back after the interpolation.

RRiva avatar Sep 09 '24 06:09 RRiva