-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling with function syntax? #198
Comments
@jlperla IIUC, what you're suggesting is to implement |
It is very practical, not just philosophical. But to give some perspective on how I think about this. In Julia, functions that map integers, i.e. In Julia, functions that map general parameters to parameters (e.g. What this means is that if I am writing generic code on functions, unless the interpolation supports
... all of this is to say: I think you should simply support the |
This is, I think, not exactly the common interpretation of This package was built with the interpretation of an interpolation as an extension of the concept of an That said, it's probably trivial to extend interpolation objects with function call syntax outside of the package - just define it so it forwards to |
Yes, I understand when Also, the notation in the examples
seems extremely odd to someone used to working with functions. how can you index Furthermore, it isn't really trivial to extend the function call outside of the package do the complexity of generic programming. Certainly not for a typical user (like the students of mine I would like to use this package). In every other function approximation library I can find, you call function-like things as functions, broadcasting as functions, etc. and it is very confusing that this one doesn't support that. Is there harm in just adding in the correct, no-overhead forwarding of |
For example of all the other libraries I can find that interpolate and use functions:
|
Replacing the array-indexing style of evaluating interpolation objects would be a crazily breaking change, and it would require a much better motivation than "it feels more natural to me" (because that argument can be, and is, used by both sides). So, to be frank, that is not going to happen anytime soon, and quite possibly never. What is still on the table is extending the current behavior with function call syntax in a backwards-compatible manner. It's been a while since i wrote some serious Julia code, but from my interpretation of this section of the manual it shouldn't require many lines of code to write something that treats interpolation objects like callable functors, and basically defines Due to the extensible nature of Julia, this is just as easy to do outside of the package as inside it, and my guess is that it would, in total, only be a handful of lines of code. My suggestion is that you try to make that work in your own code - it shouldn't require any deep knowledge of the library, just that you want to make the function call forward to |
It shouldn't be outside of this package because that could be considered a form of type-piracy and would (at least should) be blocked in METADATA. And IMO it's weird that the call doesn't work because it means that any things which you would use an interpolation of data for, like for approximating integrals via I think it would be quite a usability enhancement to just define the call. It would just be: (b::BSplineInterpolation)(args...) = b[args...] etc. for each concrete interpolation (it cannot be done on an abstract type). |
Again, it's been a while since I was actively involved with the Julia community, but this is very contrary to the sentiment that was common back when (as in, up to a couple of years ago). What changed? Are there other instances of this discussion, that I could read up on? Other packages or situations where this has been discussed and/or discouraged? Also, note that I'm absolutely not saying it's never going to be in the package (lots of negations there, sorry...). What I'm saying is that
|
No, type-piracy has never been encouraged. Write your own functions on other people's types, you can extend other people's functions with your own types, and mixtures like that are fine. It's very much discouraged to extend functions (or calls) that you don't own with types that you don't own, since that form of type-piracy can break other people's code without warning (there are some weird examples you can cook up). It's the same as in other languages where it's generally not a good idea to monkey patch some other person's package.
There is a technical limitation that if two packages do this outside of the package, and do it differently, then they will overwrite each other, which is why this kind of thing is discouraged / not allowed with registered packages. |
OK, that makes sense - thanks for explaining.
That's not what I had in mind - I say you (or @jlperla) could do this in your own scripts, to see if it solves the problems you hope it will. If it does, feel free to file a PR. But there's no need to include it in any package - this or another - to be able to use it in a program. |
I think your perspective changes somewhat depending on what you are using it for, but I strongly dislike having to call the interpolated function with array indexing as opposed to functions. For example, given the following interpolation of a function?
Now add in...
Is there any reason not to add in this function (at least for gridded?)
The text was updated successfully, but these errors were encountered: