Skip to content

Validate n_mels in paddle.audio.functional.create_dct - #80029

Open
lanqing431 wants to merge 1 commit into
PaddlePaddle:developfrom
lanqing431:fix/create-dct-invalid-mels
Open

lanqing431 wants to merge 1 commit into
PaddlePaddle:developfrom
lanqing431:fix/create-dct-invalid-mels

Conversation

@lanqing431

Copy link
Copy Markdown

PR Category

User Experience

PR Types

Bug fixes

Description

Validate that n_mels is positive before building a DCT matrix. Zero previously raised ZeroDivisionError, and negative counts could either yield an empty result or fail with a math-domain error depending on normalization. Invalid counts now raise a parameter-specific ValueError in either mode.

The four new regression cases fail against the previous implementation. All 176 cases in test_audio_functions.py pass with the checkout's create_dct loaded over the Paddle 3.3.1 CPU wheel on Windows. Ruff check/format and git diff --check passed.

Fixes #79998.

是否引起精度变化

否

@Paddle-Review-Bot

Paddle-Review-Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Paddle-Bot Review Board (review完成)

序号 位置 优先级 规则来源 状态

可维护性建议(总分 94.3 / 100,只给建议,不影响评审结论)

序号 位置 维度 状态
1 create_dct docstring 缺少新错误契约的 Raises 说明 契约一致性 💡
各维度得分(仅评本 PR 改动,点击展开)
88 契约一致性
1
88 错误处理一致性
90 API 表面一致性
92 中层优雅度
93 底层优雅度
95 约定偏离
95 设计一致性
95 高层优雅度
95 逻辑清晰度
95 测试策略
96 AI 生成债务
96 包组织结构
97 命名质量
100 跨模块架构
100 类型安全
— 抽象适配度
— 鉴权一致性
— 依赖健康度
— 未完成迁移
— 初始化耦合

Powered by Nyanpasu claude with DeepSeek-V4.1-Flash 默认推理级别, please check the suggestions carefully.

Args:
n_mfcc (int): Number of mel frequency cepstral coefficients.
n_mels (int): Number of mel filterbanks.
n_mels (int): Positive number of mel filterbanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 可维护性建议(契约一致性,不阻塞合入):本 PR 为 create_dct 新增了 n_mels <= 0 时抛出 ValueError 的错误契约,但 docstring 只把参数描述改成了 “Positive number”,没有 Raises: 段;而同模块的公开接口(如 resample、_get_sinc_resample_kernel)都会在 docstring 中声明 Raises:。建议在 Returns: 前后补充错误契约,例如:Raises: ValueError: If n_mels is not a positive integer.,让调用方从文档即可得知失败方式。

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_dct exposes ZeroDivisionError when n_mels=0

2 participants