It is true that this function is exported and could be used anywhere, but I think _constr implies that this is for advanced usage only.
The rewritten version of the constructor just switches out tibble(...) for new_tibble(list(...)):
parameters_constr2 <-
function(name, id, source, component, component_id, object) {
dials:::chr_check(name)
dials:::chr_check(id)
dials:::chr_check(source)
dials:::chr_check(component)
dials:::chr_check(component_id)
dials:::unique_check(id)
if (is.null(object)) {
rlang::abort("Element `object` should not be NULL.")
}
if (!is.list(object)) {
rlang::abort("`object` should be a list.")
}
is_good_boi <- map_lgl(object, dials:::param_or_na)
if (any(!is_good_boi)) {
rlang::abort(
paste0(
"`object` values in the following positions should be NA or a ",
"`param` object:",
paste0(which(!is_good_boi), collapse = ", ")
)
)
}
res <-
tibble::new_tibble(
list(
name = name,
id = id,
source = source,
component = component,
component_id = component_id,
object = object
),
nrow = length(name)
)
class(res) <- c("parameters", class(res))
res
}
Note with check = TRUE in the above, mark() checks equality of the outputs. :) The old constructor is as.numeric(bm2$median[1]) / as.numeric(bm2$median[2]) times slower than the new one:
This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
parameters_constr()
is called twice per resample fit, and twice for every element ofgrid
when tuning hyperparameters.As a percentage of total time, the constructor takes:
parameters_constr()
is only called once in the package, and is used in such a way that we know we won’t need recycling: https://github.com/tidymodels/dials/blob/ec3cd5154bfae1b677c753861ea4330b11330bb9/R/parameters.R#L45-L52It is true that this function is exported and could be used anywhere, but I think
_constr
implies that this is for advanced usage only.The rewritten version of the constructor just switches out
tibble(...)
fornew_tibble(list(...))
:With benchmarks:
Note with
check = TRUE
in the above,mark()
checks equality of the outputs. :) The old constructor isas.numeric(bm2$median[1]) / as.numeric(bm2$median[2])
times slower than the new one:Created on 2023-03-14 with reprex v2.0.2