Skip to content

Commit 20d5f77

Browse files
committed
Updated to version 0.1.8 (Under Development)
1 parent a9aad81 commit 20d5f77

File tree

482 files changed

+31048
-6279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

482 files changed

+31048
-6279
lines changed

.Rhistory

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
setwd("D:/D Desktop/Publications/R package broadcast/broadcast")

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Package: broadcast
22
Title: Broadcasted Array Operations Like 'NumPy'
3-
Version: 0.1.7
3+
Version: 0.1.8
44
Authors@R: person("Tony", "Wilkes", role = c("aut", "cre", "cph"),
55
email = "tony_a_wilkes@outlook.com",
66
comment = c(ORCID = "0000-0001-9498-8379"))
77
Description: Implements efficient 'NumPy'-like broadcasted operations for atomic and recursive arrays.
88
In the context of operations involving 2 (or more) arrays,
9-
“broadcasting” refers to efficiently recycling array dimensions,
9+
“broadcasting” (AKA singleton expansion) refers to efficiently recycling array dimensions,
1010
without making copies.
1111
Besides linking to 'Rcpp',
1212
'broadcast' does not use any external libraries in any way;

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ S3method(cast_dim2flat,default)
2222
S3method(cast_dim2hier,default)
2323
S3method(cast_hier2dim,default)
2424
S3method(cast_shallow2atomic,default)
25+
S3method(checkNA,default)
26+
S3method(checkNULL,default)
2527
S3method(dropnests,default)
2628
S3method(format,broadcaster)
2729
S3method(hier2dim,default)
@@ -60,8 +62,11 @@ export(cast_dim2flat)
6062
export(cast_dim2hier)
6163
export(cast_hier2dim)
6264
export(cast_shallow2atomic)
65+
export(checkNA)
66+
export(checkNULL)
6367
export(cinv)
6468
export(dropnests)
69+
export(ecumprob)
6570
export(hier2dim)
6671
export(hiernames2dimnames)
6772
export(lst.ndim)

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11

2+
# broadcast 0.1.8
3+
4+
* Slightly relaxed the behaviour for `NA`s/`NaN`s for the `+` and `-` operators involving complex numbers.
5+
* Streamlined some internal code here and there.
6+
* Changed the internal code to avoid the false-positive issue message in 'Rchk'.
7+
* Built the package with the recently updated version of 'Rcpp'.
8+
* Added the `checkNULL()` and `checkNA()` methods.
9+
* Added a new linear algebra function for statistics: `ecumprob()`.
10+
11+
<br>
12+
213
# broadcast 0.1.7
314

415
**Consistency fixes:**

R/RcppExports.R

Lines changed: 111 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
.Call(`_broadcast_rcpp_address`, x)
1414
}
1515

