broadcast Package Overview

Description

broadcast:
Broadcasted Array Operations Like ‘NumPy’

Implements efficient ‘NumPy’-like broadcasted operations for atomic and recursive arrays.

In the context of operations involving 2 (or more) arrays, “broadcasting” refers to efficiently recycling array dimensions without allocating additional memory.

Besides linking to ‘Rcpp’, ‘broadcast’ does not use any external libraries in any way; ‘broadcast’ was essentially made from scratch and can be installed out-of-the-box.

The implementations available in ‘broadcast’ include, but are not limited to, the following:

  1. Broadcasted element-wise operations on any 2 arrays; they support a large set of relational, arithmetic, Boolean, string, and bit-wise operations.

  2. A faster, more memory efficient, and broadcasted abind-like function, for binding arrays along an arbitrary dimension.

  3. Broadcasted ifelse-like, and apply-like functions.

  4. Casting functions, that cast subset-groups of an array to a new dimension, cast nested lists to dimensional lists, and vice-versa.

  5. A few linear algebra functions for statistics.

The functions in the ‘broadcast’ package strive to minimize computation time and memory usage (which is not just better for efficient computing, but also for the environment).

Functions

Broadcasted Operators
Base ‘R’ comes with relational (==, !=, etc.), arithmetic (+, -, *, /, etc.), and logical/bit-wise (&, |) operators.
‘broadcast’ provides 2 ways to use these operators with broadcasting.

The first (and simple) way is to use the broadcaster class, which comes with it’s own method dispatch for the above mentioned operators.
This method support operator precedence, and for the average ‘R’ user, this is sufficient.

The second way is to use the large set of bc.- functions.
These offer much greater control and more operators than the previous method, and has less risk of running into conflicting methods.
But it does not support operator precedence.

More information about both methods can be found here:
broadcast_operators.

Binding Arrays
‘broadcast’ provides the bind_array function, to bind arrays along an arbitrary dimension, with support for broadcasting.
See bind_array.

Casting Functions
‘broadcast’ provides several "casting" functions.
These can facility complex forms of broadcasting that would normally not be possible.
But these "casting" functions also have their own merit, beside empowering complex broadcasting.

More information about the casting functions can be found here:
broadcast_casting.

General Pairwise Broadcasted Functions
‘broadcast’ also comes with 2 general pairwise broadcasted functions:

  • bc_ifelse: Broadcasted version of ifelse.

  • bcapply: Broadcasted apply-like function.

Other functions
‘broadcast’ provides type-casting functions, which preserve names and dimensions - convenient for arrays.

‘broadcast’ also provides simple linear algebra functions for statistics.

And ‘broadcast’ comes with some helper functions:
bc_dim, ndim, lst.ndim, rep_dim.

Supported Structures

‘broadcast’ supports atomic/recursive arrays (up to 16 dimensions), and atomic/recursive vectors.
As in standard Linear Algebra convention, dimensionless vectors are interpreted as column-vectors in broadcasted array operations.

Author(s)

Author, Maintainer: Tony Wilkes tony_a_wilkes@outlook.com (ORCID)

References

Harris, C.R., Millman, K.J., van der Walt, S.J. et al. Array programming with NumPy. Nature 585, 357–362 (2020). doi:10.1038/s41586-020-2649-2. (Publisher link).