JuliaMath / JuliaMath/Interpolations.jl
Feature request: Interpolate one array, "re-use" weights on other arrays
- Dominant language
- Julia
- Stars
- 575
- Forks
- 117
- PR merge metrics
- No merged PRs in 30d
Description
In my code I need to interpolate many different arrays at the same points. A signficant part of my computation time is spent on interpolating, but I can cut the time down significantly if it would be possible to "reuse" interpolation weights and positions. The following example illustrates.
something not to different from this:
```Julia
## Create arrays, interpolation objects etc
xgrid = 1:1:10
ygrid = 1:1:10
array1 = [xgrid[ix] + 1*ygrid[iy] for ix=1:length(xgrid), iy = 1:length(ygrid) ]
array2 = [xgrid[ix] + 2*ygrid[iy] for ix=1:length(xgrid), iy = 1:length(ygrid) ]
array3 = [xgrid[ix] + 3*ygrid[iy] for ix=1:length(xgrid), iy = 1:length(ygrid) ] # Three arrays defined over the same grids
array1_intrp = LinearInterpolation((xgrid,ygrid),array1,extrapolation_bc=Line())
array2_intrp = LinearInterpolation((xgrid,ygrid),array2,extrapolation_bc=Line())
array3_intrp = LinearInterpolation((xgrid,ygrid),array3,extrapolation_bc=Line()) # Three interpolations objects
## Do lots of calculations that require calling the interpolation objects many times
for i = 1:1000 # big loop
i = 1
x = 10.0/i # Some values which depends on which iteration I am on
y = 10.0/i
val1 = array1_intrp(x,y)
val2 = array2_intrp(x,y)
val3 = array3_intrp(x,y)
val = function(val1,val2,val3) # some function that combines the three interpolated values
end
```
Now, the point is that since all of the interpolations are evaluated at the same values `(x,y)` and are "defined" on the same grids, we don't really need to do all the calculations to find `val2, val3`, since we can reuse the weights that were used in finding `val1`.
Then the question becomes:
1. Is this currently possibly? If yes, then
1.1 Is it possible to make interpolations.jl export the weights and closest grid points so that I can manually perfrom the interpolations from `val2,val3`?
1.2 Is there a way to tell interpolations to just interpolate three objects at the same time?
2. Is this something you would consider adding in the future?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.