未验证 提交 81e0c1ba 编写于 作者: F Feiyu Chan 提交者: GitHub

move fft and signal files, move signal APIs (#36540)

* move signal apis

* move fft.py and signal.py to paddle/, fix typos

* fix relative imports from fft.py and signal.py

* fix typos
上级 21bece3f
...@@ -296,6 +296,7 @@ from .hapi import flops # noqa: F401 ...@@ -296,6 +296,7 @@ from .hapi import flops # noqa: F401
from . import hub # noqa: F401 from . import hub # noqa: F401
from . import linalg # noqa: F401 from . import linalg # noqa: F401
from . import fft # noqa: F401 from . import fft # noqa: F401
from . import signal # noqa: F401
import paddle.text # noqa: F401 import paddle.text # noqa: F401
import paddle.vision # noqa: F401 import paddle.vision # noqa: F401
......
此差异已折叠。
...@@ -652,7 +652,7 @@ class TestFrame(unittest.TestCase): ...@@ -652,7 +652,7 @@ class TestFrame(unittest.TestCase):
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
frame_for_api_test(self.x, self.frame_length, self.hop_length, self.axis), frame_for_api_test(self.x, self.frame_length, self.hop_length, self.axis),
paddle.tensor.signal.frame( paddle.signal.frame(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.frame_length, self.frame_length,
self.hop_length, self.hop_length,
...@@ -678,7 +678,7 @@ class TestFrameStatic(unittest.TestCase): ...@@ -678,7 +678,7 @@ class TestFrameStatic(unittest.TestCase):
mp, sp = paddle.static.Program(), paddle.static.Program() mp, sp = paddle.static.Program(), paddle.static.Program()
with paddle.static.program_guard(mp, sp): with paddle.static.program_guard(mp, sp):
input = paddle.static.data('input', self.x.shape, dtype=self.x.dtype) input = paddle.static.data('input', self.x.shape, dtype=self.x.dtype)
output = paddle.tensor.signal.frame( output = paddle.signal.frame(
input, input,
self.frame_length, self.frame_length,
self.hop_length, self.hop_length,
...@@ -708,7 +708,7 @@ class TestFrameStatic(unittest.TestCase): ...@@ -708,7 +708,7 @@ class TestFrameStatic(unittest.TestCase):
class TestFrameException(unittest.TestCase): class TestFrameException(unittest.TestCase):
def test_frame(self): def test_frame(self):
with self.assertRaises(self.expect_exception): with self.assertRaises(self.expect_exception):
paddle.tensor.signal.frame( paddle.signal.frame(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.frame_length, self.frame_length,
self.hop_length, self.hop_length,
...@@ -731,7 +731,7 @@ class TestOverlapAdd(unittest.TestCase): ...@@ -731,7 +731,7 @@ class TestOverlapAdd(unittest.TestCase):
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
overlap_add_for_api_test(self.x, self.hop_length, self.axis), overlap_add_for_api_test(self.x, self.hop_length, self.axis),
paddle.tensor.signal.overlap_add( paddle.signal.overlap_add(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.hop_length, self.hop_length,
self.axis), self.axis),
...@@ -756,7 +756,7 @@ class TestOverlapAddStatic(unittest.TestCase): ...@@ -756,7 +756,7 @@ class TestOverlapAddStatic(unittest.TestCase):
mp, sp = paddle.static.Program(), paddle.static.Program() mp, sp = paddle.static.Program(), paddle.static.Program()
with paddle.static.program_guard(mp, sp): with paddle.static.program_guard(mp, sp):
input = paddle.static.data('input', self.x.shape, dtype=self.x.dtype) input = paddle.static.data('input', self.x.shape, dtype=self.x.dtype)
output = paddle.tensor.signal.overlap_add( output = paddle.signal.overlap_add(
input, input,
self.hop_length, self.hop_length,
self.axis), self.axis),
...@@ -783,7 +783,7 @@ class TestOverlapAddStatic(unittest.TestCase): ...@@ -783,7 +783,7 @@ class TestOverlapAddStatic(unittest.TestCase):
class TestOverlapAddException(unittest.TestCase): class TestOverlapAddException(unittest.TestCase):
def test_overlap_add(self): def test_overlap_add(self):
with self.assertRaises(self.expect_exception): with self.assertRaises(self.expect_exception):
paddle.tensor.signal.overlap_add( paddle.signal.overlap_add(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.hop_length, self.hop_length,
self.axis) self.axis)
...@@ -848,7 +848,7 @@ class TestStft(unittest.TestCase): ...@@ -848,7 +848,7 @@ class TestStft(unittest.TestCase):
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
stft(self.x, self.n_fft, self.hop_length, self.win_length, win_l, self.center, self.pad_mode), stft(self.x, self.n_fft, self.hop_length, self.win_length, win_l, self.center, self.pad_mode),
paddle.tensor.signal.stft( paddle.signal.stft(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.n_fft, self.n_fft,
self.hop_length, self.hop_length,
...@@ -891,7 +891,7 @@ class TestStftException(unittest.TestCase): ...@@ -891,7 +891,7 @@ class TestStftException(unittest.TestCase):
win_p = paddle.to_tensor(self.window) win_p = paddle.to_tensor(self.window)
with self.assertRaises(self.expect_exception): with self.assertRaises(self.expect_exception):
paddle.tensor.signal.stft( paddle.signal.stft(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.n_fft, self.n_fft,
self.hop_length, self.hop_length,
...@@ -934,7 +934,7 @@ class TestIstft(unittest.TestCase): ...@@ -934,7 +934,7 @@ class TestIstft(unittest.TestCase):
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
istft(self.x, self.hop_length, self.win_length, win_l, self.center, self.length), istft(self.x, self.hop_length, self.win_length, win_l, self.center, self.length),
paddle.tensor.signal.istft( paddle.signal.istft(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.n_fft, self.n_fft,
self.hop_length, self.hop_length,
...@@ -986,7 +986,7 @@ class TestIstftException(unittest.TestCase): ...@@ -986,7 +986,7 @@ class TestIstftException(unittest.TestCase):
win_p = paddle.to_tensor(self.window) win_p = paddle.to_tensor(self.window)
with self.assertRaises(self.expect_exception): with self.assertRaises(self.expect_exception):
paddle.tensor.signal.istft( paddle.signal.istft(
paddle.to_tensor(self.x), paddle.to_tensor(self.x),
self.n_fft, self.n_fft,
self.hop_length, self.hop_length,
......
...@@ -16,16 +16,14 @@ from typing import Optional ...@@ -16,16 +16,14 @@ from typing import Optional
import paddle import paddle
from .attribute import is_complex, is_floating_point from .tensor.attribute import is_complex, is_floating_point
from .fft import fft_r2c, fft_c2r, fft_c2c from .fft import fft_r2c, fft_c2r, fft_c2c
from ..fluid.data_feeder import check_variable_and_dtype from .fluid.data_feeder import check_variable_and_dtype
from ..fluid.framework import in_dygraph_mode from .fluid.framework import in_dygraph_mode
from ..fluid.layer_helper import LayerHelper from .fluid.layer_helper import LayerHelper
from .. import _C_ops from . import _C_ops
__all__ = [ __all__ = [
'frame',
'overlap_add',
'stft', 'stft',
'istft', 'istft',
] ]
...@@ -56,7 +54,7 @@ def frame(x, frame_length, hop_length, axis=-1, name=None): ...@@ -56,7 +54,7 @@ def frame(x, frame_length, hop_length, axis=-1, name=None):
.. code-block:: python .. code-block:: python
import paddle import paddle
from paddle.tensor.signal import frame from paddle.signal import frame
# 1D # 1D
x = paddle.arange(8) x = paddle.arange(8)
...@@ -177,7 +175,7 @@ def overlap_add(x, hop_length, axis=-1, name=None): ...@@ -177,7 +175,7 @@ def overlap_add(x, hop_length, axis=-1, name=None):
.. code-block:: python .. code-block:: python
import paddle import paddle
from paddle.tensor.signal import overlap_add from paddle.signal import overlap_add
# 2D # 2D
x0 = paddle.arange(16).reshape([8, 2]) x0 = paddle.arange(16).reshape([8, 2])
...@@ -291,11 +289,11 @@ def stft(x, ...@@ -291,11 +289,11 @@ def stft(x,
real-valued input and `onesided` is `True`) or `[..., n_fft, num_frames]`( real-valued input and `onesided` is `True`) or `[..., n_fft, num_frames]`(
`onesided` is `False`) `onesided` is `False`)
Exampels: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
from paddle.tensor.signal import stft from paddle.signal import stft
# real-valued input # real-valued input
x = paddle.randn([8, 48000], dtype=paddle.float64) x = paddle.randn([8, 48000], dtype=paddle.float64)
...@@ -415,7 +413,7 @@ def istft(x, ...@@ -415,7 +413,7 @@ def istft(x,
- :math:`N`: Value of `n_fft`. - :math:`N`: Value of `n_fft`.
- :math:`H`: Value of `hop_length`. - :math:`H`: Value of `hop_length`.
Result of `istft` expected to be the inverse of `paddle.tensor.signal.stft`, but it is Result of `istft` expected to be the inverse of `paddle.signal.stft`, but it is
not guaranteed to reconstruct a exactly realizible time-domain signal from a STFT not guaranteed to reconstruct a exactly realizible time-domain signal from a STFT
complex tensor which has been modified (via masking or otherwise). Therefore, `istft` complex tensor which has been modified (via masking or otherwise). Therefore, `istft`
gives the [Griffin-Lim optimal estimate](https://ieeexplore.ieee.org/document/1164317) gives the [Griffin-Lim optimal estimate](https://ieeexplore.ieee.org/document/1164317)
...@@ -454,12 +452,12 @@ def istft(x, ...@@ -454,12 +452,12 @@ def istft(x,
A tensor of least squares estimation of the reconstructed signal(s) with shape A tensor of least squares estimation of the reconstructed signal(s) with shape
`[..., seq_length]` `[..., seq_length]`
Exampels: Examples:
.. code-block:: python .. code-block:: python
import numpy as np import numpy as np
import paddle import paddle
from paddle.tensor.signal import stft, istft from paddle.signal import stft, istft
paddle.seed(0) paddle.seed(0)
......
...@@ -221,8 +221,6 @@ from .array import array_write # noqa: F401 ...@@ -221,8 +221,6 @@ from .array import array_write # noqa: F401
from .array import create_array # noqa: F401 from .array import create_array # noqa: F401
from .einsum import einsum # noqa: F401 from .einsum import einsum # noqa: F401
from . import fft
from . import signal
#this list used in math_op_patch.py for _binary_creator_ #this list used in math_op_patch.py for _binary_creator_
tensor_method_func = [ #noqa tensor_method_func = [ #noqa
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册