Skip to content

Commit

Permalink
Merge pull request #630 from nlmixr2/629-mem-issues
Browse files Browse the repository at this point in the history
629 mem issues
  • Loading branch information
mattfidler authored Dec 6, 2023
2 parents dd99ee0 + d60cfeb commit 5000367
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/approx.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static inline double getValue(int idx, double *y, rx_solving_options_ind *ind, r
if (op->f2 == 1.0 && op->f1 == 0.0) {
// use nocb
// Go forward
while (ISNA(ret) && i != ind->n_all_times){
while (ISNA(ret) && i != ind->n_all_times-1){
i++; ret = y[ind->ix[i]];
}
if (ISNA(ret)){
Expand Down Expand Up @@ -309,4 +309,3 @@ void _update_par_ptr(double t, unsigned int id, rx_solve *rx, int idxIn) {

/* void doSort(rx_solving_options_ind *ind); */
void sortInd(rx_solving_options_ind *ind);

19 changes: 13 additions & 6 deletions src/rxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void resetSolveLinB();
using namespace Rcpp;
using namespace arma;

typedef void (*seedEng_t)(uint32_t ncores);
typedef void (*seedEng_t)(int ncores);
extern seedEng_t seedEng;

#include "cbindThetaOmega.h"
Expand Down Expand Up @@ -2144,15 +2144,22 @@ List rxSimThetaOmega(const Nullable<NumericVector> &params = R_NilValue,
}
if (_globals.gsigma != NULL) free(_globals.gsigma);
rx->neps = sigma0.n_rows;
_globals.gsigma = (double*)malloc((rx->neps * rx->neps + 2 * rx->neps)* sizeof(double));
std::copy(&sigma0[0], &sigma0[0] + rx->neps * rx->neps, _globals.gsigma + 2 * rx->neps);
if (rx->neps > 0) {
_globals.gsigma = (double*)malloc((rx->neps * rx->neps + 2 * rx->neps)* sizeof(double));
std::copy(&sigma0[0], &sigma0[0] + rx->neps * rx->neps,
_globals.gsigma + 2 * rx->neps);
} else {
_globals.gsigma = NULL;
}
_globals.nSigma = 0;
}
arma::vec in = as<arma::vec>(sigmaLower);
arma::vec lowerSigmaV = fillVec(in, sigma0.n_rows);
arma::vec upperSigmaV = fillVec(in, sigma0.n_rows);
std::copy(&lowerSigmaV[0], &lowerSigmaV[0] + rx->neps, _globals.gsigma);
std::copy(&upperSigmaV[0], &upperSigmaV[0] + rx->neps, _globals.gsigma + rx->neps);
if (rx->neps > 0) {
std::copy(&lowerSigmaV[0], &lowerSigmaV[0] + rx->neps, _globals.gsigma);
std::copy(&upperSigmaV[0], &upperSigmaV[0] + rx->neps, _globals.gsigma + rx->neps);
}
// structure of _globals.gsigma is
// lower
// upper
Expand Down Expand Up @@ -4886,7 +4893,7 @@ SEXP rxSolve_(const RObject &obj, const List &rxControl,
warning(_("since throwing warning with NA time, change to single threaded"));
op->cores=1;
}
seedEng(op->cores);
seedEng((int)(op->cores));
if (_globals.pendingDoses != NULL) {
int i=0;
while (_globals.pendingDoses[i] != NULL){
Expand Down
15 changes: 13 additions & 2 deletions src/rxode2_df.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>
#include <stdio.h>
#include <climits>
#include <cmath>
#include "checkmate.h"
#include <stdint.h> // for uint64_t rather than unsigned long long
#include "../inst/include/rxode2.h"
Expand Down Expand Up @@ -751,12 +752,22 @@ extern "C" SEXP rxode2_df(int doDose0, int doTBS) {
} else if (TYPEOF(tmp) == LGLSXP) {
// Everything here is double
dfi = LOGICAL(tmp);
dfi[ii] = (int) (get_fkeep(j, curi + ind->ix[i], ind));
double curD = get_fkeep(j, curi + ind->ix[i], ind);
if (ISNA(curD) || std::isnan(curD)) {
dfi[ii] = NA_LOGICAL;
} else {
dfi[ii] = (int) (curD);
}
} else {
dfi = INTEGER(tmp);
/* if (j == 0) RSprintf("j: %d, %d; %f\n", j, i, get_fkeep(j, curi + i)); */
// is this ntimes = nAllTimes or nObs time for this subject...?
dfi[ii] = (int) (get_fkeep(j, curi + ind->ix[i], ind));
double curD = get_fkeep(j, curi + ind->ix[i], ind);
if (ISNA(curD) || std::isnan(curD)) {
dfi[ii] = NA_INTEGER;
} else {
dfi[ii] = (int) (curD);
}
}
jj++;
}
Expand Down
3 changes: 3 additions & 0 deletions src/rxode2parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ END_RCPP

extern "C" SEXP _rxode2parse_udfEnvSet(SEXP udf) {
BEGIN_RCPP
if (Rf_isNull(udf)) {
return R_NilValue;
}
if (Rf_length(udf) == 0 || Rf_length(udf) == 1) {
return R_NilValue;
}
Expand Down

0 comments on commit 5000367

Please sign in to comment.