Skip to contents

Creates an array filled with a scalar value. More memory-efficient than nv_array(value, shape = shape) for large arrays.

nv_fill_like() is a variant where dtype, shape, ambiguous, and device default to those of like.

Usage

nv_fill(value, shape, dtype = NULL, ambiguous = FALSE, device = NULL)

nv_fill_like(
  like,
  value,
  shape = NULL,
  dtype = NULL,
  ambiguous = NULL,
  device = NULL
)

Arguments

value

(numeric(1))
Scalar value to fill the array with.

shape

(integer())
Shape of the output array.

dtype

(character(1) | NULL)
Data type.

ambiguous

(logical(1))
Whether the type is ambiguous. Ambiguous types usually arise from R literals (e.g., 1L, 1.0) and follow special promotion rules. See the vignette("type-promotion") for more details.

device

( character(1) | PJRTDevice | quickr_device | NULL)
Device for data to live on.

like

(AnvlArray)
Existing array whose attributes are used as defaults (only for nv_fill_like()).

Value

arrayish
Has the given shape and dtype.

See also

prim_fill() for the underlying primitive.

Examples

nv_fill(0, shape = c(2, 3))
#> AnvlArray
#>  0 0 0
#>  0 0 0
#> [ CPUf32{2,3} ] 
x <- nv_array(matrix(1:6, nrow = 2))
nv_fill_like(x, 0)
#> AnvlArray
#>  0 0 0
#>  0 0 0
#> [ CPUi32{2,3} ]