Skip to content

Commit

Permalink
Merge pull request #27 from bips-hb/stepsize
Browse files Browse the repository at this point in the history
Allow stepsize in forge and expct if not running in parallel
  • Loading branch information
mnwright authored May 28, 2024
2 parents 4d9c6b0 + e7b879b commit b8e66dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
28 changes: 15 additions & 13 deletions R/expct.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,29 @@ expct <- function(
step_no <- 1
} else {
evidence <- as.data.table(evidence)
if (ncol(evidence) == 2 && all(colnames(evidence) == c("f_idx", "wt"))) {
stepsize <- nrow(evidence)
step_no <- 1
} else if (parallel & evidence_row_mode == "separate") {
# For "separate", parallelize in forge (not in cforde)
if (stepsize == 0) {
if (stepsize == 0) {
if (parallel) {
stepsize <- ceiling(nrow(evidence)/foreach::getDoParWorkers())
} else {
stepsize <- nrow(evidence)
}
} else if (stepsize > nrow(evidence)) {
stepsize <- nrow(evidence)
}
if (ncol(evidence) == 2 && all(colnames(evidence) == c("f_idx", "wt"))) {
stepsize <- nrow(evidence)
} else if (evidence_row_mode == "separate") {
# For "separate", parallelize in expct (not in cforde)
stepsize_cforde <- 0
parallel_cforde = FALSE
step_no <- ceiling(nrow(evidence)/stepsize)
} else {
# For "or", parallelize in cforde (not in forge)
if (stepsize == 0) {
stepsize <- nrow(evidence)
}
stepsize_cforde <- stepsize
# For "or", parallelize in cforde (not in expct)
parallel_cforde <- parallel
stepsize_cforde <- stepsize
parallel <- FALSE
stepsize <- nrow(evidence)
step_no <- 1
}
step_no <- ceiling(nrow(evidence)/stepsize)
}

# Check query
Expand Down
22 changes: 11 additions & 11 deletions R/forge.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,27 +114,27 @@ forge <- function(
step_no <- 1
} else {
evidence <- as.data.table(evidence)
if (stepsize == 0) {
if (parallel) {
stepsize <- ceiling(nrow(evidence)/foreach::getDoParWorkers())
} else {
stepsize <- nrow(evidence)
}
}
if (ncol(evidence) == 2 && all(colnames(evidence) == c("f_idx", "wt"))) {
stepsize <- nrow(evidence)
step_no <- 1
} else if (parallel & evidence_row_mode == "separate") {
} else if (evidence_row_mode == "separate") {
# For "separate", parallelize in forge (not in cforde)
if (stepsize == 0) {
stepsize <- ceiling(nrow(evidence)/foreach::getDoParWorkers())
}
stepsize_cforde <- 0
parallel_cforde = FALSE
step_no <- ceiling(nrow(evidence)/stepsize)
} else {
# For "or", parallelize in cforde (not in forge)
if (stepsize == 0) {
stepsize <- nrow(evidence)
}
stepsize_cforde <- stepsize
parallel_cforde <- parallel
stepsize_cforde <- stepsize
parallel <- FALSE
stepsize <- nrow(evidence)
step_no <- 1
}
step_no <- ceiling(nrow(evidence)/stepsize)
}

# Run in parallel for each step
Expand Down

0 comments on commit b8e66dc

Please sign in to comment.