Skip to content

Commit

Permalink
Add context manager
Browse files Browse the repository at this point in the history
Context manager is added to code to prevent design() from exiting due to division warning that should be ignored.
  • Loading branch information
mingdeyu committed Nov 25, 2023
1 parent 22d4fc4 commit b87bd0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions R/update.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ update.dgp <- function(object, X, Y, refit = FALSE, reset = FALSE, verb = TRUE,
}
N0 <- constructor_obj_cp$N
if ( identical(cores,as.integer(1)) ){
constructor_obj_cp$train(N, ess_burn, disable)
with(pkg.env$np$errstate(divide = 'ignore'), constructor_obj_cp$train(N, ess_burn, disable))
} else {
constructor_obj_cp$ptrain(N, ess_burn, disable, cores)
with(pkg.env$np$errstate(divide = 'ignore'), constructor_obj_cp$ptrain(N, ess_burn, disable, cores))
}
burnin <- as.integer(N0 + 0.75*N)
} else {
Expand Down Expand Up @@ -185,7 +185,7 @@ update.gp <- function(object, X, Y, refit = FALSE, reset = FALSE, verb = TRUE, .

if ( refit ){
if ( verb ) message("Re-fitting ...", appendLF = FALSE)
constructor_obj_cp$train()
with(pkg.env$np$errstate(divide = 'ignore'), constructor_obj_cp$train())
if ( verb ) message(" done")
}

Expand Down
12 changes: 6 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ crop <- function(object, crop_id_list, refit_cores, verb) {
struc$para_path <- matrix(c(struc$scale, struc$length, struc$nugget), nrow = 1, byrow=T)
}
obj <- pkg.env$dgpsi$gp(X, Y, struc)
obj$train()
with(pkg.env$np$errstate(divide = 'ignore'), obj$train())
res <- list()
res[['id']] <- object$id
res[['data']][['X']] <- X
Expand Down Expand Up @@ -979,7 +979,7 @@ crop <- function(object, crop_id_list, refit_cores, verb) {
struc$para_path <- matrix(c(struc$scale, struc$length, struc$nugget), nrow = 1, byrow = T)
}
obj <- pkg.env$dgpsi$gp(X, Y[,j,drop=F], struc)
obj$train()
with(pkg.env$np$errstate(divide = 'ignore'), obj$train())
res_j <- list()
res_j[['id']] <- uuid::UUIDgenerate()
res_j[['data']][['X']] <- X
Expand Down Expand Up @@ -1020,9 +1020,9 @@ crop <- function(object, crop_id_list, refit_cores, verb) {
object$constructor_obj$update_all_layer(all_layer)
if ( verb ) message(" - Re-fitting ...", appendLF = FALSE)
if ( identical(refit_cores, as.integer(1)) ){
object$constructor_obj$train(as.integer(100), as.integer(10), TRUE)
with(pkg.env$np$errstate(divide = 'ignore'), object$constructor_obj$train(as.integer(100), as.integer(10), TRUE))
} else {
object$constructor_obj$ptrain(as.integer(100), as.integer(10), TRUE, refit_cores)
with(pkg.env$np$errstate(divide = 'ignore'), object$constructor_obj$ptrain(as.integer(100), as.integer(10), TRUE, refit_cores))
}
est_obj <- object$constructor_obj$estimate()
internal_dims <- object[['specs']][['internal_dims']]
Expand Down Expand Up @@ -1058,9 +1058,9 @@ crop <- function(object, crop_id_list, refit_cores, verb) {
object$constructor_obj$update_all_layer(all_layer)
if ( verb ) message(" - Re-fitting ...", appendLF = FALSE)
if ( identical(refit_cores, as.integer(1)) ){
object$constructor_obj$train(as.integer(100), as.integer(10), TRUE)
with(pkg.env$np$errstate(divide = 'ignore'), object$constructor_obj$train(as.integer(100), as.integer(10), TRUE))
} else {
object$constructor_obj$ptrain(as.integer(100), as.integer(10), TRUE, refit_cores)
with(pkg.env$np$errstate(divide = 'ignore'), object$constructor_obj$ptrain(as.integer(100), as.integer(10), TRUE, refit_cores))
}
est_obj <- object$constructor_obj$estimate()
internal_dims <- object[['specs']][['internal_dims']]
Expand Down

0 comments on commit b87bd0f

Please sign in to comment.