Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for environment a bit more stricter #242

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 0 additions & 147 deletions .github/workflows/R-CMD-check-CRAN.yaml

This file was deleted.

7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ cholSE <- function(matrix, tol = (.Machine$double.eps)^(1 / 3)) {
#' @return a list of ...
#' @export
nmsimplex <- function(start, fr, rho = NULL, control = list()) {
if (is.null(rho)) rho <- environment(fr)
if (!is.environment(rho)) {
if (!is.null(rho)) {
warning("improper argument for 'rho'", call.=FALSE)
}
rho <- environment(fr)
}
step <- -.2 * start

con <- list(maxeval = 999, reltol = 1e-6, rcoeff = 1., ecoeff = 2., ccoeff = .5, trace = FALSE)
Expand Down
59 changes: 29 additions & 30 deletions src/RcppExportMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,35 @@ neldermead_wrap(SEXP fcallSEXP, SEXP rhoSEXP, SEXP nparSEXP, SEXP startSEXP, SEX
SEXP iprintSEXP)
{
BEGIN_RCPP

ev = new Rcpp::EvalStandard(fcallSEXP, rhoSEXP); // assign R function and environment
int i, Iconv, Itnum, Nfcall, Itmax, iprint;
double ftol_rel, rcoef, ecoef, ccoef;
double Start[99], Xmin[99], Ynewlo, Step[99];

NPAR = INTEGER(nparSEXP)[0];
for (i=0; i<NPAR; i++) Start[i] = REAL(startSEXP)[i];
for (i=0; i<NPAR; i++) Step[i] = REAL(stepSEXP )[i];
Itmax = INTEGER(itmaxSEXP)[0];
ftol_rel = REAL(ftol_relSEXP)[0];
rcoef = REAL(rcoefSEXP)[0];
ecoef = REAL(ecoefSEXP)[0];
ccoef = REAL(ccoefSEXP)[0];
iprint = INTEGER(iprintSEXP)[0];

nelder_fn(nmfn_wrap, NPAR, Start, Step,
Itmax, ftol_rel, rcoef, ecoef, ccoef,
&Iconv, &Itnum, &Nfcall, &Ynewlo, Xmin,
&iprint);
//Rcpp::Rcout <<ev->getNbEvals() <<std::endl;

Rcpp::NumericVector par(NPAR);
for (i=0; i<NPAR; i++) par[i] = Xmin[i];
return Rcpp::List::create(Rcpp::Named("convergence") = Iconv,
Rcpp::Named("Itnum") = Itnum,
Rcpp::Named("iter") = Nfcall,
Rcpp::Named("value") = Ynewlo,
Rcpp::Named("par") = par);

if (TYPEOF(rhoSEXP) != ENVSXP) stop("'rho' must be an environment");
ev = new Rcpp::EvalStandard(fcallSEXP, rhoSEXP); // assign R function and environment
int i, Iconv, Itnum, Nfcall, Itmax, iprint;
double ftol_rel, rcoef, ecoef, ccoef;
double Start[99], Xmin[99], Ynewlo, Step[99];

NPAR = INTEGER(nparSEXP)[0];
for (i=0; i<NPAR; i++) Start[i] = REAL(startSEXP)[i];
for (i=0; i<NPAR; i++) Step[i] = REAL(stepSEXP )[i];
Itmax = INTEGER(itmaxSEXP)[0];
ftol_rel = REAL(ftol_relSEXP)[0];
rcoef = REAL(rcoefSEXP)[0];
ecoef = REAL(ecoefSEXP)[0];
ccoef = REAL(ccoefSEXP)[0];
iprint = INTEGER(iprintSEXP)[0];

nelder_fn(nmfn_wrap, NPAR, Start, Step,
Itmax, ftol_rel, rcoef, ecoef, ccoef,
&Iconv, &Itnum, &Nfcall, &Ynewlo, Xmin,
&iprint);
//Rcpp::Rcout <<ev->getNbEvals() <<std::endl;

Rcpp::NumericVector par(NPAR);
for (i=0; i<NPAR; i++) par[i] = Xmin[i];
return Rcpp::List::create(Rcpp::Named("convergence") = Iconv,
Rcpp::Named("Itnum") = Itnum,
Rcpp::Named("iter") = Nfcall,
Rcpp::Named("value") = Ynewlo,
Rcpp::Named("par") = par);
END_RCPP
}

Expand Down