Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unname() doesn't restore the matrixClass of my DelayedOps subclass #121

Open
LTLA opened this issue Dec 13, 2024 · 0 comments
Open

unname() doesn't restore the matrixClass of my DelayedOps subclass #121

LTLA opened this issue Dec 13, 2024 · 0 comments

Comments

@LTLA
Copy link
Contributor

LTLA commented Dec 13, 2024

Another side-effect from #119 - unname() doesn't restore the matrixClass of my ReloadedArray:

library(alabaster.base)
arr <- array(rpois(260, 10), c(26, 10))
dir <- tempfile()
saveObject(arr, dir)

obj <- readArray(dir)
library(DelayedArray)
showtree(obj)
## 26x10 integer: ReloadedMatrix object
## └─ 26x10 integer: ReloadedArraySeed object
##    └─ 26x10 integer: Stack of 1 unary iso op(s)
##       └─ 26x10 raw: [seed] HDF5ArraySeed object

rownames(obj) <- LETTERS
showtree(obj)
## 26x10 integer: DelayedMatrix object
## └─ 26x10 integer: Set dimnames
##    └─ 26x10 integer: ReloadedArraySeed object
##       └─ 26x10 integer: Stack of 1 unary iso op(s)
##          └─ 26x10 raw: [seed] HDF5ArraySeed object

obj <- unname(obj)
showtree(obj)
## 26x10 integer: DelayedMatrix object
## └─ 26x10 integer: ReloadedArraySeed object
##    └─ 26x10 integer: Stack of 1 unary iso op(s)
##       └─ 26x10 raw: [seed] HDF5ArraySeed object

You can see after the unnaming, I don't recover my ReloadedMatrix class, which has some consequences for correct dispatch (e.g., see broken celldex build).

The root cause is the DelayedArray,DelayedOps-method. This first simplifies the seed to remove the opposing dimnames operations, leaving a ReloadedArraySeed, so far so good. However, because ReloadedArraySeed now inherits from DelayedOps, the code decides to call the new_DelayedArray() function instead of DelayedArray(). This bypasses my DelayedArray method for ReloadedArraySeed, leading to the incorrect class being returned.

I can see that the if condition is necessary to avoid infinite recursion, so a "simple" fix might be to check whether a DelayedArray method exists for the seed that is not the DelayedOps method:

# seed is simplified at this point.
FUN <- selectMethod("DelayedArray", class(seed))
if (FUN@defined@.Data != "DelayedOps") {
   return(FUN(seed))
}

Or some kind of logic like that.

Session information
R Under development (unstable) (2024-10-31 r87278)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 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.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] alabaster.matrix_1.7.4 alabaster.base_1.7.2   HDF5Array_1.35.2      
 [4] rhdf5_2.51.1           DelayedArray_0.33.3    SparseArray_1.7.2     
 [7] S4Arrays_1.7.1         IRanges_2.41.2         abind_1.4-8           
[10] S4Vectors_0.45.2       MatrixGenerics_1.19.0  matrixStats_1.4.1     
[13] BiocGenerics_0.53.3    generics_0.1.3         Matrix_1.7-1          

loaded via a namespace (and not attached):
 [1] zlibbioc_1.53.0         lattice_0.22-6          rhdf5filters_1.19.0    
 [4] XVector_0.47.0          Rhdf5lib_1.29.0         grid_4.5.0             
 [7] compiler_4.5.0          tools_4.5.0             alabaster.schemas_1.7.0
[10] Rcpp_1.0.13-1           jsonlite_1.8.9          crayon_1.5.3           
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant