Skip to content

Commit

Permalink
export methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Feb 26, 2024
1 parent d789dd0 commit 6d99b18
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 14 deletions.
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ exportMethods(colSums)
exportMethods(colVars)
exportMethods(convert_mode)
exportMethods(crossprod)
exportMethods(dim)
exportMethods(dimnames)
exportMethods(expm1)
exportMethods(expm1_slow)
exportMethods(extract_array)
exportMethods(extract_sparse_array)
exportMethods(is_noop)
exportMethods(is_sparse)
exportMethods(log1p)
exportMethods(log1p_single)
exportMethods(mask_matrix)
Expand Down Expand Up @@ -166,6 +170,5 @@ importMethodsFrom(BPCells,t)
importMethodsFrom(DelayedArray,OLD_extract_sparse_array)
importMethodsFrom(DelayedArray,dim)
importMethodsFrom(DelayedArray,dimnames)
importMethodsFrom(DelayedArray,drop)
importMethodsFrom(DelayedArray,extract_array)
importMethodsFrom(DelayedArray,is_sparse)
15 changes: 8 additions & 7 deletions R/Class-BPCellsMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,18 @@ array_call_DelayedArray_method <- function(..., Array = "object", type = "S4") {

# hepler function to call BPCells method for `BPCellsArray`
# running order
# (before - delayed - to_BPCells) - method - (body - DelayedArray - after)
# 1. before - extract seed_form - to_BPCells
# 2. method
# 3. body - DelayedArray - after
#' @include utils.R
array_call_BPCells_method <- function(..., before = NULL, method = NULL, body = NULL, after = NULL, Arrays = "object") {
method <- method %||% quote(methods::callGeneric())
Arrays <- rlang::syms(Arrays)
# extract whether should be delayed, always respect the first Array
seed_form <- substitute(seed_form <- Array@SeedForm, list(Array = Arrays[[1L]]))
# extract seed_form, always respect the first Array
seed_form <- substitute(
seed_form <- Array@SeedForm,
list(Array = Arrays[[1L]])
)
before <- c(
before, list(seed_form),
# transform all Arrays into BPCells object
Expand Down Expand Up @@ -210,10 +215,6 @@ methods::setAs("BPCellsMatrix", "dgCMatrix", function(from) {
})

# Default drop use `as.array` and `aperm` methods
#' @importMethodsFrom DelayedArray drop
#' @noRd
NULL

### S3/S4 combo for aperm.BPCellsMatrix
# list_methods("DelayedAperm")
aperm.BPCellsMatrix <- array_call_DelayedArray_method(
Expand Down
4 changes: 3 additions & 1 deletion R/Class-BPCellsSeed.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Seed Contract methods for `IterableMatrix`
#'
#' @param x A `IterableMatrix` object.
#' @param x A `IterableMatrix` or `BPCellsDelayedOp` object.
#' @include utils-BPCells.R
#' @aliases IterableMatrix
#' @name BPCellsSeed-class
Expand Down Expand Up @@ -108,6 +108,8 @@ methods::setMethod(
}
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "IterableMatrix", function(x) TRUE)

#' @return
Expand Down
11 changes: 11 additions & 0 deletions R/Class-BindMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,33 @@ mould_BPCells("BPCellsDelayedAbind", "ColBindMatrices",
### list_methods("DelayedAbind")
### Seed contract
### here: we override the `DelayedAbind` methods
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dim", "BPCellsDelayedAbind",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedAbind",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsDelayedAbind", function(x) TRUE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_array", "BPCellsDelayedAbind",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"OLD_extract_sparse_array", "BPCellsDelayedAbind",
delayedop_call_BPCells_method(x = , index = , Array = "x")
Expand Down
47 changes: 47 additions & 0 deletions R/Class-Delayed.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ methods::setGeneric("to_BPCells", function(object, ...) {

methods::setMethod("to_BPCells", "IterableMatrix", function(object) object)

#' @importClassesFrom DelayedArray DelayedOp
methods::setMethod("to_BPCells", "DelayedOp", function(object) {
cli::cli_abort(
"You cannot mix {.pkg BPCells} method with {.pkg DelayedArray} method"
Expand Down Expand Up @@ -94,30 +95,48 @@ methods::setMethod(
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsDelayedOp", function(x) TRUE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_array", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"OLD_extract_sparse_array", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_sparse_array", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dim", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @importMethodsFrom BPCells t
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"t", "BPCellsDelayedOp",
delayedop_call_BPCells_method(
Expand All @@ -126,6 +145,10 @@ methods::setMethod(
Array = "x"
)
)

#' @importFrom DelayedArray chunkdim
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"chunkdim", "BPCellsDelayedOp",
delayedop_call_BPCells_method(x = , Array = "x")
Expand All @@ -149,6 +172,8 @@ methods::setMethod(

### list_methods("DelayedUnaryOp")
### Seed contract
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"chunkdim", "BPCellsDelayedUnaryOp",
delayedop_call_BPCells_method(x = , Array = "x")
Expand All @@ -163,22 +188,33 @@ methods::setClass("BPCellsDelayedUnaryIsoOp",
### list_methods("DelayedUnaryIsoOp")
### Seed contract
### here: we override the `DelayedNaryIsoOp` methods
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dim", "BPCellsDelayedUnaryIsoOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedUnaryIsoOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsDelayedUnaryIsoOp", function(x) TRUE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_array", "BPCellsDelayedUnaryIsoOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"OLD_extract_sparse_array", "BPCellsDelayedUnaryIsoOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
Expand All @@ -201,22 +237,33 @@ methods::setClass("BPCellsDelayedNaryIsoOp",
### list_methods("DelayedNaryIsoOp")
### Seed contract
### here: we override the `DelayedNaryIsoOp` methods
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dim", "BPCellsDelayedNaryIsoOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedNaryIsoOp",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsDelayedNaryIsoOp", function(x) TRUE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_array", "BPCellsDelayedNaryIsoOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"OLD_extract_sparse_array", "BPCellsDelayedNaryIsoOp",
delayedop_call_BPCells_method(x = , index = , Array = "x")
Expand Down
4 changes: 4 additions & 0 deletions R/Class-RenameDims.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ mould_BPCells("BPCellsDelayedRenameDims", "RenameDims",
### Seed contract
### here: we override the `DelayedSetDimnames` methods
#' @importFrom DelayedArray is_noop
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_noop", "BPCellsDelayedRenameDims", function(x) FALSE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedRenameDims",
delayedop_call_BPCells_method(x = , Array = "x")
Expand Down
15 changes: 15 additions & 0 deletions R/Class-Subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,44 @@ mould_BPCells("BPCellsDelayedSubset", "MatrixSubset",
### list_methods("DelayedSubset")
### Seed contract
### here: we override the `DelayedSubset` methods
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dim", "BPCellsDelayedSubset",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"dimnames", "BPCellsDelayedSubset",
delayedop_call_BPCells_method(x = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsDelayedSubset", function(x) TRUE)
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_array", "BPCellsDelayedSubset",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"OLD_extract_sparse_array", "BPCellsDelayedSubset",
delayedop_call_BPCells_method(x = , index = , Array = "x")
)

#' @importFrom DelayedArray is_noop
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_noop", "BPCellsDelayedSubset", function(x) FALSE)

#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"chunkdim", "BPCellsDelayedSubset",
delayedop_call_BPCells_method(x = , Array = "x")
Expand Down
Loading

0 comments on commit 6d99b18

Please sign in to comment.