@(@\newcommand{\W}[1]{ \; #1 \; }
\newcommand{\R}[1]{ {\rm #1} }
\newcommand{\B}[1]{ {\bf #1} }
\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }
\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }
\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }
\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation. Here is a link to its
current documentation
.
Atomic Matrix Multiply Reverse Dependency: Example and Test
Purpose
This example uses the atomic matrix multiply
rev_depend function to reduce the number of variables in
the recording of @(@
g(u)
@)@.
f(u)
@[@
f(u) =
\left( \begin{array}{cc}
2 u_0 & 2 u_1 \\
2 u_2 & 2 u_3 \\
\end{array} \right)
\left( \begin{array}{cc}
2 u_4 & 2 u_5 \\
2 u_6 & 2 u_7
\end{array} \right)
=
\left( \begin{array}{cc}
4( u_0 u_4 + u_1 u_6 ) & 4( u_0 u_5 + u_1 u_7 ) \\
4( u_2 u_4 + u_3 u_6 ) & 4( u_2 u_5 + u_3 u_7 ) \\
\end{array} \right)
@]@@[@
f_{0,0} (u)
=
4 ( u_0 u_4 + u_1 u_6 )
@]@ Forward Analysis
Forward dependency analysis determines that there
is a new variable for each of the 8 multiplications by 2.0.
It also determines, using for_type
that each of the 4 elements in the matrix product result is a new variable.
Reverse Analysis
Reverse analysis detect that only 1 of the 4 elements
in the matrix product is used.
In addition it determines,
using rev_depend
,
that only 4 of the 8 multiplications by 2.0 are used.
size_var
The difference in size_var
is the difference between only using forward dependency and using both; i.e.,
(8 - 4) + (4 - 1) = 7.