Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: set use.names to false in unlist where applicable #409

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/Design.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Design = R6Class("Design",
# we need to make sure that every param has a (maybe empty) row in the graph table
fillin = data.table(id = ps$ids(), parents = list(character(0L)))
graph = rbind(graph, fillin[fillin$id %nin% graph$id, ])
graph = graph[, list("parents" = list(unlist(get("parents")))), by = "id"]
graph = graph[, list("parents" = list(unlist(get("parents"), use.names = FALSE))), by = "id"]
topo = topo_sort(graph)
pids_sorted = topo$id
storage_types = ps$storage_type
Expand Down
2 changes: 1 addition & 1 deletion R/Domain_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ check_domain_vectorize = function(ids, values, checker, more_args = list()) {
if (isTRUE(ch)) NULL else sprintf("%s: %s", id, ch)
})
}
errors = unlist(errors)
errors = unlist(errors, use.names = FALSE)
if (!length(errors)) return(TRUE)
str_collapse(errors, sep = "\n")
}
8 changes: 4 additions & 4 deletions R/ParamSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ParamSet = R6Class("ParamSet",
# fastest way to init a data.table
private$.tags = structure(list(
id = rep(paramtbl$id, lengths(paramtbl$.tags)),
tag = unlist(paramtbl$.tags)
tag = unlist(paramtbl$.tags, use.names = FALSE)
), class = c("data.table", "data.frame")
)
} else {
Expand Down Expand Up @@ -542,7 +542,7 @@ ParamSet = R6Class("ParamSet",
}
msg
})
errors = unlist(errors)
errors = unlist(errors, use.names = FALSE)
if (!length(errors)) return(TRUE)
str_collapse(errors, sep = "\n")
},
Expand Down Expand Up @@ -816,7 +816,7 @@ ParamSet = R6Class("ParamSet",
deps = self$deps
if (nrow(deps)) { # add a nice extra charvec-col to the tab, which lists all parents-ids
on = NULL
dd = deps[, list(parents = list(unlist(on))), by = "id"]
dd = deps[, list(parents = list(unlist(on, use.names = FALSE))), by = "id"]
d = merge(d, dd, by = "id", all.x = TRUE)
}
v = named_list(d$id) # add values to last col of print-dt as list col
Expand Down Expand Up @@ -863,7 +863,7 @@ ParamSet = R6Class("ParamSet",
assert_list(v, any.missing = FALSE, types = "character")
if (length(v)) assert_names(names(v), permutation.of = private$.params$id)
# as.character() to handle empty lists and resulting NULL-valures.
private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v)), key = "id")
private$.tags = data.table(id = rep(as.character(names(v)), map_int(v, length)), tag = as.character(unlist(v, use.names = FALSE)), key = "id")
setindexv(private$.tags, "tag")
# return value with original ordering
return(v)
Expand Down
2 changes: 1 addition & 1 deletion R/ParamSetCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ ParamSetCollection = R6Class("ParamSetCollection", inherit = ParamSet,
}
if (tag_sets && n != "") paramtbl[, .tags := map(.tags, function(x) c(x, sprintf("set_%s", n)))]
if (tag_params) paramtbl[, .tags := pmap(list(.tags, original_id), function(x, n) c(x, sprintf("param_%s", n)))]
newtags = paramtbl[, .(tag = unique(unlist(.tags))), by = "id"]
newtags = paramtbl[, .(tag = unique(unlist(.tags, use.names = FALSE))), by = "id"]
if (nrow(newtags)) {
private$.tags = setkeyv(rbind(private$.tags, newtags), "id")
}
Expand Down
Loading