-end</code></pre><p>The Julia compiler will specialize based on inferring the return type of <code>rrule</code>, and so can remove that branch.</p><h3 id="no_rrule-/-no_frule-has-a-method"><a class="docs-heading-anchor" href="#no_rrule-/-no_frule-has-a-method"><code>no_rrule</code> / <code>no_frule</code> has a method</a><a id="no_rrule-/-no_frule-has-a-method-1"></a><a class="docs-heading-anchor-permalink" href="#no_rrule-/-no_frule-has-a-method" title="Permalink"></a></h3><p><code>@opt_out</code> also defines a method for <a href="../api.html#ChainRulesCore.no_frule"><code>ChainRulesCore.no_frule</code></a> or <a href="../api.html#ChainRulesCore.no_rrule"><code>ChainRulesCore.no_rrule</code></a>. The body of this method doesn't matter, what matters is that it is a method-table. A simple thing you can do with this is not support opting out. To do this, filter all methods from the <code>rrule</code>/<code>frule</code> method table that also occur in the <code>no_frule</code>/<code>no_rrule</code> table. This will thus avoid ever hitting an <code>rrule</code>/<code>frule</code> that returns <code>nothing</code> (and thus prevents your library from erroring). This is easily done, though it does mean ignoring the user's stated desire to opt out of the rule.</p><p>More complex you can use this to generate code that triggers your AD. If for a given signature there is a more specific method in the <code>no_rrule</code>/<code>no_frule</code> method-table, than the one that would be hit from the <code>rrule</code>/<code>frule</code> table (Excluding the one that exactly matches which will return <code>nothing</code>) then you know that the rule should not be used. You can, likely by looking at the primal method table, workout which method you would have it if the rule had not been defined, and then <code>invoke</code> it.</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="call_back_into_ad.html">« Support calling back into ADs</a><a class="docs-footer-nextpage" href="../maths/propagators.html">The propagators: pushforward and pullback »</a><div class="flexbox-break"></div><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="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.2.1 on <span class="colophon-date" title="Friday 31 May 2024 21:55">Friday 31 May 2024</span>. Using Julia version 1.6.7.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
0 commit comments