DelayedMatrix-mult: DelayedMatrix multiplication and cross-product

DelayedMatrix-multR Documentation

DelayedMatrix multiplication and cross-product

Description

Like 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 (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.

See Also

  • %*% and crossprod in base R.

  • getAutoRealizationBackend and setAutoRealizationBackend for getting and setting the automatic realization backend.

  • DelayedMatrix-stats 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.

Examples

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)

Bioconductor/DelayedArray documentation built on March 4, 2024, 9:12 p.m.