-
Notifications
You must be signed in to change notification settings - Fork 89
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
How to implement vect
#492
Comments
In this case I think you want to move the |
Just using |
Good catch, thanks @simeonschaub . I've actually just gone down the |
Haha you just beat me to it! |
Oh, nice! I actually wasn't aware that we special-cased closures over static parameters like this. |
Heh. Arrays also sometimes get promoted, e.g.: julia> [[1,2], [3,4.0+im]]
2-element Vector{Vector{ComplexF64}}:
[1.0 + 0.0im, 2.0 + 0.0im]
[3.0 + 0.0im, 4.0 + 1.0im]
julia> [[1,2]', [3 4]]
2-element Vector{AbstractMatrix{Int64}}:
[1 2]
[3 4]
Yes, the final version thought it safest to leave that undefined, so that any changes would be possible later. The competing idea was to make it ignore anything it doesn't (yet) understand how to project, in which case it could be applied blindly. That may ultimately be the right thing. For instance if you have a type (which is not an array) and define your own ProjectTo methods, under the present design they will never be called except in rules you write. In FluxML/Zygote.jl#1044 Zygote I made a But for |
Maybe while thinking about julia> Meta.@lower Int[1,2,3]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = Base.getindex(Int, 1, 2, 3)
└── return %1
))))
julia> Meta.@lower Int[1 2; 3 4]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = Core.tuple(2, 2)
│ %2 = Base.typed_hvcat(Int, %1, 1, 2, 3, 4)
└── return %2
)))) |
I learned something new here.
Ah, great. I'm going through the process of getting back up to speed after all of the progress that's been made the last couple of months (which has been fantastic), so this context is helpeful.
Good point. In any case, I could actually see any tests for in in Zygote, so my feeling is that it's probably safe to restrict the arguments to
I had literally no idea that was how this is implemented. I don't think I'll address it in #491 if that's okay, but I agree that it would be good to cover. |
if you're taking about but when you start looking at all the Anyway, probably a deep but maybe worthwhile rabbit hole 🐰 |
Ah, no, I was just referring to the fact that |
I was oddly pleased when I discovered this. Nobody felt the need to make an
|
oh, yeah, lol -- that is wild -- sometimes i feel better not to know these things (in case i'm tempted to use them) on the otherhand i agree it's oddly pleasing |
Next question is how to make
|
Alas, not making The question becomes what to do about it. Should we generalise |
One potential edge case that we could add is when |
The short-term solution is I think not to project at all, when you aren't sure that it's safe. That seems OK, we don't guarantee 100% application of this thing, still have many rules which don't apply it yet even though they could. |
Okay, cool. I'll add another method which accepts anything and doesn't project. Do you think it would be worth starting to assemble a list of rules where we think the implementation is dubious due to a lack of projection? |
Might be premature to make a list, there are lots which just nobody has got around to, I have a branch which fixes a dozen somewhere... @pabloferz was complaining that some of them don't play well with GPUs, the solution to which may also involve weakening slightly the "guarantee" about how universally projection will happen. (And turning more branches into dispatch.) |
Sorry, I'm not trying to suggest that we need to act on the list immediately, I just don't want us to risk forgetting that this is a thing that will probably have to be addressed at some point. |
#491 implements
vect
for two special cases, but neglects the general case because I couldn't figure out how to implement it in a type-stable manner forNumber
s, or at all in general.My attempt at an implementation for
Number
s wasbut it's type-unstable because the type of
X\bar
couldn't be inferred (Julia 1.6.2). I'm not entirely sure why it can't figure it out.The
Number
specialisation of this function is interesting because it highlights that when an array is constructed invect
, the type of the elements changes from their original types some of the time but not others. For example, this isn't the case with subtypes ofAbstractArray
, which essentially pass through unchanged. I'm not sure how to do with this in general, becauseProjectTo
isn't defined for all types (onlyNumber
s andAbstractArray
s AFAICT), so we can't rely on it in general.Any thoughts on either of these issues?
The text was updated successfully, but these errors were encountered: