PeteHaitch / DelayedMatrixStats

A port of the matrixStats API to work with DelayedMatrix objects from the DelayedArray package
Other
15 stars 7 forks source link

Fix 2 issues with how the 'center' argument is handled #69

Closed hpages closed 4 years ago

hpages commented 4 years ago

See issue #68 for the details.

This patch fixes the 1st issue:

library(HDF5Array)
library(DelayedMatrixStats)

m <- matrix(1:30, nrow=6) * 10^(0:5)
M1 <- as(m, "HDF5Matrix")
M2 <- as(t(m), "HDF5Matrix")

# row/colVars():
current <- rowVars(M1, rows=5:6, center=rowMeans(M1))
stopifnot(all.equal(rowVars(M1)[5:6], current))

current <- colVars(M2, cols=5:6, center=colMeans(M2))
stopifnot(all.equal(colVars(M2)[5:6], current))

# row/colMads():
current <- rowMads(M1, rows=5:6, center=rowMedians(M1))
stopifnot(all.equal(rowMads(M1)[5:6], current))

current <- colMads(M2, cols=5:6, center=colMedians(M2))
stopifnot(all.equal(colMads(M2)[5:6], current))

# row/colSds():
current <- rowSds(M1, rows=5:6, center=rowMeans(M1))
stopifnot(all.equal(rowSds(M1)[5:6], current))

current <- colSds(M2, cols=5:6, center=colMeans(M2))
stopifnot(all.equal(colSds(M2)[5:6], current))

and the 2nd issue:

total_data_size <- length(M1) * get_type_size(type(M1))
setAutoBlockSize(total_data_size * 2/3)

# row/colVars():
current <- rowVars(M1, center=rowMeans(M1))
stopifnot(all.equal(rowVars(M1), current))

current <- colVars(M2, center=colMeans(M2))
stopifnot(all.equal(colVars(M2), current))

current <- rowVars(M1, center=0)
rs0 <- rowSums(M1^2) / (ncol(M1) - 1)
stopifnot(all.equal(rs0, current))

current <- colVars(M2, center=0)
cs0 <- colSums(M2^2) / (nrow(M2) - 1)
stopifnot(all.equal(cs0, current))

# row/colMads():
current <- rowMads(M1, center=rowMedians(M1))
stopifnot(all.equal(rowMads(M1), current))

current <- colMads(M2, center=colMedians(M2))
stopifnot(all.equal(colMads(M2), current))

# row/colSds():
current <- rowSds(M1, center=rowMeans(M1))
stopifnot(all.equal(rowSds(M1), current))

current <- colSds(M2, center=colMeans(M2))
stopifnot(all.equal(colSds(M2), current))

H.

PeteHaitch commented 4 years ago

Thanks, Hervé. I've pushed to BioC