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,] FALSE FALSE NA
#> [3,] NA NA NA
#> [4,] NA FALSE NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA NA FALSE
#> [2,] FALSE NA FALSE
#> [3,] NA NA NA
#> [4,] FALSE FALSE FALSE
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] TRUE TRUE NA
#> [3,] NA NA NA
#> [4,] NA TRUE NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA NA TRUE
#> [2,] TRUE NA TRUE
#> [3,] NA NA NA
#> [4,] TRUE TRUE TRUE
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0.4089259+0.5615059i Inf+1.536285i 1.233677+0.4181375i
#> [2,] 0.0792841-0.8069784i 1.907329-0.271761i NaN+ Infi
#> [3,] NA NA NA
#> [4,] NA -1.125494-1.895148i NaN- Infi
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NaN+0.6277156i NaN+ NaNi -0.5364090+0.3134199i
#> [2,] 0.4594311-0.2323119i NA -0.3642354-0.8131676i
#> [3,] NA NA NA
#> [4,] -2.3014982-0.2474557i -1.251299-2.028717i -0.3503391-0.8578807i
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] NA FALSE NA FALSE FALSE NA FALSE FALSE FALSE NA FALSE NA
#> [13] FALSE NA FALSE FALSE NA NA NA FALSE NA FALSE FALSE FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE NA NA TRUE TRUE TRUE TRUE NA NA
#> [16] NA NA TRUE NA TRUE NA NA 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,] 0.7859212+0.92324109i NA NA
#> [2,] -Inf+0.72578316i -1.20869689-1.30394621i Inf+ Infi
#> [3,] NaN- Infi 0.21415427-0.18822957i NA
#> [4,] 0.4866233-0.47223224i 1.06773993+0.53464711i 0.77206469-0.24404950i
#> [5,] 2.1107003-0.29681828i NaN-0.30428955i NA
#> [6,] NA NA NA
#> [7,] NA -Inf-1.29174689i NA
#> [8,] -1.1475830+1.50967606i 1.69279438+0.55250232i -2.77672155+1.92152889i
#> [9,] NaN+0.12149118i 0.88345938+1.46137605i NA
#> [10,] -1.5230441-0.16914339i -0.38023657-0.27166471i 0.53316676+0.47807183i
#> [11,] NaN+ NaNi -0.70429337+0.62851924i NA
#> [12,] 0.5826036-0.95681557i 0.54628564+0.04143551i 0.35791412-0.49855413i
#> [13,] NaN+ Infi NaN+ NaNi NA
#> [14,] -0.2794623+0.08750695i -0.09348523+3.14064083i -0.24870230-0.88587138i
#> [15,] -1.4092575-0.62104066i 2.18088072+1.41954304i -2.19182863-3.35491731i
#> [16,] -0.3087136-2.34774190i NaN+ Infi NA
#> [17,] -0.6791788+0.64872504i NaN- Infi NA
#> [18,] Inf+0.67948120i -0.46539518-1.60806716i -Inf- Infi
#> [19,] 0.1185621+0.10899563i -0.43697320+0.18288999i -0.07174269-0.02594434i
#> [20,] 0.5076277+0.49638414i -1.34433973+0.82756632i -1.09321487-0.24721334i
#> [21,] -1.3416316-0.18203993i 0.63968418-1.43571427i -1.11957782+1.80975155i
#> [22,] -0.7965291-0.31736700i 0.11488538+0.81538541i 0.16726687-0.68593903i
#> [23,] -0.2079114-0.95911547i 0.62067691-0.83139662i -0.92645115-0.42244401i
#> [24,] -0.5604326+1.43102661i 1.03654660+0.83886495i -1.78135260+1.01319848i
#> out
#> [1,] NA
#> [2,] Inf+ Infi
#> [3,] NA
#> [4,] 0.77206469-0.24404950i
#> [5,] NA
#> [6,] NA
#> [7,] NA
#> [8,] -2.77672155+1.92152889i
#> [9,] NA
#> [10,] 0.53316676+0.47807183i
#> [11,] NA
#> [12,] 0.35791412-0.49855413i
#> [13,] NA
#> [14,] -0.24870230-0.88587138i
#> [15,] -2.19182863-3.35491731i
#> [16,] NA
#> [17,] NA
#> [18,] -Inf- Infi
#> [19,] -0.07174269-0.02594434i
#> [20,] -1.09321487-0.24721334i
#> [21,] -1.11957782+1.80975155i
#> [22,] 0.16726687-0.68593903i
#> [23,] -0.92645115-0.42244401i
#> [24,] -1.78135260+1.01319848i
#> 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.