DelayedMatrix multiplication and cross-product
DelayedMatrix-mult.RdLike ordinary matrices in base R, DelayedMatrix objects and
derivatives can be multiplied with the %*% operator. They also
support crossprod() and tcrossprod().
Details
Note that matrix multiplication is not delayed: the output matrix is
realized block by block.
The automatic realization backend controls where realization
happens e.g. in memory as an ordinary matrix if not set (i.e. set to
NULL), or in an HDF5 file if set to "HDF5Array".
See ?setAutoRealizationBackend for more information
about realization backends.
Value
The object returned by matrix multiplication involving at least one DelayedMatrix object will be either:
An ordinary matrix if the automatic realization backend is
NULL(the default).A DelayedMatrix object if the automatic realization backend is not
NULL. In this case, the returned DelayedMatrix object will be either pristine or made of several pristine DelayedMatrix objects bound together (viarbind()orcbind(), both are delayed operations).For example, if the automatic realization backend is
"HDF5Array", then the returned DelayedMatrix object will be either an HDF5Array object, or it will be a DelayedMatrix object made of several HDF5Array objects bound together.
See also
getAutoRealizationBackendandsetAutoRealizationBackendfor getting and setting the automatic realization backend.matrixStats-methods for DelayedMatrix row/col summarization.
DelayedMatrix-rowsum for
rowsum()andcolsum()methods for DelayedMatrix objects.DelayedArray objects.
writeHDF5Arrayin the HDF5Array package for writing an array-like object to an HDF5 file and other low-level utilities to control the location of automatically created HDF5 datasets.HDF5Array objects in the HDF5Array package.
Examples
library(HDF5Array)
toy_h5 <- system.file("extdata", "toy.h5", package="HDF5Array")
h5ls(toy_h5)
#> group name otype dclass dim
#> 0 / M1 H5I_DATASET FLOAT 10000 x 150
#> 1 / M2 H5I_DATASET FLOAT 150 x 200
M1 <- HDF5Array(toy_h5, "M1")
m <- matrix(runif(50000), ncol=nrow(M1))
## Set backend to NULL for in-memory realization (this is the default):
setAutoRealizationBackend()
p1 <- m %*% M1 # an ordinary matrix
## Set backend to HDF5Array for realization in HDF5 file:
setAutoRealizationBackend("HDF5Array")
P2 <- m %*% M1 # an HDF5Array object
P2
#> <5 x 150> HDF5Matrix object of type "double":
#> [,1] [,2] [,3] ... [,149] [,150]
#> [1,] 2481.010 2492.454 2473.605 . 2489.904 2508.180
#> [2,] 2454.361 2486.738 2463.601 . 2490.252 2484.518
#> [3,] 2486.819 2519.504 2502.645 . 2533.711 2514.529
#> [4,] 2493.259 2508.908 2480.975 . 2538.177 2532.947
#> [5,] 2525.096 2541.923 2517.538 . 2544.587 2542.471
path(P2) # HDF5 file where the result got written
#> [1] "/tmp/RtmptRnwDm/HDF5Array_dump/auto1ce11ce173d2.h5"
## Sanity checks:
stopifnot(
is.matrix(p1),
all.equal(p1, m %*% as.matrix(M1)),
is(P2, "HDF5Array"),
all.equal(as.matrix(P2), p1)
)
setAutoRealizationBackend() # restore default (NULL)