Skip to content

Commit

Permalink
Merge pull request #295 from xoopR/fix_c_consistency
Browse files Browse the repository at this point in the history
Closes #294
  • Loading branch information
RaphaelS1 authored Oct 17, 2023
2 parents f727044 + e2f2235 commit 255a666
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
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.

0 comments on commit 255a666

Please sign in to comment.