16+
#' @keywords internal
17+
NULL
18+
19+
.rcpp_any_nonarray <- function(x) {
20+
.Call(`_broadcast_rcpp_any_nonarray`, x)
21+
}
22+
1623
#' @keywords internal
1724
#' @noRd
1825
.rcpp_bcD_dec_v <- function(x, y, nout, op, prec) {
@@ -532,6 +539,41 @@
532539
#' @keywords internal
533540
NULL
534541

542+
#' @keywords internal
543+
NULL
544+
545+
#' @keywords internal
546+
NULL
547+
548+
#' @keywords internal
549+
NULL
550+
551+
#' @keywords internal
552+
NULL
553+
554+
.rcpp_dimnames_fit <- function(x, dimnames) {
555+
.Call(`_broadcast_rcpp_dimnames_fit`, x, dimnames)
556+
}
557+
558+
.rcpp_make_dimnames2 <- function(xdimnames, ydimnames, outdim, pref) {
559+
.Call(`_broadcast_rcpp_make_dimnames2`, xdimnames, ydimnames, outdim, pref)
560+
}
561+
562+
.rcpp_make_dimnames_between <- function(adimnames, vnames, outdim) {
563+
.Call(`_broadcast_rcpp_make_dimnames_between`, adimnames, vnames, outdim)
564+
}
565+
566+
.rcpp_make_dimnames1 <- function(y_dimnames, ydim, outdim) {
567+
.Call(`_broadcast_rcpp_make_dimnames1`, y_dimnames, ydim, outdim)
568+
}
569+
570+
.rcpp_binames_set <- function(x, y, out) {
571+
invisible(.Call(`_broadcast_rcpp_binames_set`, x, y, out))
572+
}
573+
574+
#' @keywords internal
575+
NULL
576+
535577
#' @keywords internal
536578
#' @noRd
537579
.rcpp_bindhelper_setnames <- function(x, ind, rp) {
@@ -596,6 +638,48 @@ NULL
596638
invisible(.Call(`_broadcast_rcpp_shallow2atomic`, input, output, nrow, ncol, arrangement))
597639
}
598640

641+
#' @keywords internal
642+
#' @noRd
643+
.rcpp_checkmissing_is_raw <- function(y, invert) {
644+
.Call(`_broadcast_rcpp_checkmissing_is_raw`, y, invert)
645+
}
646+
647+
#' @keywords internal
648+
#' @noRd
649+
.rcpp_checkmissing_is_logical <- function(y, invert) {
650+
.Call(`_broadcast_rcpp_checkmissing_is_logical`, y, invert)
651+
}
652+
653+
#' @keywords internal
654+
#' @noRd
655+
.rcpp_checkmissing_count <- function(y, invert) {
656+
.Call(`_broadcast_rcpp_checkmissing_count`, y, invert)
657+
}
658+
659+
#' @keywords internal
660+
#' @noRd
661+
.rcpp_checkmissing_first <- function(y, invert) {
662+
.Call(`_broadcast_rcpp_checkmissing_first`, y, invert)
663+
}
664+
665+
#' @keywords internal
666+
#' @noRd
667+
.rcpp_checkmissing_last <- function(y, invert) {
668+
.Call(`_broadcast_rcpp_checkmissing_last`, y, invert)
669+
}
670+
671+
#' @keywords internal
672+
#' @noRd
673+
.rcpp_checkmissing_which32 <- function(y, invert, size) {
674+
.Call(`_broadcast_rcpp_checkmissing_which32`, y, invert, size)
675+
}
676+
677+
#' @keywords internal
678+
#' @noRd
679+
.rcpp_checkmissing_which64 <- function(y, invert, size) {
680+
.Call(`_broadcast_rcpp_checkmissing_which64`, y, invert, size)
681+
}
682+
599683
#' @keywords internal
600684
#' @noRd
601685
.rcpp_is_ma <- function(x) {
@@ -614,6 +698,20 @@ NULL
614698
.Call(`_broadcast_rcpp_clone`, x)
615699
}
616700

701+
#' @keywords internal
702+
NULL
703+
704+
#' @keywords internal
705+
NULL
706+
707+
.rcpp_ecp_mat <- function(y, sim, nrow, ncol, eps) {
708+
.Call(`_broadcast_rcpp_ecp_mat`, y, sim, nrow, ncol, eps)
709+
}
710+
711+
.rcpp_ecp_df <- function(y, sim, nrow, ncol, eps) {
712+
.Call(`_broadcast_rcpp_ecp_df`, y, sim, nrow, ncol, eps)
713+
}
714+
617715
#' @keywords internal
618716
#' @noRd
619717
.rcpp_depth_range <- function(x, depth_limit, recurse_all) {
@@ -646,44 +744,34 @@ NULL
646744

647745
#' @keywords internal
648746
#' @noRd
649-
.rcpp_make_dimnames2 <- function(xdimnames, ydimnames, outdim, pref) {
650-
.Call(`_broadcast_rcpp_make_dimnames2`, xdimnames, ydimnames, outdim, pref)
747+
.rcpp_lst_ndims <- function(x) {
748+
.Call(`_broadcast_rcpp_lst_ndims`, x)
651749
}
652750

653751
#' @keywords internal
654-
#' @noRd
655-
.rcpp_make_dimnames_between <- function(adimnames, vnames, outdim) {
656-
.Call(`_broadcast_rcpp_make_dimnames_between`, adimnames, vnames, outdim)
657-
}
752+
NULL
658753

659754
#' @keywords internal
660-
#' @noRd
661-
.rcpp_make_dimnames1 <- function(y_dimnames, ydim, outdim) {
662-
.Call(`_broadcast_rcpp_make_dimnames1`, y_dimnames, ydim, outdim)
663-
}
755+
NULL
664756

665757
#' @keywords internal
666-
#' @noRd
667-
.rcpp_is_mergeable_with_prev <- function(xB, yB) {
668-
.Call(`_broadcast_rcpp_is_mergeable_with_prev`, xB, yB)
758+
NULL
759+
760+
.rcpp_mergedims_get_endrange <- function(x, y, pos, intmax) {
761+
.Call(`_broadcast_rcpp_mergedims_get_endrange`, x, y, pos, intmax)
669762
}
670763

671-
#' @keywords internal
672-
#' @noRd
673-
.rcpp_mergedims <- function(xD, yD, mergeable) {
674-
.Call(`_broadcast_rcpp_mergedims`, xD, yD, mergeable)
764+
.rcpp_mergedims_get_prods <- function(x, y, start, end) {
765+
.Call(`_broadcast_rcpp_mergedims_get_prods`, x, y, start, end)
675766
}
676767

677-
#' @keywords internal
678-
NULL
768+
.rcpp_mergedims <- function(x, y) {
769+
.Call(`_broadcast_rcpp_mergedims`, x, y)
770+
}
679771

680772
#' @keywords internal
681773
#' @noRd
682774
.rcpp_set_attr <- function(x, name, value) {
683775
invisible(.Call(`_broadcast_rcpp_set_attr`, x, name, value))
684776
}
685777

686-
.rcpp_dimnames_fit <- function(x, dimnames) {
687-
.Call(`_broadcast_rcpp_dimnames_fit`, x, dimnames)
688-
}
689-

R/aaa04_broadcast_linearalgebra.R

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22
#'
33
#' @description
44
#' 'broadcast' provides some simple Linear Algebra Functions for Statistics: \cr
5-
#' `cinv()`; \cr
6-
#' `sd_lc()`. \cr
5+
#' `cinv()` \cr
6+
#' `sd_lc()` \cr
7+
#' `ecumprob()` \cr
78
#' \cr
89
#' \cr
910
#'
1011
#' @param x a real symmetric positive-definite square matrix.
1112
#' @param X a numeric (or logical) matrix of multipliers/constants
1213
#' @param vc the variance-covariance matrix for the (correlated) random variables.
14+
#' @param y values to estimate the cumulative probability for.
15+
#' @param sim a matrix (or data.frame) with at least 500 columns of simulated values. \cr
16+
#' If `sim` is given as a dimensionless vector,
17+
#' it will be treated as a matrix with 1 row and `length(sim)` columns,
18+
#' and this will be noted with a message.
19+
#' @param eps a non-negative numeric scaler smaller than `0.1`,
20+
#' giving the cut-off value for probabilities. \cr
21+
#' Probabilities smaller than `eps` will be replaced with `eps`,
22+
#' and probabilities larger than `1 - eps` will be replaced with `1 - eps`. \cr
23+
#' Set `eps = 0` to disable probability trimming.
1324
#' @param bad_rp if `vc` is not a Positive (semi-) Definite matrix,
1425
#' give here the value to replace bad standard deviations with. \cr \cr
1526
#'
1627
#' @details
17-
#' \bold{cinv()} \cr
28+
#' \bold{`cinv()`} \cr
1829
#' `cinv()`
1930
#' computes the Choleski inverse
2031
#' of a real symmetric positive-definite square matrix. \cr
2132
#' \cr
22-
#' \bold{sd_lc()} \cr
33+
#' \cr
34+
#' \bold{`sd_lc()`} \cr
2335
#' Given the linear combination `X %*% b`, where:
2436
#'
2537
#' - `X` is a matrix of multipliers/constants;
@@ -34,16 +46,39 @@
3446
#' (depending on the Linear Algebra Library used for base 'R'). \cr
3547
#' \cr
3648
#' \cr
37-
#'
49+
#' \bold{`ecumprob()`} \cr
50+
#' The `ecumprod(y, sim)` function takes a matrix (or data.frame) of simulated values `sim`,
51+
#' and for each row `i` (after broadcasting),
52+
#' estimates the cumulative distribution function of `sim[i, ]`,
53+
#' and returns the cumulative probability for `y[i]`. \cr
54+
#' \cr
55+
#' In terms of statistics,
56+
#' it is equivalent to the following operation for each index `i`: \cr
57+
#' `ecdf(sim[i,])(y[i])` \cr
58+
#' However, `ecumprob()` is \bold{much} faster, and supports `NA`s/`NaN`s. \cr
59+
#' \cr
60+
#' In terms of linear algebra,
61+
#' it is equivalent to the following broadcasted operation: \cr
62+
#' `rowMeans(sim <= y)` \cr
63+
#' where `y` and `sim` are \link{broadcaster} arrays. \cr
64+
#' However, `ecumprob()` is \bold{much more} memory-efficient,
65+
#' supports a data.frame for `sim`,
66+
#' and has statistical safety checks. \cr
67+
#' \cr
3868
#'
3969
#'
4070
#' @returns
4171
#' For `cinv()`: \cr
4272
#' A matrix. \cr
4373
#' \cr
4474
#' For `sd_lc()`: \cr
45-
#' A vector of standard deviations.
75+
#' A vector of standard deviations. \cr
4676
#' \cr
77+
#' For `ecumprob()`: \cr
78+
#' A vector of cumulative probabilities. \cr
79+
#' If for any observation `i` (after broadcasting,) `y[i]` is NA/NaN or any of `sim[i,]` is NA/NaN,
80+
#' the result for `i` will be `NA`. \cr
81+
#' If zero-length `y` or `sim` is given, a zero-length numeric vector is returned. \cr
4782
#' \cr
4883
#'
4984
#'

R/bc_cplx.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
#' @description
44
#' The `bc.cplx()` function performs broadcasted complex numeric operations on pairs of arrays. \cr
55
#' \cr
6-
#' Note that `bc.cplx()` uses more strict `NA` checks than base 'R': \cr
7-
#' If for an element of either `x` or `y`, either the real or imaginary part is `NA` or `NaN`,
8-
#' than the result of the operation for that element is necessarily `NA`. \cr
9-
#' \cr \cr
106
#'
117
#' @param x,y conformable vectors/arrays of type `complex`.
128
#' @param op a single string, giving the operator. \cr
139
#' Supported arithmetic operators: `r paste0(broadcast:::.op_cplx_math(), collapse = ", ")`. \cr
1410
#' Supported relational operators: `r paste0(broadcast:::.op_cplx_rel(), collapse = ", ")`.
1511
#' @param ... further arguments passed to or from methods. \cr \cr
1612
#'
13+
#' @details
14+
#' For the `*` and `/` operators, `bc.cplx()` uses more strict `NA` checks than base 'R': \cr
15+
#' If for an iteration,
16+
#' `re(x)`, `im(x)`, `re(y)`, and/or `im(y)` contains `NA`,
17+
#' than the result for that iteration is necessarily `NA_complex_`.
1718
#'
1819
#'
1920
#' @returns

0 commit comments

Comments
 (0)