1 # ifndef CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
2 # define CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
19 namespace CppAD {
namespace local {
namespace optimize {
101 size_t num_arg =
NumArg(op);
102 for(
size_t j = 0; j < num_arg; ++j)
103 { arg_match[j] = arg[j];
105 {
size_t j_op = play->
var2op(arg[j]);
106 size_t previous = opt_op_info[j_op].previous;
118 arg_match[j] =
addr_t( i_var_p );
129 while( *itr != num_op )
133 size_t candidate = *itr;
140 play->
get_op_info(candidate, op_c, arg_c, i_var_c);
143 bool match = op == op_c;
145 {
for(
size_t j = 0; j < num_arg; j++)
148 opt_op_info[ play->
var2op(arg_c[j]) ].previous;
152 opt_op_info[previous].previous == 0
160 match &= arg_match[j] ==
addr_t( i_var_p );
162 else match &= arg_match[j] == arg_c[j];
165 { match &= arg_match[j] == arg_c[j];
170 { opt_op_info[current].previous =
static_cast<addr_t>( candidate );
179 std::swap( arg_match[0], arg_match[1] );
183 while( *itr_swap != num_op )
185 size_t candidate = *itr_swap;
192 play->
get_op_info(candidate, op_c, arg_c, i_var_c);
194 bool match = op == op_c;
196 {
for(
size_t j = 0; j < num_arg; j++)
199 opt_op_info[ play->
var2op(arg_c[j]) ].previous;
202 opt_op_info[previous].previous == 0
210 match &= arg_match[j] ==
addr_t( i_var_p );
213 match &= arg_match[j] == arg_c[j];
217 { opt_op_info[current].previous =
static_cast<addr_t>(candidate);
226 hash_table_op.
clear(code);
size_t end(void) const
Fetch end for this vector of sets object.
Vector of sets of positive integers, each set stored as a singly linked list.
size_t arg_is_variable(OpCode op, const addr_t *arg, pod_vector< bool > &is_variable)
Determines which arguments are variaibles for an operator.
void add_element(size_t i, size_t element)
Add one element to a set.
The CppAD Simple Vector template class.
CPPAD_TAPE_ADDR_TYPE addr_t
size_t optimize_hash_code(OpCode op, size_t num_arg, const addr_t *arg)
Specialized hash code for a CppAD operator and its arguments (used during optimization).
size_t NumArg(OpCode op)
Number of arguments for a specified operator.
Class used to store and play back an operation sequence recording.
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
void match_op(const player< Base > *play, vector< struct_opt_op_info > &opt_op_info, size_t current, sparse_list &hash_table_op)
Search for a previous operator that matches the current one.
size_t size(void) const
number of elements currently in this vector.
OpCode
Type used to distinguish different AD< Base > atomic operations.
void get_op_info(size_t op_index, OpCode &op, const addr_t *&op_arg, size_t &var_index) const
fetch the information corresponding to an operator
size_t size(void) const
current number of elements in this vector.
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
void clear(size_t target)
Assign the empty set to one of the sets.
size_t num_op_rec(void) const
Fetch number of operators in the recording.
size_t n_set(void) const
Fetch n_set for vector of sets object.
size_t var2op(size_t var_index) const
fetch the operator corresponding to a primary variable
cons_iterator for one set of positive integers in a sparse_list object.
#define CPPAD_HASH_TABLE_SIZE
the codes retruned by hash_code are between zero and CPPAD_HASH_TABLE_SIZE minus one.