broadcast Package Overview

Description

broadcast:
‘Numpy’-Like Broadcasted Operations for Atomic and Recursive Arrays with Minimal Dependencies.

Implements simple broadcasted operations for atomic and recursive arrays.

Besides linking to ‘Rcpp’, ‘broadcast’ does not depend on, vendor, link to, include, or otherwise use any external libraries; ‘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. A set of type-specific functions for broadcasted element-wise operations on any 2 arrays; they support a large set of relational-, arithmetic-, Boolean-, and string operations.

  2. A faster, more memory efficient, and broadcasted version of abind(), for binding arrays along an arbitrary dimension;

  3. Broadcasted ifelse- and apply-like functions;

  4. The acast() function, for casting/pivoting an array into a new dimension.

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

Getting Started

An introduction and overview of the package can be found HERE.
Note that ‘broadcast’ is still somewhat experimental; if you find bugs or other issues, please report them promptly on the ‘broadcast’ GitHub issues tab.

Functions

Functions for broadcasted element-wise binary operations
‘broadcast’ provides a set of functions for broadcasted element-wise binary operations with broadcasting.
These functions use an API similar to the outer function.

The following functions for type-specific binary operations are available:

  • bc.b: Boolean (i.e. logical) operations;

  • bc.i: integer arithmetic and relational operations;

  • bc.d: decimal arithmetic and relational operations;

  • bc.cplx: complex arithmetic and (in)equality operations;

  • bc.str: string (in)equality, concatenation, and distance operations;

  • bc.raw: byte- and relational operations for vectors/arrays of type raw;

  • bc.bit: BIT-WISE operations, supporting the raw and integer types;

  • bc.list: apply any ‘R’ function to 2 recursive arrays with broadcasting.

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

The API of bind_array() is inspired by the fantastic abind::abind() function by Tony Plare & Richard Heiberger (2016).
But bind_array() differs considerably from abind::abind in the following ways:

  • bind_array() differs from abind::abind in that it can handle recursive arrays properly
    (the abind::abind function would unlist everything to atomic arrays, ruining the structure).

  • bind_array() allows for broadcasting, while abind::abind does not support broadcasting.

  • bind_array() is generally faster than abind::abind, as bind_array() relies heavily on ‘C’ and ‘C++’ code.

  • unlike abind::abind, bind_array() only binds (atomic/recursive) arrays and matrices.
    bind_array()does not attempt to convert things to arrays when they are not arrays, but will give an error instead.
    This saves computation time and prevents unexpected results.

  • bind_array() has more streamlined naming options, compared to abind::abind.

General functions
‘broadcast’ also comes with 2 general broadcasted functions:

  • bc_ifelse: Broadcasted version of ifelse.

  • bcapply: Broadcasted apply-like function.

Other functions
‘broadcast’ provides the acast function, for casting (i.e. pivoting) an array into a new dimension.

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

Overloading

Sometimes broadcasting is needed in large mathematical expression, involving multiple variables, where precedence is of importance.
For example in an expression like x + y / z^y.
For such cases, you may want to overload the base operators.
To that end, the ‘broadcast’ package provides the broadcaster class, which comes with its own method dispatch for the base operators.

Author(s)

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

References

Plate T, Heiberger R (2016). abind: Combine Multidimensional Arrays. R package version 1.4-5, https://CRAN.R-project.org/package=abind.