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

bc.cplx(x, y, "+")
## , , 1
## 
##                       [,1]                  [,2]                  [,3]
## [1,]                    NA                    NA                    NA
## [2,]        NaN+0.3511651i       -Inf-0.9781650i       -Inf-0.4186534i
## [3,] -0.1691894-0.4263392i -1.8564117+0.3328927i -1.9949649+1.0084692i
## [4,] -1.5256795-0.8252113i  0.1630589-1.5137851i -0.9006487-1.5591549i
## 
## , , 2
## 
##                       [,1]                 [,2]                [,3]
## [1,] 2.4345192+1.59245553i  1.7259606+1.808225i 1.617174+0.4180732i
## [2,]      -Inf+0.36633822i       -Inf+1.529531i                  NA
## [3,] 0.6592101+0.06618028i -0.3183245+2.780011i                  NA
## [4,] 0.9508780-1.41243644i  1.9414053-1.791155i                  NA

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
##  [1] FALSE FALSE    NA    NA    NA    NA FALSE FALSE FALSE FALSE    NA FALSE
## [13] FALSE FALSE FALSE    NA FALSE FALSE FALSE FALSE    NA    NA FALSE FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
##  [1]   NA   NA TRUE TRUE TRUE   NA TRUE TRUE   NA TRUE TRUE   NA TRUE   NA   NA
## [16] TRUE TRUE   NA   NA   NA 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-0.2622418185i        -Inf+0.05375728i                     NA
##  [2,]        NaN+         Infi         NaN+       Infi                     NA
##  [3,] -1.0577441-1.1673572661i  3.33818515-0.84833989i -4.5212615-2.99952814i
##  [4,]  0.4718046-0.6926929246i  0.97019119+0.04261842i  0.4872622-0.65193701i
##  [5,] -0.7044505+0.0151905151i         NaN+2.16457897i                     NA
##  [6,] -0.9944829+1.3371277084i -0.18838502+0.49237315i -0.4710201-0.74155153i
##  [7,]  0.8604826-0.6297760001i -0.49927015+0.38153706i -0.1893304+0.64273437i
##  [8,]  0.5764025-2.5660485413i  1.06047567-1.73446943i -3.8394720-3.72098451i
##  [9,]        NaN-         Infi -0.43673716-2.49362654i                     NA
## [10,] -0.3552517+1.7605870680i -0.78673305+0.76050264i -1.0594429-1.65528187i
## [11,]                       NA         Inf-0.16953731i                     NA
## [12,]        Inf-0.2822515422i  1.10805463+0.79075410i        Inf+       Infi
## [13,] -0.2794157+1.1591099933i -0.06576198-1.07671151i  1.2664020+0.22462471i
## [14,] -0.3256257-1.3909741026i -0.93530347-0.40944383i -0.2649669+1.43430835i
## [15,] -0.5226586+0.3943676545i                      NA                     NA
## [16,] -1.6851153-0.0006236167i -0.57438041-0.03912229i  0.9678728+0.06628377i
## [17,]  0.5884980-1.8204766270i  0.12658114+2.58004713i  4.7714082+1.28791454i
## [18,] -0.2438806-1.6371077604i                      NA                     NA
## [19,]  0.4601924-0.6009215338i  0.63347146+1.19993893i  1.0125879+0.17153609i
## [20,] -0.2877476-0.7070489923i         NaN-       Infi                     NA
## [21,]       -Inf-2.4085951934i         NaN+       NaNi                     NA
## [22,] -0.6264228-0.5838842503i  0.26106922-1.08827676i -0.7989674+0.52928718i
## [23,]        NaN+         NaNi -0.25667292+0.44435125i                     NA
## [24,]  1.6920383-0.8072323892i -0.30161385-0.32108810i -0.7695349-0.29982089i
##                          out
##  [1,]                     NA
##  [2,]                     NA
##  [3,] -4.5212615-2.99952814i
##  [4,]  0.4872622-0.65193701i
##  [5,]                     NA
##  [6,] -0.4710201-0.74155153i
##  [7,] -0.1893304+0.64273437i
##  [8,] -3.8394720-3.72098451i
##  [9,]                     NA
## [10,] -1.0594429-1.65528187i
## [11,]                     NA
## [12,]        Inf+       Infi
## [13,]  1.2664020+0.22462471i
## [14,] -0.2649669+1.43430835i
## [15,]                     NA
## [16,]  0.9678728+0.06628377i
## [17,]  4.7714082+1.28791454i
## [18,]                     NA
## [19,]  1.0125879+0.17153609i
## [20,]                     NA
## [21,]                     NA
## [22,] -0.7989674+0.52928718i
## [23,]                     NA
## [24,] -0.7695349-0.29982089i
## broadcaster