bc.cplx

Broadcasted Complex Numeric Operations

Description

The bc.cplx() function 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.

See Also

broadcast_operators

Examples

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 FALSE FALSE
#> [3,] FALSE FALSE    NA
#> [4,]    NA FALSE FALSE
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,] FALSE FALSE FALSE
#> [2,]    NA FALSE FALSE
#> [3,] FALSE FALSE FALSE
#> [4,]    NA FALSE    NA
bc.cplx(x, y, "!=")
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,]   NA TRUE TRUE
#> [3,] TRUE TRUE   NA
#> [4,]   NA TRUE TRUE
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3]
#> [1,] TRUE TRUE TRUE
#> [2,]   NA TRUE TRUE
#> [3,] TRUE TRUE TRUE
#> [4,]   NA TRUE   NA

bc.cplx(x, y, "+")
#> , , 1
#> 
#>                       [,1]                   [,2]                  [,3]
#> [1,]  0.2492337+0.3354452i  2.6884420+0.09523965i  1.4707379-0.9694091i
#> [2,]                    NA  1.8289991-0.32845984i -1.1996408+2.1032167i
#> [3,] -0.6673447+2.2294455i  0.2919521+1.00052448i        NaN+1.7739904i
#> [4,]                    NA -1.5232785+1.03075808i -0.3835455-1.1940079i
#> 
#> , , 2
#> 
#>                      [,1]                   [,2]                 [,3]
#> [1,] 0.4119949+0.1340157i  2.22459612-1.7596467i      Inf-0.47353689i
#> [2,]       NaN+      NaNi -1.29944996+1.4110470i     -Inf+0.39609088i
#> [3,] 1.6424257+1.4316991i -0.01016153-0.3492766i 1.609712-0.06516728i
#> [4,]       NaN+      Infi -0.94304612-0.8712025i      NaN-       Infi

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#>  [1] FALSE FALSE FALSE FALSE    NA    NA    NA    NA    NA    NA    NA FALSE
#> [13] FALSE    NA FALSE FALSE FALSE    NA    NA FALSE FALSE FALSE FALSE    NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#>  [1] TRUE   NA   NA   NA TRUE TRUE   NA TRUE   NA   NA TRUE TRUE   NA   NA TRUE
#> [16] TRUE TRUE TRUE   NA TRUE   NA   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.39404748-1.2465172i  0.51820332+0.38924143i  1.2075962-0.1033283i
#>  [2,]  0.16290370-0.9856002i         NaN+       NaNi                    NA
#>  [3,]         NaN+      Infi  0.23436369+1.84996101i                    NA
#>  [4,] -0.34063498-0.4230739i -0.46453091-0.62026961i -0.1041844+0.4078164i
#>  [5,]  1.78562051-0.3864921i  0.62951779+0.38707155i  1.2736800+0.4478593i
#>  [6,]  0.88713870+1.5026032i -1.36117525-0.52623108i -0.4168347-2.5121462i
#>  [7,]  0.73542440+0.4610473i         NaN-       Infi                    NA
#>  [8,]        -Inf+0.1934689i  0.01017447+0.78420666i       -Inf-      Infi
#>  [9,] -0.51722445+0.5896549i  0.45716344-1.29122061i  0.5249185+0.9374195i
#> [10,]  0.16664357-0.0793851i  0.91583574-0.29189148i  0.1294463-0.1213456i
#> [11,]                     NA                      NA                    NA
#> [12,]         NaN-      Infi -0.17997019+0.78788204i                    NA
#> [13,] -0.05758921-0.8707933i -0.23890190+0.88751446i  0.7865999+0.1569229i
#> [14,]  0.04615798-0.6302933i         Inf+0.28373877i        Inf-      Infi
#> [15,] -1.26874545-0.6890440i  0.44619233-0.55572596i -0.9490241+0.3976286i
#> [16,] -1.24631825-0.1153879i  0.18769100+0.16130001i -0.2153107-0.2226884i
#> [17,] -0.03389854+0.4071542i        -Inf+0.37215471i        Inf-      Infi
#> [18,]  1.72587153-1.2345742i -1.43374068+1.25219690i -0.9285223+3.9311902i
#> [19,]                     NA -0.20969377+0.91281176i                    NA
#> [20,]         Inf-0.1551255i -0.52272468+0.04919824i       -Inf+      Infi
#> [21,]         NaN+0.8988165i -1.53761649-0.38553577i                    NA
#> [22,]         NaN+      NaNi         NaN+       Infi                    NA
#> [23,] -1.69759612+2.6700090i         NaN+1.00467054i                    NA
#> [24,]  1.54604071-0.2805095i  1.46229670-0.40815683i  2.1462784-1.0412151i
#>                         out
#>  [1,]  1.2075962-0.1033283i
#>  [2,]                    NA
#>  [3,]                    NA
#>  [4,] -0.1041844+0.4078164i
#>  [5,]  1.2736800+0.4478593i
#>  [6,] -0.4168347-2.5121462i
#>  [7,]                    NA
#>  [8,]       -Inf-      Infi
#>  [9,]  0.5249185+0.9374195i
#> [10,]  0.1294463-0.1213456i
#> [11,]                    NA
#> [12,]                    NA
#> [13,]  0.7865999+0.1569229i
#> [14,]        Inf-      Infi
#> [15,] -0.9490241+0.3976286i
#> [16,] -0.2153107-0.2226884i
#> [17,]        Inf-      Infi
#> [18,] -0.9285223+3.9311902i
#> [19,]                    NA
#> [20,]       -Inf+      Infi
#> [21,]                    NA
#> [22,]                    NA
#> [23,]                    NA
#> [24,]  2.1462784-1.0412151i
#> broadcaster