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 NA
#> [2,] NA FALSE NA
#> [3,] NA NA NA
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] FALSE NA FALSE
#> [3,] NA NA NA
#> [4,] FALSE NA FALSE
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE NA
#> [2,] NA TRUE NA
#> [3,] NA NA NA
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE NA TRUE
#> [3,] NA NA NA
#> [4,] TRUE NA TRUE
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 1.353636+2.1346101i -0.04923198+1.6968053i NaN- Infi
#> [2,] NA 0.70674120+2.2539785i NaN+ NaNi
#> [3,] NaN- Infi NaN- Infi NaN- Infi
#> [4,] 0.596745+0.1592034i -1.63007288+0.4237369i -0.3394879-1.143304i
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 0.3352347+1.868045i -1.294715+0.822431i 0.7369759-0.5186201i
#> [2,] -0.6791349-1.721487i NaN+ Infi Inf-1.0074307i
#> [3,] NaN- Infi NaN- Infi NaN- Infi
#> [4,] 1.1448487+2.026379i NaN+1.523809i 1.5709982+0.2484444i
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] FALSE NA NA FALSE FALSE FALSE NA FALSE FALSE NA NA NA
#> [13] FALSE NA FALSE FALSE FALSE FALSE FALSE FALSE NA NA FALSE FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] NA NA NA TRUE TRUE TRUE TRUE TRUE TRUE TRUE NA NA NA TRUE NA
#> [16] NA NA 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.39829786-0.13175245i 0.5972126-0.95910156i -0.961445102+1.26242544i
#> [2,] -0.71017699-0.16418151i 1.4216172+0.71159061i -0.892769790-0.73875854i
#> [3,] NA -0.6213853+0.88754582i NA
#> [4,] Inf-1.31416682i 1.0686443-1.28008048i Inf- Infi
#> [5,] -2.50257584-0.51379953i 0.9948363-2.00759377i -3.521154055+4.51300923i
#> [6,] -Inf+0.26298665i -1.4066442-0.13868889i Inf+ Infi
#> [7,] -0.23966433+2.01960785i NaN+ NaNi NA
#> [8,] 0.04489947+0.69256219i -Inf-0.54389646i -Inf- Infi
#> [9,] NaN+0.49518515i NaN- Infi NA
#> [10,] -1.00414034+0.09446917i -0.6400728+1.13571979i 0.535432397-1.20088920i
#> [11,] 0.48794550-2.55535853i 0.9656344+1.06003185i 3.179938388-1.95030428i
#> [12,] -0.34991841-0.57807123i -0.4329605-0.99915341i -0.426080995+0.59990417i
#> [13,] -0.70524491+0.59478143i -0.1299652-0.04631316i 0.119203525-0.04463878i
#> [14,] -0.11676925-1.13265234i -0.2693644+1.62384935i 1.870710247+0.11548057i
#> [15,] 1.07674410+0.97540861i -1.9481898+1.11020803i -3.180608361-0.70487117i
#> [16,] 0.62394243+0.71153529i Inf+0.34989975i Inf+ Infi
#> [17,] NaN- Infi 0.1870965+0.87975936i NA
#> [18,] -1.69797360-0.56372683i NaN+ Infi NA
#> [19,] NaN+ NaNi NA NA
#> [20,] -0.37909182-0.65486387i NaN+0.23597314i NA
#> [21,] NaN+ Infi 0.1094576+0.11771425i NA
#> [22,] NA 1.5752780+0.10262693i NA
#> [23,] -0.14513983-1.25951337i -0.2426105+0.04478692i 0.091622162+0.29907078i
#> [24,] -0.13636000-0.41722584i -0.4248554-0.15867108i -0.008268393+0.19889704i
#> out
#> [1,] -0.961445102+1.26242544i
#> [2,] -0.892769790-0.73875854i
#> [3,] NA
#> [4,] Inf- Infi
#> [5,] -3.521154055+4.51300923i
#> [6,] Inf+ Infi
#> [7,] NA
#> [8,] -Inf- Infi
#> [9,] NA
#> [10,] 0.535432397-1.20088920i
#> [11,] 3.179938388-1.95030428i
#> [12,] -0.426080995+0.59990417i
#> [13,] 0.119203525-0.04463878i
#> [14,] 1.870710247+0.11548057i
#> [15,] -3.180608361-0.70487117i
#> [16,] Inf+ Infi
#> [17,] NA
#> [18,] NA
#> [19,] NA
#> [20,] NA
#> [21,] NA
#> [22,] NA
#> [23,] 0.091622162+0.29907078i
#> [24,] -0.008268393+0.19889704i
#> 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. Numeric and logical arrays will be coerced to 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.