Prev | Next | ADTape |
ADTape<
Base>
Tape
AD<
Base>
,
there must be one and only one id such that
ADBase<
Base>::tape_active(
id)
is true.
This object is used to record
AD<
Base>
operations and compute derivatives.
Tape.Rec
contains
the currently recorded information.
This information is recorded using the following functions:
void
Tape.RecordNonOp()
places a NonOp in the next tape location.
This is useful for operations that must reserve extra
calculation space for forward and backward modes.
void
Tape.RecordPripOp(const char *
text, const
Base &
x)
places, in the next tape location,
a PripOp that prints the parameter
value x to standard output.
The procedure call
void
Tape.RecordPrivOp(const char *
text,
x_taddr)
places, in the next tape location,
a PrivOp that prints the variable
corresponding to x_taddr to standard output.
These operators enables the user to determine the value of intermediate
variables during forward and reverse mode.
size_t
Tape.RecordParOp(const
Base &
z)
creates a ParOp
record with the value
specified by z.
The return value is the taddr of this operation in the tape.
void
Tape.RecordInvOp(AD<
Base> &
z)
creates a tape record corresponding to a new independent variable.
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordInvOp
,
z.taddr_
is the taddr of the new tape record.
void
Tape.RecordLoadOp(
OpCode
op,
AD<
Base> &
z,
size_t
offset,
size_t
x_taddr
)
creates a tape record corresponding to the value of a VecAD
element.
op
Must be one of the following values:
LdvOp
, LdpOp
.
offset
is the offset where this VecAD
array
starts in the cumulative array containing all the VecAD
arrays.
It indexes the length of this VecAD
array
and the rest of the array follows.
x_taddr
provides the information necessary to retriever the taddr in for this
element within the VecAD
array.
This has the following meaning depending on the value of op:
op | x_taddr |
LdpOp
|
location of the index in Rec.GetPar |
LdvOp
| location of the taddr as a variable in the tape |
z.taddr_
is modified so that it corresponds to the new tape record when
RecordLoadOp
returns.
Upon return from RecordLoadOp
,
z is in the list of variables and
z.taddr_
is the taddr in the tape for this op operator.
void
Tape.RecordStoreOp(
OpCode
op,
size_t
offset,
size_t
x_taddr,
size_t
y_taddr
)
creates a tape record corresponding to storing a new value for
a VecAD
element.
op
Must be one of the following values:
StvvOp
, StpvOp
.
offset
is the offset where this VecAD
array
starts in the cumulative array containing all the VecAD
arrays.
It indexes the length of this VecAD
array
and the rest of the array follows.
x_taddr
provides the information necessary to retrieve the taddr for this
VecAD
element within this VecAD
array.
This has the following meaning depending on the value of op:
op | x_taddr |
StppOp
|
location of the index in Rec.GetPar |
StpvOp
|
location of the index in Rec.GetPar |
StvpOp
| location of the taddr as a variable in the tape |
StvvOp
| location of the taddr as a variable in the tape |
y_taddr
provides the information necessary to retrieve the value for this
VecAD
element within this VecAD
array.
This has the following meaning depending on the value of op:
op | y_taddr |
StppOp
|
location of the value in Rec.GetPar |
StvpOp
|
location of the value in Rec.GetPar |
StpvOp
| location of the taddr as a variable in the tape |
StvvOp
| location of the taddr as a variable in the tape |
inline void
Tape.RecordOp(
OpCode
op,
AD<
Base> &
z,
size_t
x_taddr,
size_t
y_taddr
)
places a new dependent variable z in the tape
and sets
z.taddr_
to the corresponding taddr.
The tape record specifies the operation
z =
op(
x,
y)
where x_taddr is the taddr of x in the tape
and y_taddr is the taddr of y in the tape
(neither of these indices can be zero).
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordOp
,
z is in the list of variables and
z.taddr_
is to the taddr of the new tape record.
The procedure call
inline void
Tape.RecordOp(
OpCode
op,
size_t
x_taddr,
size_t
y_taddr
)
is the same as above except that no variable results from the
tape operation; i.e., NumVar(
op)
is zero.
inline void
Tape.RecordOp(
OpCode
op,
AD<
Base> &
z,
size_t
x_taddr,
const
Base &
p
)
places a new dependent variable z in the tape
and sets
z.taddr_
to the corresponding taddr.
The tape record specifies the operation
z =
op(
x,
p)
where x_taddr is the taddr of x in the tape
(this taddr can not be zero).
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordOp
,
z is in the list of variables and
z.taddr_
is to the taddr of the new tape record.
The value p corresponds to a parameter.
The procedure call
inline void
Tape.RecordOp(
OpCode
op,
size_t
x_taddr,
const
Base &
p
)
is the same as above except that no variable results from the
tape operation; i.e., NumVar(
op)
is zero.
inline void
Tape.RecordOp(
OpCode
op,
AD<
Base> &
z,
const
Base &
p,
size_t
y_taddr
)
places a new dependent variable z in the tape
and sets
z.taddr_
to the corresponding taddr.
The tape record specifies the operation
z =
op(
p,
y)
where y_taddr is the taddr of y in the tape
(this taddr can not be zero).
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordOp
,
z is in the list of variables and
z.taddr_
is to the taddr of the new tape record.
The value p corresponds to a parameter.
The procedure call
inline void
Tape.RecordOp(
OpCode
op,
const
Base &
p,
size_t
y_taddr
)
is the same as above except that no variable results from the
tape operation; i.e., NumVar(
op)
is zero.
inline void
Tape.RecordOp(
OpCode
op,
const
Base &
x,
const
Base &
y
)
records an operation between two parameters where
x is the left operand and y is the right operand.
No variable results from the tape operation;
i.e., NumVar(
op)
is zero.
inline void
Tape.RecordOp(
OpCode
op,
AD<
Base> &
z,
size_t
x_taddr
)
places a new dependent variable z in the tape
and sets
z.taddr_
to the corresponding taddr.
The tape record specifies the operation
z =
op(
x)
where x_taddr is the taddr of x in the tape
(this taddr can not be zero) and op specifies the
unary function.
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordOp
,
z is in the list of variables and
z.taddr_
is to the taddr of the new tape record.
void
Tape.RecordDisOp(
AD<
Base> &
z,
size_t
x_taddr,
size_t
y_taddr
)
places a new dependent variable z in the tape
and sets
z.taddr_
to the corresponding taddr.
The tape record specifies the operation
z =
f(
x)
where x_taddr is the taddr of x in the tape
and y_taddr is the taddr corresponding to the
Discrete function f
(the value x_taddr cannot be zero).
The field
z.value_
is an input and all the other
fields of z are outputs.
Upon return from RecordDisOp
,
z is in the list of variables and
z.taddr_
is to the taddr of the new tape record.
size_t
Tape.AddVec(size_t
length, const
Base *
data)
adds a variable indexed array with the specified length and values to the tape.
We use i to denote the value returned by AddVec
.
The value length is added to Rec as follows:
length ==
Rec.GetVecInd(
i)
Upon return,
the elements of data are stored in Rec
in the following way:
for
j = 0 , \ldots , length-1
,
data[
j] ==
Rec.GetVecInd(
i +
j + 1)