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 NA NA
#> [2,] NA NA NA
#> [3,] NA NA FALSE
#> [4,] FALSE FALSE FALSE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE FALSE
#> [2,] NA NA NA
#> [3,] NA NA FALSE
#> [4,] FALSE FALSE FALSE
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE NA NA
#> [2,] NA NA NA
#> [3,] NA NA TRUE
#> [4,] TRUE TRUE TRUE
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] NA NA NA
#> [3,] NA NA TRUE
#> [4,] TRUE TRUE TRUE
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] -0.8490541-2.191478i NaN+ Infi NaN-2.3208460i
#> [2,] NaN- Infi NaN- Infi NaN- Infi
#> [3,] NA NaN+ NaNi 1.166479-0.6813679i
#> [4,] -2.2194535+1.050041i -1.815285+0.8296856i -1.987219-0.1415991i
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] -1.0934749-1.585174i -1.722631-1.556154i 0.001706027-2.0049222i
#> [2,] NaN- Infi NaN- Infi NaN- Infi
#> [3,] NA NaN- Infi -0.406805486-0.7606248i
#> [4,] -0.1775023+1.216124i -3.716810+1.582522i -0.907264434+0.3989423i
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] FALSE NA NA FALSE FALSE NA FALSE FALSE FALSE NA FALSE FALSE
#> [13] FALSE NA FALSE NA NA NA FALSE NA NA FALSE NA FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] NA NA TRUE NA TRUE TRUE NA TRUE TRUE TRUE NA TRUE NA NA TRUE
#> [16] TRUE TRUE 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,] -2.51385174+0.33392842i 0.78713840+0.99580452i -2.3112767-2.240457040i
#> [2,] NaN+ Infi -0.62214110-0.19336901i NA
#> [3,] -0.42784726-1.04140407i -1.36361783+0.59823023i 1.2064195+1.164125993i
#> [4,] -0.76092961-0.19840475i NaN+ Infi NA
#> [5,] 0.17143929-0.02242093i 0.74654846+0.77033508i 0.1452594+0.115327385i
#> [6,] 0.05592646-0.16531839i -Inf-1.32381118i -Inf+ Infi
#> [7,] NA -0.80417844-0.17003764i NA
#> [8,] -1.18358274+0.45702197i -0.84264894+0.30874126i 0.8562432-0.750529900i
#> [9,] -1.20033434-1.11584240i NaN- Infi NA
#> [10,] Inf-0.70329076i 0.06300281+0.94433456i Inf+ Infi
#> [11,] NaN+0.81292124i 0.27365729-1.76662286i NA
#> [12,] 0.52857483+1.04602704i 0.18712400-1.03300622i 1.1794615-0.350284322i
#> [13,] -1.91119006+1.23692720i NaN+ NaNi NA
#> [14,] -1.00320454+0.50859968i -0.40533089-0.20950128i 0.5131821+0.004021475i
#> [15,] 0.34503458+0.51726622i 1.58421109-0.58443507i 0.8489161+0.617808563i
#> [16,] 0.50112505-0.06088066i -1.15681171+0.44584230i -0.5525642+0.293850202i
#> [17,] 2.08810919+1.82726665i -1.57944609+0.35076648i -3.9389998-2.153630456i
#> [18,] NaN- Infi -0.42165222-0.40665453i NA
#> [19,] -1.05559027+1.08486226i -0.12160329+0.31706285i -0.2156063-0.466611282i
#> [20,] NaN+ NaNi -1.25922267+0.53712680i NA
#> [21,] -Inf+1.73934970i 0.33629825-1.12293937i -Inf+ Infi
#> [22,] -0.82407850-0.91362281i 2.16239588+0.02577359i -1.7584366-1.996853662i
#> [23,] -1.83095679-0.45746185i NA NA
#> [24,] -1.61019441+0.28474197i NaN+0.65137042i NA
#> out
#> [1,] -2.3112767-2.240457040i
#> [2,] NA
#> [3,] 1.2064195+1.164125993i
#> [4,] NA
#> [5,] 0.1452594+0.115327385i
#> [6,] -Inf+ Infi
#> [7,] NA
#> [8,] 0.8562432-0.750529900i
#> [9,] NA
#> [10,] Inf+ Infi
#> [11,] NA
#> [12,] 1.1794615-0.350284322i
#> [13,] NA
#> [14,] 0.5131821+0.004021475i
#> [15,] 0.8489161+0.617808563i
#> [16,] -0.5525642+0.293850202i
#> [17,] -3.9389998-2.153630456i
#> [18,] NA
#> [19,] -0.2156063-0.466611282i
#> [20,] NA
#> [21,] -Inf+ Infi
#> [22,] -1.7584366-1.996853662i
#> [23,] NA
#> [24,] 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.