-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Late-evaluating method definitions #5395
Comments
Would this be addressed just by making varargs functions faster and making it possible (or the default) to specialize them for any number of arguments? |
It would cover many usages, but I'm not sure it would cover all. For example, the suggestion in #5394 appears to require some way of generating
when
when |
The
The only advantage of the Here's a complete example for the "difficult" case of #5394:
|
Aha! In the past I have called this a "staged method" (though not everybody loves that term). There is a demo implementation here: https://github.com/JuliaLang/julia/blob/master/examples/staged.jl |
+1 for staged functions. |
Right, I belatedly realized that I should have used that term. The main problem is that, if I understand correctly, there's no good way to generate a staged function on demand, and that's really what this issue is focused on. I'm trying to deal with the combinatorial complexity of something like #5394, where C-dimensional slices from a P-dimensional array require However, I realize that there is a possible solution that someone may already be working on, which turns out to be #265. Perhaps we should continue this discussion there. |
A "real" implementation of staged methods would indeed hook into julia's method tables. Where we currently call type inference to transform the function and cache the result, we'd first call the user-written transformation. This can be thought of as writing a compiler extension; everything else in the language stays the same but the compiler gets a bit smarter. |
This would take Julia's meta-programming capability to a new height. |
dup of #7311 |
In the process of introducing Cartesian into base, I found myself wishing for a notation like this:
The idea here is that the last argument is not really a splat (and doesn't create a tuple); it's a promise to the compiler that the method will be created for any fixed
N
, for example a method forN=3
ofThis might help us get away from needing wrapper functions that use a dictionary
_getindex_cache
to implement multidimensional methods.A more complicated example would be auto-generating the slice functions described in #5394: in the absence of a late-evaluating method definition, to support slices where
P
is the dimensionality of the parent andC
of the child would requirebinomial(P,C)
method definitions. Of course, users are likely to need only a tiny fraction of these in any given session. The notation here might be similar,Note that there are two late-evaluating parameters in this case,
P
andC
.I'm not sure that the notation
...N
covers all the potential uses of this idea, but it appears to be a start.This may be mostly or entirely redundant with #3706, and if so feel free to close this.
The text was updated successfully, but these errors were encountered: