bc.cplx

Broadcasted Complex Numeric Operations

Description

The bc.cplx() function performs broadcasted complex numeric operations on pairs of arrays.

Note that bc.cplx() uses more strict NA checks than base β€˜R’:
If for an element of either x or y, either the real or imaginary part is NA or NaN, than the result of the operation for that element is necessarily NA.


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.

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

bc.cplx(x, y, "+")
## , , 1
## 
##                       [,1]                [,2]                  [,3]
## [1,] -0.4207717+2.0271354i 0.1900254+1.180627i                    NA
## [2,]  0.4080518+1.0849961i       NaN+     NaNi  0.5759243+0.7132395i
## [3,]        NaN+      Infi       NaN+     Infi        NaN+      Infi
## [4,] -0.1629322+0.5801757i 0.5753084+1.536662i -0.3771906+2.4113251i
## 
## , , 2
## 
##                       [,1]                 [,2]                [,3]
## [1,] -0.2278947-2.0671701i      -Inf+0.8979814i      NaN+      Infi
## [2,]  1.8062907+0.9267771i 0.9688477+1.6641441i 0.565448-0.4518281i
## [3,]        NaN+      Infi       NaN+      Infi      NaN+      Infi
## [4,]        NaN-      Infi                   NA 2.173631+1.9818403i

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
##  [1]    NA FALSE FALSE    NA FALSE FALSE    NA FALSE FALSE    NA    NA FALSE
## [13]    NA    NA    NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE    NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
##  [1] TRUE   NA TRUE   NA TRUE   NA TRUE   NA TRUE   NA TRUE   NA TRUE TRUE TRUE
## [16] TRUE   NA TRUE TRUE   NA TRUE   NA   NA 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,]         NaN+       Infi        Inf+0.39607420i                      NA
##  [2,]  0.71517005+0.06852437i        NaN-1.08965525i                      NA
##  [3,]  1.37875202+1.12303534i -0.3023320+1.03530599i -1.57952609+1.08790068i
##  [4,] -1.30715985-0.31600530i        NaN+       NaNi                      NA
##  [5,]  0.90825948+0.72631289i  1.1026439-0.26682411i  1.19528460+0.55851897i
##  [6,]        -Inf-1.12226960i -1.3708223+1.04480064i         Inf-       Infi
##  [7,] -0.55657185-2.91264637i -0.2376773-0.47476120i -1.25052699+0.95650867i
##  [8,]  0.16667881+0.52640296i -1.1755223+0.66332152i -0.54510907-0.50823677i
##  [9,] -0.41090087+0.72718258i        NaN+       Infi                      NA
## [10,]  0.31193046+0.61730459i -0.3714323-0.29544334i  0.06651748-0.32144465i
## [11,] -0.19787467-1.95125715i -0.8270456-0.03037946i  0.10437325+1.61979006i
## [12,] -0.62978546-0.02660483i -0.2956311+0.82569822i  0.20815174-0.51214751i
## [13,]         NaN+       NaNi -1.2204966+0.81576169i                      NA
## [14,]         Inf-0.07542514i  0.9820169+1.75637824i         Inf+       Infi
## [15,] -0.76816439-0.77317087i                     NA                      NA
## [16,] -1.71324802-1.59759600i                     NA                      NA
## [17,] -1.81431054+1.39735540i  0.6646381+1.47892558i -3.27244450-1.75449470i
## [18,] -0.10096477+0.23797923i  0.4900046+1.32974571i -0.36592506-0.01764656i
## [19,] -1.17211096+0.44496862i -0.1910781+0.05481083i  0.19957560-0.14926812i
## [20,]  1.59123714-0.31952392i  0.5261776+0.75978279i  1.08004219+1.04086826i
## [21,]                      NA        NaN-       Infi                      NA
## [22,] -0.04086893+0.25060016i  1.2501285-0.87664905i  0.16859698+0.34911010i
## [23,]         NaN-       Infi  1.4884405+1.07545754i                      NA
## [24,]  1.84457769-0.16296974i  0.5509319+0.30318929i  1.06564732+0.46947097i
##                           out
##  [1,]                      NA
##  [2,]                      NA
##  [3,] -1.57952609+1.08790068i
##  [4,]                      NA
##  [5,]  1.19528460+0.55851897i
##  [6,]         Inf-       Infi
##  [7,] -1.25052699+0.95650867i
##  [8,] -0.54510907-0.50823677i
##  [9,]                      NA
## [10,]  0.06651748-0.32144465i
## [11,]  0.10437325+1.61979006i
## [12,]  0.20815174-0.51214751i
## [13,]                      NA
## [14,]         Inf+       Infi
## [15,]                      NA
## [16,]                      NA
## [17,] -3.27244450-1.75449470i
## [18,] -0.36592506-0.01764656i
## [19,]  0.19957560-0.14926812i
## [20,]  1.08004219+1.04086826i
## [21,]                      NA
## [22,]  0.16859698+0.34911010i
## [23,]                      NA
## [24,]  1.06564732+0.46947097i
## broadcaster