From cc8251ed0cdc440c37c2ce0c194baef4fc062d24 Mon Sep 17 00:00:00 2001 From: mb706 Date: Sun, 12 May 2024 19:35:29 +0200 Subject: [PATCH] stash --- DESCRIPTION | 2 +- attic/ParamS6.R | 14 ++++++++++++-- attic/S6ObjectCache.R | 1 + man/Sampler.Rd | 2 +- man/Sampler1D.Rd | 4 ++-- man/Sampler1DCateg.Rd | 6 +++--- man/Sampler1DNormal.Rd | 6 +++--- man/Sampler1DRfun.Rd | 6 +++--- man/Sampler1DUnif.Rd | 6 +++--- man/SamplerHierarchical.Rd | 6 +++--- man/SamplerJointIndep.Rd | 6 +++--- man/SamplerUnif.Rd | 6 +++--- tests/testthat/helper_01_params.R | 17 +++++++++-------- tests/testthat/test_Param.R | 4 +++- 14 files changed, 50 insertions(+), 36 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6c79cb3a..621fe625 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -61,7 +61,7 @@ Config/testthat/edition: 3 Config/testthat/parallel: false NeedsCompilation: no Roxygen: list(markdown = TRUE, r6 = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 VignetteBuilder: knitr Collate: 'Condition.R' diff --git a/attic/ParamS6.R b/attic/ParamS6.R index f37bd866..6ec5ef3e 100644 --- a/attic/ParamS6.R +++ b/attic/ParamS6.R @@ -15,14 +15,15 @@ p_s6 = function(support, special_vals = list(), default = NO_DEF, tags = charact cargo = set, lower = suppressWarnings(as.numeric(set$lower)), upper = suppressWarnings(as.numeric(set$upper)), - levels = as.list(set$elements), + levels = if (is.numeric(set$properties$cardinality)) as.list(set$elements), special_vals = special_vals, default = default, tags = tags, trafo = trafo, storage_type = storage_type, depends_expr = substitute(depends), - init = init) + init = init + ) } #' @export @@ -61,6 +62,7 @@ domain_qunif.ParamSet6 = function(param, x) stop("undefined") domain_is_number.ParamSet6 = function(param) { param$storage_type[[1]] != "list" } + #' @export domain_is_categ.ParamSet6 = function(param) { set = set6_cache_get(param$grouping[[1]]) @@ -69,3 +71,11 @@ domain_is_categ.ParamSet6 = function(param) { categness } + +set6_unique_repr = function(object) { + assert_r6(object, "Set") + using_unicode_for_whatever_reason = set6::useUnicode() + on.exit(set6::useUnicode(using_unicode_for_whatever_reason)) + set6::useUnicode(FALSE) + object$strprint(n = 1e10) +} diff --git a/attic/S6ObjectCache.R b/attic/S6ObjectCache.R index 618ddebd..c95fcafb 100644 --- a/attic/S6ObjectCache.R +++ b/attic/S6ObjectCache.R @@ -1,4 +1,5 @@ + S6Cache = R6Class("S6Cache", cloneable = FALSE, public = list( diff --git a/man/Sampler.Rd b/man/Sampler.Rd index f66fc8d4..178c7a07 100644 --- a/man/Sampler.Rd +++ b/man/Sampler.Rd @@ -8,11 +8,11 @@ This is the abstract base class for sampling objects like \link{Sampler1D}, \lin } \seealso{ Other Sampler: +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, \code{\link{SamplerUnif}} diff --git a/man/Sampler1D.Rd b/man/Sampler1D.Rd index b2e6a4d2..f1acc2bd 100644 --- a/man/Sampler1D.Rd +++ b/man/Sampler1D.Rd @@ -9,14 +9,14 @@ } \seealso{ Other Sampler: +\code{\link{Sampler}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super class}{ diff --git a/man/Sampler1DCateg.Rd b/man/Sampler1DCateg.Rd index 8ebbf668..979ff08b 100644 --- a/man/Sampler1DCateg.Rd +++ b/man/Sampler1DCateg.Rd @@ -8,14 +8,14 @@ Sampling from a discrete distribution, for a \code{\link{ParamSet}} containing a } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super classes}{ diff --git a/man/Sampler1DNormal.Rd b/man/Sampler1DNormal.Rd index c043e228..cc5e2d1e 100644 --- a/man/Sampler1DNormal.Rd +++ b/man/Sampler1DNormal.Rd @@ -8,14 +8,14 @@ Normal sampling (potentially truncated) for \code{\link[=p_dbl]{p_dbl()}}. } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super classes}{ diff --git a/man/Sampler1DRfun.Rd b/man/Sampler1DRfun.Rd index dd479245..c2d65417 100644 --- a/man/Sampler1DRfun.Rd +++ b/man/Sampler1DRfun.Rd @@ -8,14 +8,14 @@ Arbitrary sampling from 1D RNG functions from R. } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super classes}{ diff --git a/man/Sampler1DUnif.Rd b/man/Sampler1DUnif.Rd index 0254bf28..5bb3b6c1 100644 --- a/man/Sampler1DUnif.Rd +++ b/man/Sampler1DUnif.Rd @@ -8,14 +8,14 @@ Uniform random sampler for arbitrary (bounded) parameters. } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super classes}{ diff --git a/man/SamplerHierarchical.Rd b/man/SamplerHierarchical.Rd index e0b6f9fd..9973825c 100644 --- a/man/SamplerHierarchical.Rd +++ b/man/SamplerHierarchical.Rd @@ -10,14 +10,14 @@ and if dependencies do not hold, values are set to \code{NA} in the resulting \c } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerJointIndep}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super class}{ diff --git a/man/SamplerJointIndep.Rd b/man/SamplerJointIndep.Rd index ee4a3349..b05a487f 100644 --- a/man/SamplerJointIndep.Rd +++ b/man/SamplerJointIndep.Rd @@ -8,14 +8,14 @@ Create joint, independent sampler out of multiple other samplers. } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, -\code{\link{SamplerUnif}}, -\code{\link{Sampler}} +\code{\link{SamplerUnif}} } \concept{Sampler} \section{Super class}{ diff --git a/man/SamplerUnif.Rd b/man/SamplerUnif.Rd index 77a038b3..df6283d6 100644 --- a/man/SamplerUnif.Rd +++ b/man/SamplerUnif.Rd @@ -10,14 +10,14 @@ Hence, also works for \link{ParamSet}s sets with dependencies. } \seealso{ Other Sampler: +\code{\link{Sampler}}, +\code{\link{Sampler1D}}, \code{\link{Sampler1DCateg}}, \code{\link{Sampler1DNormal}}, \code{\link{Sampler1DRfun}}, \code{\link{Sampler1DUnif}}, -\code{\link{Sampler1D}}, \code{\link{SamplerHierarchical}}, -\code{\link{SamplerJointIndep}}, -\code{\link{Sampler}} +\code{\link{SamplerJointIndep}} } \concept{Sampler} \section{Super classes}{ diff --git a/tests/testthat/helper_01_params.R b/tests/testthat/helper_01_params.R index 9ebae7f4..e0de0e20 100644 --- a/tests/testthat/helper_01_params.R +++ b/tests/testthat/helper_01_params.R @@ -2,11 +2,12 @@ # use th_ to indicate a test helper object # Param -th_param_int = function() ParamInt$new(id = "th_param_int", default = 0, lower = -10, upper = 10) -th_param_nat = function() ParamInt$new(id = "th_param_nat", default = 1L, lower = 1L, upper = 4L) -th_param_dbl = function() ParamDbl$new(id = "th_param_dbl", default = 0, lower = -10, upper = 10) -th_param_dbl_na = function() ParamDbl$new(id = "th_param_dbl_na", default = 0, - lower = -10, upper = 10, special_vals = list(NA)) -th_param_fct = function() ParamFct$new(id = "th_param_fct", default = "a", levels = letters[1:3]) -th_param_lgl = function() ParamLgl$new(id = "th_param_lgl", default = FALSE) -th_param_uty = function() ParamUty$new(id = "th_param_uty") +th_param_int = function() ps(th_param_int = p_int(default = 0, lower = -10, upper = 10)) +th_param_nat = function() ps(th_param_nat = p_int(default = 1L, lower = 1L, upper = 4L)) +th_param_dbl = function() ps(th_param_dbl = p_dbl(default = 0, lower = -10, upper = 10)) +th_param_dbl_na = function() ps(th_param_dbl_na = p_dbl(default = 0, lower = -10, upper = 10, special_vals = list(NA))) +th_param_fct = function() ps(th_param_fct = p_fct(default = "a", levels = letters[1:3])) +th_param_lgl = function() ps(th_param_lgl = p_lgl(default = FALSE)) +th_param_uty = function() ps(th_param_uty = p_uty()) + + diff --git a/tests/testthat/test_Param.R b/tests/testthat/test_Param.R index 68bcf90d..75cde4b3 100644 --- a/tests/testthat/test_Param.R +++ b/tests/testthat/test_Param.R @@ -1,4 +1,6 @@ -context("Param") + + + test_that("basic properties", {