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

Projecting a Tangent{Complex} to Numbers #531

Closed
mzgubic opened this issue Jan 12, 2022 · 4 comments · Fixed by #535
Closed

Projecting a Tangent{Complex} to Numbers #531

mzgubic opened this issue Jan 12, 2022 · 4 comments · Fixed by #535
Labels
bug Something isn't working ProjectTo related to the projection functionality

Comments

@mzgubic
Copy link
Member

mzgubic commented Jan 12, 2022

At present:

julia> tc = Tangent{ComplexF64}(; re=1, im=NoTangent());

julia> ProjectTo(1.0)(tc)
Tangent{ComplexF64}(re = 1, im = NoTangent())

whereas I think we want

julia> ProjectTo(1.0)(tc)
1.0

The solution would be to change the current

(project::ProjectTo{<:Complex})(dx::Tangent{<:Complex}) = project(Complex(dx.re, dx.im))

to

(project::ProjectTo{<:Number})(dx::Tangent{<:Complex}) = project(Complex(dx.re, dx.im))

which would also fix e.g. ProjectTo(π)(tc).

@oxinabox
Copy link
Member

Sounds right

@oxinabox oxinabox added ProjectTo related to the projection functionality bug Something isn't working labels Jan 12, 2022
@mcabbott
Copy link
Member

Does this occur in the wild?

To get from real to complex, you must go through some function, and its gradient shouldn't really let a Tangent of the wrong type for the arguments propagate backwards.

@mzgubic
Copy link
Member Author

mzgubic commented Jan 12, 2022

I haven't ran into it, but how about this example?

julia> y, pb = rrule(+, 1.0, 1.0im); pb(Tangent{Complex}(;re=1.0))
(NoTangent(), Tangent{Complex}(re = 1.0,), 1.0 + 0.0im)

I guess if you take the stance that the Tangent{Complex}(;re=1.0) is always a wrong thing to return, and it should just be the natural differential, then the example is invalid and I can't think of a reasonable example.

@mcabbott
Copy link
Member

Ok. I'm a little uneasy, but I agree that is a good example, and we do have a bit of a "if someone missed at first, catch it later" policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ProjectTo related to the projection functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants