SOMASparseNDArray
is a sparse, N-dimensional array with
offset (zero-based) integer indexing on each dimension. The
SOMASparseNDArray
has a user-defined schema, which includes:
type
: aprimitive
type, expressed as an Arrow type (e.g.,int64
,float32
, etc), indicating the type of data contained within the array.shape
: the shape of the array, i.e., number and length of each dimension. This is a soft limit which can be increased using$resize()
up to themaxshape
.maxshape
: the hard limit up to whichshape
may be increased using$resize()
.
All dimensions must have a positive, non-zero length.
Note
In TileDB this is an sparse array with N
int64
dimensions
of domain [0, maxInt64)
and a single attribute.
Duplicate Writes
As duplicate index values are not allowed, index values already present in the object are overwritten and new index values are added (lifecycle: maturing).
Super classes
tiledbsoma::SOMAObject
-> tiledbsoma::SOMAArrayBase
-> tiledbsoma::SOMANDArrayBase
-> SOMASparseNDArray
Methods
Inherited methods
tiledbsoma::SOMAObject$class()
tiledbsoma::SOMAObject$exists()
tiledbsoma::SOMAObject$get_metadata()
tiledbsoma::SOMAObject$initialize()
tiledbsoma::SOMAObject$is_open()
tiledbsoma::SOMAObject$mode()
tiledbsoma::SOMAObject$reopen()
tiledbsoma::SOMAObject$set_metadata()
tiledbsoma::SOMAArrayBase$allows_duplicates()
tiledbsoma::SOMAArrayBase$attributes()
tiledbsoma::SOMAArrayBase$attrnames()
tiledbsoma::SOMAArrayBase$close()
tiledbsoma::SOMAArrayBase$colnames()
tiledbsoma::SOMAArrayBase$dimensions()
tiledbsoma::SOMAArrayBase$dimnames()
tiledbsoma::SOMAArrayBase$index_column_names()
tiledbsoma::SOMAArrayBase$is_sparse()
tiledbsoma::SOMAArrayBase$maxshape()
tiledbsoma::SOMAArrayBase$ndim()
tiledbsoma::SOMAArrayBase$non_empty_domain()
tiledbsoma::SOMAArrayBase$open()
tiledbsoma::SOMAArrayBase$print()
tiledbsoma::SOMAArrayBase$schema()
tiledbsoma::SOMAArrayBase$shape()
tiledbsoma::SOMANDArrayBase$create()
tiledbsoma::SOMANDArrayBase$resize()
tiledbsoma::SOMANDArrayBase$set_data_type()
tiledbsoma::SOMANDArrayBase$tiledbsoma_has_upgraded_shape()
tiledbsoma::SOMANDArrayBase$tiledbsoma_upgrade_shape()
Method read()
Reads a user-defined slice of the SOMASparseNDArray
.
Arguments
coords
Optional
list
of integer vectors, one for each dimension, with a length equal to the number of values to read. IfNULL
, all values are read. List elements can be named when specifying a subset of dimensions.result_order
Optional order of read results. This can be one of either
"ROW_MAJOR,
"COL_MAJOR", or
"auto"` (default).log_level
Optional logging level with default value of “
warn
”.
Method write()
Write matrix-like data to the array (lifecycle: maturing).
Arguments
values
Any
matrix
-like object coercible to aTsparseMatrix
. Character dimension names are ignored becauseSOMANDArray
s use integer indexing.bbox
A vector of integers describing the upper bounds of each dimension of
values
. Generally should beNULL
.
Method .write_coordinates()
Write a COO table to the array.
Arguments
values
A
data.frame
or Arrow table with data in COO format; must be named with the dimension and attribute labels of the array.
Examples
uri <- withr::local_tempfile(pattern = "soma-sparse-array")
mat <- Matrix::rsparsematrix(100L, 100L, 0.7, repr = "T")
mat[1:3, 1:5]
#> 3 x 5 sparse Matrix of class "dgTMatrix"
#>
#> [1,] 0.59 . 1.30 -1.20 .
#> [2,] 0.30 0.55 1.20 -1.50 -2.9
#> [3,] 0.41 . -0.37 0.59 .
(arr <- SOMASparseNDArrayCreate(uri, arrow::float64(), shape = dim(mat)))
#> <SOMASparseNDArray>
#> uri: /tmp/RtmpjD0Pq2/soma-sparse-array270935291ab9
#> dimensions: soma_dim_0, soma_dim_1
#> attributes: soma_data
arr$write(mat)
arr$close()
(arr <- SOMASparseNDArrayOpen(uri))
#> <SOMASparseNDArray>
#> uri: /tmp/RtmpjD0Pq2/soma-sparse-array270935291ab9
#> dimensions: soma_dim_0, soma_dim_1
#> attributes: soma_data
m2 <- arr$read()$sparse_matrix()$concat()
m2[1:3, 1:5]
#> 3 x 5 sparse Matrix of class "dgTMatrix"
#>
#> [1,] 0.59 . 1.30 -1.20 .
#> [2,] 0.30 0.55 1.20 -1.50 -2.9
#> [3,] 0.41 . -0.37 0.59 .