sparse_arr-class | R Documentation |
The sparse_mat
class implements sparse matrices, potentially stored out-of-memory. Both compressed-sparse-column (CSC) and compressed-sparse-row (CSR) formats are supported. Sparse vectors are also supported through the sparse_vec
class.
## Instance creation
sparse_mat(data, index, type = "double",
nrow = NA_integer_, ncol = NA_integer_, dimnames = NULL,
pointers = NULL, domain = NULL, offset = 0L, rowMaj = FALSE,
tolerance = c(abs=0), sampler = "none", ...)
sparse_vec(data, index, type = "double",
length = NA_integer_, names = NULL,
domain = NULL, offset = 0L, rowMaj = FALSE,
tolerance = c(abs=0), sampler = "none", ...)
# Check if an object is a sparse matrix
is.sparse(x)
# Coerce an object to a sparse matrix
as.sparse(x, ...)
## Additional methods documented below
data |
Either the non-zero values of the sparse array, or (if |
index |
For |
type |
A 'character' vector giving the storage mode of the data in virtual memory such. See |
nrow , ncol , length |
The number of rows and columns, or the length of the array. |
dimnames |
The names of the sparse matrix dimensions. |
names |
The names of the sparse vector elements. |
pointers |
The (zero-indexed) pointers to the start of either the rows or columns (depending on the value of |
domain |
Either |
offset |
If |
rowMaj |
Whether the data should be stored using compressed-sparse-row (CSR) representation (as opposed to compressed-sparse-column (CSC) representation). Defaults to 'FALSE', for efficient access to columns. Set to 'TRUE' for more efficient access to rows instead. |
tolerance |
For non- |
sampler |
For non-zero tolerances, how the |
x |
An object to check if it is a sparse matrix or coerce to a sparse matrix. |
... |
Additional arguments to be passed to constructor. |
An object of class sparse_mat
.
data
:The non-zero data values. Can be a numeric vector or a list of numeric vectors.
type
:The storage mode of the accessed data when read into R. This is a 'factor' with levels 'raw', 'logical', 'integer', 'numeric', or 'character'.
dim
:Either NULL
for vectors, or an integer vector of length one of more giving the maximal indices in each dimension for matrices and arrays.
names
:The names of the data elements for vectors.
dimnames
:Either NULL
or the names for the dimensions. If not NULL
, then this should be a list of character vectors of the length given by 'dim' for each dimension. This is always NULL
for vectors.
index
:The indices of the non-zero items. Can be a numeric vector or a list of numeric vectors.
pointers
:The pointers to the beginning of the rows or columns if index
and data
use vector storage rather than list storage.
domain
:Either NULL
or a vector with length equal to the number of rows (for CSC matrices) or the number of columns (for CSR matrices). If NULL
, then index
is assumed to be row or column indices. If a vector, then they define the how the non-zero elements are matched to rows or columns. The index
value of each non-zero element is matched against this domain using binary search. Must be numeric.
offset
:If domain
is NULL
(i.e., index
represents the actual row/column indices), then this is the index of the first row/column. The default of 0 means that index
is indexed from 0.
tolerance
:For non-NULL
domain, the tolerance used for floating-point equality when matching index
to the domain
. The vector should be named. Use 'absolute' to use absolute differences, and 'relative' to use relative differences.
sampler
:The type of summarization or interpolation performed when there are multiple index
values within the tolerance of the requested domain
value(s).
ops
:Deferred arithmetic operations.
transpose
Indicates whether the data is stored in row-major order (TRUE) or column-major order (FALSE). For a matrix, switching the order that the data is read is equivalent to transposing the matrix (without changing any data).
matter
sparse_mat
and sparse_vec
instances can be created through sparse_mat()
and sparse_vec()
, respectively.
Class-specific methods:
atomdata(x)
:Access the 'data' slot.
adata(x)
:An alias for atomdata(x).
atomindex(x)
:Access the 'index' slot.
aindex(x)
:An alias for atomindex(x).
pointers(x)
:Access the 'pointers' slot.
domain(x)
:Access the 'domain' slot.
tolerance(x), tolerance(x) <- value
:Get or set resampling 'tolerance'.
sampler(x), sampler(x) <- value
:Get or set the 'sampler' method.
fetch(x, ...)
:Pull data into shared memory.
flash(x, ...)
:Push data to a temporary file.
Standard generic methods:
dim(x):
Get 'dim'.
dimnames(x), dimnames(x) <- value
:Get or set 'dimnames'.
x[i, j, ..., drop], x[i, j] <- value
:Get or set the elements of the sparse matrix. Use drop = NULL
to return a subset of the same class as the object.
cbind(x, ...), rbind(x, ...)
:Combine sparse matrices by row or column.
t(x)
:Transpose a matrix. This is a quick operation which only changes metadata and does not touch the data representation.
rowMaj(x)
:Check the data orientation.
Kylie A. Bemis
matter
x <- matrix(rbinom(100, 1, 0.2), nrow=10, ncol=10)
y <- sparse_mat(x)
y[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.