File: is_sparse.R

package info (click to toggle)
r-bioc-s4arrays 1.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: ansic: 730; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
### =========================================================================
### The is_sparse() and `is_sparse<-`() generics
### -------------------------------------------------------------------------
###

### IMPORTANT: Array-like objects for which is_sparse() is TRUE **must**
### support SparseArray::extract_sparse_array(). More about this in the
### extract_sparse_array.R file from the SparseArray package where the
### extract_sparse_array() generic is defined.

setGeneric("is_sparse", function(x) standardGeneric("is_sparse"))

### By default, nothing is considered sparse.
setMethod("is_sparse", "ANY", function(x) FALSE)

### All [C|R|T]sparseMatrix derivatives are considered sparse. Note that
### they all support SparseArray::extract_sparse_array() via the default
### extract_sparse_array() method defined in the SparseArray package.
setMethod("is_sparse", "CsparseMatrix", function(x) TRUE)
setMethod("is_sparse", "RsparseMatrix", function(x) TRUE)
setMethod("is_sparse", "TsparseMatrix", function(x) TRUE)


setGeneric("is_sparse<-", signature="x",
    function(x, value) standardGeneric("is_sparse<-")
)