Bioconductor / SparseArray

High-performance sparse data representation and manipulation in R
8 stars 2 forks source link

`extract_sparse_array` recurses infinitely for `dgRMatrix` objects #18

Closed LTLA closed 1 month ago

LTLA commented 1 month ago
library(Matrix)
library(SparseArray)

# Testing dgCMatrix objects as a control:
xc <- rsparsematrix(100, 20, 0.5)
extract_sparse_array(xc, list(NULL, NULL))
## <100 x 20 SparseMatrix> of type "double" [nzcount=1000 (50%)]:
##          [,1]   [,2]   [,3] ... [,19] [,20]
##   [1,]   0.00   0.00   0.00   .   0.7   0.0
##   [2,]   0.00   0.00   0.00   .   0.0   0.0
##   [3,]   0.00   0.00   0.00   .   0.0   0.0
##   [4,]   0.46   1.60   0.00   .  -1.6  -2.2
##   [5,]   1.70   0.00   0.33   .  -1.2   0.0
##    ...      .      .      .   .     .     .
##  [96,]  0.620  0.000  0.000   .  0.00 -1.30
##  [97,]  1.600  0.000 -0.510   . -0.78  1.80
##  [98,]  2.400 -0.500  0.027   .  0.12  1.10
##  [99,]  0.960  0.000 -0.990   .  0.00  0.28
## [100,] -0.780  0.880  0.180   .  1.60  0.00

# Now testing dgRMatrix objects:
xr <- as(xc, "RsparseMatrix")
extract_sparse_array(xr, list(NULL, NULL))
## Error in stopifnot(length(class2) == 1L) : node stack overflow

This is causing check failures for alabaster.matrix in BioC-devel. It must have triggered by a recent-ish change in SparseArray (or related packages) as my failing test was last modified in 2023.

Session information ``` R version 4.4.0 Patched (2024-05-20 r86569) Platform: x86_64-pc-linux-gnu Running under: Ubuntu 22.04.5 LTS Matrix products: default BLAS: /home/luna/Software/R/R-4-4-branch/lib/libRblas.so LAPACK: /home/luna/Software/R/R-4-4-branch/lib/libRlapack.so; LAPACK version 3.12.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] SparseArray_1.5.44 S4Arrays_1.5.10 IRanges_2.39.2 [4] abind_1.4-8 S4Vectors_0.43.2 MatrixGenerics_1.17.0 [7] matrixStats_1.4.1 BiocGenerics_0.51.3 Matrix_1.7-0 loaded via a namespace (and not attached): [1] zlibbioc_1.51.1 compiler_4.4.0 tools_4.4.0 XVector_0.45.0 [5] crayon_1.5.3 grid_4.4.0 lattice_0.22-6 ```
hpages commented 1 month ago

Yep, sorry for that. Should go away with SparseArray 1.5.45 (see commit 028d25475b7f320bb90b9b1a122c12c713db8184).

Effect of these changes won't become visible on the daily report before next Thursday.