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, and device default to those of like.

Usage

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

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

Arguments

value

(numeric(1))
Scalar value to fill the array with. It has to be something dtype can hold: a whole number in its range for an integer data type, a non-negative one for an unsigned integer, and a logical or 0 / 1 for bool.

shape

(integer())
Shape of the output array.

dtype

(NULL | character(1) | DataType)
Data type of the result. The default (NULL) uses the default data type for nv_fill and dtype(like) for nv_fill_like.

device

(NULL | character(1) | device)
The device the data lives on, given either as:

  • a device string naming the platform (e.g. "cpu", "cuda", "cuda:<n>"), which is resolved against the backend in use, or

  • a device object as returned by nv_device(): a PJRTDevice for the "pjrt" backend or a quickr_device for the "quickr" backend. Because a device object is backend-specific, it also determines the backend.

The default (NULL) uses default_device().

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

# the R double settles the data type, the shape is given
nv_fill(0, shape = c(2, 3))
#> AnvlArray
#>  0 0 0
#>  0 0 0
#> [ CPUf32{2,3} ] 

# `_like` takes shape, data type and device from an existing array
x <- nv_matrix(1:6, nrow = 2)
nv_fill_like(x, 0)
#> AnvlArray
#>  0 0 0
#>  0 0 0
#> [ CPUi32{2,3} ]