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

Should I be using @seed instead of seed()? #14

Closed PeteHaitch closed 5 years ago

PeteHaitch commented 6 years ago

With the change to the seed() getter in 3551306bb239e9d4d6d3521afa557b646251d980, should I now be using x@seed instead of seed(x) to check whether a DelayedArray is "simple" (i.e. the seed is just a matrix, Matrix, HDF5ArraySeed, SolidRleArraySeed, etc.) rather than a DelayedOp?

hpages commented 6 years ago

Hi Pete, x@seed gives you the immediate child of x in the tree of delayed ops (x being considered the root node). In contrast seed(x) goes all the way down to the leaf node of the tree so will never return a DelayedOp object. This means that a test like is(seed(x), "DelayedOp") would always return FALSE. Note that if by "simple" you mean "pristine", you could use is_pristine(x). It just does !is(x@seed, "DelayedOp"). Finally note that x@seed is equivalent to seed(x) if and only if x is pristine. Hope this helps.

hpages commented 6 years ago

Related to this, 3 days ago I added nseed(): https://github.com/Bioconductor/DelayedArray/commit/f7e647b675f479db9d4d3cf4b229d02e810e6126 seed(x) is only supported if nseed(x) is 1. Otherwise it raises an error:

> library(HDF5Array)
> M1 <- as(matrix(1:15, ncol=3), "HDF5Array")
> nseed(M1)
[1] 1
> seed(M1)
An object of class "HDF5ArraySeed"
Slot "filepath":
[1] "/tmp/RtmpXcnIht/HDF5Array_dump/auto00005.h5"

Slot "name":
[1] "/HDF5ArrayAUTO00005"

Slot "dim":
[1] 5 3

Slot "first_val":
[1] 1

Slot "chunkdim":
[1] 5 3

> M2 <- as(matrix(1:9, ncol=3), "HDF5Array")
> M3 <- rbind(M1, M2)
> nseed(M3)
[1] 2
> seed(M3)
Error in seed(x = x) : 
  seed() is not supported on a DelayedArray object with multiple seeds at
  the moment. Note that you can check the number of seeds with nseed().

This is another important difference with x@seed: x@seed can never fail!

H.

hpages commented 5 years ago

Closing this.