Commit f5716e48 authored by Dylan Aïssi's avatar Dylan Aïssi

New upstream version 0.8.0+dfsg

parent 1d4944ed
......@@ -8,29 +8,35 @@ Description: Wrapping an array-like object (typically an on-disk object) in
also works on in-memory array-like objects like DataFrame objects
(typically with Rle columns), Matrix objects, and ordinary arrays and
data frames.
Version: 0.6.6
Version: 0.8.0
Encoding: UTF-8
Author: Hervé Pagès
Author: Hervé Pagès <hpages@fredhutch.org>, with contributions from
Peter Hickey <peter.hickey@gmail.com>
Maintainer: Hervé Pagès <hpages@fredhutch.org>
biocViews: Infrastructure, DataRepresentation, Annotation,
GenomeAnnotation
Depends: R (>= 3.4), methods, stats4, matrixStats, BiocGenerics (>=
0.25.1), S4Vectors (>= 0.17.43), IRanges (>= 2.11.17),
0.27.1), S4Vectors (>= 0.19.15), IRanges (>= 2.11.17),
BiocParallel
Imports: stats
LinkingTo: S4Vectors
Suggests: Matrix, HDF5Array, genefilter, SummarizedExperiment, airway,
pryr, knitr, BiocStyle, RUnit
pryr, DelayedMatrixStats, knitr, BiocStyle, RUnit
License: Artistic-2.0
VignetteBuilder: knitr
Collate: utils.R bind-arrays.R Array-class.R ArrayGrid-class.R
extract_array.R show-utils.R DelayedOp-class.R showtree.R
DelayedArray-class.R realize.R block_processing.R
DelayedArray-utils.R DelayedMatrix-utils.R DelayedArray-stats.R
Collate: utils.R compress_atomic_vector.R Nindex-utils.R aperm2.R
linearInd.R bind-arrays.R Array-class.R extract_array.R
ArrayGrid-class.R show-utils.R SparseArraySeed-class.R
read_block.R mapToGrid.R makeCappedVolumeBox.R blockGrid.R
DelayedOp-class.R showtree.R DelayedArray-class.R chunkGrid.R
block_processing.R RealizationSink-class.R realize.R
DelayedArray-subsetting.R DelayedArray-utils.R
DelayedMatrix-utils.R DelayedArray-stats.R
DelayedMatrix-stats.R RleArray-class.R zzz.R
git_url: https://git.bioconductor.org/packages/DelayedArray
git_branch: RELEASE_3_7
git_last_commit: bdb0ac0
git_last_commit_date: 2018-09-10
Date/Publication: 2018-09-11
NeedsCompilation: no
Packaged: 2018-09-12 01:25:39 UTC; biocbuild
git_branch: RELEASE_3_8
git_last_commit: 7c23cf4
git_last_commit_date: 2018-10-30
Date/Publication: 2018-10-30
NeedsCompilation: yes
Packaged: 2018-10-31 01:42:10 UTC; biocbuild
useDynLib(DelayedArray)
import(methods)
importFrom(stats, setNames,
dnorm, pnorm, qnorm,
......@@ -23,13 +25,31 @@ exportClasses(
## ArrayGrid-class.R:
ArrayViewport, ArrayGrid, ArbitraryArrayGrid, RegularArrayGrid,
## extract_array.R:
integer_OR_NULL,
## SparseArraySeed-class.R:
SparseArraySeed,
## DelayedOp-class.R:
DelayedOp,
DelayedUnaryOp,
DelayedSubset,
DelayedAperm,
DelayedUnaryIsoOp,
DelayedUnaryIsoOpStack,
DelayedUnaryIsoOpWithArgs,
DelayedSubassign,
DelayedDimnames,
DelayedNaryOp,
DelayedNaryIsoOp,
DelayedAbind,
## DelayedArray-class.R:
DelayedArray, DelayedMatrix,
DelayedArray1,
## realize.R:
## chunkGrid.R:
integer_OR_NULL,
## RealizationSink-class.R:
RealizationSink, arrayRealizationSink,
## RleArray-class.R:
......@@ -42,9 +62,13 @@ exportClasses(
### Export S3 methods
###
S3method(aperm, ArbitraryArrayGrid)
S3method(aperm, RegularArrayGrid)
S3method(aperm, SparseArraySeed)
S3method(aperm, DelayedArray)
S3method(as.array, Array)
S3method(as.array, SparseArraySeed)
S3method(as.character, Array)
S3method(as.character, ArrayGrid)
......@@ -58,6 +82,7 @@ S3method(as.integer, Array)
S3method(as.logical, Array)
S3method(as.matrix, Array)
S3method(as.matrix, SparseArraySeed)
S3method(as.numeric, Array)
......@@ -67,26 +92,35 @@ S3method(as.vector, Array)
S3method(mean, DelayedArray)
S3method(range, DelayedArray)
S3method(split, DelayedArray)
S3method(summary, DelayedOp)
S3method(summary, DelayedSubset)
S3method(summary, DelayedAperm)
S3method(summary, DelayedUnaryIsoOp)
S3method(summary, DelayedUnaryIsoOpStack)
S3method(summary, DelayedUnaryIsoOpWithArgs)
S3method(summary, DelayedDimnames)
S3method(summary, DelayedNaryIsoOp)
S3method(summary, DelayedAbind)
S3method(t, DelayedMatrix)
S3method(t, Array)
S3method(unique, DelayedArray)
### We also export them thru the export() directive so that (a) they can be
### called directly, (b) tab-completion on the name of the generic shows them,
### and (c) methods() doesn't asterisk them.
export(
aperm.ArbitraryArrayGrid,
aperm.RegularArrayGrid,
aperm.SparseArraySeed,
aperm.DelayedArray,
as.array.Array,
as.array.SparseArraySeed,
as.character.ArrayGrid,
as.character.Array,
......@@ -100,6 +134,7 @@ export(
as.logical.Array,
as.matrix.Array,
as.matrix.SparseArraySeed,
as.numeric.Array,
......@@ -109,17 +144,22 @@ export(
mean.DelayedArray,
range.DelayedArray,
split.DelayedArray,
summary.DelayedOp,
summary.DelayedSubset,
summary.DelayedAperm,
summary.DelayedUnaryIsoOp,
summary.DelayedUnaryIsoOpStack,
summary.DelayedUnaryIsoOpWithArgs,
summary.DelayedDimnames,
summary.DelayedNaryIsoOp,
summary.DelayedAbind,
t.DelayedMatrix
t.Array,
unique.DelayedArray
)
......@@ -143,6 +183,7 @@ exportMethods(
"==", "!=", "<=", ">=", "<", ">", # "Compare" group generic
sweep,
anyNA, which,
unique,
max, min, range, sum, prod, any, all, # "Summary" group generic
mean,
round, signif,
......@@ -163,13 +204,15 @@ exportMethods(
summary,
## Methods for generics defined in the BiocGenerics package:
dims,
cbind, rbind,
grepl,
table,
path, "path<-",
updateObject,
## Methods for generics defined in the S4Vectors package:
isEmpty,
showAsCell, isEmpty,
## Methods for generics defined in the IRanges package:
ranges, start, end, width,
......@@ -182,23 +225,42 @@ exportMethods(
###
export(
## linearInd.R:
linearInd,
## ArrayGrid-class.R:
ArrayViewport, makeNindexFromArrayViewport,
ArbitraryArrayGrid, RegularArrayGrid,
## SparseArraySeed-class.R:
SparseArraySeed, dense2sparse, sparse2dense,
## makeCappedVolumeBox.R:
makeCappedVolumeBox, makeRegularArrayGridOfCappedLengthViewports,
## blockGrid.R:
setAutoBlockSize, getAutoBlockSize,
get_type_size, getAutoBlockLength,
setAutoBlockShape, getAutoBlockShape,
blockGrid, rowGrid, colGrid,
## showtree.R:
showtree, contentIsPristine,
## DelayedArray-class.R:
new_DelayedArray,
## realize.R:
supportedRealizationBackends, getRealizationBackend, setRealizationBackend,
## block_processing.R:
getDefaultBPPARAM, setDefaultBPPARAM,
defaultGrid, blockApply, effectiveGrid, currentBlockId, currentViewport,
write_array_to_sink,
setAutoGridMaker, getAutoGridMaker,
setAutoBPPARAM, getAutoBPPARAM,
blockApply, blockReduce,
effectiveGrid, currentBlockId, currentViewport,
BLOCK_write_to_sink,
## RealizationSink-class.R:
supportedRealizationBackends,
getRealizationBackend, setRealizationBackend,
RealizationSink,
## RleArray-class.R:
RleArray
......@@ -213,23 +275,41 @@ export(
## bind-arrays.R:
arbind, acbind,
## extract_array.R:
extract_array, type,
## ArrayGrid-class.R:
refdim, isLinear,
refdim, maxlength, aperm, downsample,
## extract_array.R:
extract_array, type, chunkdim,
## SparseArraySeed-class.R:
aind, nzdata, sparsity, is_sparse, extract_sparse_array,
## read_block.R:
read_block, write_block,
read_sparse_block, write_sparse_block,
## mapToGrid.R:
mapToGrid, mapToRef,
## makeCappedVolumeBox.R:
isLinear,
## DelayedOp-class.R:
isNoOp,
is_noop,
## showtree.R:
simplify, netSubsetAndAperm,
## DelayedArray-class.R:
matrixClass, DelayedArray, nseed, seed, "seed<-", aperm,
matrixClass, DelayedArray, nseed, seed, "seed<-",
## chunkGrid.R:
chunkdim, chunkGrid,
## RealizationSink-class.R:
close,
## realize.R:
chunk_dim, write_block_to_sink, close,
realize,
## DelayedArray-utils.R:
......@@ -242,12 +322,17 @@ export(
### Exactly the same list as above.
exportMethods(
arbind, acbind,
refdim, isLinear,
extract_array, type, chunkdim,
isNoOp,
extract_array, type,
refdim, maxlength, aperm, downsample,
aind, nzdata, sparsity, is_sparse, extract_sparse_array,
read_block, write_block,
mapToGrid, mapToRef,
isLinear,
is_noop,
simplify, netSubsetAndAperm,
matrixClass, DelayedArray, nseed, seed, "seed<-", aperm,
chunk_dim, write_block_to_sink, close,
matrixClass, DelayedArray, nseed, seed, "seed<-",
chunkdim, chunkGrid,
close,
realize,
pmax2, pmin2, apply,
rowMaxs, colMaxs, rowMins, colMins, rowRanges, colRanges
......
CHANGES IN VERSION 0.8.0
------------------------
NEW FEATURES
o Add get/setAutoBlockSize(), getAutoBlockLength(),
get/setAutoBlockShape() and get/setAutoGridMaker().
o Add rowGrid() and colGrid(), in addition to blockGrid().
o Add get/setAutoBPPARAM() to control the automatic 'BPPARAM' used by
blockApply().
o Reduce memory usage when realizing a sparse DelayedArray to disk
On-disk realization of a DelayedArray object that is reported to be sparse
(by is_sparse()) to a "sparsity-optimized" backend (i.e. to a backend with
a memory efficient write_sparse_block() like the TENxMatrix backend imple-
mented in the HDF5Array package) now preserves sparse representation of
the data all the way. More precisely, each block of data is now kept in
a sparse form during the 3 steps that it goes thru: read from seed,
realize in memory, and write to disk.
o showtree() now displays whether a tree node or leaf is considered sparse
or not.
o Enhance "aperm" method and dim() setter for DelayedArray objects. In
addition to allowing dropping "ineffective dimensions" (i.e. dimensions
equal to 1) from a DelayedArray object, aperm() and the dim() setter now
allow adding "ineffective dimensions" to it.
o Enhance subassignment to a DelayedArray object.
So far subassignment to a DelayedArray object only supported the **linear
form** (i.e. x[i] <- value) with strong restrictions (the subscript 'i'
must be a logical DelayedArray of the same dimensions as 'x', and 'value'
must be an ordinary vector of length 1).
In addition to this linear form, subassignment to a DelayedArray object
now supports the **multi-dimensional form** (e.g. x[3:1, , 6] <- 0). In
this form, one subscript per dimension is supplied, and each subscript
can be missing or be anything that multi-dimensional subassignment to
an ordinary array supports. The replacement value (a.k.a. the right
value) can be an array-like object (e.g. ordinary array, dgCMatrix object,
DelayedArray object, etc...) or an ordinary vector of length 1. Like the
linear form, the multi-dimensional form is also implemented as a delayed
operation.
o Re-implement internal helper simple_abind() in C and support long arrays.
simple_abind() is the workhorse behind realization of arbind() and
acbind() operations on DelayedArray objects.
o Add "table" and (restricted) "unique" methods for DelayedArray objects,
both block-processed.
o range() (block-processed) now supports the 'finite' argument on a
DelayedArray object.
o %*% (block-processed) now works between a DelayedMatrix object and an
ordinary vector.
o Improve support for DelayedArray of type "list".
o Add TENxMatrix to list of supported realization backends.
o Add backend-agnostic RealizationSink() constructor.
o Add linearInd() utility for turning array indices into linear indices.
Note that linearInd() performs the reverse transformation of
base::arrayInd().
o Add low-level utilities mapToGrid() and mapToRef() for mapping reference
array positions to grid positions and vice-versa.
o Add downsample() for reducing the "resolution" of an ArrayGrid object.
o Add maxlength() generic and methods for ArrayGrid objects.
SIGNIFICANT USER-VISIBLE CHANGES
o Multi-dimensional subsetting is no more delayed when drop=TRUE and the
result has only one dimension. In this case the result now is returned
as an **ordinary** vector (atomic or list). This is the only case of
multi-dimensional single bracket subsetting that is not delayed.
o Rename defaultGrid() -> blockGrid(). The 'max.block.length' argument
is replaced with the 'block.length' argument. 2 new arguments are
added: 'chunk.grid' and 'block.shape'.
o Major improvements to the block processing mechanism.
All block-processed operations (except realization by block) now support
blocks of **arbitrary** geometry instead of column-oriented blocks only.
'blockGrid(x)', which is called by the block-processed operations to get
the grid of blocks to use on 'x', has the following new features:
1) It's "chunk aware". This means that, when the chunk grid is known (i.e.
when 'chunkGrid(x)' is not NULL), 'blockGrid(x)' defines blocks that
are "compatible" with the chunks i.e. that any chunk is fully contained
in a block. In other words, blocks are chosen so that chunks don't
cross their boundaries.
2) When the chunk grid is unknown (i.e. when 'chunkGrid(x)' is NULL),
blocks are "isotropic", that is, they're as close as possible to an
hypercube instead of being "column-oriented" (column-oriented blocks,
also known as "linear blocks", are elongated along the 1st dimension,
then along the 2nd dimension, etc...)
3) The returned grid has the lowest "resolution" compatible with
'getAutoBlockSize()', that is, the blocks are made as big as possible
as long as their size in memory doesn't exceed 'getAutoBlockSize()'.
Note that this is not a new feature. What is new though is that an
exception now is made when the chunk grid is known and some chunks
are >= 'getAutoBlockSize()', in which case 'blockGrid(x)' returns a
grid that is the same as the chunk grid.
These new features are supposed to make the returned grid "optimal" for
block processing. (Some benchmarks still need to be done to
confirm/quantify this.)
o The automatic block size now is set to 100 Mb (instead of 4.5 Mb
previously) at package startup. Use setAutoBlockSize() to change the
automatic block size.
o No more 'BPREDO' argument to blockApply().
o Replace block_APPLY_and_COMBINE() with blockReduce().
BUG FIXES
o No-op operations on a DelayedArray derivative really act like no-ops.
Operating on a DelayedArray derivative (e.g. RleArray, HDF5Array or
GDSArray) will now return an objet of the original class if the result
is "pristine" (i.e. if it doesn't carry delayed operations) instead of
degrading the object to a DelayedArray instance. This applies for example
to 't(t(x))' or 'dimnames(x) <- dimnames(x)' etc...
......@@ -7,6 +7,14 @@
### an array-like semantic.
setClass("Array", representation("VIRTUAL"))
### Note that some objects with dimensions (i.e. with a non-NULL dim()) can
### have a length() that is not 'prod(dim(x))' e.g. data-frame-like objects
### (for which 'length(x)' is 'ncol(x)') and SummarizedExperiment derivatives
### (for which 'length(x)' is 'nrow(x)').
### Terminology: Should we still consider that these objects are "array-like"
### or "matrix-like"? Or should these terms be used only for objects that
### have dimensions **and** have a length() defined as 'prod(dim(x))'?
### Even though prod() always returns a double, it seems that the length()
### primitive function takes care of turning this double into an integer if
### it's <= .Machine$integer.max
......@@ -23,27 +31,10 @@ setGeneric("getArrayElement", signature="x",
function(x, subscripts) standardGeneric("getArrayElement")
)
### Return an integer vector parallel to 'dim' and guaranteed to contain no
### out-of-bounds subscripts.
.from_linear_to_multi_subscript <- function(i, dim)
{
stopifnot(isSingleInteger(i))
if (i < 1L || i > prod(dim))
stop("subscript is out of bounds")
i <- i - 1L
subscripts <- integer(length(dim))
for (along in seq_along(dim)) {
d <- dim[[along]]
subscripts[[along]] <- offset <- i %% d
i <- (i - offset) %/% d
}
subscripts + 1L
}
### Support multi-dimensional and linear subsetting.
### FIXME: Linear subsetting should support a single *numeric* subscript.
### FIXME: Multi-dimensional subsetting should support things like
### x[[5, 15, 2]] and x[["E", 15, "b"]].
### TODO: Multi-dimensional subsetting should support things like
### x[[5, 15, 2]] and x[["E", 15, "b"]].
### TODO: Linear subsetting should support a single *numeric* subscript.
setMethod("[[", "Array",
function(x, i, j, ...)
{
......@@ -60,14 +51,32 @@ setMethod("[[", "Array",
stop(wmsg("each subscript must be a single integer ",
"when subsetting an ", class(x), " object with [["))
if (nsubscript == x_ndim) {
## Multi-dimensional subsetting.
subscripts <- unlist(Nindex, use.names=FALSE)
if (!(all(subscripts >= 1L) && all(subscripts <= x_dim)))
stop("some subscripts are out of bounds")
} else {
## Translate linear subsetting into multi-dimensional subsetting.
subscripts <- .from_linear_to_multi_subscript(Nindex[[1L]], x_dim)
## Linear subsetting.
## We turn this into a multi-dimensional subsetting by
## transforming the user-supplied linear index into an array
## (i.e. multi-dimensional) index.
i <- Nindex[[1L]]
if (i < 1L || i > prod(x_dim))
stop("subscript is out of bounds")
subscripts <- as.integer(arrayInd(i, x_dim))
}
getArrayElement(x, subscripts)
}
)
### S3/S4 combo for t.Array
### t() will work out-of-the-box on any Array derivative that supports aperm().
t.Array <- function(x)
{
if (length(dim(x)) != 2L)
stop(wmsg("the ", class(x), " object to transpose ",
"must have exactly 2 dimensions"))
aperm(x)
}
setMethod("t", "Array", t.Array)
This diff is collapsed.
This diff is collapsed.
......@@ -12,20 +12,22 @@
setMethod("dnorm", "DelayedArray",
function(x, mean=0, sd=1, log=FALSE)
stash_DelayedUnaryIsoOp(x, "dnorm",
Rargs=list(mean=mean, sd=sd, log=log))
stash_DelayedUnaryIsoOpStack(x,
function(a) dnorm(a, mean=mean, sd=sd, log=log))
)
setMethod("pnorm", "DelayedArray",
function(q, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(q, "pnorm",
Rargs=list(mean=mean, sd=sd, lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(q,
function(a) pnorm(a, mean=mean, sd=sd,
lower.tail=lower.tail, log.p=log.p))
)
setMethod("qnorm", "DelayedArray",
function(p, mean=0, sd=1, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(p, "qnorm",
Rargs=list(mean=mean, sd=sd, lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(p,
function(a) qnorm(a, mean=mean, sd=sd,
lower.tail=lower.tail, log.p=log.p))
)
......@@ -38,22 +40,22 @@ setMethod("qnorm", "DelayedArray",
setMethod("dbinom", "DelayedArray",
function(x, size, prob, log=FALSE)
stash_DelayedUnaryIsoOp(x, "dbinom",
Rargs=list(size=size, prob=prob, log=log))
stash_DelayedUnaryIsoOpStack(x,
function(a) dbinom(a, size=size, prob=prob, log=log))
)
setMethod("pbinom", "DelayedArray",
function(q, size, prob, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(q, "pbinom",
Rargs=list(size=size, prob=prob,
lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(q,
function(a) pbinom(a, size=size, prob=prob,
lower.tail=lower.tail, log.p=log.p))
)
setMethod("qbinom", "DelayedArray",
function(p, size, prob, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(p, "qbinom",
Rargs=list(size=size, prob=prob,
lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(p,
function(a) qbinom(a, size=size, prob=prob,
lower.tail=lower.tail, log.p=log.p))
)
......@@ -66,20 +68,22 @@ setMethod("qbinom", "DelayedArray",
setMethod("dpois", "DelayedArray",
function(x, lambda, log=FALSE)
stash_DelayedUnaryIsoOp(x, "dpois",
Rargs=list(lambda=lambda, log=log))
stash_DelayedUnaryIsoOpStack(x,
function(a) dpois(a, lambda=lambda, log=log))
)
setMethod("ppois", "DelayedArray",
function(q, lambda, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(q, "ppois",
Rargs=list(lambda=lambda, lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(q,
function(a) ppois(a, lambda=lambda,
lower.tail=lower.tail, log.p=log.p))
)
setMethod("qpois", "DelayedArray",
function(p, lambda, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(p, "qpois",
Rargs=list(lambda=lambda, lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(p,
function(a) qpois(a, lambda=lambda,
lower.tail=lower.tail, log.p=log.p))
)
......@@ -92,21 +96,21 @@ setMethod("qpois", "DelayedArray",
setMethod("dlogis", "DelayedArray",
function(x, location=0, scale=1, log=FALSE)
stash_DelayedUnaryIsoOp(x, "dlogis",
Rargs=list(location=location, scale=scale, log=log))
stash_DelayedUnaryIsoOpStack(x,
function(a) dlogis(a, location=location, scale=scale, log=log))
)
setMethod("plogis", "DelayedArray",
function(q, location=0, scale=1, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(q, "plogis",
Rargs=list(location=location, scale=scale,
lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(q,
function(a) plogis(a, location=location, scale=scale,
lower.tail=lower.tail, log.p=log.p))
)
setMethod("qlogis", "DelayedArray",
function(p, location=0, scale=1, lower.tail=TRUE, log.p=FALSE)
stash_DelayedUnaryIsoOp(p, "qlogis",
Rargs=list(location=location, scale=scale,
lower.tail=lower.tail, log.p=log.p))
stash_DelayedUnaryIsoOpStack(p,
function(a) qlogis(a, location=location, scale=scale,
lower.tail=lower.tail, log.p=log.p))
)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -4,15 +4,6 @@
###
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Transpose
###
### S3/S4 combo for t.DelayedMatrix
t.DelayedMatrix <- function(x) aperm(x)
setMethod("t", "DelayedMatrix", t.DelayedMatrix)
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Matrix multiplication
###
......@@ -21,7 +12,7 @@ setMethod("t", "DelayedMatrix", t.DelayedMatrix)
### DelayedMatrix objects is not supported.
###
.DelayedMatrix_block_mult_by_left_matrix <- function(x, y)
.BLOCK_mult_by_left_matrix <- function(x, y)
{
stopifnot(is.matrix(x),
is(y, "DelayedMatrix") || is.matrix(y),
......@@ -29,45 +20,79 @@ setMethod("t", "DelayedMatrix", t.DelayedMatrix)
ans_dim <- c(nrow(x), ncol(y))
ans_dimnames <- simplify_NULL_dimnames(list(rownames(x), colnames(y)))
ans_type <- typeof(match.fun(type(x))(1) * match.fun(type(y))(1))
ans_type <- typeof(vector(type(x), 1L) * vector(type(y), 1L))
sink <- RealizationSink(ans_dim, ans_dimnames, ans_type)
on.exit(close(sink))
## We're going to walk along the columns so need to increase the block
## length so that each block is made of at least one column.
max_block_len <- max(get_max_block_length(type(y)), nrow(y))
spacings <- get_spacings_for_linear_capped_length_blocks(dim(y),
max_block_len)
y_grid <- RegularArrayGrid(dim(y), spacings)
spacings[[1L]] <- ans_dim[[1L]]
ans_grid <- RegularArrayGrid(ans_dim, spacings) # parallel to 'y_grid'
y_grid <- colGrid(y)
ans_spacings <- c(ans_dim[[1L]], ncol(y_grid[[1L]]))
ans_grid <- RegularArrayGrid(ans_dim, ans_spacings) # parallel to 'y_grid'
nblock <- length(y_grid) # same as 'length(ans_grid)'
for (b in seq_len(nblock)) {
if (get_verbose_block_processing())
message("Processing block ", b, "/", nblock, " ... ",
appendLF=FALSE)
y_viewport <- y_grid[[b]]
block <- as.matrix(extract_block(y, y_viewport))
block <- read_block(y, y_viewport)
block_ans <- x %*% block
write_block_to_sink(block_ans, sink, ans_grid[[b]])
write_block(sink, ans_grid[[b]], block_ans)
if (get_verbose_block_processing())
message("OK")
}
as(sink, "DelayedArray")
}
setMethod("%*%", c("DelayedMatrix", "matrix"),
function(x, y) t(t(y) %*% t(x))
)
setMethod("%*%", c("matrix", "DelayedMatrix"),
.DelayedMatrix_block_mult_by_left_matrix
setMethod("%*%", c("ANY", "DelayedMatrix"),
function(x, y)
{
if (!is.matrix(x)) {
if (!is.vector(x))