Skip to content

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

Closed
@oxinabox

Description

@oxinabox

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Structural TangentRelated to the `Tangent` type for structured (composite) valuesrule definition helperrelating to helpers for declaring rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions