Irfft

torch_irfft(
  self,
  signal_ndim,
  normalized = FALSE,
  onesided = TRUE,
  signal_sizes = list()
)

Arguments

self

(Tensor) the input tensor of at least signal_ndim + 1 dimensions

signal_ndim

(int) the number of dimensions in each signal. signal_ndim can only be 1, 2 or 3

normalized

(bool, optional) controls whether to return normalized results. Default: FALSE

onesided

(bool, optional) controls whether input was halfed to avoid redundancy, e.g., by torch_rfft(). Default: TRUE

signal_sizes

(list or torch.Size, optional) the size of the original signal (without batch dimension). Default: NULL

Note

Due to the conjugate symmetry, `input` do not need to contain the full
complex frequency values. Roughly half of the values will be sufficient, as
is the case when `input` is given by [`~torch.rfft`] with
`rfft(signal, onesided=TRUE)`. In such case, set the `onesided`
argument of this method to `TRUE`. Moreover, the original signal shape
information can sometimes be lost, optionally set `signal_sizes` to be
the size of the original signal (without the batch dimensions if in batched
mode) to recover it with correct shape.

Therefore, to invert an [torch_rfft()], the `normalized` and
`onesided` arguments should be set identically for [torch_irfft()],
and preferably a `signal_sizes` is given to avoid size mismatch. See the
example below for a case of size mismatch.

See [torch_rfft()] for details on conjugate symmetry.

The inverse of this function is torch_rfft().

For CUDA tensors, an LRU cache is used for cuFFT plans to speed up
repeatedly running FFT methods on tensors of same geometry with same
configuration. See cufft-plan-cache for more details on how to
monitor and control the cache.

irfft(input, signal_ndim, normalized=False, onesided=TRUE, signal_sizes=NULL) -> Tensor

Complex-to-real Inverse Discrete Fourier Transform

This method computes the complex-to-real inverse discrete Fourier transform. It is mathematically equivalent with torch_ifft with differences only in formats of the input and output.

The argument specifications are almost identical with torch_ifft. Similar to torch_ifft, if normalized is set to TRUE, this normalizes the result by multiplying it with \(\sqrt{\prod_{i=1}^K N_i}\) so that the operator is unitary, where \(N_i\) is the size of signal dimension \(i\).

Warning

Generally speaking, input to this function should contain values following conjugate symmetry. Note that even if onesided is TRUE, often symmetry on some part is still needed. When this requirement is not satisfied, the behavior of torch_irfft is undefined. Since torch_autograd.gradcheck estimates numerical Jacobian with point perturbations, torch_irfft will almost certainly fail the check.

For CPU tensors, this method is currently only available with MKL. Use torch_backends.mkl.is_available to check if MKL is installed.

Examples

if (torch_is_installed()) { x = torch_randn(c(4, 4)) torch_rfft(x, 2, onesided=TRUE) x = torch_randn(c(4, 5)) torch_rfft(x, 2, onesided=TRUE) y = torch_rfft(x, 2, onesided=TRUE) torch_irfft(y, 2, onesided=TRUE, signal_sizes=c(4,5)) # recover x }
#> torch_tensor #> -0.0903 0.3919 0.0848 -0.6948 2.2436 #> -1.1448 -0.6908 -0.1444 0.0947 0.2402 #> 0.5605 -0.5919 -0.2863 -0.2805 1.7053 #> -0.3723 -1.4191 -1.0517 -0.4421 0.7274 #> [ CPUFloatType{4,5} ]