Skip to content

Commit dc98c25

Browse files
steff456kgrytergommers
authored
Add device keyword to fftfreq and rfftfreq (#506)
Co-authored-by: Athan <[email protected]> Co-authored-by: Ralf Gommers <[email protected]>
1 parent d5f252b commit dc98c25

File tree

1 file changed

+31
-27
lines changed
  • spec/API_specification/array_api

1 file changed

+31
-27
lines changed

spec/API_specification/array_api/fft.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ._types import Tuple, Union, Sequence, array, Optional, Literal
1+
from ._types import Tuple, Union, Sequence, array, Optional, Literal, device
22

33

44
def fft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal['backward', 'ortho', 'forward'] = 'backward') -> array:
@@ -22,7 +22,7 @@ def fft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal['
2222
Default: ``None``.
2323
axis: int
2424
axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used.
25-
25+
2626
Default: ``-1``.
2727
norm: Literal['backward', 'ortho', 'forward']
2828
normalization mode. Should be one of the following modes:
@@ -61,7 +61,7 @@ def ifft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal[
6161
Default: ``None``.
6262
axis: int
6363
axis (dimension) over which to compute the inverse Fourier transform. If not set, the last axis (dimension) is used.
64-
64+
6565
Default: ``-1``.
6666
norm: Literal['backward', 'ortho', 'forward']
6767
normalization mode. Should be one of the following modes:
@@ -98,14 +98,14 @@ def fftn(x: array, /, *, s: Sequence[int] = None, axes: Sequence[int] = None, no
9898
- ``s[i]`` is ``-1``, the whole input array along the axis ``i`` is used (no padding/trimming).
9999
- ``s`` is not provided, the size of each transformed axis (dimension) in the output array must equal the size of the corresponding axis in the input array.
100100
101-
If ``s`` is not ``None``, ``axes`` must not be ``None`` either, and ``s[i]`` corresponds to the size along the transformed axis specified by ``axes[i]``.
101+
If ``s`` is not ``None``, ``axes`` must not be ``None`` either, and ``s[i]`` corresponds to the size along the transformed axis specified by ``axes[i]``.
102102
103103
Default: ``None``.
104104
axes: Sequence[int]
105105
axes (dimensions) over which to compute the Fourier transform. If ``None``, all axes must be transformed.
106-
106+
107107
If ``s`` is specified, the corresponding ``axes`` to be transformed must be explicitly specified too.
108-
108+
109109
Default: ``None``.
110110
norm: Literal['backward', 'ortho', 'forward']
111111
normalization mode. Should be one of the following modes:
@@ -144,14 +144,14 @@ def ifftn(x: array, /, *, s: Sequence[int] = None, axes: Sequence[int] = None, n
144144
- ``s[i]`` is ``-1``, the whole input array along the axis ``i`` is used (no padding/trimming).
145145
- ``s`` is not provided, the size of each transformed axis (dimension) in the output array must equal the size of the corresponding axis in the input array.
146146
147-
If ``s`` is not ``None``, ``axes`` must not be ``None`` either, and ``s[i]`` corresponds to the size along the transformed axis specified by ``axes[i]``.
147+
If ``s`` is not ``None``, ``axes`` must not be ``None`` either, and ``s[i]`` corresponds to the size along the transformed axis specified by ``axes[i]``.
148148
149149
Default: ``None``.
150150
axes: Sequence[int]
151151
axes (dimensions) over which to compute the Fourier transform. If ``None``, all axes must be transformed.
152-
152+
153153
If ``s`` is specified, the corresponding ``axes`` to be transformed must be explicitly specified too.
154-
154+
155155
Default: ``None``.
156156
norm: Literal['backward', 'ortho', 'forward']
157157
specify the normalization mode. Should be one of the following modes:
@@ -188,11 +188,11 @@ def rfft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal[
188188
- ``n`` is greater than the length of the input array, the input array is zero-padded to length ``n``.
189189
- ``n`` is less than the length of the input array, the input array is trimmed to length ``n``.
190190
- ``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``.
191-
191+
192192
Default: ``None``.
193193
axis: int
194194
axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used.
195-
195+
196196
Default: ``-1``.
197197
norm: Literal['backward', 'ortho', 'forward']
198198
normalization mode. Should be one of the following modes:
@@ -227,11 +227,11 @@ def irfft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal
227227
- ``n//2+1`` is greater than the length of the input array, the input array is zero-padded to length ``n//2+1``.
228228
- ``n//2+1`` is less than the length of the input array, the input array is trimmed to length ``n//2+1``.
229229
- ``n`` is not provided, the length of the transformed axis of the output must equal the length ``2*(m-1)``, where ``m`` is the length of the input along the axis specified by ``axis``.
230-
230+
231231
Default: ``None``.
232232
axis: int
233233
axis (dimension) over which to compute the inverse Fourier transform. If not set, the last axis (dimension) is used.
234-
234+
235235
Default: ``-1``.
236236
norm: Literal['backward', 'ortho', 'forward']
237237
normalization mode. Should be one of the following modes:
@@ -273,10 +273,10 @@ def rfftn(x: array, /, *, s: Sequence[int] = None, axes: Sequence[int] = None, n
273273
Default: ``None``.
274274
axes: Sequence[int]
275275
axes (dimensions) over which to compute the Fourier transform. If ``None``, all axes must be transformed.
276-
276+
277277
If ``s`` is specified, the corresponding ``axes`` to be transformed must be explicitly specified too.
278-
279-
Default: ``None``.
278+
279+
Default: ``None``.
280280
norm: Literal['backward', 'ortho', 'forward']
281281
normalization mode. Should be one of the following modes:
282282
@@ -319,10 +319,10 @@ def irfftn(x: array, /, *, s: Sequence[int] = None, axes: Sequence[int] = None,
319319
Default: ``None``.
320320
axes: Sequence[int]
321321
axes (dimensions) over which to compute the Fourier transform. If ``None``, all axes must be transformed.
322-
322+
323323
If ``s`` is specified, the corresponding ``axes`` to be transformed must be explicitly specified too.
324-
325-
Default: ``None``.
324+
325+
Default: ``None``.
326326
norm: Literal['backward', 'ortho', 'forward']
327327
normalization mode. Should be one of the following modes:
328328
@@ -355,11 +355,11 @@ def hfft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal[
355355
- ``n//2+1`` is greater than the length of the input array, the input array is zero-padded to length ``n//2+1``.
356356
- ``n//2+1`` is less than the length of the input array, the input array is trimmed to length ``n//2+1``.
357357
- ``n`` is not provided, the length of the transformed axis of the output must equal the length ``2*(m-1)``, where ``m`` is the length of the input along the axis specified by ``axis``.
358-
358+
359359
Default: ``None``.
360360
axis: int
361361
axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used.
362-
362+
363363
Default: ``-1``.
364364
norm: Literal['backward', 'ortho', 'forward']
365365
normalization mode. Should be one of the following modes:
@@ -391,11 +391,11 @@ def ihfft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal
391391
- ``n`` is greater than the length of the input array, the input array is zero-padded to length ``n``.
392392
- ``n`` is less than the length of the input array, the input array is trimmed to length ``n``.
393393
- ``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``.
394-
394+
395395
Default: ``None``.
396396
axis: int
397397
axis (dimension) over which to compute the Fourier transform. If not set, the last axis (dimension) is used.
398-
398+
399399
Default: ``-1``.
400400
norm: Literal['backward', 'ortho', 'forward']
401401
normalization mode. Should be one of the following modes:
@@ -413,7 +413,7 @@ def ihfft(x: array, /, *, n: Optional[int] = None, axis: int = -1, norm: Literal
413413
"""
414414

415415

416-
def fftfreq(n: int, /, *, d: float = 1.0) -> array:
416+
def fftfreq(n: int, /, *, d: float = 1.0, device: Optional[device] = None) -> array:
417417
"""
418418
Returns the discrete Fourier transform sample frequencies.
419419
@@ -430,6 +430,8 @@ def fftfreq(n: int, /, *, d: float = 1.0) -> array:
430430
window length.
431431
d: float
432432
sample spacing between individual samples of the Fourier transform input. Default: ``1.0``.
433+
device: Optional[device]
434+
device on which to place the created array. Default: ``None``.
433435
434436
Returns
435437
-------
@@ -438,10 +440,10 @@ def fftfreq(n: int, /, *, d: float = 1.0) -> array:
438440
"""
439441

440442

441-
def rfftfreq(n: int, /, *, d: float = 1.0) -> array:
443+
def rfftfreq(n: int, /, *, d: float = 1.0, device: Optional[device] = None) -> array:
442444
"""
443-
Returns the discrete Fourier transform sample frequencies (for ``rfft`` and ``irfft``).
444-
445+
Returns the discrete Fourier transform sample frequencies (for ``rfft`` and ``irfft``).
446+
445447
For a Fourier transform of length ``n`` and length unit of ``d`` the frequencies are described as:
446448
447449
.. code-block::
@@ -457,6 +459,8 @@ def rfftfreq(n: int, /, *, d: float = 1.0) -> array:
457459
window length.
458460
d: float
459461
sample spacing between individual samples of the Fourier transform input. Default: ``1.0``.
462+
device: Optional[device]
463+
device on which to place the created array. Default: ``None``.
460464
461465
Returns
462466
-------

0 commit comments

Comments
 (0)