rfft#
- ivy.rfft(x, /, *, n=None, axis=-1, norm='backward', out=None)[source]#
Compute the one-dimensional discrete Fourier transform for real-valued input.
Note
Applying the one-dimensional inverse discrete Fourier transform for real-valued input to the output of this function must return the original (i.e., non-transformed) input array within numerical accuracy (i.e., irfft(rfft(x)) == x), provided that the transform and inverse transform are performed with the same arguments (axis and normalization mode) and consistent length.
Note
If the input a contains an imaginary part, it is silently discarded.
- Parameters:
x (
Union
[Array
,NativeArray
]) – input array. Must have a real-valued floating-point data type.n (
Optional
[int
], default:None
) – length of the transformed axis of the input. If - n is greater than the length of the input array, the input array is zero-padded to length n. - n is less than the length of the input array, the input array is trimmed to length n. - n is not provided, the length of the transformed axis of the output must equal the length of the input along the axis specified by axis. Default isNone
.axis (
int
, default:-1
) – axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used. Default is-1
.norm (
Literal
['backward'
,'ortho'
,'forward'
], default:'backward'
) – normalization mode. Should be one of the following modes: - ‘backward’: no normalization. - ‘ortho’: normalize by 1/sqrt(n) (i.e., make the FFT orthonormal). - ‘forward’: normalize by 1/n. Default isbackward
.out (
Optional
[Array
], default:None
) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – an array transformed along the axis (dimension) indicated by axis. The returned array must have a complex-valued floating-point data type determined by Type Promotion Rules.
This function conforms to the `Array API Standard
<https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)
`docstring <https (//data-apis.org/array-api/latest/)
API_specification/generated/array_api.max.html>`_
in the standard.
Both the description and the type hints above assumes an array input for simplicity,
but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.
Examples
With ivy.Array input:
>>> x = ivy.array([0,1,2]) >>> y = ivy.rfft(x) >>> print(y) ivy.array([ 3. +0.j , -1.5+0.8660254j])
>>> x = ivy.array([2.3,3.14,7.2]) >>> y = ivy.zeros(2) >>> ivy.rfft(x, out=y) >>> print(x) ivy.array([2.29999995, 3.1400001 , 7.19999981])
>>> x = ivy.array([-1.2, 3.4, -5.6]) >>> ivy.rfft(x, n=4, out=x) >>> print(x) ivy.array([ -3.3999999+0.j , 4.3999996-3.4j, -10.2 +0.j ], dtype=complex64)
With ivy.Container input:
>>> x = ivy.Container(a=ivy.array([0.,1.,2.]), ... b=ivy.array([3.,4.,5.])) >>> y = ivy.rfft(x) >>> print(y) { a: ivy.array([3.+0.j, -1.5+0.8660254j]), b: ivy.array([12.+0.j, -1.5+0.8660254j]) }
- Array.rfft(self, /, *, n=None, axis=-1, norm='backward', out=None)[source]#
ivy.Array instance method variant of ivy.rfft. This method simply wraps the function, and so the docstring for ivy.rfft also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array. Must have a real-valued floating-point data type.n (
Optional
[int
], default:None
) – length of the transformed axis of the input. If - n is greater than the length of the input array, the input array is zero-padded to length n. - n is less than the length of the input array, the input array is trimmed to length n. - n is not provided, the length of the transformed axis of the output must equal the length of the input along the axis specified by axis. Default isNone
.axis (
int
, default:-1
) – axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used. Default is-1
.norm (
Literal
['backward'
,'ortho'
,'forward'
], default:'backward'
) – normalization mode. Should be one of the following modes: - ‘backward’: no normalization. - ‘ortho’: normalize by 1/sqrt(n) (i.e., make the FFT orthonormal). - ‘forward’: normalize by 1/n. Default isbackward
.out (
Optional
[Array
], default:None
) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array transformed along the axis (dimension) indicated by axis. The returned array must have a complex-valued floating-point data type determined by Type Promotion Rules.
Examples
>>> x = ivy.array([0,1,2]) >>> y = x.rfft() >>> print(y) ivy.array([ 3. +0.j , -1.5+0.8660254j])
- Container.rfft(self, /, *, n=None, axis=-1, norm='backward', out=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.rfft. This method simply wraps the function, and so the docstring for ivy.rfft also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array. Must have a real-valued floating-point data type.n (
Optional
[Union
[int
,Container
]], default:None
) – length of the transformed axis of the input. If - n is greater than the length of the input array, the input array is zero-padded to length n. - n is less than the length of the input array, the input array is trimmed to length n. - n is not provided, the length of the transformed axis of the output must equal the length of the input along the axis specified by axis. Default isNone
.axis (
Union
[int
,Container
], default:-1
) – axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used. Default is-1
.norm (
Union
[Literal
['backward'
,'ortho'
,'forward'
],Container
], default:'backward'
) – normalization mode. Should be one of the following modes: - ‘backward’: no normalization. - ‘ortho’: normalize by 1/sqrt(n) (i.e., make the FFT orthonormal). - ‘forward’: normalize by 1/n. Default isbackward
.out (
Optional
[Union
[Array
,Container
]], default:None
) – Optional output array, for writing the result to. It must have a shape that the inputs broadcast to.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Returns:
ret – an array transformed along the axis (dimension) indicated by axis. The returned array must have a complex-valued floating-point data type determined by Type Promotion Rules.
Examples
>>> x = ivy.Container(a=ivy.array([0.,1.,2.]), ... b=ivy.array([3.,4.,5.])) >>> y = x.rfft() >>> print(y) { a: ivy.array([3.+0.j, -1.5+0.8660254j]), b: ivy.array([12.+0.j, -1.5+0.8660254j]) }