\(\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}} }\)
json_graph_op¶
View page sourceJson AD Graph Operator Definitions¶
Notation¶
op_code¶
Each operator definition has a op_code value that is used to identify it for a particular json_ad_graph .
Arguments¶
The values first_arg , … , last_arg are the node indices for arguments to an operator.
Unary Operators¶
All these operations create one result node and have the following Json definition:
"op_code"
: op_code ,"name"
: name ,"n_arg"
: 1where name is a String . A corresponding op_usage has the form
[ op_code , arg ]
The possible values for the string name are listed in the table below. The corresponding result is the node value as a function of the argument value.
name |
result |
|
absolute value |
|
inverse cosine |
|
inverse hyperbolic cosine |
|
inverse sine |
|
inverse hyperbolic sine |
|
inverse tangent |
|
inverse hyperbolic sine |
|
cosine |
|
hyperbolic cosine |
|
error functions |
|
complementary error function |
|
exponential |
|
minus one plus the exponential |
|
log plus one |
|
logarithm |
|
negative |
|
sign function |
|
sine |
|
hyperbolic sine |
|
square root |
|
tangent |
|
hyperbolic tangent |
Example¶
The file json_unary_op.cpp is an example and test for one of these operators.
Binary Operators¶
All these operations create one result node and have the following Json definition:
"op_code"
: op_code ,"name"
: name ,"n_arg"
: 2where name is a String . A corresponding op_usage has the form
[ op_code , first_arg , second_arg ]
The possible values for the string name are listed below:
add¶
The result is the first argument value plus the second argument value; see the example and test json_add_op.cpp .
azmul¶
If the first argument value is zero, the result is zero (even if the second argument value is nan). Otherwise the result is the first argument value times the second argument value; see the example and test json_azmul_op.cpp .
div¶
The result is the first argument value divided by the second argument value; see the example and test json_div_op.cpp .
mul¶
The result is the first argument value times the second argument value; see the example and test json_mul_op.cpp .
pow¶
The result is the first argument value raised to the second argument value; see the example and test json_pow_op.cpp .
sub¶
The result is the first argument value minus the second argument value; see the example and test json_sub_op.cpp .
sum¶
This operator has the following Json definition:
"op_code"
: op_code ,"name"
: "sum"
A corresponding op_usage has the form
[ op_code , n_result , n_arg , [ first_arg , …, last_arg ] ]
where n_result is always 1
.
This operation creates one node with value equal to
the sum of values corresponding to all of its argument nodes.
Example¶
The file json_sum_op.cpp is an example and test of this operation.
Conditional Expressions¶
These operators are conditional expressions and have the following Json definition:
"op_code"
: op_code ,"name"
: “ cexp_
rel ,"n_arg"
: 4where rel is eq
(equal),
le
(less than or equal), or
lt
(less than).
The first argument is left ,
the second is right ,
the third is if_true ,
the fourth is if_false ,
the result is given by
if
( left cop right )else
where the comparison cop is define by the cases below:
cexp_eq¶
For this operator cop is ==
cexp_le¶
For this operator cop is <=
cexp_lt¶
For this operator cop is <
Other Comparisons¶
Note that
CondExpGt
( left , right , if_true , if_false )
is equivalent to
CondExpLe
( left , right , if_false , if_true )
Similar conversions can be used for all the possible conditional expressions .
Example¶
The file json_cexp_op.cpp is an example and test for one of these operators.
Compare Operators¶
These are comparison operators and have the following Json definition:
"op_code"
: op_code ,"name"
: “ comp_
rel “where rel is eq
(equal),
ne
(not equal),
le
(less than or equal), or
lt
(less than).
A corresponding op_usage has the form
[ op_code , n_result , n_arg , [ left , right ] ]
n_result¶
This is always zero because a comparison operator does not create any new nodes.
n_arg¶
This is always two because a comparison operator has two argument nodes corresponding to the left and right operands.
left, right¶
The logical comparison is defined as the logical expression
left cop right
The comparison cop is define by the cases below. The Json graph corresponds to the comparison being true. If, for a value of the independent parameters and variables, the comparison is false, the Json graph may no longer be valid. For example, the Json graph may only contain the code for the true case below:
if
( left cop right )else
Including this operator enables CppAD to detect when the graph may no longer be a valid representation of the intended function.
comp_eq¶
For this operator cop is ==
comp_le¶
For this operator cop is <=
comp_lt¶
For this operator cop is <
comp_ne¶
For this operator cop is !=
Other Comparisons¶
The comparison result true for left > right is equivalent to the comparison result true for right < left . The comparison result false for left > right is equivalent to the comparison result true for left <= right . In a similar fashion, all the possible comparisons results can be converted to a true result for one of the comparisons above.
Example¶
The file json_comp_op.cpp is an example and test for one of these operators.
Discrete Functions¶
This operator has the following Json definition:
"op_code"
: op_code ,"name"
: "discrete"
A corresponding op_usage has the form
[ op_code , name , n_result , n_arg , [ arg ] ]
name¶
The value name is a String specifying the name of the discrete function that is called.
n_result¶
This is always 1
because a discrete function
creates one new node.
The result node value is the specified discrete function of the argument value.
n_arg¶
This is always 1
because a discrete function has
one argument node.
arg¶
is the node index for the argument to the discrete function.
Example¶
the example and test json_discrete_op.cpp .
Atomic Functions¶
These operators create n_result nodes with values determined by an evaluation of the an atomic_three or atomic_four function.
Atomic Three¶
This operator has the following Json definition:
"op_code"
: op_code ,"name"
: "atom"
A corresponding op_usage has the form
Atomic Four¶
This operator has the following Json definition:
"op_code"
: op_code ,"name"
: "atom4"
A corresponding op_usage has the form
name¶
The value name is a
String specifying the
name
of the atomic_three
function that is called.
call_id¶
is a Non-Negative Integer specifying the call_id for an atomic four function.
n_result¶
is the number of results for this function; i.e., its range space dimension.
n_arg¶
is the number of arguments to this function; i.e., its domain space dimension.
first_arg, …, last_arg¶
The values corresponding to the node indices
first_arg , …, last_arg are the
arguments (independent variables) for the atomic function evaluation.
In the case where the atomic function is a chkpoint_two
function,
the independent dynamic parameters are specified by calling its
new_dynamic routine.
Example¶
the example and test json_atom_op.cpp .
Print¶
This operator has the following Json definition:
"op_code"
: op_code ,"name"
: "print"
A corresponding op_usage has the form
[ op_code , before , after , n_result , n_arg , [ notpos , value ] ]
before¶
is a String that is printed before the value for this operator.
after¶
is a String that is printed after the value for this operator.
n_result¶
This is always zero because a print operator does not create any new nodes.
n_arg¶
This is always two because a print operator has two argument nodes.
notpos¶
This is notpos which determines if the value is printed.
value¶
This is the value that is printed.
Example¶
The file json_print_op.cpp is an example and test of this operator.
Contents¶
Name |
Title |
---|---|
json_unary_op.cpp |
|
json_add_op.cpp |
|
json_azmul_op.cpp |
|
json_div_op.cpp |
|
json_mul_op.cpp |
|
json_pow_op.cpp |
|
json_sub_op.cpp |
|
json_sum_op.cpp |
|
json_cexp_op.cpp |
|
json_comp_op.cpp |
|
json_discrete_op.cpp |
|
json_atom_op.cpp |
|
json_atom4_op.cpp |
|
json_print_op.cpp |