These functions provide the implementations for their underlying infix operators (i.e. rray_add() powers +). All operators apply broadcasting to their input.

x %b+% y

rray_add(x, y)

x %b-% y

rray_subtract(x, y)

x %b*% y

rray_multiply(x, y)

x %b/% y

rray_divide(x, y)

x %b^% y

rray_pow(x, y)

rray_identity(x)

rray_opposite(x)

Arguments

x, y

A pair of vectors.

Value

The value of the arithmetic operation, with dimensions identical to the common dimensions of the input.

Details

In case you want to apply arithmetic operations with broadcasting to purely base R objects using infix operators, custom infix functions have been exported, such as %b+%, which will perform addition with broadcasting no matter what type the input is.

Examples

library(magrittr) x <- rray(1:8, c(2, 2, 2)) %>% rray_set_row_names(c("r1", "r2")) %>% rray_set_col_names(c("c1", "c2")) y <- matrix(1:2, nrow = 1) # All arithmetic functions are applied with broadcasting rray_add(x, y)
#> <rray<int>[,2,2][2]> #> , , 1 #> #> c1 c2 #> r1 2 5 #> r2 3 6 #> #> , , 2 #> #> c1 c2 #> r1 6 9 #> r2 7 10 #>
# And the power `+` when any underlying input # is an rray x + y
#> <rray<int>[,2,2][2]> #> , , 1 #> #> c1 c2 #> r1 2 5 #> r2 3 6 #> #> , , 2 #> #> c1 c2 #> r1 6 9 #> r2 7 10 #>
# If you happen to only have base R matrices/arrays # you can use `rray_add()` or `%b+%` to get the # broadcasting behavior rray_add(y, matrix(1:2))
#> [,1] [,2] #> [1,] 2 3 #> [2,] 3 4
y %b+% matrix(1:2)
#> [,1] [,2] #> [1,] 2 3 #> [2,] 3 4