Skip to content

Commit

Permalink
Merge pull request #278 from mrc-ide/odin-mrc-3745
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz authored Oct 31, 2022
2 parents 76a6a83 + c41cfb8 commit 38f841d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: odin
Title: ODE Generation and Integration
Version: 1.4.1
Version: 1.4.2
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Thibaut", "Jombart", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion inst/js/dust.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/js/odin.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion inst/js/test-discrete.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function call_odin_bundle(Model, pars, tStart, tEnd, dt, nParticles) {
return dust.wodinRunDiscrete(Model, pars, tStart, tEnd, dt, nParticles)
const solution = dust.wodinRunDiscrete(Model, pars, tStart, tEnd, dt, nParticles);
return solution({mode: "grid", tStart, tEnd, nPoints: Infinity});
}
9 changes: 6 additions & 3 deletions tests/testthat/helper-js.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ call_odin_bundle_continuous <- function(bundle, user, t0, t1, tn,
} else {
control_js <- V8::JS(jsonlite::toJSON(control, auto_unbox = TRUE))
}
res <- ct$call("call_odin_bundle", odin_js, user_js, t0, t1, tn, control_js)
res$y <- t(res$y)
res

ct$call("call_odin_bundle", odin_js, user_js, t0, t1, tn, control_js)
}


Expand Down Expand Up @@ -74,3 +73,7 @@ skip_if_no_js <- function() {
## behaves poorly.
skip_on_cran()
}

list_to_matrix <- function(x) {
matrix(unlist(x), ncol = length(x))
}
22 changes: 12 additions & 10 deletions tests/testthat/test-js-bundle.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ test_that("bundle works", {
sol <- with(list(K = 100, r = 0.5, y0 = 1),
K / (1 + (K / y0 - 1) * exp(-r * t)))

expect_equal(res$names, "N")
expect_equal(res$x, t)
expect_equal(drop(res$y), sol, tolerance = 1e-6)
expect_equal(res$values$name, "N")
expect_equal(res$values$y[[1]], sol, tolerance = 1e-6)
})


Expand Down Expand Up @@ -52,9 +52,9 @@ test_that("include interpolate", {

tt <- seq(t0, t1, length.out = tn)

expect_equal(res$names, c("y", "p"))
expect_equal(res$values$name, c("y", "p"))
zz <- ifelse(tt < 1, 0, ifelse(tt > 2, 1, tt - 1))
expect_equal(res$y[, 1], zz, tolerance = 2e-5)
expect_equal(res$values$y[[1]], zz, tolerance = 2e-5)
})


Expand All @@ -78,12 +78,12 @@ test_that("include sum", {

res <- call_odin_bundle_continuous(bundle, NULL, t0, t1, tn)
expect_equal(
res$names,
res$values$name,
c("y[1]", "y[2]", "y[3]", "ytot", "y2[1]", "y2[2]", "y2[3]"))

y <- res$y[, 1:3]
ytot <- res$y[, 4]
y2 <- res$y[, 5:7]
y <- list_to_matrix(res$values$y[1:3])
ytot <- res$values$y[[4]]
y2 <- list_to_matrix(res$values$y[5:7])

expect_equal(ytot, rowSums(y))
expect_equal(y2, y * 2)
Expand Down Expand Up @@ -127,8 +127,10 @@ test_that("include fancy sum", {
tt <- seq(t0, t1, length.out = tn)
cmp <- odin::odin_(code, target = "r")$new(user = user)$run(tt)

expect_equal(res$names, c("y[1]", "y[2]", "y[3]", "y[4]"))
expect_equal(res$y, unname(cmp[, -1]), tolerance = 1e-5)
expect_equal(res$values$name, c("y[1]", "y[2]", "y[3]", "y[4]"))

expect_equal(list_to_matrix(res$values$y),
unname(cmp[, -1]), tolerance = 1e-5)
})


Expand Down

0 comments on commit 38f841d

Please sign in to comment.