Skip to content

Commit

Permalink
add BPCellsBasicSeed class
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 30, 2024
1 parent d1c7913 commit 6867ad2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
2 changes: 0 additions & 2 deletions R/Class-BPCellsMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,3 @@ methods::setMethod(
methods::setMethod("matrixClass", "BPCellsArray", function(x) {
"BPCellsMatrix"
})

methods::setMethod("entity", "BPCellsMatrix", function(x) x@seed)
5 changes: 3 additions & 2 deletions R/Class-BPCellsSeed.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ methods::setClass("BPCellsSeed",
)
methods::setClass("BPCellsUnaryOpsSeed", contains = c("BPCellsSeed", "VIRTUAL"))
methods::setClass("BPCellsNaryOpsSeed", contains = c("BPCellsSeed", "VIRTUAL"))
methods::setClass("BPCellsBasicSeed", contains = c("BPCellsSeed", "VIRTUAL"))

#' @export
#' @rdname BPCellsSeed
Expand All @@ -38,7 +39,7 @@ methods::setMethod("BPCellsSeed", "BPCellsSeed", function(x) {
#############################################################
# used to extract the actual entity of `BPCellsSeed` objet.
methods::setGeneric("entity", function(x, ...) standardGeneric("entity"))
methods::setMethod("entity", "BPCellsSeed", function(x) x)
methods::setMethod("entity", "BPCellsBasicSeed", function(x) x)
methods::setMethod("entity", "BPCellsUnaryOpsSeed", function(x) {
x@matrix
})
Expand All @@ -55,7 +56,7 @@ methods::setMethod("entity", "BPCellsUnaryOpsSeed", function(x) {
############################################################
# Iterable_dgCMatrix_wrapper
methods::setClass("BPCellsdgCMatrixSeed",
contains = c("BPCellsSeed", get_class("Iterable_dgCMatrix_wrapper"))
contains = c("BPCellsBasicSeed", get_class("Iterable_dgCMatrix_wrapper"))
)

#' @noRd
Expand Down
2 changes: 1 addition & 1 deletion R/Class-Dir.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
methods::setClass("BPCellsDirSeed",
contains = c("BPCellsSeed", get_class("MatrixDir"))
contains = c("BPCellsBasicSeed", get_class("MatrixDir"))
)

BPCellsDirSeed <- function(x) methods::as(x, "BPCellsDirSeed")
Expand Down
2 changes: 1 addition & 1 deletion R/Class-HDF5.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# - add method of subset: Method-subset.R
# - add method of showtree: showtree.R
methods::setClass("BPCellsHDF5Seed",
contains = c("BPCellsSeed", get_class("MatrixH5"))
contains = c("BPCellsBasicSeed", get_class("MatrixH5"))
)

BPCellsHDF5Seed <- function(x) methods::as(x, "BPCellsHDF5Seed")
Expand Down
2 changes: 1 addition & 1 deletion R/Class-Mem.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @noRd
NULL

methods::setClass("BPCellsMemSeed", contains = "BPCellsSeed")
methods::setClass("BPCellsMemSeed", contains = c("BPCellsBasicSeed", "VIRTUAL"))
methods::setClass("BPCellsPackedMemSeed",
contains = c("BPCellsMemSeed", get_class("PackedMatrixMemBase"))
)
Expand Down
3 changes: 2 additions & 1 deletion R/runSVD.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ methods::setMethod(
)

methods::setMethod("SpectraSVD", "BPCellsMatrix", function(x, ...) {
SpectraSVD(x = entity(x), ...)
x <- x@seed
methods::callGeneric()
})

methods::setMethod(
Expand Down
51 changes: 34 additions & 17 deletions R/showtree.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,24 @@ showtree <- function(object) {
#' @export
#' @rdname showtree
methods::setMethod("nseed", "BPCellsMatrix", function(x) {
nseed(entity(x))
x <- x@seed
methods::callGeneric()
})

#' @importFrom DelayedArray seed
#' @export
#' @rdname showtree
methods::setMethod("seed", "BPCellsMatrix", function(x) {
seed(entity(x))
x <- x@seed
methods::callGeneric()
})

#' @importFrom DelayedArray path
#' @export
#' @rdname showtree
methods::setMethod("path", "BPCellsMatrix", function(object, ...) {
path(entity(object), ...)
object <- object@seed
methods::callGeneric()
})

#' @importFrom DelayedArray seed<-
Expand Down Expand Up @@ -144,11 +147,11 @@ methods::setMethod("path", "BPCellsHDF5Seed", function(object, ...) object@path)

#' @export
#' @rdname showtree
methods::setMethod("seed", "BPCellsSeed", function(x) x)
methods::setMethod("seed", "BPCellsBasicSeed", function(x) x)

#' @export
#' @rdname showtree
methods::setMethod("nseed", "BPCellsSeed", function(x) 1L)
methods::setMethod("nseed", "BPCellsBasicSeed", function(x) 1L)

# Five DelayedUnaryOp-like seeds ------------------------------------
###########################################################
Expand Down Expand Up @@ -201,20 +204,34 @@ methods::setMethod("nseed", "BPCellsNaryOpsSeed", function(x) {

# Don't use this, we directly use `seed` function to return all seeds
# this is different with what the DelayedArray does.
new_seedApply <- function(x, .fn, ...) {
if (methods::is(x, "BPCellsMatrix")) {
x <- entity(x)
methods::setGeneric("new_seedApply",
signature = "x", function(x, .fn, ...) {
standardGeneric("new_seedApply")
}
if (methods::is(x, "BPCellsUnaryOpsSeed")) {
return(Recall(entity(x), .fn, ...))
}
if (methods::is(x, "BPCellsNaryOpsSeed")) {
)

methods::setMethod("new_seedApply", "BPCellsMatrix", function(x, .fn, ...) {
x <- x@seed
methods::callGeneric()
})

methods::setMethod(
"new_seedApply", "BPCellsUnaryOpsSeed",
function(x, .fn, ...) {
x <- entity(x)
methods::callGeneric()
}
if (is.list(x)) {
)

methods::setMethod(
"new_seedApply", "BPCellsNaryOpsSeed",
function(x, .fn, ...) {
x <- entity(x)
ans <- lapply(x, FUN = new_seedApply, .fn = .fn, ...)
return(unlist(ans, recursive = FALSE, use.names = FALSE))
} else {
list(.fn(x, ...))
unlist(ans, recursive = FALSE, use.names = FALSE)
}
}
)

methods::setMethod("new_seedApply", "BPCellsBasicSeed", function(x, .fn, ...) {
list(.fn(x, ...))
})

0 comments on commit 6867ad2

Please sign in to comment.