Skip to content

Proposal to migrate DelayedMask to the DelayedArray package #122

@LTLA

Description

@LTLA

My alabaster.matrix package has a DelayedMask class that replaces all instances of a placeholder with an NA value during extract_*_array() calls. Essentially, it is equivalent to:

library(DelayedArray)
y <- DelayedArray(matrix(rbinom(100, 1, 0.2), ncol=5))
placeholder <- 1

z <- y
z[z == placeholder] <- NA

# Gives the same (abstract) matrix contents as:
alabaster.matrix::DelayedMask(y, placeholder)

AFAICT the DelayedMask approach should be more efficient as the DelayedMask only realizes one matrix while the delayed [<- requires realization of both z and z == placeholder. (Currently DelayedMask is literally for masking NAs but it could be generalized to handle more boolean operations, e.g., so z[z > cap] <- cap could be used to upper-bound the contents of the matrix.)

Would this be of interest to the DelayedArray package? Perhaps there might be an easy way that we can detect that the logical subset is generated from the same matrix that it is operating on in [<-, and switch from creating a DelayedNaryIsoOp to a DelayedMask.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions