bc.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.

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

bc.cplx(x, y, "+")
#> , , 1
#> 
#>          [,1]               [,2]                [,3]
#> [1,] NaN+Infi      NaN+     Infi      NaN+      Infi
#> [2,] NaN+Infi 0.302389+0.381028i 1.691718-0.2047692i
#> [3,] NaN-Infi      NaN-     Infi                  NA
#> [4,] NaN+NaNi      NaN+2.192970i                  NA
#> 
#> , , 2
#> 
#>                      [,1]               [,2]           [,3]
#> [1,]       NaN+      Infi      NaN+     Infi NaN+      Infi
#> [2,] 0.1839039-0.4920997i 1.135124-1.414095i Inf+0.5433026i
#> [3,]       NaN-      Infi      NaN-     Infi NaN-      Infi
#> [4,]       NaN+2.0713268i      NaN+3.198894i NaN+0.2647460i

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#>  [1] FALSE    NA FALSE FALSE FALSE    NA FALSE    NA    NA    NA FALSE FALSE
#> [13] FALSE FALSE    NA FALSE FALSE FALSE FALSE FALSE FALSE    NA FALSE    NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#>  [1] TRUE   NA TRUE TRUE TRUE TRUE   NA   NA TRUE   NA   NA TRUE   NA   NA TRUE
#> [16] TRUE   NA   NA   NA TRUE TRUE TRUE TRUE   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+       Infi          NaN+      NaNi                    NA
#>  [2,] -1.3979291-0.91158869i  0.039639111+1.3028914i  1.1322884-1.8574844i
#>  [3,] -0.1053596+0.68072471i  2.906605609+0.4237700i -0.5947097+1.9339500i
#>  [4,] -0.1277946-2.10630310i -0.477020946+0.2438057i  0.5744894+0.9735936i
#>  [5,]  1.6969458+0.52532547i  0.523833834+1.1398722i  0.2901137+2.2094845i
#>  [6,] -0.4884888-0.15381087i  2.349956844+2.1788601i -0.8127953-1.4257977i
#>  [7,]  1.6342893-1.97499216i          NaN-0.4051345i                    NA
#>  [8,]  1.7118440+1.23408790i  1.227283864+0.4350838i  1.5639869+2.2593718i
#>  [9,]  1.1159989+2.24374567i          NaN+      Infi                    NA
#> [10,]        NaN-       Infi -1.059705781-0.6077321i                    NA
#> [11,]  0.2425376-0.33966936i         -Inf+1.9869338i       -Inf+      Infi
#> [12,]        Inf-1.52260850i -1.148841743+0.1713432i       -Inf+      Infi
#> [13,]        NaN-0.54581476i          NaN-      Infi                    NA
#> [14,]  0.7510077+0.32053204i -0.249969238+1.2408671i -0.5854665+0.8517776i
#> [15,]       -Inf+0.47650878i  1.220738930+0.5476360i       -Inf-      Infi
#> [16,] -0.8928327-0.97398154i -0.008639608-0.8426143i -0.8129770+0.7607284i
#> [17,]  0.1073202+0.02312121i                      NA                    NA
#> [18,]                     NA  0.175675504-0.5990442i                    NA
#> [19,] -2.6363219+0.66033126i -0.121415009+2.1525219i -1.1012885-5.7549149i
#> [20,] -1.0133720-1.16401245i  1.013819065-0.7123080i -1.8565113-0.4582650i
#> [21,]  0.2931706-0.71259378i -0.904901963-0.9179538i -0.9194188+0.3757104i
#> [22,]        NaN+       NaNi -0.110448411-1.6348613i                    NA
#> [23,]  0.4776885-0.57476745i  1.349974108+0.1100252i  0.7081059-0.7233634i
#> [24,]                     NA          Inf-0.5132093i                    NA
#>                         out
#>  [1,]                    NA
#>  [2,]  1.1322884-1.8574844i
#>  [3,] -0.5947097+1.9339500i
#>  [4,]  0.5744894+0.9735936i
#>  [5,]  0.2901137+2.2094845i
#>  [6,] -0.8127953-1.4257977i
#>  [7,]                    NA
#>  [8,]  1.5639869+2.2593718i
#>  [9,]                    NA
#> [10,]                    NA
#> [11,]       -Inf+      Infi
#> [12,]       -Inf+      Infi
#> [13,]                    NA
#> [14,] -0.5854665+0.8517776i
#> [15,]       -Inf-      Infi
#> [16,] -0.8129770+0.7607284i
#> [17,]                    NA
#> [18,]                    NA
#> [19,] -1.1012885-5.7549149i
#> [20,] -1.8565113-0.4582650i
#> [21,] -0.9194188+0.3757104i
#> [22,]                    NA
#> [23,]  0.7081059-0.7233634i
#> [24,]                    NA
#> broadcaster