![]() |
Prev | Next |
result = CondExpRel(left, right, if_true, if_false)
Base
operation sequence
,
the conditional result
if( left Cop right )
result = if_true
else result = if_false
The relational
Rel
and comparison operator
Cop
above have the following correspondence:
Rel Lt Le Eq Ge Gt
Cop < <= == >= >
If
f
is the ADFun
object corresponding to the
AD operation sequence,
the assignment choice for
result
in an AD conditional expression is made each time
f.Forward
is used to evaluate the zero order Taylor
coefficients with new values for the
independent variables
.
This is in contrast to the AD comparison operators
which are boolean valued and not included in the AD operation sequence.
Rel
represents one of the following
two characters: Lt
, Le
, Eq
, Ge
, Gt
.
As in the table above,
Rel
determines which comparison operator
Cop
is used
when comparing
left
and
right
.
Type
is float
, double
, or any type of the form
AD<Base>
.
(Note that all four arguments must have the same type.)
left
has prototype
const Type& left
It specifies the value for the left side of the comparison operator.
right
has prototype
const Type& right
It specifies the value for the right side of the comparison operator.
if_true
has prototype
const Type& if_true
It specifies the return value if the result of the comparison is true.
if_false
has prototype
const Type& if_false
It specifies the return value if the result of the comparison is false.
result
has prototype
Type& if_false
left
and
right
have been determined,
it is known if the true or false case is required.
From this point on, values corresponding to the case that is not required
are not computed.
This optimization is done for the rest of zero order forward mode
as well as forward and reverse derivatives calculations.
CondExp(flag, if_true, if_false)
for the same meaning as
CondExpGt(flag, Type(0), if_true, if_false)
Use of CondExp
is deprecated, but continues to be supported.
Base
atomic operation
and hence is part of the current
AD of
Base
operation sequence
.
template <class Base>
AD<Base> atan2 (const AD<Base> &y, const AD<Base> &x)
{ AD<Base> alpha;
AD<Base> beta;
AD<Base> theta;
AD<Base> zero(0.);
AD<Base> pi2(2. * atan(1.));
AD<Base> pi(2. * pi2);
AD<Base> ax = fabs(x);
AD<Base> ay = fabs(y);
// if( ax > ay )
// theta = atan(ay / ax);
// else theta = pi2 - atan(ax / ay);
alpha = atan(ay / ax);
beta = pi2 - atan(ax / ay);
theta = CondExpGt(ax, ay, alpha, beta); // use of CondExp
// if( x <= 0 )
// theta = pi - theta;
theta = CondExpLe(x, zero, pi - theta, theta); // use of CondExp
// if( y <= 0 )
// theta = - theta;
theta = CondExpLe(y, zero, -theta, theta); // use of CondExp
return theta;
}