Skip to content

Commit ce6a807

Browse files
authored
derivative for in-place functions of the form f!(::AbstractArray, ::Real) (#219)
1 parent aa798b2 commit ce6a807

File tree

8 files changed

+130
-28
lines changed

8 files changed

+130
-28
lines changed

docs/_rst/source/basic_api.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ Use ``ForwardDiff.derivative`` to differentiate functions of the form ``f(::Real
88

99
.. function:: ForwardDiff.derivative!(out, f, x)
1010

11-
Compute :math:`f'(x)`, storing the output in ``out``. If ``x`` is a ``Tuple``,
12-
then ``f`` will be called as ``f(x...)`` and the derivatives with respect to
13-
each element in `x` will be stored in the respective element of ``out`` (which
14-
should also be a ``Tuple``).
11+
Compute :math:`f'(x)`, storing the output in ``out``.
12+
13+
.. function:: ForwardDiff.derivative!(out, f!, y, x, cfg = ForwardDiff.DerivativeConfig(f!, y, x))
14+
15+
Compute and return :math:`f'(x)`, storing the output in ```out``. This form assumes that
16+
:math:`f'(x)` can be called as ``f!(y, x)`` such that the value result is stored in
17+
``y``.
1518

1619
.. function:: ForwardDiff.derivative(f, x)
1720

18-
Compute and return :math:`f'(x)`. If ``x`` is a ``Tuple``, ``f`` will be
19-
called as ``f(x...)``, and a ``Tuple`` of derivatives will be returned.
21+
Compute and return :math:`f'(x)`.
22+
23+
.. function:: ForwardDiff.derivative(f!, y, x, cfg = ForwardDiff.DerivativeConfig(f!, y, x))
24+
25+
Compute and return :math:`f'(x)`. This form assumes that :math:`f'(x)` can be called as
26+
``f!(y, x)`` such that the value result is stored in ``y``.
2027

2128
Gradients of :math:`f(x) : \mathbb{R}^{n_1} \times \dots \times \mathbb{R}^{n_k} \to \mathbb{R}`
2229
------------------------------------------------------------------------------------------------

docs/_sources/basic_api.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@ Use ``ForwardDiff.derivative`` to differentiate functions of the form ``f(::Real
88

99
.. function:: ForwardDiff.derivative!(out, f, x)
1010

11-
Compute :math:`f'(x)`, storing the output in ``out``. If ``x`` is a ``Tuple``,
12-
then ``f`` will be called as ``f(x...)`` and the derivatives with respect to
13-
each element in `x` will be stored in the respective element of ``out`` (which
14-
should also be a ``Tuple``).
11+
Compute :math:`f'(x)`, storing the output in ``out``.
12+
13+
.. function:: ForwardDiff.derivative!(out, f!, y, x, cfg = ForwardDiff.DerivativeConfig(f!, y, x))
14+
15+
Compute and return :math:`f'(x)`, storing the output in ```out``. This form assumes that
16+
:math:`f'(x)` can be called as ``f!(y, x)`` such that the value result is stored in
17+
``y``.
1518

1619
.. function:: ForwardDiff.derivative(f, x)
1720

18-
Compute and return :math:`f'(x)`. If ``x`` is a ``Tuple``, ``f`` will be
19-
called as ``f(x...)``, and a ``Tuple`` of derivatives will be returned.
21+
Compute and return :math:`f'(x)`.
22+
23+
.. function:: ForwardDiff.derivative(f!, y, x, cfg = ForwardDiff.DerivativeConfig(f!, y, x))
24+
25+
Compute and return :math:`f'(x)`. This form assumes that :math:`f'(x)` can be called as
26+
``f!(y, x)`` such that the value result is stored in ``y``.
2027

2128
Gradients of :math:`f(x) : \mathbb{R}^{n_1} \times \dots \times \mathbb{R}^{n_k} \to \mathbb{R}`
2229
------------------------------------------------------------------------------------------------

docs/basic_api.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,28 @@ <h2>Derivatives of <span class="math">\(f(x) : \mathbb{R} \to \mathbb{R}^{n_1} \
152152
<dl class="function">
153153
<dt>
154154
<code class="descname">ForwardDiff.derivative!(out, f, x)</code></dt>
155-
<dd><p>Compute <span class="math">\(f'(x)\)</span>, storing the output in <code class="docutils literal"><span class="pre">out</span></code>. If <code class="docutils literal"><span class="pre">x</span></code> is a <code class="docutils literal"><span class="pre">Tuple</span></code>,
156-
then <code class="docutils literal"><span class="pre">f</span></code> will be called as <code class="docutils literal"><span class="pre">f(x...)</span></code> and the derivatives with respect to
157-
each element in <cite>x</cite> will be stored in the respective element of <code class="docutils literal"><span class="pre">out</span></code> (which
158-
should also be a <code class="docutils literal"><span class="pre">Tuple</span></code>).</p>
155+
<dd><p>Compute <span class="math">\(f'(x)\)</span>, storing the output in <code class="docutils literal"><span class="pre">out</span></code>.</p>
156+
</dd></dl>
157+
158+
<dl class="function">
159+
<dt>
160+
<code class="descname">ForwardDiff.derivative!(out, f!, y, x, cfg = ForwardDiff.DerivativeConfig(f!, y, x))</code></dt>
161+
<dd><p>Compute and return <span class="math">\(f'(x)\)</span>, storing the output in <code class="docutils literal"><span class="pre">`out</span></code>. This form assumes that
162+
<span class="math">\(f'(x)\)</span> can be called as <code class="docutils literal"><span class="pre">f!(y,</span> <span class="pre">x)</span></code> such that the value result is stored in
163+
<code class="docutils literal"><span class="pre">y</span></code>.</p>
159164
</dd></dl>
160165

161166
<dl class="function">
162167
<dt id="ForwardDiff.derivative">
163168
<code class="descclassname">ForwardDiff.</code><code class="descname">derivative</code><span class="sig-paren">(</span><em>f</em>, <em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#ForwardDiff.derivative" title="Permalink to this definition"></a></dt>
164-
<dd><p>Compute and return <span class="math">\(f'(x)\)</span>. If <code class="docutils literal"><span class="pre">x</span></code> is a <code class="docutils literal"><span class="pre">Tuple</span></code>, <code class="docutils literal"><span class="pre">f</span></code> will be
165-
called as <code class="docutils literal"><span class="pre">f(x...)</span></code>, and a <code class="docutils literal"><span class="pre">Tuple</span></code> of derivatives will be returned.</p>
169+
<dd><p>Compute and return <span class="math">\(f'(x)\)</span>.</p>
170+
</dd></dl>
171+
172+
<dl class="function">
173+
<dt>
174+
<code class="descclassname">ForwardDiff.</code><code class="descname">derivative</code><span class="sig-paren">(</span><em>f!</em>, <em>y</em>, <em>x</em>, <em>cfg = ForwardDiff.DerivativeConfig(f!</em>, <em>y</em>, <em>x)</em><span class="sig-paren">)</span></dt>
175+
<dd><p>Compute and return <span class="math">\(f'(x)\)</span>. This form assumes that <span class="math">\(f'(x)\)</span> can be called as
176+
<code class="docutils literal"><span class="pre">f!(y,</span> <span class="pre">x)</span></code> such that the value result is stored in <code class="docutils literal"><span class="pre">y</span></code>.</p>
166177
</dd></dl>
167178

168179
</div>

docs/genindex.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ <h2 id="F">F</h2>
145145
<table style="width: 100%" class="indextable genindextable"><tr>
146146
<td style="width: 33%" valign="top"><dl>
147147

148-
<dt><a href="basic_api.html#ForwardDiff.derivative">ForwardDiff.derivative() (built-in function)</a>
148+
<dt><a href="basic_api.html#ForwardDiff.derivative">ForwardDiff.derivative() (built-in function)</a>, <a href="basic_api.html#ForwardDiff.derivative">[1]</a>
149149
</dt>
150150

151151

0 commit comments

Comments
 (0)