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

Don't mark fill! non-differentiable #515

Merged
merged 2 commits into from
Aug 27, 2021
Merged

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Aug 27, 2021

Closes #514:

julia> Zygote.gradient((x,y) -> sum(fill!(x,y)), [1,2,3], 4)
ERROR: Mutating arrays is not supported -- called setindex!(::Vector{Int64}, _...)

Original non-diff rule being removed here is from #310 I believe.

@mcabbott mcabbott merged commit ddc4677 into JuliaDiff:master Aug 27, 2021
@CarloLucibello
Copy link
Contributor

This caused regressions in some of my code. In fact, it is not uncommon to write a = fill!(similar(x), 0),
we have many examples also in this repo. I'll file a PR with the rrule!

@CarloLucibello CarloLucibello mentioned this pull request Sep 1, 2021
@mcabbott
Copy link
Member Author

mcabbott commented Sep 1, 2021

Sorry about breaking things.

But how can that work without getting this wrong? Sorry, this is the bit that's easy to get right:

julia> Zygote.gradient((x,y) -> sum(fill!(x,y)), [1,2,3], 4)
(nothing, nothing)

julia> Zygote.gradient((x,y) -> sum(map(_ -> y, x)), [1,2,3], 4)
([nothing, nothing, nothing], 3)

The hard part is that similar(x) might be used elsewhere, and I don't think Zygote can know.

@mcabbott mcabbott deleted the fill_bang branch September 1, 2021 04:06
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

Successfully merging this pull request may close these issues.

Rule for fill! is wrong
3 participants