bigalgebra is designed to interoperate with the
bigmemory ecosystem. This vignette demonstrates how to
create in-memory and file-backed big.matrix objects,
interact with them via the package’s wrappers, and manage the underlying
resources safely.
big.matrix objectsIn-memory matrices behave much like ordinary R matrices but reside in shared memory, allowing multiple R sessions to access the same data.
X <- big.matrix(3, 3, type = "double", init = 0)
X[,] <- matrix(1:9, nrow = 3)
X[]
#> [,1] [,2] [,3]
#> [1,] 1 4 7
#> [2,] 2 5 8
#> [3,] 3 6 9Once created, the objects can be passed directly to Level 1 helpers:
File-backed matrices persist their contents on disk, making them suitable for data sets that exceed available RAM.
dir.create(tmp_fb <- tempfile())
Y <- filebacked.big.matrix(4, 2, type = "double",
backingpath = tmp_fb,
backingfile = "fb.bin",
descriptorfile = "fb.desc",
init = 0)
Y[,] <- matrix(runif(8), nrow = 4)
Y[]
#> [,1] [,2]
#> [1,] 0.6873701 0.1718248
#> [2,] 0.2224260 0.5158964
#> [3,] 0.1031403 0.5424801
#> [4,] 0.1385640 0.4317004These objects participate in higher-level operations without being loaded into memory.
Z <- filebacked.big.matrix(4, 2, type = "double",
backingpath = tmp_fb,
backingfile = "res.bin",
descriptorfile = "res.desc",
init = 0)
dvcal(ALPHA = 1.5, X = Y, BETA = 0, Y = Z)
Z[]
#> [,1] [,2]
#> [1,] 1.0310552 0.2577372
#> [2,] 0.3336390 0.7738446
#> [3,] 0.1547104 0.8137202
#> [4,] 0.2078460 0.6475506