-
Notifications
You must be signed in to change notification settings - Fork 26
WIP: metaprogramming-based interpolation #38
Conversation
There's one important thing to discuss: interpolation of multi-valued functions. Let's say I had an RGB image but for some reason didn't want to use the RGB immutable. Then each spatial location is 3-valued. The original implementation somewhat awkwardly allowed you to set the position once and then calculate the interpolated value re-using the same set of coefficients. Since this version doesn't define any temporary storage, that becomes more awkward. We could reintroduce the storage, but I also wonder if there is a nicer API for this. For example, Thoughts? |
Huh. Cool. And somewhat magical... I must admit that this code is even more opaque to me at first sight than the previous version - especially since so much happens in contexts where it's not always straightforward to see what various variables represent. (Stepping through code in my head is difficult enough - doing it through code that I first had to generate in my head makes it more difficult. Not very surprising... :P) Documentation and some examples in comments, once we're done, will probably help this quite a lot. However, I do find it very elegant how it seems like every combination of interpolation order and boundary condition can be expressed with a A couple of comments:
|
Yeah, this is the big negative of this approach. We don't have to go this way; it's more important that this works for those nice people who help make Grid better 😄, even if we have to give up some on performance. I'm willing to accept your guidance on where the right balance is. One tip, though: at least at first, instead of generating the code in your head, try calling (for example)
Absolutely. This was merely to give you a sense for what I was thinking about, upon which you might consider basing your own extensions.
Hm, that is interesting. I hadn't thought about whether one wants to encode the "spatial" dimensionality in the type. I'll have to think this through more carefully. |
@tlycken, are we good to go with this approach? I'm thinking of punting on the multi-valued issue for now. There's another approach we could take: since the low-level API will be quite different, and that low-level API is considered "public," we could just start a new |
This also: - compares against the correct answer - provides a number of fixes to many of the boundary conditions - add a BCinbounds type that avoids any bounds-checking
Yeah, sure - I'm willing to learn what I need to understand the meta-programming approach, and it does look like it could provide a better framework. However, I like the suggestion to deprecate If we don't introduce any big changes to |
Also, OT but maybe relevant for the implementation of this: I'm going to be afk with no internet connection for most of August, so don't hold your breath for replies from me if you don't have very big lungs =) |
Sounds like a fun time! OK, I'll start a new package. I'm immersed in other things at this moment, so this will unfold over time. Thanks for getting back to me. |
I'm back from the bush, and have started taking a look at this a little more closely. I think I'm getting the hang of how linear interpolation works in 1D, but I can't seem to wrap my head around the general principle for how multidimensional interpolation maps to recursion. (I've started reading this paper, but it's a long read...) For the linear case it's quite straightforward, but for e.g. quadratic or cubic B-splines it's not at all clear to me how (or even that) it works. Anyway, it seems like a good approach, given that it can be generalized to higher-order interpolation, so I'm all for continuing with it. I think maybe the structure could be somewhat different to make new additions easier - and maybe that will help finding some more descriptive function names as well... - I'll see if I can come up with an example for (at least) linear interpolation. |
Welcome back! Hope you had a blast. To be honest, I haven't thought about higher-order interpolation at all. I've just assumed it will work similarly. I'm currently utterly swamped by JuliaImages/Images.jl#135, so it will still be a little while before I can get to this. I did remember that I have a commit I never pushed (one that fleshes out the Linear case more completely). I'll push now. |
Looks like it got sorted based on date, so you'll have to scroll up to find it. |
Nice! I took the liberty of stealing some of your code, rewriting some of it quite a lot, and re-packaging it in a new (yet unregistered) package Interpolations.jl. It does almost exactly the same thing as yours, but it has the additional benefit of separation of boundary conditions and extrapolation behavior. |
Woot! Very exciting. Thanks for doing this! |
Now that Interpolations.jl exists, should we close this PR and continue discussion there? |
Closing in favor of Interpolations.jl. |
OK, here's a prototype of the kind of thing I had in mind with #36. You can test by checking out the cartesian branch and then, from the
test/
directory sayingIn each case, old is on top and new is on the bottom. The first pair is for 1d, the second for 2d.
The improvement is not as large as I expected, but it's still substantial. Bounds-checking takes more time than the actual computation, at least in 1 & 2 dimensions. (You can profile to see that.)
I didn't implement all the boundary conditions, but only because I'm out of time for working on this further. I don't foresee any obstacles, though.