Skip to content

Commit

Permalink
Merge #1079
Browse files Browse the repository at this point in the history
1079: ProjectTo{AbstractArray}(::Tangent{Any}) fix r=willtebbutt a=willtebbutt

Resolves #1078 

Co-authored-by: WT <[email protected]>
Co-authored-by: willtebbutt <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2021
2 parents 700c314 + 79454f3 commit 446594d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Zygote"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.6.22"
version = "0.6.23"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ _project(x::AbstractArray, dx::Tuple) = _project(x, reshape(collect(dx), axes(x)
# CRC likes Tangent{<:Complex}, but Zygote makes Tangent{Any}
(project::ProjectTo{<:Complex})(dx::Tangent) = project(Complex(dx.re, dx.im))

# CRC likes Tangent{AbstractArray}, but Zygote makes Tangent{Any}
# in particular this would hit https://github.com/JuliaDiff/ChainRulesCore.jl/blob/2ec2549b73b22bc08f554dae864fb650cfb9c3d7/src/projection.jl#L139
# if we were not losing track of the Primal in the Tangent
# This type piracy is just giving up that safety check.
(project::ProjectTo{AbstractArray})(dx::Tangent) = dx

"""
ZBack{F}(back) <: Function
Expand Down
7 changes: 7 additions & 0 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ end
test_rrule(ZygoteRuleConfig(), sum, x -> cbrt(x), randn(5))
test_rrule(ZygoteRuleConfig(), sum, x -> cbrt(x), randn(5); rrule_f=rrule_via_ad)
end

# See https://github.com/FluxML/Zygote.jl/issues/1078
@testset "ProjectTo{AbstractArray}(::Tangent{Any})" begin
X = UpperHessenberg(randn(5, 5))
dX = Tangent{Any}(element=randn(5, 5))
@test ProjectTo(X)(dX) === dX
end
end

@testset "FastMath support" begin
Expand Down

2 comments on commit 446594d

@willtebbutt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45491

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.23 -m "<description of version>" 446594defcdc636386b33a5950e791a54ad28420
git push origin v0.6.23

Please sign in to comment.