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 FALSE FALSE
## [2,] NA NA NA
## [3,] NA FALSE NA
## [4,] FALSE FALSE NA
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] FALSE NA NA
## [2,] NA NA NA
## [3,] NA NA FALSE
## [4,] NA NA NA
bc.cplx(x, y, "!=")
## , , 1
##
## [,1] [,2] [,3]
## [1,] NA TRUE TRUE
## [2,] NA NA NA
## [3,] NA TRUE NA
## [4,] TRUE TRUE NA
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] TRUE NA NA
## [2,] NA NA NA
## [3,] NA NA TRUE
## [4,] NA NA NA
bc.cplx(x, y, "+")
## , , 1
##
## [,1] [,2] [,3]
## [1,] NA -Inf+0.3433922i Inf-1.294168i
## [2,] NA NA NA
## [3,] NA -Inf-0.6964674i NA
## [4,] -0.9212439-0.7769773i -0.838082+0.4888053i NA
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 0.8308573-0.2424652i NA NA
## [2,] NA NA NA
## [3,] NA NA -Inf+0.3488331i
## [4,] NA NA NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "==")
## [1] FALSE NA NA NA NA NA NA NA FALSE NA FALSE NA
## [13] NA NA NA NA NA NA
bc.cplx(array(gen() + gen() * -1i), array(gen() + gen() * -1i), "!=")
## [1] NA NA NA NA NA NA NA NA TRUE NA NA TRUE NA NA NA
## [16] NA TRUE 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,] Inf-1.79601232i -1.02093582+0.21172596i -Inf+ Infi
## [2,] NaN+ NaNi NaN+ Infi NaN+ NaNi
## [3,] -0.8083487-0.72459931i 0.95384519-1.12963102i -1.58956940+0.22198023i
## [4,] NaN+ NaNi NaN+ NaNi NaN+ NaNi
## [5,] -0.9402953-0.23419349i NaN+1.23597932i NaN+ NaNi
## [6,] Inf+0.33197407i NA NaN+ NaNi
## [7,] -Inf-0.63102158i NaN-1.98507173i NaN+ Infi
## [8,] NA NaN+ NaNi NaN+ NaNi
## [9,] -0.3819833-0.01465508i -0.04276508+0.59407522i 0.02504176-0.22630007i
## [10,] 0.1957182+1.50709696i 0.21439330+1.43083081i -2.11444010+0.60315110i
## [11,] NaN+ Infi NaN+ Infi -Inf+ NaNi
## [12,] -0.2341587+1.47408549i NaN- Infi Inf+ Infi
## [13,] 0.3334745+0.58226041i -0.04337930+0.30316199i -0.19098511+0.07583874i
## [14,] NaN- Infi 0.96601064+0.07149116i Inf- Infi
## [15,] NA -Inf-0.61002745i NaN- Infi
## [16,] NaN- Infi NA NaN+ NaNi
## [17,] NA NaN- Infi NaN+ NaNi
## [18,] NaN+ Infi NA -Inf+ NaNi
## out
## [1,] -Inf+ Infi
## [2,] NA
## [3,] -1.58956940+0.22198023i
## [4,] NA
## [5,] NA
## [6,] NA
## [7,] NA
## [8,] NA
## [9,] 0.02504176-0.22630007i
## [10,] -2.11444010+0.60315110i
## [11,] NA
## [12,] NA
## [13,] -0.19098511+0.07583874i
## [14,] NA
## [15,] NA
## [16,] NA
## [17,] NA
## [18,] NAbc.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.