1 # ifndef CPPAD_LOCAL_FOR_HES_SWEEP_HPP
2 # define CPPAD_LOCAL_FOR_HES_SWEEP_HPP
15 namespace CppAD {
namespace local {
27 # define CPPAD_FOR_HES_SWEEP_TRACE 0
91 template <
class Base,
class Vector_set>
96 const Vector_set& for_jac_sparse,
97 const Vector_set& rev_jac_sparse,
98 Vector_set& for_hes_sparse
105 const addr_t* arg = CPPAD_NULL;
128 Vector_set vecad_sparse;
131 if( num_vecad_vec > 0 )
133 vecad_sparse.
resize(num_vecad_vec, limit);
134 vecad_ind.
extend(num_vecad_ind);
135 vecad_jac.
extend(num_vecad_vec);
137 for(i = 0; i < num_vecad_vec; i++)
143 for(k = 1; k <= length; k++)
144 vecad_ind[j+k] = num_vecad_vec;
148 vecad_jac[i] =
false;
162 size_t user_old=0, user_m=0, user_n=0, user_i=0, user_j=0;
169 const Base* parameter = CPPAD_NULL;
171 parameter = play->
GetPar();
177 bool more_operators =
true;
178 # if CPPAD_FOR_HES_SWEEP_TRACE
180 std::cout << std::endl;
185 while(more_operators)
192 bool include =
NumRes(op) > 0;
194 include = rev_jac_sparse.is_element(i_var, 0);
197 include |= op ==
EndOp;
206 if( include )
switch( op )
250 # if CPPAD_USE_CPLUSPLUS_2011
259 arg[0], for_jac_sparse, for_hes_sparse
275 arg, for_jac_sparse, for_hes_sparse
283 arg[1], for_jac_sparse, for_hes_sparse
290 more_operators =
false;
299 arg[0], for_jac_sparse, for_hes_sparse
323 arg, for_jac_sparse, for_hes_sparse
331 arg[1], for_jac_sparse, for_hes_sparse
339 arg[0], for_jac_sparse, for_hes_sparse
347 arg, for_jac_sparse, for_hes_sparse
358 user_atom = play->
get_user_info(op, arg, user_old, user_m, user_n);
367 # if CPPAD_FOR_HES_SWEEP_TRACE
368 user_usrrp.
resize( user_m );
376 user_x, user_ix, user_iy,
377 for_jac_sparse, rev_jac_sparse, for_hes_sparse
390 user_x[user_j] = parameter[arg[0]];
394 if( user_j == user_n )
407 user_ix[user_j] = arg[0];
410 if( user_j == user_n )
423 # if CPPAD_FOR_HES_SWEEP_TRACE
425 user_usrrp[user_i] = arg[0];
428 if( user_i == user_m )
439 user_iy[user_i] = i_var;
442 if( user_i == user_m )
450 arg, for_jac_sparse, for_hes_sparse
459 # if CPPAD_FOR_HES_SWEEP_TRACE
460 typedef typename Vector_set::const_iterator const_iterator;
468 for(k = 0; k < user_m; k++)
469 {
size_t k_var = user_iy[k];
471 for(i = 0; i < limit; i++)
472 { zf_value[i] =
false;
473 for(j = 0; j < limit; j++)
474 zh_value[i * limit + j] =
false;
476 const_iterator itr_1(for_jac_sparse, i_var);
479 { zf_value[j] =
true;
482 for(i = 0; i < limit; i++)
483 { const_iterator itr_2(for_hes_sparse, i);
486 { zh_value[i * limit + j] =
true;
493 arg_tmp[0] = user_usrrp[k];
511 std::cout << std::endl;
514 for(i = 0; i < limit; i++)
515 { zf_value[i] =
false;
516 for(j = 0; j < limit; j++)
517 zh_value[i * limit + j] =
false;
519 const_iterator itr_1(for_jac_sparse, i_var);
522 { zf_value[j] =
true;
525 for(i = 0; i < limit; i++)
526 { const_iterator itr_2(for_hes_sparse, i);
529 { zh_value[i * limit + j] =
true;
534 bool delay_print = op ==
UsrrpOp;
552 std::cout << std::endl;
555 std::cout << std::endl;
565 # undef CPPAD_FOR_HES_SWEEP_TRACE
void resize(size_t n)
resize the vector (existing elements preserved when n <= capacity_).
size_t num_par_rec(void) const
Fetch number of parameters in the recording.
size_t extend(size_t n)
Increase the number of elements the end of this vector (existing elements are always preserved)...
void printOpResult(std::ostream &os, size_t nfz, const Value *fz, size_t nrz, const Value *rz)
Prints the result values correspnding to an operator.
size_t num_vec_ind_rec(void) const
Fetch number of VecAD indices in the recording.
CPPAD_TAPE_ADDR_TYPE addr_t
static Float quiet_NaN(void)
not a number
next UsrrpOp (UsrrvOp) is a parameter (variable) result
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 GetVecInd(size_t i) const
Fetch a VecAD index from the recording.
void resize(size_t n)
change the number of elements in this vector.
size_t NumRes(OpCode op)
Number of variables resulting from the specified operation.
virtual bool for_sparse_hes(const vector< bool > &vx, const vector< bool > &r, const vector< bool > &s, vector< std::set< size_t > > &h, const vector< Base > &x)
Link, after case split, from for_hes_sweep to atomic_base.
next UserOp marks end of a user atomic call
atomic_base< Base > * get_user_info(const OpCode op, const addr_t *op_arg, size_t &user_old, size_t &user_m, size_t &user_n) const
unpack extra information corresponding to a UserOp
void forward_sparse_hessian_mul_op(const addr_t *arg, const Vector_set &for_jac_sparsity, Vector_set &for_hes_sparsity)
Forward mode Hessian sparsity pattern for multiplication operator.
virtual void set_old(size_t id)
Set value of id (used by deprecated old_atomic class)
size_t size(void) const
number of elements currently in this vector.
OpCode
Type used to distinguish different AD< Base > atomic operations.
void forward_sparse_hessian_pow_op(const addr_t *arg, const Vector_set &for_jac_sparsity, Vector_set &for_hes_sparsity)
Forward mode Hessian sparsity pattern for power operator.
next UserOp marks beginning of a user atomic call
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 num_vecad_vec_rec(void) const
Fetch number of VecAD vectors in the recording.
next UsrapOp (UsravOp) is a parameter (variable) argument
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
void forward_sparse_hessian_nonlinear_unary_op(size_t i_v, const Vector_set &for_jac_sparsity, Vector_set &for_hes_sparsity)
Forward mode Hessian sparsity pattern for non-linear unary operators.
void printOp(std::ostream &os, const local::player< Base > *play, size_t i_op, size_t i_var, OpCode op, const addr_t *ind)
Prints a single operator and its operands.
#define CPPAD_ASSERT_NARG_NRES(op, n_arg, n_res)
Check that operator op has the specified number of of arguments and results.
void forward_sparse_hessian_div_op(const addr_t *arg, const Vector_set &for_jac_sparsity, Vector_set &for_hes_sparsity)
Forward mode Hessian sparsity pattern for division operator.
Base GetPar(size_t i) const
Fetch a parameter from the recording.
void for_hes_sweep(const local::player< Base > *play, size_t n, size_t numvar, const Vector_set &for_jac_sparse, const Vector_set &rev_jac_sparse, Vector_set &for_hes_sparse)
Given the forward Jacobian sparsity pattern for all the variables, and the reverse Jacobian sparsity ...
size_t num_var_rec(void) const
Fetch number of variables in the recording.