Skip to content

Commit

Permalink
* R/: Cannot use rep.int(maxBound) because of NULL. Use rep_len wher…
Browse files Browse the repository at this point in the history
…e appropriate.
  • Loading branch information
MLopez-Ibanez committed Dec 10, 2024
1 parent 8aa203e commit 30c8d47
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions R/irace.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ recoverFromFile <- function(filename)
# FIXME: This function is too slow and it shows up in profiles.
numeric.configurations.equal <- function(x, configurations, parameters, threshold, param.names)
{
d <- rep(0.0, nrow(configurations))
d <- numeric(nrow(configurations))
isSimilar <- matrix(TRUE, nrow = nrow(configurations), ncol = length(param.names))
selected <- seq_nrow(configurations)
for (i in seq_along(param.names)) {
Expand Down Expand Up @@ -348,10 +348,10 @@ generateInstances <- function(race_state, scenario, n, update = FALSE)
blockSize <- scenario$blockSize
n_blocks <- length(instances) / blockSize
# Sample instances index in groups (ntimes)
selected_blocks <- unlist(lapply(rep(n_blocks, ntimes), sample.int, replace = FALSE))
selected_blocks <- unlist(lapply(rep.int(n_blocks, ntimes), sample.int, replace = FALSE))
sindex <- c(outer(seq_len(blockSize), (selected_blocks - 1L) * blockSize, "+"))
} else {
sindex <- rep(seq_along(instances), ntimes)
sindex <- rep.int(seq_along(instances), ntimes)
}
# Sample seeds.
race_state$instances_log <- rbind(race_state$instances_log,
Expand Down
4 changes: 2 additions & 2 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ initialiseModel <- function (parameters, configurations)
type <- param[["type"]]
if (type == "c") {
nbValues <- length(param[["domain"]])
value <- rep(1. / nbValues, nbValues)
param <- rep(list(value), nbConfigurations)
value <- rep_len(1. / nbValues, nbValues)
param <- rep_len(list(value), nbConfigurations)
} else {
if (type == "r" || type == "i") {
sd <- init_sd_numeric(param)
Expand Down
14 changes: 7 additions & 7 deletions R/race.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ overall_ranks <- function(x, test)
ninstances <- colSums2(!is.na(x))
uniq.ninstances <- sort(unique(ninstances), decreasing = TRUE)
last.r <- 0L
ranks <- rep(Inf, ncol(x))
ranks <- rep_len(Inf, ncol(x))
# Iterate from the largest to the lowest number of instances.
for (k in uniq.ninstances) {
confs <- which(ninstances == k)
Expand Down Expand Up @@ -580,8 +580,8 @@ elitist_race <- function(race_state, maxExp,
capping <- scenario$capping
n_configurations <- nrow(configurations)
experiment_log <- data.table(instance=integer(0), configuration=integer(0), time=numeric(0), bound=numeric(0))
alive <- rep(TRUE, n_configurations)
is_rejected <- rep(FALSE, n_configurations)
alive <- rep_len(TRUE, n_configurations)
is_rejected <- logical(n_configurations)

## FIXME: Remove argument checking. This must have been done by the caller.
irace.assert(maxExp > 0L)
Expand Down Expand Up @@ -622,7 +622,7 @@ elitist_race <- function(race_state, maxExp,
experiments_used <- 0L
# is_elite[i] : number of instances to be seen in this race on which i has
# been previously evaluated.
is_elite <- rep(0L, n_configurations)
is_elite <- integer(n_configurations)

## FIXME: Probably, instead of this, we should keep elite_safe in the race_state.
if (is.null(elite.data)) {
Expand Down Expand Up @@ -673,7 +673,7 @@ elitist_race <- function(race_state, maxExp,
irace.assert(elitist_new_instances %% blockSize == 0L)
# FIXME: This should go into its own function.
n_elite <- ncol(elite.data)
which_elites <- which(rep(TRUE, n_elite))
which_elites <- which(rep_len(TRUE, n_elite))
irace.note("Preliminary execution of ", n_elite,
" elite configuration(s) over ", elitist_new_instances, " instance(s).\n")
for (k in seq_len(elitist_new_instances)) {
Expand Down Expand Up @@ -868,10 +868,10 @@ elitist_race <- function(race_state, maxExp,


if (nrow(Results) < current_task) {
Results <- rbind(Results, rep(NA_real_, ncol(Results)))
Results <- rbind(Results, rep_len(NA_real_, ncol(Results)))
rownames(Results) <- race_instances[seq_nrow(Results)]
if (capping) {
experimentsTime <- rbind(experimentsTime, rep(NA_real_, ncol(experimentsTime)))
experimentsTime <- rbind(experimentsTime, rep_len(NA_real_, ncol(experimentsTime)))
rownames(experimentsTime) <- race_instances[seq_nrow(experimentsTime)]
}
}
Expand Down
5 changes: 3 additions & 2 deletions R/testing.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ testConfigurations <- function(configurations, scenario)

# Create experiment list
experiments <- createExperimentList(configurations, parameters = scenario$parameters,
instances = testInstances, instances_ID = instances_id, seeds = instanceSeed,
bounds = rep.int(scenario$boundMax, nrow(configurations)))
instances = testInstances, instances_ID = instances_id, seeds = instanceSeed,
# We cannot use rep.int because scenario$boundMax may be NULL.
bounds = rep(scenario$boundMax, nrow(configurations)))
race_state <- RaceState$new(scenario)
if (scenario$debugLevel >= 3L) {
irace.note ("Memory used before execute_experiments() in testConfigurations():\n")
Expand Down

0 comments on commit 30c8d47

Please sign in to comment.