-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use data.table to speed up sampleUniform and sampleModel.
* DESCRIPTION: Import data.table * NEWS.md: Document it. * R/configurations.R: New file. * R/generation.R (sampleUniform,sampleModel): Use data.table. * tests/testthat/bug-13-lookup.rds, tests/testthat/test-bug-13.R: Delete because it depends on the previous sampling. * R/irace.R: setDTthreads according to parallel. * tests/testthat/test-repair.R: Improve tests.
- Loading branch information
1 parent
4364898
commit d1e639a
Showing
16 changed files
with
575 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ Imports: | |
utils, | ||
compiler, | ||
fs, | ||
data.table (>= 1.15.0), | ||
matrixStats, | ||
R6, | ||
withr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Returns a data.table | ||
configurations_alloc <- function(colnames, nrow, parameters) | ||
{ | ||
parameter_type <- function(type) { | ||
stopifnot(type %in% c("i","r","o","c")) | ||
switch(type, | ||
i = NA_integer_, | ||
r = NA_real_, | ||
c = NA_character_, | ||
o = NA_character_, | ||
irace.internal.error("Unknown type '", type, "'")) | ||
} | ||
|
||
column_type <- function(x, n, types) | ||
rep(switch(x, | ||
.ID. = NA_integer_, | ||
.PARENT. = NA_integer_, | ||
.WEIGHT. = NA_real_, | ||
parameter_type(types[x])), n) | ||
|
||
x <- sapply(colnames, column_type, n=nrow, types = parameters$types, | ||
simplify=FALSE, USE.NAMES=TRUE) | ||
setDT(x) | ||
x | ||
} | ||
|
||
# FIXME: It may be faster to create a single expression that concatenates all | ||
# the elements of forbidden using '|' | ||
filter_forbidden <- function(configurations, forbidden) | ||
{ | ||
# We have to use a variable name that will never appear in | ||
# configurations, so .FORBIDDEN | ||
for (.FORBIDDEN in forbidden) { | ||
configurations <- configurations[eval(.FORBIDDEN)] | ||
#print(configurations) | ||
#print(str(configurations)) | ||
if (nrow(configurations) == 0L) return(configurations) | ||
} | ||
#print(nrow(configurations)) | ||
configurations | ||
} | ||
|
||
which_satisfied <- function(configurations, condition) | ||
{ | ||
# If there is no condition, do not waste time evaluating it. | ||
if (isTRUE(condition)) | ||
return(seq_len(nrow(configurations))) | ||
r <- eval(condition, configurations) | ||
# Return TRUE if TRUE, FALSE if FALSE or NA | ||
## FIXME: If we byte-compile the condition, then we should incorporate the | ||
## following into the condition directly. | ||
# r & !is.na(r) | ||
# Return indexes where r is TRUE. | ||
which(r) | ||
} | ||
|
Oops, something went wrong.