Skip to content
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

Fix: Window functions generate incorrect shape for with symmetric attribute #4256

Merged
merged 5 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/Operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -19263,8 +19263,8 @@ nstfts = ((signal.shape[1] - length) // step) + 1
output = np.empty([1, nstfts, onesided_length, 2], dtype=np.float32)
for i in range(nstfts):
start = i * step
stop = i * step + onesided_length
complex_out = np.fft.fft(signal[0, start:stop, 0])
stop = i * step + length
complex_out = np.fft.fft(signal[0, start:stop, 0])[0:onesided_length]
output[0, i] = np.stack((complex_out.real, complex_out.imag), axis=1)

expect(node, inputs=[signal, step, length], outputs=[output],
Expand Down
4 changes: 2 additions & 2 deletions docs/TestCoverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12138,8 +12138,8 @@ nstfts = ((signal.shape[1] - length) // step) + 1
output = np.empty([1, nstfts, onesided_length, 2], dtype=np.float32)
for i in range(nstfts):
start = i * step
stop = i * step + onesided_length
complex_out = np.fft.fft(signal[0, start:stop, 0])
stop = i * step + length
complex_out = np.fft.fft(signal[0, start:stop, 0])[0:onesided_length]
output[0, i] = np.stack((complex_out.real, complex_out.imag), axis=1)

expect(node, inputs=[signal, step, length], outputs=[output],
Expand Down
4 changes: 2 additions & 2 deletions onnx/backend/test/case/node/stft.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def export() -> None:
output = np.empty([1, nstfts, onesided_length, 2], dtype=np.float32)
for i in range(nstfts):
start = i * step
stop = i * step + onesided_length
complex_out = np.fft.fft(signal[0, start:stop, 0])
stop = i * step + length
complex_out = np.fft.fft(signal[0, start:stop, 0])[0:onesided_length]
output[0, i] = np.stack((complex_out.real, complex_out.imag), axis=1)

expect(node, inputs=[signal, step, length], outputs=[output],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions onnx/defs/math/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ ONNX_OPERATOR_SET_SCHEMA(
Symmetric_Component = Mul(Symmetric_Size_FP, IsSymmetric_FP)
Size_FP = Add(Periodic_Component, Symmetric_Component)
AngularIncrement = Div (Tau, Size_FP)
Range = Range (Zero, Size_FP, One)
Range = Range (Zero, Periodic_Size_FP, One)
RangeAngular = Mul (Range, AngularIncrement)
TwoRangeAngular = Mul (RangeAngular, Two)
CosTwoRangeAngular = Cos (TwoRangeAngular)
Expand Down Expand Up @@ -2956,7 +2956,7 @@ ONNX_OPERATOR_SET_SCHEMA(
Symmetric_Component = Mul(Symmetric_Size_FP, IsSymmetric_FP)
Size_FP = Add(Periodic_Component, Symmetric_Component)
AngularIncrement = Div (Tau, Size_FP)
Range = Range (Zero, Size_FP, One)
Range = Range (Zero, Periodic_Size_FP, One)
RangeAngular = Mul (Range, AngularIncrement)
TwoRangeAngular = Mul (RangeAngular, Two)
CosTwoRangeAngular = Cos (TwoRangeAngular)
Expand Down Expand Up @@ -2994,7 +2994,7 @@ ONNX_OPERATOR_SET_SCHEMA(
Symmetric_Component = Mul(Symmetric_Size_FP, IsSymmetric_FP)
Size_FP = Add(Periodic_Component, Symmetric_Component)
AngularIncrement = Div (Tau, Size_FP)
Range = Range (Zero, Size_FP, One)
Range = Range (Zero, Periodic_Size_FP, One)
RangeAngular = Mul (Range, AngularIncrement)
TwoRangeAngular = Mul (RangeAngular, Two)
CosTwoRangeAngular = Cos (TwoRangeAngular)
Expand Down
27 changes: 27 additions & 0 deletions onnx/test/shape_inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4202,6 +4202,15 @@ def test_hammingwindow(self): # type: () -> None
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

graph = self._make_graph([],
[make_node("Constant", [], ['shape'],
value=make_tensor('shape', TensorProto.INT64, (), (10,))),
make_node("HammingWindow", ['shape'], ['y'], periodic=0)],
[])
self._assert_inferred(graph,
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

def test_hannwindow(self): # type: () -> None
graph = self._make_graph([],
[make_node("Constant", [], ['shape'],
Expand All @@ -4212,6 +4221,15 @@ def test_hannwindow(self): # type: () -> None
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

graph = self._make_graph([],
[make_node("Constant", [], ['shape'],
value=make_tensor('shape', TensorProto.INT64, (), (10,))),
make_node("HannWindow", ['shape'], ['y'], periodic=0)],
[])
self._assert_inferred(graph,
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

def test_blackmanwindow(self): # type: () -> None
graph = self._make_graph([],
[make_node("Constant", [], ['shape'],
Expand All @@ -4222,6 +4240,15 @@ def test_blackmanwindow(self): # type: () -> None
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

graph = self._make_graph([],
[make_node("Constant", [], ['shape'],
value=make_tensor('shape', TensorProto.INT64, (), (10,))),
make_node("BlackmanWindow", ['shape'], ['y'], periodic=0)],
[])
self._assert_inferred(graph,
[make_tensor_value_info('shape', TensorProto.INT64, ()),
make_tensor_value_info('y', TensorProto.FLOAT, (10,))]) # type: ignore

def test_dft_reals(self): # type: () -> None
graph = self._make_graph([],
[make_node("Constant", [], ['input'],
Expand Down