## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
has_fftwtools <- requireNamespace("fftwtools", quietly = TRUE)

## -----------------------------------------------------------------------------
library(zufft)

## -----------------------------------------------------------------------------
x <- c(1, 4, 2, 8, 5, 7)
fft_c2c(fft_c2c(x), inverse = TRUE)                 # x again
fft_c2c(fft_c2c(x), inverse = TRUE, norm = "none")  # 6 * x, as fftwtools

## -----------------------------------------------------------------------------
fft_c2c(x)  # full spectrum, as fftw(x) and fftw_r2c(x)
fft_r2c(x)  # first n %/% 2 + 1 values, as fftw_r2c(x, HermConj = 0)

## -----------------------------------------------------------------------------
X <- fft_r2c(1:7)
fft_c2r(X, n = 7, norm = "none")   # as fftw_c2r(X, HermConj = 0, n = 7)

## ----eval = has_fftwtools-----------------------------------------------------
z <- complex(real = rnorm(8), imaginary = rnorm(8))
all.equal(fft_c2c(z, inverse = 1, norm = "none"), fftwtools::fftw_c2c(z, inverse = 1))
all.equal(fft_r2c(x), fftwtools::fftw_r2c(x, HermConj = 0))
all.equal(fft_c2r(X, n = 7, norm = "none"), fftwtools::fftw_c2r(X, HermConj = 0, n = 7))

## ----eval = has_fftwtools-----------------------------------------------------
m <- matrix(rnorm(24), 6)
all.equal(fft_c2c(m, axes = 1), fftwtools::mvfftw(m))
M <- fft_r2c(m, axes = 1)
all.equal(fft_c2r(M, n = 6, axes = 1, norm = "none"), fftwtools::mvfftw_c2r(M, HermConj = 0, n = 6))

## ----eval = has_fftwtools-----------------------------------------------------
x2 <- matrix(rnorm(35), 5, 7)
all.equal(fft_r2c(x2), fftwtools::fftw_r2c_2d(x2, HermConj = 0))
all.equal(fft_c2c(x2), fftwtools::fftw2d(x2))

