-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[ONNX][TOPI] Add DFT operator
#13999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e45ffb5
4a55461
72b6530
df9dfc3
3b06160
3c10eb6
5540440
93b3fab
911c963
0b27f18
aaca2b9
f14e420
25009bb
312b97e
5d044c6
f68894f
4471e12
2f933be
df65290
cce4151
0c81b0a
9f0f486
5804377
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1987,6 +1987,33 @@ def stft( | |
| return _make.stft(data, n_fft, hop_length, win_length, window, normalized, onesided) | ||
|
|
||
|
|
||
| def dft(re_data, im_data, inverse=False): | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid allocating the imaginary part when possible. In practice, I think we only need real to complex DFT and complex to real iDFT. In both cases, we can remove one of input or output tensors. So rather than defining one big DFT op that does everything, how about making more fine-grained definition for each possible use case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will try to do this soon.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if we define real to complex DFT, we can exploit the "onesided" optimization. |
||
| Computes the discrete Fourier transform of input (calculation along the last axis). | ||
| This gives frequency components of the signal as they change over time. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| re_data : relay.Expr | ||
| N-D tensor, real part of the input signal. | ||
|
|
||
| im_data : relay.Expr | ||
| N-D tensor, imaginary part of the input signal. | ||
| If the signal is real, then the values of this tensor are zeros. | ||
|
|
||
| inverse : bool | ||
| Whether to perform the inverse discrete fourier transform. | ||
|
|
||
| Returns | ||
| ------- | ||
| re_output : relay.Expr | ||
| The Fourier Transform of the input (Real part). | ||
| im_output : relay.Expr | ||
| The Fourier Transform of the input (Imaginary part). | ||
| """ | ||
| return TupleWrapper(_make.dft(re_data, im_data, inverse), 2) | ||
|
|
||
|
|
||
| def trilu(data, k, upper=True): | ||
| """Given a 2-D matrix or batches of 2-D matrices, returns the | ||
| upper or lower triangular part of the tensor. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document that this is 1D DFT along the last axis.
We cannot use this op to support 2D DFT (PyTorch
fft2op), correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description of the fact that calculations occur along the last axis is already given in the functions where the algorithm is implemented:
python/tvm/topi/signal.pypython/tvm/topi/cuda/signal.pypython/tvm/relay/op/transform.pyWe can use 1D DFT (which computes along the last axis) to calculate n-D DFT (and 2D DFT in particular). This can be done with the following pseudocode:
axesis a vector that contains the axes along which it is necessary to perform n-D Fourier transform (for 2D, the length of this vector must be 2).The same approach is used in numpy: here and here.