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

bc.cplx(x, y, "+")
#> , , 1
#> 
#>                    [,1]           [,2]                [,3]
#> [1,]                 NA             NA                  NA
#> [2,] -1.6366+0.1074383i NaN+0.3812892i 0.1929796+1.481202i
#> [3,]    -Inf-1.3822263i             NA      -Inf+0.459708i
#> [4,]     NaN-      Infi NaN-      Infi       NaN-     Infi
#> 
#> , , 2
#> 
#>          [,1]            [,2]           [,3]
#> [1,]       NA              NA  NaN-     Infi
#> [2,]       NA -Inf+1.0664958i  NaN+     Infi
#> [3,] NaN+NaNi -Inf-0.1174577i -Inf+2.039671i
#> [4,] NaN-Infi  NaN-      Infi  NaN-     Infi

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#>  [1] FALSE FALSE    NA    NA FALSE FALSE FALSE    NA FALSE FALSE    NA FALSE
#> [13] FALSE FALSE FALSE    NA    NA    NA    NA FALSE FALSE FALSE FALSE    NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#>  [1]   NA   NA   NA TRUE TRUE   NA TRUE TRUE   NA TRUE TRUE TRUE TRUE TRUE   NA
#> [16] TRUE TRUE   NA TRUE TRUE TRUE   NA   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,]         NaN-0.316831576i -0.4285282+2.2487615i                       NA
#>  [2,]                       NA -1.5702578+0.4682035i                       NA
#>  [3,]  1.01710981-1.041189722i                    NA                       NA
#>  [4,] -0.08305864-0.382734706i       -Inf+2.0627462i        Inf+         Infi
#>  [5,] -0.08913402+1.402903161i -1.2414866-1.4542311i  2.1508041-1.6120639975i
#>  [6,]         NaN-        Infi  1.2659291-0.9913854i                       NA
#>  [7,]  2.01638164+0.738226838i        NaN-      Infi                       NA
#>  [8,] -0.76788647-1.343472503i                    NA                       NA
#>  [9,] -0.24534313+0.199907746i        NaN+      NaNi                       NA
#> [10,] -0.67106899+0.542873468i -0.6822471+0.3886152i  0.2468660-0.6311614741i
#> [11,] -2.48311768+0.621871332i  0.3651571+0.3606265i -1.1309914-0.6683972263i
#> [12,]                       NA  0.4849540-0.2503982i                       NA
#> [13,]  0.43626302-0.065315212i  1.4739239+0.3721291i  0.6673242+0.0660765260i
#> [14,]  0.80104753+1.651757074i        NaN+      Infi                       NA
#> [15,]  0.44741757+0.695749829i -1.6665258-0.2970820i -0.5389382-1.2924047389i
#> [16,] -0.02390239-0.135301815i  0.1378112-0.7894954i -0.1101142+0.0002247264i
#> [17,]  0.13639272-1.099735969i  1.4447832+0.7756236i  1.0500391-1.4830906297i
#> [18,]        -Inf-0.455901652i  0.2483171-0.6658897i       -Inf+         Infi
#> [19,]         NaN+        Infi -1.3363976+1.2257364i                       NA
#> [20,]  0.81151120+0.681759676i -0.7008007-0.6529186i -0.1235740-1.0076284272i
#> [21,] -0.65581095+0.714718421i -0.6372493-0.1243459i  0.5067874-0.3739063960i
#> [22,]  0.54388803+0.009156165i -0.6993598+2.0087487i -0.3987659+1.0861309406i
#> [23,]         NaN+        NaNi -0.7697223-0.4722257i                       NA
#> [24,]         Inf+0.923551012i        Inf+1.4830660i        Inf+         Infi
#>                            out
#>  [1,]                       NA
#>  [2,]                       NA
#>  [3,]                       NA
#>  [4,]        Inf+         Infi
#>  [5,]  2.1508041-1.6120639975i
#>  [6,]                       NA
#>  [7,]                       NA
#>  [8,]                       NA
#>  [9,]                       NA
#> [10,]  0.2468660-0.6311614741i
#> [11,] -1.1309914-0.6683972263i
#> [12,]                       NA
#> [13,]  0.6673242+0.0660765260i
#> [14,]                       NA
#> [15,] -0.5389382-1.2924047389i
#> [16,] -0.1101142+0.0002247264i
#> [17,]  1.0500391-1.4830906297i
#> [18,]       -Inf+         Infi
#> [19,]                       NA
#> [20,] -0.1235740-1.0076284272i
#> [21,]  0.5067874-0.3739063960i
#> [22,] -0.3987659+1.0861309406i
#> [23,]                       NA
#> [24,]        Inf+         Infi
#> broadcaster