bpvec {BiocParallel}R Documentation

Parallel, vectorized evaluation

Description

bpvec applies FUN to subsets of X. Any type of object X is allowed, provided length, [, and c methods are available. The return value is a vector of length equal to X, as with FUN(X).

Usage

bpvec(X, FUN, ..., AGGREGATE=c, BPPARAM=bpparam())

## S4 method for signature 'ANY,ANY'
bpvec(X, FUN, ..., AGGREGATE=c, BPPARAM=bpparam())

## S4 method for signature 'ANY,BiocParallelParam'
bpvec(X, FUN, ..., AGGREGATE=c, BPPARAM=bpparam())

## S4 method for signature 'ANY,missing'
bpvec(X, FUN, ..., AGGREGATE=c, BPPARAM=bpparam())

Arguments

X

Any object for which methods length, [, and c are implemented.

FUN

The function to be applied to subsets of X.

...

Additional arguments for FUN.

AGGREGATE

A function taking any number of arguments ... called to reduce results (elements of the ... argument of AGGREGATE from parallel jobs. The default, c, concatenates objects and is appropriate for vectors; rbind might be appropriate for data frames.

BPPARAM

A optional BiocParallelParam instance determining the parallel back-end to be used during evaluation.

Details

When BPPARAM is an instance of a class derived from BiocParallelParam for which no other method applies, this method creates a vector of indexes and uses these in conjunction with bplapply to arrange for parallel evaluation.

When BPPARAM is a class for which no method is defined (e.g., SerialParam), FUN(X) is used.

See showMethods{bpvec} for additional methods, e.g., method?bpvec("MulticoreParam").

Value

The result should be identical to FUN(X, ...) (assuming that AGGREGATE is set appropriately).

Author(s)

Martin Morgan mailto:mtmorgan@fhcrc.org. Original code as attributed in pvec.

See Also

bplapply for parallel lapply.

BiocParallelParam for possible values of BPPARAM.

Examples

showMethods("bpvec")

## ten tasks (1:10), called with as many back-end elements are specified
## by BPPARAM.  Compare with bplapply
system.time(result <- bpvec(1:10, function(v) {
    message("working") ## 10 tasks
    sqrt(v)
}))
result


[Package BiocParallel version 0.6.1 Index]