2 namespace dynamic_data {
12 double sexp_to_double(SEXP x);
13 SEXP double_to_sexp(
double x);
14 double charptr_to_double(
const char *x);
15 const char* double_to_charptr(
double x);
17 double sexp_to_double(SEXP x) {
19 double* py = (
double*) px;
22 SEXP double_to_sexp(
double x) {
24 SEXP* py = (SEXP*) px;
27 double charptr_to_double(
const char *x) {
29 double* py = (
double*) px;
32 const char* double_to_charptr(
double x) {
34 const char** py = (
const char**) px;
37 #endif // #ifdef WITH_LIBTMB 47 SEXP data = double_to_sexp( tx[0] );
48 int index = (int) tx[1];
49 ty[0] = sexp_to_double( VECTOR_ELT(data, index) );
63 SEXP list = double_to_sexp( tx[0] );
64 const char* str = double_to_charptr( tx[1] );
65 SEXP elmt = R_NilValue;
66 SEXP names = Rf_getAttrib(list, R_NamesSymbol);
68 for (i = 0; i < Rf_length(list); i++) {
69 if(strcmp(CHAR(STRING_ELT(names, i)), str) == 0) {
70 elmt = VECTOR_ELT(list, i);
74 ty[0] = sexp_to_double( elmt );
88 SEXP envir = double_to_sexp( tx[0] );
89 const char* nam = double_to_charptr( tx[1] );
90 SEXP res = Rf_findVar(Rf_install(nam), envir);
91 ty[0] = sexp_to_double( res );
103 LENGTH( double_to_sexp( asDouble(tx[0]) ))
106 SEXP data = double_to_sexp( tx[0] );
107 int n = LENGTH( data );
108 if (n != (
int) ty.size())
109 Rf_error(
"Data update: " 110 "number of items to replace (%i) " 111 "does not match replacement length (%i)",
113 double* pdata = REAL(data);
114 for (
int i = 0; i<n; i++) ty[i] = pdata[i];
134 px[0] = 0; px[1] = 0;
140 Type set_dependent(
double x, Type fake_parameter) {
141 CppAD::vector<Type> tx(2);
143 tx[1] = fake_parameter;
144 return set_dependent(tx)[0];
149 CppAD::vector<Type> tx(1);
151 CppAD::vector<Type> ty(sexp_to_vector(tx));
157 Type envir_lookup_by_name(Type envir,
const char* name) {
158 CppAD::vector<Type> tx(2);
160 tx[1] = charptr_to_double( name );
161 return envir_lookup_by_name(tx)[0];
166 Type list_lookup_by_name(Type list,
const char* name) {
167 CppAD::vector<Type> tx(2);
169 tx[1] = charptr_to_double( name );
170 return list_lookup_by_name(tx)[0];
175 Type list_lookup_by_index(Type list, Type index) {
176 CppAD::vector<Type> tx(2);
179 return list_lookup_by_index(tx)[0];
183 template<
class T1,
class T2>
184 void cpy(T1 &x, T2 y) {
185 for (
int i=0; i<y.size(); i++) {
186 x.coeffRef(i) = y.coeffRef(i);
221 #define DATA_UPDATE(name) \ 222 atomic::dynamic_data::cpy(name, \ 223 atomic::dynamic_data::sexp_to_vector( \ 224 atomic::dynamic_data::list_lookup_by_name( \ 225 atomic::dynamic_data::envir_lookup_by_name( \ 226 atomic::dynamic_data::set_dependent( \ 227 atomic::dynamic_data::sexp_to_double( \ 228 ENCLOS(TMB_OBJECTIVE_PTR -> report) \ 230 TMB_OBJECTIVE_PTR -> theta[0] \ Vector class used by TMB.
Namespace with special functions and derivatives.
#define TMB_ATOMIC_VECTOR_FUNCTION( ATOMIC_NAME, OUTPUT_DIM, ATOMIC_DOUBLE, ATOMIC_REVERSE)
Construct atomic vector function based on known derivatives.