Prev Next a_fun_property_xam.cpp Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
C++: a_fun Properties: Example and Test
# include <cstdio>
# include <string>
# include <cppad/swig/cppad_swig.hpp>

bool a_fun_property_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 = 1; // number of independent variables
     int n_dep = 2; // number of dependent variables
     int n_var = 1; // phantom variable at address 0
     int n_op = 1;  // special operator at beginning
     //
     // dimension some vectors
     vec_double x = cppad_swig::vec_double(n_ind);
     vec_a_double ay = cppad_swig::vec_a_double(n_dep);
     //
     // independent variables
     x[0] = 1.0;
     vec_a_double ax = cppad_swig::independent(x);
     n_var = n_var + n_ind; // one for each indpendent
     n_op = n_op + n_ind;
     //
     // first dependent variable
     ay[0] = ax[0] + ax[0];
     n_var = n_var + 1; // one variable and operator
     n_op = n_op + 1;
     //
     // second dependent variable
     a_double ax0 = ax[0];
     ay[1] = ax0.sin();
     n_var = n_var + 2; // two varialbes, one operator
     n_op = n_op + 1;
     //
     // define f(x) = y
     a_fun af = cppad_swig::a_fun(ax, ay);
     n_op = n_op + 1; // speical operator at end
     //
     // check af properties
     ok = ok && af.size_ind() == n_ind;
     ok = ok && af.size_dep() == n_dep;
     ok = ok && af.size_var() == n_var;
     ok = ok && af.size_op() == n_op;
     //
     return( ok  );
}

Input File: build/lib/example/cplusplus/a_fun_property_xam.cpp