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,] NA FALSE NA
#> [4,] NA NA NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] FALSE FALSE NA
#> [2,] NA NA NA
#> [3,] FALSE FALSE FALSE
#> [4,] NA NA NA
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] NA NA NA
#> [3,] NA TRUE NA
#> [4,] NA NA NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE NA
#> [2,] NA NA NA
#> [3,] TRUE TRUE TRUE
#> [4,] NA NA NA
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0.3664669-0.1258509i 2.670481-0.136057i 0.9324911+0.1942748i
#> [2,] NaN- Infi NaN- Infi NaN- Infi
#> [3,] NaN+ Infi 1.074822+1.613478i NaN+ NaNi
#> [4,] NaN- Infi NA NaN-0.7934125i
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 0.8676454+0.5684837i 0.06008942-0.4873169i NA
#> [2,] NaN- Infi NaN- Infi NaN- Infi
#> [3,] 1.4960575+0.2485741i 2.11379225-0.2396001i 0.04697117+1.060300i
#> [4,] NaN-0.8756615i NaN-0.3781628i NaN-1.268878i
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] NA NA NA NA NA FALSE NA NA FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE NA NA NA NA FALSE FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] TRUE TRUE NA TRUE TRUE NA NA NA NA TRUE TRUE NA TRUE TRUE NA
#> [16] TRUE NA TRUE TRUE TRUE TRUE NA TRUE 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.137263162+0.04752972i -0.98813747+0.7513142i 1.0880626-0.9014079i
#> [2,] -1.501906095+0.51572200i 1.09996085+1.1614630i -2.2510299-1.1771343i
#> [3,] NaN+1.81358191i 1.41977570+0.6720446i NA
#> [4,] NaN+ Infi NaN- Infi NA
#> [5,] 0.689180888+1.77331918i NA NA
#> [6,] NaN+ NaNi -2.61749323+0.1040397i NA
#> [7,] 0.092378551-0.42853428i -0.40644113+0.5993970i 0.2193157+0.2295454i
#> [8,] -0.318157722-0.20779086i 0.45475089-1.1349679i -0.3805185+0.2666057i
#> [9,] 0.483826545-0.99382872i 1.00466768+1.7166736i 2.1921644-0.1678954i
#> [10,] 2.056174557-0.70191233i -0.08760769-0.4306843i -0.4824393-0.8240692i
#> [11,] 0.267526902+1.32419848i 0.61264041-1.3460984i 1.9463992+0.4511400i
#> [12,] 0.379091749-1.66093328i 1.10115387-0.4449428i -0.3215819-1.9976172i
#> [13,] 1.074633751+0.10278415i 0.11592479-0.2750381i 0.1528462-0.2836500i
#> [14,] -0.686571479+0.14074224i -0.59638052-1.3231587i 0.5956822+0.8245071i
#> [15,] NaN- Infi NaN+ NaNi NA
#> [16,] -0.453943664+0.39968072i 0.29557066+0.3907139i -0.2903332-0.0592282i
#> [17,] 1.000647235-0.09283919i -Inf+0.3619943i -Inf+ Infi
#> [18,] -Inf+1.15620429i NA NA
#> [19,] -1.258000532-0.93229452i 1.50648966+0.2107450i -1.6986884-1.6696093i
#> [20,] -0.008042516-0.44616105i 0.64737109-0.8870950i -0.4009937-0.2816973i
#> [21,] 0.509805148+0.01067018i NaN+ Infi NA
#> [22,] NA -0.57271556-1.8336704i NA
#> [23,] NA -0.07845260+1.0193775i NA
#> [24,] -0.375351371+0.89832618i Inf-1.1758465i -Inf+ Infi
#> out
#> [1,] 1.0880626-0.9014079i
#> [2,] -2.2510299-1.1771343i
#> [3,] NA
#> [4,] NA
#> [5,] NA
#> [6,] NA
#> [7,] 0.2193157+0.2295454i
#> [8,] -0.3805185+0.2666057i
#> [9,] 2.1921644-0.1678954i
#> [10,] -0.4824393-0.8240692i
#> [11,] 1.9463992+0.4511400i
#> [12,] -0.3215819-1.9976172i
#> [13,] 0.1528462-0.2836500i
#> [14,] 0.5956822+0.8245071i
#> [15,] NA
#> [16,] -0.2903332-0.0592282i
#> [17,] -Inf+ Infi
#> [18,] NA
#> [19,] -1.6986884-1.6696093i
#> [20,] -0.4009937-0.2816973i
#> [21,] NA
#> [22,] NA
#> [23,] NA
#> [24,] -Inf+ Infi
#> 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.