File: SparseArray-Complex-methods.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 (40 lines) | stat: -rw-r--r-- 1,449 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
### =========================================================================
### 'Complex' methods for SparseArray objects
### -------------------------------------------------------------------------
###
### The 'Complex' group consists of the following methods:
###   Re, Im, Mod, Arg, Conj
###
### See '?S4groupGeneric' for more information.
###
### The corresponding base functions all accept an array of type "complex",
### "double", or "integer", and they all return an array of same dimensions
### as the input array.
### Re(), Im(), Mod(), Arg() return an array of type "double" (whatever
### the type of the input array).
### Conj() returns an array of type "complex" if the input array is of type
### "complex', and an array of type "double" otherwise.
### 


.SVT_SparseArray_Complex <- function(op, z)
{
    stopifnot(isSingleString(op), is(z, "SVT_SparseArray"))
    check_svt_version(z)

    if (type(z) != "complex")
        stop(wmsg("the ", op, "() method for SVT_SparseArray objects ",
                  "only supports input of type \"complex\" at the moment"))

    ## Returns 'ans_type' and 'ans_SVT' in a list of length 2.
    C_ans <- SparseArray.Call("C_Complex_SVT", z@dim, z@type, z@SVT, op)
    ans_type <- C_ans[[1L]]
    ans_SVT <- C_ans[[2L]]

    new_SVT_SparseArray(z@dim, z@dimnames, ans_type, ans_SVT, check=FALSE)
}

setMethod("Complex", "SVT_SparseArray",
    function(z) .SVT_SparseArray_Complex(.Generic, z)
)