DFT#
DFT - 17#
Version
name: DFT (GitHub)
domain: main
since_version: 17
function:
support_level: SupportType.COMMON
shape inference: True
This version of the operator has been available since version 17.
Summary
Attributes
axis - INT : The axis on which to perform the DFT. By default this value is set to 1, which corresponds to the first dimension after the batch index.
inverse - INT : Whether to perform the inverse discrete fourier transform. By default this value is set to 0, which corresponds to false.
onesided - INT : If onesided is 1, only values for w in [0, 1, 2, …, floor(n_fft/2) + 1] are returned because the real-to-complex Fourier transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m,w]=X[m,n_fft-w]*. Note if the input or window tensors are complex, then onesided output is not possible. Enabling onesided with real inputs performs a Real-valued fast Fourier transform (RFFT). When invoked with real or complex valued input, the default value is 0. Values can be 0 or 1.
Inputs
Between 1 and 2 inputs.
input (heterogeneous) - T1:
dft_length (optional, heterogeneous) - T2:
Outputs
output (heterogeneous) - T1:
Type Constraints
T1 in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.
T2 in ( tensor(int32), tensor(int64) ): Constrain scalar length types to int64_t.
Examples
default
import numpy as np
import onnx
node = onnx.helper.make_node("DFT", inputs=["x"], outputs=["y"], axis=1)
x = np.arange(0, 100).reshape(10, 10).astype(np.float32)
y = np.fft.fft(x, axis=0)
x = x.reshape(1, 10, 10, 1)
y = np.stack((y.real, y.imag), axis=2).astype(np.float32).reshape(1, 10, 10, 2)
expect(node, inputs=[x], outputs=[y], name="test_dft")
node = onnx.helper.make_node("DFT", inputs=["x"], outputs=["y"], axis=2)
x = np.arange(0, 100).reshape(10, 10).astype(np.float32)
y = np.fft.fft(x, axis=1)
x = x.reshape(1, 10, 10, 1)
y = np.stack((y.real, y.imag), axis=2).astype(np.float32).reshape(1, 10, 10, 2)
expect(node, inputs=[x], outputs=[y], name="test_dft_axis")
node = onnx.helper.make_node(
"DFT", inputs=["x"], outputs=["y"], inverse=1, axis=1
)
x = np.arange(0, 100, dtype=np.complex64).reshape(
10,
10,
)
y = np.fft.ifft(x, axis=0)
x = np.stack((x.real, x.imag), axis=2).astype(np.float32).reshape(1, 10, 10, 2)
y = np.stack((y.real, y.imag), axis=2).astype(np.float32).reshape(1, 10, 10, 2)
expect(node, inputs=[x], outputs=[y], name="test_dft_inverse")