jacobwilliams / finterp

Multidimensional (1D-6D) Linear and Nearest-Neighbor Interpolation with Modern Fortran
Other
54 stars 11 forks source link

Support for multi-dimensional output #8

Open RRiva opened 1 month ago

RRiva commented 1 month ago

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 commented 1 month ago

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.