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,] FALSE FALSE FALSE
#> [2,] NA NA NA
#> [3,] FALSE NA FALSE
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA FALSE FALSE
#> [2,] NA NA NA
#> [3,] FALSE FALSE FALSE
#> [4,] FALSE FALSE NA
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] NA NA NA
#> [3,] TRUE NA TRUE
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA TRUE TRUE
#> [2,] NA NA NA
#> [3,] TRUE TRUE TRUE
#> [4,] TRUE TRUE NA
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 2.0408621+1.8191024i 2.715173+0.05500153i 2.180423+0.4025967i
#> [2,] NaN- Infi NaN- Infi NA
#> [3,] 0.2816933-0.5669337i NaN- Infi -Inf+0.1792602i
#> [4,] 3.3370955-0.7808263i 3.210514-0.18309753i Inf-0.7318754i
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NaN+ Infi 0.7740078+0.45361228i 2.594544+1.4508609i
#> [2,] NaN- Infi NaN- Infi NaN+ NaNi
#> [3,] -0.5350672+0.09485116i -0.9031504+0.50091062i 1.226096-0.7011346i
#> [4,] 4.1439388-0.64391993i 2.0185839+0.09167376i NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE NA NA
#> [13] FALSE FALSE NA FALSE NA NA NA FALSE FALSE NA NA NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] TRUE NA TRUE TRUE TRUE NA TRUE NA NA TRUE NA TRUE NA NA NA
#> [16] TRUE TRUE TRUE TRUE TRUE NA TRUE NA TRUE
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 x*y
#> [1,] 1.8302949-0.73951387i -0.1899603-0.8367107i -0.96644242-1.39094898i
#> [2,] -0.9136331+0.01849284i -0.3952930+1.8345041i 0.32722759-1.68337377i
#> [3,] -1.8080843-0.58576861i 0.3860938-0.4719634i -0.97455147+0.62718811i
#> [4,] -0.8687589-0.07441813i 0.1883878-1.3206391i -0.26194307+1.13329752i
#> [5,] -0.2404875-0.06101244i -0.5539646-0.9772986i 0.07359421+0.26882686i
#> [6,] NA 0.4452131-0.7698438i NA
#> [7,] -1.8857071-1.28104477i NaN+1.4325067i NA
#> [8,] NaN- Infi 0.1112337-0.9707394i NA
#> [9,] -Inf+0.81796819i NaN+ NaNi NA
#> [10,] 0.1280914+0.06164320i -1.1931209-0.2278787i -0.13878140-0.10273710i
#> [11,] NaN+ NaNi 0.6051733-0.4917523i NA
#> [12,] -1.3305869+0.86869688i 0.1969603-1.5208757i 1.05910720+2.19475606i
#> [13,] -1.1872601+0.30550302i -0.9791813+2.1488859i 0.50605183-2.85042943i
#> [14,] 1.6788816+0.67127638i -Inf+0.7380816i -Inf- Infi
#> [15,] 0.4656628-0.24912632i -0.5182833+0.8332749i -0.03375453+0.51714313i
#> [16,] -0.5087432+0.07028198i NaN- Infi NA
#> [17,] NaN-0.20323439i 0.2725502+1.3890502i NA
#> [18,] NaN+ Infi -1.8344568+0.3116692i NA
#> [19,] -1.8545954-0.19702638i NaN+ Infi NA
#> [20,] -0.6340956-1.34874333i NA NA
#> [21,] 0.8770446-0.69001972i 2.4782086-0.9368964i 1.52702247-2.53171274i
#> [22,] 1.0915938-0.55580729i 1.6104730+0.7702768i 2.18610772-0.05428327i
#> [23,] Inf-0.63558222i NA NA
#> [24,] -1.5315631-0.96666698i 1.3134334-0.2565405i -2.25959536-0.87674475i
#> out
#> [1,] -0.96644242-1.39094898i
#> [2,] 0.32722759-1.68337377i
#> [3,] -0.97455147+0.62718811i
#> [4,] -0.26194307+1.13329752i
#> [5,] 0.07359421+0.26882686i
#> [6,] NA
#> [7,] NA
#> [8,] NA
#> [9,] NA
#> [10,] -0.13878140-0.10273710i
#> [11,] NA
#> [12,] 1.05910720+2.19475606i
#> [13,] 0.50605183-2.85042943i
#> [14,] -Inf- Infi
#> [15,] -0.03375453+0.51714313i
#> [16,] NA
#> [17,] NA
#> [18,] NA
#> [19,] NA
#> [20,] NA
#> [21,] 1.52702247-2.53171274i
#> [22,] 2.18610772-0.05428327i
#> [23,] NA
#> [24,] -2.25959536-0.87674475i
#> 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.