From 35fab724261fd832d17641d967c0cbd86fed8aaa Mon Sep 17 00:00:00 2001 From: PlumBlossomMaid <1589524335@qq.com> Date: Fri, 29 May 2026 13:25:56 +0000 Subject: [PATCH] Add torchaudio.functional.resample API mapping and alignment tests - Add torchaudio.functional.resample -> paddle.audio.functional.resample mapping in paconvert/api_mapping.json using ChangeAPIMatcher - Create tests/torchaudio_tests/ directory for torchaudio API tests - Add test_functional_resample.py with 6 test cases covering: basic positional args, all kwargs, reordered kwargs, custom lowpass/rolloff, kaiser method with beta, and batch input --- paconvert/api_mapping.json | 4 + tests/torchaudio_tests/__init__.py | 0 .../test_functional_resample.py | 91 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tests/torchaudio_tests/__init__.py create mode 100644 tests/torchaudio_tests/test_functional_resample.py diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index 2b4e144f8..bdc7416d6 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -13368,5 +13368,9 @@ "args_list": [ "*docstr" ] + }, + "torchaudio.functional.resample": { + "Matcher": "ChangeAPIMatcher", + "paddle_api": "paddle.audio.functional.resample" } } diff --git a/tests/torchaudio_tests/__init__.py b/tests/torchaudio_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/torchaudio_tests/test_functional_resample.py b/tests/torchaudio_tests/test_functional_resample.py new file mode 100644 index 000000000..692977fce --- /dev/null +++ b/tests/torchaudio_tests/test_functional_resample.py @@ -0,0 +1,91 @@ +# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import textwrap + +from apibase import APIBase + +obj = APIBase("torchaudio.functional.resample") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0) + result = torchaudio.functional.resample(waveform, 16000, 8000) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0) + result = torchaudio.functional.resample(waveform=waveform, orig_freq=16000, new_freq=8000) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4) + + +def test_case_3(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0) + result = torchaudio.functional.resample(new_freq=8000, waveform=waveform, orig_freq=16000) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4) + + +def test_case_4(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0) + result = torchaudio.functional.resample(waveform, 16000, 8000, lowpass_filter_width=12, rolloff=0.95) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4) + + +def test_case_5(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0) + result = torchaudio.functional.resample(waveform, 8000, 16000, resampling_method="sinc_interp_kaiser", beta=12.0) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4) + + +def test_case_6(): + pytorch_code = textwrap.dedent( + """ + import torch + import torchaudio + waveform = torch.sin(torch.arange(1000, dtype=torch.float32) * 0.1).unsqueeze(0).unsqueeze(0).expand(4, 1, -1) + result = torchaudio.functional.resample(waveform, 44100, 16000) + """ + ) + obj.run(pytorch_code, ["result"], rtol=1e-4)