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

For a tuple primal @scalar_rule returns a tuple (not a Composite) differential. #211

Closed
oxinabox opened this issue Aug 26, 2020 · 0 comments · Fixed by #214
Closed

For a tuple primal @scalar_rule returns a tuple (not a Composite) differential. #211

oxinabox opened this issue Aug 26, 2020 · 0 comments · Fixed by #214
Labels
rule definition helper relating to helpers for declaring rules Structural Tangent Related to the `Tangent` type for structured (composite) values

Comments

@oxinabox
Copy link
Member

With #163 we effectily decided that as far as we are concerned, julia only has single output functions.
in #163 we made the approprate changes for rrules which was that pullbacks need to take a single input, which might be a Composite{Tuple}.

But we have not made the change for forward mode, at least not consistently or to the @scalar_rule macro.

An example (and possibly the only example) of this problem is:

We currently have

julia> frule((Zero(), 1.0), sincos, π)
((1.2246467991473532e-16, -1.0), (-1.0, -1.2246467991473532e-16))

But we should have:

julia> frule((Zero(), 1.0), sincos, π)
((1.2246467991473532e-16, -1.0), Composite{Tuple{Float64, Float64}}(-1.0, -1.2246467991473532e-16))

This should be changed in this section:

if n_outputs > 1
# For forward-mode we only return a tuple if output actually a tuple.
pushforward_returns = Expr(:tuple, pushforward_returns...)
else
pushforward_returns = pushforward_returns[1]
end

This issiue becomes more pressing with #207 because that macro can't trivially know if a function is returnig multiple outputs, but if we say multiple outputs don't exist, then it is easy.

@oxinabox oxinabox added the Structural Tangent Related to the `Tangent` type for structured (composite) values label Aug 26, 2020
@oxinabox oxinabox added the rule definition helper relating to helpers for declaring rules label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule definition helper relating to helpers for declaring rules Structural Tangent Related to the `Tangent` type for structured (composite) values
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant