![]() |
Prev | Next |
s =
f.ForSparseJac(
q,
r)
F : B^n \rightarrow B^m
to denote the
AD function
corresponding to f.
For a fixed
n \times q
matrix
R
,
the Jacobian of
F[ x + R * u ]
with respect to
u
at
u = 0
is
\[
J(x) = F^{(1)} ( x ) * R
\]
Given a
sparsity pattern
for
R
,
ForSparseJac
returns a sparsity pattern for the
J(x)
.
ADFun<
Base>
f
Note that the ADFun
object f is not const
.
After this the sparsity pattern
for each of the variables in the operation sequence
is stored in the object f.
x \in B^n
.
If f.useVecAD
is true,
the sparsity patter is only valid for the value of x
in the previous zero order forward mode
call
f.Forward(0,
x)
If there is no previous zero order forward mode call using f,
the value of the independent
variables
during the recording of the AD sequence of operations is used
for x.
size_t
q
It specifies the number of columns in the Jacobian
J(x)
.
Note that the memory required for the calculation is proportional
to
q
times the total number of variables
in the AD operation sequence corresponding to f
(f.size_var
).
Smaller values for q can be used to
break the sparsity calculation
into groups that do not require to much memory.
const
Vector &
r
(see Vector
below)
and its size is
n * q
.
It specifies a
sparsity pattern
for the matrix R as follows:
for
i = 0 , \ldots , n-1
and
j = 0 , \ldots , q-1
.
\[
R_{i,j} \neq 0 ; \Rightarrow \; r [ i * q + j ] = {\rm true}
\]
Vector
s
(see Vector
below)
and its size is
m * q
.
It specifies a
sparsity pattern
for the matrix
J(x)
as follows:
for
x \in B^n
,
for
i = 0 , \ldots , m-1
,
and
j = 0 , \ldots , q-1
\[
J(x)_{i,j} \neq 0 ; \Rightarrow \; s [ i * q + j ] = {\rm true}
\]
q = n
and
R
is the
n \times n
identity matrix,
If follows that
\[
r [ i * q + j ] = \left\{ \begin{array}{ll}
{\rm true} & {\rm if} \; i = j \\
{\rm flase} & {\rm otherwise}
\end{array} \right.
\]
is an efficient sparsity pattern for
R
;
i.e., the choice for r has as few true values as possible.
In this case,
the corresponding value for s is a
sparsity pattern for the Jacobian
J(x) = F^{(1)} ( x )
.