Bioconductor / DelayedArray

A unified framework for working transparently with on-disk and in-memory array-like datasets
https://bioconductor.org/packages/DelayedArray
24 stars 9 forks source link

Inconsistent `dimnames` after matrix multiplication with zero-column output #113

Closed LTLA closed 6 months ago

LTLA commented 6 months ago

When multiplying a DelayedMatrix with a ordinary matrix, the dimnames changes when the output has no columns:

library(DelayedArray)
X <- DelayedArray(matrix(runif(100), 20, 5))
y <- cbind(runif(5), runif(5))
str(X %*% y) # two columns:
## num [1:20, 1:2] 1.78 1.01 1.38 1.33 2 ...

str(X %*% y[,1,drop=FALSE]) # one column:
## num [1:20, 1] 1.78 1.01 1.38 1.33 2 ...

str(X %*% y[,0,drop=FALSE]) # no columns:
## num[1:20, 0 ] 
## - attr(*, "dimnames")=List of 2
##  ..$ : NULL
##  ..$ : NULL

You can see how the dimnames suddenly changes from NULL to list(NULL, NULL). This is causing BiocSingular's tests to break around some equality checks that use DelayedArrays to compute the expected result.

Session information ``` R Under development (unstable) (2023-11-10 r85507) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 20.04.6 LTS Matrix products: default BLAS: /home/luna/Software/R/trunk/lib/libRblas.so LAPACK: /home/luna/Software/R/trunk/lib/libRlapack.so; LAPACK version 3.11.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C time zone: America/Los_Angeles tzcode source: system (glibc) attached base packages: [1] stats4 stats graphics grDevices utils datasets methods [8] base other attached packages: [1] DelayedArray_0.29.7 SparseArray_1.3.4 S4Arrays_1.3.4 [4] abind_1.4-5 IRanges_2.37.1 S4Vectors_0.41.3 [7] MatrixGenerics_1.15.0 matrixStats_1.2.0 BiocGenerics_0.49.1 [10] Matrix_1.6-5 loaded via a namespace (and not attached): [1] zlibbioc_1.49.0 lattice_0.22-5 XVector_0.43.1 grid_4.4.0 [5] compiler_4.4.0 tools_4.4.0 crayon_1.5.2 ```
hpages commented 6 months ago

Seems to be gone in DelayedArray 0.29.9:

library(DelayedArray)

X <- DelayedArray(matrix(runif(100), 20, 5))
y <- cbind(runif(5), runif(5))

str(X %*% y[,0,drop=FALSE])
## num[1:20, 0 ] 

Let me know if you still run into problems with this.

Session information ``` R Under development (unstable) (2024-01-02 r85764) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 23.10 Matrix products: default BLAS: /home/hpages/R/R-4.4.r85764/lib/libRblas.so LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C time zone: America/Los_Angeles tzcode source: system (glibc) attached base packages: [1] stats4 stats graphics grDevices utils datasets methods [8] base other attached packages: [1] DelayedArray_0.29.9 SparseArray_1.3.4 S4Arrays_1.3.5 [4] abind_1.4-5 IRanges_2.37.1 S4Vectors_0.41.3 [7] MatrixGenerics_1.15.0 matrixStats_1.2.0 BiocGenerics_0.49.1 [10] Matrix_1.6-5 loaded via a namespace (and not attached): [1] zlibbioc_1.49.0 lattice_0.22-5 XVector_0.43.1 grid_4.4.0 [5] compiler_4.4.0 tools_4.4.0 crayon_1.5.2 ```
LTLA commented 6 months ago

So it seems; closing.