| SFBM-class {bigsparser} | R Documentation |
Class SFBM
Description
A reference class for storing and accessing sparse matrix-like data stored in files on disk.
Convert a 'dgCMatrix' or 'dsCMatrix' to an SFBM.
Usage
as_SFBM(spmat, backingfile = tempfile(), compact = FALSE)
Arguments
spmat |
A 'dgCMatrix' (non-symmetric sparse matrix of type 'double') or 'dsCMatrix' (symmetric sparse matrix of type 'double'). |
backingfile |
Path to file where to store data. Extension |
compact |
Whether to use a compact format? Default is |
Details
An object of class SFBM has many fields:
-
$address: address of the external pointer containing the underlying C++ object to be used as aXPtr<SFBM>in C++ code -
$extptr: (internal) use$addressinstead -
$nrow: number of rows -
$ncol: number of columns -
$nval: number of non-zero values -
$p: vector of column positions -
$backingfileor$sbk: File with extension 'sbk' that stores the data of the SFBM -
$rds: 'rds' file (that may not exist) corresponding to the 'sbk' file -
$is_saved: whether this object is stored in$rds?
And some methods:
-
$save(): Save the SFBM object in$rds. Returns the SFBM. -
$add_columns(): Add new columns from a 'dgCMatrix' or a 'dsCMatrix'. -
$dense_acc(): Equivalent toas.matrix(.[ind_row, ind_col]). Use with caution;ind_rowandind_colmust be positive indices within range.
Value
The new SFBM.
Examples
spmat2 <- Matrix::Diagonal(4, 0:3)
spmat2[4, 2] <- 5
spmat2[1, 4] <- 6
spmat2[3, 4] <- 7
spmat2
# Stores all (i, x) for x != 0
(X2 <- as_SFBM(spmat2))
matrix(readBin(X2$sbk, what = double(), n = 100), 2)
# Stores only x, but all (even the zero ones) from first to last being not 0
(X3 <- as_SFBM(spmat2, compact = TRUE))
X3$first_i
readBin(X3$sbk, what = double(), n = 100)