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 NA NA
#> [4,] NA NA NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA FALSE FALSE
#> [2,] NA NA NA
#> [3,] NA NA NA
#> [4,] NA NA NA
bc.cplx(x, y, "!=")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,] NA NA NA
#> [3,] NA NA NA
#> [4,] NA NA NA
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NA TRUE TRUE
#> [2,] NA NA NA
#> [3,] NA NA NA
#> [4,] NA NA NA
bc.cplx(x, y, "+")
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0.7114997+1.106419i 0.6051309-1.458699i 0.8673343-0.7814531i
#> [2,] NaN+ Infi NaN+ Infi NaN+ Infi
#> [3,] NaN+ NaNi NaN+ NaNi NaN+ NaNi
#> [4,] NaN- Infi NaN- Infi NaN+ NaNi
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] NaN-Infi 1.651163+0.6897112i 2.19754-1.062578i
#> [2,] NaN+Infi NaN+ Infi NA
#> [3,] NaN+NaNi NaN+ NaNi NaN+ NaNi
#> [4,] NA NaN- Infi NaN- Infi
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#> [1] NA FALSE FALSE FALSE FALSE FALSE FALSE NA FALSE NA FALSE NA
#> [13] FALSE NA NA FALSE FALSE NA FALSE NA NA FALSE FALSE NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#> [1] NA NA TRUE TRUE TRUE TRUE TRUE NA TRUE NA NA NA TRUE TRUE NA
#> [16] TRUE TRUE TRUE NA TRUE TRUE TRUE NA NA
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.35950321-1.4758245i -1.23264951+0.72542065i -0.6051974+2.8053860i
#> [2,] NaN+1.2376768i 0.60202147+3.07487490i NA
#> [3,] 0.14963085-0.3899868i -Inf-0.68248604i -Inf+ Infi
#> [4,] NaN+ NaNi -0.11237867-0.53896818i NA
#> [5,] 1.09147268-1.5218617i 0.84639464+1.67002389i 3.4653620+0.5346899i
#> [6,] -0.89087738+0.7287787i 0.42139079+0.61193892i -0.8213756-0.2380619i
#> [7,] -0.49888010-0.3375170i -0.10009039-1.84593323i -0.5731007+0.9546816i
#> [8,] NaN- Infi 0.84235693-0.35311524i NA
#> [9,] -Inf-1.8764092i -0.70357708-0.46704466i Inf+ Infi
#> [10,] 0.02985191+0.5059391i NaN+ Infi NA
#> [11,] 0.63791922+0.3835276i NA NA
#> [12,] 0.32338322-0.2288057i -0.05905760+0.64867847i 0.1293231+0.2232845i
#> [13,] NaN+ Infi 1.71098626+1.84795858i NA
#> [14,] 1.46180506-0.2441844i -0.32459228-0.63788166i -0.6302514-0.8531983i
#> [15,] 1.79588192+0.7948651i 0.09098014+0.87836488i -0.5347920+1.6497565i
#> [16,] -0.20714058-0.8368086i 0.91767335+1.12053135i 0.7475829-1.0000245i
#> [17,] -0.11238350-1.7152582i NaN- Infi NA
#> [18,] -0.47986339-1.1525107i 0.54243558+0.05942392i -0.1918083-0.6536782i
#> [19,] -1.36635191-0.8743840i 0.17060819+0.43551984i 0.1477007-0.7442504i
#> [20,] -1.56565271-0.5909001i 0.07950234+0.68764710i 0.2818577-1.1235945i
#> [21,] -1.26397031-0.3955948i NaN+ NaNi NA
#> [22,] NA -1.74763117+1.40086950i NA
#> [23,] Inf+0.3852927i 1.09540463-0.37410137i Inf- Infi
#> [24,] -0.57214946+0.3476391i NA NA
#> out
#> [1,] -0.6051974+2.8053860i
#> [2,] NA
#> [3,] -Inf+ Infi
#> [4,] NA
#> [5,] 3.4653620+0.5346899i
#> [6,] -0.8213756-0.2380619i
#> [7,] -0.5731007+0.9546816i
#> [8,] NA
#> [9,] Inf+ Infi
#> [10,] NA
#> [11,] NA
#> [12,] 0.1293231+0.2232845i
#> [13,] NA
#> [14,] -0.6302514-0.8531983i
#> [15,] -0.5347920+1.6497565i
#> [16,] 0.7475829-1.0000245i
#> [17,] NA
#> [18,] -0.1918083-0.6536782i
#> [19,] 0.1477007-0.7442504i
#> [20,] 0.2818577-1.1235945i
#> [21,] NA
#> [22,] NA
#> [23,] Inf- Infi
#> [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.