-
-
Couldn't load subscription status.
- Fork 216
preserve type over broadcast #1302
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
Conversation
|
Glad existing tests pass with this. Is there an easy way to test the new behaviour? Ideally hitting both paths (i.e. broadcasting a fairly simple function and a nasty one). Is there a simple package with an array type for which the old code didn't work & the new does? |
|
I guess LinearAlgebra.Diagonal could serve as a test (it does fail on master, and works here)? I'm not sure what the cleanest way is of hitting the slow fallback though |
|
One way to be sure of hitting the slow path is to broadcast a closure, like |
|
I'll probably return to this tomorrow, adding some simple tests |
|
Am not sure Diagonal will work as a test, and the one in ea21486 seems to pass on tagged Zygote. In general its map & broadcast seem to agree: I thought perhaps there were some disagreements for Adjoint, but now I don't see them. Something like Is it possible that the issue here is just that the original array type lacks such an overload? Or maybe there's a reason it cannot? |
|
I am also not entirely sure anymore - the documentation about implementing your own array types at the very least does not mention overloading map, but does mention specifying the broadcaststyle (which determines the output type of broadcasts) (see https://docs.julialang.org/en/v1/manual/interfaces/ ) This map vs broadcast thing could cause other problems, but I feel that in general julia really should make both broadcast and map use the same output type automatically. Using only base types I could come up with this example: |
|
Note that many functions like I think the one with a splat calls this. The docs mention |
|
But would you then rather not change zygote to correctly call broadcast where it should? Consider the example of Set, where map errors while broadcast works just fine. I really don't like having to define methods outside the official recommended interface, just to work around something that zygote arguably does wrong |
|
I do think this is the documented interface, although I agree many implementations don't quite follow it (including some which I wrote). Making Zygote more forgiving is OK. I can't see a way to push a Set into this bit of Zygote. Supposedly it does support Dict, for which neither broadcast nor map works. I think even Tuple doesn't reach this code, only arrays. One reason people write |
fixes #1301