JuliaDiff / JuliaDiff/ChainRulesCore.jl

Documentation on default arguments

Open
#223 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Julia
Stars
267
Forks
66
PR merge metrics
No merged PRs in 30d

Description

From slack. Point out that an rrule is basically a new dispatch. So if you have any default arguments, you will need to redefine them. For example

using Zygote, ChainRulesCore
function f(x, y=0.0; a=2)
    return a * x + y
end
function ChainRulesCore.rrule(::typeof(f), x, y=0.0; a=2)
    r = f(x, y; a)
    function f_pb(Δr)
        # implementation, which can use the `y`, and `a`
    end
    return r, f_pb
end

Can point out that the kwargs on the dispatch is useful to slurp up keyword arguments to pass to the f(...) in the primal but you would need to separate out any values with defaults, as you would implementing any other dispatch.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the documentation covering rrule dispatches and default arguments. Explain that an rrule is a new dispatch, so default positional and keyword arguments must be redefined, while kwargs can collect keyword arguments for the primal call. Done means the documentation includes the Julia example and clearly describes separating defaulted values.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.