Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
docs, fixes in variable exponent
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Sonabend committed Jul 17, 2020
1 parent ca81189 commit 18bfac4
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 117 deletions.
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2020-07-17.
Once it is accepted, delete this file and tag the release (commit 502c918e89).
51 changes: 25 additions & 26 deletions R/SetWrapper_ExponentSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
ExponentSet <- R6Class("ExponentSet",
inherit = ProductSet,
public = list(
#' @description Create a new `ExponentSet` object. It is not recommended to construct this class directly.
#' @description Create a new `ExponentSet` object. It is not recommended to construct this
#' class directly.
#' @param set [Set] to wrap.
#' @param power numeric. Power to raise Set to.
#' @return A new `ExponentSet` object.
Expand Down Expand Up @@ -53,38 +54,36 @@ ExponentSet <- R6Class("ExponentSet",
#' @description Tests if elements `x` are contained in `self`.
#' @template param_xall
#' @param bound logical
#' @return If `all == TRUE` then returns `TRUE` if all `x` are contained in `self`, otherwise `FALSE`.
#' If `all == FALSE` returns a vector of logicals corresponding to the length of `x`, representing
#' if each is contained in `self`. If `bound == TRUE` then an element is contained in `self` if it
#' is on or within the (possibly-open) bounds of `self`, otherwise `TRUE` only if the element is within
#' `self` or the bounds are closed.
#' @return If `all == TRUE` then returns `TRUE` if all `x` are contained in `self`,
#' otherwise `FALSE`. If `all == FALSE` returns a vector of logicals corresponding to the
#' length of `x`, representing if each is contained in `self`. If `bound == TRUE` then an
#' element is contained in `self` if it is on or within the (possibly-open) bounds of `self`,
#' otherwise `TRUE` only if the element is within `self` or the bounds are closed.
contains = function(x, all = FALSE, bound = FALSE) {

if (self$power == "n") {
if (!testTuple(x)) {
stop("Variable exponent set can only perform containedness checks on a single tuple.")
} else {
if (x$length == 1) {
return(self$wrappedSets[[1]]$contains(x$elements[[1]], all, bound))
} else {
return(setpower(self$wrappedSets[[1]], x$length)$contains(x, all, bound))
}
}
}

x <- listify(x)

ret <- sapply(x, function(el) {
if (!testSet(el)) {
el <- as.Set(el)
if (self$power == "n") {
len <- x[[1]]$length
if (len == 1) {
return(self$wrappedSets[[1]]$contains(unlist(rsapply(x, "elements", active = TRUE)),
all, bound))
} else {
return(setpower(self$wrappedSets[[1]], len)$contains(x, all, bound))
}
} else {
ret <- sapply(x, function(el) {
if (!testSet(el)) {
el <- as.Set(el)
}

if (el$length != self$power) {
return(FALSE)
}
if (el$length != self$power) {
return(FALSE)
}

all(self$wrappedSets[[1]]$contains(el$elements, bound = bound))
})
all(self$wrappedSets[[1]]$contains(el$elements, bound = bound))
})
}

returner(ret, all)
}
Expand Down
5 changes: 5 additions & 0 deletions R/operation_cleaner.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ operation_cleaner <- function(sets, operation_class, nest, simplify = TRUE) {
} else if (is.null(wraps)) {
return(x)
} else {
if (inherits(x, "ExponentSet")) {
if (x$power == "n") {
return(x)
}
}
return(wraps)
}
}))
Expand Down
15 changes: 10 additions & 5 deletions R/operation_setpower.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@
#' x$contains(Tuple$new(0))
#' x$contains(Tuple$new(0, 1))
#' x$contains(Tuple$new(0, 1, 0, 0, 1, 1, 0))
#' x$contains(Tuple$new(0, 2))
#' x$contains(list(Tuple$new(0, 2), Tuple$new(1, 1)))
#'
#' @export
setpower <- function(x, power, simplify = FALSE, nest = FALSE) {
if (getR6Class(x) == "UniversalSet") {
classx <- getR6Class(x)
if (classx == "UniversalSet") {
return(x)
}

Expand All @@ -55,11 +56,15 @@ setpower <- function(x, power, simplify = FALSE, nest = FALSE) {
return(x)
} else if (power == "n") {
return(ExponentSet$new(x, power))
} else if (getR6Class(x) %in% c("Set", "FuzzySet", "Tuple", "FuzzyTuple") & simplify) {
} else if (classx %in% c("Set", "FuzzySet", "Tuple", "FuzzyTuple") & simplify) {
x <- rep(list(x), power)
return(do.call(setproduct, c(x, list(nest = nest, simplify = TRUE))))
} else if (inherits(x, "ExponentSet")) {
return(ExponentSet$new(x$wrappedSets[[1]], x$power * power))
} else if (classx == "ExponentSet") {
if (x$power == "n") {
return(x)
} else {
return(ExponentSet$new(x$wrappedSets[[1]], x$power * power))
}
} else {
return(ExponentSet$new(x, power))
}
Expand Down
6 changes: 6 additions & 0 deletions R/operation_setproduct.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ setproduct <- function(..., simplify = FALSE, nest = FALSE) {
}

classes <- sapply(sets, getR6Class)
if ("ExponentSet" %in% classes) {
varexp <- sapply(sets[classes == "ExponentSet"], function(x) x$power == "n")
if (any(varexp)) {
return(sets[classes == "ExponentSet"][which(varexp)[1]][[1]])
}
}

if (length(unique(rsapply(sets, "strprint"))) == 1 & !simplify) {
return(ExponentSet$new(sets[[1]], length(sets)))
Expand Down
3 changes: 1 addition & 2 deletions man/ConditionalSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions man/ExponentSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/FuzzySet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/FuzzyTuple.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/Interval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/LogicalSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/Set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/Tuple.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/UniversalSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions man/as.FuzzySet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions man/as.Interval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/as.Set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/listSpecialSets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/powerSet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18bfac4

Please sign in to comment.