From 790a149d4190e15acb62fd4ccc00c4c27dbfbfa3 Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Fri, 20 Sep 2024 18:34:08 -0500 Subject: [PATCH 1/4] Explicitly initialize order to 0 --- man/reexports.Rd | 1 + src/genModelVars.h | 3 + tests/testthat/test-000-modelVars.R | 1 + tests/testthat/test-phi.R | 202 ++++++++++++++-------------- 4 files changed, 105 insertions(+), 102 deletions(-) diff --git a/man/reexports.Rd b/man/reexports.Rd index 8cba3d62e..2857ff16d 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -38,3 +38,4 @@ below to see their documentation. \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}} }} +\value{ Inherited from parent routine } diff --git a/src/genModelVars.h b/src/genModelVars.h index e44a90bb8..2395c2634 100644 --- a/src/genModelVars.h +++ b/src/genModelVars.h @@ -227,6 +227,9 @@ static inline int sortStateVectorsErrHandle(int prop, int pass, int i) { static inline SEXP sortStateVectors(SEXP ordS) { int *ord = INTEGER(ordS); + for (int i = 0; i < Rf_length(ordS); i++) { + ord[i] = 0; // explicitly initialize to avoid valgrind warning + } sbt.o = 0; // we can use sbt.o since all the code has already been output sbt.s[0] = 0; for (int i = 0; i < tb.de.n; i++) { diff --git a/tests/testthat/test-000-modelVars.R b/tests/testthat/test-000-modelVars.R index c2fa41864..bdb8e078e 100644 --- a/tests/testthat/test-000-modelVars.R +++ b/tests/testthat/test-000-modelVars.R @@ -20,6 +20,7 @@ d/dt(y3) = a3*y1*y2 et <- eventTable() et$add.sampling(seq(0, 20, by = 0.01)) + out <- solve(rigid, et) expect_equal(rxModelVars(rigid), rxModelVars(rigid$cmpMgr$rxDll())) diff --git a/tests/testthat/test-phi.R b/tests/testthat/test-phi.R index ea40e15c7..ce8c85591 100644 --- a/tests/testthat/test-phi.R +++ b/tests/testthat/test-phi.R @@ -1,106 +1,104 @@ rxTest({ - rxTest({ - test_that("phi/pnorm/qnorm", { - expect_equal(phi(1:3), pnorm(1:3)) - expect_equal(phi(as.double(1:3)), pnorm(as.double(1:3))) - - o <- rxode2({ - o <- phi(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3)) - ) - - o <- rxode2({ - o <- pnorm(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3)) - ) - - o <- rxode2({ - o <- pnorm(a, 0.5) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3), 0.5) - ) - - o <- rxode2({ - o <- pnorm(a, 0.5, 2) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - pnorm(as.double(1:3), 0.5, 2) - ) - - suppressMessages(expect_error(rxode2({ - o <- pnorm() - }))) - - suppressMessages(expect_error(rxode2({ - o <- pnorm(a, b, c, d) - }))) - - o <- rxode2({ - o <- qnorm(a) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3))) - ) - - o <- rxode2({ - o <- qnorm(a, 0.5) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3), 0.5)) - ) - - o <- rxode2({ - o <- qnorm(a, 0.5, 2) - }) - - expect_equal( - rxSolve(o, data.frame(a = 1:3), et(0))$o, - suppressWarnings(qnorm(as.double(1:3), 0.5, 2)) - ) - - suppressMessages(expect_error(rxode2({ - o <- qnorm() - }))) - - suppressMessages(expect_error(rxode2({ - o <- qnorm(a, b, c, d) - }))) - - m <- rxode2({ - o <- pnorm(a) - }) - - skip_if_not_installed("units") - expect_error(rxS(m), NA) - - m <- rxode2({ - o <- pnorm(a, b) - }) - - expect_error(rxS(m), NA) - - m <- rxode2({ - o <- pnorm(a, b, c) - }) - - expect_error(rxS(m), NA) + test_that("phi/pnorm/qnorm", { + expect_equal(phi(1:3), pnorm(1:3)) + expect_equal(phi(as.double(1:3)), pnorm(as.double(1:3))) + + o <- rxode2({ + o <- phi(a) }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3)) + ) + + o <- rxode2({ + o <- pnorm(a) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3)) + ) + + o <- rxode2({ + o <- pnorm(a, 0.5) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3), 0.5) + ) + + o <- rxode2({ + o <- pnorm(a, 0.5, 2) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + pnorm(as.double(1:3), 0.5, 2) + ) + + suppressMessages(expect_error(rxode2({ + o <- pnorm() + }))) + + suppressMessages(expect_error(rxode2({ + o <- pnorm(a, b, c, d) + }))) + + o <- rxode2({ + o <- qnorm(a) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3))) + ) + + o <- rxode2({ + o <- qnorm(a, 0.5) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3), 0.5)) + ) + + o <- rxode2({ + o <- qnorm(a, 0.5, 2) + }) + + expect_equal( + rxSolve(o, data.frame(a = 1:3), et(0))$o, + suppressWarnings(qnorm(as.double(1:3), 0.5, 2)) + ) + + suppressMessages(expect_error(rxode2({ + o <- qnorm() + }))) + + suppressMessages(expect_error(rxode2({ + o <- qnorm(a, b, c, d) + }))) + + m <- rxode2({ + o <- pnorm(a) + }) + + skip_if_not_installed("units") + expect_error(rxS(m), NA) + + m <- rxode2({ + o <- pnorm(a, b) + }) + + expect_error(rxS(m), NA) + + m <- rxode2({ + o <- pnorm(a, b, c) + }) + + expect_error(rxS(m), NA) }) }) From d559ff31ccaac96c343ee8a595922cc20ee4db86 Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Fri, 20 Sep 2024 18:39:20 -0500 Subject: [PATCH 2/4] Version bump --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ cran-comments.md | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b84997409..a66d74618 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: rxode2 -Version: 3.0.0 +Version: 3.0.1 Title: Facilities for Simulating from ODE-Based Models Authors@R: c( person("Matthew L.","Fidler", role = c("aut", "cre"), email = "matthew.fidler@gmail.com", comment=c(ORCID="0000-0001-8538-6691")), diff --git a/NEWS.md b/NEWS.md index 3071a368b..b906176f9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rxode2 3.0.1 + +- explicitly initialize the order vector to stop valgrind warning (requested from CRAN) + # rxode2 3.0.0 ## Breaking Changes diff --git a/cran-comments.md b/cran-comments.md index 45bee1034..cf7878ccc 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,3 @@ -- This works with the new dparser, PreciseSums and lotri to reduce abi linkages -- This rxode2 combines the rxode2parse rxode2random and rxode2et (as - requested by CRAN) +- explicitly initialized C integer vector `ordS` in rxode2 code to + avoid valgrind warning (as requested by CRAN). +- all other warnings come from the `units` package From fcbb9fe1fa4319b066f09e3f8d985fd40c79a355 Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Fri, 20 Sep 2024 19:46:47 -0500 Subject: [PATCH 3/4] Remove vignette code evaluation for syntax vignette --- man/rmdhunks/rxode2-create-models.Rmd | 16 ++++++++-------- vignettes/rxode2-syntax.Rmd | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/man/rmdhunks/rxode2-create-models.Rmd b/man/rmdhunks/rxode2-create-models.Rmd index d71ccf870..17e6c3fdf 100644 --- a/man/rmdhunks/rxode2-create-models.Rmd +++ b/man/rmdhunks/rxode2-create-models.Rmd @@ -1,8 +1,8 @@ -The ODE-based model specification may be coded inside four places: +The ODE-based model specification may be coded inside four places: - Inside a `rxode2({})` block statements: -```{r modBracket} +``` r library(rxode2) mod <- rxode2({ # simple assignment @@ -15,7 +15,7 @@ mod <- rxode2({ - Inside a `rxode2("")` string statement: -```{r modString} +``` r mod <- rxode2(" # simple assignment C2 <- centr/V2 @@ -27,7 +27,7 @@ mod <- rxode2(" - In a file name to be loaded by rxode2: -```{r modFile} +``` r writeLines(" # simple assignment C2 <- centr/V2 @@ -38,10 +38,10 @@ writeLines(" mod <- rxode2(filename='modelFile.rxode2') unlink("modelFile.rxode2") ``` - + - In a model function which can be parsed by `rxode2`: -```{r modFun} +``` r mod <- function() { model({ # simple assignment @@ -94,10 +94,10 @@ For the last type of model (a model function), a call to `rxode2` creates a parsed `rxode2` ui that can be translated to the `rxode2` compilation model. -```{r} +``` r mod$simulationModel -# or +# or mod$simulationIniModel ``` diff --git a/vignettes/rxode2-syntax.Rmd b/vignettes/rxode2-syntax.Rmd index 3583a590f..d356a8394 100644 --- a/vignettes/rxode2-syntax.Rmd +++ b/vignettes/rxode2-syntax.Rmd @@ -17,7 +17,7 @@ knitr::opts_chunk$set( ## Introduction -This briefly describes the syntax used to define models +This briefly describes the syntax used to define models that `rxode2` will translate into R-callable compiled code. It also describes the communication of variables between `R` and the `rxode2` modeling specification. @@ -35,7 +35,7 @@ describes the communication of variables between `R` and the ## Bugs and/or deficiencies -- The modulo operator `%%` is currently unsupported. +- The modulo operator `%%` is currently unsupported. ## Note @@ -49,10 +49,10 @@ Below is a commented example to quickly show the capabilities of ## Example -```{r} +``` r f <- function() { ini({ - + }) model({ # An rxode2 model specification (this line is a comment). @@ -86,18 +86,18 @@ via the `d/dt(identifier)` operator as part of the model specification, and which are model parameters via the `params=` argument in `rxode2` `solve()` method: -``` +``` r m1 <- rxode2(model = ode, modName = "m1") # model parameters -- a named vector is required -theta <- +theta <- c(KA=0.29, CL=18.6, V2=40.2, Q=10.5, V3=297, Kin=1, Kout=1, EC50=200) # state variables and their amounts at time 0 (the use of names is # encouraged, but not required) inits <- c(depot=0, centr=0, peri=0, eff=1) -# qd1 is an eventTable specification with a set of dosing and sampling +# qd1 is an eventTable specification with a set of dosing and sampling # records (code not shown here) solve(theta, event = qd1, inits = inits) From ad80998a48d44a30668b8692bdba1b9274a3538b Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Fri, 20 Sep 2024 19:51:04 -0500 Subject: [PATCH 4/4] Add library(rxode2) to syntax vignette --- vignettes/rxode2-syntax.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/vignettes/rxode2-syntax.Rmd b/vignettes/rxode2-syntax.Rmd index d356a8394..026a6a1f2 100644 --- a/vignettes/rxode2-syntax.Rmd +++ b/vignettes/rxode2-syntax.Rmd @@ -13,6 +13,7 @@ vignette: > knitr::opts_chunk$set( collapse = TRUE, comment = "#>") +library(rxode2) ``` ## Introduction