Skip to contents

Broadcasts arrays to a common shape using NumPy-style broadcasting rules.

Usage

nv_broadcast_arrays(...)

Arguments

...

(arrayish)
Arrays to broadcast.

Value

(list() of arrayish)
List of arrays, all with the same shape.

Broadcasting Rules

  1. If the arrays have different numbers of dimensions, prepend size-1 dimensions to the shorter shape.

  2. For each dimension: if the sizes match, keep them; if one is 1, expand it to the other's size; otherwise raise an error.

Examples

x <- nv_array(matrix(1:6, nrow = 2))
y <- nv_array(c(10, 20, 30))
nv_broadcast_arrays(x, y)
#> [[1]]
#> AnvlArray
#>  1 3 5
#>  2 4 6
#> [ CPUi32{2,3} ] 
#> 
#> [[2]]
#> AnvlArray
#>  10 20 30
#>  10 20 30
#> [ CPUf32{2,3} ] 
#>