Skip to contents

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

Usage

nv_broadcast_tensors(...)

Arguments

...

(tensorish)
Tensors to broadcast.

Value

(list() of tensorish)
List of tensors, all with the same shape.

Broadcasting Rules

  1. If the tensors 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

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