Serializes a named list of arrays into the safetensors format.
Arguments
- arrays
(named
listofAnvlArray)
Named list of arrays to serialize. Names must be unique.- con
(
NULL| connection)
An optional connection to write to. IfNULL(default), a raw vector is returned.
Value
(raw | NULL)
A raw vector if con is NULL, otherwise NULL invisibly.
Examples
# data types and shapes round-trip unchanged
x <- nv_matrix(1:6, nrow = 2)
x
#> AnvlArray
#> 1 3 5
#> 2 4 6
#> [ CPUi32{2,3} ]
raw_data <- nv_serialize(list(x = x))
raw_data
#> [1] 39 00 00 00 00 00 00 00 7b 22 78 22 3a 7b 22 73 68 61 70 65 22 3a 5b 32 2c
#> [26] 33 5d 2c 22 64 74 79 70 65 22 3a 22 49 33 32 22 2c 22 64 61 74 61 5f 6f 66
#> [51] 66 73 65 74 73 22 3a 5b 30 2c 32 34 5d 7d 7d 01 00 00 00 03 00 00 00 05 00
#> [76] 00 00 02 00 00 00 04 00 00 00 06 00 00 00
nv_unserialize(raw_data)
#> $x
#> AnvlArray
#> 1 3 5
#> 2 4 6
#> [ CPUi32{2,3} ]
#>