fft#

ivy.fft(x, dim, /, *, norm='backward', n=None, out=None)[source]#

Compute the one dimensional discrete Fourier transform given input at least 1-D input x.

Parameters:
  • x (Union[Array, NativeArray]) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.

  • dim (int) – The dimension along which to take the one dimensional FFT.

  • norm (str) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be “backward”. (default: 'backward') “backward” indicates no normalization. “ortho” indicates normalization by $frac{1}{sqrt{n}}$. “forward” indicates normalization by $frac{1}{n}$.

  • n (Optional[Union[int, Tuple[int]]]) – Optional argument indicating the sequence length, if given, the input would be (default: None) padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1.

  • out (Optional[Array]) – Optional output array, for writing the result to. It must have a shape that the (default: None) inputs broadcast to.

Return type:

Array

Returns:

ret – The result of the FFT operation.

Examples

>>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0)
ivy.array([-3.44509285e-16+1.14423775e-17j,  8.00000000e+00-8.11483250e-16j,
        2.33486982e-16+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j,
        9.95799250e-17+2.33486982e-16j,  0.00000000e+00+7.66951701e-17j,
        1.14423775e-17+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j])
>>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0, n=16)
ivy.array([-3.44509285e-16+1.14423775e-17j,  1.00000000e+00+5.02733949e+00j,
    8.00000000e+00-8.11483250e-16j,  1.00000000e+00-5.02733949e+00j,
    2.33486982e-16+1.22464680e-16j,  1.00000000e+00-1.49660576e+00j,
    0.00000000e+00+1.22464680e-16j,  1.00000000e+00-6.68178638e-01j,
    9.95799250e-17+2.33486982e-16j,  1.00000000e+00-1.98912367e-01j,
    0.00000000e+00+7.66951701e-17j,  1.00000000e+00+1.98912367e-01j,
    1.14423775e-17+1.22464680e-16j,  1.00000000e+00+6.68178638e-01j,
    0.00000000e+00+1.22464680e-16j,  1.00000000e+00+1.49660576e+00j])
>>> ivy.fft(np.exp(2j * np.pi * np.arange(8) / 8), 0, norm="ortho")
ivy.array([-1.21802426e-16+4.04549134e-18j,  2.82842712e+00-2.86902654e-16j,
    8.25501143e-17+4.32978028e-17j,  0.00000000e+00+4.32978028e-17j,
    3.52068201e-17+8.25501143e-17j,  0.00000000e+00+2.71158374e-17j,
    4.04549134e-18+4.32978028e-17j,  0.00000000e+00+4.32978028e-17j])
Array.fft(self, dim, /, *, norm='backward', n=None, out=None)#

ivy.Array instance method variant of ivy.ifft. This method simply wraps the function, and so the docstring for ivy.ifft also applies to this method with minimal changes.

Parameters:
  • self (Array) – Input volume […,d_in,…], where d_in indicates the dimension that needs FFT.

  • dim (int) – The dimension along which to take the one dimensional FFT.

  • norm (str) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be (default: 'backward') “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • n (Optional[Union[int, Tuple[int]]]) – Optional argument indicating the sequence length, if given, the input (default: None) would be padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1.

  • out (Optional[Array]) – Optional output array, for writing the result to. It must have a shape (default: None) that the inputs broadcast to.

Return type:

Array

Returns:

ret – Array containing the transformed input.

Examples

>>> a = ivy.array((np.exp(2j * np.pi * np.arange(8) / 8)))
>>> a.fft(0)
ivy.array([-3.44509285e-16+1.14423775e-17j,  8.00000000e+00-8.11483250e-16j,
            2.33486982e-16+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j,
            9.95799250e-17+2.33486982e-16j,  0.00000000e+00+7.66951701e-17j,
            1.14423775e-17+1.22464680e-16j,  0.00000000e+00+1.22464680e-16j])
Container.fft(self, dim, /, *, norm='backward', n=None, out=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#

ivy.Container instance method variant of ivy.fft. This method simply wraps the function, and so the docstring for ivy.fft also applies to this method with minimal changes.

Parameters:
  • self (Container) – Container containing input volumes […,d_in,…], where d_in indicates the dimension that needs FFT.

  • dim (int) – The dimension along which to take the one dimensional FFT.

  • norm (str) – Optional argument, “backward”, “ortho” or “forward”. Defaults to be (default: 'backward') “backward”. “backward” indicates no normalization. “ortho” indicates normalization by 1/sqrt(n). “forward” indicates normalization by 1/n.

  • n (Optional[Union[int, Tuple[int]]]) – Optional argument indicating the sequence length, if given, the input would (default: None) be padded with zero or truncated to length n before performing FFT. Should be a integer greater than 1.

  • out (Optional[Array]) – Optional output array, for writing the result to. It must have a shape that (default: None) the inputs broadcast to.

Return type:

Container

Returns:

ret – Container containing the transformed inputs.

Examples

>>> a = ivy.array(np.array([ 6.+0.j, -2.+2.j, -2.+0.j, -2.-2.j]))
>>> b = ivy.array(np.exp(2j * np.pi * np.arange(8) / 8))
>>> c = ivy.Container(a=a, b=b)
>>> dims = ivy.Container(a=0, b=0)
>>> c.fft(dims)
{
a: ivy.array([0.+0.j, 12.+0.j, 8.+0.j, 4.+0.j]),
b: ivy.array([-3.44509285e-16+1.14423775e-17j, 8.00000000e+00-8.11483250e-16j,
               2.33486982e-16+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j,
               9.95799250e-17+2.33486982e-16j, 0.00000000e+00+7.66951701e-17j,
               1.14423775e-17+1.22464680e-16j, 0.00000000e+00+1.22464680e-16j])
}