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

Closes #294 #295

Merged
merged 3 commits into from
Oct 17, 2023
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 DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: distr6
Title: The Complete R6 Probability Distributions Interface
Version: 1.8.2
Version: 1.8.3
Authors@R:
c(person(given = "Raphael",
family = "Sonabend",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# distr6 1.8.3

* Add `decorators` argument to `c.Matdist` and `c.Arrdist`

# distr6 1.8.1

* Add 'transformer' functions `pdfcdf` and `cdfpdf`, which use Rcpp to transform matrics/arrays/vectors between pdf->cdf and cdf->pdf respectively.
Expand Down
11 changes: 8 additions & 3 deletions R/SDistribution_Arrdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ Arrdist <- R6Class("Arrdist",
#' @title Combine Array Distributions into a Arrdist
#' @description Helper function for quickly combining distributions into a [Arrdist].
#' @param ... array distributions to be concatenated.
#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions.
#' @return [Arrdist]
#' @examples
#' # create three array distributions with different column names
Expand All @@ -383,13 +384,17 @@ Arrdist <- R6Class("Arrdist",
#' })
#' do.call(c, arr)
#' @export
c.Arrdist <- function(...) {
c.Arrdist <- function(..., decorators = NULL) {
# get the pdfs and decorators
pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)),
recursive = FALSE
)
pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)]
decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))


if (is.null(decorators)) {
decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
}

nt <- unique(vapply(pdfs, function(.x) dim(.x)[3L], integer(1)))
if (length(nt) > 1) {
Expand All @@ -399,7 +404,7 @@ c.Arrdist <- function(...) {
pdfs <- .merge_arrpdf_cols(pdfs)
pdfs <- do.call(abind::abind, list(what = pdfs, along = 1))

as.Distribution(pdfs, fun = "pdf", decorators = decs)
as.Distribution(pdfs, fun = "pdf", decorators = decorators)
}

#' @title Extract one or more Distributions from an Array distribution
Expand Down
11 changes: 8 additions & 3 deletions R/SDistribution_Matdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ Matdist <- R6Class("Matdist",
#' @title Combine Matrix Distributions into a Matdist
#' @description Helper function for quickly combining distributions into a [Matdist].
#' @param ... matrix distributions to be concatenated.
#' @param decorators If supplied then adds given decorators, otherwise pulls them from underlying distributions.
#' @return [Matdist]
#' @examples
#' # create three matrix distributions with different column names
Expand All @@ -346,16 +347,20 @@ Matdist <- R6Class("Matdist",
#' })
#' do.call(c, mats)
#' @export
c.Matdist <- function(...) {
c.Matdist <- function(..., decorators = NULL) {
# get the pdfs and decorators
pdfdec <- unlist(lapply(list(...), function(x) list(gprm(x, "pdf"), x$decorators)),
recursive = FALSE
)
pdfs <- pdfdec[seq.int(1, length(pdfdec), by = 2)]
decs <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))

if (is.null(decorators)) {
decorators <- unique(unlist(pdfdec[seq.int(2, length(pdfdec), by = 2)]))
}


as.Distribution(do.call(rbind, .merge_matpdf_cols(pdfs)), fun = "pdf",
decorators = decs)
decorators = decorators)
}

#' @title Extract one or more Distributions from a Matdist
Expand Down
4 changes: 3 additions & 1 deletion man/c.Arrdist.Rd

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

4 changes: 3 additions & 1 deletion man/c.Matdist.Rd

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

1 change: 1 addition & 0 deletions man/distr6-package.Rd

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

Loading