|
3 | 3 | @define_diffrule M.f(x, y) = :(df_dx($x, $y)), :(df_dy($x, $y)) |
4 | 4 | ⋮</code></pre><p>Define a new differentiation rule for the function <code>M.f</code> and the given arguments, which should be treated as bindings to Julia expressions. Return the defined rule's key.</p><p>The LHS should be a function call with a non-splatted argument list, and the RHS should be the derivative expression, or in the <code>n</code>-ary case, an <code>n</code>-tuple of expressions where the <code>i</code>th expression is the derivative of <code>f</code> w.r.t the <code>i</code>th argument. Arguments should be interpolated wherever they are used on the RHS.</p><p>Note that differentiation rules are purely symbolic, so no type annotations should be used.</p><p><strong>Examples</strong></p><pre><code class="language-julia hljs">@define_diffrule Base.cos(x) = :(-sin($x)) |
5 | 5 | @define_diffrule Base.:/(x, y) = :(inv($y)), :(-$x / ($y^2)) |
6 | | -@define_diffrule Base.polygamma(m, x) = :NaN, :(polygamma($m + 1, $x))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/e1c8c2700a47b1d3f25c23832977b0b8a7d031fd/src/api.jl#L4-L26">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.diffrule"><a class="docstring-binding" href="#DiffRules.diffrule"><code>DiffRules.diffrule</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">diffrule(M::Union{Expr,Symbol}, f::Symbol, args...)</code></pre><p>Return the derivative expression for <code>M.f</code> at the given argument(s), with the argument(s) interpolated into the returned expression.</p><p>In the <code>n</code>-ary case, an <code>n</code>-tuple of expressions will be returned where the <code>i</code>th expression is the derivative of <code>f</code> w.r.t the <code>i</code>th argument.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> DiffRules.diffrule(:Base, :sin, 1) |
| 6 | +@define_diffrule Base.polygamma(m, x) = :NaN, :(polygamma($m + 1, $x))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/441a9fe1e62f04af300494fa44ac45360a10b2d6/src/api.jl#L4-L26">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.diffrule"><a class="docstring-binding" href="#DiffRules.diffrule"><code>DiffRules.diffrule</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">diffrule(M::Union{Expr,Symbol}, f::Symbol, args...)</code></pre><p>Return the derivative expression for <code>M.f</code> at the given argument(s), with the argument(s) interpolated into the returned expression.</p><p>In the <code>n</code>-ary case, an <code>n</code>-tuple of expressions will be returned where the <code>i</code>th expression is the derivative of <code>f</code> w.r.t the <code>i</code>th argument.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> DiffRules.diffrule(:Base, :sin, 1) |
7 | 7 | :(cos(1)) |
8 | 8 |
|
9 | 9 | julia> DiffRules.diffrule(:Base, :sin, :x) |
10 | 10 | :(cos(x)) |
11 | 11 |
|
12 | 12 | julia> DiffRules.diffrule(:Base, :sin, :(x * y^2)) |
13 | | -:(cos(x * y ^ 2))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/e1c8c2700a47b1d3f25c23832977b0b8a7d031fd/src/api.jl#L45-L66">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.hasdiffrule"><a class="docstring-binding" href="#DiffRules.hasdiffrule"><code>DiffRules.hasdiffrule</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">hasdiffrule(M::Union{Expr,Symbol}, f::Symbol, arity::Int)</code></pre><p>Return <code>true</code> if a differentiation rule is defined for <code>M.f</code> and <code>arity</code>, or return <code>false</code> otherwise.</p><p>Here, <code>arity</code> refers to the number of arguments accepted by <code>f</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> DiffRules.hasdiffrule(:Base, :sin, 1) |
| 13 | +:(cos(x * y ^ 2))</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/441a9fe1e62f04af300494fa44ac45360a10b2d6/src/api.jl#L45-L66">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.hasdiffrule"><a class="docstring-binding" href="#DiffRules.hasdiffrule"><code>DiffRules.hasdiffrule</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">hasdiffrule(M::Union{Expr,Symbol}, f::Symbol, arity::Int)</code></pre><p>Return <code>true</code> if a differentiation rule is defined for <code>M.f</code> and <code>arity</code>, or return <code>false</code> otherwise.</p><p>Here, <code>arity</code> refers to the number of arguments accepted by <code>f</code>.</p><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> DiffRules.hasdiffrule(:Base, :sin, 1) |
14 | 14 | true |
15 | 15 |
|
16 | 16 | julia> DiffRules.hasdiffrule(:Base, :sin, 2) |
|
23 | 23 | true |
24 | 24 |
|
25 | 25 | julia> DiffRules.hasdiffrule(:Base, :-, 3) |
26 | | -false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/e1c8c2700a47b1d3f25c23832977b0b8a7d031fd/src/api.jl#L69-L95">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.diffrules"><a class="docstring-binding" href="#DiffRules.diffrules"><code>DiffRules.diffrules</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">diffrules(; filter_modules=(:Base, :SpecialFunctions, :NaNMath))</code></pre><p>Return a list of keys that can be used to access all defined differentiation rules for modules in <code>filter_modules</code>.</p><p>Each key is of the form <code>(M::Symbol, f::Symbol, arity::Int)</code>. Here, <code>arity</code> refers to the number of arguments accepted by <code>f</code> and <code>M</code> is one of the modules in <code>filter_modules</code>.</p><p>To include all rules, specify <code>filter_modules = nothing</code>.</p><div class="admonition is-info" id="Note-cc44e06970c44125"><header class="admonition-header">Note<a class="admonition-anchor" href="#Note-cc44e06970c44125" title="Permalink"></a></header><div class="admonition-body"><p>Calling <code>diffrules()</code> with the implicit default keyword argument <code>filter_modules</code> does <em>not</em> return all rules defined by this package but rather only rules for the packages for which DiffRules 1.0 provided rules. This is done in order to not to break downstream packages that assumed this list would never change. It is planned to change <code>diffrules()</code> to return all rules, i.e., to use the default keyword argument <code>filter_modules=nothing</code>, in an upcoming breaking release of DiffRules.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> first(DiffRules.diffrules()) isa Tuple{Symbol,Symbol,Int} |
| 26 | +false</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/441a9fe1e62f04af300494fa44ac45360a10b2d6/src/api.jl#L69-L95">source</a></section></details></article><article><details class="docstring" open="true"><summary id="DiffRules.diffrules"><a class="docstring-binding" href="#DiffRules.diffrules"><code>DiffRules.diffrules</code></a> — <span class="docstring-category">Function</span></summary><section><div><pre><code class="language-julia hljs">diffrules(; filter_modules=(:Base, :SpecialFunctions, :NaNMath))</code></pre><p>Return a list of keys that can be used to access all defined differentiation rules for modules in <code>filter_modules</code>.</p><p>Each key is of the form <code>(M::Symbol, f::Symbol, arity::Int)</code>. Here, <code>arity</code> refers to the number of arguments accepted by <code>f</code> and <code>M</code> is one of the modules in <code>filter_modules</code>.</p><p>To include all rules, specify <code>filter_modules = nothing</code>.</p><div class="admonition is-info" id="Note-cc44e06970c44125"><header class="admonition-header">Note<a class="admonition-anchor" href="#Note-cc44e06970c44125" title="Permalink"></a></header><div class="admonition-body"><p>Calling <code>diffrules()</code> with the implicit default keyword argument <code>filter_modules</code> does <em>not</em> return all rules defined by this package but rather only rules for the packages for which DiffRules 1.0 provided rules. This is done in order to not to break downstream packages that assumed this list would never change. It is planned to change <code>diffrules()</code> to return all rules, i.e., to use the default keyword argument <code>filter_modules=nothing</code>, in an upcoming breaking release of DiffRules.</p></div></div><p><strong>Examples</strong></p><pre><code class="language-julia-repl hljs">julia> first(DiffRules.diffrules()) isa Tuple{Symbol,Symbol,Int} |
27 | 27 | true |
28 | 28 |
|
29 | 29 | julia> (:Base, :log, 1) in DiffRules.diffrules() |
|
36 | 36 | for (M, _, _) in DiffRules.diffrules(; filter_modules=nothing) |
37 | 37 | ) |
38 | 38 | true</code></pre><p>If you set <code>filter_modules=(:Base,)</code> only rules for functions in Base are returned:</p><pre><code class="language-julia-repl hljs">julia> all(M === :Base for (M, _, _) in DiffRules.diffrules(; filter_modules=(:Base,))) |
39 | | -true</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/e1c8c2700a47b1d3f25c23832977b0b8a7d031fd/src/api.jl#L118-L175">source</a></section></details></article></article><nav class="docs-footer"><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.17.0 on <span class="colophon-date" title="Friday 29 May 2026 07:52">Friday 29 May 2026</span>. Using Julia version 1.12.6.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
| 39 | +true</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JuliaDiff/DiffRules.jl/blob/441a9fe1e62f04af300494fa44ac45360a10b2d6/src/api.jl#L118-L175">source</a></section></details></article></article><nav class="docs-footer"><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.17.0 on <span class="colophon-date" title="Friday 29 May 2026 07:53">Friday 29 May 2026</span>. Using Julia version 1.12.6.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments