Description Usage Arguments Details Value See Also Examples
View source: R/colBlockApply.R
Apply a function over blocks of columns or rows using DelayedArray's block processing mechanism.
1 2 3 | colBlockApply(x, FUN, ..., grid = NULL, BPPARAM = getAutoBPPARAM())
rowBlockApply(x, FUN, ..., grid = NULL, BPPARAM = getAutoBPPARAM())
|
x |
A matrix-like object to be split into blocks and looped over. This can be of any class that respects the matrix contract. |
FUN |
A function that operates on columns or rows in |
... |
Further arguments to pass to |
grid |
An ArrayGrid object specifying how |
BPPARAM |
A BiocParallelParam object from the BiocParallel package, specifying how parallelization should be performed across blocks. |
This is a wrapper around blockApply
that is dedicated to looping across rows or columns of x
.
The aim is to provide a simpler interface for the common task of apply
ing across a matrix,
along with a few modifications to improve efficiency for parallel processing and for natively supported x
.
Note that the fragmentation of x
into blocks is not easily predictable,
meaning that FUN
should be capable of operating on each row/column independently.
Users can retrieve the current location of each block within x
with currentViewport
inside FUN
.
If grid
is not explicitly set to an ArrayGrid object, it can take several values:
If TRUE
, the function will choose a grid that (i) respects the memory limits in getAutoBlockSize
and (ii) fragments x
into sufficiently fine chunks that every worker in BPPARAM
gets to do something.
If FUN
might make large allocations, this mode should be used to constrain memory usage.
The default grid=NULL
is very similar to TRUE
except that that memory limits are ignored when x
is of any type that can be passed directly to FUN
.
This avoids unnecessary copies of x
and is best used when FUN
itself does not make large allocations.
If FALSE
, the function will choose a grid that covers the entire x
.
This is provided for completeness and is only really useful for debugging.
A list of length equal to the number of blocks,
where each entry is the output of FUN
for the results of processing each the rows/columns in the corresponding block.
blockApply
, for the original DelayedArray implementation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | x <- matrix(runif(10000), ncol=10)
str(colBlockApply(x, colSums))
str(rowBlockApply(x, rowSums))
library(Matrix)
y <- rsparsematrix(10000, 10000, density=0.01)
str(colBlockApply(y, colSums))
str(rowBlockApply(y, rowSums))
library(DelayedArray)
z <- DelayedArray(y) + 1
str(colBlockApply(z, colSums))
str(rowBlockApply(z, rowSums))
# We can also force multiple blocks:
library(BiocParallel)
BPPARAM <- SnowParam(2)
str(colBlockApply(x, colSums, BPPARAM=BPPARAM))
str(rowBlockApply(x, rowSums, BPPARAM=BPPARAM))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.