library("broadcast")
x.dim <- c(4:2)
x.len <- prod(x.dim)
gen <- function() sample(c(rnorm(20), NA, NaN, Inf, -Inf))
x <- array(gen() + gen() * -1i, x.dim)
y <- array(gen() + gen() * -1i, c(4,1,1))
bc.cplx(x, y, "==")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#> [2,] FALSE FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#> [2,] FALSE FALSE NA
#> [3,] NA NA FALSE
#> [4,] FALSE FALSE FALSE
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#> [2,] TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA NA NA
#> [2,] TRUE TRUE NA
#> [3,] NA NA TRUE
#> [4,] TRUE TRUE TRUE
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] NaN+ NaNi NaN+ Infi NaN+ Infi
#> [2,] -2.2365687+0.1961816i -1.7208194+1.2487175i 0.9675972-1.3362241i
#> [3,] -0.6087265-2.0163031i -1.2597202-2.6791579i 1.9790077-0.9752097i
#> [4,] Inf+0.1328738i -0.1345944+0.2730959i NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NaN+ Infi NaN+ Infi NaN+ Infi
#> [2,] 1.738211+1.5645189i -0.5065945+0.2925575i NaN+1.6977581i
#> [3,] NA NaN- Infi -Inf+0.0733964i
#> [4,] -1.410217+0.4074887i 0.1988667+0.4068313i 0.9257624+0.1651630i
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] FALSE NA NA FALSE FALSE FALSE NA NA FALSE FALSE NA NA
#> [13] FALSE NA FALSE FALSE FALSE FALSE FALSE NA FALSE FALSE NA FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] TRUE TRUE TRUE TRUE NA NA NA NA NA NA NA NA NA TRUE TRUE
#> [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE NA
x <- array(gen() + gen() * -1i)
y <- array(gen() + gen() * -1i)
bcr(x) <- bcr(y) <- TRUE
out <- x * y
bind_array(list(x = x, y = y, `x*y` = x*y, out = out), 2L)
#> x y
#> [1,] -0.546300440+0.094438684i NaN+ Infi
#> [2,] 1.116403607+1.602367497i 0.96520397+0.018854534i
#> [3,] 1.024595061+1.724531098i 0.03395946+1.137438164i
#> [4,] -Inf-1.296901767i -Inf+1.069272337i
#> [5,] 1.053912326-0.006317397i -0.43200991+0.403661091i
#> [6,] NaN- Infi NA
#> [7,] -0.323553150-1.584686331i NaN- Infi
#> [8,] NaN+ Infi 1.29686106+0.048182859i
#> [9,] NaN+ NaNi 1.28639801-0.288332038i
#> [10,] 0.998150948-0.492194497i -0.97414964+0.125682778i
#> [11,] -1.169740443+0.513577092i 0.99896018-0.610052588i
#> [12,] 2.151490355-0.198219809i NaN+ NaNi
#> [13,] Inf+0.796445459i -0.58032496-0.739387215i
#> [14,] NaN+0.252555091i 0.93174342-0.065977560i
#> [15,] 1.865056415+0.326945910i -0.03358181+1.483630580i
#> [16,] -0.858689577+0.012167450i 0.60378791+1.104497704i
#> [17,] NA Inf-0.418571026i
#> [18,] -0.980605681-1.693245551i -2.33882319+0.049467255i
#> [19,] NA 2.11815687-0.371055575i
#> [20,] 0.457086453-2.113690250i -0.65911914+0.487262894i
#> [21,] 2.636480739-0.771712027i NaN-0.160348368i
#> [22,] -0.001839698+0.468610725i 0.60233661+0.008455011i
#> [23,] -0.020937606+0.736118648i -1.32346372+0.429330621i
#> [24,] -0.196945990+0.454667206i NA
#> x*y out
#> [1,] NA NA
#> [2,] 1.047345299+1.5676607i 1.047345299+1.5676607i
#> [3,] -1.926752791+1.2239777i -1.926752791+1.2239777i
#> [4,] Inf+ NaNi Inf+ NaNi
#> [5,] -0.452750486+0.4281526i -0.452750486+0.4281526i
#> [6,] NA NA
#> [7,] NA NA
#> [8,] NA NA
#> [9,] NA NA
#> [10,] -0.910488014+0.6049215i -0.910488014+0.6049215i
#> [11,] -0.855215084+1.2266462i -0.855215084+1.2266462i
#> [12,] NA NA
#> [13,] -Inf- Infi -Inf- Infi
#> [14,] NA NA
#> [15,] -0.547698925+2.7560753i -0.547698925+2.7560753i
#> [16,] -0.531905306-0.9410741i -0.531905306-0.9410741i
#> [17,] NA NA
#> [18,] 2.377223516+3.9116941i 2.377223516+3.9116941i
#> [19,] NA NA
#> [20,] 0.728648396+1.6158950i 0.728648396+1.6158950i
#> [21,] NA NA
#> [22,] -0.005070226+0.2822458i -0.005070226+0.2822458i
#> [23,] -0.288328115-0.9832155i -0.288328115-0.9832155i
#> [24,] NA NA
#> broadcasterbc.cplx
Broadcasted Complex Numeric Operations
Description
The bc.cplx() method performs broadcasted complex numeric operations on pairs of arrays.
Usage
bc.cplx(x, y, op, ...)
## S4 method for signature 'ANY'
bc.cplx(x, y, op)
Arguments
x, y
|
conformable vectors/arrays of type complex.
|
op
|
a single string, giving the operator. Supported arithmetic operators: +, -, *, /. Supported relational operators: ==, !=. |
β¦
|
further arguments passed to or from methods. |
Details
For the * and / operators, bc.cplx() uses more strict NA checks than base βRβ:
If for an iteration, re(x), im(x), re(y), and/or im(y) contains NA, than the result for that iteration is necessarily NA_complex_.
Value
For arithmetic operators:
A complex array as a result of the broadcasted arithmetic operation.
For relational operators:
A logical array as a result of the broadcasted relational comparison.