Skip to content

Commit

Permalink
Explicitly initialize order to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Sep 20, 2024
1 parent 096e100 commit 790a149
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 102 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: 3 additions & 0 deletions src/genModelVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-000-modelVars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
202 changes: 100 additions & 102 deletions tests/testthat/test-phi.R
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 790a149

Please sign in to comment.