DelayedMatrix-mult | R Documentation |
Like ordinary matrices in base R, DelayedMatrix objects and
derivatives can be multiplied with the %*%
operator. They also
support crossprod()
and tcrossprod()
.
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.
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 (via rbind()
or cbind()
, 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.
%*%
and crossprod
in base R.
getAutoRealizationBackend
and
setAutoRealizationBackend
for getting and setting
the automatic realization backend.
matrixStats-methods for DelayedMatrix row/col summarization.
DelayedMatrix-rowsum for rowsum()
and
colsum()
methods for DelayedMatrix objects.
DelayedArray objects.
writeHDF5Array
in 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.
library(HDF5Array)
toy_h5 <- system.file("extdata", "toy.h5", package="HDF5Array")
h5ls(toy_h5)
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
path(P2) # HDF5 file where the result got written
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.