rray-logical: Logical operators

Description Usage Arguments Details Value Examples

Description

These functions perform logical operations on arrays, with broadcasting. They power the logical operators of &, |, and ! with rrays, but are also exported for use with base R objects.

Usage

1
2
3
4
5
6
7
8
9

Arguments

x, y

Vectors, matrices, arrays, or rrays.

axes

An integer vector specifying the axes to reduce over. 1 reduces the number of rows to 1, performing the reduction along the way. 2 does the same, but with the columns, and so on for higher dimensions. The default reduces along all axes.

Details

The operators themselves rely on R's dispatching rules to dispatch to the correct rray logical operator. When comparing rrays with base R matrices and arrays, this generally works fine. However, if you compare classed objects like factor("x") & rray(1) then a fall through error is thrown. There is nothing we can do about this. See ?groupGeneric for more information on this.

The behavior of comparing an array with a length 0 dimension with another array is slightly different than base R since broadcasting behavior is well defined. Length 0 dimensions are not exceptions to the normal broadcasting rules. Comparing dimensions of 0 and 1, the common dimension is 0 because 1 always becomes the other dimension in the comparison. On the other hand, comparing dimensions 0 and 2 is an error because neither are 1, and they are not identical.

Value

The value of the logical comparison, with broadcasting.

rray_any() and rray_all() return a logical object with the same shape as x everywhere except along axes, which have been reduced to size 1.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
x <- rray(TRUE, c(2, 2, 3))
y <- matrix(c(TRUE, FALSE))

# `TRUE` wherever `y` is broadcasted to be `TRUE`
x & y

# ---------------------------------------------------------------------------
# Behavior with edge cases

x <- rray(TRUE, c(1, 2))

# The common dim is (0, 2)
logical() & x

# You can have empty arrays with shape
# The common dim is (0, 2, 2)
y <- array(logical(), c(0, 1, 2))
x & y

# You cannot broadcast dimensions
# of 2 and 0. Following standard
# broadcasting rules, they do not
# match and neither are 1, so an
# error should be thrown
try(x & array(logical(), c(1, 0)))

rray documentation built on July 23, 2019, 5:04 p.m.