diff --git a/TMB/inst/include/convert.hpp b/TMB/inst/include/convert.hpp index 1b9cd73e8..3347ae607 100644 --- a/TMB/inst/include/convert.hpp +++ b/TMB/inst/include/convert.hpp @@ -5,19 +5,16 @@ \brief Convert vector/matrix-Types to double SEXP types */ -#ifdef WITH_LIBTMB -double asDouble(int x); -double asDouble(double x); -double asDouble(AD x); -double asDouble(AD > x); -double asDouble(AD > > x); -#else -double asDouble(int x){return double(x);} -double asDouble(double x){return x;} -double asDouble(AD x){return CppAD::Value(x);} -double asDouble(AD > x){return CppAD::Value(CppAD::Value(x));} -double asDouble(AD > > x){return CppAD::Value(CppAD::Value(CppAD::Value(x)));} -#endif +inline double asDouble(double const x){ + return x; +} +inline double asDouble(int const x){ + return x; +} +template +double asDouble(AD const x){ + return asDouble(CppAD::Value(x)); +} /** \brief Convert TMB matrix, vector, scalar or int to R style */ template @@ -28,8 +25,8 @@ SEXP asSEXP(const matrix &a) SEXP val; PROTECT(val = Rf_allocMatrix(REALSXP, nr, nc)); double *p = REAL(val); - for(R_xlen_t i=0; i asMatrix(SEXP x) R_xlen_t nr = Rf_nrows(x); // nrows is int R_xlen_t nc = Rf_ncols(x); // ncols is int matrix y(nr, nc); - for(R_xlen_t i=0; i0)&(nrows!=ncols))Rf_error("hessianrows and hessianrows must have same length"); + if((nrows>0)&(nrows!=ncols))Rf_error("hessianrows and hessiancols must have same length"); vector cols(ncols); vector cols0(ncols); vector rows(nrows);