-
-
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
Tuple of callables should be callable #32682
Comments
So this looks like an issue with
|
Apparently this is due to #31442 |
Just brainstorming... what if E.g. (I realize this is a bit annoying when you want to do |
Duplicate of #22129 |
I would like to propose allowing tuples of functions to be be
callable
and have the syntax:At the moment this is disallowed with an error, e.g.:
Another use for this would be to unpack the keys and values of a dictionary in a single line:
k,v = (keys, values)(mydict::Dict)
I do not know where
callable
is specified. Searching the docs forcallable
or in the help?callable
does not give anything concrete about how to allow something to be callable.How should broadcasting work? I think a reasonable proposal is
(f,g).(x) == (f.(x), g.(x))
. Is this ambiguous or not desirable for a reason I cannot foresee?Since
f
andg
would be accessing the same input, and likely be doing similar operations, this introduces a performance issues. It makes it really easy to write non-performant code. My assumption was that there would be a lot of duplicated work if e.g.f
andg
both look throughx
separately, they should know to share common work.This was motivated by the
(minimum,maximum)(x)
example. There is an existing function for this,extrema
which should return the same result faster:On Julia-1.1:
So you can see that this callable tuple is twice as slow. EXCEPT!
On Julia-1.3:
Ummm. So now the tuple
(minimum,maximum)
is faster thanextrema
? I don't understand this. Some threading magic?Anyway I think this is a general problem, is the compiler smart enough to let
f
andg
know about the shared work betweenf
andg
and use them together?I was going to propose explicitly dispatching to more efficient joint methods, e.g.
(T::Tuple{typeof(minimum),typeof(maximum)})(x) = extrema(x)
but not only is this ugly, very specific, and hopefully could be automatically made efficient by the compiler. It is also, as demonstrated above, less efficient than(minimum(x),maximum(x))
currently!f
mutatesx
, or if we should do anything. If it is literally the case that(f,g)(x) = (f(x),g(x))
then I guess the order of these two matter. But if its possible to do these two functions in parallel, it might be a problem. I also don't know how that might affect shared work.I would like to help implement this. I think it looks like setting up methods that look like
But as I said at the top, I don't know what decides if a type is callable.
The text was updated successfully, but these errors were encountered: