Skip to content

Commit

Permalink
require named arguments even in workhorses
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Dec 11, 2024
1 parent 9593da1 commit 87446e5
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 114 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pomp
Type: Package
Title: Statistical Inference for Partially Observed Markov Processes
Version: 6.0.1.1
Version: 6.0.1.2
Date: 2024-12-11
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="[email protected]",comment=c(ORCID="0000-0001-6159-3207")),
person(given=c("Edward","L."),family="Ionides",role="aut",comment=c(ORCID="0000-0002-4190-0174")) ,
Expand Down
17 changes: 12 additions & 5 deletions R/flow.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ setMethod(
"flow",
signature=signature(object="pomp"),
definition=function (
object, x0,
object,
...,
x0,
t0 = timezero(object),
times = time(object),
params = coef(object),
...,
verbose = getOption("verbose", FALSE)) {
verbose = getOption("verbose", FALSE)
) {

tryCatch(
flow_internal(object=object,x0=x0,t0=t0,times=times,params=params,
Expand All @@ -80,8 +82,13 @@ setMethod(
}
)

flow_internal <- function (object, x0, t0, times, params, ...,
.gnsi = TRUE, verbose) {
flow_internal <- function (
object,
...,
x0, t0, times, params,
.gnsi = TRUE,
verbose
) {

verbose <- as.logical(verbose)

Expand Down
2 changes: 1 addition & 1 deletion R/trajectory.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ trajectory_internal <- function (
pompLoad(object)
on.exit(pompUnload(object))

x0 <- rinit(object,params=params,verbose=verbose,.gnsi=.gnsi)
x0 <- rinit(object,params=params,.gnsi=.gnsi)

x <- do.call(
flow,
Expand Down
129 changes: 88 additions & 41 deletions R/workhorses.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ NULL
##' @param params a \code{npar} x \code{nrep} matrix of parameters.
##' Each column is treated as an independent parameter set, in correspondence with the corresponding column of \code{x}.
##' @param log if TRUE, log probabilities are returned.
##' @param \dots additional arguments are ignored.
##' @param ... additional arguments are ignored.
##' @return
##' \code{dmeasure} returns a matrix of dimensions \code{nreps} x \code{ntimes}.
##' If \code{d} is the returned matrix, \code{d[j,k]} is the likelihood (or log likelihood if \code{log = TRUE}) of the observation \code{y[,k]} at time \code{times[k]} given the state \code{x[,j,k]}.
Expand Down Expand Up @@ -95,11 +95,11 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
...,
y = obs(object),
x = states(object),
times = time(object),
params = coef(object),
...,
log = FALSE
) {
tryCatch(
Expand All @@ -110,8 +110,12 @@ setMethod(
}
)

dmeasure_internal <- function (object, y, x, times, params, ..., log = FALSE,
.gnsi = TRUE) {
dmeasure_internal <- function (
object,
y, x, times, params,
log = FALSE,
.gnsi = TRUE
) {
storage.mode(y) <- "double"
storage.mode(x) <- "double"
storage.mode(params) <- "double"
Expand Down Expand Up @@ -167,8 +171,8 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
params = coef(object),
...,
params = coef(object),
log = FALSE
) {
tryCatch(
Expand All @@ -178,8 +182,12 @@ setMethod(
}
)

dprior_internal <- function (object, params, log = FALSE,
.gnsi = TRUE, ...) {
dprior_internal <- function (
object,
params,
log = FALSE,
.gnsi = TRUE
) {
storage.mode(params) <- "double"
pompLoad(object)
on.exit(pompUnload(object))
Expand Down Expand Up @@ -233,10 +241,10 @@ setMethod(
signature=signature(object="pomp"),
definition = function (
object,
...,
x = states(object),
times = time(object),
params = coef(object),
...,
log = FALSE
) {
tryCatch(
Expand All @@ -246,7 +254,12 @@ setMethod(
}
)

dprocess_internal <- function (object, x, times, params, log = FALSE, .gnsi = TRUE, ...) {
dprocess_internal <- function (
object,
x, times, params,
log = FALSE,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -302,7 +315,8 @@ setMethod(
"partrans",
signature=signature(object="pomp"),
definition=function (
object, params,
object,
params,
dir = c("fromEst", "toEst"),
...
) {
Expand All @@ -314,8 +328,12 @@ setMethod(
}
)

partrans_internal <- function (object, params, dir = c("fromEst", "toEst"),
.gnsi = TRUE, ...) {
partrans_internal <- function (
object,
params,
dir = c("fromEst", "toEst"),
.gnsi = TRUE
) {
if (object@partrans@has) {
dir <- switch(dir,fromEst=-1L,toEst=1L)
pompLoad(object)
Expand Down Expand Up @@ -374,10 +392,10 @@ setMethod(
signature=signature("pomp"),
definition=function (
object,
...,
params = coef(object),
t0 = timezero(object),
nsim = 1,
...
nsim = 1
) {
tryCatch(
rinit_internal(object=object,params=params,t0=t0,nsim=nsim,...),
Expand All @@ -386,8 +404,12 @@ setMethod(
}
)

rinit_internal <- function (object, params, t0, nsim = 1,
.gnsi = TRUE, ...) {
rinit_internal <- function (
object,
params, t0,
nsim = 1,
.gnsi = TRUE
) {
storage.mode(params) <- "double"
pompLoad(object)
on.exit(pompUnload(object))
Expand Down Expand Up @@ -442,11 +464,11 @@ setMethod(
signature=signature("pomp"),
definition=function (
object,
...,
params = coef(object),
t0 = timezero(object),
x,
log = FALSE,
...
log = FALSE
) {
tryCatch(
dinit_internal(object=object,x=x,params=params,t0=t0,log=log,...),
Expand All @@ -455,7 +477,12 @@ setMethod(
}
)

dinit_internal <- function (object, x, params, t0, log, .gnsi = TRUE, ...) {
dinit_internal <- function (
object,
x, params, t0,
log,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -511,10 +538,10 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
...,
x = states(object),
times = time(object),
params = coef(object),
...
params = coef(object)
) {
tryCatch(
rmeasure_internal(object=object,x=x,times=times,params=params,...),
Expand All @@ -523,8 +550,11 @@ setMethod(
}
)

rmeasure_internal <- function (object, x, times, params,
.gnsi = TRUE, ...) {
rmeasure_internal <- function (
object,
x, times, params,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -578,10 +608,10 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
...,
x = states(object),
times = time(object),
params = coef(object),
...
params = coef(object)
) {
tryCatch(
emeasure_internal(object=object,x=x,times=times,params=params,...),
Expand All @@ -590,8 +620,11 @@ setMethod(
}
)

emeasure_internal <- function (object, x, times, params,
.gnsi = TRUE, ...) {
emeasure_internal <- function (
object,
x, times, params,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -647,10 +680,10 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
...,
x = states(object),
times = time(object),
params = coef(object),
...
params = coef(object)
) {
tryCatch(
vmeasure_internal(object=object,x=x,times=times,params=params,...),
Expand All @@ -659,8 +692,11 @@ setMethod(
}
)

vmeasure_internal <- function (object, x, times, params,
.gnsi = TRUE, ...) {
vmeasure_internal <- function (
object,
x, times, params,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -715,16 +751,20 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
params = coef(object),
...
...,
params = coef(object)
)
tryCatch(
rprior_internal(object=object,params=params,...),
error = function (e) pStop(who="rprior",conditionMessage(e))
)
)

rprior_internal <- function (object, params, .gnsi = TRUE, ...) {
rprior_internal <- function (
object,
params,
.gnsi = TRUE
) {
storage.mode(params) <- "double"
pompLoad(object)
on.exit(pompUnload(object))
Expand Down Expand Up @@ -795,11 +835,11 @@ setMethod(
signature=signature(object="pomp"),
definition=function (
object,
...,
x0 = rinit(object),
t0 = timezero(object),
times = time(object),
params = coef(object),
...
params = coef(object)
) {
tryCatch(
rprocess_internal(object=object,x0=x0,t0=t0,times=times,params=params,...),
Expand All @@ -808,8 +848,11 @@ setMethod(
}
)

rprocess_internal <- function (object, x0, t0, times, params, ...,
.gnsi = TRUE) {
rprocess_internal <- function (
object,
x0, t0, times, params,
.gnsi = TRUE
) {
storage.mode(x0) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down Expand Up @@ -869,18 +912,22 @@ setMethod(
signature=signature("pomp"),
definition=function (
object,
...,
x = states(object),
times = time(object),
params = coef(object),
...
params = coef(object)
)
tryCatch(
skeleton_internal(object=object,x=x,times=times,params=params,...),
error = function (e) pStop(who="skeleton",conditionMessage(e))
)
)

skeleton_internal <- function (object, x, times, params, .gnsi = TRUE, ...) {
skeleton_internal <- function (
object,
x, times, params,
.gnsi = TRUE
) {
storage.mode(x) <- "double"
storage.mode(params) <- "double"
pompLoad(object)
Expand Down
2 changes: 1 addition & 1 deletion inst/include/pomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void eeulermultinom
{
double lambda = 0.0;
int j, k;
if ( !R_FINITE(size) || size < 0.0 || !R_FINITE(dt) || dt < 0.0) {
if (!R_FINITE(size) || size < 0.0 || !R_FINITE(dt) || dt < 0.0) {
for (k = 0; k < m; k++) trans[k] = R_NaReal;
warn("in 'eeulermultinom': NAs produced.");
return;
Expand Down
Loading

0 comments on commit 87446e5

Please sign in to comment.