![]() |
Prev | Next |
VecAD<
Base>
v(
n)
v.size()
b =
v[
i]
r =
v[
x]
y =
v[
x]
is recorded in the corresponding
AD of Base
operation sequence
and
transferred to the corresponding ADFun
object f.
Such an index can change each time
zero order f.Forward
is used; i.e.,
f is evaluated with new value for the
independent variables
.
Note that the value of y depends on the value of x
in a discrete fashion and CppAD computes its partial derivative with
respect to x as zero.
Vector< AD<
Base> >
is much more efficient for
storing AD values where Vector is any
SimpleVector
template class,
If only the indices,
and not the values in the vector,
depend on the independent variables,
The Discrete
functions are a much more efficient
way to represent these vectors.
VecAD<
Base>::reference
which is very much like the AD<
Base>
type
with some notable exceptions:
v[
i]
can be used to compute the corresponding Base value.
+=
,
-=
,
*=
, or
/=
.
For example, the following syntax is not valid:
v[
x] +=
z;
no matter what the types of z.
void
.
For example, the following syntax is not valid:
z =
v[
x] =
u;
no matter what the types of z, and u.
VecAD<
Base>::reference
arguments.
For example, the following syntax is not valid:
CondExpGt(
y,
z,
u,
v)
no matter what the types of z, u, and v.
VecAD<
Base>::reference
arguments
(use the entire VecAD<
Base>
vector instead).
AD<
Base>
; i.e., VecAD
vectors
cannot be passed to Independent
.
VecAD<
Base>
v(
n)
creates an VecAD
object v with
n elements.
The initial value of the elements of v is unspecified.
size_t
n
v.size()
returns the number of elements in the vector v;
i.e., the value of n when it was constructed.
b =
v[
i]
as size_t
indexing of a VecAD
object.
This indexing is only valid if the vector v is a
parameter
; i.e.,
it does not depend on the independent variables.
size_t
i
It must be greater than or equal zero
and less than n; i.e., less than
the number of elements in v.
Base
b
and is a reference to the i-th element in the vector v.
It can be used to change the element value;
for example,
v[
i] =
c
is valid where c is a Base object.
The reference b is no longer valid once the
destructor for v is called; for example,
when v falls out of scope.
r =
v[
x]
as AD indexing of a VecAD
object.
const AD<
Base> &
x
The value of x must be greater than or equal zero
and less than n; i.e., less than
the number of elements in v.
VecAD<
Base>::reference
r
The object r has an AD type and its
operations are recorded as part of the same
AD of Base
operation sequence
as
for AD<
Base>
objects.
It acts as a reference to the
element with index
{\rm floor} (x)
in the vector v
(
{\rm floor} (x)
is
the greatest integer less than or equal x).
Because it is a reference, it can be used to change the element value;
for example,
v[
x] =
z
is valid where z is an
VecAD<
Base>::reference
object.
As a reference, r is no longer valid once the
destructor for v is called; for example,
when v falls out of scope.
VecAD
vectors.
It returns true if it succeeds and false otherwise.
Ldp
or Ldv
operation
(unless all of the elements of the vector are
parameters
).
The effect of this can be seen by executing the following steps:
cppad/local/ForwardSweep.h
,
change the definition of CppADForwardSweepTrace
to
# define CppADForwardSweepTrace 1
Example
directory, execute the command
./OneTest LuVecADOk "lu_vec_ad.cpp -DNDEBUG" > LuVecADOk.log
This will write a trace of all the forward tape operations,
for the test case LuVecADOk.cpp
,
to the file LuVecADOk.log
.
Example
directory execute the commands
grep "op=" LuVecADOk.log | wc -l
grep "op=Ld[vp]" LuVecADOk.log | wc -l
grep "op=St[vp][vp]" LuVecADOk.log | wc -l
The first command counts the number of operators in the tracing,
the second counts the number of VecAD load operations,
and the third counts the number of VecAD store operations.
(For CppAD version 05-11-20 these counts were 956, 348, and 118
respectively.)