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

bc.cplx(x, y, "+")
## , , 1
## 
##                      [,1]           [,2] [,3]
## [1,]                   NA             NA   NA
## [2,]       Inf+0.9337914i             NA   NA
## [3,] 0.2239998+1.1857386i -Inf+1.114283i   NA
## [4,]                   NA             NA   NA
## 
## , , 2
## 
##      [,1]                   [,2] [,3]
## [1,]   NA                     NA   NA
## [2,]   NA         Inf+1.3295458i   NA
## [3,]   NA -0.02308633-0.4062878i   NA
## [4,]   NA                     NA   NA

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
##  [1]    NA    NA FALSE    NA    NA    NA FALSE    NA    NA FALSE    NA FALSE
## [13]    NA    NA    NA    NA    NA FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
##  [1]   NA   NA   NA   NA   NA   NA   NA   NA   NA   NA TRUE TRUE   NA   NA   NA
## [16] TRUE   NA   NA

x <- gen() + gen() * -1i
y <- gen() + gen() * -1i
out <- bc.cplx(array(x), array(y), "*")
cbind(x, y, x*y, out)
##                            x                      y                      
##  [1,]                     NA                     NA                    NA
##  [2,]        NaN+       Infi        NaN-       Infi        Inf+      NaNi
##  [3,] -0.5026942-1.32857743i  1.0606997-0.43316135i -1.1086960-1.1914740i
##  [4,] -2.7677025-1.01516962i                     NA                    NA
##  [5,]        NaN+1.64250347i        NaN+       NaNi        NaN+      NaNi
##  [6,]        Inf-1.48304067i  1.2248073+1.41816255i        Inf+      Infi
##  [7,]        NaN+       Infi                     NA        NaN+      NaNi
##  [8,]        NaN-       Infi        Inf+0.12760337i        NaN-      Infi
##  [9,]  0.2155461+2.63231949i        NaN+       Infi       -Inf+      Infi
## [10,]                     NA -1.5141906-0.08596882i                    NA
## [11,]        NaN+       NaNi        NaN+       Infi        NaN+      NaNi
## [12,]        NaN-       Infi -1.5118193+1.14315273i        Inf+      Infi
## [13,]  0.7457438-3.55203240i                     NA                    NA
## [14,]                     NA  0.1511629+0.07850631i                    NA
## [15,]        NaN+0.87080258i       -Inf+0.74576140i        NaN-      Infi
## [16,]        NaN+       NaNi        NaN-       Infi        NaN+      NaNi
## [17,]  0.8591737-0.05294708i -0.8632114-0.57166338i -0.7719164-0.4454536i
## [18,]        Inf+2.13145960i        NaN+       NaNi        NaN+      NaNi
##                         out
##  [1,]                    NA
##  [2,]                    NA
##  [3,] -1.1086960-1.1914740i
##  [4,]                    NA
##  [5,]                    NA
##  [6,]        Inf+      Infi
##  [7,]                    NA
##  [8,]                    NA
##  [9,]                    NA
## [10,]                    NA
## [11,]                    NA
## [12,]                    NA
## [13,]                    NA
## [14,]                    NA
## [15,]                    NA
## [16,]                    NA
## [17,] -0.7719164-0.4454536i
## [18,]                    NA