JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
http://juliamath.github.io/Interpolations.jl/
Other
524 stars 110 forks source link

Implement inplace GriddedInterpolation #496

Closed jaemolihm closed 2 years ago

jaemolihm commented 2 years ago

I implemented inplace GriddedInterpolation. Closes #495

Example:

    knots = ([0., 1.],)
    y = view([1., 2.], :)
    f1 = interpolate(knots, y, Gridded(Linear()))
    f2 = interpolate!(knots, y, Gridded(Linear()))
    y .= 0
    @test f1(0.5) ≈ 1.5
    @test f2(0.5) ≈ 0

This PR contains a breaking change: now Gridded interpolation with interpolate (not interpolate!) copies the coefs. (So I also changed the test of parent(itp) === A to run only for the inplace case: https://github.com/JuliaMath/Interpolations.jl/pull/496/files#diff-2601b635c79ac4a680dc705eb40012421a64af0e738b5bf152f4953de37e7ce1R47) For BSplines, this was already the case. So I made that change to make Gridded and BSpline behave the same. But, this change is not necessary for the new inplace feature, so I can revert it.

y = rand(2)
f1 = interpolate((1:2,), y, Gridded(Linear()))
f2 = interpolate!((1:2,), y, Gridded(Linear()))
g1 = interpolate(y, BSpline(Linear()))
g2 = interpolate!(y, BSpline(Linear()))
y .= 0
@info f1 g1
@info f2 g2
mkitti commented 2 years ago

This looks pretty good.

Could you fix the errors on https://github.com/JuliaMath/Interpolations.jl/blob/9dbcb647ab2f448ba27c975f67dadf01681da06b/test/io.jl#L61 and https://github.com/JuliaMath/Interpolations.jl/blob/9dbcb647ab2f448ba27c975f67dadf01681da06b/test/io.jl#L68

mkitti commented 2 years ago

Could you bump the version in Projecto.toml to 0.14.0 once you get the tests passing here?

codecov[bot] commented 2 years ago

Codecov Report

Merging #496 (774371c) into master (9dbcb64) will increase coverage by 0.16%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #496      +/-   ##
==========================================
+ Coverage   86.75%   86.91%   +0.16%     
==========================================
  Files          27       27              
  Lines        1819     1819              
==========================================
+ Hits         1578     1581       +3     
+ Misses        241      238       -3     
Impacted Files Coverage Δ
src/gridded/gridded.jl 96.82% <100.00%> (+4.76%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9dbcb64...774371c. Read the comment docs.

mkitti commented 2 years ago

I hope to merge this as is with test passing in less than 24 hours. Thanks.

mkitti commented 2 years ago

Also could you write some documentation for this, or at least add the example to the docs.

jaemolihm commented 2 years ago

Thanks for the comments! I bumped version and added an example to the docs.

mkitti commented 2 years ago

I plan on releasing next week. Feel free to ping me if that does not happen. Thanks again.

jaemolihm commented 2 years ago

@mkitti This is a gentle ping for the release

mkitti commented 2 years ago

I'll get it done this week.

mkitti commented 2 years ago

Released: https://github.com/JuliaMath/Interpolations.jl/releases/tag/v0.14.0