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.
Numeric and logical arrays will be coerced to 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,]    NA FALSE FALSE
#> [3,]    NA    NA    NA
#> [4,] FALSE FALSE    NA
#> 
#> , , 2
#> 
#>       [,1]  [,2]  [,3]
#> [1,]    NA    NA    NA
#> [2,] FALSE FALSE    NA
#> [3,]    NA    NA    NA
#> [4,] FALSE    NA FALSE
bc.cplx(x, y, "!=")
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,]   NA   NA   NA
#> [2,]   NA TRUE TRUE
#> [3,]   NA   NA   NA
#> [4,] TRUE TRUE   NA
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3]
#> [1,]   NA   NA   NA
#> [2,] TRUE TRUE   NA
#> [3,]   NA   NA   NA
#> [4,] TRUE   NA TRUE

bc.cplx(x, y, "+")
#> , , 1
#> 
#>                      [,1]                [,2]                  [,3]
#> [1,]       NaN+      NaNi      NaN+      NaNi        NaN+      NaNi
#> [2,]       NaN+      NaNi      Inf-0.8781240i 0.01684851-0.1562253i
#> [3,]       NaN+      Infi                  NA        NaN+      Infi
#> [4,] 0.3066861-0.3870061i 1.489581+0.2497775i        NaN+      Infi
#> 
#> , , 2
#> 
#>                       [,1]                 [,2]                [,3]
#> [1,]        NaN+      NaNi       NaN+      NaNi       NaN+     NaNi
#> [2,]  0.2550466-0.3749591i -1.205204-0.3379996i       NaN-     Infi
#> [3,]        NaN+      Infi       NaN+      Infi       NaN+     Infi
#> [4,] -0.4305977-1.4787541i       NaN-0.3931917i 0.8991706-1.931342i

bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
#>  [1]    NA FALSE FALSE    NA    NA    NA    NA    NA FALSE FALSE    NA    NA
#> [13] FALSE FALSE    NA FALSE FALSE FALSE    NA    NA FALSE FALSE FALSE FALSE
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
#>  [1]   NA TRUE   NA TRUE TRUE TRUE   NA TRUE TRUE   NA   NA TRUE TRUE TRUE   NA
#> [16]   NA TRUE TRUE   NA 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-       Infi         NaN-        Infi        -Inf+       NaNi
#>  [2,]  0.72281636+0.80545552i  0.97557448+0.596658605i  0.22457923+1.21705645i
#>  [3,]        -Inf-0.19750134i  0.55951090+0.414715067i        -Inf-       Infi
#>  [4,]  0.66549132+0.33149033i -0.03552841-1.787477350i  0.56888762-1.20132798i
#>  [5,]  1.49670504-1.13066536i  0.07327041-0.537436754i -0.49799694-0.88722861i
#>  [6,]         NaN-0.52834148i                       NA                      NA
#>  [7,]         NaN+       NaNi         NaN+        NaNi         NaN+       NaNi
#>  [8,]  0.96121877-0.29649840i  0.39246054-0.028448045i  0.36880563-0.14370871i
#>  [9,]  0.59144601+0.39415483i        -Inf-0.322377569i        -Inf-       Infi
#> [10,]  1.60738428-0.41964889i         NaN+        Infi         Inf+       Infi
#> [11,]  0.02808674+0.05027616i  2.41425156-0.145264863i  0.07511182+0.11729929i
#> [12,] -0.85368434+0.27798476i  0.79679362+0.180343030i -0.73034285+0.06754046i
#> [13,]  1.74382741-0.22741890i -0.13275241+1.180811242i  0.03704151+2.08932141i
#> [14,] -1.46018801+0.47897239i  0.51747555-1.143341596i -0.20798254+1.91735019i
#> [15,]  0.02452262-0.55246852i         NaN+0.089655525i         NaN+       NaNi
#> [16,]                      NA -1.13534303-0.046150812i                      NA
#> [17,] -0.80336151-0.45400517i         Inf+0.168829322i        -Inf-       Infi
#> [18,]         NaN+       Infi  0.06068880+0.784717586i        -Inf+       Infi
#> [19,]  0.34067955+2.55128130i -0.53154137-1.111894950i  2.65567152-1.73491143i
#> [20,]  1.35760586-0.70103663i  0.36429928+0.555428787i  0.88395076+0.49866624i
#> [21,] -2.77640740+0.11041789i  1.00091542+0.004374498i -2.77943201+0.09837358i
#> [22,]  0.74805624+0.21187361i -0.26412739-2.109236378i  0.24930938-1.63378906i
#> [23,] -1.04003952+3.67072991i -0.72480010-1.230322775i  5.27000336-1.38096109i
#> [24,] -1.38611888+0.94302708i -1.47074357-0.112671235i  2.14487747-1.23077529i
#>                           out
#>  [1,]        -Inf+       NaNi
#>  [2,]  0.22457923+1.21705645i
#>  [3,]        -Inf-       Infi
#>  [4,]  0.56888762-1.20132798i
#>  [5,] -0.49799694-0.88722861i
#>  [6,]                      NA
#>  [7,]         NaN+       NaNi
#>  [8,]  0.36880563-0.14370871i
#>  [9,]        -Inf-       Infi
#> [10,]         Inf+       Infi
#> [11,]  0.07511182+0.11729929i
#> [12,] -0.73034285+0.06754046i
#> [13,]  0.03704151+2.08932141i
#> [14,] -0.20798254+1.91735019i
#> [15,]         NaN+       NaNi
#> [16,]                      NA
#> [17,]        -Inf-       Infi
#> [18,]        -Inf+       Infi
#> [19,]  2.65567152-1.73491143i
#> [20,]  0.88395076+0.49866624i
#> [21,] -2.77943201+0.09837358i
#> [22,]  0.24930938-1.63378906i
#> [23,]  5.27000336-1.38096109i
#> [24,]  2.14487747-1.23077529i
#> broadcaster