Skip to content
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

Array Indexing Error #597

Closed
lhnguyen-vn opened this issue Apr 12, 2020 · 2 comments
Closed

Array Indexing Error #597

lhnguyen-vn opened this issue Apr 12, 2020 · 2 comments

Comments

@lhnguyen-vn
Copy link

I ran into a Zygote bug related to array slicing. Here's a MWE:

array = [[1,2], [3,4], [5,6]]
_, back = Zygote.pullback(x -> x[1:2], array)
back([[1,1], [1,1]]) # MethodError: no method matching +(::Nothing, ::Array{Int64,1})

This is a relatively well-known issue, Zygote uses nothing as a stronger zero. Internally, this is the source of the error:

dx = _zero(x, eltype(dy))
dxv = view(dx, inds...)
dxv .+= _droplike(dy, dxv)

Shouldn't the last line just be dxv .= _droplike(dy, dxv)? This gives the correct behavior and I can't think of why one would want to add to an array filled with nothing instead?

@lhnguyen-vn
Copy link
Author

On second thoughts, .+= is correct. Perhaps _zero should be extended for arrays of arrays, something along the line of

_zero(xs::AbstractArray{<:AbstractArray}, T=Any) = [_zero(x) for x in xs]

This gives the correct gradient for my case, and I notice also solves issue #454.

@AzamatB
Copy link
Contributor

AzamatB commented Jun 18, 2020

This seems to be fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants