Skip to contents

nv_save() saves a named list of arrays to a file in the safetensors format, and nv_read() loads them back. The data type and shape of each array are restored.

Usage

nv_save(arrays, path)

nv_read(path, device = NULL)

Arguments

arrays

(named list of AnvlArray)
Named list of arrays. Names must be unique.

path

(character(1))
File path to write to or read from.

device

(NULL | character(1) | PJRTDevice)
The device on which to place the loaded arrays ("cpu", "cuda", ...) when the active backend is "pjrt", defaulting to default_device().

Value

nv_save(): (NULL)
Invisibly.

nv_read(): (named list of AnvlArray)

Details

These are convenience wrappers around nv_serialize() and nv_unserialize() that open and close a file connection.

Examples

x <- nv_matrix(1:6, nrow = 2)
x
#> AnvlArray
#>  1 3 5
#>  2 4 6
#> [ CPUi32{2,3} ] 
path <- tempfile(fileext = ".safetensors")
nv_save(list(x = x), path)
nv_read(path)
#> $x
#> AnvlArray
#>  1 3 5
#>  2 4 6
#> [ CPUi32{2,3} ] 
#>