File: NaArray-aperm.R

package info (click to toggle)
r-bioc-sparsearray 1.6.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,768 kB
  • sloc: ansic: 16,138; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,590 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
### =========================================================================
### Transposition of an NaArray object
### -------------------------------------------------------------------------
###


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Transposition
###

### S3/S4 combo for t.NaMatrix
t.NaMatrix <- function(x)
{
    check_svt_version(x)
    new_NaSVT <- SparseArray.Call("C_transpose_2D_SVT", x@dim, x@type, x@NaSVT)
    BiocGenerics:::replaceSlots(x, dim=rev(x@dim),
                                   dimnames=rev(x@dimnames),
                                   NaSVT=new_NaSVT,
                                   check=FALSE)
}
setMethod("t", "NaMatrix", t.NaMatrix)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### aperm()
###
### Supports S4Arrays::aperm2() extended semantic.
###

.aperm_NaSVT <- function(a, perm, .NAME=c("C_aperm_SVT", "C_aperm0_SVT"))
{
    stopifnot(is(a, "NaArray"))
    check_svt_version(a)

    .NAME <- match.arg(.NAME)

    aperm0_NaSVT <- function(x, perm) {
        new_NaSVT <- SparseArray.Call(.NAME, x@dim, x@type, x@NaSVT, perm)
        BiocGenerics:::replaceSlots(x, dim=x@dim[perm],
                                       dimnames=x@dimnames[perm],
                                       NaSVT=new_NaSVT,
                                       check=FALSE)
    }
    S4Arrays:::extended_aperm(a, perm, aperm0_NaSVT)
}

### S3/S4 combo for aperm.NaArray
aperm.NaArray <- function(a, perm, ...) .aperm_NaSVT(a, perm, ...)
setMethod("aperm", "NaArray", aperm.NaArray)