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

Rule for fill! is wrong #514

Closed
mcabbott opened this issue Aug 27, 2021 · 2 comments · Fixed by #515
Closed

Rule for fill! is wrong #514

mcabbott opened this issue Aug 27, 2021 · 2 comments · Fixed by #515

Comments

@mcabbott
Copy link
Member

I believe these should all be (Zero, 3):

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)

julia> Diffractor.gradient((x,y) -> sum(fill!(x,y)), [1,2,3], 4)
(ChainRulesCore.NoTangent(), ChainRulesCore.NoTangent())

julia> Diffractor.gradient((x,y) -> sum(map(_ -> y, x)), [1,2,3], 4)
ERROR: AssertionError: Base.issingletontype(typeof(f))
Stacktrace:
 [1] (::∂⃖{1})(#unused#::typeof(map), f::Function, a::Vector{Int64})
   @ Diffractor ~/.julia/packages/Diffractor/K2lJa/src/jet.jl:185

More generally, should in-place functions which completely overwrite their input be allowed? Like circshift! or sum! or mul!.

@oxinabox
Copy link
Member

oxinabox commented Aug 27, 2021

In forward mode they should be allowed.
In reverse they shouldn't (yet)

@mcabbott
Copy link
Member Author

Oh right. Because some pullback may be relying on this array still having the same values, when it eventually gets called.

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 a pull request may close this issue.

2 participants