|
Prev | Next | a_fun_abort_xam.cpp | Headings |
# include <cstdio>
# include <string>
# include <cppad/swig/cppad_swig.hpp>
bool a_fun_abort_xam(void) {
using cppad_swig::a_double;
using cppad_swig::vec_bool;
using cppad_swig::vec_int;
using cppad_swig::vec_double;
using cppad_swig::vec_a_double;
using cppad_swig::a_fun;
using cppad_swig::sparse_rc;
using cppad_swig::sparse_rcv;
using cppad_swig::sparse_jac_work;
using cppad_swig::sparse_hes_work;
using std::string;
//
// initialize return variable
bool ok = true;
//------------------------------------------------------------------------
int n_ind = 2;
//
// create ax
vec_double x = cppad_swig::vec_double(n_ind);
for(int i = 0; i < n_ind ; i++) {
x[i] = i + 1.0;
}
vec_a_double ax = cppad_swig::independent(x);
//
// preform some a_double operations
a_double ax0 = ax[0];
a_double ax1 = ax[1];
a_double ay = ax0 + ax1;
//
// check that ay is a variable; its value depends on the value of ax
ok = ok && ay.variable();
//
// abort this recording
cppad_swig::abort_recording();
//
// check that ay is now a parameter, no longer a variable.
ok = ok && ay.parameter();
//
// since it is a parameter, we can retrieve its value
double y = ay.value();
//
// its value should be x0 + x1
ok = ok && y == x[0] + x[1];
//
// an abort when not recording has no effect
cppad_swig::abort_recording();
//
return( ok );
}